Local LLM Inference Parameter Tuning: A Practical Guide for MoE Models

    This article explains how to tune key parameters for locally served MoE large language models under limited VRAM. Based on two consumer hardware platforms and Q4-quantized models, it covers context length, GPU offload, evaluation and physical batch sizes, CPU-side expert weight placement, and KV cache quantization, with measured prefill and decode results plus practical tuning recommendations.

    As mixture-of-experts (MoE) large language models become more common, more developers are deploying them on local workstations. MoE models are characterized by a large total parameter count and a small active parameter count. For example, a model with roughly 35B total parameters and about 3B active parameters per step can offer useful inference capability after Q4 quantization while keeping VRAM requirements relatively modest. However, the performance of such a deployment depends heavily on inference serving configuration. This article uses a common local model serving setup as an example and combines hands-on experience from two hardware platforms to explain how key parameters should be configured.

    1. Hardware Platforms and Models

    The tuning experience in this article is based on two typical hardware combinations:

    • Platform A: DDR5 5600 memory + a mid-to-high-end consumer GPU with 16GB VRAM;
    • Platform B: DDR5 6000 memory + a mid-range consumer GPU with 12GB VRAM.

    The main model discussed is a Q4-quantized MoE model with roughly 35B total parameters and about 3B active parameters. Because the total parameter count far exceeds the VRAM capacity of a single GPU, a hybrid inference strategy using GPU offload plus CPU sharing is required. This is the core difficulty in parameter tuning. At the end of the article, a smaller MoE model with about 14B total parameters is also used as a comparison to show how model scale affects configuration strategy.

    2. Key Parameters Explained

    2.1 Context Length

    Context length directly determines the VRAM footprint of the KV cache. Setting the context length to 262144 (256K) can support very long document analysis and codebase-level understanding, but the KV cache will consume a large amount of VRAM and squeeze the space available for resident model weights. Reducing it to 128000 frees more resources for model weights. Therefore, this parameter should be set according to actual requirements rather than always maximized.

    2.2 GPU Offload Layers

    GPU offload determines how many Transformer layers of weights remain resident in VRAM. In testing, both platforms used an offload of about 40 layers, which is a balance point between weight residency and KV cache space. Too little offload causes a large amount of computation to fall back to the CPU, sharply reducing decode speed. Too much offload can cause VRAM overflow in long-context scenarios.

    2.3 Evaluation Batch Size and Physical Batch Size

    Evaluation batch size affects the number of tokens processed at once during the prefill stage, while physical batch size constrains the actual chunk size in VRAM. The two need to be configured together:

    • Long-context scenarios: Larger batch combinations are recommended, such as 8192/4096 or 4096/2048, to significantly improve prefill throughput.
    • Fast-generation scenarios: Smaller combinations such as 2048/512 can reduce peak VRAM usage and leave room for the KV cache and weights.

    Note that an excessively large physical batch can easily trigger overflow on a 12GB VRAM platform. It is recommended to start with conservative values and increase them gradually while validating stability.

    2.4 CPU Placement of MoE Expert Weights

    This is a key parameter specific to MoE models. Because each layer of an MoE model contains a large number of expert weights while only a small number of experts are activated at a time, placing some expert weights in CPU memory and scheduling them on demand can trade memory for VRAM. In testing:

    • Long-context configurations needed more expert weights (26–32 units) placed on the CPU to free space for the KV cache.
    • Fast-generation configurations needed only 15–27 units, allowing more weights to remain on the GPU and improving decode speed.

    This parameter acts as an adjustment valve for balancing VRAM usage and is also a major source of performance differences among configuration plans.

    2.5 KV Cache Quantization

    Quantizing the KV cache to Q8 can reduce cache usage by about half with almost no loss in generation quality. For ultra-long contexts at the 256K level, KV quantization is almost mandatory; otherwise, 12–16GB of VRAM can hardly hold both weights and cache.

    3. Two Typical Configuration Plans and Performance Reference

    3.1 Platform A (16GB VRAM + DDR5 5600)

    Plan 1: Long-context priority

    • Context length: 262144
    • GPU offload: 40 layers
    • Evaluation/physical batch size: 8192 / 4096
    • CPU-side expert weights: 26
    • KV quantization: Q8
    • Measured performance: prefill about 2600 token/s, decode about 55 token/s

    Plan 2: Fast-generation priority

    • Context length: 128000
    • Evaluation/physical batch size: 2048 / 512
    • CPU-side expert weights: 15
    • Measured performance: prefill about 900 token/s, decode about 69 token/s

    The two plans show a clear tradeoff. Plan 1 delivers nearly three times the prefill throughput of Plan 2 and is suitable for loading long documents in a single pass. Plan 2 has faster decode and is better suited to conversational continuous output.

    3.2 Platform B (12GB VRAM + DDR5 6000)

    • Long-context plan: context 262144, batch size 4096/2048, CPU-side expert weights 32, KV quantization Q8; prefill about 1600 token/s, decode about 47 token/s.
    • Fast-generation plan: context 128000, batch size 2048/512, CPU-side expert weights 27; prefill about 720 token/s, decode about 51 token/s.

    Comparing the two platforms shows that the smaller the VRAM, the more expert weights need to be moved to the CPU, and overall speed drops by about 30%–40%. However, with appropriate configuration, 256K context can still run smoothly.

    3.3 Comparison with a Smaller Model

    When deploying an MoE model with about 14B total parameters (Q4 quantized) on Platform B, the model itself can fit entirely in VRAM, so CPU-side expert weights can be set to 0. Under a 128000 context and 2048/512 batch size, prefill reaches about 2700 token/s and decode about 89 token/s. This shows that when VRAM is sufficient to hold all weights, the advantage of MoE’s small active parameter count is fully released.

    4. Practical Tuning Recommendations

    1. Restart the inference service before testing: Testing showed that if the service is not restarted after loading models multiple times, VRAM fragmentation and cache residue can cause a 10%–15% performance drop. Always restart before formal benchmarking.
    2. Define the scenario before setting parameters: Determine whether the workload is long-document analysis or high-frequency conversation, then choose the corresponding batch size and weight placement strategy. Do not try to use one set of parameters for every scenario.
    3. Adjust incrementally: Change only one parameter at a time and record the changes in prefill/decode performance to avoid being unable to attribute performance changes when multiple parameters are modified together.
    4. Watch memory bandwidth: CPU-side expert scheduling for MoE models depends heavily on memory bandwidth. DDR5 6000 can provide a noticeable decode improvement over 5600, and upgrading memory is often more cost-effective than upgrading the GPU.

    5. Conclusion

    Local deployment of MoE large models is essentially a resource-scheduling tradeoff among VRAM, memory, and compute. By properly configuring five key parameters—context length, GPU offload, batch size, expert weight placement, and KV quantization—even a mid-range platform with 12GB VRAM can support 256K ultra-long context and usable generation speed. We hope the configuration approaches and measured data in this article provide a reusable reference for developers tuning local inference services.