· AI

Sizing hardware for local inference

Memory capacity decides whether a model fits and memory bandwidth decides how fast it runs. How quantization changes both, and how to measure tokens per second on your own prompt before you buy anything.

Size hardware for local inference on memory first. Two numbers do most of the work: how much memory the model can sit in, and how fast the machine can read that memory. Core counts and GPU model names come after those two.

That holds whether the memory is the VRAM on a graphics card, the unified memory in a laptop-class chip or ordinary system RAM. The physics are the same in each case and only the numbers change.

Capacity: will it fit

A model is a file of numbers, and the whole file has to be in memory to run. The llama.cpp documentation says so directly: models are fully loaded into memory, and "memory and disk requirements are the same."

The size of the file is the number of parameters multiplied by the bits used to store each one. That second figure is what quantization changes. The llama.cpp project publishes a table for one 8-billion-parameter model, Llama 3.1 8B, that shows the range:

  • At 16 bits per weight, the file is 14.96 GiB.
  • At the Q8_0 setting (8.50 bits per weight), it is 7.95 GiB.
  • At Q4_K_M (4.89 bits per weight), it is 4.58 GiB.
  • At the most aggressive setting listed (about 2 bits per weight), it is 1.87 GiB.

Two things to take from that table. A "4-bit" quantization is closer to 5 bits in practice, so do the arithmetic with the real figure. And the same model spans an eightfold range in size depending on a setting you choose.

The file is not the whole requirement. The model also needs working memory for the context it is reading, and that grows with the context length you configure. It grows again with concurrency. Ollama's documentation notes that parallel request processing "results in increasing the context size by the number of parallel requests." Then there is the operating system and anything else on the machine.

So the capacity question has four inputs: the model file at the quantization you intend to run, the context length, the number of simultaneous requests and what else shares the memory. Add them up and leave headroom.

If the total exceeds the fast memory you have, the runtime will usually still load the model by splitting it between the GPU and system memory. Ollama's ollama ps command reports this in its processor column, with an example of "48%/52% CPU/GPU." A split model runs, and it runs at something close to the speed of the slower half. If you sized for a GPU and see a split, you have missed your target.

Bandwidth: how fast will it run

Here is the part that surprises people who come from sizing virtual machines. To generate one token, the machine reads essentially all of the model's weights once and does a small amount of arithmetic on each. The processor spends most of its time waiting for memory. An Arm engineering guide on the subject gives the relationship as a formula: decode tokens per second equals effective memory bandwidth divided by the bytes read per token. A long-running thread on the llama.cpp project puts it more bluntly: "LLMs are bound by Memory Bandwidth not Compute."

You can work out a ceiling on the back of an envelope. Dual-channel DDR5-5600 has a theoretical peak of 89.6 GB per second (5,600 million transfers a second, 8 bytes each, two channels). Divide that by a 4.9 GB model file and you get about 18 tokens per second. That is the most the memory could deliver if nothing else were in the way. A real system will come in under it. Double the model size and the ceiling halves.

How big the file is, and how fast memory can feed it
8 billion
Quantization
16 bits per weight16.0 GB
Q8_0, 8.50 bits8.5 GB
Q4_K_M, 4.89 bits4.9 GB
About 2 bits2.0 GB

About 4.9 GB on disk. Dual-channel DDR5-5600 could deliver at most about 18 tokens per second.

File size is estimated as parameters × bits per weight ÷ 8. The ceiling divides 89.6 GB per second, the peak for dual-channel DDR5-5600, by the file size.

This explains several things that otherwise look odd.

Adding cores stops helping early, because the cores are all waiting on the same memory channels. A server CPU with eight or twelve memory channels generates tokens faster than a desktop CPU with two, for the same reason.

GPUs are fast at this mostly because their memory is fast. A discrete GPU's memory bandwidth is several times that of a dual-channel desktop.

An integrated GPU that shares system memory does not escape the limit. It reads the same weights over the same memory channels as the CPU does.

And a smaller quantization is faster as well as smaller, since there are fewer bytes to read per token.

There is a second speed to know about. Reading the prompt is a different job from writing the answer. The prompt's tokens can be processed together, which makes that phase depend more on compute. The same Arm guide notes that prompt processing speeds up when you add cores, and that the best thread count for it often differs from the best one for generation. So every system has two rates, one for tokens in and one for tokens out, and they do not move together.

Quantization: the trade

Fewer bits per weight gives you a smaller file and more tokens per second, and it costs accuracy. Nobody can tell you in advance where the loss starts to matter for your task. A classifier with five labels may be unaffected at a setting where a model writing SQL begins making mistakes.

The practical approach is to pick the task first, build a small set of test cases with known right answers, and run the same set at two or three quantization levels. I described that kind of test in February. It applies here without changes.

Measuring on your own prompt

A published tokens-per-second figure was measured on someone else's prompt, at someone else's context length, with someone else's output length. Measure your own before you size anything.

Use the real prompt. That means the full system prompt, the retrieved context if there is any and a typical user input. A long system prompt changes the result more than people expect, because all of it is read before the first output token appears.

Record the two rates separately. Ollama's API returns the counts and durations you need with every response: prompt_eval_count and prompt_eval_duration for the input side, eval_count and eval_duration for the output side, plus load_duration and total_duration. The durations are in nanoseconds. Divide each count by its duration to get tokens per second. Other runtimes report the same quantities under different names.

Work out time to first token. For an interactive application this is what the user feels. It is the load time, if the model was not already in memory, plus the time to read the prompt.

Test cold and warm. Ollama's FAQ says models are kept in memory for five minutes by default before being unloaded. The first request after an idle period pays the load time again. Decide whether that is acceptable or whether the model should stay loaded, which means its memory is never free for anything else.

Test at the concurrency you expect. Four simultaneous requests share the same memory bandwidth, so they do not each get the single-request rate.

Check where the model landed. Confirm with the runtime's own status command that the model is on the processor you think it is on, and look again after any driver or runtime upgrade.

From the measurement to the purchase

Work backward from the requirement. The application team owns three numbers: the prompt length, the output length and the response time users will accept. From those you get a required rate for tokens in and tokens out. The test tells you the smallest model and quantization that does the task. Model size and required rate together give you a memory capacity and a memory bandwidth. Then you can look at hardware.

Sized in that order, the answer is often less hardware than the first estimate suggested, because the task turned out to fit a smaller model. Sometimes it goes the other way, and that is better learned from a test than from a purchase.

Runtimes and model formats change quickly, and an upgrade can move these numbers in either direction. Keep the test prompt and the script that runs it, and run both again after every upgrade and before every hardware decision.

Views are my own.