GPU VRAM Requirements for Running Open-Source LLMs Locally

    Estimate how much GPU memory you need to run 4B, 26B, and 31B open-source language models locally. This guide explains model weights, KV cache, and runtime overhead, compares common VRAM capacities, and provides configuration examples for llama.cpp and vLLM.

    All figures in this article are estimates intended to support hardware selection, not replace testing. Actual memory usage varies with parameter count, quantization format, and inference framework. Check the official model card before downloading a model.

    1. Establish Consistent Measurement Conditions

    A reported VRAM figure can change substantially under different conditions. The following table defines the assumptions used in this guide. Check these same factors when comparing estimates from other sources.

    Factor Assumption used here Notes
    Model size Approximately 4B, 26B, and 31B parameters Parameter counts are approximate; consult the official model card
    Quantization INT4, estimated at 0.5 bytes per parameter Actual formats, including GGUF Q4 variants and AWQ, require slightly more space
    Context length 4K–8K tokens Longer contexts significantly increase KV cache memory
    Batch size 1, for a single-user conversation Concurrent requests increase cache requirements proportionally
    Inference engine llama.cpp, vLLM, Ollama, and similar tools Runtime overhead varies by engine
    Offloading Full GPU loading by default Offloading to system RAM significantly reduces inference speed
    System environment Working drivers and no other large applications using VRAM Desktop environments and browsers also consume VRAM

    2. The Three Main Components of VRAM Usage

    Model weight size alone does not tell you how much GPU memory inference requires. In practice, VRAM usage has three main components.

    Quantized Model Weights

    Weight size is approximately the number of parameters multiplied by the bytes required per parameter. BF16 uses 2 bytes per parameter, while INT4 uses approximately 0.5 bytes. INT4 weights therefore occupy roughly one-quarter of the space required by BF16 weights.

    KV Cache

    During generation, the model stores key and value vectors for previous tokens so that subsequent computations can reuse them. KV cache size can be estimated with this formula:

    1. KV cache bytes ≈ 2 × number of layers × number of KV heads × head_dim
    2. × context length × batch size × bytes per element

    For example, consider a model with 40 layers, 8 KV heads, a head_dim of 128, an 8,192-token context, a batch size of 1, and an FP16 cache using 2 bytes per element:

    1. 2 × 40 × 8 × 128 × 8192 × 1 × 2 ≈ 1.25 GiB

    This example illustrates the calculation only. For an actual model, use the layer count and KV head count in its configuration file.

    Runtime Overhead

    The inference framework’s computation graph, CUDA context, temporary buffers, and preprocessing and postprocessing also consume VRAM. Allow approximately 1–2 GB for this overhead, although the actual amount depends on the framework and driver versions.

    When choosing a GPU, account for all three components and leave some headroom. Sizing VRAM solely around model weights can lead to out-of-memory (OOM) errors as conversations grow longer.

    3. Estimated VRAM Requirements by Model Size

    • Small model, approximately 4B parameters: INT4 weights require around 2–2.5 GB. Including KV cache and runtime overhead, 4–6 GB is generally sufficient. This size is suitable for validating an inference setup and handling everyday questions.
    • Mid-size model, approximately 26B parameters: INT4 weights require around 13 GB. GGUF Q4 files are typically larger, at approximately 14–15 GB. After accounting for KV cache and runtime overhead, more than 16 GB of VRAM is recommended. A 12 GB GPU is only worth attempting with a short context and CPU offloading, which noticeably reduces speed.
    • Large model, approximately 31B parameters: INT4 weights require around 15.5 GB. With a 4K–8K context, total usage is approximately 20–22 GB. A 24 GB GPU provides some headroom, but longer contexts can quickly consume the remaining space.

    4. Choose a Model Based on Dedicated GPU VRAM

    The table below summarizes recommended model sizes and their operating constraints.

    VRAM capacity Recommended model Conditions and risks
    6 GB Approximately 4B Keep the context relatively short. A 26B model cannot fit entirely in VRAM and is not recommended
    8–12 GB Approximately 4B Running a 26B model requires CPU offloading and is slow. Longer contexts may cause OOM errors, making this unsuitable for everyday use
    16 GB Approximately 26B An INT4 model can run reasonably reliably, but context length still needs to be controlled during long, multi-turn conversations
    24 GB or more Approximately 31B The model can fit entirely in VRAM, but long contexts still require context management

    Successfully loading a model does not mean it will run reliably. After deployment, test VRAM usage and generation speed during long conversations. Frequent transfers between GPU memory and system RAM will noticeably degrade the experience.

    Example Inference Engine Settings

    The following examples show common engine settings. Check the help output for your installed version to confirm the exact parameter names.

    llama.cpp:

    1. llama-server -m <model-file>.gguf -ngl <GPU-layer-count> -c 8192 -b 512

    The -ngl option controls how many layers are placed on the GPU. Setting it too high can cause OOM errors; setting it too low reduces speed. The -c option sets the context length.

    vLLM:

    1. vllm serve <model-path> --max-model-len 8192 --gpu-memory-utilization 0.85

    The --max-model-len option limits the maximum context length. The --gpu-memory-utilization option controls the fraction of GPU memory vLLM can use.