Local LLM VRAM Requirements: Quantization Testing and Hardware Selection

    Running open-source LLMs locally makes VRAM the first practical hurdle, yet the figures quoted for open-weight releases usually describe only the theoretical size of raw BF16/FP16 weights. This guide turns the key variables—parameter count, quantization precision, activated parameters, and context length—into a practical method for estimating VRAM from theoretical size to real usage. It provides a quick-reference table of VRAM requirements across model sizes and quantization levels, a breakdown of weights, KV cache, and runtime overhead, hardware tier recommendations spanning 6 GB to 24 GB GPUs and unified-memory platforms, a Python script for estimating VRAM at different context lengths, and a reliable local benchmarking workflow, along with common pitfalls to avoid.

    Running an open-source LLM locally, the first hurdle you cannot avoid is often whether you have enough VRAM. When an open-weight model is released, the figure its authors usually quote is the theoretical size of the raw BF16/FP16 weights. For local users planning to run a quantized version, that number is of limited value: it accounts for neither the cache and context overhead during inference nor the actual deviation introduced by the quantization format. This guide builds an estimation approach that goes from “theoretical size” to “measured usage,” organized around a few key variables—parameter count, quantization precision, activated parameters, and context length—and offers selection advice by VRAM tier.

    1. Quick Reference: VRAM Requirements

    The table below summarizes the VRAM requirements of mainstream model sizes under different quantization precisions. The values are empirical references for typical ranges; actual usage fluctuates with the inference framework, context length, and concurrency, so treat the method in Section 7 as authoritative for re-measuring on your target machine.

    Parameter scale Typical quantization Inference VRAM (incl. overhead) Recommended starting VRAM tier Use case
    2B class 4–8 bit ~2–4 GB 4 GB and up Validating the minimal runnable pipeline; lightweight Q&A and text rewriting
    4B class 4–8 bit ~4–6 GB 6 GB GPU or 16 GB unified memory The first local experience for most users
    26B class, sparse activation (~4B activated per token) 4–5 bit ~12–16 GB 12 GB to start, 16 GB for more comfort Stronger reasoning without the VRAM cost of a large model
    31B class 4–5 bit ~20–24 GB 24 GB and above Generation quality, coding ability, and long context matter more

    Use this table to “pick a tier with headroom,” not to “cut it close to the ceiling.” There are two reasons:

    • The quantization ranges here are generally conservative; low-bit quantization causes precision loss, so for important scenarios, compare multiple precision tiers on your target hardware before deciding.
    • Inference VRAM is not fixed; it keeps rising with context length, batch concurrency, and cache growth.

    The right approach is to select a tier based on your typical context length with 15%–25% headroom; see Section 4 for the specific calculation.

    2. Why the Official Numbers Are Only a Rough Reference

    The weight-size formula itself is not wrong; the problem lies in three places:

    • It describes “static storage requirements.” What actually consumes VRAM during inference is the sum of weights, the KV cache, framework overhead, and intermediate activations.
    • It is based on the original precision. What local users actually run is mostly quantized models, where the weights themselves shrink to about half or even less.
    • It cannot reflect engineering differences. For the same “4-bit model,” different quantization schemes can differ noticeably in VRAM usage and inference speed.

    Therefore, VRAM planning cannot just ask “how big is this model” but must answer three questions: where the weights are stored, at what precision, and how much room is left for context. If any one of the three is not accounted for, you can trigger an OOM (out-of-memory) error a few turns into a conversation.

    3. Understand the Architecture: Dense vs. Sparse-Activation Models

    Open-weight models commonly used locally fall into two broad categories. At similar parameter scales, the two place different demands on hardware:

    • Dense models: every token passes through all parameters for computation, so VRAM requirements grow in step with compute.
    • Sparse-activation models: composed of multiple “expert” subnetworks, where each token activates only a small fraction of them. Take a model with “26B total parameters, ~4B activated per token” as an example: the weights must be loaded into VRAM in full, but a single token actually uses only about one-sixth of the parameters.

    This is exactly what makes the 26B-class row in the table most noteworthy. Its VRAM requirement is comparable to that of a dense model at the same scale, yet its compute for a single inference is close to that of a 4B-class dense model. In other words, on a machine with ample VRAM, a sparse-activation model can deliver capabilities close to a large model at a response speed close to a small model. But two boundaries must be kept in mind:

    • VRAM is occupied according to “total parameters” and cannot be estimated from “activated parameters.”
    • When processing multiple requests in a batch, different tokens activate different experts, so the parameters actually used in computation increase and response latency rises accordingly.

    4. Breaking Down VRAM Usage into Three Parts

    Weights: Determined by Parameter Count and Quantization

    The size of quantized weights can be estimated with the general empirical formula below:

    1. weight VRAM ≈ total parameters × bytes per parameter × (1 + quantization metadata overhead)
    2. where: bytes per parameter = quantization precision (bit) / 8

    Bytes per parameter for different precisions:

    • FP16/BF16: 2 bytes
    • 8-bit: 1 byte
    • 4-bit: 0.5 byte

    Grouped quantization must also store metadata such as scale factors for each quantization block, and the overhead depends on the group size, usually 5%–15% overall. By this calculation:

    Total parameters FP16 (theoretical) 8-bit 4-bit (incl. metadata)
    2B ~4 GB ~2.5 GB ~1.5 GB
    4B ~8 GB ~4.5 GB ~2.5 GB
    26B (sparse activation) ~52 GB ~28 GB ~15 GB
    31B ~62 GB ~33 GB ~18 GB

    As you can see, switching from FP16 to 4-bit reduces the weight size to about a quarter. But the “weight table” is only the first step in VRAM planning.

    KV Cache: The Hidden Cost That Grows Linearly with Context

    When an LLM processes text, it caches the Key and Value vectors for every previous token at each layer to avoid recomputation—this is the KV cache. Its size is directly related to the model architecture, context length, batch size, and cache precision:

    1. KV cache = 2 × layers × KV heads × head dim × sequence length × batch size × bytes per element

    Take a model with 32 layers, 8 KV heads, and head dim 128 as an example:

    • The cache for a single token is about 2 × 32 × 8 × 128 × 2 = 128 KB (at FP16).
    • A context of 10,000 tokens takes about 1.25 GB; 100,000 tokens takes about 12.5 GB, which already exceeds the entire set of weights of a 26B-class 4-bit model.

    If you also process 4 concurrent requests at once, this number must be multiplied by 4 again. In long-context scenarios, the KV cache often exhausts VRAM before the weights do.

    Runtime Overhead and Fragmentation

    Beyond weights and the KV cache, VRAM must also be allocated for:

    • The inference engine itself: e.g., asynchronous compute streams, memory pools, and log buffers;
    • Temporary tensors during forward computation: e.g., attention scores and intermediate activations, which vary with batch size;
    • Auxiliary structures such as the tokenizer, sampler, and system prompt templates.

    These parts usually grow somewhat with model size. In addition, repeatedly creating and freeing tensors of different lengths produces VRAM fragmentation, so a model that “fits on paper” may actually fail to load.

    As an engineering rule of thumb, you can multiply the sum of “weights + KV cache” by a factor of 1.15–1.3 to estimate total usage. A more reliable approach is to use the observed VRAM peak as the standard.

    5. How to Choose a Hardware Tier

    6 GB (Entry-Level GPU)

    • Positioning: start from a 2B–4B class model, first getting the complete “download → quantize → inference” pipeline working at the smallest parameter scale.
    • Note: do not use 26B-class or 31B-class models as a starting point. Even if you manage to load them via memory offloading, the frequent data movement will slow responses to the point of losing practical value.

    8–12 GB (Mainstream Gaming GPU)

    • Positioning: 4B-class models can run stably with headroom to spare, suitable for everyday Q&A, summarization, and simple code completion.
    • Note: this tier can try low-precision versions of 26B-class sparse-activation models, but avoid enabling ultra-long context and high concurrency at the same time.

    12–16 GB (Mid-to-High-End GPU)

    • Positioning: 26B-class sparse-activation models enter a range that is genuinely usable; at 4–5 bit precision, single-turn long-text conversations are usually fairly smooth.
    • Note: “being able to launch” is not the same as “running smoothly.” Focus your evaluation on generation speed, time to first token, and long-conversation stability, not on “whether it lights up.”

    24 GB and Above (High-End or Professional GPU)

    • Positioning: 31B-class models can run stably under normal context, with headroom to add longer system prompts, document Q&A, or multi-concurrent serving.
    • Note: long context remains the main variable. If you need to handle very long text, prioritize strategies such as lowering KV cache precision and chunked processing.

    Unified Memory Platforms (Integrated GPUs, Mobile Processors, etc.)

    • Core difference: the CPU and GPU share physical memory, so there is no concept of dedicated VRAM, and you should not apply the GPU VRAM table.
    • Reference lines: 4B-class models usually run comfortably with 16 GB of memory; 26B-class sparse-activation models are recommended to start from 32 GB; 31B-class models are recommended at 48 GB and above.
    • Note: the operating system usually reserves a portion of memory for graphics-related tasks, so the space available to the model is smaller than the total physical memory. It is recommended to explicitly raise this limit in the system.

    About Quantization Format Compatibility

    • Format matching: some quantization formats support layered loading under low VRAM, keeping weights in memory or on disk and loading them into VRAM on demand. This reduces VRAM usage but increases data movement overhead.
    • Format differences: different formats have different requirements for hardware instruction sets and backend support; switching a model to a different format can change speed noticeably.

    When choosing, do not look only at “parameter scale × quantization precision” but also confirm whether the format is fully and efficiently supported on the target platform.

    Verifying in the Cloud

    When you are unsure whether your local hardware can run it, you can first use pay-as-you-go, elastically scalable cloud GPU instances to run a round of verification—general-purpose GPU cloud hosts from providers such as Baidu AI Cloud are one such option. After getting the target model and context length working in the cloud, use that to decide which local GPU tier to upgrade to, which is more controllable than buying hardware directly.

    6. Context Length: The Overlooked Variable

    Many OOMs do not occur when loading the model but halfway through a conversation. The usual reason is that multi-turn conversations keep accumulating and the KV cache keeps expanding. Combining this with the formula in Section 4, you can use the script below to estimate a model’s VRAM usage on the target machine at different context lengths and get a headroom judgment:

    1. import math
    2. def estimate_vram(
    3. params_b, # total parameters (billions)
    4. quant_bits, # weight quantization precision (bits)
    5. layers, # number of model layers
    6. kv_heads, # number of KV heads
    7. head_dim, # dimension of a single attention head
    8. context_len, # context length (tokens)
    9. batch=1, # concurrent batch size
    10. kv_bits=16, # KV cache precision (bits)
    11. overhead=1.25 # runtime overhead factor
    12. ):
    13. gb = 1024 ** 3
    14. meta_ratio = 0.12 if quant_bits <= 4 else 0.04
    15. weights = params_b * 1e9 * quant_bits / 8 * (1 + meta_ratio) / gb
    16. kv = (2 * layers * kv_heads * head_dim * context_len
    17. * batch * kv_bits / 8) / gb
    18. total = (weights + kv) * overhead
    19. return round(weights, 2), round(kv, 2), round(total, 2)
    20. # 26B-class sparse-activation model as an example (structure values are placeholders; replace with the actual config)
    21. w, kv, total = estimate_vram(
    22. params_b=26, quant_bits=4,
    23. layers=40, kv_heads=8, head_dim=128,
    24. context_len=32000
    25. )
    26. print(f"weights ~ {w} GB, KV cache ~ {kv} GB, estimated total ~ {total} GB")

    Substituting context lengths of 4K, 32K, and 128K for the same configuration makes the following directly visible:

    • From 4K to 32K, the KV cache grows about 8×.
    • By 128K, the KV cache can even exceed the weights themselves.

    This is the classic scenario of “the weight table looks sufficient, but it actually won’t run.” If the long-context need is clear, you can start from three places:

    • Use a low-precision KV cache, e.g., halving it by dropping the cache precision from 16-bit to 8-bit;
    • Adopt an inference framework that supports KV cache quantization;
    • For long documents, use chunked summarization, retrieval augmentation, and similar approaches to avoid stuffing all the content in at once.

    7. How to Run a Reliable Local Benchmark

    The table is a starting point, not the finish line. It is recommended to verify on the target machine following these steps:

    1. Fix variables: change only one condition at a time, such as comparing different quantization precisions under the same context and the same prompt. Otherwise you cannot tell where a difference comes from.
    2. Record separately: after loading completes, record the VRAM baseline; during inference, record the VRAM peak (not the average), because OOM is triggered by the peak.
    3. Choose the right speed metrics: use “tokens generated per second” and “time to first token” as the core metrics. Reporting only “total time” is distorted by input and output length and loses comparability.
    4. Simulate real workloads: multi-turn conversations, long system prompts, and batch requests should all be included in testing, especially verifying performance when the context approaches the limit.
    5. Watch fragmentation and stability: after running continuously for several hours, re-check whether VRAM usage keeps climbing, to judge whether there is fragment accumulation or cache that is not being released.

    8. Common Misconceptions and Pitfalls

    • Misconception 1: Multiply the official parameter count by 2 to get the VRAM requirement. This ignores both quantization and cache, as well as runtime overhead.
    • Misconception 2: If VRAM just barely fits, it will run. Fragmentation, context growth, and temporary tensors can turn “just barely” into “just short.”
    • Misconception 3: A sparse-activation model’s VRAM is calculated from activated parameters. VRAM is calculated from total parameters; what is calculated from activated parameters is the compute per inference.
    • Misconception 4: Copy discrete-GPU experience to integrated-GPU platforms. You should prioritize total physical memory and the amount the system allocates to graphics tasks.
    • Misconception 5: The lower the quantization precision, the better the deal. Low-bit quantization saves VRAM but may cause precision loss; for critical scenarios, do comparison tests before deciding.

    9. Conclusion

    VRAM planning for local LLM deployment is essentially a “budget allocation” problem. Weights determine the base cost, the KV cache determines the room for expansion, and runtime overhead determines the safety margin. Remember three principles: estimate by “weights + context + headroom,” not just parameter count; benchmark against real workloads, not just theoretical values; and pick the tier first, then choose the quantization precision. Do these three things, and you can find the best balance between capability and resources on your own machine at an appropriate cost.