Local LLM Deployment: Tuning VRAM and Throughput in Practice

    This article walks through practical tuning of local large language model inference, focusing on VRAM usage and throughput. It explains why default parameters often hide performance bottlenecks, how to offload Mixture-of-Experts (MoE) layers, how to budget KV cache precision and length, how to probe the maximum context window with binary search, and why parallel slots and batch sizes should be tuned for single-user workloads. It also covers non-generative context compression for long conversations and ends with a step-by-step deployment workflow. Readers will learn how to achieve several-fold throughput gains on limited VRAM.

    1. Why Default Parameters Are the Biggest Performance Drain

    When running LLMs locally, the common approach is to use a model runner or a general-purpose inference framework, load the weights into VRAM with a single command, and start chatting. The process looks smooth, but the real performance bottleneck is often hidden by the default configuration. Defaults are designed to “start on as much hardware as possible,” not to “run fastest on the current GPU.” As a result, they make conservative or even wrong trade-offs: packing all layers into VRAM, enabling multiple parallel slots, using medium-precision KV cache, and setting a small context window.

    The outcome: VRAM usage looks high while throughput is absurdly low; or VRAM is not full but the context is capped at a tiny value. To break through this, developers need to understand the coupling between several core variables: model architecture (dense vs. Mixture-of-Experts), KV cache precision and length, number of parallel slots, batch granularity, and offloading strategy.

    2. Offloading Strategy for MoE Models: The Decisive Lever

    Mixture-of-Experts (MoE) architectures split the feed-forward network into multiple expert subnetworks, and each token activates only a few of them. These models have a very large total parameter count, but the compute per inference is relatively manageable. The problem is VRAM: planning by “total parameters” easily leads to the conclusion that “this GPU can’t fit it”; but planning by the “activation path”—keeping resident compute like attention layers in VRAM and placing expert layers in system memory on demand, scheduled by the inference framework at runtime—can deliver high throughput on a very small VRAM budget.

    Measurements show a striking contrast: on the same 8GB GPU, putting all layers in VRAM nearly maxes out VRAM and yields only single-digit tokens/s; putting only attention-related layers in VRAM and routing expert layers to memory drops VRAM usage to around 30% while pushing throughput above 20 tokens/s—about a 7x speedup, with less VRAM used.

    The engineering key is recognizing tensor naming patterns. General-purpose inference frameworks typically distinguish roles by tensor name, and expert feed-forward layers often carry a recognizable naming pattern (for example, containing the ffn and exps fragments). A tuning script can use regex matching to split tensors into “resident in VRAM” and “offloadable” groups, then generate a layer-placement config the framework supports. Note that naming may differ across model families, so the script should use a configurable rule table rather than a single hard-coded pattern.

    Illustrative pseudocode:

    1. import re
    2. EXPERT_PATTERN = re.compile(r"ffn_.*_exps")
    3. def classify(tensors):
    4. gpu, cpu = [], []
    5. for name in tensors:
    6. (cpu if EXPERT_PATTERN.search(name) else gpu).append(name)
    7. return gpu, cpu

    3. KV Cache: The VRAM Math of Precision and Length

    The KV cache is the second-largest source of VRAM usage, and its size can be estimated directly:

    1. KV_MB = 2 × layers × kv_heads × head_dim × ctx × bytes / 1024²

    Here layers is the number of layers, kv_heads is the number of key-value heads (much smaller than attention heads under grouped-query attention), head_dim is the per-head dimension, ctx is the context length, and bytes is the number of bytes per element (2 for half precision, ~1 for 8-bit quantization, ~0.5 for 4-bit quantization).

    On the same 8GB GPU with the same 8B dense model, throughput differs by nearly 3x across KV configurations: half-precision KV is fastest, 8-bit and 4-bit mixed quantization are noticeably slower, and the combination of “high-precision KV + multiple slots + long context” is slowest. The reason is that low-bit KV requires extra dequantization compute, and paging and slot-management overhead rises.

    So the correct strategy is not to quantize blindly, but to do the math first and then decide: estimate KV usage at half precision first; if enough VRAM remains, use half precision; if not, step down to 8-bit, then 4-bit, while watching whether throughput actually drops.

    4. Context Limit: Skip Formula-Based Prediction, Use Binary Probing

    The VRAM estimation formulas circulating in the community are mostly fitted for 8-bit weights and half-precision KV. Once weight or KV precision changes, the error is amplified and available context is often severely underestimated (for example, computing only 4K). A more reliable approach is to let the runtime answer for itself: start from min(native context, 65536), and if VRAM overflows, halve the candidate, probing at most five rounds and taking the first value that starts successfully.

    1. candidate = min(native_ctx, 65536)
    2. for _ in range(5):
    3. if start_server(ctx=candidate) succeeds:
    4. break
    5. candidate //= 2

    This replaces “estimation” with “verification,” which is more robust in local environments with complex precision combinations and frequently changing framework versions. In practice, the usable context of an 8B model can often be raised from 4K to the 64K range.

    5. Parallel Slots: Converge to 1 for Single-User Scenarios

    To support concurrent multi-user access, general-purpose inference frameworks enable multiple parallel slots by default, splitting VRAM across slots. In a single-user interactive scenario, this cuts KV VRAM and compute scheduling into four parts, wasting VRAM and lowering single-request throughput. Converging slots to 1 can nearly double throughput for the same model (for example, from about 18 tokens/s to about 38 tokens/s). The rule is simple: if the service serves only one interactive session, slots should be 1; only increase gradually when there is genuine concurrency demand and ample VRAM.

    6. Batch Granularity: Measure Instead of Guess

    The optimal values for batch-related parameters (especially compute batch and micro-batch size) are strongly tied to model architecture and VRAM bandwidth, with no universal answer. The empirical trend: the longer the context, the more a larger micro-batch helps. In measurements, a larger micro-batch was about 7.6% faster than a small one at 8K context, and about 21.6% faster at 64K context. Engineering-wise, put candidate values into the startup script, run a benchmark over a fixed prompt set, and take the highest throughput, rather than copying documentation defaults.

    7. Long-Conversation Context Compression: Don’t Block the Main Path with Generative Summarization

    When the context approaches its limit, history must be compressed. The initial common approach is to call a local model to generate a summary, but under a single-slot configuration, the summary request competes with the main conversation for the same execution queue, easily causing timeouts or even deadlocks. A more robust option is non-generative compression: keep the most recent N turns verbatim by turn, apply structured extraction to earlier content (preserving user goals, constraints, confirmed conclusions, and to-dos), and, when needed, combine with external storage and retrieval to turn long history into “summary entries + on-demand recall.” The main path only does concatenation, without introducing extra model calls.

    1. Identify the model architecture (dense or MoE) and decide the offloading strategy accordingly;
    2. Estimate half-precision usage with the KV formula and choose a precision tier;
    3. Converge slots to 1 and set micro-batch to the measured optimum;
    4. Determine the context limit with binary probing;
    5. Build a fixed benchmark set and continuously regress throughput and VRAM;
    6. Use non-generative compression and external retrieval for long conversations.

    Tuning in this order typically yields several-fold throughput gains on limited VRAM while moving context capability from “just enough” to “comfortable.” In cloud environments, the same methodology can be solidified into reusable deployment templates by combining container platforms, object storage, and monitoring/alerting services, achieving a consistent tuning baseline across local and cloud.