Unit 8 of 11 · about 4 hours · explain
Exact prefix identity, version scope and tenant privacy scope
A prefix hit authorizes use of another request's derived state. Model compatibility and tenant isolation must be explicit rather than inferred from equal text or a low collision probability.
You'll be able to
- Explain exact reuse identity across tokens, positions, templates, model versions and adapters.
- Specify a tenant-scoped namespace and invalidation rule that cannot be chosen by an untrusted client.
- Identify why media placeholders and mutable embeddings need identity beyond token IDs.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Hands-On LLM Serving and Optimization: prompt structure and tenantsHands-On LLM Serving and Optimization - Prefix Caching and Advanced KV Caching
Chapter 6, Prefix Caching: Best Practices and Scaling Prefix Cache, printed pp. 227 to 230
Read the formatting and tenant examples. Prefer an authenticated cache namespace over inserting a client-supplied tenant ID into the prompt; prompt changes also change model inputs.
- vLLM 0.31.0: multimodal keys and cache isolationvLLM Automatic Prefix Caching Design
Extra hashes; A hashing example with multi-modality inputs; Cache Isolation for Security
- vLLM 0.31.0: actual extra-key fieldsvLLM Automatic Prefix Caching Design
generate_block_hash_extra_keys,_gen_lora_extra_hash_keys,_gen_mm_extra_hash_keysand_gen_prompt_embeds_extra_hash_keysTrace these helpers only. The LoRA helper uses adapter name and path, not a checksum of files changed in place; invalidate or change the namespace on such updates.
Focus on
- Reuse requires the same effective causal inputs, positions, masks and model computation. Template or tokenizer changes can alter the leading token stream even when the displayed text looks unchanged.
- Separate mathematical identity from storage compatibility. Model weights, adapter contents and positional policy affect values; dtype, layout, quantization scales and cache-group conventions affect whether stored bytes can be consumed safely.
- Some fields are bound by the engine instance rather than repeated in each block key. A persistent or transferred cache needs an explicit model/tokenizer/template/adapter/layout version namespace and invalidation path.
- Bind privacy scope to authenticated server-side identity. In vLLM, first-block
cache_saltpropagates through parent hashes. Equal media placeholders are insufficient: processed media and supplied embeddings also affect KV. Freeze input data before hashing.
Common mistakes · 3
- Treating
cache_saltas authentication. An untrusted client must not select another tenant's namespace, and cache isolation is not a complete timing-channel defense. - Assuming stable adapter names or paths imply stable weights. In-place changes require invalidation or a content-version namespace.
- Reusing prompt embeddings after mutation because token IDs did not change. Cached hashes and KV now describe the old data.
Try it yourself
Closed-book, before checking anything
servelab.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Must changing temperature invalidate prompt KV for identical fixed input tokens?Answer
Not by itself. Temperature changes sampling after logits, not the deterministic prompt forward pass. Continuations and RNG state remain separate request state.
2.Why do two images with the same placeholder tokens need different cache identities?Answer
The placeholders are replaced by different processed embeddings. The effective model inputs differ even though the token IDs match.
3.Why can a model version be absent from a local block hash without making all reuse unsafe?Answer
The pool may belong exclusively to one fixed model instance. That binding must be enforced; cross-instance persistence or transfer cannot assume it.
You're done when
Your matrix rejects incompatible or unauthorized reuse and explains which fields are in each key, which are bound by the pool, and which remain request-local.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 12 more in the section
- Hands-On LLM Serving and Optimization - Prefix Caching and Advanced KV CachingChi Wang and Peiheng Hu (O'Reilly) · required
Read "Prefix Caching" in Chapter 6 (RadixAttention, use cases, best practices, scaling the prefix cache) and "Advanced KV Caching" in Chapter 7 (long context, cost and latency, LMCache). Separate exact-reuse mechanisms from capacity extensions such as offload.
- vLLM Automatic Prefix Caching DesignvLLM Project · required
Check block hashing, extra hash keys (multimodal inputs, LoRA, cache salt), isolation and eviction against v0.31.0, the version pinned here; cache-key fields change between releases.
Also in this section
- Efficient Memory Management for Large Language Model Serving with PagedAttentionvLLM Project · primary
Read the memory-waste motivation, block-table design, sharing and copy-on-write sections, then reproduce the logical-to-physical translation on paper. Separate the paper's reported workloads from results on your engine and hardware.
- SGLang: Efficient Execution of Structured Language Model ProgramsSGLang Project · required
Study RadixAttention, longest-prefix matching, eviction and cache-aware scheduling. Compare its sequence-level radix index with vLLM's block-level paging instead of treating them as competing names for one mechanism.
- AI Systems Performance Engineering - Chapter 18, tuning KV-cache utilizationChris Fregly (O'Reilly) · support
Read "Tuning KV Cache Utilization and Management" in Chapter 18 and "Prefix Caching" in Chapter 16. Leave the disaggregated pool and transfer sections for INF-7.
- Nano-vLLM - Block Manager and Sequence LifecycleGeeeekExplorer · required
Trace nanovllm/engine/block_manager.py, sequence.py, scheduler.py and attention.py. Draw allocate, append, share, preempt and free transitions, then implement randomized allocator tests in your own project before touching production-engine code.
- Mini-SGLang - Radix Cache and Cache TestsSGLang Project · required
Read docs/structures.md, the cache allocation code and tests/core/test_cache_allocate.py. Compare exact prefix identity and lifecycle with Nano-vLLM, then add tenant and version fields to your own prefix index.
- SGLang documentation - Radix cache eviction and HiCacheSGLang Project · support
Use the radix eviction policy and session radix cache pages to compare eviction choices with vLLM, and the HiCache design page for a GPU, host and storage hierarchy.
- AI Performance Engineering - KV Cache SystemsWafer · reference
A curated index. Use Section 4 only to find a primary KV-cache source the other entries lack.
- 100 Days of LLM Inference - Days 5, 9, 10 and 16Elizabeth Thomas · support
Use the four notebooks for KV arithmetic, paged allocation, radix reuse and prompt-layout experiments. Re-run conclusions against your own property tests and workload because these notebooks are a supplementary learning journal.
- TensorTonic Language Modeling from Scratch - Find Reusable Prefixes in a KV TrieTensorTonic · support
Solve after the prefix-index unit and add the cases its public tests leave out to your own property tests.
- LLM Inference: From scratch, one token at a time - Modules 02 and 06Tushar Amrit · support
Use The KV Cache for fragmentation and reuse and Memory Optimization for paging, prefix sharing and KV compression. Work the checkpoints before the matching units.
- LLM Inference Systems Laboratory - KV StateRoadmap-Final · support
Implement the paged allocator and prefix index with differential, randomized, cancellation, collision, fork and pressure tests. Retain one reuse workload that improves hit rate but not goodput.
- vLLM 0.31.0 - cache specifications and connector lifecyclevLLM Project · reference
Read the per-layer attention, MLA and Mamba specifications for hybrid state contracts; read the V1 connector metadata, load synchronization and deferred-free methods for transfer ownership. These fill the pool's hybrid-state and connector-contract gaps, without requiring distributed execution.