ML Systems: From Weights to Work. Lesson 7. Why inference runs out of headroom. This educational session uses fictional healthcare operations examples. This session uses AI narration. Prefill and decode stress different resources A language-model request usually starts by processing the supplied prompt, often called prefill, then generates output tokens. Prefill can perform substantial parallel matrix computation across prompt positions. Autoregressive decoding produces successive tokens and repeatedly accesses model weights and cached state. Whether a particular request is compute-bound, bandwidth-bound or limited elsewhere depends on model shape, batch size, sequence length, kernels and hardware. Time to first token, time between tokens, total completion time and aggregate tokens per second describe different experiences. A large batch can improve throughput while making an individual request wait longer. Continuous batching lets requests enter and leave a serving batch as they progress, but does not remove resource contention. For a voice agent, an attractive throughput figure is weak evidence if the long tail leaves callers waiting in silence. Account for the key-value cache A simplified key-value cache contains two tensors, keys and values, across layers, key-value heads, head dimensions, sequence positions and concurrent sequences. The byte count is two times layers times KV heads times head dimension times sequence length times batch times bytes per cached value. Use KV heads, not query heads, in a grouped-query architecture. The formula assumes a uniform full-length cache and omits implementation-specific allocation and paging overhead. A binary gigabyte is two to the power thirty bytes, the unit written G i B. For thirty-two layers, eight KV heads, head dimension 128, sequence length 8192 and two-byte cache values, one sequence needs one binary gigabyte of KV payload. Sixteen such sequences need sixteen binary gigabytes. If the model instead had thirty-two KV heads, the payload would be four times larger. A wider context or higher concurrency can consume the remaining memory even when the quantized weights fit comfortably. Nominal precision is not total memory An eight-billion-parameter model at four bits per weight has a raw payload of four billion bytes, or about 3.73 binary gigabytes. Quantization scales and other metadata, runtime buffers, activations, graph capture, cache allocation and fragmentation add to that number. The lab includes an explicit reserve so you can see the difference between known payloads and an assumed allowance. That reserve is not a measured constant or an assurance that every runtime is covered. Mixture-of-experts models require another distinction: parameters activated per token and parameters that must remain resident are not the same number. Routing can reduce computation relative to activating every expert while memory and communication remain substantial. Loading experts on demand introduces a different performance tradeoff. Do not size a model's memory from its active-parameter count without understanding the serving design. Measure the workload you will actually serve Build a load test with realistic prompt lengths, output lengths, concurrency, arrival bursts and tool delays. Separate cold start from warmed service. Record queue time, prefill, decoding, cancellations and failed requests. Report distributions, not just averages, and keep the quality evaluation tied to the exact quantized model, adapter, prompt and runtime version used in the performance test. A healthcare workflow might allow an asynchronous RCM analysis to take several seconds but require a voice acknowledgment much sooner. Serving both through one unbounded queue can make the voice path unpredictable. Admission control, routing, reserved capacity and bounded output length may be more effective than buying a larger context window. When memory fits, the next question is whether the system meets its latency and quality requirements under the intended load; fitting is only the beginning of the capacity argument. Your decision exercise. Use the lab defaults: 8B parameters at 4 bits, 32 layers, 8 KV heads, head dimension 128, context 8192, batch 16, two-byte KV values, 4 binary gigabytes explicit overhead and a 24 binary gigabytes device budget. A colleague proposes doubling context with no change to concurrency, arguing that the weights are still only 3.73 binary gigabytes. Which capacity statement follows from the simplified calculation? Option 1. Both cases fit because weight quantization also halves the KV cache automatically. Option 2. The default is about 23.73 binary gigabytes; doubling context makes it about 39.73 binary gigabytes, exceeding the budget before any throughput claim. Option 3. The default requires only 8 binary gigabytes because grouped-query attention removes the cache. Pause here and commit to a choice. Name the decisive evidence and one limitation before continuing. Reference analysis. The default cache is sixteen binary gigabytes: one binary gigabyte per full-length sequence times sixteen sequences. Add 3.73 binary gigabytes of raw weights and four binary gigabytes of explicit reserve to get about 23.73 binary gigabytes. Doubling context doubles this cache to thirty-two binary gigabytes and raises the total to about 39.73 binary gigabytes. Weight precision does not automatically change cache precision. Even the nominally fitting default has little headroom and depends on the reserve being adequate; it is not a production capacity result. Measure the runtime and latency distribution before accepting the concurrency target. Now change one fact. Keep the longer context but halve concurrency. The simplified total returns to its earlier value. Explain what this does and does not tell you about requests per second, queue delay and a voice service-level objective. Give a capacity review that distinguishes raw weight payload, KV residency, runtime reserve and observed peak memory. Then name the four latency measurements you would collect during a burst test. Explain how a system can generate more total tokens per second while giving a worse experience to each caller. Your recommendation should state a workload and an admission policy, not just a GPU memory size.