Frontier

KV cache sizing and memory budgets

An 80 GB accelerator budgeted line by line for Qwen3.8-27B: weights, runtime reserve, the key-value pool at 64 KiB per token, the reference float32 DeltaNet matrix state of 144 MiB per sequence, and the same budget redone at FP8.

Updated

01 · Concept

Concept

You have one 80 GB accelerator and a product requirement: serve Qwen3.8-27B to as many simultaneous conversations as the card allows, each with an 8,192-token window. Somebody subtracts 54 for the weights from 80, divides the remainder by lesson 7.2’s 64 KiB per token, and reports 48 users. The worked result is 36: the naive estimate is high by one third, and the failure mode is an out-of-memory crash under load. This lesson does the budget line by line because everything downstream prices against it.

Start with usable capacity rather than brochure capacity. A part marketed as 80 GB carries 80 GiB-class HBM and reports roughly 79.6 GiB to the runtime once ECC and reserved firmware regions are taken out, so the number you can actually allocate is smaller than the number on the box. Doing the entire budget in one unit family is the only defence, so convert everything to gibibytes and stay there. The bf16 weights, about 54 GB from the canonical figure, are 50.3 GiB. Next comes a line the naive subtraction omits entirely: the runtime reserve. The driver context, activation buffers for the largest batch you intend to run, temporary workspace for the attention and feed-forward kernels, and allocator fragmentation together consume several gibibytes before a single token of cache exists. Six gibibytes is an illustrative and not especially generous figure; serving frameworks encode the same idea as a utilization fraction, defaulting to holding back roughly a tenth of the device. The remainder is the pool:

79.6 GiB50.3 GiB6 GiB = 23.3 GiB = 23,859 MiB.79.6\ \text{GiB} - 50.3\ \text{GiB} - 6\ \text{GiB} \ =\ 23.3\ \text{GiB} \ =\ 23{,}859\ \text{MiB}.

Now price one sequence, and price it completely. Lesson 7.2 derived the cache at 4 KiB per token per caching layer, 64 KiB per token across the 16 full-attention layers, and that derivation is not repeated here. An 8,192-token conversation therefore holds

  1. Weights, bfloat1654 GB · fixed
  2. KV cache, one full-context sequence16 GiB · grows per token
  3. DeltaNet recurrent state~144 MiB · constant
  4. Activations, fragmentation, runtimereserve, never zero
What fills an acceleratorWeights are fixed the moment you choose a precision. Everything left over is what decides how many concurrent sequences fit, and the KV cache is the only part that grows with every token generated.Derived in lesson 7.2-the-kv-cache
8,192 tokens×64 KiB = 524,288 KiB = 512 MiB8{,}192\ \text{tokens} \times 64\ \text{KiB} \ =\ 524{,}288\ \text{KiB} \ =\ 512\ \text{MiB}

of keys and values. But the 48 Gated DeltaNet layers are not free either. In the reference Transformers path, each keeps a 3 MiB float32 matrix state, 144 MiB across the layers, excluding the small convolution state. The state belongs to the sequence, not the model. Every concurrent conversation carries its own copy. The true per-sequence cost is 512 plus 144, or 656 MiB, and the pool holds

23,859 MiB656 MiB  36 concurrent sequences.\frac{23{,}859\ \text{MiB}}{656\ \text{MiB}} \ \approx\ 36\ \text{concurrent sequences}.

Thirty-six, not forty-eight. The three corrections that closed the gap were the unit conversion, the runtime reserve, and the constant recurrent state.

Push the same pool to the other extreme. A full 262,144-token sequence holds 16,384 MiB of K/V plus 144 MiB of matrix state, so the pool holds one. At 32,768 tokens each sequence costs 2,048 plus 144, or 2,192 MiB, and the card serves ten. Concurrency is a function of the context length you promise.

Redo the budget with FP8 weights and an FP8 cache. The weights halve to about 27 GB, or 25.15 GiB, and the cache halves to 32 KiB per token. The pool becomes about 48.45 GiB or 49,613 MiB. Each 8,192-token sequence now costs 256 MiB of cache plus the unchanged 144 MiB reference state, 400 MiB in total, so the card serves

49,613 MiB400 MiB  124 concurrent sequences,\frac{49{,}613\ \text{MiB}}{400\ \text{MiB}} \ \approx\ 124\ \text{concurrent sequences},

and five full-native-context conversations rather than one. That is about a 3.4-fold gain in concurrency from this paired precision change.

Omitting the DeltaNet state predicts 46 bf16 sequences instead of 36, about 28 percent too many, and 193 FP8 sequences instead of 124, about 56 percent too many. The state is constant, so as each variable term shrinks its relative weight grows; many copies of a fixed 144 MiB become a major budget line.

Carry two habits out of this lesson. Budget in one unit family, and price a sequence completely rather than pricing only its cache. Lesson 9.4 changes the capacity line by changing the silicon, and lesson 9.10 turns these occupancy figures into cost per token.

02 · Analogy

Analogy

A removals van has a stated capacity, but the usable space is what remains after the tail lift, the straps, the blankets, and the driver's own toolbox. Load planning that starts from the brochure figure ends with furniture on the pavement. A memory budget is the same exercise: the brochure says 80 GB, the weights are the piano, the runtime reserve is the toolbox nobody counted, and every extra passenger brings luggage that scales with the trip and a bag that does not.

03 · Lab

Lab

Weights50.3 GiB
KV pool23.3 GiB
Per sequence2,192 MiB
Concurrent sequences10

Fits, with room to spare.

KV fixed at 64 KiB per token (16 attention layers, lesson 7.2) plus 144 MiB of Gated DeltaNet state per sequence, constant in length.

04 · Teach it back

Teach it back

Budget an 80 GB accelerator for Qwen3.8-27B line by line and state how many 8,192-token conversations it serves concurrently, then redo the budget with FP8 weights and an FP8 cache.

Minimum: 80 characters and 15 words. Your writing stays only in this browser.

Waiting for your explanation.

Compare with a model answer

An 80 GB part reports roughly 79.6 GiB usable. The bf16 weights are about 54 GB, which is 50.3 GiB, and a 6 GiB runtime reserve leaves about 23.3 GiB, or 23,859 MiB, as the state pool. Lesson 7.2 derived 64 KiB per token, so an 8,192-token conversation holds 512 MiB of cache; the reference float32 DeltaNet matrix state adds 144 MiB, giving 656 MiB per sequence and 36 concurrent conversations. One full 262,144-token sequence needs 16,384 MiB of cache plus 144 MiB, so only one fits. With FP8 weights at about 27 GB and an FP8 cache at 32 KiB per token, the pool grows to 49,613 MiB and each 8,192-token sequence costs 256 plus 144, or 400 MiB, giving 124 concurrent conversations and five full-context sequences.

05 · Check your understanding

Check your understanding

01On an 80 GB accelerator running Qwen3.8-27B in bf16, why does the naive estimate of 48 concurrent 8,192-token conversations overshoot the worked figure of 36?
Answer and explanation

It counts 80 GB as fully usable, ignores the runtime reserve, and omits the 144 MiB reference float32 DeltaNet matrix state each sequence carries — Brochure capacity is not usable capacity, the runtime needs several gibibytes before any cache is allocated, and the constant per-sequence recurrent state is real memory that the KV arithmetic alone never shows.

02Lesson 7.2 derived Qwen3.8-27B's cache as 64 KiB per token rather than 256 KiB. Which architectural fact produces the smaller figure?
Answer and explanation

Only the 16 full-attention layers cache keys and values; the other 48 Gated DeltaNet layers keep fixed-size state — Assuming all 64 layers cache quadruples the estimate; the hybrid layout means three quarters of the depth contributes no per-token cache at all.

03Moving to FP8 weights and an FP8 cache raises concurrency from 36 to 124 sequences. What happens to the share of the budget taken by the DeltaNet state?
Answer and explanation

It rises, because the constant 144 MiB reference state stays fixed while everything around it shrinks — Ignoring the state overestimates bf16 concurrency by about 28 percent but FP8 concurrency by about 56 percent; a constant term grows in relative importance as the variable terms shrink.

Complete the teach-back and answer the quiz correctly to finish this lesson.

◎ · Evidence marker

Sources

  1. Woosuk Kwon et al. (2023). Efficient Memory Management for Large Language Model Serving with PagedAttention.
  2. vLLM Project (2026). vLLM Documentation.
  3. Qwen Team (2026). Qwen3.8-27B Model Card.