Skip to content
Inference Academy

A map of vLLM and one request through it

How vLLM's V1 engine is laid out at v0.34.0: the API server, engine core and GPU worker processes, the ZMQ link between them, and the three calls at the heart of every engine step. Then follow one chat request from the HTTP handler to the streamed tokens, with the file and function for each hop, and set up a checkout to read along.

By

Key takeaways

  • vLLM V1 splits serving into processes: an API server that tokenises and streams, an engine core that schedules and owns the KV cache, and one worker per GPU that runs the model.
  • The API server and the engine core talk over ZMQ sockets with msgpack messages, so tokenisation and detokenisation never block the scheduler.
  • Every engine step is three calls: schedule, execute the model, update from the output. Everything else hangs off those three.
  • Pin a release when you read the code. Paths, defaults and even whole components change between versions.
25 min · verified 2026-111 animated diagram
Share

Goal: know where everything lives in vLLM's V1 engine, so the rest of this track (scheduler, KV cache, model runner, CUDA graphs, speculative decoding and LoRA) has a map to hang on. By the end you can follow one request through the code and name the function at each hop.

You need: Git, and Python you can read comfortably. No GPU for this lesson. Background that helps: prefill, decode and the roofline, scheduling, chunked prefill and preemption and engines compared from the inside.

Honest limits. This track is pinned to vLLM v0.34.0 (tag commit 62d4bc3, 14 November 2026). vLLM changes quickly: between releases, files move, defaults change and components are rewritten (the model runner in this release is a rewrite called Model Runner V2). Every path, default and line reference here was read from that tag. If you read a newer release, expect differences and treat this track as a guide to where to look, not a description of your version. We re-check it each quarter.

#Get the code

Read along in your own checkout, at the same tag:

bash
git clone --depth 1 --branch v0.34.0 https://github.com/vllm-project/vllm.git
cd vllm

Three places to know:

Folder What is in it
vllm/v1/engine/ The front end (async_llm.py), the client that talks to the engine core (core_client.py) and the engine core itself (core.py)
vllm/v1/core/ The scheduler (sched/scheduler.py) and the KV cache manager (kv_cache_manager.py, block_pool.py, kv_cache_utils.py)
vllm/v1/worker/ The GPU worker (gpu_worker.py) and the model runner (gpu/model_runner.py)

The project's own design notes are in docs/design/. arch_overview.md, prefix_caching.md, cuda_graphs.md and model_runner_v2.md are worth reading alongside this track.

#The processes

vLLM V1 serves with several cooperating processes. For one node and vllm serve --tensor-parallel-size 4, that is six: one API server, one engine core and four GPU workers.

flowchart LR
  C[Client] -->|HTTP, SSE| API
  subgraph API[API server process]
    H[OpenAI handlers] --> AL[AsyncLLM<br/>tokenise, render]
    OP[Output processor<br/>detokenise, stop strings]
  end
  AL -->|ZMQ, msgpack<br/>EngineCoreRequest| EC
  subgraph EC[Engine core process]
    BL[Busy loop] --> S[Scheduler]
    S --> KV[KV cache manager]
    BL --> EX[Executor]
  end
  EX --> W0[GPU worker 0<br/>model runner]
  EX --> W1[GPU worker 1]
  EX --> W2[GPU worker 2]
  EX --> W3[GPU worker 3]
  EC -->|ZMQ<br/>EngineCoreOutputs| OP
  OP -->|tokens| H
  • API server. Handles HTTP, applies the chat template and tokenises (through a renderer), and streams results back. It holds an AsyncLLM (vllm/v1/engine/async_llm.py) and, through it, an AsyncMPClient (core_client.py) that sends requests over ZMQ sockets, encoded with msgpack.
  • Engine core. One per data-parallel rank. It runs a busy loop (EngineCoreProc.run_busy_loop in core.py) that reads new requests, takes one engine step, and sends the outputs back.
  • GPU workers. One per GPU. Each loads its shard of the weights, owns its share of the KV cache tensors and runs the forward pass. With one GPU, the executor is UniProcExecutor and the worker runs inside the engine core process; with more, MultiprocExecutor starts a process per GPU (vllm/v1/executor/).

This split exists for speed. Tokenising, detokenising and checking stop strings are Python work on the CPU. If they ran in the same loop as the scheduler, every slow piece of text processing would delay the next GPU step.

Inside every inference engine
Animated
request→API server→Scheduler→KV cache manager→Model runner→Kernels→Sampler and detokeniser→tokens

API server

OpenAI-compatible HTTP, tokenisation, chat templates. Separate processes in modern engines.

Every engine has these parts. They differ in how each is built, and that is where real performance gaps come from.

#The engine step

The heart of vLLM is EngineCore.step() in vllm/v1/engine/core.py. Stripped of logging and bookkeeping, it is:

python
scheduler_output = self.scheduler.schedule()
future = self.model_executor.execute_model(scheduler_output, non_block=True)
model_output = future.result()          # or sample_tokens() if sampling is separate
engine_core_outputs = self.scheduler.update_from_output(scheduler_output, model_output)
  1. Schedule. Decide which requests run this step and how many tokens each gets, and allocate KV cache blocks for them. The result, a SchedulerOutput, is a description of the batch.
  2. Execute. The workers update their copy of the batch, build input tensors, run the forward pass and sample.
  3. Update. Append the sampled tokens to each request, check stop conditions, free the blocks of finished requests and produce EngineCoreOutputs for the API server.

With async scheduling (on by default in v0.34.0 when nothing incompatible is configured), the engine core schedules step N+1 while the GPU is still running step N. The loop then uses step_with_batch_queue instead of step, but the three calls are the same. Lesson 2 covers what that does to the scheduler.

#One request, hop by hop

Follow a streaming chat completion. Each row names the file and function at v0.34.0.

# What happens Where
1 The OpenAI chat handler parses the request and builds SamplingParams vllm/entrypoints/openai/chat_completion/
2 AsyncLLM.generate() creates an output collector for the request, then calls add_request() vllm/v1/engine/async_llm.py
3 The renderer applies the chat template and tokenises; the input processor validates the result and builds an EngineCoreRequest vllm/renderers/ and InputProcessor.process_inputs() in vllm/v1/engine/input_processor.py
4 The output processor registers the request, so it can detokenise its tokens later vllm/v1/engine/output_processor.py
5 The client sends the request to the engine core over ZMQ AsyncMPClient.add_request_async() in core_client.py
6 The engine core turns it into a Request (with block hashes for prefix caching) and adds it to the scheduler's waiting queue EngineCore.preprocess_add_request() and Scheduler.add_request()
7 A later schedule() call admits it: prefix-cache lookup, block allocation, a prefill chunk within the token budget Scheduler.schedule() in sched/scheduler.py
8 The worker adds it to its persistent batch, builds inputs, runs the model and samples GPUModelRunner.execute_model() and sample_tokens() in worker/gpu/model_runner.py
9 update_from_output() appends the token and checks stop conditions sched/scheduler.py
10 EngineCoreOutputs go back over ZMQ; a background task in the API server picks them up AsyncLLM._run_output_handler()
11 The output processor detokenises, checks stop strings and pushes a RequestOutput to the request's collector OutputProcessor.process_outputs()
12 generate() yields it, and the handler writes a server-sent event async_llm.py, then the handler

Steps 7 to 11 repeat once per generated token (or per few tokens with speculative decoding) until the request finishes. If a stop string is found in step 11, the API server asks the engine core to abort the request, because only the API server sees the text.

The docstring of AsyncLLM.generate() lists the same four stages in its own words: make a stream for the request, process the input, add it to the detokenizer, add it to the engine core. Read it first; it is the shortest summary of the front end in the code.

#Reading tips

  • Start from EngineCore.step() and read outwards. Almost everything is reached from one of its three calls.
  • Skip what you do not need on the first pass. The scheduler is about 3,900 lines at v0.34.0, and much of it handles features you can ignore at first: KV connectors for disaggregated serving, encoder inputs for multimodal models, Mamba layers, pipeline and data parallelism. Look for the comment # First, schedule the RUNNING requests. and the matching one for waiting requests.
  • Read the tests. tests/v1/core/test_scheduler.py and tests/v1/core/test_prefix_caching.py build a scheduler with a fake KV cache and no model, and show the intended behaviour in a few lines each.
  • Note the version in your notes. When you quote a default or a line number, write the release next to it.

#Exercises

  1. In your checkout, open vllm/v1/engine/core.py and find step() and run_busy_loop(). Write down the three calls in step() and what each returns.
  2. Open vllm/v1/engine/async_llm.py. Find where generate() calls add_request(), and where _run_output_handler() pulls outputs from the engine core. Which object connects the two for one request?
  3. Without running anything, predict how many processes vllm serve starts with --tensor-parallel-size 2 --data-parallel-size 2. Then check your answer against the process table in docs/design/arch_overview.md.

#Check your answers

Show answers

(1) schedule() returns a SchedulerOutput; execute_model() returns a future for the model output (or None, in which case sample_tokens() produces it); update_from_output() returns the EngineCoreOutputs for each client. (2) A per-request output collector: generate() creates it through add_request(), the output processor puts each RequestOutput into it, and generate() reads from it. (3) Four GPU workers, two engine cores (one per data-parallel rank), two API servers (the default count follows the data-parallel size) and one DP coordinator: nine.

#Where to go next

Quick quiz

+10 XP per correct answer, +25 XP for a perfect score

  1. 1. Which process owns the scheduler and the KV cache bookkeeping?

  2. 2. Why does tokenisation run in the API server process and not in the engine core?

  3. 3. A deployment runs vllm serve with tensor parallel size 4 on one node. How many processes does the V1 architecture start?

Up next · 30 min · Pro, first part free

Inside vLLM's scheduler: token budget, chunked prefill and preemption

How vLLM's V1 scheduler at v0.34.0 builds each batch: one rule for prefill and decode alike, a token budget, running requests before waiting ones, chunked prefill and the long-prefill threshold, preemption by recompute, the FCFS and priority policies, and what async scheduling changes. Read the code with a guide and predict the scheduler's choices.

Continue →

Found this useful?

Send it to someone who is learning the same thing.

Share this lesson