Unit 7 of 13 · about 5 hours · explain

Reconstructing the block manager, prefix cache, model runner and attention backend

Reuse your allocator and paged-attention invariants. The new task is to find their actual enforcement points and follow a schedule into the selected backend.

You'll be able to

  • Trace logical token positions through cache lookup, physical allocation and runner metadata to attention dispatch.
  • Identify cache ownership and lifetime boundaries in two miniature engines and vLLM V1.
  • Explain which runner assumptions constrain a scheduler or cache contribution.

Covers

Block manager and prefix-cache reconstructionModel runner and attention-backend reconstruction
1

Read

In this order, only the parts listed

0 of 3 done

  1. Nano-vLLM block ownership and attention addressesNano-vLLM and Mini-SGLang as Engine Reconstruction Bridges

    can_allocate, allocate, deallocate, may_append and hash_blocks; follow nanovllm/engine/model_runner.py: allocate_kv_cache, prepare_prefill, prepare_decode and run_model; then nanovllm/layers/attention.py: Attention.forward

  2. Mini-SGLang radix ownership and runner preparationNano-vLLM and Mini-SGLang as Engine Reconstruction Bridges

    RadixPrefixCache.lock_handle, match_prefix, insert_prefix, evict and _tree_walk; follow python/minisgl/scheduler/scheduler.py: _prepare_batch, including page-table allocation and attention metadata preparation

  3. vLLM 0.31.0 cache-manager entry pointsvLLM V1 Architecture Overview

    KVCacheManager.get_computed_blocks, allocate_slots and free; follow vllm/v1/worker/gpu_model_runner.py: _prepare_inputs, _build_attention_metadata, execute_model and initialize_attn_backend

    Trace one supported dense text model and selected backend. Hybrid cache groups and distributed connectors are interface reading, not an implementation requirement.

2

Focus on

  • Record the cache key, lookup result, references, free/used accounting and invalidation scope. Equal prompt suffixes are not equal prefixes.
  • Separate cache storage from attention addressing. The allocator chooses physical pages; the runner supplies positions, lengths, slot mappings and block tables; the backend consumes them.
  • Nano-vLLM excludes the final prompt block from prefix lookup at this commit. Follow the exact recomputed suffix rather than assuming every complete prompt block is reused.
  • Graph replay, padding and asynchronously prepared metadata extend lifetimes. A free operation must respect in-flight consumers, not merely the host request status.
Common mistakes · 3
  • Calling an unreferenced cached page unused memory. It may remain reusable until eviction; release and eviction are different operations.
  • Assuming a cache hash supplies model, tokenizer and tenant isolation. Verify the full identity scope separately.
  • Treating Mini-SGLang's check_integrity as a complete invariant suite. It is an empty method in the pinned radix implementation; write independent checks.
3

Try it yourself

Closed-book, before checking anything

Closed-book, map a cold prompt, an exact shared prefix and an append across a page boundary from request tokens to attention inputs. Use a CPU page-table fixture to compare gathered logical KV with a contiguous oracle and to recount references after release. Annotate the corresponding pinned source calls and graph/eager dispatch boundary; inspect GPU execution separately from this address-correctness check.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Which two maps are needed to find a cached token's physical KV?Answer

    The request's logical token position to logical page/offset, and its block table from logical page to physical page. Layer and KV-head layout then locate the values.

  2. 2.Why can released KV still occupy cache storage?Answer

    Release removes active references, but a prefix index may retain reusable content. Eviction makes that storage available for replacement.

  3. 3.Does a prefix hit prove the runner skips the whole prompt?Answer

    No. Lookup rules, block alignment and the need to recompute a final token or suffix determine actual skipped work. Trace returned token counts and scheduled inputs.

You're done when

Your three annotated cases reconcile token positions, page ownership and runner metadata, and each attention input has an identified producer and lifetime.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 12 more in the section
  • vLLM V1 Architecture OverviewvLLM Project · required

    Map API server, EngineCore, scheduler, KV cache manager, model executor and distributed deployment from the current documentation into exact source files. Select the bounded contribution only after identifying its state and fallback boundaries.

  • Nano-vLLM and Mini-SGLang as Engine Reconstruction BridgesGeeeekExplorer and SGLang Project · required

    Reconstruct Nano-vLLM first, then compare Mini-SGLang cache, scheduler, overlap and model-runner boundaries. Move to vLLM or SGLang only when you can predict where the same responsibility lives.

Also in this section