How to Estimate LLM VRAM Requirements and Choose Quantization Settings for Local Deployment
Most open-weight model cards quote the theoretical BF16 footprint of the raw weights. That number tells a local deployment almost nothing useful, because real inference consumes far more VRAM than the weights alone: intermediate activations, attention cache, and the runtime overhead of the inference framework itself. Budget hardware against weight size only, and the out-of-memory error will almost certainly hit right after the model finishes loading, the moment actual inference begins. This guide breaks VRAM usage into its component parts, walks through the weight-size formula, explains why mixture-of-experts (MoE) models behave differently, shows how KV cache scales with context length, and gives a reusable estimation script plus per-VRAM-tier recommendations. Estimate first, quantize second, leave headroom third.
1. Why the “Theoretical” Number Is Rarely Enough
Many open-weight models publish a theoretical figure based on BF16 raw precision. For anyone deploying locally, that number has limited reference value. Actual runtime VRAM consumption goes well beyond the weights themselves: it also includes intermediate tensors produced during inference, the attention (KV) cache, and the runtime overhead of the inference framework. If you size hardware against the weight footprint alone, an out-of-memory failure is nearly guaranteed to appear once the model finishes loading and real inference starts.
So it pays to build a habit of estimating component by component and then leaving headroom, rather than memorizing a single number. The rest of this guide starts from what VRAM is actually spent on.
2. The Four Components of VRAM Usage
A single local inference run consumes VRAM across four categories:
- Model weights — tied directly to parameter count and quantization precision. This is the largest and by far the easiest component to estimate.
- KV cache (attention cache) — grows roughly linearly with context length and batch size. It is the hidden cost that most easily runs out of control on long-context workloads.
- Activations and intermediate tensors — created transiently during inference. Modest for a single request, but they scale noticeably with batch size.
- Framework and runtime overhead — the inference engine, CUDA context, VRAM fragmentation, and similar costs. Budget somewhere between 0.5 and 1.5 GB.
What actually determines whether a configuration runs stably is the sum of all four, not any one of them.
3. The Weight VRAM Formula
The core formula for weight footprint is straightforward:
Weight VRAM (bytes) ≈ parameter count × bytes per parameter
Typical values for “bytes per parameter” at each precision level:
| Precision | Bytes per parameter | Notes |
|---|---|---|
| BF16 / FP16 | 2 | Native precision; best quality, highest footprint |
| INT8 | 1 | Small quality loss, half the footprint |
| INT4 | ≈0.5 | The mainstream quantization tier; slightly above 0.5 once metadata is included |
A few 4-bit estimates:
- ~4B model: 4 × 10⁹ × 0.5 B ≈ 2 GB of weights
- ~26B model: 26 × 10⁹ × 0.5 B ≈ 13 GB of weights
- ~31B model: 31 × 10⁹ × 0.5 B ≈ 15.5 GB of weights
This explains why small models start comfortably on low-VRAM devices while anything above roughly 20B parameters demands a much higher VRAM tier. Note that the table above is a general-purpose approximation; real figures shift slightly depending on the quantization scheme, vocabulary size, and metadata.
4. What Makes MoE Models Different
Consider a model described as “26B total, roughly 4B activated.” It uses a mixture-of-experts architecture: about 26B parameters in total, but only about 4B of them participate in computation for any given token. That leads to a conclusion people frequently get backwards:
- VRAM footprint is determined by total parameters. Every expert’s weights must stay resident in VRAM, so the requirement is in the ~13 GB range, not the ~2 GB of a 4B model.
- Inference speed tracks the activated parameters. Because each step only computes the 4B active parameters, throughput is often better than that of a dense model with the same total parameter count.
This distinction matters a great deal when choosing a model. MoE trades VRAM for speed, but whether a model loads at all still depends on the total weight footprint, not the active parameter count.
5. KV Cache: The Key Variable in Long-Context Scenarios
The size of the KV cache is approximately proportional to context length, layer count, attention head dimension, and batch size:
KV cache ≈ 2 × layers × hidden_dim × sequence_length × batch_size × bytes_per_element
The factor of 2 accounts for storing both the Key and the Value tensors. Stretch the context from 2K to 32K and this component can grow by more than an order of magnitude — a difference of several gigabytes is enough to push a configuration that “just barely fit” straight into an overflow. When planning VRAM for a local deployment, budget for your target context length rather than defaulting to the shortest one.
6. A Reusable Estimation Script
The pseudocode below ties the logic together so you can sanity-check your own configuration quickly:
def estimate_vram_bytes(num_params, bits, layers, hidden_dim,seq_len, batch=1, overhead_gb=1.0):# 1. Weight footprintweight_bytes = num_params * (bits / 8)# 2. KV cache (assuming an FP16 cache, 2 bytes per element)kv_bytes = 2 * layers * hidden_dim * seq_len * batch * 2# 3. Framework and runtime overheadoverhead = overhead_gb * (1024 ** 3)total_gb = (weight_bytes + kv_bytes + overhead) / (1024 ** 3)return round(total_gb, 1)
Plug in the parameter count, quantization bit width, and target context length and you get an estimate much closer to real runtime behavior. Add another 15–20% on top as a safety margin.
7. Choosing Settings by VRAM Tier
Putting the estimates together, hardware tiers can be planned roughly as follows (figures are empirical ranges, for reference only):
- ~6 GB VRAM: Prioritize ~4B-class models with 4-bit quantization — around 2 GB of weights, leaving room for a full run within 4–6 GB. Attempting a 20B+ model here will very likely fail during loading.
- 8–12 GB VRAM: 4B-class models run comfortably, and it is worth evaluating low-bit quantized versions of 26B-class MoE models. Pay particular attention to KV cache growth from context length, and avoid running at the absolute limit.
- 12–16 GB VRAM: The range where 26B-class MoE models become worth seriously trying. “It starts” is not the same as “it runs stably” — focus on observed inference speed rather than the nominal parameter count.
- 24 GB and above: Quantized versions of 31B-class models are worth a try, offering noticeably better long-context and code capability.
For devices with a unified memory architecture, such as high-memory thin-and-light laptops or workstations, VRAM and system RAM are shared. The selection logic is identical, but you should additionally watch whether system memory is being contended for by the model and other applications.
8. Practical Lessons
- Estimate before installing. Compute the weight footprint with the formula in Section 3, add KV cache and overhead, and compare the total against your hardware ceiling before deciding on a quantization tier.
- Pick the quantization tier based on quality needs. 4-bit is the mainstream choice balancing cost-effectiveness and quality; when higher fidelity is required, move up to 8-bit and increase the VRAM budget accordingly.
- Set context length only as needed. Unless you genuinely work with long documents, there is no reason to max out the context window from the start — it is a VRAM sink.
- Watch actual throughput, not just “it loads.” A successful start is only step one; an acceptable tokens-per-second rate is the real usability bar.
- Always leave headroom. Keeping a 15–20% VRAM buffer absorbs runtime fluctuation and fragmentation.
Conclusion
The VRAM problem in local LLM deployment comes down to a component-wise sum — weights plus cache plus overhead — weighed against the headroom your hardware provides. Once you understand the parameter-count-to-precision conversion, the VRAM/speed tradeoff of MoE architectures, and how KV cache scales with context length, you can make reliable decisions for a given piece of hardware without relying on any single “standard answer.” Estimate, quantize, leave headroom: those three steps cover the vast majority of local inference scenarios.
