VRAM, RAM & Storage for Local AI Inference
In this article
To run local AI inference, you need enough VRAM to hold the model weights plus the key-value (KV) cache, enough system RAM to load the model and run the operating system, and enough storage to store the model files and any datasets. As a starting point: 8 GB VRAM handles 7B-parameter models at 4-bit quantization, 16 GB handles 13B models, and 24 GB handles 30B models. System RAM should be at least the model size plus 4–8 GB for the OS, and storage should be at least 2–3 times the model file size to allow for downloads, conversions, and temporary files.
What You'll Need
- A computer with a dedicated GPU (NVIDIA, AMD, or Apple Silicon) or a CPU with enough system RAM for CPU-only inference.
- Knowledge of your GPU's VRAM capacity and your system's total RAM.
- Access to model files in a format like GGUF, GPTQ, or EXL2, typically from Hugging Face.
- Inference software such as Ollama, LM Studio, text-generation-webui, or llama.cpp.
- Free disk space at least 2–3 times the size of the models you plan to download.
Step-by-Step
- Determine your model size and quantization. Model size in billions of parameters (e.g., 7B, 13B, 70B) and quantization level (4-bit, 5-bit, 8-bit) dictate memory needs. A 7B model at 4-bit uses roughly 4–5 GB of VRAM; at 8-bit, about 7–8 GB; at 16-bit, about 14 GB.
- Calculate VRAM for weights. Use the rule of thumb: VRAM (GB) ≈ parameters (B) × bytes per parameter. For 4-bit, bytes per parameter ≈ 0.5; for 8-bit ≈ 1; for 16-bit ≈ 2. So a 13B model at 4-bit needs about 6.5 GB for weights alone.
- Add KV cache and overhead. The KV cache grows with context length and batch size. For a 7B model with 4K context, expect 1–2 GB extra; for 32K context, 4–8 GB. Add 1–2 GB for CUDA overhead and other processes. Total VRAM = weights + KV cache + overhead.
- Check system RAM. System RAM must hold the model during loading and any CPU offloading. If the model fits entirely in VRAM, 16 GB system RAM is usually enough for 7B–13B models. For CPU-only inference, you need system RAM roughly equal to the model size plus 4–8 GB for the OS.
- Estimate storage needs. Model files are typically 2–8 GB for 7B at 4-bit, 4–15 GB for 13B, and 20–40 GB for 70B. Keep at least 2–3 times the largest model size free for downloads, conversions, and temporary files.
- Choose quantization based on hardware. If VRAM is limited, use 4-bit or 5-bit quantization. If you have 24 GB VRAM, you can run 30B models at 4-bit or 13B at 8-bit. For CPU-only, use 4-bit GGUF files.
- Install inference software. Download and install Ollama, LM Studio, or text-generation-webui from their official sites. These tools handle model loading and memory management.
- Download a model and test. Start with a small model like Llama 3.2 3B or Mistral 7B at 4-bit. Monitor VRAM usage with tools like nvidia-smi (NVIDIA) or Task Manager (Windows). If you run out of VRAM, reduce context length, batch size, or quantization.
- Adjust settings for your hardware. In your inference software, set GPU layers to offload as many layers as fit in VRAM. For CPU-only, set threads to match CPU cores. Reduce context length if you hit memory limits.
- Plan for growth. If you want to run larger models or longer contexts, consider a GPU with more VRAM (e.g., 24 GB or 48 GB) or use system RAM with CPU offloading, though performance will drop.
Common Mistakes
- Underestimating KV cache: long contexts can double or triple VRAM needs.
- Ignoring system RAM: even with a powerful GPU, insufficient RAM can cause swapping and crashes.
- Using too high quantization: 8-bit or 16-bit models may not fit in VRAM, causing out-of-memory errors.
- Forgetting storage overhead: model downloads and conversions can temporarily double disk usage.
- Assuming VRAM equals model size: overhead and cache add significant memory.
Tips
- Use 4-bit quantization for the best balance of quality and memory on consumer GPUs.
- Monitor VRAM usage during inference to find the sweet spot for context length and batch size.
- For Apple Silicon, unified memory means system RAM is shared with the GPU; 16 GB unified memory can run 7B models at 4-bit.
- Keep models on an SSD for faster loading; NVMe is preferable for large models.
- Use smaller context windows (e.g., 2K–4K) unless you need long conversations.
Troubleshooting
If you get out-of-memory errors, first reduce context length and batch size. Next, lower quantization (e.g., from 5-bit to 4-bit). If using GPU offloading, reduce the number of GPU layers. Check that no other applications are using VRAM. For CPU-only, ensure you have enough system RAM and close memory-hungry apps. If the model loads but is very slow, it may be partially offloaded to CPU; increase GPU layers if VRAM allows. If storage runs out during download, free up space or use a drive with more capacity. Always restart the inference software after changing settings.
Frequently Asked Questions
How much VRAM do I need for a 7B model?
At 4-bit quantization, about 4–6 GB of VRAM for weights plus 1–2 GB for KV cache and overhead, so 6–8 GB total. At 8-bit, about 8–10 GB.
Can I run local AI without a GPU?
Yes, using CPU-only inference with GGUF models. You need system RAM roughly equal to the model size plus 4–8 GB for the OS. Performance will be slower.
How much storage should I reserve for models?
At least 2–3 times the size of the largest model you plan to use. A 7B 4-bit model is about 4 GB, so reserve 10–15 GB free.
What is KV cache and why does it matter?
KV cache stores attention keys and values for the context window. It grows with context length and batch size, adding 1–8 GB or more to VRAM needs.
Does quantization affect quality?
Yes, lower-bit quantization (4-bit) reduces quality slightly compared to 8-bit or 16-bit, but it is often acceptable for many tasks and enables running larger models on consumer hardware.
Can I use system RAM as VRAM?
Some software allows CPU offloading, using system RAM for part of the model. This works but is much slower than pure GPU inference.