Troubleshooting GPU Memory Out-of-Memory Errors
GPU out-of-memory (OOM) errors occur when the model needs more VRAM than the GPU provides. The usual causes are a model profile that does not match the hardware, or a misconfigured memory setting.
Startup allocates GPU memory in phases, and the fix depends on which phase failed. Check the container logs, then follow the matching issue below. If the default logs are not enough, refer to Enable Detailed Logging.
Start with a combination of GPUs and a profile listed in the Support Matrix for NIMs. Refer to the Release Notes for model-specific startup failures and validated workarounds. Use the steps below to diagnose memory pressure. If a worker crashes or reports an illegal memory access during warmup, check the logs to determine whether memory pressure caused the failure.
How GPU Memory Is Used
During startup, NIM and its inference backend allocate GPU memory in stages.
Model weights use the most memory. Estimate weight memory from the model’s
parameter count and the profile’s precision. The model card typically lists
the parameter count. If you have a safetensors index, the
metadata.total_size value in model.safetensors.index.json gives the total
weight size in bytes.
A good heuristic formula for per-GPU weight memory is:
Where bytes_per_parameter depends on precision:
Examples
In addition to model weights, GPU memory holds the KV cache, activations,
communication buffers, and CUDA graphs. LoRA adapters, multimodal
reservations, and hybrid model state can also consume memory.
NIM_KVCACHE_PERCENT controls the fraction of memory the backend can use.
The following table describes how NIM passes that setting to each engine.
Check the effective startup configuration because the image, profile, and user overrides can change the memory fraction. NIM can lower internal defaults to leave headroom on constrained hardware. Explicit settings take precedence. Refer to Advanced Configuration for configuration precedence.
When no configuration source sets the fraction, NIM leaves it unset on both
backends, and the engine uses its own default. The clamp does not set a value
in this case. NIM still maps explicit values such as
NIM_KVCACHE_PERCENT=0.92 to the backend argument.
The backend uses the remaining budget to size the KV cache. The backend and model determine the allocation order and what counts toward the budget. CUDA graphs, adapter buffers, multimodal buffers, and hybrid model state can also consume memory before or during profiling. Check the logs for the allocation that failed. Reducing the maximum context length limits request size, but the allocated KV cache can stay the same size.
Memory Estimate Warnings Before Weight Download
NIM prefers profiles that it estimates will fit, but it can still try a hardware-compatible profile if the estimate is unavailable, the VRAM minimum is out of date, or the estimate exceeds available memory. In these cases, NIM warns before downloading weights and trying to start the backend, whether you use automatic, default, or explicit profile selection. The estimate is advisory. Hardware, precision, topology, configuration, and backend checks still apply, and startup can fail with an OOM error.
NIM does not shorten the context length automatically. For LoRA deployments,
check --max-lora-rank and --max-loras. The allocated capacity can exceed
the rank of the adapter you load. If an override invalidates the declared
memory estimate and NIM cannot read the required metadata, NIM warns and
attempts startup without verifying the estimate.
For Qwen3.5 MoE models on vLLM, NIM accounts for built-in multi-token
prediction ("method": "mtp") when the speculative configuration sets a
positive num_speculative_tokens value and the checkpoint’s
model.safetensors.index.json supplies a positive metadata.total_size value.
Without the checkpoint size, NIM cannot account for the MTP decoder weights
and skips the estimate based on configuration alone. NIM cannot verify
allocations for other speculative methods, external draft models, or MTP
without a positive token count. In these cases, NIM reports
Qwen3.5 backend allocation cannot be verified.
With vLLM, lowering --gpu-memory-utilization can produce a memory warning
even when the GPU has enough free physical memory. The estimated engine
allocation must also fit the utilization budget. If you specify
--kv-cache-memory-bytes, the pool must cover the estimated context
requirement and fit alongside allocations outside the KV cache. An explicit
utilization value also sets an initial reservation, which must fit in the
reported free memory even if you specify a KV cache pool.
The profile’s declared VRAM minimum applies to physical memory regardless of
the utilization setting.
Out of Memory During Weight Loading
Symptoms
The OOM error appears early in startup, during model loading, before any messages about KV cache or graph compilation. Typical log patterns include the following:
Cause
The GPU does not have enough memory to hold the model weights at the selected precision and tensor parallelism (TP) degree. For example, a 70-billion-parameter model in BF16 requires approximately 140 GB of weight memory, which does not fit on a single 80 GB GPU.
Resolution
Run list-model-profiles to find profiles that distribute the model across more GPUs or use a lower-precision quantization:
Look for profiles with higher tensor parallelism (TP) or pipeline parallelism (PP), or choose a profile that uses FP8 or NVFP4. Prefer a precision that your GPU supports natively to avoid a performance penalty. Use the formula in How GPU Memory Is Used to estimate whether the weights fit. For details, refer to Model Profiles and Selection.
Out of Memory During LoRA Adapter Allocation
LoRA adapter weights use GPU memory in addition to the base model weights.
Increasing --max-lora-rank or --max-loras can exhaust memory even when the
profile fits without LoRA. If a failure starts after you increase these settings,
compare your values with the profile’s defaults and choose a supported
profile with enough memory for the required adapters. Reducing context
length does not change how much memory the adapter weights require.
A kernel assertion about the maximum supported LoRA rank points to a rank limit. Adding GPU memory or reducing the number of adapter slots does not remove that limit. Use a rank that the model and backend support. Refer to the Release Notes for model-specific restrictions.
Out of Memory During KV Cache Allocation
KV cache allocation failures fall into two categories: insufficient memory (the KV cache genuinely does not fit) and memory fragmentation (the KV cache fits in total but the allocator cannot find contiguous blocks). Check the error message to determine which applies.
Insufficient Memory
Symptoms
The error occurs after weights are loaded, during memory profiling or KV cache block allocation. Look for log messages mentioning KV cache, determine_available_memory, or block allocation failures. NIM may also print an advisory warning before the crash similar to the following:
Cause
The model’s default context length (max_position_embeddings from config.json) requires more KV cache memory than fits in the GPU budget after weights, activations, and overhead are subtracted. This is common when running a model with a long native context (for example, 128K tokens) on a GPU with limited free memory.
Resolution
Reduce the context length with NIM_MAX_MODEL_LEN or the shared
--max-model-len argument. NIM translates the setting to --max-model-len
on vLLM and --context-length on SGLang. Use the value that NIM suggests in
the warning or choose one that suits your workload.
Reducing --max-model-len limits the maximum sequence length (input + output tokens) per request. Choose a value that fits your use case.
Lowering NIM_KVCACHE_PERCENT reduces the KV cache budget and can make an
allocation failure worse if the cache is already too small. If model,
adapter, or multimodal allocations exhaust memory before the backend sizes
the KV cache, reducing the context length alone might leave too little memory
for the deployment. Refer to the known issue for validated workarounds.
Memory Fragmentation
Symptoms
The error occurs during KV cache allocation and reports that the free memory is less than the requested allocation size. The error also mentions a large amount of memory “reserved by PyTorch but unallocated” and suggests setting expandable_segments:True similar to the following:
Cause
The PyTorch CUDA memory allocator requires contiguous memory blocks for each tensor allocation. During model loading and torch.compile, many temporary allocations fragment the GPU address space into small, non-contiguous pieces. When KV cache allocation begins, the total free memory may be sufficient, but no single contiguous block is large enough for individual per-layer KV cache tensors (typically 1+ GiB each).
This is particularly common with hybrid architectures (such as NemotronH models that combine Mamba and attention layers) where torch.compile creates extensive temporary allocations.
Resolution
Set PYTORCH_ALLOC_CONF=expandable_segments:True to instruct PyTorch to use CUDA virtual memory APIs, which allow allocations to grow without requiring physically contiguous pages:
This setting changes how the allocator uses available GPU memory and can reduce fragmentation. Before using it with deployments that share CUDA allocations between processes, check the CUDA IPC compatibility limitations.
Out of Memory During CUDA Graph Compilation or Warmup
Symptoms
The OOM error appears during CUDA graph capture, memory profiling, or sampler warmup. Depending on the backend and model, the error can occur before or after KV cache allocation. The logs can include the following error.
preceded by messages such as:
or:
Cause
Graph capture or warmup requires more memory than the GPU has available. The amount of headroom you need depends on the model, capture configuration, and other allocations.
Resolution
If the failure occurs after KV-cache allocation, reducing
NIM_KVCACHE_PERCENT can leave more headroom by shrinking the KV cache.
For example, changing the value from 0.9 to 0.85 reduces the requested budget by 5% of
total GPU memory. The value in the following command is illustrative. Check
how much memory your profile needs before choosing a value.
Set NIM_DISABLE_CUDA_GRAPH=1 to test whether graph capture causes the
failure. NIM uses --enforce-eager on vLLM and
--disable-decode-cuda-graph --disable-prefill-cuda-graph on SGLang.
Disabling graphs can reduce throughput, and the model and adapters still
require memory. If compilation runs when the first requests arrive, those
requests can take longer.
Out of Memory After Startup
An OOM error can occur while the server processes requests. vLLM can recover from some of these errors by returning HTTP 500 for the affected requests. An engine-level failure, including a runtime OOM on SGLang, can stop the server. Check the container logs and readiness endpoint, then restart the deployment if the engine exited. If the error recurs, check request concurrency, context length, and available GPU memory before sending traffic again.
CPU KV Cache Offload Reduced or Disabled at Startup
Some vLLM profiles enable CPU KV cache offload, which stores the offloaded
data in /dev/shm. Before starting vLLM, NIM LLM and VLM checks how
much space is free there. If the offload tier set by the profile or NIM
runtime configuration would leave less than 4 GiB free,
NIM LLM and VLM reduces the tier to the available space minus 4 GiB.
If the reduced tier is smaller than 8 GiB, NIM disables CPU KV cache offload.
A smaller tier or disabled offload lowers throughput at high concurrency.
The startup log reports the adjustment in a warning like the following.
To keep the full tier, start the container with the --shm-size value from
the warning or use --ipc=host. The nim_config_resolved startup event records
the requested tier as the previous value.
If you set the offload tier using container arguments, NIM_PASSTHROUGH_ARGS,
or an environment variable, NIM LLM and VLM uses the value you set.
It logs a warning if /dev/shm cannot hold the tier, and vLLM stops at startup.
Enable Detailed Logging
Set NIM_LOG_LEVEL to INFO or DEBUG to inspect startup diagnostics on either
backend. These include GPU information and topology from nvidia-smi, along with
the model’s estimated memory requirements. The vLLM backend also prints a GPU
Memory Report covering allocations such as model weights and KV cache. On SGLang,
use the engine’s memory allocation logs.
To enable detailed logging, set the NIM_LOG_LEVEL environment variable:
Related Topics
The following pages provide profile selection, memory clamping, and environment-variable detail:
- Model Profiles and Selection — profile listing and selection
- Advanced Configuration — GPU memory management, automatic clamping, and configuration priority
- Environment Variables — full reference for
NIM_LOG_LEVEL,NIM_DISABLE_CUDA_GRAPH, and other variables