Local LLM Deployment: 20GB GPU Selection and Optimization

    This article covers the key factors for running large language models locally on 20GB-class consumer GPUs. It explains how VRAM capacity and bandwidth affect feasibility and speed, provides a practical VRAM budgeting method, discusses prefill and decode behavior, model-size fit, bf16 support, memory-efficient attention, and multi-GPU trade-offs. It also offers a selection checklist and optimization practices for quantization, KV cache management, batching, and benchmarking.

    1. Why VRAM comes first when running LLMs locally

    Large language model inference has two main phases:

    • Prefill: The model processes the entire input prompt in one pass and produces the initial output needed for generation. This phase is mostly compute-intensive.
    • Decode: The model generates one token at a time until it reaches a stop condition or a maximum length.

    In both phases, the model weights must remain resident in GPU memory. If VRAM is insufficient, the inference framework may offload part of the weights to host memory or even storage. When that happens, each forward pass must fetch data across the PCIe bus, whose bandwidth is usually only tens of GB/s. As a result, generation speed can drop from dozens of tokens per second to only one token every few seconds.

    For local deployment, VRAM capacity is therefore the first gate: it determines whether a model can run at all. VRAM bandwidth is the second gate: it determines how fast the model runs. A model with slightly insufficient capacity but acceptable speed is often very different in practical usability from a model with enough capacity and smooth performance.

    Among consumer GPUs, the 20GB to 24GB range is a notable tier. It crosses the boundary from “barely runnable” to “relatively comfortable” in terms of capacity, while still costing far less than data-center accelerators. Many individual developers and small teams evaluate this tier first when building local knowledge-base assistants, coding helpers, long-text processing tools, and similar applications. This article does not recommend any specific product model. Instead, it explains how to evaluate, select, and optimize GPUs in this class from a general engineering perspective.

    2. How VRAM is allocated: a practical memory budget

    2.1 Four main VRAM consumers

    When a single GPU runs one model, VRAM usage generally consists of four parts:

    1. Model weights
      This is parameter count multiplied by the number of bytes used per parameter. FP16 or FP32 uses 2 or 4 bytes per parameter. INT8 quantization uses roughly 1 byte. A 4-bit model theoretically uses about 0.5 bytes per parameter, but in practice it is usually estimated as quantized weights plus a small amount of scaling metadata.

    2. KV cache
      During autoregressive generation, every step needs the key and value vectors of all previous tokens. To avoid recomputation, inference frameworks cache them. The KV cache grows with sequence length.

    3. Framework and runtime overhead
      This includes context structures, temporary operator buffers, memory fragmentation, and other runtime costs.

    4. Reserved space
      This is space kept for dynamic allocation and batching expansion. A common recommendation is to reserve about 10% to 20%.

    For calculation, the values below are converted into GiB, where 1 GiB = 2^30 bytes. It is also worth noting that a GPU labeled “20GB” provides about 18.6 GiB when measured in binary units. The actual usable memory is therefore somewhat less than the decimal number suggests.

    2.2 Estimation formula

    The KV cache can be estimated with the following formula:

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

    The factor 2 represents both the key and value tensors. If the model uses grouped-query attention or another design with shared KV heads, substituting the actual number of KV heads can significantly reduce the cache size.

    The following pseudocode shows a complete estimation flow without relying on any third-party library:

    1. GIB = 1024 ** 3 # Number of bytes in 1 GiB
    2. def estimate_vram(param_count, bytes_per_param, kv_budget_bytes, reserve_ratio=0.15):
    3. """Estimate VRAM required for single-request inference.
    4. param_count: Model parameter count
    5. bytes_per_param: Bytes per parameter. FP16 = 2; use the actual value for quantized models
    6. kv_budget_bytes: KV cache bytes calculated using the formula in Section 2.2
    7. reserve_ratio: Reserve ratio
    8. """
    9. weight = param_count * bytes_per_param
    10. runtime = 1.0 * GIB # Context and temporary buffers; use empirical values and calibrate with tests
    11. total = weight + kv_budget_bytes + runtime
    12. return total / GIB, total / (1 - reserve_ratio) / GIB
    13. # Example: 7B parameters, FP16 precision, about 4K context
    14. required, recommended = estimate_vram(7e9, 2, kv_budget_bytes=2 * GIB)
    15. print(f"Minimum required: {required:.1f} GiB, recommended with reserve: {recommended:.1f} GiB")

    2.3 Typical model sizes on a 20GB GPU

    Using the formula above, we can roughly estimate how common model sizes fit on a 20GB GPU. The values below are approximate and depend on model architecture, inference framework, and version.

    Model size Precision / quantization Approx. weight usage Total usage with 4K context Feasibility on a single 20GB GPU
    3B FP16 5.6 GB About 8 GB Comfortable; supports multiple concurrent requests
    7B FP16 13.0 GB About 15.5 GB Runnable, but long-context headroom is limited
    7B 4-bit 3.3 GB About 5.8 GB Very comfortable; supports long context and concurrency
    14B 4-bit 6.5 GB About 9.0 GB Feasible, with some concurrency capability
    32B 4-bit 15.0 GB About 17.5 GB Borderline; usually single-request service, long context may require KV compression
    70B 4-bit 33.0 GB About 35.5 GB Not feasible on a single GPU; requires multiple GPUs or more VRAM

    A practical rule is:

    • On a 20GB GPU, models around 7B to 14B with 4-bit quantization are the most comfortable choice.
    • Models around 32B are in a borderline zone.
    • Models around 70B are generally beyond the capability of a single card in this class.

    3. Capacity determines whether it runs; bandwidth determines how fast it runs

    3.1 A Roofline view of the decode phase

    Using the Roofline model, hardware performance can be understood through two limits:

    • Compute limit: Peak computational throughput, usually measured in TFLOPS.
    • Bandwidth limit: Memory bandwidth divided by arithmetic intensity. Arithmetic intensity is the number of floating-point operations performed per byte read from memory.

    During decode, the model must read all weights for every generated token. For a linear layer, each parameter corresponds to roughly one multiply-add operation, or about 2 FLOPs, while requiring about 2 bytes of data in FP16. The arithmetic intensity is therefore about 1 FLOP/Byte.

    For many GPUs in this class, the ridge point—the arithmetic intensity where the two lines meet—is usually around 100 to 300 FLOP/Byte. Decode therefore falls on the sloped part of the Roofline and is typically memory-bound.

    This means that simply increasing the number of compute cores has limited effect on decode speed. The main factors are:

    1. GPU memory bandwidth.
    2. The amount of data that must be read at each step, including weights and KV cache.

    A rough estimate is:

    1. Theoretical token speed ≈ memory bandwidth × memory access efficiency ÷ bytes read per step
    2. Bytes read per step ≈ weight bytes + current KV cache bytes

    For example, with about 760 GB/s bandwidth, a 7B FP16 model, and a 4K context, each step reads at least about 15 GB of data. The theoretical upper bound is about 50 tokens/s. In real workloads, operator efficiency and sampling strategies usually reduce this to 50% to 80% efficiency, resulting in roughly 25 to 40 tokens/s, which matches typical observations.

    In contrast, prefill processes many tokens at once. Its arithmetic intensity is much higher and it is closer to compute-bound. In this phase, core compute throughput, the availability of tensor compute units, and supported precision formats directly affect time to first token.

    3.2 How to interpret bandwidth numbers

    For GPUs in the 20GB and 24GB capacity classes, memory bandwidth is usually in the range of about 700 GB/s to 1000 GB/s, with some higher-end models approaching about 1000 GB/s.

    A rough estimate for common configurations:

    • A 14B-level 4-bit model reads about 8 GB per step. On these GPUs, it can generally reach about 40 to 90 tokens/s.
    • Switching to a 32B-level 4-bit model doubles the per-step read volume, and speed drops noticeably.

    Therefore, GPU selection should consider two points together:

    1. Whether capacity can hold the target model and context.
    2. Whether bandwidth can support the expected generation speed.

    Comparing only capacity or only compute throughput can lead to incomplete conclusions.

    3.3 Why long context is especially memory-hungry

    The KV cache grows linearly with context length and scales with batch size. Consider a 7B-level model with 32 layers, 8 KV heads, and a head dimension of 128:

    • At a 4K context, the KV cache is about 0.5 GB, which is almost negligible.
    • At a 32K context, it grows to about 4 GB.
    • If the GPU is serving 8 concurrent requests, the KV cache alone can approach 32 GB, which far exceeds a 20GB GPU.

    In addition, if the inference framework does not use a memory-efficient attention implementation, intermediate attention results can grow quadratically with sequence length, increasing VRAM pressure further. Therefore, whether long context is supported depends not only on model size, but also on KV cache budget and attention kernel implementation.

    4. Three key capabilities beyond capacity

    4.1 Precision format: bf16 is an important dividing line

    FP16 and bf16 are both 16-bit formats, but they allocate bits differently:

    • FP16 uses 1 sign bit, 5 exponent bits, and 10 mantissa bits. It has relatively high precision, but its maximum value is about 65504, making overflow more likely.
    • bf16 uses 1 sign bit, 8 exponent bits, and 7 mantissa bits. Its dynamic range is the same as FP32, so overflow risk is lower.

    Many models have activation distributions with a wide range and are trained primarily in bf16. On hardware with native bf16 support, inference can be performed directly in bf16. On older architectures that only support FP16, one common approach is to reduce compute precision to FP16. Another is to store weights in FP16 but upcast computations to FP32 inside the framework. The first option may cause overflow, while the second increases VRAM usage and may affect speed.

    For scenarios such as long context and multi-turn conversation, precision format can noticeably affect output stability. When selecting hardware, architectures with native bf16 support should be preferred.

    4.2 Memory-efficient attention and paged VRAM management

    Memory-efficient attention implementations, often provided as fused kernels, can perform attention without explicitly materializing the full attention matrix. This reduces attention-related VRAM usage from quadratic growth with sequence length to linear growth. For a 20GB GPU, this directly determines how long a context can be enabled for long documents and long conversations.

    Paged KV cache management, commonly referred to as PagedAttention, divides the cache into fixed-size blocks and allocates them on demand. This greatly reduces wasted reserved space and fragmentation, allowing the same GPU to handle more concurrent requests.

    These capabilities are already common in mainstream inference frameworks, but whether they can be fully enabled depends on how well the hardware architecture, driver version, and framework version match.

    4.3 Hidden costs of multi-GPU scaling

    A 20GB GPU has slightly less capacity than a 24GB GPU. A natural idea is that two cards can be combined into 40GB and therefore run a 70B model. In practice, however, there are hidden costs:

    • Reduced utilization after splitting: Once a model is split across two GPUs, every layer may require cross-GPU synchronization. Many consumer GPUs do not support direct high-speed GPU-to-GPU communication such as P2P, so data may have to pass through host memory. Communication overhead becomes a larger share of total time.
    • Power and space costs: Power consumption roughly doubles. This places higher demands on the power supply, power connectors, motherboard slot spacing, and chassis airflow.

    Multi-GPU configurations make sense mainly when running very large models is a hard requirement. For normal inference workloads, a single GPU with sufficient VRAM is usually the better choice.

    5. A practical GPU selection checklist

    Based on the analysis above, the following checklist can be used directly:

    1. Budget by weights + KV cache + reserve
      Do not only ask whether the model can be loaded. Calculate actual usage based on target context length and concurrency, and reserve about 10% to 20%.

    2. Look at bandwidth for decode, and compute for prefill
      Interactive conversation experience is mostly determined by memory bandwidth. Prefill-heavy tasks, such as batch document processing and long-text summarization, should focus more on compute throughput.

    3. Prefer architectures with native bf16 and memory-efficient attention
      These capabilities affect precision stability and long-context support.

    4. Evaluate compatibility of modified or non-standard products
      Some consumer GPUs may have non-official modifications, such as expanded VRAM. Their memory capacity and bandwidth may differ from official specifications, and compatibility with firmware, drivers, and common frameworks may be uncertain. Before purchase, validate with real stress tests.

    5. Account for total system power and cooling
      GPUs in this class often consume more than 300W under full load. The system should have a power supply with enough wattage and enough power connectors. Chassis airflow and the GPU’s own cooling capacity should also be sufficient.

    6. Prefer a single GPU; be cautious with multi-GPU
      Multi-GPU parallelism introduces splitting efficiency loss and deployment complexity. For common tasks, a single GPU is usually recommended.

    It is also important to view this class of hardware objectively. It is still consumer-grade hardware and is not designed for 7×24 high-load inference. If the application requires long-term stable external service, multi-user concurrency, or peak elasticity, a more robust approach is to use the local environment for development, debugging, and preprocessing of privacy-sensitive data, while moving high-concurrency inference to on-demand cloud GPU instances. This forms a hybrid “local + cloud” architecture.

    6. Making the most of 20GB: general optimization practices

    1. Weight quantization
      Prefer 4-bit or 8-bit quantized versions when possible. For example, a 7B model can drop from about 13 GB in FP16 to about 3–4 GB in 4-bit. The freed VRAM can be used entirely for KV cache, enabling longer context or more concurrency. Quantization may introduce slight accuracy loss, so validate answer quality against a business evaluation set before production.

    2. KV cache quantization and compression
      For long-context scenarios, quantizing the KV cache to 8-bit or even lower precision can significantly reduce memory usage. Some inference frameworks support 8-bit KV quantization. Actual support depends on the framework version.

    3. Set reasonable batching and context limits
      Use continuous batching to improve throughput. Also set a reasonable maximum context length per request so that a single long request does not consume all available VRAM.

    4. Reduce prefill overhead
      Use prefix caching to reuse common prefixes such as system prompts. Use tensor parallelism to distribute prefill computation across multiple GPUs and reduce time to first token.

    5. Measure instead of relying only on estimation
      VRAM usage, throughput, and time to first token can vary significantly with framework version, quantization method, and sampling parameters. It is best to run stress tests on the target hardware using real business workloads and use the results as the basis for capacity planning and scaling decisions.

    7. Conclusion

    A consumer GPU with 20GB of VRAM offers a practical balance between local capability and deployment cost. It is suitable for individual developers and small teams building prototypes, running offline inference, and handling privacy-sensitive scenarios.

    When selecting hardware, keep three main lines in mind:

    • VRAM capacity determines the maximum model size and context length.
    • VRAM bandwidth determines decode speed.
    • Native bf16 support and memory-efficient attention determine precision stability and long-context capability.

    At the same time, techniques such as quantization, cache management, and batching can help use VRAM more efficiently. When the workload exceeds the capability of a single GPU, multi-GPU configurations or on-demand cloud GPU instances can be considered. A phased approach of “local development and debugging plus cloud-based elastic service” can help find a sustainable balance between cost and experience.