← Inference From First Principles

Key-Value Caching

A KV cache written by hand into GPT-2: why it is exact, what it saves, what it costs in memory, and how it fails when its state is wrong.

I deliberately reused a key-value cache built for one prompt while continuing a different prompt. The code ran without an error. But compared with a correctly recomputed reference, its next-position logits were off by a median maximum absolute error of 11.6 across twenty random trials (28.7 in the worst), and its top token agreed with the reference in only 8 of 20 trials.

In a second experiment I built the prefix cache after multiplying one layer’s MLP output-projection weights by 1.02, then continued with the original weights. The logits were off by a median of only 0.042, and the top token agreed in all twenty trials.

The first mistake is loud, if you have a reference to compare against. The second could pass any test that only checks the chosen tokens. Both are the same mistake: a KV cache is derived state, valid only for the exact computation that produced it.

Autoregressive Generation counted 1,040 token positions processed by a naive 32-token generation from a 17-token prompt, against 48 if each position were processed once. Prefill and Decode used the library’s cache as a black box. This chapter builds the cache itself, checks that it computes the same function as recomputation, measures what it saves in time and costs in memory, and examines what goes wrong when its state is reused incorrectly.

Where this sits

The Transformer as a Computation established that an earlier position cannot attend to later tokens. Attention and Its Computational Cost measured cache-shaped attention in isolation. Prefill and Decode timed cached decode through the library. Here we implement the cache and test its contract.

The Inference Lab gains two cache implementations; forward_cached, a GPT-2 forward pass that reads and updates the cache; and CachedBackend, which hides the cache behind the next_logits(ids) interface from Building Our First Inference Engine. The backend checks whether each request extends the token prefix it remembers, and resets if not. That is a useful first guard, not the full validity contract: it does not check the model’s identity, so it would not notice changed weights or configuration (see “State identity” below).

Beyond single completions, the cache is what lets a long agent session avoid recomputing an unchanged history, and what could let requests sharing a system prompt reuse its state, provided the model and the prefix both match exactly. PagedAttention and Prefix Caching take up allocation and sharing.

Why the cache is exact

The intuition. Because attention is causal, nothing at position \(i\) ever depends on what comes later. So once a position’s keys and values have been computed, they stay correct for every later step, as long as the model, positions, mask and earlier tokens are unchanged.

What is stored, and why not the query. At every layer, each new position computes a query, a key and a value. Its query is used once, to compute that position’s own attention output. Its key and value are needed again by every later position. So the cache keeps keys and values, one set per layer.

What a cached step does. Each step feeds in one new token, computes its query, key and value at every layer, appends the key and value to the cache, and attends over everything stored so far. With \(T-1\) cached positions, that is a \(1\times T\) score row per head.

What the cache does not do. It removes the recomputation of earlier positions: their projections, feed-forward layers and attention outputs. It does not remove attention over the past: every step still reads all the cached keys and values, so step cost and memory traffic still grow with context. And decoding stays sequential.

What “exact” means here. The cached computation is mathematically the same function. Floating-point results can still differ in the last bits, because a one-token cached operation and a full uncached matrix operation add numbers in different orders.

Counting positions. For a prompt of length \(P\) and \(n\) selected tokens (prefill selects the first, so only \(n-1\) generated tokens are fed back):

Loop Positions pushed through the model
No reuse \(nP + n(n-1)/2\)
With a cache \(P + n - 1\)

With \(P=17\) and \(n=32\): 1,040 positions without reuse, 48 with a cache, a ratio of about 21.7. That ratio counts positions; it is not a speed-up. Real time also depends on matrix shapes, launch overhead and cache traffic, so the benefit is large when the recomputed work was expensive and can be small when fixed overhead dominates. We measure it below.

KV cache principle

What is in it, and how big

For each layer, ConcatCache stores keys and values as tensors of shape \([B,h_{kv},T,d_h]\). Here \(h_{kv}\) is the number of key/value heads: 12 for GPT-2, but possibly fewer than the number of query heads in grouped-query or multi-query models. Ignoring alignment and allocator overhead, the active cache needs:

\[ \text{bytes} = 2 \cdot L \cdot h \cdot d_h \cdot T \cdot s \cdot B \]
where \(L\) is the number of layers, \(h\) the number of KV heads, \(d_h\) the head dimension, \(T\) the active length, \(s\) the bytes per element and \(B\) the batch size. The factor of 2 is keys plus values.

The formula matches the actual tensor sizes (numel × element_size) of live ConcatCache tensors in the recorded GPU experiment:

Precision Active length Formula (bytes) Concat tensor bytes
fp32 128 9,437,184 9,437,184
fp32 1,024 75,497,472 75,497,472
fp16 128 4,718,592 4,718,592
fp16 1,024 37,748,736 37,748,736

So a full-length GPT-2 cache is 72 MiB in fp32, or 36 MiB in fp16, per sequence. It grows linearly with context, batch and KV-head count. These are tensor sizes, not physical memory traffic or peak device residency; they exclude the model, temporary attention tensors, metadata, unused static capacity and allocator reservations.

Against the model. GPT-2’s 124,439,808 parameters take about 237 MiB in fp16. The script observed about 10,069 MiB free at one point and, after subtracting the fp16 model, computed an illustrative upper bound of 273 full-length caches. That is a scale estimate, not a tested batch capacity: it ignores activations, other allocations, fragmentation and runtime workspace. What it does show is that even for this small model, a few long-context caches cost as much as the weights.

Writing it

Making the forward pass from The Transformer as a Computation cache-aware takes three changes, plus one obligation about when the cache may be trusted.

1. Positions. If the cache already holds cache.length positions and \(t\) new tokens arrive, their position embeddings must be indexed from cache.length to cache.length + t - 1. Restarting at zero would give them the wrong positions. GPT-2’s learned position table has a fixed size, so a request that would exceed it must be rejected before any state is written.

2. The mask. The \(t\) new queries attend to \(\text{total}=\text{cache.length}+t\) keys. Query \(i\) in the chunk sits at absolute position \(\text{total}-t+i\) and may see keys only up to that position. The code masks the upper triangle with diagonal=total - t + 1. For a single token (\(t=1\)) nothing needs masking; for chunked prefill the offset is essential.

3. Updating and advancing. At each layer, cache.update(layer, k, v) appends the new keys and values and returns the full visible prefix for attention. After all layers, cache.advance(t) increases the shared length once.

x = wte[ids] + wpe[arange(offset, offset + t)]
for layer in range(n_layer):
    ...
    keys, values = cache.update(layer, k, v)          # [B, h, length + t, d_h]
    scores = q @ keys.transpose(-2, -1) / sqrt(d_h)
    scores = scores.masked_fill(triu(ones(t, total), diagonal=total - t + 1), -inf)
    ...
cache.advance(t)

The obligation: validity. Before any of this, the caller must establish that the stored tensors really represent the requested prefix under the same model and positional rules. That is a separate responsibility (see “State identity”). Note also that this teaching implementation has no rollback: if a forward pass fails after some layers have written their buffers, the cache is left partly updated.

Two storage strategies

ConcatCache StaticCache
How it grows Appends with torch.cat, allocating and copying each time Allocates max_len once and writes slices in place
What is live Only the active length Full capacity, from the start
Reset reset() (exact behaviour not described here) reset() sets the active length to zero; storage is not zeroed
Size reporting nbytes() nbytes() = capacity; used_bytes() = active part

(The concat strategy resembles a simple dynamic cache; it is not a claim about how any particular library allocates.)

Is a reset static cache safe? After reset(), old values remain in memory, so what keeps them out? The cache only returns views up to the active length, so stale entries beyond it are logically inaccessible. A regression test checks this: it resets a used static buffer, fills it with a different prefix and compares with a fresh buffer, and the logits match exactly. That supports the invariant for the tested path. It does not cover every aliasing or concurrency error, and a future test should interrupt an update halfway and check that the next request cannot see partial state.

Concat vs Static cache

It is the same function

Speed is worthless without agreement, so this comes first.

Tokens. From the 17-token prompt, each configuration generated 48 tokens greedily, compared with the uncached reference:

Tokens identical to no-reuse?
Concat cache, GPU and CPU yes, all 48
Static cache, GPU and CPU yes, all 48
Library cache, GPU yes, all 48

Logits. Tokens can hide small differences, so the parity command also compared cached logits with full recomputation at each of the 48 positions. On the GPU, the per-position maximum absolute error had a median of \(6.1\times10^{-5}\) and a worst value of \(6.7\times10^{-4}\); the CPU’s worst was \(5.3\times10^{-4}\). A separate check against the library at the original prompt differed by about \(6.1\times10^{-5}\) on the GPU and \(9.2\times10^{-5}\) on the CPU.

That is good evidence for these inputs and execution paths, not proof for all prefixes or decoding methods. A rare near-tie elsewhere could still flip a token, and for other models an absolute-error threshold should be paired with a relative-error or decision-margin check.

Tests. The checked-in tests use a tiny, randomly initialised GPT-2 to cover both cache designs: generation against recomputation, logits against the library, chunked against one-shot prefill, cache sizes, static overflow and reset, a deliberately wrong prefix, branch independence, and the backend’s hit/miss accounting. They do not run the real-model commands, and they do not test swapping weights after a cache is built. The GPT-2 measurements are recorded separately in research/ch10/results.json.

What it saves

The question. How much faster is one decode step with a cache, as the context grows?

The set-up. Time a single new input position after a prefix of length \(T\). Without reuse, the same hand-written forward pass processes the whole prefix plus the new token. With reuse, the prefix is prefilled once (outside the timing) and later steps extend the cache. Ranges are from two runs, each a median over several steps. This is steady-state step cost, not the cost of building the cache or completing a request.

Context GPU: no cache GPU: concat GPU: static CPU: no cache CPU: concat CPU: static
16 9.2 – 10.6 ms 9.1 ms 8.4 – 8.8 ms 77 – 79 ms 33.5 ms 29 – 31 ms
128 13.0 – 14.1 ms 9.2 – 11.7 ms 9.6 – 11.4 ms 279 – 299 ms 36 – 42 ms 33 – 34 ms
512 35.6 – 38.4 ms 9.1 – 12.1 ms 9.4 – 9.8 ms 1,141 – 1,185 ms 42 – 47 ms 34 – 49 ms
960 81 – 96 ms 8.4 – 16.5 ms 8.6 – 12.6 ms – – –

The same data as speed-ups (uncached divided by concat-cached, within each run):

Context GPU CPU, one thread
16 1.0 – 1.2× 2.3×
128 1.2 – 1.4× 7.2 – 7.8×
512 3.2 – 3.9× 24 – 28×
960 4.9 – 11.5× –

On one CPU thread, the cache pays off immediately. 2.3× at 16 tokens of context, 24–28× at 512. That fits removing a great deal of repeated matrix work, though individual CPU bottlenecks were not instrumented.

On this GPU, short contexts gain little. At 16 tokens, cached and uncached steps differed by at most about 20% in the two runs. That fits a substantial fixed cost per step, of the kind seen in Chapters 7 and 9, though no profiler isolated it here. At 512 tokens the cache was 3.2–3.9× faster; at 960, 4.9–11.5×.

The 960-token row is noisy. The concat step ranged from 8.4 to 16.5 ms between the two runs. That is too much variation to rank concat against static; a controlled repetition with fixed clocks, matched warm-up and more samples would be needed.

Inside the engine

The Chapter 6 engine gives a request-level view: 32 greedy tokens after a 17-token prompt, using the uncached library backend or either cached hand-written backend. Because the forward implementations differ, this is an integration test of the engine and its accounting, not a controlled measurement of what caching saves.

Device Backend ms per output token Output tokens/s Same ids as uncached library? Positions per request
CPU library, no reuse 118.8 8.4 reference 1,040
CPU hand-written, concat 33.5 29.8 yes 48
CPU hand-written, static 35.0 28.6 yes 48
GPU library, no reuse 8.5 117 reference 1,040
GPU hand-written, concat 9.9 101 yes 48
GPU hand-written, static 10.1 99 yes 48

On the CPU, the cached hand-written engine was about 3.5 times faster. On the GPU it was slower than the uncached library engine: about 9.9–10.1 ms per token against 8.5. Extra eager-PyTorch operations and fixed dispatch overhead in the hand-written code are likely contributors, but neither was isolated. For the benefit of caching itself, the matched step comparison above is the better evidence.

Don’t join absolute times across sessions. Prefill and Decode recorded about 11 ms per cached library decode step; this chapter recorded about 5–8 ms under related but not identical conditions. (That library figure does not sit easily with this chapter’s own tables, which show 8.4–16.5 ms per hand-written cached step and 8.5–10.1 ms per engine token; its measurement boundary is not recorded in a comparable form, so the discrepancy cannot be resolved from the record.) A check found that host-side selection and readback account for about a millisecond, not the whole difference, and the rest is unexplained. Compare speed-ups within a matched run, with its timing boundary and environment recorded.

What it costs in memory

The question. Do the two storage strategies stress the allocator differently?

The set-up. The memory command prefilled 16 random tokens, then extended each cache with 944 more one-token inputs to reach 960 positions, at batch sizes 1 and 8 in fp32. (Synthetic inputs; no meaningful text was generated.) Three different measures are reported: the active cache tensors, the peak PyTorch allocation above a baseline taken after model loading, and the allocator’s total reservation at the end, which includes memory unrelated to the cache.

Batch Design Active KV bytes at 960 Peak extra PyTorch allocated PyTorch reserved at end
1 concat 67.5 MiB 71.3 MiB 636 MiB
1 static 67.5 MiB (72 MiB capacity) 73.1 MiB 610 MiB
8 concat 540 MiB 563 MiB 2,926 MiB
8 static 540 MiB (576 MiB capacity) 588 MiB 1,108 MiB

Allocated memory looks the same. For both designs, peak extra allocation stayed close to the active cache size. (Concat’s temporary copies happen one layer at a time, so they do not double the whole cache at once.)

Reserved memory does not. At batch 8, concat ended with 2,926 MiB reserved against static’s 1,108 MiB, a difference of 1,818 MiB. Reserved memory is held by PyTorch’s caching allocator and may be reusable by PyTorch; it is not, by itself, proof of fragmentation, live demand or physical residency. Repeatedly requesting ever-larger tensors plausibly explains much of the gap, but allocator block reuse was not instrumented.

So this single batch-8 result motivates explicit allocation policies; it does not establish a fixed penalty for dynamic caches. Static allocation commits capacity up front but avoids repeated resizing; concat keeps only the active length live but churns the allocator. Attributing the gap properly would need allocator snapshots, controlled cache clearing and repetitions across batch and context sizes. PagedAttention explores blocked allocation.

State identity

The contract. Cached keys and values are valid only if everything that produced them still holds: the exact earlier token ids, and the computation: model weights, active adapters, tokeniser mapping (if text is tokenised), positional scheme, masks and relevant execution settings.

What the backend actually checks. CachedBackend.next_logits(ids) reuses its cache only if self.cache is not None, 0 < len(self.tokens) < len(ids) and ids[:len(self.tokens)] == self.tokens; otherwise it resets. That checks the token prefix and nothing else:

Part of the contract Checked by CachedBackend?
Requested ids extend the remembered prefix Yes
Cache length equals the remembered prefix length No (not separately asserted)
Model weights, adapters, configuration unchanged No
Positional rules and masks unchanged No

In the recorded engine experiment, each of five GPU requests reset once and then reused the next 31 prefixes: 5 resets and 155 reuses over 160 calls.

An identity key, not yet wired in. The helper prefix_key(manifest_sha256, token_ids) hashes a manifest hash with the ordered token ids. Tests confirm that changing either input changes the key. But CachedBackend does not use it, and it is not a shared prefix-cache index. Even if it were wired in, a hash is only as complete as what it covers: the manifest would need to capture live adapter state, positional rules, software versions and any mutable weights.

What goes wrong

The test. Four deliberately invalid ways of reusing a cache, plus two correct controls, each over 20 seeded trials. Each trial uses a random 24-token prefix and one supplied continuation token; the reference is a fresh recomputation of the logits after that token. So “argmax agrees” means agreement with the reference computation, not with any ground-truth next word.

Cache scenario Median max-absolute logit error Worst max-absolute error Argmax agrees with reference
Correct reuse 0.00003 0.00005 20/20
Built for another prompt 11.6 28.7 8/20
Wrong position offset 54.9 72.1 1/20
Static buffer reused without resetting length 5.7 17.3 14/20
Static buffer reused after resetting length 0.00003 0.00005 20/20
Prefix computed using perturbed weights 0.042 0.158 20/20

Loud failures. A cache from another prompt, a wrong position offset and a forgotten reset all produced large logit errors. Yet the top token still agreed in many trials: 8 of 20 for another prompt, 14 of 20 for the missed reset. (These are not comparisons with chance, since the model’s top token is not uniformly distributed.) The lesson: a test that checks only the chosen token would miss several clearly invalid cache states.

The quiet failure. The perturbed-weight case multiplies one layer’s MLP output-projection weight matrix by 1.02 while building the prefix cache, then continues with the original weights. The logits moved by a median of 0.042, and every top token agreed. This mimics one aspect of an adapter or model change; it is not a real adapter swap. And the 0.042 is an absolute logit error, so it cannot be compared with the figure from Matrix Multiplication and GPU Execution, \(3.6\times10^{-4}\), which was a relative matrix-product error, to argue that the cache is “numerically acceptable”. The real problem is that the two halves of the computation used different weights.

The fix is invalidation, not tolerance. A loose logit tolerance would accept the quiet failure. The correct response is to bind the cache to a frozen or versioned model and configuration, and check that binding before every reuse. The current backend does not, so a real adapter change or in-place weight update must be handled by an explicit invalidation hook until the full identity check exists.

State identity and failure modes

Sharing a prefix

Two continuations can safely start from the same validated prefix. In the recorded example, a 512-token prefix produced a 36 MiB fp32 concat cache. fork() cloned it into two separate sets of tensors; each was continued with a different token and compared with full recomputation. Both branches differed by at most \(6.1\times10^{-5}\), and the parent cache’s length stayed at 512.

That verifies isolated branches for one example. It saves no memory, because fork() copies the tensors rather than sharing physical blocks, and it measures no serving time. PagedAttention and Prefix Caching address shared storage and copy-on-write.

Inference Lab increment

The Lab now has:

  • ConcatCache and StaticCache, with update, advance, reset, fork and nbytes (and used_bytes() on StaticCache), plus cache_bytes(...) for active storage.
  • forward_cached(ids, weights, config, cache) for full prefill, chunked prefill and one-token continuation, with position offsets and an offset causal mask.
  • CachedBackend, which plugs into the Chapter 6 engine, checks the token prefix, resets on a mismatch, and counts calls, reuses, resets and positions processed. It does not yet bind the cache to a checked manifest key.
  • prefix_key(manifest_sha256, token_ids), an identity-key helper not yet used by the backend.
  • Reproducible parity, speed, memory, hazards and engine experiments, with recorded results and tests that run without downloading GPT-2.

The acceptance rule is stricter than the current code: reuse cached state only if the stored token prefix, the cache length and every relevant model and configuration identity are valid for this request. The backend covers the first. The next engineering tasks are to store and verify the full identity, invalidate on change, and make updates failure-safe. A faster path whose cache provenance cannot be established is not yet a safe optimisation.

Limits of this chapter’s evidence

About the set-up

  • One small model, specific hardware. Larger models and other hardware may behave differently; the short-context GPU result was not profiled.
  • No production cache manager. Eviction, paging, quantisation, shared physical blocks, rollback and ragged batches were not tested.

About the measurements

  • Two forward implementations in the engine table. The matched step comparison isolates caching better.
  • Few runs, drifting times. Two runs per context are not enough for a general ranking, and absolute step times drifted between sessions.
  • Tensor bytes versus allocation. Formula checks count tensor storage; peak allocation and reserved memory are different questions, and only batches 1 and 8 were measured.
  • Illustrative capacity. The 273-sequence figure ignores activations, workspace, allocator behaviour and other applications.

About the hazards

  • Synthetic, small-sample hazards. Twenty trials on random prefixes, one supplied token and one perturbed weight matrix do not give rates for real workloads or real adapter changes.
  • Incomplete identity enforcement. Mutable model state, mask and position changes, partial updates and concurrent calls need safeguards the backend does not have.

What you should now be able to do

  • Explain why causal attention allows earlier keys and values to be reused, and why floating-point results still need not be bit-identical.
  • Calculate active KV storage, distinguishing query heads from KV heads, and separate tensor size from allocator reservation.
  • Count positions processed with and without a cache, without mistaking the ratio for a speed-up.
  • Implement position offsets, chunk-aware causal masking and consistent per-layer advancement.
  • Check a cache for token-level parity and compare logits against a stated tolerance.
  • Explain why caching paid off immediately on one CPU thread but only at longer contexts on this GPU, using matched implementations.
  • Distinguish concat growth from static allocation, and read allocator metrics cautiously.
  • Recognise stale-prefix, wrong-position, missed-reset and changed-weights hazards, and explain why matching top tokens can hide them.
  • Design an identity and invalidation check that goes beyond the current prefix-only backend.

The cache made each decode step cheap in arithmetic, but every step still reads the full cache and all the weights. Whether a step is then limited by arithmetic, by memory bandwidth or by overhead is the question Memory Bandwidth and Compute Bottlenecks tries to answer with predictions made before measuring.

Key terms

  • KV cache: stored keys and values of earlier positions at each layer, reusable while the earlier computation remains valid.
  • KV head: an attention head that stores keys and values; there may be fewer KV heads than query heads in GQA or MQA.
  • Static cache: capacity preallocated in fixed tensors and filled in place.
  • Concat cache: storage grown through concatenation as positions arrive.
  • State identity: the prefix and complete set of model/configuration dependencies that produced a cache.
  • Invalidation: discarding or resetting state when its identity no longer matches.
  • Fork: making independent continuation state; this chapter’s fork() clones tensor contents, not shared physical blocks.
  • Allocator-reserved memory: memory held by a framework’s caching allocator, distinct from memory occupied by live tensors.
  • Prefix key: a hash of a manifest identifier and ordered prefix tokens; in this Lab it is a helper, not an enforced backend check.

Reader exercises

  1. Remove the total - t + 1 causal-mask offset and measure the first divergent logit, not just the first divergent selected token. Explain the position that became wrongly visible.
  2. Compute the fp16 cache size for 32 layers, 32 KV heads, head dimension 128 and context 8,192. Repeat with eight KV heads, and state what a 24 GiB budget does not tell you about feasible batch size.
  3. Extend CachedBackend to persist (manifest_sha256, token_prefix, active_length) alongside the tensors. Add tests where the ids do not change, but the backend’s weights or adapter identity does; ensure the old state is rejected.
  4. Inject a failure in layer 2 of forward_cached after an earlier layer has updated its cache. Show whether the next call can reuse inconsistent state, then implement reset-on-failure or transactional advancement.
  5. Repeat the allocator experiment at batch 32, record allocated and reserved memory separately, and capture an allocator snapshot before calling the difference fragmentation.
  6. Make a rollback operation that truncates a cache to length \(k\); test both cache designs, update the stored prefix identity and reject out-of-range rollback.
  7. Modify greedy_cached so it does not execute an unnecessary extra cached forward pass after selecting the final requested token. Check its final cache.length, especially at the model’s context limit.
  8. Compare two different model-weight perturbations using both logit max-error and argmax decision margins, and explain why matching tokens is insufficient.
  9. Replace cloned fork() branches with a read-only shared prefix and copy-on-write suffix. Measure real memory sharing rather than just numerical parity.

References

Evidence in this chapter

Claim Evidence classification
Causal attention permits reuse of unchanged prefix KV state Established model property, subject to model/configuration identity
Active storage is \(2Lh_{kv}d_hTsB\) bytes Arithmetic; four concat tensor-size checks agree
Concat, static and library cached generation matched 48 uncached greedy tokens on tested paths Book result, one GPT-2 prompt, CPU/GPU as recorded
Per-step maximum absolute logit differences: median about \(6.1\times10^{-5}\), worst GPU \(6.7\times10^{-4}\) Book result, one prompt and 48 steps; numerical, not bitwise equality
32-token request: position count 1,040 no reuse versus 48 with cache Analytic count and book backend accounting
CPU cached step at context 512: about 24–28× faster than recomputation Book result, two runs, same hand-written forward
GPU cached step at context 512: about 3.2–3.9× faster Book result, two runs; short contexts show little gain
Cached hand-written engine slower than uncached library on GPU at 17–48 positions Book result, mixed implementations; not causal attribution
Batch-8 concat run reserved 1,818 MiB more PyTorch allocator memory than static Book result, one configuration; cause not directly profiled
Four incorrect reuse scenarios caused logit deviations Book result, 20 random trials each; last column is reference argmax agreement
A 2% perturbation of one MLP projection changed logits without changing observed argmaxes Book result, single synthetic weight perturbation; not an adapter swap
Forked continuation caches matched reference logits and kept parent length Book result; deep copies, not physically shared KV storage
Token-prefix validation in CachedBackend Implemented and tested; full manifest identity not enforced
273 full-length fp16 caches could fit in a memory budget Illustrative arithmetic, not a measured operating capacity
Paged cache management, physical prefix sharing, eviction, rollback, adapter invalidation NOT_IMPLEMENTED / NOT_MEASURED in this chapter