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

Sampling, streaming and cleanup reconstructionDistributed worker and telemetry reconstruction
1

Read

In this order, only the parts listed

0 of 3 done

  1. Nano-vLLM sample and completion loopNano-vLLM and Mini-SGLang as Engine Reconstruction Bridges

    run, call, write_shm, read_shm and exit; follow nanovllm/layers/sampler.py: Sampler.forward; nanovllm/engine/scheduler.py: postprocess; and nanovllm/engine/llm_engine.py: generate

  2. Mini-SGLang output delivery and abort ownershipNano-vLLM and Mini-SGLang as Engine Reconstruction Bridges

    _process_last_data, _process_one_msg abort branch and _free_req_resources; follow python/minisgl/tokenizer/detokenize.py: DetokenizeManager.detokenize; python/minisgl/server/api_server.py: stream_chat_completions, stream_with_cancellation and abort_user; python/minisgl/scheduler/io.py: rank-specific receive/reply methods

  3. vLLM 0.31.0 output state and telemetryvLLM V1 Architecture Overview

    OutputProcessor.process_outputs, abort_requests, _finish_request, do_tracing and _update_stats_from_finished; follow vllm/v1/engine/async_llm.py: generate and abort; Architecture Overview: GPU Worker Processes and DP Coordinator Process

    Worker/rank coordination is source reading plus labeled local-process simulation. Trace actual execution with one worker on your GPU; additional GPUs are not required.

2

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

Try it yourself

Closed-book, before checking anything

Without notes, draw successful completion and cancellation during an in-flight iteration through all output and cleanup owners. Use CPU fake-runner events to replay late output after cancellation and repeated terminal notifications; assert no second client completion and no double release. Link each event to the pinned implementation and identify the telemetry needed to distinguish generated tokens from client-visible content.
4

Quiz yourself

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

0 got · 0 missed

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