Unit 8 of 13 · about 4 hours · explain
Reconstructing sampling, streaming, cleanup, workers and telemetry
The request is not finished when the kernel returns. Sampling, stream delivery and cleanup determine output correctness, measured latency and whether the next request inherits stale state.
You'll be able to
- Trace logits through sampling, token state, detokenization and streaming to the client.
- Locate cancellation and completion cleanup across request, cache and frontend owners.
- Map worker control messages and telemetry boundaries without claiming distributed performance from a single-device run.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Nano-vLLM sample and completion loopNano-vLLM and Mini-SGLang as Engine Reconstruction Bridges
run,call,write_shm,read_shmandexit; follownanovllm/layers/sampler.py:Sampler.forward;nanovllm/engine/scheduler.py:postprocess; andnanovllm/engine/llm_engine.py:generate - Mini-SGLang output delivery and abort ownershipNano-vLLM and Mini-SGLang as Engine Reconstruction Bridges
_process_last_data,_process_one_msgabort branch and_free_req_resources; followpython/minisgl/tokenizer/detokenize.py:DetokenizeManager.detokenize;python/minisgl/server/api_server.py:stream_chat_completions,stream_with_cancellationandabort_user;python/minisgl/scheduler/io.py: rank-specific receive/reply methods - vLLM 0.31.0 output state and telemetryvLLM V1 Architecture Overview
OutputProcessor.process_outputs,abort_requests,_finish_request,do_tracingand_update_stats_from_finished; followvllm/v1/engine/async_llm.py:generateandabort; Architecture Overview: GPU Worker Processes and DP Coordinator ProcessWorker/rank coordination is source reading plus labeled local-process simulation. Trace actual execution with one worker on your GPU; additional GPUs are not required.
Focus on
- Mark when sampled token IDs become request state, when text becomes printable, when a chunk is sent and when the client sees content. These are distinct timing boundaries.
- Follow cancellation past the frontend acknowledgment. Request queues, KV references, in-flight work and output collectors may have different cleanup times.
- Mini-SGLang's overlap loop can observe terminal requests again while earlier work completes. Its finished-request guard is an ownership clue, not a reason to remove duplicate-event tests.
- Locate each telemetry producer and aggregation boundary. Join request and iteration records without logging sensitive prompt text or introducing unbounded metric labels.
Common mistakes · 3
- Equating one stream chunk with one model token. Detokenization, buffering and output intervals can merge or delay content.
- Using Nano-vLLM's terminal batch output as proof of online streaming behavior. That interface returns completed outputs, not an HTTP stream.
- Trusting Mini-SGLang's non-streaming usage fields as measured counts. The pinned API returns literal zeros there; count token IDs independently.
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.Does receiving an abort acknowledgment prove all KV is reusable immediately?Answer
No. Follow the cache owner and any in-flight consumers to the safe release point; acknowledgment and device completion can differ.
2.Why can first-content latency exceed first sampled-token latency?Answer
A token may not yet decode to printable text, and output processing, buffering, transport or a slow client can delay visible content.
3.What can a CPU worker-loss simulation establish?Answer
Request identity, terminal outcome, retry and bounded cleanup behavior under its event model. It cannot establish collective timing or distributed GPU throughput.
You're done when
Your map distinguishes generated tokens, visible chunks and safe release, and both normal completion and cancellation reconcile every owner and telemetry record.
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
- Hands-On LLM Serving and Optimization - Chapters 8 and 9, frameworks and optimization in practiceChi Wang and Peiheng Hu (O'Reilly) · primary
Read Chapter 9 as a worked sequence from traffic generation and baseline through quantized and distributed variants, then the vLLM architecture and scheduler sections of Chapter 8. Replace its model, engine version and hardware with your own fixed contract.
- TensorRT-LLM Benchmarking GuideNVIDIA · required
Use the benchmark workflow, configuration capture, startup metrics and online-serving path as a benchmark-governance reference. Apply the same discipline to your engine and never import NVIDIA results as your own evidence.
- UCSD CSE 291A (Spring 2026) - Guest lecture: Engineering vLLMUC San Diego · support
Read the scribe notes, Sections 3, 6 and 7: the architecture overview, model parallelism and serving topology, and the hybrid KV allocator with offloading. Use it to predict where a change would live before reading code.
- AI Performance Engineering - Inference Engine and Benchmark LanesWafer · reference
A curated index. Use Sections 4 and 5 only to find a mechanism source for the contribution.
- AI Systems Performance Engineering companion code - inference labsChris Fregly (O'Reilly) · required
Use
labs/dynamic_router,labs/cache_aware_disagg_inference,labs/speculative_decodeorlabs/flashinfer_attentionas a pattern for a controlled baseline, optimization and profile. Rerun everything under your own manifest. - Etalon: Holistic Performance Evaluation Framework for LLM Inference SystemsMicrosoft Research · required
Use its per-request SLO and goodput framing to audit the benchmark. Preserve raw outcomes, quality acceptance and load shape so a throughput increase cannot hide missed latency targets.
- Machine Learning Systems, Volume 2 - The Economics and Architecture of InferenceHarvard (Vijay Janapa Reddi) · support
Read the opening sections of Inference at Scale for cost per token, utilization and serving-architecture dimensions, then build your own capacity and cost model from measured numbers.
- MLPerf Inference Datacenter BenchmarkMLCommons · support
Study scenario definitions, audit discipline and reproducibility. Borrow governance ideas appropriate to the capstone; submitting to MLPerf or reproducing its fleet hardware is outside the gate.
- Artificial Analysis - Performance benchmarking methodologyArtificial Analysis · reference
Read how its latency, output speed and price figures are measured. Use its public numbers as an outside comparison for your capacity plan, never as your own evidence.
- LLM Inference Systems Laboratory - Full CapstoneRoadmap-Final · required
Complete the architecture map, contribution, fallbacks, correctness and fault suite, raw benchmark package, negative result, capacity and cost plan, independent reproduction and design defense. This artifact supplies the track milestone.
- SciPy bootstrap confidence intervalsSciPy · support
Read the resampling procedure, paired parameter, Notes on degenerate data and Examples. Apply it to independent trials; do not assume correlated serving requests are independent samples.
- Machine Learning Systems, Volume 2 - Sustainable AIVijay Janapa Reddi · support
For optional energy/carbon accounting, read Energy measurement techniques, System-level energy profiling and Operational carbon calculation. State meter boundaries and apply PUE only to complete IT energy, once.