vLLM

Learn to run vLLM 0.28.0 in production: serve models from Python and an OpenAI-compatible API, see how its scheduler and paged KV cache work inside, and tune caching, structured output, quantization, and multi-GPU serving with measurements.

  • Beginner → production
  • 13 units · approximately 14 hours
  • v0.28.0 · Reviewed 2026-09-02

Independent educational course. Project names and marks belong to their respective owners; their use does not imply sponsorship or endorsement.

How to work through this course

Before you begin: The free Foundations course or equivalent knowledge of tokens, the KV cache, and batching, plus comfort with Python and a Linux shell. Hands-on steps need an NVIDIA GPU; every lesson also has an exercise that runs on a laptop.

By the end: Deploy a pinned vLLM service, explain where its memory and time go, and choose settings by measured latency, throughput, and quality on your own traffic.

  1. Understand the idea. Read each section in order and study its diagrams. When a pause-and-predict question appears, commit to an answer before you reveal it. Look up unfamiliar terms in the glossary below.
  2. Try it yourself. Run the code examples and compare your output with the lesson's. Use the browser labs where available; steps that need a GPU are optional and say so.
  3. Check your understanding. Answer the knowledge check at the end of each lesson and make sure you can say why the other options are wrong. Complete all units to unlock the final quiz; the passing score is 80%.

The optional project brings the lessons together. Keep notes on your choices, results, and any failures so you can explain what you learned.

Course orientation

What is vLLM?

vLLM is an open-source inference engine for large language models. It loads a model's weights onto one or more GPUs, accepts requests from Python or an OpenAI-compatible HTTP server, decides which requests run at every step, keeps each request's KV cache in fixed-size blocks, and streams the generated tokens back.

The problem it solves

Serving many users from one GPU is mostly a scheduling and memory problem. Requests arrive at random, prompts range from ten tokens to a hundred thousand, and answers finish at different times. Batching whole requests together leaves the GPU idle while it waits for the longest one, and reserving cache space for the longest possible answer wastes most of the memory. vLLM schedules work one step at a time and hands out cache memory in small blocks as each request grows.

Request path

  1. 01API server and Python entry points

    `vllm serve` exposes OpenAI-compatible endpoints such as `/v1/chat/completions`, and the `LLM` class runs batches in Python. Both render chat templates, tokenize prompts, and validate sampling settings.

  2. 02Engine core and scheduler

    At every step the scheduler picks which waiting and running requests get tokens, within a per-step token budget and a limit on concurrent sequences, and splits long prompts into chunks.

  3. 03KV cache manager

    GPU memory left after the weights becomes a pool of cache blocks of 16 tokens each. A block table maps each request's positions to blocks, and requests that share a prefix can share blocks.

  4. 04Model runner and workers

    One worker per GPU runs the forward pass with optimized attention kernels, compiled graphs, and CUDA graphs, then samples the next token for every request in the batch.

  5. 05Output processing

    Detokenization, stop checks, streaming, and metrics turn sampled token IDs into responses, and free a request's blocks when it finishes or is cancelled.

What it covers

  • Scheduling and batching requests on the GPUs of one server, including preemption when the KV cache runs out.
  • Managing KV cache memory: paging, prefix caching, and lower-precision cache formats.
  • Running the model fast: compiled graphs, quantized weights, speculative decoding, and tensor, pipeline, data, and expert parallelism.
  • Serving the OpenAI-compatible API, structured output, tool-call parsing, and Prometheus metrics.

Outside its scope

  • Training or fine-tuning models. vLLM serves weights that already exist, including LoRA adapters trained elsewhere.
  • Routing across a fleet of servers, autoscaling, and cache-aware load balancing. Systems such as NVIDIA Dynamo sit above vLLM for that.
  • Production access control. `--api-key` protects only part of the API, so authentication, rate limits, and logging belong in a gateway in front of it.
  • Guaranteed support for every model and GPU. Features depend on the model architecture, the hardware, and the release you pin.
Key terms in this course
PagedAttention
vLLM's attention scheme that reads the KV cache from fixed-size blocks through a block table, so a request's cache need not be contiguous.
KV block
A fixed-size slice of the KV cache, 16 token positions by default in vLLM 0.28.0.
Block table
A per-request list that maps logical cache positions to physical blocks in GPU memory.
Continuous batching
Scheduling at every model step, so finished requests leave and waiting ones join without waiting for the whole batch.
Token budget
The most tokens the scheduler may process in one step, set by `--max-num-batched-tokens`.
Chunked prefill
Splitting a long prompt across several steps so it shares each step with running decodes.
Prefix caching
Reusing cached blocks when a new request starts with exactly the same tokens as an earlier one.
Preemption
Pausing a running request and freeing its cache blocks when memory runs out, then recomputing it later.
Speculative decoding
Proposing several tokens cheaply and checking them all in one pass of the full model.
TTFT and TPOT
Time to first token and time per output token: the two latencies users feel most.
Goodput
Requests per second that meet every latency target, the measure used to choose a configuration.

Syllabus

  1. 02Offline inference with the Python API75 minProOpenCreate one LLM instance, run a whole dataset through a single generate call, and explain why that beats a loop of single-prompt calls.
  2. 03The OpenAI-compatible server: endpoints, streaming, and security60 minProOpenPick the vLLM 0.28.0 endpoint that matches a task, and predict which endpoints a given model exposes.
  3. 04Inside the vLLM engine: processes, the core loop, and request states60 minProOpenName the processes a vLLM 0.28.0 server runs and say which one tokenizes, schedules, executes the model, and detokenizes.
  4. 05Compilation, CUDA graphs, and GPU execution65 minProOpenExplain what torch.compile and CUDA graph replay each remove from a decode step, and why small models gain the most.
  5. 06PagedAttention and the KV block pool60 minLabProOpenMap any token position to its logical block, offset, and physical block through a block table.
  6. 07Continuous batching, the token budget, and chunked prefill60 minProOpenExplain why iteration-level batching keeps more requests running than static batching, and count the steps each needs for a set of requests.
  7. 08Prefix caching and speculative decoding65 minProOpenPredict how many prompt tokens a request will reuse from vLLM's prefix cache, block by block, and explain why one changed early token breaks the rest.
  8. 09Structured outputs, reasoning parsers, and tool calling70 minProOpenConstrain vLLM 0.28.0 output with a JSON schema, regex, grammar, or choice list, and explain how the constraint masks the next-token choices.
  9. 10Model tasks, images, and LoRA adapters70 minProOpenTell from a model's architecture and startup log which runner, tasks, and endpoints a vLLM server offers, and pick the matching endpoint.
  10. 11Memory, precision, and quantization70 minProOpenBreak a vLLM process's GPU memory into weights, activation peak, CUDA graphs, other buffers, and KV cache, and predict the KV cache size from them.
  11. 12Tensor, pipeline, data, and expert parallelism75 minProOpenExplain what tensor, pipeline, data, and expert parallelism each split across GPUs, and what data each one sends between them.
  12. 13Benchmark and operate vLLM75 minProOpenDesign a benchmark workload that matches production traffic, and record everything needed to repeat it.
Full unit-by-unit learning objectives (58 outcomes)

01 · What is vLLM?

  • Describe what vLLM does for a model and what it leaves to the model, the hardware, and the rest of your platform.
  • Trace one request through the API server, the engine core's scheduler and KV cache manager, and the GPU worker, and say which process runs each part.
  • Explain, with numbers, how iteration-level scheduling and paged KV memory beat a plain batched generate loop.
  • Start a server, send a first request, and confirm from the logs, the health check, the model list, and the finish reason that it really worked.
  • Choose between the offline LLM class and the online server for a given job.

02 · Offline inference with the Python API

  • Create one LLM instance, run a whole dataset through a single generate call, and explain why that beats a loop of single-prompt calls.
  • Write SamplingParams that say exactly what you mean, knowing vLLM 0.28.0's defaults, including max_tokens of 16.
  • Read a RequestOutput: its request ID, prompt tokens, candidates, text, finish_reason, and stop_reason.
  • Run chat conversations through LLM.chat and pooling models through embed, classify, and score.
  • Release the GPU cleanly when a job ends, and choose AsyncLLM when you need streaming or cancellation.

03 · The OpenAI-compatible server: endpoints, streaming, and security

  • Pick the vLLM 0.28.0 endpoint that matches a task, and predict which endpoints a given model exposes.
  • Show exactly which tokens and sampling settings a chat request will use, including defaults taken from the model's generation_config.json.
  • Read a streamed response from its first event to data: [DONE], and tell a complete answer from a truncated, failed, or cut-off one.
  • Explain what happens inside vLLM when a client disconnects, and check that the request's memory was released.
  • Decide which controls belong in a gateway, and list the endpoints that --api-key does not protect.

04 · Inside the vLLM engine: processes, the core loop, and request states

  • Name the processes a vLLM 0.28.0 server runs and say which one tokenizes, schedules, executes the model, and detokenizes.
  • Trace one engine iteration from scheduling through sampling and output, and predict how a token budget splits a long prompt into chunks.
  • Follow a request through the waiting, running, preempted, and finished states, including what happens when a client disconnects.
  • Simulate the scheduler on a laptop and read the matching queue, cache, and preemption metrics on a real server.

05 · Compilation, CUDA graphs, and GPU execution

  • Explain what torch.compile and CUDA graph replay each remove from a decode step, and why small models gain the most.
  • Choose `--compilation-config` settings (`mode` and `cudagraph_mode`) for a workload and predict which batches will replay a graph, pad, or run without one.
  • Read vLLM's startup log to separate weight loading, compilation, and graph capture time, and find how much memory the graphs took.
  • Run a controlled comparison that changes one execution setting at a time, and keep a working eager configuration to fall back to.

06 · PagedAttention and the KV block pool

  • Map any token position to its logical block, offset, and physical block through a block table.
  • Count the blocks a request needs and calculate the memory lost to partly filled blocks.
  • Explain how reference counts and copy-on-write let requests share KV blocks safely, and what vLLM 0.28.0 shares.
  • Work out how many KV blocks vLLM will allocate at startup from GPU memory, weights, and the profiled overhead, and check the result against the startup log.

07 · Continuous batching, the token budget, and chunked prefill

  • Explain why iteration-level batching keeps more requests running than static batching, and count the steps each needs for a set of requests.
  • Predict how vLLM 0.28.0 fills one engine step from `--max-num-batched-tokens` and `--max-num-seqs`, including their defaults on your GPU.
  • Choose a token budget by trading inter-token latency for time to first token, using chunked prefill.
  • Recognize preemption, explain what it costs, and pick the setting that stops it.

08 · Prefix caching and speculative decoding

  • Predict how many prompt tokens a request will reuse from vLLM's prefix cache, block by block, and explain why one changed early token breaks the rest.
  • Calculate the expected tokens per step and the speedup of speculative decoding from an acceptance rate, a draft length, and a draft cost.
  • Configure prefix caching and a speculative method in vLLM 0.28.0 and read their counters and log lines.
  • Decide which of the two a workload needs by measuring whether its time goes to repeated prefill or to serial decode.

09 · Structured outputs, reasoning parsers, and tool calling

  • Constrain vLLM 0.28.0 output with a JSON schema, regex, grammar, or choice list, and explain how the constraint masks the next-token choices.
  • Say exactly what a constraint guarantees and what it does not, including what happens when output stops at max_tokens.
  • Match a model to its chat template, tool-call parser, and reasoning parser, and configure the server flags that enable them.
  • Rebuild streamed tool calls from their fragments and reject streams that are incomplete or malformed.
  • Place validation and authorization at the two trust boundaries of a tool loop.

10 · Model tasks, images, and LoRA adapters

  • Tell from a model's architecture and startup log which runner, tasks, and endpoints a vLLM server offers, and pick the matching endpoint.
  • Calculate how many tokens and how much KV cache an image costs for a Qwen-VL model, and cap that cost with vLLM 0.28.0 settings.
  • Size the GPU memory that `--max-loras` and `--max-lora-rank` reserve, and predict when a request for an adapter has to wait.
  • Read embedding, classification, and score responses correctly: dimensions, normalization, label order, and what a score does and does not mean.

11 · Memory, precision, and quantization

  • Break a vLLM process's GPU memory into weights, activation peak, CUDA graphs, other buffers, and KV cache, and predict the KV cache size from them.
  • Choose a weight quantization method and a KV cache dtype that vLLM 0.28.0 supports, and calculate what each saves.
  • Explain why a lower-bit checkpoint can fail to lower time per output token, using bytes read, arithmetic intensity, and kernel support.
  • Pick an offloading option and estimate what its transfers cost per step.
  • Validate a precision or offload change for quality, latency, and capacity before it reaches production.

12 · Tensor, pipeline, data, and expert parallelism

  • Explain what tensor, pipeline, data, and expert parallelism each split across GPUs, and what data each one sends between them.
  • Calculate weight and KV cache memory per GPU for Llama 3.1 70B under different layouts, and decide whether a layout fits.
  • Estimate how much communication tensor parallelism adds per forward pass and when the interconnect makes it too expensive.
  • Choose tensor, pipeline, and data-parallel sizes for a model, a GPU count, and a traffic target, and check the choice with vLLM's startup log and a benchmark.

13 · Benchmark and operate vLLM

  • Design a benchmark workload that matches production traffic, and record everything needed to repeat it.
  • Run `vllm bench serve` at several request rates and read TTFT, TPOT, ITL, throughput, and goodput together.
  • Find the saturation point on a load curve and choose an operating capacity with headroom below it.
  • Compute latency percentiles and goodput yourself from a saved per-request result file.
  • Monitor a running server with the `vllm:` Prometheus metrics and work through a production readiness checklist.

Optional field project

Launch and tune a support-assistant API on vLLM

  1. 01Stand up a baseline you can reproduce
  2. 02Measure memory, scheduling, and reuse
  3. 03Add structured output, tools, adapters, and a cheaper precision
  4. 04Find capacity and prepare for production
View optional project brief

Sign in to read the project brief.

Free guides and tools