Deployed Lab

Module 3 · GPUs and Kubernetes for AI · Chapter 09 · Free

GPU sizing: memory math for weights, KV cache and concurrency

20 min1 clickable picture1 hands-on lab1 predict, 2 quick quizzes, 5-question final quiz5-min video review
In 30 seconds

The picture: GPU memory is a fixed shelf. Weights are boxes that never move, the cache is boxes added per customer, and overhead is the space your hands need to work.

What this chapter gives you
The cold open

Copperline is a made up B2B SaaS company. Priya Nair, its staff platform engineer, rents a 24 GB GPU for the support copilot. The plan looks sound: the 8B model at FP16 needs 16 GB of weights, so 8 GB spare.

The budget had one line, and a real budget has four.

The plan for this chapter
  1. Step 1: weights. Step 2: KV cache.
  2. Step 3: overhead and headroom, then what is left.
  3. Steps 4 and 5: card classes by memory, then the picture.
  4. Steps 6 and 7: a worked 8B example, and tensor parallelism.
  5. Step 8: the break-it lab.

Next: the one line everyone gets right.

Step 1: Weights, the fixed first line

Weights are the simplest line in the budget:

Weights = parameter count x bytes per parameter
FP16 or BF16: 2 bytes    INT8: 1 byte    INT4: 0.5 bytes

Think of weights as furniture bolted to the floor of a rented room. Where the picture breaks down:

Chapter 3 builds this line from the model card. Deeper math: GPUs and memory sizing in the AI engineering course.

Next: the line that grows while you serve.

Step 2: KV cache, priced per token, per sequence

Each live sequence keeps a KV cache: saved key and value vectors for every token in its context. Chapter 3 gives the approximation reused here:

KV bytes per token (approximation)
  = layers x hidden size x 2 (keys and values) x bytes per value
8B example (illustrative): about 0.5 MB per token

Now the cold open adds up. At 2,048 tokens, one sequence needs about 1 GB of cache. After weights and overhead, the card has about 4 GB left: four sequences. Forty users need about 40 GB of cache alone.

Next: the allowance nobody wants to budget.

Step 3: Overhead, headroom, and what is left

Weights plus cache is still not the whole card. A serving engine needs working space:

Then keep headroom: memory you do not allocate. Spikes land there instead of an out of memory error.

The order of operations is the whole lesson:

The budget, in order
Card memory, minus weights, minus overhead, minus headroom
= KV budget. Concurrency = KV budget / cache per sequence

Compute concurrency last, from what is left.

Next: matching the finished budget to a card class.

Step 4: Choosing a card class by memory

Size by memory first. Speed comes after the model fits with its workload. Well known card classes:

Rent follows the class. Illustrative only: a mid class card might list at an illustrative price of $1.50 per GPU hour, a top class card at $3.50. Check current listings before any budget meeting with Greg, the finance partner.

Predict first:

The model loads because weights fit. The failure waits for traffic: as caches grow, the total crosses 48 GB and the engine must refuse work, preempt sequences, or crash.

Next: the picture, one card split into its four budget lines.

Step 5: The picture, one card, four lines

Press Next to fill the card line by line.

One GPU split into its memory budget A card holds weights, overhead, then KV cache. What remains is headroom, and cache space sets concurrency. One GPUfixed memory Weightsnever moves Overheadengine room KV cacheper sequence Headroomdo not spend
  1. The card total is the ceiling. Every line is paid out of it, in order.
  2. Parameters times bytes per parameter. Fixed, shared by every sequence.
  3. Activations, runtime and fragmentation, subtracted before any concurrency claim.
  4. What remains buys caches: this budget divided by cache per sequence.
  5. Reserve a slice on purpose. Allocating every gigabyte plans a peak failure.

Next: the full arithmetic, on an 8B deployment with a stated target.

Step 6: Worked example, sizing an 8B FP16 deployment

Target: an illustrative 8B model at FP16, full context 8,192 tokens, 8 concurrent sequences, cache at the chapter 3 approximation of 0.5 MB per token.

1. Weights. 8 billion times 2 bytes = 16 GB.

2. Cache per sequence. 8,192 tokens times 0.5 MB = 4,096 MB, about 4 GB.

3. Cache for the target. 8 sequences times 4 GB = 32 GB.

4. Overhead. Rule of thumb allowance: 4 GB.

5. Total. 16 + 32 + 4 = 52 GB, before headroom.

6. The card. An L40S at 48 GB does not fit it. An A100 80 GB or an H100 at 80 GB does, with 28 GB unallocated: headroom plus growth room for about 7 more full sequences.

What decided the card was not the weights, but the 32 GB of cache. Halve the context and the total drops to about 36 GB, and the 48 GB class works.

Next: when one card is not enough.

Step 7: When one GPU is not enough, tensor parallelism

Sometimes the budget beats every card: a 70B model at FP16 needs about 140 GB of weights alone. The standard answer is tensor parallelism: split each layer's work across several GPUs, so each holds part of the weights and part of the cache.

Think of four cooks sharing one recipe book, each holding some pages. Where the picture breaks down:

Next: the lab, where a confident plan meets your red pen.

Step 8: Break-it lab, debug the sizing plan

Why this exercise: sizing errors are cheap on paper and expensive at load test. This plan for Copperline's extraction workload contains exactly three planted errors.

Lab: Step 8 hands you Copperline's sizing plan for the extraction model, and it is wrong by more than ten times on concurrency. This lab runs in your browser and needs JavaScript enabled.

What to notice

Next: a field note, then the mix-ups.

Field note, November 2026

Serving engines in this category, including vLLM, TensorRT-LLM and SGLang, expose settings for the share of GPU memory the cache may use, because operators are expected to set that budget deliberately. In production practice, sizing sheets that list only weights are a common cause of first load test failures. Treat the four line budget as the minimum a review should show.

Mix-ups to avoid

Chapter quiz

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

Review this chapter in 5 minutes

Watch the whole chapter recapped: GPU memory math, KV cache and concurrency, card classes, and tensor parallelism when one card is not enough.

Decision rule: never approve a GPU plan that does not show all four lines and the concurrency they leave, at full context.

Review

Glossary

Weights
The model's parameters, loaded once and resident. Example: 8B at FP16 is 16 GB.
Precision
Bytes per parameter. Example: FP16 uses 2, INT8 uses 1.
KV cache
Saved keys and values per token per sequence. Example: about 0.5 MB per token here.
Concurrency
Sequences a card serves at once. Example: KV budget divided by cache per sequence.
Activations
Temporary values computed while a batch runs. Example: they grow with batch size.
Overhead allowance
Planned space for engine, buffers and fragmentation. Example: 4 GB here.
Headroom
Memory left unallocated for spikes. Example: 8 GB unspent in the corrected plan.
Card class
A GPU model grouped by memory. Example: L4 24 GB, L40S 48 GB, H100 80 GB.
Tensor parallelism
Splitting each layer across GPUs sharing weights and cache. Example: a 70B model across four cards.
Interconnect
Fast links between GPUs in a server. Example: split cards swap partial results over it.

Next: "Scheduling and sharing GPUs: MIG, time-slicing and quotas".