FDE Academy

Module 3 · Inference engineering · Chapter 25 · Free

GPUs and memory: sizing a model to hardware

18 min1 diagram1 VRAM calculator1 matching exercise3 checks
The problem A customer in a regulated industry must keep prompts inside their own data center. They have a budget for "a few GPUs" and a shortlist of open models. Procurement asks one question: how much GPU memory do we need to buy? Guess low and the model will not load or crashes under load. Guess high and you have spent a lot on idle silicon. A back-of-envelope calculation done in the first meeting can prevent either mistake.

Three things a GPU gives you

When you read about a GPU for inference, three separate properties matter. Mixing them up is the most common source of bad sizing advice.

Capacity is the first gate because it is binary. If the weights do not fit, nothing else matters. Speed is a matter of degree; fit is a yes or no.

What is inside a GPU server for inference A host computer with CPU memory connects to a GPU whose memory holds weights and cache. The GPU memory feeds the compute units. A fast link connects this GPU to a second GPU for splitting a large model. HostCPU + system RAM GPU memoryweights + KV cache Compute unitsthe arithmetic Second GPUshares the model
  1. For good speed the model weights sit in GPU memory for the whole time the server is running. If they do not fit, the model cannot run efficiently on that GPU.
  2. The KV cache (Chapter 23) is stored in the same memory, and it grows with context length and the number of simultaneous requests. Whatever the weights leave over is what the cache gets.
  3. Every decode step streams the weights and cache across this path. Its bandwidth, quoted in terabytes per second on spec sheets, often limits how fast tokens appear.
  4. When a model is too big for one GPU, it can be split across several. The GPUs then exchange data over a fast link, so the quality of that link matters for multi-GPU speed.
  5. The host's memory is large but much slower to reach from the GPU. Spilling there keeps things from crashing, but speed usually drops sharply. Plan to fit in GPU memory.
HostGPU memoryComputePeer GPU

The sizing formula

A first estimate has three parts. Everything is in bytes, then divided by a billion for gigabytes here.

1. Weights = parameters x bytes per parameter. A model with 8 billion parameters stored in a 2-byte format (such as FP16 or BF16) takes 16 GB. In a 1-byte format (8-bit) it takes 8 GB. In a 4-bit format it takes roughly 4 GB, plus a small amount for scaling data. Precision is the biggest lever on the weights.

2. KV cache = 2 x layers x KV heads x head dimension x tokens x batch x bytes per element. The 2 is for keys and values. Use KV heads, not attention heads: in grouped-query attention several attention heads share one set of keys and values, so the cache is smaller than the head count suggests. "Tokens" means context length held per request, prompt plus output, and "batch" means requests alive at once.

3. Activations and runtime overhead: temporary working memory, the inference engine's own buffers and some fragmentation. It is hard to calculate exactly, so the calculator uses a percentage of weights plus cache. A margin of 10 to 20 percent is a common starting assumption. Measure on your engine to refine it.

Two caveats. First, for a mixture-of-experts model, use the total parameter count for weights, since all experts generally must be resident (Chapter 23). Second, some architectures compress or limit the cache (for example with a sliding attention window), which makes this formula an overestimate for them. Check the model's configuration file for the real layer, head and dimension values.

VRAM calculator

Pick a preset or type your own values. Presets are illustrative shapes, not specifications of any named model: look up the real numbers in the model's published configuration. The GPU memory sizes in the table are editable and also illustrative.

VRAM calculator (illustrative presets)

Weights
KV cache
Overhead
Total needed
WeightsKV cacheOverhead
Does it fit? Edit the memory per GPU (GB, illustrative) and the number of GPUs.
GPU memory each (GB)GPUsCombinedFits?
Show the formulas with your numbers
Assumptions to remember GB here means 1 billion bytes, not 2^30. Multi-GPU rows assume the model and cache split evenly and ignore per-GPU duplicated buffers and communication memory, so leave extra margin. The cache term assumes every request uses the full context length. Real traffic is usually shorter on average, but plan for the long tail, or you will see out-of-memory errors at peak. Nothing here estimates speed. A model can fit and still be too slow. That is what Chapter 24 is for.

Reading a spec sheet

Look for three lines first: memory size, memory bandwidth and compute at the precision you plan to use. As a real example, NVIDIA's H100 page, at the time this chapter was written, lists 80 GB of memory at 3.35 TB/s for its SXM version and 94 GB at 3.9 TB/s for its NVL version. Check the current page, as products and listings change. Notice two things. Higher precision numbers for compute are often quoted "with sparsity", which gives a higher figure that only applies to models using that feature, so compare like with like and read the footnotes. And an interconnect speed is listed separately: it matters only when you use more than one GPU.

At a high level, NVIDIA's data center GPUs have moved through architecture generations. Its pages name Hopper (which includes the H100) and the newer Blackwell, whose page highlights support for 4-bit floating point (FP4) in its second-generation Transformer Engine. Newer generations generally bring more memory, more bandwidth and support for lower-precision formats, which together change what fits and how fast it runs. For exact numbers, always go to the current official product page.

Where models run: three tiers

Other accelerators exist beyond NVIDIA GPUs, such as cloud-vendor AI chips. Their trade-offs are mainly in software maturity and availability, so check the engine support you need before committing.

Match the term to what it limits

Check your understanding

Recap

In the field A composite example: a customer wanted to host a mid-size model for an internal assistant on a single GPU and asked for a yes or no. The weights fit with room to spare, so the first answer was yes. Then the FDE asked for the longest conversation users would have and how many people would be active at once. With the calculator, the cache for twenty long conversations did not fit alongside the weights. The options became clear in minutes: a smaller context limit, a lower-precision cache, a quantized model, or two GPUs. The customer chose with real numbers instead of finding out at launch.
Go deeper This chapter follows the topic order of the book Inference Engineering by Philip Kiely (Baseten Books): sections 3.1 GPU Architecture, 3.2 GPU Architecture Generations, 3.3 Instances, 3.4 Other Datacenter Accelerator Options and 3.5 Local Inference. The book is at baseten.co/inference-engineering. This course is independent material, not endorsed by the author or Baseten. Official hardware pages: NVIDIA H100 and NVIDIA Blackwell architecture.

Chapter quiz

Four questions. Score 70% or more to mark this chapter complete.

Review