Skip to content

Operator task guide

How to tune vLLM chunked prefill, prefix caching, and throughput

Chunked prefill splits long prompt prefills across scheduler steps capped by --max-num-batched-tokens so large prompts do not stall active decode streams (improving inter-token latency). Automatic prefix caching (--enable-prefix-caching) reuses KV blocks across shared system prompts or multi-turn chats.

Setting --max-num-batched-tokens too high spikes activation memory and triggers CUDA OOM during warmup, while setting it too low drops prefill throughput on compute-bound GPUs. Benchmark one flag change at a time with vllm bench serve.

Reviewed . Reference guidance is not a diagnosis of your workload.

Step-by-step method

  1. 1

    Inspect resolved chunked prefill and prefix caching defaults

    Recent vLLM versions enable chunked prefill and prefix caching by default depending on model and version. Check startup logs so you know which scheduler settings are active.

    grep -iE 'chunked|prefix_caching|max_num_batched_tokens|max_num_seqs' vllm.log
  2. 2

    Run a reproducible baseline benchmark with vllm bench serve

    Capture p50/p95/p99 TTFT, ITL, and output tokens/sec with fixed prompt/output distributions and seed before tuning flags.

    vllm bench serve --backend vllm --base-url http://127.0.0.1:8000 \
      --model YOUR_MODEL --dataset-name random \
      --random-input-len 2048 --random-output-len 256 --seed 42 \
      --num-prompts 500 --request-rate 8 --percentile-metrics ttft,itl,e2el --metric-percentiles 50,95,99
  3. 3

    Tune --max-num-batched-tokens for TTFT vs ITL balance

    Lower --max-num-batched-tokens (e.g. 2048 to 4096) to protect decode ITL under heavy long-prompt arrival, or raise it (e.g. 8192 to 16384) when GPU HBM allows and maximizing prefill throughput matters more.

    vllm serve YOUR_MODEL \
      --enable-chunked-prefill \
      --enable-prefix-caching \
      --max-num-batched-tokens 4096 \
      --max-num-seqs 128
  4. 4

    Check prefix cache hit rate and preemption counters after tuning

    Inspect Prometheus metrics after each benchmark run to verify prefix cache hit rates increased without introducing KV preemptions or activation OOMs.

    curl -fsS http://127.0.0.1:8000/metrics | grep -E 'prefix_cache|num_preemptions|gpu_cache_usage_perc'

Throughput and latency tuning tradeoffs

Signals, meanings and actions for how to tune vllm chunked prefill, prefix caching, and throughput.
SignalWhat it meansNext action
High decode ITL jitter whenever long prompts arriveLarge prefills are monopolizing scheduler iterations.Enable chunked prefill and lower --max-num-batched-tokens.
CUDA OOM during dummy run / memory profiling at startup--max-num-batched-tokens or --max-num-seqs creates an oversized activation peak.Reduce --max-num-batched-tokens (for example to 2048 or 4096) and re-profile.
High TTFT on multi-turn chat or RAG system promptsShared prompt prefixes are being recomputed.Verify --enable-prefix-caching is active and check prefix_cache_hits in /metrics.
Preemptions climb while raising --max-num-seqsScheduler admits more requests than KV cache blocks can hold.Lower --max-num-seqs or increase KV capacity via FP8 KV / higher TP.

Evidence checklist

  • Resolved startup scheduler config (chunked prefill, prefix caching, max_num_batched_tokens)
  • vllm bench serve output with TTFT, ITL, and output throughput
  • Prompt length distribution and shared-prefix ratio
  • Prometheus gpu_cache_usage_perc and num_preemptions_total
  • Startup profiling memory peak if OOM occurs

Common mistakes

Benchmarking random single-turn prompts to test prefix caching

Random tokens never share prefixes, masking prefix-caching wins and sizing needs.

Cranking --max-num-batched-tokens without watching startup OOM

vLLM profiles worst-case activation memory against max_num_batched_tokens at boot.

Ignoring preemption metrics during throughput benchmarks

Recomputing evicted sequences consumes GPU FLOPs and cuts real served tok/s.

Frequently asked questions

What is a good starting value for --max-num-batched-tokens in vLLM?

For low-latency interactive serving, 2048 to 4096 protects inter-token latency while keeping activation peaks modest. For offline batch prefill throughput on 80GB+ GPUs, 8192 to 16384 increases compute utilization.

When does --enable-prefix-caching help most?

It accelerates multi-turn conversations, few-shot system prompts, agent loops, and RAG workloads where requests share identical leading token blocks.

Can chunked prefill cause CUDA out of memory errors?

Yes, if --max-num-batched-tokens is set larger than available activation headroom or exceeds max-model-len expectations during startup profiling.

How do I disable prefix caching or chunked prefill to A/B test?

Use --no-enable-prefix-caching or --no-enable-chunked-prefill (flag names depend on vLLM release; confirm with vllm serve --help) while holding seed and prompt mix constant.

Live diagnosis, no signup

Upload your GPU log. Find what happened first.

Get the likely cause, supporting evidence, and next safe steps with the same cloud reasoning used by paid plans. A crash the engine recognizes is answered in seconds, then checked by an independent AI review that updates this page when it finishes. A crash it does not recognize waits for the AI's own answer, which can take a few minutes. No account, card, or installation. Logs are masked at Denpex API ingress and are not saved to account history.

Before uploading, review cloud data handling and local options.

training_logs.txt
No log to hand? Try one:

Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.

3 free cloud diagnoses per day

Try Denpex for 30 days. FREE.

No credit card. No automatic subscription. See whether Denpex helps with an incident you already understand.

Start your free 30-day Team evaluation

Up to 50 diagnoses a day for 30 days. Verify your work email to activate an eligible company evaluation, then replay a resolved incident and compare the evidence and next steps with your team's confirmed cause.

Use your company email, for example alex@yourcompany.com.

Who qualifies?

Company email domains activate the free 30-day Team evaluation (up to 50 diagnoses a day) after an email and domain check, whatever mail provider you use. If we cannot verify your domain automatically, support reviews it: write to support@denpex.com. Free local diagnosis in the editor extension needs no account.

Using a personal email (Gmail, Outlook, Naver, QQ) or solo cluster? Create a free $0 account (no work email required) to save 7-day history and unlock AI fallback, or send a cluster crash log for a live walkthrough.

Apply the method to your incident

Use the three free diagnoses to review your error and relevant evidence. Keep reference guidance separate from the cause and recovery status of your own workload.

Diagnose your incident