VRAM Requirements and Model Selection for Local Open-Source LLM Deployment

    This article provides a practical guide to estimating VRAM requirements and selecting models for local deployment of open-source large language models. It explains why parameter count alone is not enough, breaks down VRAM usage into weights, KV Cache, and runtime overhead, compares common model sizes, and offers recommendations for different GPU and unified memory configurations. It also covers context length, common pitfalls, troubleshooting, and planning for multi-user deployments.

    1. Start with the conclusion: VRAM sufficiency is not just about parameter count

    When deploying open-source large language models locally, many people’s first question is not “Is the model good?” but “Can this machine run it at all?”

    A common estimation method is to divide the parameter count by 2 and use that as the VRAM requirement. For example, under BF16 (16-bit brain floating point) precision, each parameter takes about 2 bytes, so a 7B model theoretically needs about 14GB. In that case, a 16GB GPU may appear to be just enough.

    In practice, however, this estimation is often insufficient. There are four common reasons:

    • Precision is not converted: Quantized models store weights in 4-bit or 8-bit formats, so actual usage can be far below the BF16 theoretical value.
    • KV Cache is ignored: As context length increases and concurrency grows, KV Cache usage rises roughly linearly.
    • Runtime overhead: Activations, temporary buffers, inference engine contexts, and driver contexts are not included in parameter count.
    • Precision is set too high: Using FP16 as the default may waste twice as much VRAM.

    Therefore, VRAM planning should be based on “weights + KV Cache + runtime overhead”, with some headroom reserved.

    2. VRAM budget: weights, KV Cache, and runtime overhead

    1. Weights: determined by parameter count and precision

    Weights are the easiest part to estimate:

    1. Weights (GiB) ≈ parameter count (B) × bytes per parameter × 1e9 ÷ 1024^3
    2. Bytes per parameter:
    3. BF16 / FP16 = 2
    4. FP8 / INT8 = 1
    5. 4-bit ≈ 0.5~0.6, where 0.5 is the theoretical value and 0.6 is a practical estimate that includes quantization metadata and alignment overhead

    Common parameter scales correspond to the following weight sizes:

    Parameter count FP16 / BF16 8-bit 4-bit (estimated)
    4B ≈7.5 GiB ≈3.7 GiB ≈1.9~2.3 GiB
    8B ≈14.9 GiB ≈7.5 GiB ≈3.7~4.6 GiB
    31B ≈57.7 GiB ≈28.8 GiB ≈14.4~17.6 GiB

    Switching from FP16 to 4-bit usually reduces weight size to about one quarter of the original. This is where quantization is most valuable for machines with limited VRAM.

    2. KV Cache: the easily underestimated hidden usage

    Large models generate text token by token. To avoid repeated computation, inference engines cache the Key/Value vectors of generated tokens in VRAM. This is KV Cache. It is usually proportional to sequence length:

    1. KV Cache (GiB) ≈
    2. 2 × number of layers × KV heads × head dimension × sequence length × batch size × bytes per element ÷ 1024^3
    3. The factor 2 means one copy for Key and one for Value.

    Take a model with 32 layers, 8 KV heads, head dimension 128, and KV Cache stored in FP16. The KV Cache per token is:

    1. 2 × 32 × 8 × 128 × 2 ÷ 1024 = 128 KiB/token

    Then:

    1. 8K context → about 1 GiB
    2. 32K context → about 4 GiB
    3. 128K context → about 16 GiB
    4. 32 concurrent requests × 4K context → about 16 GiB
    5. 64 concurrent requests × 4K context → about 32 GiB

    In other words, a 4B-level model may have weights of only about 2GB, but if the context is long or concurrency is high, KV Cache can easily exceed the model weights themselves.

    3. Runtime overhead: the safety margin that should always be reserved

    In addition to the two items above, you also need to reserve space for activations, intermediate tensors, inference engine contexts, graphics driver contexts, and VRAM fragmentation. For a single-user interactive scenario, it is recommended to reserve an additional 10%~20%, and no less than 1GB.

    Unified memory devices require an extra calculation: VRAM and system memory are shared, and the operating system, browser, development tools, and other applications also consume memory.

    Here is a simple VRAM estimation script:

    1. def estimate_vram_gib(
    2. params_b, # Total parameters, in billions
    3. layers, kv_heads, head_dim, # From model configuration
    4. ctx_len, batch=1,
    5. weight_bits=4,
    6. kv_bits=16,
    7. overhead_ratio=0.15, # Runtime overhead ratio
    8. ):
    9. # Weights: convert using 1 GiB = 1024^3 bytes
    10. weight = params_b * 1e9 * (weight_bits / 8) / 1024**3
    11. # KV Cache: one K and one V copy per token
    12. per_token = 2 * layers * kv_heads * head_dim * (kv_bits / 8)
    13. kv = per_token * ctx_len * batch / 1024**3
    14. total = (weight + kv) * (1 + overhead_ratio)
    15. return {
    16. "weights_GiB": round(weight, 2),
    17. "kv_cache_GiB": round(kv, 2),
    18. "total_GiB": round(total, 2)
    19. }
    20. # Example: 31B total parameters, 32 layers, 8 KV heads, head dimension 128, 32K context, 4-bit weights
    21. print(estimate_vram_gib(31, 32, 8, 128, ctx_len=32768, weight_bits=4))
    22. # Example output: {'weights_GiB': 14.44, 'kv_cache_GiB': 4.0, 'total_GiB': 21.21}

    If 4-bit quantization metadata and alignment overhead are considered, the weight size may rise to about 15.7~17.6GiB, and total VRAM usage may rise to about 23~25GiB. Therefore, actual selection should be based on model configuration and measured results from the inference engine.

    3. VRAM requirements by common model tiers

    Common model tiers in local deployment today include:

    • 4B-level lightweight models: focused on low resource usage.
    • MoE models with about 26B total parameters and about 4B active parameters: balancing quality and speed.
    • 31B dense models: higher capability ceiling, but also higher resource requirements.

    The following table shows estimated VRAM requirements under 4-bit quantization + single-user interactive scenario. Default assumptions: batch size is 1, KV Cache uses FP16, context length is 32K; the 26B MoE and 31B examples assume a common configuration of 32 layers, 8 KV heads, and head dimension 128. Actual values should follow the model configuration.

    Model tier Estimated weights Estimated VRAM with context and overhead GPU recommendation Unified memory recommendation Positioning
    2B-level ≈1.2 GiB ≈3~4 GiB 4~6 GB 8 GB Pipeline validation, lightweight tasks
    4B-level ≈1.9~2.3 GiB ≈4~6 GiB; shorter context is more stable 6~8 GB 8~16 GB Local first choice; long context needs control
    26B with 4B active MoE ≈12.1~14.5 GiB About 19~22 GiB with 32K context 24 GB is more stable; 16 GB only recommended for short context 32 GB Balances quality and speed
    31B dense ≈14.4~17.6 GiB About 21~25 GiB with 32K context 24 GB is tight; 32 GB is more stable 32 GB or more Code, complex reasoning

    When using this table, pay attention to three points:

    1. The ranges are estimates, not measured values: Different layer counts, KV head counts, context lengths, and inference engine implementations can affect the result.
    2. MoE is compute- or bandwidth-friendly, but not VRAM-capacity-friendly: During inference, only about 4B parameters are activated, reducing computation and some weight reading compared with a dense model of the same total parameter count. However, weights usually still need to be fully resident, so VRAM capacity should still be planned according to the total parameter count.
    3. 8-bit uses about twice the weight VRAM of 4-bit: With a 32K context, a 31B model with 8-bit quantization usually needs about 32GB of VRAM, and a 24GB GPU often can only consider 4-bit execution.

    4. Choosing models by GPU VRAM tier: what if VRAM is insufficient?

    GPU VRAM tier Recommended option Notes
    4~6 GB 2B-level, 4B-level 4-bit Context should be controlled within 8K~16K; disable high concurrency first
    8 GB 4B-level first choice 8B-level 4-bit can be tried, but be cautious with long context; enable KV Cache quantization
    12~16 GB 4B-level is easy; 26B-with-4B-active MoE can be tried For MoE, keep context within 16K; enable KV Cache quantization, reduce concurrency, or prefer 24GB VRAM if necessary
    24 GB 26B MoE is relatively stable; 31B 4-bit is usable 31B has limited headroom with a 32K context; monitor VRAM usage and reduce context if necessary
    32 GB or more 31B model, long context, multi-card environment Consider 8-bit or longer context; multi-card tensor parallelism increases communication overhead

    In actual selection, it is important to distinguish between two types of hardware:

    • GPUs with sufficient bandwidth but limited capacity: Consumer discrete GPUs are mostly this type. Using 4-bit quantization to fit the model into VRAM usually causes limited speed loss.
    • Devices with large capacity but limited bandwidth: Unified memory architecture devices have considerable capacity, but decode speed is mainly limited by memory bandwidth.

    One commonly overlooked point is: within the same VRAM tier, “can load” and “runs stably” are two different things. It is recommended to always reserve 10%~20% headroom; otherwise, KV Cache can easily overflow when long context or multi-turn conversations push usage up.

    5. How to plan for unified memory devices

    Unified memory architecture maps the CPU, GPU, dedicated compute units, and system memory into a unified address space, so memory is VRAM. Therefore, planning should focus on “total unified memory” and “memory bandwidth”, not traditional GPU VRAM.

    Unified memory capacity Supported models Notes
    8~16 GB 2B-level, 4B-level Memory must be reserved for the system and applications; 4B-level is more suitable for contexts within 8K
    24~32 GB 4B-level; 26B-with-4B-active MoE 26B MoE is relatively stable at medium context; speed is limited by bandwidth
    48~64 GB 26B MoE, 31B Can support long context; suitable for single-user quality-focused scenarios
    96 GB or more 31B and above, very large context Capacity is sufficient; speed ceiling still depends on memory bandwidth

    When using unified memory devices, pay attention to the following:

    1. Decode speed depends on bandwidth: During token-by-token generation, at least one full weight read is required per step. Theoretical decode speed is approximately “effective memory bandwidth ÷ model size”. Unified memory devices have considerable capacity, but their bandwidth is usually lower than high-end discrete GPUs, so whether a large model runs fast mainly depends on bandwidth.
    2. Pay attention to system limits on compute task memory: Some systems by default limit the proportion of memory that graphics or compute tasks can allocate. If model weights occupy most of unified memory, other applications may run out of memory or even fail to start.
    3. MoE also needs bandwidth consideration: During MoE inference, although only some experts are activated, the weights of activated experts are still read; batch processing, routing strategies, and inference engine scheduling can also change decode speed.
    4. Hybrid scheduling on demand should be used cautiously: Layers that do not fit in VRAM can be placed in system memory and scheduled on demand by the inference engine. However, weights must pass through the memory channel for every token, and speed may drop by an order of magnitude. This is only suitable as a fallback for getting the model to run.

    6. Context length: the most easily underestimated VRAM black hole

    Many people’s VRAM budget is finished with “weights + 2GB”, only to fail when long context is enabled. Based on the earlier formula, for a model with 32 layers, 8 KV heads, and head dimension 128, the KV Cache for a single 8K context is about 1GiB; 32K is about 4GiB; 128K is about 16GiB.

    If 32K or even 128K context is enabled, or multiple users are served at the same time, KV Cache can easily exceed the model weights themselves. Controllable practices include:

    • Set maximum context by scenario: Use 8K~16K for daily Q&A, and expand separately for long-document tasks, avoiding maxing out from the beginning.
    • Enable KV Cache quantization: Some inference engines support compressing KV Cache to 8-bit, which can reduce usage by about half, at the cost of possible slight accuracy loss under extremely long context.
    • Enable prefix cache reuse: Prefixes from multi-turn conversations or fixed system prompts can be reused, avoiding repeated computation and repeated occupancy.
    • Control concurrency and batch size: VRAM usage is approximately the KV Cache of a single request multiplied by concurrency. Throughput improvements come at the cost of VRAM.
    • Pay attention to attention mechanism design: Designs such as GQA and sliding window attention can reduce KV Cache usage and are worth considering during procurement and model selection.

    How long a context can a 4B model support?

    Take a 4B model with about 2.3GiB of weights as an example. If the GPU has 6GB, after reserving runtime overhead, only about 2~3GiB can be allocated to KV Cache. At about 128KiB per token, an 8K context is about 1GiB, 16K is about 2GiB, and 32K is about 4GiB. Therefore, a 6GB GPU is more suitable for contexts around 8K; an 8GB GPU can try 16K; only a 24GB GPU provides more comfortable room for long context.

    Why does MoE still use a lot of VRAM?

    MoE models have large total parameter counts, and weights usually need to be fully resident. Although each inference only activates some experts, reducing computation and some bandwidth pressure, VRAM capacity still needs to be planned according to the total parameter count.

    7. Common mistakes and troubleshooting checklist

    1. Estimating VRAM using BF16 parameter count: Quantized models should be converted according to the target precision; otherwise, requirements are easily overestimated.
    2. Assuming MoE needs less VRAM because fewer parameters are activated: MoE saves computation and bandwidth pressure, but weights still occupy VRAM according to the total parameter count.
    3. Looking only at capacity, not bandwidth: Capacity determines whether the model can run, while bandwidth determines how fast it runs. Both are essential.
    4. Ignoring system limits on unified memory devices: After memory is occupied by the system and graphics tasks, available headroom may be far below the nominal capacity.
    5. Pursuing maximum context: KV Cache grows linearly with length, and long context should only be enabled when needed.

    When problems occur, troubleshoot in the following order:

    • Out-of-memory error at startup: Reduce context length, reduce concurrency, or switch to a lower-bit quantization version.
    • Model starts but is very slow: Check whether a large amount of weights is being scheduled to memory, and whether memory bandwidth is limited.
    • Long conversation becomes slow or interrupted after a while: Monitor KV Cache growth over turns, check whether VRAM usage is close to the upper limit, and set a context limit.

    8. From local experimentation to multi-user use: plan one step ahead

    During local single-user experimentation, VRAM planning can be centered around “one person and one context”. However, once a model needs to serve multiple users or be embedded into a business system, the question changes from “Can it load?” to “How many concurrent users can it stably support?”

    • Different capacity focuses: Single-user scenarios focus on whether weights can fully fit into VRAM; multi-user services focus more on KV Cache capacity and need to reserve enough space for concurrency.
    • VRAM, latency, and throughput require trade-offs: Larger batch sizes improve throughput, but VRAM usage and latency also rise. It is recommended to use actual business traffic for load testing to determine the maximum concurrency at which VRAM usage remains in a safe range.
    • Use cloud platform capabilities to scale elastically: When deploying on GPU instances or container services, model files can be stored in object storage; use logging services and monitoring alerts to continuously observe VRAM usage, first-token latency, and decode speed; then scale the number of instances elastically based on business peaks.

    Whether it is single-machine local deployment or cloud-based multi-user service, the same planning approach applies: estimate VRAM first, then select the model, and finally run real tests.

    9. Quick decision index

    Decision item Recommended approach
    6~8 GB VRAM 4B-level 4-bit, with context controlled within 8K~16K
    12~16 GB VRAM 4B-level as daily primary model; 26B-with-4B-active MoE can be tried, with context recommended within 16K
    24 GB VRAM 26B MoE is relatively stable; 31B 4-bit is usable, but watch headroom at 32K context
    32 GB or more VRAM or unified memory 31B model with long context; prioritize memory bandwidth
    Multi-user service Scale VRAM and instances by concurrency, and continuously monitor VRAM usage

    VRAM configuration is essentially a balance among three variables: model parameter count determines the lower bound of weights, quantization precision determines how much weights can be compressed, and context length plus concurrency determine how high KV Cache can grow. 4B-level models are suitable as a local first choice. MoE models with about 26B total parameters and about 4B active parameters offer a better balance of quality and speed on around 24GB of VRAM. 31B models are better suited for 24GB or more VRAM, and should be carefully planned in combination with context length, KV Cache quantization, and monitoring.