Local LLM VRAM Estimation and Hardware Selection: A Complete Guide
A practical guide to estimating how much VRAM a local LLM actually needs and choosing the right hardware. It breaks total memory usage into model weights, KV cache, and runtime overhead, provides a reusable estimation script plus quick-reference tables for common model sizes, and explains how to tell whether your workload is limited by VRAM capacity or memory bandwidth. It also covers hardware selection across discrete-GPU and unified-memory platforms, tuning priorities when memory runs short, and practical alternatives to buying new hardware.
When people first start deploying models locally, many treat the vendor’s raw BF16 weight size as the hardware requirement. A 7B model, for example, is about 14GB in BF16, which makes 16GB of VRAM look “just enough.” Yet during actual loading, it frequently fails with out-of-memory errors. The reason is simple: that number counts only the static model itself and ignores the caches and runtime overhead generated dynamically during inference.
A VRAM budget can be summarized as:
Total usage ≈ model weights + KV cache + activations and runtime overhead + safety margin
The sections below first lay out the estimation formulas, then give selection advice for both discrete-GPU and unified-memory hardware. Note that the layer counts, attention head counts, and other parameters in the examples are used only to demonstrate the calculation. For real selection, always use the actual values from your model’s configuration.
1. Breaking Down VRAM: Weights Are Only a Third of the Story
Model weights: determined by parameter count and quantization bit-width
Weights are the part that stays fixed after deployment, so the estimate is straightforward: parameter count × bytes per parameter. How many bytes each parameter takes depends on the storage precision and quantization scheme:
| Storage format | Avg bytes per parameter (approx) | Notes |
|---|---|---|
| FP32 | ~4.0 | Usually only for fine-tuning, evaluation, and similar scenarios |
| BF16 / FP16 | 2.0 | The size of the original weights as labeled by the vendor |
| 8-bit quantization | ~1.05 | Close to full precision, with a relatively high VRAM cost |
| 4-bit group quantization | ~0.53–0.63 | Finer groups give higher accuracy but larger metadata overhead |
Take 4-bit group quantization as an example: each weight occupies half a byte, and every 32 or 128 weights share a group of scaling factors (some schemes also store zero points). Computing this at 16 bits per group with 2 parameters, the extra overhead is roughly 1/16 to 1/64 byte per parameter, i.e. 0.0625 to 0.0156 byte, for a total of about 0.53–0.63 byte. So the rough conversion is: every billion parameters takes about 0.6GB at 4-bit, about 1.1GB at 8-bit, and about 2GB at BF16. In practice, it’s wise to reserve 0.65–0.7GB per billion parameters to leave margin for differences between quantization formats.
KV cache: context length is the real VRAM killer
During autoregressive generation, the model must revisit all prior history every time it produces a token. To avoid recomputation, the framework caches each layer’s Key and Value tensors for the tokens already processed. That is the KV cache. It scales linearly with sequence length, and the formula is:
KV bytes = 2 × num_layers × num_kv_heads × head_dim × seq_len × batch_size × bytes_per_element
Here the factor of 2 accounts for the two caches, K and V; and under mechanisms like grouped-query attention (GQA), the number of KV heads is typically far smaller than the total number of attention heads. Take a typical dense model with 32 layers, 8 KV groups, a head dimension of 128, and 16-bit caching: each token takes 2×32×8×128×2 = 131072 bytes, i.e. 128KB. From this:
| Context length | Single session | 4 concurrent |
|---|---|---|
| 4K | 0.5GB | 2GB |
| 8K | 1GB | 4GB |
| 32K | 4GB | 16GB |
| 128K | 16GB | 64GB |
Double the context and the KV cache doubles too; then multiply by the number of concurrent sessions, and it’s easy to exhaust VRAM. A model supporting a 128K context doesn’t mean a 128K context will actually run.
Activations and runtime overhead: don’t cut it too close
Runtime overhead is invisible but always present. It mainly includes:
- Intermediate activations: attention scores, intermediate layer tensors, and so on produced by each forward pass, whose size relates to batch size and sequence length;
- Dynamic allocation: the framework’s caching allocator repeatedly requests and frees VRAM blocks, and long-running services tend to accumulate fragmentation;
- Prefill peaks: the longer the first prompt and the larger the batch, the higher the instantaneous usage during computation.
When VRAM is just barely enough with no margin, the typical symptom is “it starts up, but errors out as soon as it hits a long prompt or a multi-turn conversation.” It’s recommended to leave at least a 10%–20% safety margin; for inference services, add another 1–2GB on top.
2. A Reusable VRAM Estimation Script
The script below depends on no third-party libraries and parameterizes all three components plus the margin, so you can try it against your own model configuration:
def estimate_vram(params_b, layers, kv_heads, head_dim,ctx_len=8192, batch=1, kv_bytes=2,bytes_per_param=0.65, safety_ratio=0.15):"""Estimate VRAM usage for a single forward pass, returned in GiB (1 GiB = 1024^3 bytes).bytes_per_param: default assumes 4-bit group quantization (0.65 already includes quantization metadata and margin)kv_bytes: bytes per element in the KV cache, 2 for 16-bit, 1 for 8-bit"""weight = params_b * bytes_per_paramkv = 2 * kv_bytes * layers * kv_heads * head_dim * ctx_len * batch / 1024**3runtime = 1.0 # empirical value for intermediate activations and runtime overhead; for serving, raise to 1.5–2.0total = (weight + kv + runtime) * (1 + safety_ratio)return {"weight": round(weight, 2), "kv_cache": round(kv, 2),"runtime": round(runtime, 2), "total": round(total, 2)}# Example: a 32B dense model with 32 layers, 8 KV heads, and head_dim of 128print(estimate_vram(params_b=32, layers=32, kv_heads=8, head_dim=128, ctx_len=32768))# {'weight': 20.8, 'kv_cache': 4.0, 'runtime': 1.0, 'total': 29.67}
For the same model, changing ctx_len to 8192 brings total usage down to about 23.0GB, and to 4096 it drops to about 20.7GB. Under identical hardware, simply adjusting the context length can cross an entire VRAM tier. That is exactly what “long context is a VRAM killer” looks like in numbers.
Quick reference: rough thresholds by parameter scale
Weights are estimated at 4-bit, KV cache is computed with the typical configuration above, and the figures assume a single session at an 8K context. Actual values depend on the model configuration you use:
| Model size | 4-bit weight size | Total usage at 8K context | Recommended starting VRAM |
|---|---|---|---|
| 2B–4B | 1.3–2.6GB | ~4–5GB | 6–8GB |
| 7B–8B | 4.6–5.2GB | ~7–8GB | 10–12GB |
| 13B–14B | 8.5–9.1GB | ~11–12GB | 14–16GB |
| 32B dense | 20.8GB | ~23GB | 24GB+ |
| 26B total / ~4B active MoE | 16.9GB | ~19GB | 24GB+ |
3. Identify the Bottleneck First: VRAM Capacity vs Memory Bandwidth
Before choosing hardware, figure out what mainly constrains your task. There are two broad categories:
- Prefill-heavy tasks like long-document analysis and code understanding: they process a long input in one pass, so the bottleneck is compute and memory bandwidth, with VRAM capacity as a hard threshold;
- Decode-heavy tasks like everyday chat and content generation: they produce text token by token, and each token requires moving all weights from VRAM into the compute units once. These tasks are bandwidth-bound, and the throughput ceiling can be roughly estimated as:
Theoretical decode speed (token/s) ≈ memory bandwidth (GB/s) ÷ weight bytes read per token (GB)
Take a 4-bit 7B model as an example: each token requires reading about 4.6GB of weights. At 500GB/s of memory bandwidth, the theoretical ceiling is about 500÷4.6≈109 token/s; at 900GB/s, it’s about 196 token/s. Real speed is usually only a fraction of the theoretical value, affected by compute-unit utilization, sampling strategy, and framework implementation. But this formula is enough to explain why “the same model runs at wildly different speeds on different GPUs.”
It also leads to an important conclusion: for a mixture-of-experts (MoE) model, the total parameter count determines VRAM usage, while the active parameter count determines decode speed. For instance, a 26B-total MoE model that activates only about 4B parameters per inference uses nearly the same VRAM as a 26B dense model but decodes at a speed close to a small 4B model. So such models offer the best “quality per cost” on a machine with ample VRAM but mediocre bandwidth.
4. Choosing a Discrete-GPU Platform: Match Your VRAM Tier
| VRAM tier | Feasible model size at 4-bit | Selection notes |
|---|---|---|
| ~6GB | 2B–4B | Keep context under 4K; don’t run multiple sessions at once |
| 8–12GB | 7B–8B | 8K context is safe; 32K+ needs an evaluation of KV usage |
| 14–16GB | 13B–14B, or a 7B model at 8-bit | At the same capacity, pick one: a bigger model at lower precision, or a smaller model at higher precision |
| 24GB+ | 32B dense, 26B MoE | Long context and high concurrency are still strained; leave margin |
| 48GB+ | Multiple concurrent 32B models, or consider higher precision | Concurrency is mostly determined by VRAM capacity |
Three reminders:
- Can 16GB run a 26B-class MoE? Its 4-bit weights alone take about 17GB, and once you add KV and runtime overhead, 16GB will almost certainly overflow at default precision. Prefer the 24GB tier. Attempting it on a 16GB card requires more aggressive quantization or shorter context, and the experience is hard to enjoy.
- Starts up ≠ runs stably: whether it loads depends only on weight size, but whether it runs smoothly also depends on KV and concurrency. After loading just the weights, whatever VRAM remains is your budget for context and concurrency.
- Multi-GPU isn’t simple addition: two 12GB cards total 24GB, but tensor parallelism needs frequent inter-GPU communication, and bandwidth differs between cards. Whether it works, and how well, must be measured, not planned by adding capacities together.
5. Evaluating Unified-Memory Devices
On devices with integrated-graphics architectures (whether laptops, mini PCs, or all-in-ones), the CPU and integrated GPU share the same memory pool, and there is no separate VRAM. So the evaluation shifts to “memory budget” and “memory bandwidth.”
Memory budget: leave enough room for the OS and other programs
The available memory shown on screen isn’t all you can give to the model. The operating system, browser, dev tools, and similar programs already take several GB, and the integrated GPU also reserves part of the memory as a display and runtime buffer. With 32GB of unified memory, for example, often only just over 20GB is actually available to the model. Plan accordingly:
| Available memory (rule of thumb) | Feasible option |
|---|---|
| 16GB device, ~10GB for the model | 7B–8B 4-bit model, short context |
| 32GB device, ~20–24GB for the model | 13B–14B 4-bit model, or a 8B 8-bit model with longer context |
| 64GB+, ~45GB+ for the model | 32B dense or 26B MoE model, with support for longer context |
Memory bandwidth: it sets the speed ceiling
Unified memory usually has clearly lower bandwidth than high-end discrete GPUs, which constrains decode speed even more. Using the formula above: a GPU with 900GB/s running a 4-bit 7B model needs to move about 4.6GB of weights per token; a device with 200GB/s running the same model needs to move the same 4.6GB. In other words, even when memory is sufficient, decode speed roughly drops in proportion to bandwidth.
In addition, on some unified-memory devices, model compute can also be limited by CPU compute, especially during the prefill phase with long prompts. Real performance is closely tied to how well the inference framework is adapted to the device, so it’s best to rely on real-workload testing.
6. Tuning Priority: Cut Context First, Then Concurrency, and Only Lower Precision Last
When VRAM runs short, many people’s first instinct is to switch to a lower-bit model, but the accuracy loss is often irreversible. A more sensible order is:
- Shorten the context: 8K is enough for most chat scenarios, and contexts above 32K often serve only a few long-document tasks, so you can configure them per task;
- Limit concurrency: set it to a single session for local, single-user use, and open it up gradually only when serving others;
- Quantize the KV cache: dropping a 16-bit KV to 8-bit halves KV usage outright. This trades a controllable quality loss for a clear gain in VRAM, and it pays off most in long-context scenarios;
- Adjust quantization granularity: for quality-sensitive models, prefer a 4-bit version with finer grouping rather than jumping straight to a lower precision;
- Only then consider lowering weight quantization precision: 4-bit is a fairly balanced choice for local deployment today, and going lower should first be validated with real-workload quality comparisons.
After tuning, test two things: whether VRAM stays stable without creeping up after 30+ minutes of continuous inference; and whether it still overflows during multi-turn long conversations and batch requests. The former checks for memory leaks and fragmentation, the latter validates the concurrency budget.
7. Beyond Buying New Hardware
VRAM is never big enough. Beyond upgrading hardware, there are two practical paths:
- CPU–GPU hybrid inference: place some layers in memory and others in VRAM to break through the VRAM capacity limit, at the cost of a noticeable drop in speed. It fits scenarios where “slow is acceptable, but it must run”;
- On-demand cloud usage: if you only occasionally need a large model, or need to support many concurrent users, then rather than a one-time investment in high-VRAM hardware, it’s better to call it on demand in the cloud by usage. Enterprise-grade applications can combine serverless/function-compute and container services, load the model on demand from object storage, and track call quality with log services and monitoring alerts.
8. Deployment Checklist
- Confirm the model’s actual parameter count, distinguishing total from active parameters;
- Fill in the layer count, KV head count, and head dimension from the official configuration, and plug them into the formula to get the per-token KV cost;
- Set the target context length and concurrency to derive budgets for the three parts: weights, KV, and runtime;
- Against the hardware’s available VRAM (or the available memory on a unified-memory device), leave around 20% margin;
- Get it running with a short context first, then gradually increase length and concurrency while watching the VRAM curve and decode speed;
- Lock in a parameter configuration that matches your serving scenario, so you avoid “it works this time, but breaks when someone else runs it.”
Back to the original question: “how much VRAM does this model need” has no single answer. It is jointly determined by quantization precision, context length, and concurrency. Rather than trusting any one reference table, it’s better to master this breakdown-and-estimation method, so that every number can be traced to its source. Test your own machine first, then decide which upgrade is worth it, which is often more cost-effective than simply swapping in a new card.
