← All posts

Maximising LLM Inference Throughput with vLLM

Serving an LLM is mostly a memory problem, not an arithmetic one. Each request carries a key-value (KV) cache that grows with every token, and how that cache is stored decides how many requests fit on a GPU at once. vLLM is an open-source serving engine built around that observation.

It is written against vLLM 0.34.0, the release on PyPI since 16 November 2026.

In short

  • Decoding reads all the weights and the whole KV cache for every token, so throughput depends on how many requests stay resident in GPU memory.
  • PagedAttention stores the KV cache in fixed-size blocks, and continuous batching schedules per iteration; the authors report 2 to 4 times higher throughput than FasterTransformer and Orca at the same latency.
  • Those gains appear under concurrent load; a single user sending one request at a time sees little from paging.
  • Benchmark with a stated latency target, a fixed workload and restarts between runs, because prefix caching can inflate repeated runs.

Is vLLM a good fit?

WorkloadWhat helps or what to check
Many concurrent usersGood fit. Paged memory and continuous batching raise the number of resident requests.
Long shared prompts or documentsEnable prefix caching; it reuses only a shared leading run of full blocks.
One user, one request at a timeLittle gain from paging. Measure time to first token and time per output token before adopting.
Small model on a laptopThe quickstart lists Linux; for Apple Silicon the docs point to the separate vLLM-Metal project.
Model too large for one GPUTensor parallelism on one node, pipeline parallelism across nodes or on GPUs without NVLink.
Offline batch jobsThe LLM class schedules prompts together; judge it by tokens per second.
Several different models at onceOne server hosts one base model (LoRA adapters on that model aside), so plan one server per model.

Why decoding is memory-bound

Generation is sequential. The model produces one token, appends it, and runs again. The PagedAttention paper points out that iterations cannot be parallelised across tokens and that the work often reduces to matrix-vector products, which makes the phase memory-bound and leaves compute underused. Every step reads all the weights and the whole KV cache from GPU memory to produce one token, so time per step is set by memory traffic, not FLOPs.

Batching fixes the idle GPU, because one read of the weights serves many requests, but batch size is capped by how many KV caches fit in memory. The paper's Figure 1 shows a 13B-parameter model on a 40 GB A100 with roughly 65% of memory taken by weights and close to 30% by KV cache. To a first approximation, throughput is the number of requests you can keep resident.

How big the KV cache is

For each token, each layer stores one key vector and one value vector per KV head. The size per token is:

bytes per token = 2 x layers x KV heads x head dim x bytes per value
KV cache        = bytes per token x tokens held

The paper gives a worked case for OPT-13B: 2 x 5120 (hidden size) x 40 layers x 2 bytes (FP16) = 800 KB per token, or up to 1.6 GB for a 2048-token request.

Modern models usually use grouped-query attention, which shrinks the cache by sharing KV heads. Take Qwen2.5-7B-Instruct. Its published config has 28 layers, 28 attention heads, 4 KV heads, hidden size 3584 and bfloat16 weights. The config has no explicit head dimension, so I derive it as 3584 / 28 = 128. Then:

2 x 28 x 4 x 128 x 2 bytes = 57,344 bytes = 56 KiB per token
56 KiB x 4,096 tokens      = 224 MiB per request
56 KiB x 32,768 tokens     = 1.75 GiB per request
                             (max_position_embeddings)

With all 28 heads stored as KV heads the same model would need 7 times more, 392 KiB per token. Check the config of the model you serve; quantised KV caches change the byte count.

As a capacity estimate, take an 80 GB card with vLLM allowed 90 per cent of memory (illustrative). The model card gives 7.61B parameters, so the weights take about 7.61 x 2 = 15.2 GB in bfloat16. That leaves at most 72 - 15.2 = 56.8 GB for the KV cache, which at 57,344 bytes per token is about 990,000 tokens, or roughly 495 requests of 2,000 tokens. It is an upper bound: activations, CUDA graphs and other overheads take part of that memory, so the startup log gives the real figure.

Where the memory goes: fragmentation

Early serving systems stored each request's KV cache in one contiguous region sized for the maximum output length. The paper names three kinds of waste:

  • Reservation. Slots held for tokens not yet generated; they sit idle until used.
  • Internal fragmentation. Slots reserved for a length the request never reaches.
  • External fragmentation. Gaps between allocations that are too small to reuse, which arise because reservations differ in size.

In the paper's profiling, only 20.4% to 38.2% of KV cache memory held actual token states in the existing systems it compared against. The figures come from the paper's workload and its own Orca implementations (three variants, since Orca was not publicly available), so they are not a general constant.

PagedAttention and block tables

PagedAttention borrows from operating-system virtual memory. The KV cache is cut into fixed-size blocks, 16 tokens by default in vLLM (the paper found 16 large enough to use the GPU efficiently, and on ShareGPT blocks of 16 to 128 performed best). A request sees a list of logical blocks, and a per-request block table maps each to a physical block anywhere in GPU memory. Blocks are allocated as tokens arrive, so waste per request is bounded by one partly filled block.

Logical KV blocks of one request mapped through a block table to non-contiguous physical blocks Logical blocks Block table Physical blocks Block 0 (full) Block 1 (full) Block 2 (partly full) 0 maps to 7 1 maps to 2 2 maps to 5 Physical 7 Physical 2 Physical 5 Physical numbers are arbitrary: blocks need not be adjacent or ordered
Figure 1. One request's logical KV blocks, its block table, and the physical blocks they point to. Only the last block can hold unused slots.

The cost is that attention kernels must follow the block table to gather keys and values instead of reading one contiguous array. The paper implements a custom kernel for this and reports 20% to 26% higher attention kernel latency than the optimised FasterTransformer kernel, which it argues is small because attention is only part of the model's work. Large blocks hurt when sequences are shorter than the block.

Sharing and copy-on-write

Blocks are reference-counted, so requests can share them. With parallel sampling (several outputs from one prompt) the prompt blocks are stored once. When a sample must write into a shared block, vLLM allocates a new block, copies the contents and decrements the old block's count. The paper measures the memory saved by sharing at 6.1% to 9.8% for parallel sampling and 37.6% to 55.2% for beam search on the Alpaca dataset (16.2% to 30.5% and 44.3% to 66.3% on ShareGPT).

Continuous batching

Classic static batching holds a batch until its slowest request finishes. Orca (OSDI 2022) schedules at the granularity of one model iteration instead of one request, so finished requests leave and new ones join after every step. The Orca abstract reports a 36.9 times throughput improvement over NVIDIA FasterTransformer at the same latency, on a GPT-3 175B model.

vLLM combines this scheduling with paged memory. In the paper's ShareGPT experiments (OPT-13B, 66B and 175B), vLLM sustained 1.7 to 2.7 times higher request rates than the Orca (Oracle) variant and 2.7 to 8 times higher than Orca (Max), at similar latency. The abstract's headline is 2 to 4 times higher throughput than FasterTransformer and Orca at the same latency, larger for longer sequences, larger models and more complex decoding. These are the authors' 2023 benchmarks, not reproduced here, and they do not predict your gain on a different model, GPU or traffic mix.

Other features worth knowing

  • Prefix caching. The KV blocks of earlier prompts are kept and reused when a new prompt starts with the same tokens. The docs say it reuses only the longest run of full blocks at the start of the prompt, and each block's hash covers all earlier tokens, so a change early in the prompt invalidates everything after it. The engine argument is enable_prefix_caching.
  • Chunked prefill. In the V1 engine it is on by default where possible. Decode requests are batched first, then prompt chunks fill the remaining token budget (max_num_batched_tokens).
  • Speculative decoding. A cheap drafter proposes tokens and the target model verifies them. The docs list several methods (EAGLE, multi-token prediction, a draft model, n-gram and suffix decoding among them), give no speedup figures and say results depend on model, traffic, hardware and sampling. They also state that vLLM does not guarantee stable log probabilities, and outputs can vary with hardware precision and batch size.
  • Quantisation. Supported formats include AWQ, GPTQ, FP8 and INT8 through several tools. Hardware support is uneven: the docs' table lists FP8 W8A8 under LLM Compressor as supported on Ada, Hopper and AMD GPUs but not Volta, Turing or Ampere. Evaluate quality loss on your task.
  • Tensor and pipeline parallelism. Tensor parallelism shards each layer across GPUs and suits a model that fits on one node. Pipeline parallelism splits by layers; the docs suggest it when the GPU count does not divide the model evenly, on GPUs without NVLink, or across nodes. The docs say to add GPUs until the model fits, then read the GPU KV cache size and Maximum concurrency lines in the startup log, and add more only if those fall short.

Key flags and what they trade

Run vllm serve --help for the full list in your version.

FlagEffectTrade-off
--max-model-lenCaps context length per requestLower values leave more room for concurrent requests; longer prompts are rejected
--gpu-memory-utilizationShare of GPU memory vLLM may useThe engine arguments page advises leaving it unset on CUDA and ROCm; the default is 1.0 with the extensible KV cache and 0.92 otherwise
--max-num-seqsLimit on concurrent requests in a batchLower values reduce KV cache demand and preemption, at the cost of batch size
--max-num-batched-tokensToken budget per scheduler stepSmaller favours inter-token latency, larger favours time to first token
--tensor-parallel-sizeGPUs sharding each layerFits larger models and frees memory for KV cache; adds synchronisation
--pipeline-parallel-sizeGPU groups splitting layersSuits uneven GPU counts, GPUs without NVLink and multi-node setups; can add latency
--enable-prefix-cachingReuses KV blocks of shared prefixesGains only when prompts share a leading prefix

When the cache runs out, vLLM preempts requests and recomputes them later (the V1 default is recompute, not swap), which raises end-to-end latency. The docs suggest lowering max_num_seqs or max_num_batched_tokens, or adding parallelism.

To size --max-num-seqs, start from the startup log line GPU KV cache size: N tokens, Maximum concurrency for M tokens per request: X.XXx. X assumes every request uses the full context length M, so it is the worst case. For a typical load, divide N by the prompt plus output tokens of an average request. For example, with N = 400,000 and requests of about 2,000 tokens, roughly 200 requests fit before preemption begins. Set --max-num-seqs at or below that figure, and lower it if latency shows requests being preempted.

Working examples

Both examples follow the quickstart, which installs with uv pip install vllm --torch-backend=auto followed by vllm download-kernels. Start the server, which listens on http://localhost:8000 by default:

vllm serve Qwen/Qwen2.5-1.5B-Instruct --max-model-len 8192

Then call it with the OpenAI Python client. The key is a placeholder because the server was started without --api-key:

from openai import OpenAI

client = OpenAI(api_key="EMPTY", base_url="http://localhost:8000/v1")
reply = client.chat.completions.create(
    model="Qwen/Qwen2.5-1.5B-Instruct",
    messages=[{"role": "user", "content": "What is a KV cache?"}],
    max_tokens=128,
)
print(reply.choices[0].message.content)

For offline batch work, the LLM class schedules a list of prompts together:

from vllm import LLM, SamplingParams

llm = LLM(model="Qwen/Qwen2.5-1.5B-Instruct", max_model_len=8192)
params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=128)
prompts = ["Explain paged memory in one sentence."]
outputs = llm.generate(prompts, params)
print(outputs[0].outputs[0].text)

generate does not apply the chat template, so this sends the raw text to an instruct model. Use llm.chat for chat-formatted input.

Benchmarking

vLLM ships benchmark commands. vllm bench serve drives a running server and reports request throughput, output and total token throughput, and time to first token (TTFT), time per output token (TPOT) and inter-token latency (ITL) in milliseconds. vllm bench throughput runs offline without a server and reports requests and tokens per second. The docs' example uses --dataset-name sharegpt with --num-prompts 10, far too few prompts for a real measurement.

MetricMeaning (per the vLLM docs)Reflects
TTFTTime from sending a request to its first streamed outputInteractive responsiveness, prompt length, queueing
TPOT(end-to-end latency minus TTFT) / (output tokens minus 1), per requestStreaming speed for one user
ITLGaps between consecutive streamed outputs, pooled over requestsStalls and jitter between streamed outputs
ThroughputRequests per second and tokens per secondCost per token at saturation

A bigger batch raises tokens per second and per-token latency, so a throughput number without a latency target is incomplete. Report both at a stated request rate, with mean, median and P99. When comparing configurations or engines, hold fixed:

  • the same model weights, precision and GPU, with versions of every engine recorded;
  • the same dataset or input and output length distributions, with enough prompts;
  • the same sampling settings, including maximum output length and whether outputs are forced to a fixed length;
  • the same request arrival pattern, since closed-loop and fixed-rate traffic stress the scheduler differently;
  • warm-up excluded, and the same prefix-caching setting. The docs warn that repeated runs against one server can reuse prefix-cache entries and inflate throughput; restart the server between runs, vary --seed, or use vllm bench sweep serve, which resets server caches between runs.

Run more than once, and keep the commands with the results.

Limits

The flags and defaults above follow the vLLM 0.34.0 docs, and they change between releases, so check them against the version you install. The post covers one server on one node; for deployment on Kubernetes, see KServe Meets vLLM.

Sources