How to Calculate VRAM for Local LLM Deployment: Quantization and Model Selection Pitfalls
Deploying an open-source large language model locally usually starts with one question: how much VRAM does it actually need? The answer is rarely just the weight size listed on a model card, because real inference also allocates memory for KV cache, runtime buffers, and quantization metadata. This article breaks local LLM VRAM usage into its four components, provides a repeatable estimation formula for weights and KV cache, and maps typical parameter sizes (roughly 2B, 4B, 26B, and 31B) and quantization levels (INT8, INT4) to practical VRAM tiers. It also covers unified memory devices, how to avoid out-of-memory failures when moving from short to long context, a step-by-step fallback order once you do hit the limit, and a checklist for validating a deployment against your own workload instead of benchmark scores.
Introduction: Theoretical VRAM Is Not the Same as What Actually Runs
When deploying open-source large language models locally, the most common question is: “How much VRAM does this model actually need?” Model cards usually quote weight memory under half precision (BF16/FP16), but that number is only a starting point. At runtime, VRAM usage is not made up of weights alone. It also includes the KV cache, runtime overhead, and quantization metadata. Many cases of “the weights look like they fit, but VRAM blows up on the first inference pass” come from counting only the weights and never estimating the total runtime cost.
So the goal of VRAM planning is not to find a single answer to “what is the largest parameter count I can run.” It is to build a reproducible estimation method: start with weights, then account for KV cache driven by context length and concurrency, then reserve headroom for runtime peaks, and finally validate against the quantization tier and the actual task you care about. Choosing a model, a quantization level, and a context length this way is far less likely to end in failure.
What VRAM Usage Is Actually Made Of
VRAM used by a single local inference process can be broken into four parts: model weights, KV cache, runtime overhead, and quantization metadata.
1. Model Weights: The Baseline
Model weights are the most obvious component. They depend on the parameter count and the number of bytes per parameter.
Weight VRAM ≈ parameter count × bytes per parameter
Common mappings:
- FP16 / BF16: roughly 2 bytes per parameter
- INT8: roughly 1 byte per parameter
- INT4: roughly 0.5 bytes per parameter
For example, a 31B parameter model with INT4 quantization:
31B × 0.5 ≈ 15.5GB
This is only the weight portion. It does not include KV cache, runtime buffers, or quantization metadata.
2. KV Cache: The Main Source of Growth from Long Context and Concurrency
Many people focus on weights and overlook the KV cache. KV cache grows with context length and the number of concurrent requests, and it is the primary source of extra VRAM consumption in long-document, multi-turn conversation, and batched request scenarios.
A rough approximation:
KV ≈ 2 × layers × KV heads × head_dim × sequence length × concurrency × bytes per parameter
Two things to watch here. If the model uses an architecture like GQA or MQA, the number of KV heads changes. If KV quantization is enabled, the bytes per parameter also change. As a result, KV cache size for the same context length can vary enormously between model architectures.
3. Runtime Overhead: Do Not Treat It as a Fixed Constant
Runtime overhead covers operator workspace buffers in the inference framework, temporary tensors, memory pools, and fragmentation. It is not a permanently fixed “small overhead.” It shifts with batch size, sequence length, cache pool settings, and fragmentation behavior, so it should be budgeted for at peak.
In other words, you cannot pick a configuration based only on “weights + theoretical KV.” You also need to account for the additional memory the inference framework claims at its peak.
4. Quantization Metadata: Real Compression Is Slightly Below Theory
Low-bit quantization does not store parameters alone. It also carries scaling factors, zero points, block information, calibration tables, and similar metadata. Consequently, the actual file size and actual VRAM footprint of an INT4 model are usually slightly higher than the theoretical “parameter count × 0.5.”
Rough Estimation: Get the Total First, Then Choose
A practical order of judgment:
- Estimate weight VRAM first.
- Then estimate KV cache at your target context length.
- Add 10%–20% runtime headroom.
- Finally, validate with your own real workload.
The table below is an illustrative reference for quick comparison.
| Parameter size | Quantized weight VRAM | Recommended VRAM tier | Suitable scenario |
|---|---|---|---|
| ~2B (lightweight) | ~2–4GB | 4GB tier is the minimum; 6GB is more stable. Below 4GB, running FP16 or long context directly is not advisable | Validating a minimal end-to-end path |
| ~4B (small) | ~4–6GB | Start at a 6GB or 16GB unified memory tier | Most people’s first local experience |
| ~26B (sparse / mixture of experts) | ~12–16GB | 16GB is more comfortable. This row is estimated on total parameters; MoE expert routing does not change weight residency. If the total parameter count pushes weights beyond available VRAM, switch to a smaller model or use CPU offload | Wanting stronger reasoning without jumping to the heaviest model |
| ~31B (larger dense) | ~20–24GB | 24GB and above | Prioritizing quality, coding ability, and long context |
The word “approximately” in this table matters. These are reference ranges, not guarantees. Actual usage is affected by the quantization method, context length, concurrency, the inference framework, and whether KV quantization is enabled.
Choosing by VRAM Tier
Around 6GB
This tier should first run a small ~4B version and get the end-to-end pipeline working. A ~26B or ~31B model is not impossible to attempt, but making one of them your default starting point makes it easy to blow through VRAM during loading or the first inference pass.
If the quantized weights already come close to the tier’s ceiling, reduce context length or concurrency, enable KV quantization, or use CPU offload. Otherwise you may run out of VRAM.
8–12GB
A ~4B version is more comfortable at this tier, and you can start evaluating quantized builds at medium scale. Do not pick a configuration that sits right at the theoretical limit. Leave room for context length, concurrency, and runtime peaks.
12–16GB
This is where a ~26B mixture-of-experts build starts to be worth seriously attempting. At this tier, “it boots” does not mean “it runs stably.” Pay more attention to actual inference throughput, time to first token, and long-context behavior.
The same caution applies as above: if quantized weights already sit near the tier’s ceiling, reduce context length or concurrency, enable KV quantization, or use CPU offload, or you may run out of VRAM.
24GB and Above
A ~31B dense model is a more worthwhile investment at 24GB and above. That said, the VRAM tier is only a reference. Long context still increases KV cache usage substantially. After deployment, keep monitoring the VRAM curve, especially when switching from short to long context and from a single conversation to multiple concurrent ones.
How to Choose Unified Memory Devices
On devices with a unified memory architecture, the processor and the graphics unit share the same physical memory, so there is no strictly separate “VRAM.” Two factors matter most when choosing here:
- Total memory capacity: This determines whether model weights and KV cache fit entirely. Do not assign all memory to the model. Leave headroom for the system, caches, and other programs.
- Memory bandwidth: This sets the upper bound on inference speed. When capacity is sufficient but bandwidth is not, generation speed for larger models can be noticeably limited.
On a unified memory device, you can start with a small test: generate continuously with a short prompt and observe whether tokens/s is acceptable. If bandwidth is insufficient, decide whether to keep pushing toward a larger parameter model or fall back to a smaller one.
Quantization Precision: Trading VRAM Against Quality
Quantization is unavoidable in local deployment. Common tiers include INT8, INT4, and some more aggressive low-bit formats. The core trade-off:
- Lower precision means less VRAM and faster inference, but output quality may drop.
- Higher precision means more stable quality, but greater pressure on VRAM and bandwidth.
A rough guide:
| Scenario | Recommendation |
|---|---|
| Within 4B on a low-VRAM device | Try INT4 first to guarantee it runs |
| 7B–13B on 12–16GB VRAM | Prefer INT4; try INT8 when quality matters |
| 31B on 24GB VRAM | Prefer INT4; coding, complex reasoning, or long tasks may need higher precision |
| Code generation, long reasoning chains | Keep higher precision where possible, or choose a larger model, and test with your real workload |
One caveat: larger models generally have some quality margin, which can partially offset the loss from quantization in certain situations. That is an empirical observation, not an absolute rule. In the end, run a small-scale comparison on your own real task samples rather than relying only on general benchmark scores.
How to Avoid Running Out of VRAM with Long Context
Many out-of-memory failures are not caused by the model being too large, but by the context length being underestimated. Moving context from a few thousand tokens to tens of thousands can multiply KV cache size, enough to fill VRAM that looked comfortable.
A simple rule of thumb:
KV grows approximately linearly with sequence length
For example, with everything else held constant, moving context from 8K to 32K makes the sequence 4× longer, and KV cache grows by close to 4×. If you also increase concurrency at the same time, memory pressure rises further.
Recommended strategies:
- Get it working with a shorter context first, then extend it step by step while watching the VRAM curve.
- Reserve explicit headroom for long-context scenarios rather than sitting at the theoretical ceiling.
- Check whether your inference framework supports optimizations such as KV cache reuse, KV quantization, and paged caching.
- Evaluate multi-request concurrency separately, because concurrency amplifies KV cache further.
FAQ: Why Does It Run Out of VRAM When the Weights Fit?
Because weights are only one part of VRAM usage. During actual inference, you also need room for KV cache, temporary operator tensors, memory pools, and fragmentation. If the context is long, concurrency is high, or the framework makes large peak allocations, VRAM can overflow during inference.
How Do I Estimate KV Cache Growth Going from 8K to 32K Context?
Start with the formula:
KV ≈ 2 × layers × KV heads × head_dim × sequence length × concurrency × bytes per parameter
With other parameters unchanged, increasing sequence length from 8K to 32K grows KV cache to roughly 4× the original. If the model uses GQA/MQA, or if KV quantization is enabled, recalculate based on the actual architecture.
Fallback Steps After Running Out of VRAM
If you do run out of VRAM, degrade in this order:
- Reduce context length.
- Reduce concurrency.
- Switch from INT8 to INT4.
- Enable KV quantization.
- Enable CPU offload, moving some weights or KV to system memory.
- Switch to a smaller model or a lighter architecture.
- Check whether the inference framework is using an oversized batch size or memory pool.
Best Practices Checklist
- Get the total before choosing: Estimate with “weights + KV cache + runtime overhead,” not weights alone.
- Leave enough headroom: Reserve roughly 10%–20% VRAM for fragmentation, caches, and peak fluctuation.
- Start small, then scale up: Validate the pipeline with a small parameter version before moving to larger models.
- Validate with your real workload: Speed, quality, and stability should be judged against your own tasks. General benchmarks are only a reference.
- Keep monitoring: After deployment, watch the real VRAM and throughput curves, especially once you extend context length and raise concurrency.
Conclusion
Configuring VRAM for local deployment of an open-source large language model is fundamentally about balancing hardware capacity, quantization precision, context length, and output quality. The theoretical weight figure is only a starting point. A decision that actually holds up in practice has to factor in KV cache, runtime overhead, concurrency scale, and the bandwidth constraints of unified memory architectures. Choosing by tier, leaving enough headroom, and validating with your real workload is the reliable path to avoiding out-of-memory failures and getting a stable experience.
