Unit 9 of 11 · about 3 hours · explain
Cache-aware routing, KV offload and connector metadata
A prefix can be correct but live in the wrong place. Reuse pays only if reaching compatible state costs less than recomputing it, and movement must not outlive its storage owner.
You'll be able to
- Explain cache affinity as a routing hint that competes with queueing and load balance.
- Distinguish local prefix reuse, host/storage offload and KV transfer.
- Specify transfer metadata and ownership until load or save completion.
Covers
Read
In this order, only the parts listed
0 of 3 done
- RadixAttention: replica affinity and stale routing hintsSGLang: Efficient Execution of Structured Language Model Programs
arXiv:2312.07104v2, Appendix A.4, Data-Parallel Distributed RadixAttention
- Hands-On LLM Serving and Optimization: offload vocabularyHands-On LLM Serving and Optimization - Prefix Caching and Advanced KV Caching
Chapter 7, Advanced KV Caching: Self-Hosting LLMs, KV cache offloading, printed pp. 261 to 262; Hands-on LMCache, printed pp. 264 to 266
Read the hierarchy and cold/warm comparison. Skip the deployment commands, compression, blending and fleet cost claims; this unit needs a local transfer model, not that model size or topology.
- vLLM 0.31.0: connector ownership and synchronizationvLLM 0.31.0 - cache specifications and connector lifecycle
KVConnectorMetadata,KVConnectorHandshakeMetadata;KVConnectorBase_V1methodsget_num_new_matched_tokens,update_state_after_alloc,start_load_kv,wait_for_layer_load,wait_for_saveandrequest_finishedRead these contracts only. The metadata base classes do not prescribe a complete wire schema; design your compatible-state descriptor explicitly.
Focus on
- Compare predicted queue plus remaining prefill cost, not prefix length alone. A hot replica can have enough queue delay to lose to an idle replica that recomputes.
- Offload retains compatible state on a colder tier; it does not make host or storage bytes GPU-resident. Restore time includes lookup, transfer, synchronization and any conversion, with real destination capacity reserved.
- Transfer metadata needs request generation, exact prefix/position boundary, model and adapter version, tenant authorization, layer/group layout, dtype/scales, valid length and source/destination mapping. A checksum detects corruption, not permission or compatibility.
- Asynchronous save pins source blocks until completion; load must finish before its consumer reads. A cancelled transfer still needs acknowledged cleanup. Routing metadata may be stale, so the destination validates the hit and falls back safely.
Common mistakes · 3
- Treating a router's hit prediction as authority to use state. The destination must confirm presence, identity, compatibility and authorization.
- Freeing a source page as soon as a save is submitted. A pending copy can then read a recycled generation.
- Assuming a larger cold-tier cache gives a faster decode path. Restoring state and attending to it still consume time and device capacity.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.When should an idle miss replica beat a busy hit replica?Answer
When its predicted queue plus recomputation and remaining service is less than the hit replica's queue plus reuse and remaining service, under the same request contract.
2.Is a matching checksum enough to accept transferred KV?Answer
No. It can confirm payload integrity but not model compatibility, logical positions, tenant permission or freshness.
3.In the V1 connector contract, what does deferred freeing on
request_finishedrequire?AnswerThe engine must retain the request's blocks while asynchronous save/send owns them, and release them when transfer completion is reported. Submission alone is not completion.
You're done when
Your local simulation changes routing at the predicted queue crossover, rejects incompatible transfers and preserves source ownership through completion or acknowledged cancellation.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 11 more in the section
- 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.
- 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 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.
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.
- 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.
- 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.
- 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.