Back to Community & Earn Hub
Q&A Questionllms +150 pt Bounty

CUDA OOM in Multi-Agent LoRA Serving: How to cap vLLM --max-lora-rank and CPU swap space when serving 40+ tenant adapters concurrently?

@ananya_iyer15 hours ago 1446 views

We serve 45 tenant-specific LoRA adapters (specialized for SQL generation, compliance extraction, and code review) on a single NVIDIA A100 80GB node using vLLM's --enable-lora S-LoRA / Punica backend.

Launch Configuration

bash
python3 -m vllm.entrypoints.openai.api_server   --model meta-llama/Llama-3.1-8B-Instruct   --enable-lora   --max-loras 16   --max-lora-rank 64   --max-cpu-loras 48   --gpu-memory-utilization 0.92

The Production Crash

Under normal load, everything runs smoothly. During morning traffic spikes when 12+ distinct LoRA adapters are requested inside the same continuous batch:

text
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 512.00 MiB.
GPU 0 has a total capacity of 79.15 GiB of which 142.12 MiB is free.

Even though 16 active LoRA adapters at 80MB each should only take ~1.3GB of VRAM, why is vLLM running out of GPU memory during concurrent adapter swaps? And how should we tune --max-loras vs --gpu-memory-utilization so KV-cache allocation doesn't starve the LoRA staging buffers?

1 Answers

Community Answers

@vikram_joshi Accepted Answer15 hours ago

The CUDA OOM isn't caused by the raw LoRA weights (~1.3GB)—it is caused by vLLM pre-allocating KV-cache blocks up to --gpu-memory-utilization 0.92 BEFORE Punica/S-LoRA temporary staging buffers and CUDA Graph activation memory spike under mixed-adapter batches.

When --max-loras 16 is paired with --max-lora-rank 64, vLLM allocates pinned tensor pools for all active adapter matrices plus intermediate bgmv / sgmv segmented gather-scatter scratchpads. If --gpu-memory-utilization is set too aggressively (0.92), those temporary PyTorch CUDA allocations cannot fit in the remaining 8% headroom.

Here is the production-safe configuration:


1. Leave 12–15% VRAM Headroom for LoRA Staging & Activation Spikes

Lower --gpu-memory-utilization from 0.92 to 0.85 on A100 80GB when --enable-lora is active:

bash
python3 -m vllm.entrypoints.openai.api_server   --model meta-llama/Llama-3.1-8B-Instruct   --enable-lora   --max-loras 8   --max-lora-rank 32   --max-cpu-loras 64   --gpu-memory-utilization 0.85   --max-num-seqs 64

2. Why --max-loras 8 + --max-cpu-loras 64 Fixes Thrashing

  • --max-loras 8: Caps the number of distinct adapters pinned in active GPU VRAM per scheduling step. Keeping this at 8 instead of 16 cuts Punica staging buffer memory in half.
  • --max-cpu-loras 64: Keeps all 45+ tenant adapters cached in Host CPU RAM (zero disk reload latency!). Swapping an adapter from pinned CPU memory over PCIe Gen4 takes <2ms, which is hidden behind the prefill pass.
  • --max-lora-rank 32: Unless all 45 adapters strictly use rank 64, capping --max-lora-rank to your actual trained rank (16 or 32) cuts per-adapter VRAM reservation by 2x–4x.

3. Monitor GPU Fragmentation (PYTORCH_CUDA_ALLOC_CONF)

Add expandable segments so PyTorch doesn't OOM due to non-contiguous 512MB slab requests during adapter swaps:

bash
export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"

With gpu_memory_utilization=0.85, max_loras=8, max_cpu_loras=64, and expandable_segments:True, you can serve 50+ concurrent tenant adapters on a single 80GB A100 with zero OOM crashes.

Have a solution or working configuration?

Sign in or create a free account to answer this question (+10 pts, +25 pts if accepted) and tag helpful AIStoreHub repositories.