Troubleshooting Local LLMs: RAM, VRAM, & Disk Gotchas

Troubleshooting Local LLMs: RAM, VRAM, & Disk Gotchas

Memory and IO Troubleshooting for Large Language Model Deployments

Practical steps to diagnose and fix RAM, VRAM, and disk IO bottlenecks so your LLMs run reliably — actionable checklist and quick fixes to implement now.

Running large language models in production can fail silently when memory or IO limits are reached. This guide helps engineers quickly identify whether issues are system RAM, GPU VRAM, or disk/mmap bottlenecks, and gives concrete remediation steps to restore service and improve capacity.

  • Pinpoint whether the problem is RAM, VRAM, or disk IO and get a fix within minutes.
  • Techniques to reduce model memory footprint: quantization, pruning, and memory mapping.
  • GPU strategies: offload, activation checkpointing, sharding, and mixed-precision workflows.
  • Common mistakes and a compact implementation checklist to deploy fixes safely.

When to apply this guide

Use this guide when model inference or training fails with out-of-memory errors, slow cold starts, excessive swapping, or when throughput drops unexpectedly under load. It’s applicable to self-hosted servers, cloud VMs, and GPU-based inference clusters running models from ~7B parameters upward.

Quick answer

If you see OOMs or huge latency spikes: check host RAM and swap use first, then GPU VRAM, and finally disk IO/mmap errors. Short-term fixes: reduce batch size, enable swap/more RAM, run model in 8-bit/4-bit quantized mode, or offload weights to CPU/NVMe. Long-term: model sharding, mixed precision, and proper mmap-backed model loading.

Rapidly diagnose RAM shortages

Symptoms of host RAM shortage include system-level OOM kills, large swap activity, long GC pauses in Python, or process crashes during model load.

  • Check memory stats: free -h, vmstat 1 5, and top/htop for real-time view.
  • Find OOM kills in kernel logs: dmesg -T | grep -i kill or journalctl -k.
  • Python process RSS vs virtual memory: ps -o pid,rss,vsz,cmd -p PID. High VSZ with low RSS suggests memory-mapped files.
  • Track allocations in Python: use tracemalloc or guppy/heapy for heap inspection when feasible.
Quick RAM signals and likely causes
SignalLikely causeImmediate action
OOM killer entriesHost RAM exhaustionReduce concurrent processes, add RAM/swap
High swap usageInsufficient RAMIncrease RAM or tune swappiness
Long Python pausesGC or large allocationsProfile allocations, limit batch sizes

Reduce model RAM footprint

Memory use during model load and inference comes from model weights, optimizer/state (during training), and activations. The following actions lower the resident set size (RSS).

  • Use quantized weights (8-bit or 4-bit) with libraries such as bitsandbytes or supported backends. Example: load model in 8-bit to cut RAM footprint ~2–4x for weights.
  • Enable memory-mapped model loading: map tensors from disk instead of loading full into RAM. Many frameworks support mmap-style backends.
  • Disable unnecessary Python objects and GC-heavy structures. Keep a minimal runtime and avoid frameworks that replicate weights in multiple copies.
  • For training: switch to gradient checkpointing, optimizer state sharding (e.g., ZeRO), or offload optimizer state to CPU/NVMe.

Diagnose and resolve VRAM issues

GPU out-of-memory (OOM) errors present as CUDA OOM messages or process crashes. They typically occur during model load, batch processing, or when multiple models share GPUs.

  • Inspect GPU memory: nvidia-smi --query-gpu=memory.used,memory.total,utilization.gpu --format=csv.
  • List per-process GPU memory: nvidia-smi pmon -c 1 or nvidia-smi --query-compute-apps=pid,used_memory --format=csv.
  • Watch CUDA logs and framework traces (PyTorch torch.cuda.memory_summary()) to identify allocations causing peak usage.
  • Temporarily reduce batch size and sequence length to validate VRAM pressure vs other issues.

Manage GPU memory: offload, quantize, and sharding

When a single GPU lacks memory for the full model, combine these approaches for both temporary recovery and long-term scaling.

  • Weight offloading: keep primary weights on CPU/NVMe and stream layers to GPU as needed. Useful for inference on large models when latency allows.
  • Activation offload and checkpointing: recompute activations during backward pass to save memory during training.
  • Quantization: use 8-bit/4-bit kernels on GPU to reduce weight memory and bandwidth. Verify numeric quality on a validation set.
  • Sharding: split model parameters across GPUs (tensor and pipeline parallelism). Tools: DeepSpeed ZeRO, FairScale, or native framework sharding.
Strategies for GPU memory reduction
StrategyTypical savingsTrade-offs
8-bit quantization2×+ weight savingsMinor accuracy drop, CPU/GPU kernel support needed
Offload to CPU/NVMeDepends on model sizeHigher latency, IO contention
Sharding (ZeRO)Linear scaling with GPUsComplexity, synchronization overhead

Fix disk space, mmap and IO bottlenecks

Disk issues often cause long model load times, mmap failures, or runtime stalls when models stream from NVMe. Identify whether the disk, filesystem, or OS limits are the constraint.

  • Check disk free space and inodes: df -h and df -i.
  • Monitor IO: iostat -x 1 5, iotop, or dstat reveal throughput and queue depths.
  • Look for mmap errors in logs; insufficient address space or broken file mappings can surface as segfaults or failed tensor loads.
  • For cold starts, pre-warm mmap files by touching pages or using framework prefetch where available to avoid per-request stalls.
  • Ensure correct filesystem for large-model mmap: avoid network filesystems without proper mmap semantics; prefer local NVMe or appropriately configured cluster storage with direct IO.

Common pitfalls and how to avoid them

  • Assuming VRAM is the only bottleneck — Remedy: measure host RAM and IO first; add observability for all layers.
  • Loading multiple model copies inadvertently (e.g., per-worker) — Remedy: share model instance across worker threads/processes or use a model server process.
  • Relying on swap for heavy workloads — Remedy: increase physical RAM or offload to NVMe-backed memory; tune swappiness only as a short-term mitigation.
  • Using network filesystems for mmap without testing — Remedy: use local NVMe for mmap-backed models or ensure the remote FS supports required semantics and performance.
  • Blindly applying quantization — Remedy: validate model quality on representative data and use supported kernels to avoid runtime failures.

Implementation checklist

  • Measure: collect host RAM, swap, GPU VRAM, and disk IO metrics under load.
  • Short-term fixes: reduce batch size/seq length, restart processes to free fragmented memory, enable temporary swap or add RAM.
  • Medium-term: enable quantized weights, memory-mapped loading, weight offload to CPU/NVMe, and activation checkpointing.
  • Long-term: architect sharding across GPUs, autoscale nodes, and standardize on storage that supports mmap and sustained throughput.
  • Validate: run regression tests for latency, throughput, and model quality after each change.

FAQ

  • Q: How do I know if slowdown is IO or memory?

    A: High disk queue, low CPU/GPU utilization, and long load times indicate IO; high swap, OOM logs, or CUDA OOMs point to memory.
  • Q: Is quantization safe for production?

    A: Often yes for inference if validated; test accuracy and numeric stability on representative inputs.
  • Q: Can I run a 70B model on a 24GB GPU?

    A: Possibly with aggressive sharding + offload + 4-bit quantization, but expect higher latency and complex orchestration.
  • Q: When should I add swap?

    A: Use swap only as temporary relief to prevent crashes; heavy swap will severely degrade performance — prefer adding RAM or offloading.
  • Q: Which metric should I alert on first?

    A: Alert on sudden increases in swap usage, GPU memory usage nearing capacity, and disk IO queue length during deployments.