Practical Guide to VRAM Configuration and Model Selection for Local LLMs

    Deploying large language models locally requires understanding that theoretical VRAM specifications are just a starting point. This guide explains the actual VRAM consumption breakdown—including weights, KV cache, and runtime overhead—and provides a practical estimation model. It offers hardware tier recommendations, discusses the impact of context length and quantization, and outlines a step-by-step deployment workflow to help you choose the right local model configuration.

    1. Why “Official Theoretical VRAM” is Only a Starting Point

    When deploying large language models locally, many users first check the weight footprint in the model documentation. However, this often represents the theoretical weight value at FP16/BF16 precision. Actual deployments typically use 4-bit, 5-bit, or 8-bit quantized versions, creating a significant gap.

    More importantly, running a model requires more than just accommodating the weights. A complete inference process involves at least the following VRAM overheads:

    1. Weight VRAM: Determined by the number of parameters and quantization bit-width; the most intuitive part.
    2. KV Cache: Grows linearly with context length, batch size, number of layers, and attention head dimensions. It can be very significant in long-context scenarios.
    3. Temporary Activations and Working Buffers: Related to batch size, sequence length, and operator implementation. The peak can be higher than the average.
    4. Runtime Context Overhead: Fixed or semi-fixed usage generated by the accelerated runtime, communication libraries, memory allocators, and graph capture.
    5. Safety Margin: Used to handle fragmentation, peak fluctuations, and other system process consumption.

    Therefore, VRAM configuration should not just ask “how large are the model weights,” but rather “what is the peak VRAM at the target context length and batch size.” The former is a theoretical value, while the latter determines stable operation.

    2. Basic VRAM Budget Estimation Model

    You can establish an initial budget using a simplified formula:

    1. Peak VRAM ≈ Weight VRAM
    2. + KV Cache
    3. + Temporary Activations
    4. + Runtime Overhead
    5. + Safety Margin

    The weight VRAM can be roughly expressed as:

    1. Weight VRAM ≈ Parameters × Bytes per parameter × Quantization overhead coefficient

    Under 4-bit quantization, each parameter takes about 0.5 bytes. However, quantization metadata, alignment, and partially retained precision layers add extra overhead. In practice, estimate 0.55 to 0.65 bytes/parameter. For 8-bit, estimate 1.0 to 1.1 bytes/parameter. FP16/BF16 is close to 2 bytes/parameter.

    The simplified KV Cache estimation can be written as:

    1. KV Cache ≈ 2 × Layers × KV Heads × Head Dimension × Context Length × Batch Size × Bytes per element

    Here is a pseudocode example:

    1. function estimate_vram(params_b, bits, ctx, layers, kv_heads, head_dim, batch):
    2. weight_gb = params_b * 1e9 * (bits / 8) / 1024^3 * 1.15
    3. kv_gb = 2 * layers * kv_heads * head_dim * ctx * batch * 2 / 1024^3
    4. overhead_gb = 1.0
    5. safety_gb = 1.0
    6. return weight_gb + kv_gb + overhead_gb + safety_gb

    This formula is not an exact performance model, but it is sufficient to help determine the hardware tier. During actual selection, rely on peak monitoring under your target runtime, and perform stress testing by gradually increasing the context length and batch size.

    3. Actual VRAM Tiers for Different Parameter Scales

    Based on common local deployment practices, models can be divided into three tiers: lightweight, mid-size Mixture of Experts (MoE), and large parameters. Note: Although MoE models have fewer active parameters and may offer computational speed advantages, the weights still need to be loaded according to the total parameter count. Therefore, VRAM cannot be estimated solely by active parameters.

    Parameter Scale 4-bit Weight Size Suggested VRAM Starting Point Applicable Scenarios
    Lightweight model, ~2 to 4 billion params ~2 to 3GB 4 to 6GB Initial validation, lightweight Q&A, low-context tasks
    Mid-size MoE, ~26B total params, ~4B active ~13 to 16GB 16GB for better headroom Strong local reasoning, code assistance, medium context
    Large model, ~31 billion params ~16 to 20GB 24GB and above Higher priority on quality, long context, and complex tasks

    This table should be understood as a “starting point for decision-making,” not a “guaranteed value.” For example, running a lightweight model on a 6GB VRAM tier is usually more stable; the 12 to 16GB tier allows for serious experimentation with mid-size MoE models, but you must control context length and batch size; the 24GB+ tier is better suited for large parameter models, though long context will still significantly increase KV Cache.

    4. Selection Advice by Hardware Tier

    1. 4 to 6GB VRAM Tier

    This tier is suitable for lightweight models. Keep the context length within a medium range, set the batch size to 1, and prioritize stable startup and responsiveness. Do not directly challenge mid-size MoE or large parameter models, or you may encounter out-of-memory (OOM) errors, system memory swapping, or drastic speed drops.

    If you only need to validate workflows, perform simple text processing, or run offline small tools, lightweight models are sufficient. Focus on whether the quantized version is complete, whether the runtime overhead is controllable, and if other system programs are consuming VRAM.

    2. 8 to 12GB VRAM Tier

    This tier runs lightweight models more stably and can evaluate low-quantization versions of mid-size models. However, “can start” does not mean “can run stably.” Start with a shorter context, record peak VRAM, and gradually increase the context. If VRAM approaches the limit, prioritize reducing context length and batch size rather than blindly increasing the quantization compression rate.

    3. 12 to 16GB VRAM Tier

    Mid-size MoE models enter the range of serious experimentation. Pay more attention to actual inference speed, time-to-first-token (TTFT), and peak VRAM under long context. MoE models have fewer active parameters, offering potential computational efficiency advantages, but weight footprint is still calculated by total parameter scale. Do not mistakenly assume that fewer active parameters means lower VRAM usage.

    4. 24GB and Above VRAM Tier

    Large parameter models are worth trying here, suitable for scenarios requiring higher output quality, complex reasoning, and long context. However, the VRAM table is not a guarantee. When context increases from 4K to 32K or longer, the KV Cache may grow to several gigabytes, and increasing batch size will multiply the usage. Reserve an adequate safety margin.

    5. Unified Memory Architecture Devices

    Devices with a unified memory architecture do not rely on discrete VRAM but rather total system memory and memory bandwidth. The advantage is potentially larger capacity, but bandwidth is typically lower than discrete VRAM, so inference speed expectations need adjusting. During deployment, reserve sufficient memory for the system and other applications to prevent system freezing caused by excessive model usage. The VRAM estimation formula can still be a starting point, but base your decisions on actual peaks and swapping behavior.

    5. Impact of Context Length, Batch Size, and Quantization Bit-width

    Context length is the most easily underestimated variable. KV Cache grows linearly with context, and long-context tasks can push an originally “just enough” configuration over the limit. It is recommended to use incremental testing: gradually increase context by 512, 1024, 2048, 4096, 8192, and record the peak VRAM and speed for each step.

    Batch size is equally important. When batch size increases from 1 to 2 or 4, both KV Cache and temporary activations rise. For local single-user scenarios, prioritize a batch size of 1 for stability; multi-user concurrency or batch offline tasks require recalculation of capacity planning.

    Regarding quantization bit-width: 4-bit has lower VRAM usage but may cause quality loss; 8-bit is more stable but consumes more VRAM. If the task has high requirements for code, math, or long-text consistency, compare the output quality before and after quantization using a small sample first, before deciding whether to adopt a lower bit-width.

    6. Practical Workflow and Troubleshooting Checklist

    It is recommended to follow this workflow:

    1. Define the task type, target context length, and acceptable speed.
    2. Use the formula to estimate weights, KV Cache, and runtime overhead.
    3. Start with batch size 1 and a shorter context.
    4. Monitor peak VRAM and gradually increase context length.
    5. Record speed and quality differences under different quantization bit-widths.
    6. Reserve a 10% to 20% VRAM safety margin.

    Common issues include: Out of memory at startup, usually because weights plus runtime overhead already exceed limits; Crashing after running for a while, likely due to KV Cache growth from long context; Sudden speed drop, potentially caused by system memory swapping or VRAM fragmentation; Decreased output quality, possibly due to low quantization bit-width or mismatched quantization version. Corresponding strategies include reducing context, reducing batch size, increasing quantization bit-width, adding a safety margin, or switching to a smaller parameter tier.

    If local hardware is insufficient, you can choose general GPU compute instances on cloud platforms (such as Baidu AI Cloud) for short-term validation, and then decide on the local configuration based on measured peaks. During cloud validation, pay attention to VRAM capacity, memory bandwidth, data compliance, and cost. Avoid equating short-term test results directly with long-term production capacity.

    7. Conclusion

    The core of VRAM configuration for local LLM deployment is not memorizing a fixed table, but mastering the budget method of “weights + KV Cache + temporary activations + runtime overhead + safety margin.” Lightweight models are suitable for starting at 4 to 6GB; mid-size MoE models are recommended for the 16GB tier for better headroom; large parameter models require 24GB and above, with margins reserved for long context. Unified memory architecture devices should consider total memory and bandwidth. Ultimately, model selection should be based on target context, batch size, and measured peaks—prioritize stability first, then pursue larger parameters and longer context.