Running a 27B Model on a 22GB GPU: Budget VRAM Before Choosing Settings

    A 27B model can run on a consumer GPU with 22GB of VRAM, but model weights are only part of the memory budget. This guide explains how to estimate KV cache and vision-related memory use, choose a starting llama.cpp configuration, measure inference performance, and compare quantization options and dense versus MoE models.

    1. Start with the VRAM Budget

    Running a 27B-class model on a consumer GPU with 22GB of VRAM is feasible—but only if you account for memory use first. Model weights, the KV cache, the vision encoder, and runtime overhead all consume VRAM. If their combined requirements exceed available memory, the model may fail to load or crash during a long conversation.

    The practical approach is to estimate memory requirements, choose settings that fit, and then validate them through testing.

    2. How to Estimate VRAM Requirements

    The memory budget has four main components:

    1. Model weights: A Q4-quantized 27B model typically requires around 15–16GB, depending on the quantization scheme and which layers retain higher precision.
    2. Vision encoder or projector (mmproj): Image understanding adds memory requirements. Use the actual file size as a budgeting reference.
    3. KV cache: Memory use grows linearly with context length, making this the main variable in long-context workloads.
    4. Runtime overhead: Framework compute buffers, memory fragmentation, and system usage also consume VRAM. Reserve approximately 1–2GB.

    The approximate KV cache formula is:

    1. KV cache bytes =
    2. 2 × number of layers × number of KV heads × head dimension
    3. × context length × bytes per element

    The factor of two accounts for both the key and value caches. Bytes per element are 2 for FP16, approximately 1 for Q8, and approximately 0.5 for Q4.

    This is only an estimate. Models using grouped-query attention (GQA) have fewer KV heads and can therefore require substantially less cache memory. Always use the actual configuration of your model.

    Consider a hypothetical model with 64 layers, 8 KV heads, a head dimension of 128, and a context length of 32,768 tokens. Its KV cache would require approximately 8GB at FP16 or 4GB at Q8.

    At a 100K-token context length, the same architecture would need approximately 12GB for a Q8 KV cache. Adding around 15GB of weights, roughly 1GB for the vision component, and runtime overhead brings the total above 28GB. A 22GB GPU cannot hold all of this at once. A claim that this configuration supports a 100K-token context entirely within 22GB of VRAM does not hold up under this calculation.

    On a 22GB GPU, start with a 16K-token context and aim to leave approximately 3GB of headroom. Once the model runs reliably, increase the context length gradually toward 32K.

    If you need a longer context, consider lower-precision weights, a smaller model, or fewer concurrent requests. However, Q3 quantization can degrade the capabilities of a 27B-class model, so test output quality before reducing precision.

    For llama.cpp, an example starting command is:

    1. ./llama-server \
    2. -m model-27b-q4.gguf \
    3. --n-gpu-layers 999 \
    4. --cache-type-k q8_0 \
    5. --cache-type-v q8_0 \
    6. --flash-attn on \
    7. --ctx-size 16384 \
    8. --mmproj mmproj.gguf

    Before launching, run ./llama-server --help to verify the supported parameter names. These may change between versions.

    Quantized V cache typically also requires Flash Attention. Check the documentation for your installed version to confirm the relevant settings. The command does not include --mtp, because it is not a universally supported option across versions.

    4. How to Measure and Interpret Performance

    Previously reported reference speeds were approximately 23–30 tokens per second. However, those figures did not include complete test conditions, such as the model version, quantization, context length, concurrency, or framework version. They should not be used directly to make hardware purchasing decisions.

    For reproducible measurements, keep the following conditions fixed and record them:

    • Model filename and quantization type
    • Context length
    • Input and output token counts
    • Number of concurrent requests
    • Backend, such as CUDA or Vulkan
    • Framework version or commit hash

    Record two separate metrics:

    • Time to first token (TTFT): Reflects prompt-processing, or prefill, performance.
    • Decode speed: Reflects how quickly the model generates output tokens.

    These metrics are affected by different factors and should be evaluated separately.

    Generation-time estimates are straightforward. Producing 500 tokens takes approximately 20 seconds at 25 tokens per second, or 25 seconds at 20 tokens per second. Streaming lets users see output sooner, but does not reduce the total generation time.

    What MTP Can—and Cannot—Accelerate

    Multi-token prediction (MTP) allows a model to predict tokens at multiple subsequent positions in a single forward pass. During inference, it is often used for speculative decoding: several tokens are drafted, then verified by the main model.

    With standard acceptance and rejection sampling, the output distribution is theoretically equivalent to ordinary autoregressive decoding. Whether MTP can be enabled depends on two requirements:

    1. The model weights must contain the corresponding prediction heads.
    2. The inference framework must implement the appropriate decoding path.

    MTP benefits are usually most noticeable for short-context tasks that generate substantial output. It does not accelerate prefill, so long-document inputs can still have high TTFT.

    As concurrency increases, verification overhead must be weighed against batching benefits. Use measured results rather than assuming that MTP will always improve throughput.

    5. Choosing Between Dense and MoE Models

    A 27B dense model activates all its parameters during inference and can provide relatively consistent generation quality.

    A mixture-of-experts (MoE) model has a large total parameter count but activates only some experts for each token. This can make decoding faster. However, faster decoding does not mean lower VRAM requirements: all expert weights still need to be loaded into VRAM for fully GPU-resident inference.

    An earlier reference mentioned an MoE model with approximately 35B total parameters and around 3B active parameters per token, along with high decode-speed figures. Its exact model name should be verified on the official release page; those speed figures are not used here.

    For this type of model, the same budgeting process applies: calculate weight storage and KV cache requirements before choosing a context length.

    Dimension Dense model, approximately 27B MoE model with many total parameters but fewer active parameters
    VRAM use All model weights must fit in VRAM All expert weights must fit in VRAM
    Decode speed Limited by computation across all parameters Fewer active parameters can make decoding faster
    Generation quality Often more consistent at comparable scale Model-dependent; requires testing
    Typical use cases Complex reasoning, coding, multi-step agents Everyday conversation, batch processing

    6. Quantization and Output Quality

    KV Cache Quantization

    KV cache quantization is generally less risky for quality than weight quantization. Q8 typically has a small impact, but it should still be tested with long contexts.

    Weight Quantization

    Q3 quantization can reduce the capabilities of a 27B-class model. A previously reported case of degraded instruction following in a particular Q4_K_M release also suggests that different releases at the same nominal precision may behave differently.

    If quality problems appear, try a quantized file from another source or increase precision.

    Vision Support

    A vision component enables image understanding in a compatible model, but it also consumes VRAM and must be included in the budget.

    Community feedback suggests that some 27B-class models perform well on multi-step tool use and codebase understanding. However, there is no uniform evaluation standard for these reports, so judge the model against your own tasks.

    Prepare 10–20 real test cases—for example, code refactoring, long-document summarization, and structured information extraction—and compare different quantized versions side by side. General benchmark scores alone are unlikely to show whether a model is usable in your workflow.

    7. Troubleshooting Checklist

    • Out-of-memory error at startup: Reduce the context length, offload fewer layers to the GPU, or use a smaller weight file.
    • Slowdowns or crashes during long conversations: Check whether KV cache requirements exceed the memory budget as the context grows, and lower the context limit if necessary.