A hand hovers over a computer graphics card in a workshop setting.

How to Fix Local Llm Running Out of Vram Memory on 8gb Gpu Ollama Quantization Fix

AlYour terminal shows “CUDA out of memory” while Ollama loads a model, and the chat never starts. That is the classic sign of how to fix local llm running out of vram memory on 8gb gpu ollama quantization fix: the model file is simply too large for the card. An 8 GB GPU holds roughly 7 GB of usable VRAM after display buffers, and a 15 GB model will never fit without compression.

Quick answer: Switch to a quantized model tag such as qwen2.5:7b-instruct-q4_K_M, or lower the context window with OLLAMA_NUM_PARALLEL=1 and a smaller num_ctx. Quantization at 4-bit typically cuts VRAM use by more than half. Expect a 7B model at Q4 to run in about 4–5 GB.

This guide walks through detection, model selection, environment settings, and the mistakes that keep models spilling into system RAM.

What you need before starting

Gather a few basics before touching settings. Ten minutes of preparation saves an hour of guessing.

Hardware and software checklist:

  • An NVIDIA GPU with 8 GB VRAM (RTX 3060, 4060, 3070, or laptop equivalents), or an AMD card with ROCm support
  • Ollama installed and running (ollama --version confirms it)
  • A terminal with admin rights if you edit environment variables at the system level
  • Updated GPU drivers — older drivers can misreport free VRAM
  • Roughly 10 GB of free disk space for an extra model download

How to check what Ollama actually sees. Run nvidia-smi while a model is loaded. The “Memory-Usage” column tells you the real number. If Ollama shows a model sitting at 7.9 GB, you are at the ceiling. On Linux, ollama ps confirms whether the model is running on GPU (100% GPU) or partly on CPU. On Windows and macOS, ollama ps works the same way inside PowerShell or Terminal.

Understanding quantization sizes. Model parameters are stored at different precisions. The table below compares typical sizes for a 7B model.

Comparison: quantization levels for a 7B model

Tag suffix Bits File size Fits in 8 GB?
q8_0 8-bit ~7.7 GB Tight, often no
q5_K_M 5-bit ~5.1 GB Yes, small context
q4_K_M 4-bit ~4.4 GB Yes, comfortably
q3_K_M 3-bit ~3.5 GB Yes, quality drops

Notice that Q4_K_M is the sweet spot. It leaves room for the context window and the KV cache, which grows with conversation length. Q5 fits but tightens your margin.

Laptop GPUs share memory
Laptops with 8 GB dedicated VRAM still work, but Windows may reserve 0.5–1 GB. Budget for 6.5–7 GB of usable space.

Know your baseline. Run ollama run llama3.2:3b first. A 3B model loads in under 3 GB and confirms the GPU path works. If that fails, the issue is drivers, not quantization.

Confirm the driver and runtime versions first with nvidia-smi and nvcc --version. If they disagree on CUDA support, fix that before downloading anything, because a model that seems too large may simply be failing to allocate through a mismatched stack.

Step-by-step instructions

Animated hands type on a keyboard in front of monitors displaying code and a video call.

Follow these steps in order. Each one produces a clear result you can verify before moving on.

Before the first step, capture a reference point. Start nvidia-smi --query-gpu=memory.used,memory.total --format=csv -l 2 in a side terminal so every change has a numeric effect you can compare against, and note idle usage while no model is loaded. An idle card above 1 GB already has something holding memory.

Log each change with the exact environment value and the resulting ollama ps line. When a later tweak regresses performance, the log shows which setting to revert instead of guessing. Keep the Modelfile under version control if you tune context often, so you can rebuild a working configuration in seconds rather than retracing edits.

Finally, test one step at a time. Changing the model, context, and parallelism together makes it impossible to tell which lever fixed the crash — or which one quietly hurt speed.

Step 1: Confirm the memory failure

Run your problem model with ollama run <model>. Watch the terminal and a second window running nvidia-smi -l 1. The error appears within seconds if VRAM is the cause. Outcome: you see the exact peak memory number before the crash.

Step 2: Check the current model’s size

Run ollama list and note the tag. Then check the model page to see the parameter count and quantization. A tag without a suffix usually defaults to 4-bit, but some builds default higher. Outcome: you know whether the model is 7B, 13B, or 70B.

Step 3: Pull a quantized replacement

Download a smaller tag:

ollama pull qwen2.5:7b-instruct-q4_K_M

For Llama, use llama3.1:8b-instruct-q4_K_M. Mistral offers mistral:7b-instruct-q4_K_M. Outcome: a model file under 5 GB appears in ollama list.

Check the model library first
Ollama’s model pages list available tags with sizes. Pick the tag that declares a file size near 4.5 GB.

Step 4: Cap the context window

Large context eats VRAM. Create or edit the Modelfile:

FROM qwen2.5:7b-instruct-q4_K_M
PARAMETER num_ctx 4096

Then run ollama create myqwen -f Modelfile. Outcome: the model loads with a fixed 4K context.

Step 5: Limit parallelism and reload

Set OLLAMA_NUM_PARALLEL=1 and OLLAMA_MAX_LOADED_MODELS=1 in your environment, restart the Ollama service, and reload. Outcome: ollama ps reports 100% GPU with headroom below 7 GB.

Tips for better results

Squeezing a model into 8 GB is part engineering, part tuning. These habits keep quality high while staying inside the limit.

Pick the right model class. A strong 7B or 8B model at Q4 usually beats a 13B model at Q2. Small quantization errors compound on tiny models. Qwen2.5 7B, Llama 3.1 8B, and Mistral 7B all run well at Q4_K_M.

Watch the KV cache, not just the weights. The KV cache grows with each token in context. At num_ctx 8192, a 7B model can add 1–2 GB. Dropping to 4096 frees that space instantly. If answers truncate, raise context gradually and re-check nvidia-smi.

Use Q5 when quality matters most. If your task is code generation or precise summarization, try q5_K_M at a 2048 context. It fits in 8 GB and preserves more fidelity. Accept shorter conversations as the trade-off.

Close GPU-hungry apps. A browser with many tabs, a video call, or a game overlay can claim 1 GB of VRAM. Close them before benchmarking so your numbers reflect the model alone.

Prefer smaller batch sizes. Ollama’s num_batch parameter (default 512) controls prompt processing chunks. Setting it to 128 reduces peak memory during long prompts at a small speed cost.

Speed versus fit
Partial GPU offload through num_gpu layers lets a model spill to CPU. It runs, but token speed can drop from 30 tokens per second to under 5.

Benchmark before and after. Run the same prompt twice and note tokens per second from ollama run --verbose. A healthy Q4 7B on an RTX 3060 should produce roughly 30–40 tokens per second. If you see 4, the model is partly on CPU.

Keep the system lean on Linux. On headless servers, disabling the display manager frees several hundred MB. On desktop Linux, the compositor alone can hold 300 MB.

Also on Windows, set the card to prefer maximum performance in the NVIDIA Control Panel; the default power profile can downclock memory and skew your throughput readings. Measure with the same prompt each time so the numbers stay comparable.

Common mistakes to avoid

Most OOM errors come from a handful of repeating causes. Spotting them early saves repeated downloads.

Using an unquantized or Q8 model on 8 GB. A Q8 7B model is 7.7 GB — before context. It will fail or spill. Always check the tag before pulling. A model above 9B parameters at any reasonable quantization rarely fits.

Setting context too high “for safety.” A 32K context sounds generous but can add several GB. Start at 2048 or 4096 and raise only when needed.

Forgetting that Ollama keeps models loaded. By default, a model stays in VRAM for 5 minutes after use. Loading a second model triggers an OOM even though the first chat is closed. Set OLLAMA_KEEP_ALIVE=0 for one-off runs, or set OLLAMA_MAX_LOADED_MODELS=1.

Editing environment variables without restarting. Changes to OLLAMA_NUM_PARALLEL or OLLAMA_MAX_LOADED_MODELS only apply after systemctl restart ollama or a tray restart.

Ignoring shared memory on Windows. Windows WDDM reserves VRAM and can silently cap Ollama below 8 GB. Watching Task Manager’s GPU tab during load reveals the true ceiling. If the model needs more, reduce the context.

Assuming a bigger number is always better. A 13B model at Q2 often produces worse answers than a 7B at Q4, and it may still spill. Match model size to VRAM, not to benchmark leaderboards.

Not verifying the GPU is actually used. If ollama ps shows a split like “55%/45% CPU/GPU,” you never solved the problem — you hid it. Check after every change.

Recheck after driver updates and after any Ollama upgrade, since defaults occasionally shift between releases. Compare the reported GPU percentage against a known-good run rather than trusting a single reading, and repeat the check once the model has handled a long prompt.

Driver mismatches cause false OOM errors
If nvidia-smi reports free memory that Ollama refuses to use, update the driver and CUDA toolkit together. Mixed versions are a common culprit.

FAQ

Will a 13B model run on an 8 GB GPU with quantization?

Only at aggressive quantization, such as Q2 or Q3, and with a small context window. Quality suffers noticeably, and speed drops if any layers spill to CPU. A 7B or 8B model at Q4_K_M is the safer choice for everyday work.

How much VRAM does a 7B Q4 model actually need?

Roughly 4.5 GB for the weights, plus 0.5–1.5 GB for the KV cache depending on context length. At a 4096 context, total usage typically lands near 5.5–6 GB. That leaves a workable margin on an 8 GB card.

Why does Ollama still crash after I picked a smaller model?

Check whether an old model is still resident. Run ollama ps, then stop it with ollama stop <model>. Also confirm your environment variables took effect after a service restart.

Does lowering quantization hurt answer quality?

Yes, slightly, and mostly at Q3 and below. At Q4_K_M the difference is small for chat and summarization. For code or exact reasoning, test Q4 against Q5 and pick what your task tolerates.

Can I run two models at once on 8 GB?

Rarely. Two 3B models at Q4 might fit together, but a 7B plus anything else usually exceeds the limit. Set OLLAMA_MAX_LOADED_MODELS=1 and unload between sessions.

Conclusion

The fix for VRAM exhaustion on an 8 GB card comes down to three levers: a Q4_K_M model tag, a modest context window, and one loaded model at a time. Together they keep usage under 7 GB and preserve most of the model’s quality. Larger models do not automatically mean better answers when the card forces aggressive compression. Treat the tag suffix and num_ctx value as your primary controls, and verify with ollama ps after every change. Start now by running nvidia-smi alongside a test prompt, then pull the Q4 tag of the model you actually use and compare the speed. That single change usually turns a dead terminal into a working local assistant.

About the author

Max Walker

Max Walker

Max Walker is a trend spotter and writer with a keen eye for emerging patterns in culture, technology, and business. He's passionate about exploring the forces shaping our future.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *