Running Open-Source LLMs Locally: VRAM, Quantization, and Model Selection

    This article explains how to plan local open-source LLM deployment by estimating VRAM for model weights, KV cache, and runtime overhead; comparing 4-bit and 6-bit quantization; and selecting dense and MoE models based on task and hardware. It also covers benchmarking at realistic context lengths with llama.cpp, controlling context size, and when to combine local inference with cloud resources.

    1. Estimate VRAM First: Weights, KV Cache, and Runtime Overhead

    VRAM is the first constraint for local inference. VRAM usage consists of three parts:

    1. Model weights: parameter count multiplied by bytes per parameter. FP16 takes 2 bytes per parameter, 6-bit takes about 0.75 bytes, and 4-bit takes about 0.5 bytes. Actual quantized files are slightly larger depending on the format.
    2. KV cache: stores attention intermediate results for the context, and its usage grows with context length and concurrency. The formula is:

      KV cache bytes = 2 × layers × KV heads × head dimension × context length × concurrency × bytes per element

    3. Runtime overhead: the inference framework, GPU driver context, and temporary buffers usually require reserving 1 to 2 GB.

    For example, consider a model with 32 layers, 8 KV heads, and head dimension 128, using FP16 for the KV cache. With a single request, a 4K context cache is about 0.5 GB, and a 20K context cache is about 2.5 GB.

    When selecting a model, first roughly calculate total demand as “weights plus KV cache plus runtime overhead,” then leave headroom. When VRAM is just at the limit, frameworks can easily overflow or fall back to memory offloading, and speed drops noticeably.

    The table below gives weight estimates for common models, excluding KV cache and runtime overhead:

    Model size Estimated 4-bit weights Estimated 6-bit weights 12GB VRAM 24GB VRAM
    9B dense model ~4.5GB ~6.8GB Can run fully Can run fully with ample headroom
    14B dense model ~7GB ~10.5GB 4-bit can run fully; 6-bit requires offloading Can run fully
    27B dense model ~13.5GB ~20GB Cannot fit fully; requires offloading, with a noticeable speed drop 4-bit can run fully; 6-bit has very little headroom and may be insufficient with long contexts
    35B total-parameter MoE model ~17.5GB ~26GB Requires offloading some weights to memory 4-bit can run fully; 6-bit requires offloading or more VRAM

    Note that MoE models activate only a small subset of parameters per pass, but all weights still need to reside in VRAM or memory. Therefore, “fewer active parameters” does not mean “lower VRAM usage.”

    2. 4-bit or 6-bit: Choose by Goal

    Q4 and Q6 are common quantization levels in the community. Their main differences are as follows:

    Comparison 6-bit (Q6-like) 4-bit (Q4-like)
    File size Larger, about 1.5 times that of 4-bit Smaller
    Answer quality Closer to the original model; generally more stable on complex reasoning, code, and fine-grained instruction following Usable for most daily tasks; details and long-chain reasoning may decline slightly
    Inference speed Usually slower Usually faster, because fewer weights need to be read per token
    Use cases VRAM headroom, quality first Tight VRAM, speed or concurrency first

    4-bit is usually faster, but the gain depends on the model, hardware, and inference framework; do not copy someone else’s numbers. The most reliable approach is to compare the two quantized versions on your own machine with the same set of scripts.

    The standard for evaluating speed should also change with the scenario. For human reading, 5 to 10 tokens per second is usually enough to keep up with reading pace. Interactive chat cares more about first-token latency and output smoothness. Offline batch processing cares only about total time.

    3. Model Size Selection: Trade-offs by Task and Hardware

    Common local models fall into three categories:

    • Small dense models (about 7B to 9B): relatively weaker absolute capability, but low VRAM usage and less speed degradation at long contexts; suitable as an always-on model for daily tasks.
    • Medium-to-large dense models (about 27B): generally stronger overall capability, but high VRAM requirements; difficult to run fully on 12GB VRAM.
    • Large-total-parameter MoE models (about 35B total parameters, about 3B active parameters): low compute per token and usually faster, but total weight size remains large, so VRAM and memory requirements are still high. Some MoE models may be less coherent than dense models of comparable scale in summarization and synthesis of very long documents; this varies by model and should be tested with your own long documents.

    Model selection can follow this order:

    1. When hardware is sufficient, choose the dense model with the strongest overall capability that can fit fully in VRAM.
    2. When hardware is constrained, choose between a faster MoE model and a smaller model with more stable long-context performance based on the task’s context length and quality requirements.

    This article does not provide specific measured speeds because the speed of the same model is affected by quantization tools, context length, batch size, and driver version. Readers should rely on their own test results.

    4. Deployment and Benchmarking Steps

    1. Choose a mature inference runtime: prefer open-source frameworks that support mainstream quantization formats and provide OpenAI-compatible APIs, making integration with higher-level applications easier.
    2. Disable unnecessary reasoning modes: some models output reasoning by default, which lengthens responses and reduces effective speed. How to disable it varies by model and framework version; check the model card and the framework documentation to confirm whether a corresponding parameter or chat template variable is available.
    3. Benchmark at real context lengths: advertised speeds are usually measured at short contexts. With llama.cpp, for example, use the following commands to test 4K and 20K contexts:
    1. llama-bench -m model-file.gguf -p 4096 -n 128 -ngl 99
    2. llama-bench -m model-file.gguf -p 20480 -n 128 -ngl 99

    Here, -p sets the prompt length, -n sets the generation length, and -ngl sets the number of layers offloaded to the GPU. The output lists prompt processing speed and generation speed separately; record the latter as a reference for chat experience. If VRAM is insufficient, gradually lower -ngl and record the speed change.

    1. Control context length: longer context settings increase KV cache size and consume more VRAM. Use the smallest sufficient value required by the workload.

    5. When You Need Cloud Resources

    Local deployment suits privacy-sensitive scenarios with moderate call volume. When you need to run larger models, support multiple concurrent requests, or fine-tune models, consumer hardware is usually insufficient. In that case, consider cloud options such as model inference services, container platforms, and GPU instances from major cloud providers. When choosing, compare price, available regions, data storage and cross-border transfer terms, and whether the required model versions are available.

    A common combination is “local small models for daily tasks, cloud large models for complex tasks.” With this architecture, design routing rules so requests involving sensitive data always stay local.