Nadhebe
tutorials

vLLM CUDA Out of Memory (OOM): Fixes for max_model_len, gpu_memory_utilization, and PagedAttention

Resolve vLLM CUDA Out of Memory errors when serving DeepSeek R1 and Llama models using VRAM allocation flags, KV cache quantization, and tensor parallelism.

Nadhebe Editorial Team Nadhebe Editorial Team
· · 2 min read
GPU Lab Verified
Vintage editorial illustration comparing VRAM block allocation charts and CUDA memory management on a soft sage green background
On this page

vLLM CUDA Out of Memory (OOM): Fixes for max_model_len, gpu_memory_utilization, and PagedAttention

Serving large language models like DeepSeek R1 70B or Llama 3 with vLLM provides high token throughput. However, engineers frequently encounter torch.cuda.OutOfMemoryError failures during engine startup or peak concurrent user traffic.

This tutorial provides tested configuration flags and memory allocation strategies to eliminate vLLM CUDA OOM crashes permanently.


Memory Allocation Architecture

 ┌────────────────────────────────────────────────────────────────────────┐
 │                    VLLM GPU VRAM ALLOCATION MATRIX                     │
 └───────────────────────────────────┬────────────────────────────────────┘

 ┌──────────────────────────┐        │        ┌──────────────────────────┐
 │ MODEL WEIGHTS (FP16/FP8) ├────────┼───────►│ PAGEDATTENTION KV CACHE  │
 │ • Static Model Memory    │        │        │ • Dynamic Request Blocks │
 └──────────────────────────┘        │        └──────────────────────────┘
 ┌──────────────────────────┐        │
 │ PYTORCH & CUDA OVERHEAD  ├────────┘
 │ • Reserved Buffer (10%)  │
 └──────────────────────────┘

3 Core Configuration Fixes

Fix 1: Adjust --gpu-memory-utilization

If vLLM crashes during engine initialization before serving any requests, reduce the reserved KV cache threshold from 0.90 to 0.82:

python3 -m vllm.entrypoints.openai.api_server \
    --model deepseek-ai/DeepSeek-R1-Distill-Llama-70B \
    --gpu-memory-utilization 0.82 \
    --tensor-parallel-size 4

Fix 2: Cap Context Window (--max-model-len)

Large models defaulting to 128k context windows require massive KV cache memory. Restrict maximum sequence length to match actual application requirements:

--max-model-len 8192

Fix 3: Enable FP8 / INT4 KV Cache Quantization

Reduce KV cache VRAM footprint by 50% without retraining:

--kv-cache-dtype fp8

Frequently asked questions

Why does vLLM throw CUDA OOM before processing a single inference request?

By default, vLLM pre-allocates up to 90% of available GPU VRAM (`gpu_memory_utilization=0.90`) for KV cache blocks. If PyTorch overhead or small GPU memory buffers exceed the remaining 10%, CUDA crashes.

What is the optimal `gpu_memory_utilization` setting for vLLM on single 24GB GPUs?

Set `--gpu-memory-utilization 0.85` or `--gpu-memory-utilization 0.80` to leave sufficient VRAM headroom for PyTorch initialization.

Sources & references

  1. [1]vLLM Memory Management Guide
Nadhebe Editorial Team

Nadhebe Editorial Team

The collective editorial desk, technical writers, and hardware validation engineers at Nadhebe. All publications undergo multi-stage peer review and physical GPU lab validation.

Includes Free AI Starter Kit

The Weekly AI Engineering Briefing

Join AI engineers building with Claude, MCP, Gemini, and open-source models. Received by developers, researchers, and technical founders.