vLLM and LLM Inference Serving
vLLM is an open-source engine that runs large language model inference on GPUs and serves the results through an OpenAI-compatible API. It exists to make LLM serving fast and cheap by cutting the memory wasted on the key-value cache, so more requests fit on one GPU.
itArtificial intelligence and machine learning | OpenSkills.info
Intro
vLLM and LLM Inference Serving
vLLM is an open-source inference and serving engine for large language models. It runs a model on GPU (and other accelerators), accepts generation requests, and returns text, embeddings, or structured outputs through an OpenAI-compatible HTTP API. The project began in the Sky Computing Lab at UC Berkeley and introduced PagedAttention, the technique that made high-throughput LLM serving practical. This course covers what vLLM is, how it works inside, how it scales, and when it is the right tool for serving an LLM.
Why LLM serving is a distinct problem
A trained LLM is a large set of weights. Inference takes a sequence of input tokens and produces output tokens one at a time. Each generated token depends on the previous tokens, so generation is iterative: one forward pass of the model per token. This iteration is what makes LLM serving unlike serving a classifier or a regressor.
Two properties dominate the design space. First, token generation is memory-IO bound, not compute bound. Loading the model weights and the per-request attention state from GPU memory takes longer than the math that produces the next token. Throughput is therefore governed by how large a batch fits in GPU memory, not by peak FLOPs. Second, each request holds per-token state — the key-value (KV) cache — that grows with sequence length. A 13B parameter model consumes roughly 1 MB of GPU memory per token of sequence state. On an A100 with 40 GB, after loading the 26 GB of weights, only about 14 thousand tokens of KV state fit at once. That ceiling caps the batch size and therefore the throughput.
The job of an LLM serving engine is to use that scarce GPU memory efficiently — to keep the GPU busy with useful work, to fit as many concurrent requests as possible, and to do it without exploding latency.
How naive batching fails LLMs
The simplest approach is static batching: collect N requests, run them as a batch, and finish the batch when every request emits its end-of-sequence token. The problem is that requests finish at different times. In a chat workload, one prompt may produce two tokens and another two hundred. Once the short request finishes, its slot in the batch sits idle until the longest request in the batch completes. The longer the variance in output length, the more GPU cycles are wasted on finished requests. With variable prompts and variable outputs, static batching leaves the GPU underutilized most of the time.
A second problem is memory reservation. A serving system that pre-allocates a contiguous buffer for each request's KV cache, sized for the maximum possible sequence length, reserves memory the request will likely never use. Most sequences end well before the maximum length. The reserved-but-unused space cannot serve another request, so effective batch size shrinks and throughput drops.
Continuous batching
Continuous batching (also called iteration-level or dynamic batching) addresses the first problem. Instead of holding the batch fixed for the lifetime of its members, the scheduler re-evaluates the batch at every decode iteration. When a request finishes, the scheduler drops it and admits a waiting request into the freed slot on the next iteration. The GPU never waits for the slowest request in a batch to finish before starting new work.
Continue the course
This section is part of the paid course.
See pricing to subscribe, or log in if you already have access.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://docs.vllm.ai/en/latest/
Supports
- vLLM is a fast and easy-to-use library for LLM inference and serving.
- https://docs.vllm.ai/en/latest/
Supports
- vLLM is fast with PagedAttention, continuous batching of incoming requests, chunked prefill, prefix caching, CUDA/HIP graphs, and a wide range of quantization formats (FP8, MXFP8/MXFP4, NVFP4, INT8, INT4, GPTQ/AWQ, GGUF, compressed-tensors, ModelOpt, TorchAO).
- https://docs.vllm.ai/en/latest/
Supports
- vLLM seamlessly supports 200+ model architectures on HuggingFace, including decoder-only LLMs, Mixture-of-Expert LLMs, hybrid attention and state-space models, multi-modal models, and embedding and retrieval models.
- https://docs.vllm.ai/en/latest/
Supports
- vLLM supports NVIDIA GPUs, AMD GPUs, and x86/ARM/PowerPC CPUs, with hardware plugins for Google TPUs, Intel Gaudi, IBM Spyre, Huawei Ascend, Apple Silicon, and others.
- https://docs.vllm.ai/en/latest/
Supports
- vLLM was originally developed in the Sky Computing Lab at UC Berkeley and has grown into one of the most active open-source AI projects with contributors from over 2000 contributors.
- https://blog.vllm.ai/2023/06/20/vllm.html
Supports
- PagedAttention takes inspiration from traditional OS concepts such as paging and virtual memory, allowing the KV cache to be non-contiguous by allocating memory in fixed-size pages (blocks), limiting wastage to under 4% in the last block.
- https://arxiv.org/abs/2309.06180
Supports
- The vLLM paper is Efficient Memory Management for Large Language Model Serving with PagedAttention, Kwon et al., SOSP 2023.
- https://docs.vllm.ai/en/latest/design/arch_overview/
Supports
- vLLM V1 uses a multi-process architecture: an API server process (ZMQ to engine cores), an engine core process per data-parallel rank running the scheduler and KV cache management, one GPU worker process per GPU, and a conditional DP coordinator process.
- https://docs.vllm.ai/en/latest/design/arch_overview/
Supports
- A single-node deployment with 4 GPUs (vllm serve --tensor-parallel-size 4) has 1 API server, 1 engine core, and 4 GPU workers = 6 processes total.
- https://docs.vllm.ai/en/latest/design/arch_overview/
Supports
- By default there is 1 API server process; under data parallelism the API server count scales to match the data parallel size, configurable with --api-server-count. Each API server connects to all engine cores via ZMQ in a many-to-many topology.
- https://docs.vllm.ai/en/latest/getting_started/quickstart/
Supports
- vllm serve <model> starts the OpenAI-compatible server at http://localhost:8000 by default, implementing list models, create chat completion, and create completion endpoints.
- https://docs.vllm.ai/en/latest/getting_started/quickstart/
Supports
- By default the server applies generation_config.json from the Hugging Face model repository if it exists; pass --generation-config vllm to use vLLM defaults instead.
- https://docs.vllm.ai/en/latest/getting_started/quickstart/
Supports
- The --api-key flag or VLLM_API_KEY environment variable enable API key checking in the header; multiple keys can be passed for key rotation.
- https://docs.vllm.ai/en/latest/getting_started/quickstart/
Supports
- vLLM supports multiple attention backends, selected automatically or via --attention-backend; on NVIDIA CUDA these include FLASH_ATTN and FLASHINFER, on AMD ROCm TRITON_ATTN, ROCM_ATTN, and variants.
- https://docs.vllm.ai/en/latest/getting_started/quickstart/
Supports
- The LLM class provides the primary Python interface for offline inference; SamplingParams specifies sampling parameters; llm.generate adds prompts to the engine's waiting queue and executes with high throughput.
- https://www.anyscale.com/blog/continuous-batching-llm-inference
Supports
- LLM inference is memory-IO bound, not compute bound; it takes more time to load 1MB of data to the GPU's compute cores than for those cores to perform LLM computations on 1MB of data, so throughput is largely determined by how large a batch fits in high-bandwidth GPU memory.
- https://www.anyscale.com/blog/continuous-batching-llm-inference
Supports
- A 13B parameter model consumes nearly 1MB of state for each token in a sequence; on an A100 with 40GB RAM, after storing 26GB of model parameters, about 14k tokens can be held in memory at once, capping the batch size for a given max sequence length.
- https://www.anyscale.com/blog/continuous-batching-llm-inference
Supports
- Continuous batching (also called dynamic batching or iteration-level scheduling) implements iteration-level scheduling where the batch size is determined per iteration; once a sequence completes, a new sequence can be inserted in its place, yielding higher GPU utilization. This was described in the Orca paper (OSDI 2022).
- https://www.anyscale.com/blog/continuous-batching-llm-inference
Supports
- Continuous batching frameworks manage the prefill vs decode mix via hyperparameters such as waiting_served_ratio, the ratio of requests waiting for prefill to those waiting for end-of-sequence tokens.
- https://www.anyscale.com/blog/continuous-batching-llm-inference
Supports
- The prefill phase pre-computes inputs of the attention mechanism that remain constant over the lifetime of the generation, and efficiently uses the GPU's parallel compute because these inputs can be computed independently.
- https://docs.vllm.ai/en/latest/serving/parallelism_scaling/
Supports
- vLLM's distributed inference includes Megatron-LM's tensor parallel algorithm; the default distributed runtimes are Ray for multi-node and native Python multiprocessing for single-node, overridable with --distributed-executor-backend mp|ray.
- https://docs.vllm.ai/en/latest/serving/parallelism_scaling/
Supports
- Guidelines for choosing a distributed inference strategy: single GPU if the model fits; single-node multi-GPU tensor parallelism if the model is too large for one GPU but fits on one node; multi-node combining tensor parallel (per node) with pipeline parallel (per node count) if the model is too large for one node.
- https://docs.vllm.ai/en/latest/serving/parallelism_scaling/
Supports
- vLLM supports Data Parallel attention with Expert or Tensor Parallel MoE layers for large-scale Mixture-of-Experts deployment.
- https://docs.vllm.ai/en/latest/serving/parallelism_scaling/
Supports
- At startup vLLM logs GPU KV cache size (total tokens the cache can hold) and Maximum concurrency for a given tokens-per-request estimate taken from ModelConfig.max_model_len; use these to size the deployment.
- https://docs.vllm.ai/en/latest/serving/parallelism_scaling/
Supports
- For multi-node deployment, every node must provide an identical execution environment including model path and Python packages; container images are recommended. Tensor parallel size is set to GPUs per node and pipeline parallel size to the number of nodes.
- https://docs.vllm.ai/en/latest/serving/parallelism_scaling/
Supports
- GPUDirect RDMA allows network adapters to directly access GPU memory, bypassing CPU and system memory, reducing latency and CPU overhead for large cross-node data transfers; enable with IPC_LOCK capability and /dev/shm shared memory.
- https://docs.vllm.ai/en/latest/design/arch_overview/
Supports
- vLLM models' constructor signature is uniform: def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):, enabling sharding and quantization at initialization so each layer only creates the shard it needs and a 405B model can be served across many 80GB GPUs.
- https://docs.vllm.ai/en/latest/
Supports
- vLLM supports speculative decoding including n-gram, suffix, EAGLE, and DFlash drafters, and multi-token-prediction (MTP) modules.
- https://docs.vllm.ai/en/latest/
Supports
- vLLM's server implements the OpenAI-compatible API server plus the Anthropic Messages API and gRPC support, with structured outputs using xgrammar or guidance, tool calling, and reasoning parsers.
- https://github.com/Hannibal046/awesome-llm
Supports
- The Awesome-LLM list's LLM Inference section catalogs serving engines including vLLM, SGLang, llama.cpp, ollama, Text-Generation-Inference (TGI), TensorRT-LLM, DeepSpeed-MII, and LMDeploy.
- https://www.digitalocean.com/community/tutorials/digitalocean-s-technical-writing-guidelines
Supports
- The DigitalOcean Technical Writing Guidelines govern the writing style of learner-facing content; they are not added to sources.yaml because they govern style rather than course facts.
