Illustrated title card for the guide: vLLM VRAM and KV Cache Calculator
gpu-memory

vLLM VRAM and KV Cache Calculator

Estimate VRAM and KV cache for vLLM, choose a GPU memory budget and context limit, then verify full-length request capacity in the startup log.

Set --max-model-len to the largest prompt-plus-output budget your workload needs. On CUDA and ROCm with vLLM 0.34.0’s extensible KV cache active, leave --gpu-memory-utilization unset unless you need to reserve VRAM for allocations vLLM does not measure. Estimate the cache needed for your target concurrency, then compare it with the capacity vLLM reports at startup. Serve CLI · Memory tuning · Startup logs

Choose the context limit and memory budget

SettingHow to size it
--max-model-lenAdd the maximum prompt and output token budgets for one request. An omitted value comes from the model config. Pass auto to use the model’s maximum context length if it fits in GPU memory. Otherwise, vLLM chooses the largest length that fits. Serve CLI
--gpu-memory-utilizationThis limits the fraction of GPU memory the instance’s model executor can use. On CUDA and ROCm with the extensible cache active, vLLM sizes the cache from the memory free after CUDA graph capture and warmup. If the flag is omitted in this mode, the utilization fraction defaults to 1.0. In this mode, set a lower fraction only to reserve memory for allocations vLLM does not measure, such as another process allocating GPU memory after startup. If the flag is omitted with estimate-based sizing, the utilization fraction defaults to 0.92. Serve CLI · Memory tuning
--kv-cache-memory-bytesAn explicit value sets the KV cache size in bytes per GPU. vLLM ignores --gpu-memory-utilization when this value is set. Leave it unset for the workflow below. Serve CLI

Calculate KV cache and total VRAM

Use this worksheet for one GPU with uniform full attention, equal key and value head sizes, and a dense, unpadded, unquantized KV cache. Assume one cache slot per KV head, one stored state per token and separate cache blocks for each request. The block rounding follows vLLM’s full-attention cache calculation. KV cache interface

KV bytes per token = 2 × layers × KV heads × head size × bytes per value
Blocks per request = round_up((prompt tokens + output tokens) / block size)
KV bytes per request = blocks per request × block size × KV bytes per token
Target KV bytes = KV bytes per request × concurrent requests

Estimate unquantized weight bytes as parameter count times bytes per weight. Add a budget for activations, graph capture and other runtime allocations. With an explicit utilization fraction, subtract weights and that runtime budget from total VRAM times the fraction to estimate the room for KV cache. Use the startup log to check the estimate against the initialized engine. Serve CLI · Memory tuning · Startup logs

Worked example on one GPU

Qwen lists 1.54 billion parameters, 28 layers and two KV heads for Qwen2.5-1.5B-Instruct. Its head size is 1,536 ÷ 12 = 128 in vLLM’s Qwen2 implementation. PyTorch lists BF16 as a 16-bit type, so count two bytes per value. Qwen model card · Qwen configuration · vLLM Qwen2 implementation · PyTorch data types

Assume 8 GiB of total VRAM, a 0.80 utilization cap, and 1.50 GiB budgeted for runtime allocations outside the weights and cache. Target eight concurrent requests, each with up to 6,144 prompt tokens and 2,048 output tokens. For the worksheet, use BF16 for weights and cache and assume an illustrative block size of 64 tokens. The table shows planning arithmetic. Serve CLI · Memory tuning · KV cache interface

QuantityCalculation
Context limit6,144 + 2,048 = 8,192 tokens
BF16 weights1.54 billion × 2 bytes ≈ 2.87 GiB
KV per token2 × 28 × 2 × 128 × 2 = 28,672 bytes
KV per full-length request128 blocks × 64 tokens × 28,672 bytes = 224 MiB
KV for eight requests8 × 224 MiB = 1.75 GiB
Estimated room for KV(8 GiB × 0.80) − 2.87 GiB − 1.50 GiB ≈ 2.03 GiB

The target adds up to about 6.12 GiB for weights, runtime and cache, or 76.5% of the assumed GPU’s VRAM. The example’s 80% cap leaves 1.60 GiB outside vLLM’s budget.

Start vLLM and check the cache logs

Start the example with the host set to 127.0.0.1. On a dedicated CUDA or ROCm GPU with the extensible cache active and no extra headroom requirement, omit the utilization flag. Qwen model card · Serve CLI · Memory tuning

vllm serve Qwen/Qwen2.5-1.5B-Instruct \
  --host 127.0.0.1 \
  --dtype bfloat16 \
  --kv-cache-dtype auto \
  --max-model-len 8192 \
  --gpu-memory-utilization 0.80
  • GPU KV cache size reports how many tokens the GPU KV cache can hold at once. With separate blocks for each request, the example needs 8 × 8,192 = 65,536 cached tokens to hold all eight full-length requests at once. Startup logs
  • Maximum concurrency estimates how many requests can fit in the KV cache at once if each uses the configured maximum sequence length. For example, a reported capacity of 49,152 tokens at an 8,192-token limit would give this workload a cache estimate of six full-length requests. Startup logs · KV cache interface

If capacity is short and your workload allows shorter requests, lower --max-model-len to their combined prompt and output budget and recalculate blocks per request. If the context must stay fixed and insufficient cache space causes frequent preemptions, consider lowering --max-num-seqs to reduce the number of sequences processed per iteration. For frequent preemptions caused by insufficient KV cache space, consider raising an explicit utilization cap if the GPU has room for the extra allocation. Check the startup capacity again after changing settings. Serve CLI · Memory tuning · Startup logs · KV cache interface

Evidence and limits. The settings and log fields were checked against vLLM 0.34.0 documentation on 2026-11-26. The command was not run on a GPU. The worksheet uses the published Qwen configuration and illustrative VRAM inputs.

Sources

  1. vLLM 0.34.0 serve CLI
  2. vLLM 0.34.0 Optimization and Tuning
  3. vLLM 0.34.0 KV Cache Interface
  4. vLLM 0.34.0 Qwen2 implementation
  5. Qwen2.5-1.5B-Instruct model card
  6. Qwen2.5-1.5B-Instruct model configuration
  7. PyTorch 2.15 Tensor Attributes
  8. vLLM 0.34.0 Parallelism and Scaling

Related