Skip to content

SGLang torch.OutOfMemoryError: CUDA out of memory

Fix SGLang torch.OutOfMemoryError during RadixCache allocation, CUDA graph warmup, or high-concurrency serving by tuning --mem-fraction-static and batching.

Quick answer

SGLang pre-allocates a static GPU memory pool controlled by --mem-fraction-static for model weights and the RadixAttention KV cache. If other processes occupy VRAM, or activation and CUDA graph peaks exceed the remaining unreserved fraction, SGLang throws torch.OutOfMemoryError.

Symptom
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 2.00 GiB in sglang
Root cause
Static KV pool fraction (--mem-fraction-static), activation batch peak, or co-resident GPU usage exceeded physical GPU VRAM.
Recommended fix
Run nvidia-smi to ensure no stale Python/vLLM/SGLang workers occupy VRAM on the target GPUs.
How Denpex helps
Denpex investigates SGLang torch.OutOfMemoryError: CUDA out of memory 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.
Inference#sglang#cuda-oom#radix-cache#kv-cache#inference

What this failure is

A PyTorch CUDA allocation inside SGLang failed because weights, the static RadixCache pool, or runtime activations exceeded available GPU HBM.

Live diagnosis, no signup

Is this what broke your run? Paste your log.

You're reading about SGLang torch.OutOfMemoryError: CUDA out of memory. 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.

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

Why it happens (the mechanism)

Either --mem-fraction-static is too high leaving zero room for FlashInfer/CUDA graph/activation peaks, another process holds GPU memory on the same device, or incoming concurrent prefills exceed --chunked-prefill-size and --max-running-requests budgets.

What you'll observe

  • SGLang crashes at startup or under load with torch.OutOfMemoryError: CUDA out of memory
  • RadixAttention pool consumes GPU capacity leaving insufficient activation headroom

Common symptoms and what they mean

Check possible explanations against the incident evidence. A matching symptom alone does not establish its cause.

SymptomPossible explanation
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate ... in sglang.srtStatic KV pool fraction (--mem-fraction-static), activation batch peak, or co-resident GPU usage exceeded physical GPU VRAM.
Memory pool initialization fails on rank during model or CUDA graph warmupStatic KV pool fraction (--mem-fraction-static), activation batch peak, or co-resident GPU usage exceeded physical GPU VRAM.

Which systems are affected

  • SGLang inference servers on NVIDIA GPUs
  • Tensor-parallel and single-GPU SGLang deployments

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.

  • ✓Verify clean startup through CUDA graph warmup and run representative concurrent prompts while monitoring /metrics cache usage.

Root cause

  • Static KV pool fraction (--mem-fraction-static), activation batch peak, or co-resident GPU usage exceeded physical GPU VRAM.

The fix and how to prevent it

How to fix it

  • Run nvidia-smi to ensure no stale Python/vLLM/SGLang workers occupy VRAM on the target GPUs.
  • Lower --mem-fraction-static (for example from 0.88 down to 0.80 or 0.78) when OOM occurs during CUDA graph capture or forward activations.
  • Cap concurrency and prefill peaks using --max-running-requests and --chunked-prefill-size, or test --disable-cuda-graph as a controlled isolation step.
  • If model weights alone consume too much HBM, increase --tp or switch to FP8/AWQ weight quantization.

Step-by-step remediation

  1. 1Run nvidia-smi to ensure no competing GPU processes exist.
  2. 2Lower --mem-fraction-static from 0.88 to 0.80 and cap --max-running-requests.
  3. 3Replay peak prompt lengths and verify stable memory under load.

How to prevent it

  • Load-test worst-case concurrent prompt lengths before deploying
  • Reserve 12% to 20% HBM headroom outside --mem-fraction-static for FlashInfer workspaces and CUDA graphs

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.

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.
Already have an account? Sign in

Searchable error signature

search key
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 2.00 GiB in sglang
RuntimeError: Not enough memory. Please lower --mem-fraction-static or --max-running-requests

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 logs

No credit card. Daily allowance follows verified trust tier. Instant access.

Why the recommended fix works

Lowering --mem-fraction-static returns HBM headroom to temporary PyTorch/FlashInfer activation buffers and CUDA graphs while capping --max-running-requests limits concurrent peak allocation.

Code examples

snippet
nvidia-smi
python3 -m sglang.launch_server --model-path YOUR_MODEL --tp 2 --mem-fraction-static 0.80 --max-running-requests 64

This snippet illustrates the entry-specific check. Verify the installed versions, permissions, target and workload context before using it. A command or API example is not proof of recovery.

Best practices by model family

Model / StackRecommendationNotes
OOM during CUDA graph / warmupLower --mem-fraction-static to 0.78 to 0.82Frees headroom outside static RadixCache pool.
OOM mid-serving under spikeLower --max-running-requests or --chunked-prefill-sizeCaps activation memory during long prefills.

With the fix vs without the fix

DimensionWith the fixWithout the fix
Headroom tuningSized --mem-fraction-static + --chunked-prefill-sizeDefault 0.88+ collides with large batch activations
Process hygieneClean nvidia-smi check before server launchZombie worker leaves partial VRAM unavailable

Diagnostic note

“Unlike PyTorch training where OOM shrinks batch size, in SGLang lowering --mem-fraction-static actually gives PyTorch/CUDA graphs MORE free memory outside the static KV pool when warmup crashes.”

Diagnose 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 extension

SGLang errors in context

SGLang failures cross RadixAttention cache pools, FlashInfer kernels, and worker timeouts.

Compare related sglang errors

Frequently asked questions

Questions engineers and on-call staff commonly ask about this failure.

Should I raise or lower --mem-fraction-static on SGLang CUDA out of memory?
If SGLang says there is not enough memory for KV cache blocks, raising it helps (on an idle GPU). If PyTorch throws torch.OutOfMemoryError during warmup or forward activations, lowering --mem-fraction-static frees memory outside the KV pool.
How does --chunked-prefill-size prevent SGLang OOMs?
Chunked prefill caps how many prompt tokens process in one step, preventing huge temporary attention and MLP activation spikes.

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.