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

Exact token, position and chat-template identityModel, tokenizer, adapter and cache-layout version scopeTenant and privacy scopeMultimodal embedding and media-cache identity
1

Read

In this order, only the parts listed

0 of 3 done

  1. 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.

  2. 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

  3. 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_keys and _gen_prompt_embeds_extra_hash_keys

    Trace 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.

2

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_salt propagates 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_salt as 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.
3

Try it yourself

Closed-book, before checking anything

Closed-book, make a hit/miss matrix for one cached token prefix. Change one field at a time: leading token, absolute position, template-produced tokens, model revision, adapter contents, cache layout, tenant namespace and media embedding. Require a miss or a verified conversion for every incompatible case. A sampling-temperature change alone may reuse prompt KV for the same already-fixed tokens, but must not reuse a sampled continuation or RNG state. Execute the matrix as CPU descriptor comparisons in servelab.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 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. 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. 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