RAM vs VRAM: The Difference Every AI Developer Should Understand
Learn the practical difference between RAM and VRAM, how to check usage on Linux, and choose hardware for local AI models.
The OOM error that started it
You try to load a 7B parameter model with llama.cpp and get 'Not enough memory' or a CUDA out-of-memory error. You check your system monitor: 64 GB RAM, 16 GB VRAM. Why can't it run? The answer is that RAM and VRAM are not interchangeable, and knowing the difference saves you hours of debugging.
This article explains what RAM and VRAM do, how they differ, and how to check your system's usage. Then we'll walk through a real example: running a local LLM with llama.cpp and measuring memory consumption.
You'll leave with a clear decision framework for buying or renting hardware for local AI work.
Note: This guide was written in May 2025, referencing current tools like nvidia-smi, htop, and llama.cpp.
What is RAM?
RAM (Random Access Memory) is the main memory of your computer. The CPU reads and writes data here, and it holds your operating system, running programs, and their data. RAM is fast, but it's far slower than VRAM.
For AI workloads, RAM stores the model weights when they are not on the GPU, plus your input data, intermediate tensors, and the tokenizer. If your model fits in VRAM, RAM is less critical. If it doesn't, the CPU has to access model weights from RAM, which is slow.
Typical RAM sizes: 16 GB for basic development, 32 GB for comfortable local AI, 64 GB+ for large models or multitasking.
What is VRAM?
VRAM (Video RAM) is memory on your graphics card. It is physically close to the GPU cores and has extremely high bandwidth, which is essential for parallel matrix operations in neural networks.
When you run a model on a GPU, the model weights, activations, and optimizer states must reside in VRAM. If they don't fit, you get the dreaded 'CUDA out of memory'.
VRAM is not expandable like RAM. You buy a GPU with a fixed amount, and you can't add more later (except by buying a new card).
Common VRAM sizes: 8 GB (entry-level), 12 GB (mid-range), 24 GB (high-end consumer), 48 GB+ (professional).
Key differences at a glance
Here's the short version: RAM is general-purpose, VRAM is specialized for graphics and parallel compute. VRAM is much faster but more expensive per GB. For AI, VRAM is the bottleneck for most models.
The table below summarizes the differences.
- Purpose: RAM holds all running programs; VRAM holds data for the GPU.
- Speed: VRAM bandwidth is 10-20x higher than typical RAM.
- Capacity: RAM typically 16-64 GB; VRAM typically 8-24 GB.
- Expandability: RAM can be added; VRAM is fixed on the card.
- Cost: VRAM is much more expensive per GB.
- Bottleneck: For LLMs, VRAM capacity limits model size; RAM speed limits CPU inference.
How to check your memory usage
Before buying hardware or debugging an OOM, you need to know what you're working with. Here are the commands to check RAM and VRAM on Linux.
First, check RAM with free and htop. Then check VRAM with nvidia-smi.
free -h
htopnvidia-smi- free -h shows total, used, and available RAM.
- htop gives a live view with per-process memory.
- nvidia-smi shows GPU name, VRAM total, used, and processes using it.
- For a one-liner that prints just the VRAM used: nvidia-smi --query-gpu=memory.used --format=csv
Step 1: Install llama.cpp
To see the difference in practice, we'll run a small LLM with llama.cpp. First, clone and build the repository.
llama.cpp is a popular C++ implementation of LLaMA models that can run on CPU or GPU. We'll use it to measure memory usage.
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make -j$(nproc)- Make sure you have cmake and a C++ compiler installed.
- If you have a CUDA GPU, build with LLAMA_CUDA=1 make to enable GPU acceleration.
Step 2: Download a small model
We'll use a 1B parameter model that fits in most GPUs. The TinyLlama 1.1B model is a good choice.
Download the GGUF quantized version to keep the file size manageable.
wget https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf- The Q4_K_M quantization uses 4-bit weights, reducing memory footprint.
- This file is about 700 MB.
Step 3: Run the model and watch memory
Now run the model in interactive mode. In another terminal, use nvidia-smi and free to watch memory usage.
First, run the model with CPU only to see RAM usage.
./main -m tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf -n 32 -p "Hello world"- While it runs, note the RAM usage in htop. It will be around 1-2 GB.
- Now run with GPU offload: ./main -m tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf -n 32 -p "Hello world" -ngl 99
- Watch nvidia-smi: VRAM usage jumps to ~1.5 GB, and RAM usage stays low.
Step 4: Measure the difference
Let's capture the actual numbers. Use the following script to run both and sample memory.
This script runs the model once on CPU and once on GPU, printing the peak memory from /proc.
#!/bin/bash
# Run on CPU
/usr/bin/time -v ./main -m tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf -n 32 -p "Hello world" 2>&1 | grep 'Maximum resident'
# Run on GPU
nvidia-smi --query-gpu=memory.used --format=csv -l 1 > gpu_usage.log &
./main -m tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf -n 32 -p "Hello world" -ngl 99
kill %1
sort -t, -k2 -n gpu_usage.log | tail -1- The CPU run will show a maximum resident set size around 1.5 GB.
- The GPU run will show VRAM usage around 1.4 GB, while RAM stays under 500 MB.
- This proves that VRAM is the primary memory for GPU inference.
Why VRAM is the bottleneck for local AI
Large language models need a lot of memory. A 7B parameter model in 16-bit needs about 14 GB of VRAM just for weights, plus overhead for activations and KV cache.
If you have 16 GB VRAM, you can run a 7B model with quantization. If you have 8 GB, you're limited to smaller models or heavy quantization.
RAM matters when you run models on CPU. CPU inference is slower but allows you to run models larger than your VRAM, at the cost of speed.
For most developers, the practical rule is: match the model size to your VRAM, not your RAM.
How much VRAM do you really need?
Here's a quick guide based on model size and quantization. These are rough estimates for inference only.
Use this table to plan your next GPU purchase.
- 1B model (Q4): 1-2 GB VRAM
- 3B model (Q4): 3-4 GB VRAM
- 7B model (Q4): 5-6 GB VRAM
- 13B model (Q4): 9-10 GB VRAM
- 70B model (Q4): 40+ GB VRAM
- For fine-tuning, multiply by 4-8x due to optimizer states and gradients.
What I would do: a recommended setup
If you're starting local AI development, I recommend a GPU with at least 16 GB VRAM, like an RTX 4080 or 4090. That lets you run 7B-13B models comfortably.
If you're on a budget, an RTX 3060 12 GB is a good entry point. For production, consider cloud GPUs like A100 or H100.
Here's a copy-paste starter script to check if a model fits in your VRAM before you download it.
#!/bin/bash
# Check if model fits in VRAM
# Usage: ./check_vram.sh <model_size_in_GB>
model_gb=$1
vram_gb=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader | head -1 | awk '{print $1}')
if (( $(echo "$model_gb * 1.2 > $vram_gb" | bc -l) )); then
echo "Model may not fit. Need at least $(echo "$model_gb * 1.2" | bc) GB VRAM."
else
echo "Model should fit."
fiTroubleshooting common memory errors
If you still hit errors, here are the usual culprits and fixes.
CUDA out of memory: reduce batch size, use quantization, or offload layers to CPU.
System RAM exhausted: close other applications, or use a smaller model.
Swap thrashing: avoid swapping by using a model that fits in RAM.
Here's a quick checklist to debug.
- Check nvidia-smi to see if other processes are using VRAM.
- Use nvidia-smi --query-compute-apps=pid,used_memory --format=csv to see which processes.
- If you're using PyTorch, set torch.cuda.empty_cache() after each batch.
- For llama.cpp, reduce context size with -c 512.
- Try a more aggressive quantization like Q4_K_M instead of Q8.
FAQ
Quick answers to common questions.
- Can I use RAM as VRAM? Not directly. Some frameworks allow CPU offloading, but it is much slower.
- Is more RAM always better for AI? More RAM helps when running CPU inference or large datasets, but VRAM is more critical for GPU acceleration.
- How do I know if my model fits in VRAM? Check the model size and add overhead. Use the script above.
- Can I add VRAM to my laptop? No, VRAM is soldered on the GPU. You need an external GPU or a new laptop.
- What is the best budget GPU for AI? The RTX 3060 12 GB is a good start for under $300.
Next step: run your own test
Now that you understand the difference, run the memory measurement script on your own machine. It takes five minutes and gives you a clear picture of your hardware.
Create the script, run it, and note the numbers. That data will guide your future hardware decisions.
cat > check_mem.sh << 'EOF'
#!/bin/bash
echo "RAM:"
free -h | grep Mem
echo "VRAM:"
nvidia-smi --query-gpu=memory.total,memory.used --format=csv
EOF
chmod +x check_mem.sh
./check_mem.shKey takeaways
- Apply one concrete change from this post before collecting more reading.
- Prefer browser-side tools when the work involves secrets, tokens, or PII.
- Document the why next to the how so the next reviewer inherits context.
FAQ
- Who is this guide on gpu for?
- Working developers who need a practical take on ram vs vram: the difference every ai developer should understand — not a marketing overview. Skim the sections, apply one tip, then come back when you hit an edge case.
- Do I need an account to use the related tools?
- No. code.live tools run in your browser with no signup. Nothing you paste is uploaded to a server for the client-side utilities linked from this post.
- How often is this article updated?
- This post was published October 17, 2026. Fundamentals stay stable; check linked tool pages and official docs when version-specific behavior matters.