vLLM runs out of GPU memory during serving after the prefill token budget is raised
Raising the number of tokens vLLM may batch per step improves time to first token and throughput, and it also raises the peak activation memory a prefill step needs. When that peak collides with the memory already reserved for the KV cache, the failure arrives during serving rather than at startup, after the deployment has looked healthy.
Drop --max-num-batched-tokens to 2048 to 4096 first, then --max-num-seqs, and only then touch gpu_memory_utilization. A runtime failure after a throughput change points at step size, not at cache size.
- Symptom
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 3.83 GiB. GPU 0 has a total capacity of 79.15 GiB of which 2.11 GiB is free.- Root cause
- Two different budgets draw on the same device memory. gpu_memory_utilization reserves a pool that the KV cache is carved from, while the batched token limit governs how much work a single step may do and therefore how large the activation tensors for that step become. Raising the second does not consult the first.
- Recommended fix
- Lower --max-num-batched-tokens toward 2048 to 4096 as the first move when the failure appears at runtime rather than at startup. This is the setting that grew the step.
- How Denpex helps
- Denpex investigates vLLM runs out of GPU memory during serving after the prefill token budget is raised using the evidence you provide or your connected workload collects. Earlier rank, host or application evidence is needed to distinguish an initiating failure from a downstream report.
What this failure is
A serving-time out-of-memory failure caused by the per-step prefill token budget rather than by the KV cache reservation, appearing only once arriving prompts are long enough to build a maximum-sized batch.
Is this what broke your run? Paste your log.
You're reading about vLLM runs out of GPU memory during serving after the prefill token budget is raised. Paste your own traceback and relevant evidence for an investigation of your workload, with a next action or a specific missing fact. A reference entry does not establish your cause. No account or card for the free diagnosis. Review data handling before submitting sensitive logs.
Before uploading, review cloud data handling and local options.
Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.
Why it happens (the mechanism)
The batched token budget decides how much prefill work goes into one step, and activation memory for that step scales with it. That memory is not part of the pool the KV cache was sized against, so raising the budget quietly increases peak usage above what startup profiling measured. Profiling runs before any real prompt has arrived, so the configuration that fails under long prompts is one that was never exercised at its own limit.
What you'll observe
- The server starts cleanly and fails only once real traffic arrives
- The failure correlates with long prompts rather than with the number of concurrent users
- A configuration tuned for throughput on one model fails on another of similar size
- Reducing the served context length does not help, because the prompts were already within it
Common symptoms and what they mean
Check possible explanations against the incident evidence. A matching symptom alone does not establish its cause.
| Symptom | Possible explanation |
|---|---|
| torch.OutOfMemoryError: CUDA out of memory raised during a forward pass while serving rather than during startup | Two different budgets draw on the same device memory. gpu_memory_utilization reserves a pool that the KV cache is carved from, while the batched token limit governs how much work a single step may do and therefore how large the activation tensors for that step become. Raising the second does not consult the first. |
| Failures beginning immediately after --max-num-batched-tokens or --enable-chunked-prefill was changed | The token budget only binds when a step is large enough to reach it, which requires long prompts or a heavy prefill mix. A deployment can therefore pass startup profiling, serve ordinary traffic for hours, and fail the first time the arriving prompts are long enough to build a full-sized batch. |
| A log line advising that if out-of-memory occurs during cudagraph capture, consider decreasing gpu_memory_utilization or switching to eager mode | The reason the served context length is not the lever is that the prompts were always inside it. What changed is how many prefill tokens the scheduler is willing to put into one step, which is a throughput setting rather than a capacity one. |
Which systems are affected
- vLLM V1, where chunked prefill is enabled by default whenever possible
- Deployments tuned toward a batched token budget above 8192 for throughput
- Mixed traffic combining long prompts with many short decodes in the same step
- Configurations where max_num_seqs multiplied by max_model_len already consumes most of the cache budget
How to confirm this is the problem
Use this checklist to test the hypothesis against a small reproduction. No single line proves the root cause, so preserve the preceding events and compare one variable at a time.
- ✓Check whether the failure began with a change to --max-num-batched-tokens or --enable-chunked-prefill rather than with a change in traffic volume.
- ✓Correlate the failures against prompt length rather than request rate. A token budget only binds once a step is large enough to reach it.
- ✓Restart with the budget set to 2048 and replay the same traffic. Success at the lower budget with everything else unchanged confirms the step size rather than the cache was the cause.
Root cause
- Two different budgets draw on the same device memory. gpu_memory_utilization reserves a pool that the KV cache is carved from, while the batched token limit governs how much work a single step may do and therefore how large the activation tensors for that step become. Raising the second does not consult the first.
- The token budget only binds when a step is large enough to reach it, which requires long prompts or a heavy prefill mix. A deployment can therefore pass startup profiling, serve ordinary traffic for hours, and fail the first time the arriving prompts are long enough to build a full-sized batch.
- The reason the served context length is not the lever is that the prompts were always inside it. What changed is how many prefill tokens the scheduler is willing to put into one step, which is a throughput setting rather than a capacity one.
The fix and how to prevent it
How to fix it
- Lower --max-num-batched-tokens toward 2048 to 4096 as the first move when the failure appears at runtime rather than at startup. This is the setting that grew the step.
- Reduce --max-num-seqs next, to 256 or 128 for large models or long-context work, which lowers how many sequences can contribute to a single batch.
- Adjust --gpu-memory-utilization only after those two, and do not exceed roughly 0.95, since vLLM needs headroom for activations and the CUDA context.
- Add --enforce-eager if the failure occurs during graph capture, which removes the memory reserved for CUDA graphs.
- Tune by measurement rather than by arithmetic: raise the budget until the deployment fails at representative load, then step back one notch and keep that value with the model and hardware recorded next to it.
- Respect the documented relationships, including that the batched token budget must be at least max_num_seqs and at least max_model_len when chunked prefill is disabled.
Step-by-step remediation
- 1Confirm the failures began with a change to --max-num-batched-tokens or --enable-chunked-prefill rather than with a change in traffic.
- 2Group failures by prompt length rather than request rate; the budget binds only on steps large enough to reach it.
- 3Restart with --max-num-batched-tokens 2048 and replay the same traffic.
- 4If it still fails, reduce --max-num-seqs to 128 or 256 for large or long-context models.
- 5Keep the final budget alongside the model, GPU and vLLM version, since it does not transfer between them.
How to prevent it
- Load-test with prompts as long as the real workload's longest, since a budget that never fills is a budget that never fails.
- Record the batched token budget with the model, GPU and vLLM version, because the safe value does not transfer between them and the default has changed across releases.
- Change one of the two budgets at a time, so a regression can be attributed to the setting that caused it.
Save this diagnosis and catch the next crash automatically
All root cause, fix, and prevention steps above are free to read. Create a free account with any email or GitHub to keep your saved diagnosis history across the encyclopedia and run cloud checks, or use a work email below for the 30-day Team evaluation. No card required.
Or start a 30-day free Team trial (work email)
Verified work email unlocks all 14 fleet diagnostic tools, Slack alerts, and team history for 30 days. No card and no automatic charge.
Searchable error signature
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 3.83 GiB. GPU 0 has a total capacity of 79.15 GiB of which 2.11 GiB is free.
INFO: Chunked prefill is enabled with max_num_batched_tokens=16384.
WARNING: If out-of-memory occurs during cudagraph capture, consider decreasing gpu_memory_utilization or switching to eager mode.Use this text as a lookup key in logs and upstream issue trackers. It is not presented as a captured customer log. Confirm the cause from your own preceding events, versions, configuration and the cited references.
Diagnose your own log automatically
The root cause and fix steps above stay free. Create a free account to analyze full job logs, attribute the first failed rank, and keep saved incident history.
Sign up free. Analyze your cluster logsNo credit card. Daily allowance follows verified trust tier. Instant access.
Why the recommended fix works
Lowering the token budget shrinks the largest step the scheduler can build, which lowers the activation peak that collides with the reserved cache. It costs time to first token rather than correctness, and it targets the quantity that actually changed, unlike lowering the served context length, which does nothing when the prompts were already inside it.
Best practices by model family
| Model / Stack | Recommendation | Notes |
|---|---|---|
| Runtime out-of-memory after a throughput change | Lower --max-num-batched-tokens to 2048 to 4096 | This is the setting that enlarged the step and its activation peak. |
| Large model or long-context serving | --max-num-seqs 128 to 256 | Bounds how many sequences contribute to one batch. |
| Throughput-oriented small model on a large GPU | A budget above 8192, validated at long-prompt load | Better time to first token, but only safe if tested at the prompt lengths that fill it. |
| Failure during graph capture | --enforce-eager | Removes the memory reserved for CUDA graphs from the peak. |
With the fix vs without the fix
| Dimension | With the fix | Without the fix |
|---|---|---|
| When the failure appears | During serving, on long prompts | Expected at startup, like a cache sizing error |
| Which budget is responsible | The per-step batched token limit | Assumed to be gpu_memory_utilization |
| Effect of lowering max_model_len | No help when prompts were already inside it | Assumed to reduce memory in every case |
Diagnostic note
“There is no closed-form value for this budget, and looking for one wastes time. The working method upstream and in practice is to raise it until the deployment fails at representative load and then step back one notch, because the limit depends on the model, the sequence mix and the card. What matters is that the load used for that experiment contains the longest prompts the service will really see; tuning against short prompts produces a value that fails the first time a long one arrives.”
Visual fingerprint
reserved by gpu_memory_utilization [ weights ][ KV cache pool ]
needed per step by the token budget [ activations for max_num_batched_tokens ]
^
grows when the budget is raised, until it
collides with the reserved pool at runtimeDiagnose this failure in VS Code
Select the traceback or open the failed terminal, then run Denpex locally to inspect matched failure patterns, supporting evidence and next checks without uploading the log. Verify recommendations against your workload before changing production.
Install the free VS Code extensionvLLM errors in context
vLLM failures cross request, model, KV cache, worker, kernel and host boundaries. The hub compares common signatures and evidence checks that help distinguish possible causes.
Compare related vllm errorsRelated failures to investigate next
Frequently asked questions
Questions engineers and on-call staff commonly ask about this failure.
Why did it start fine and fail later?
Should I lower gpu_memory_utilization?
Is there a formula for max_num_batched_tokens?
Does lowering max_model_len help?
Don't just read the fix, diagnose your run
The encyclopedia explains documented failure patterns. Denpex investigates your logs, configuration and stack, shows the supporting evidence, and asks for missing details when needed.