Running Mixture-of-Experts LLMs on Consumer GPUs: Practice and Analysis

    Mixture-of-Experts (MoE) models have large total parameter counts but activate only a small fraction per token, making them feasible to run locally even when the full weights exceed GPU VRAM. This article breaks down the hardware budget for local deployment—model weights, KV cache, and intermediate buffers—explains why MoE architectures work on limited VRAM, walks through a practical deployment workflow, and describes how to measure inference performance and evaluate quality claims correctly.

    1. Background

    Mixture-of-Experts (MoE) large language models have appeared in large numbers recently. These models have very large total parameter counts, but inference for each token only activates a small fraction of those parameters. For local deployers, this means a model whose full weights cannot fit in VRAM may still be runnable.

    One developer ran a model with 35B total parameters and roughly 3B active parameters on a machine with 8GB of VRAM and 16GB of RAM, completing multiple rounds of conversation. The recorded generation speed was about 16 tokens per second with a context of around 23,000 tokens. This figure demonstrates feasibility, but it only reflects one configuration and one type of task. The sections below break this kind of practice into reusable methods.

    2. Do the Math First: Three Components of the Hardware Budget

    Before deploying locally, you need to estimate three kinds of memory usage.

    2.1 Model Weights

    Weight size is approximately the parameter count multiplied by the storage bits per parameter, divided by 8. With 4-bit quantization, a 35B-parameter model weighs in at roughly 18GB. That already exceeds the VRAM of most consumer GPUs and is also larger than a typical 16GB of system RAM.

    2.2 KV Cache

    During text generation, the model must store the attention keys and values for every processed token—the KV cache. Its size can be approximated as:

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

    The longer the context, the larger the KV cache. A 64K context brings considerable extra usage. In the later stages of a multi-turn conversation, memory pressure will be noticeably higher than at the start.

    2.3 Intermediate Compute Buffers

    Inference also requires activation values, temporary tensors, and the runtime framework’s own overhead. As a rule of thumb, leave some headroom rather than allocating all VRAM and RAM to weights.

    3. Why MoE Can Run on Limited VRAM

    A dense model uses all of its parameters to generate every token. In an MoE model, each layer typically contains a router that selects a small number of experts to participate in the computation for each token. The model’s total size and its per-step compute cost are therefore two separate metrics.

    The model’s components can be divided into two categories:

    • Resident components: attention layers, the router, shared experts (if any), embedding layers, and so on. These are used at every step and are good candidates for GPU acceleration.
    • On-demand components: routed experts. Only a few are activated at each step; the rest take no part in computing the current token.

    This distinction is the basis of the offloading strategy. Keeping resident components in VRAM and on-demand components in system RAM reduces VRAM pressure while preserving compute speed.

    One caveat is needed here. The claim that inactive experts consume no memory only holds under a specific mechanism. Expert weights must be stored somewhere. If total weights exceed RAM capacity, the system typically relies on memory mapping: data pages are read into RAM on demand when accessed, while unaccessed pages remain on disk. This explains why observed RAM usage in practice is far below total weight size.

    However, if the activated experts switch frequently between adjacent tokens, disk reads increase and speed can drop sharply. The effectiveness of offloading therefore depends on routing locality and is constrained by RAM capacity and disk read speed.

    4. Deployment Workflow

    The workflow below applies to most local inference frameworks. Refer to your framework’s documentation for exact parameter names.

    4.1 Prepare the Inference Runtime

    Get the source code or a precompiled build from the official repository and compile it according to its instructions. Make sure the acceleration backend matching your GPU is enabled during compilation. Run a smoke test with a small model first to confirm normal output before loading a large model.

    4.2 Choose a Quantization Level

    More aggressive quantization means smaller size but greater precision loss. 4-bit quantization is usually the compromise in VRAM-constrained scenarios. When choosing, check the release notes for the size and benchmark data of each quantization tier rather than judging by filename alone.

    4.3 Configure Launch Parameters

    An illustrative configuration is shown below. The key names are for explanatory purposes only and are not real parameters of any specific framework:

    1. model_path: ./models/moe-35b-a3b-q4.bin
    2. context_length: 65536
    3. gpu_layers: all_resident_layers # attention, router, shared experts go into VRAM
    4. expert_offload: cpu_or_mmap # routed experts stay in RAM or are accessed via memory mapping
    5. threads: physical_core_count
    6. batch_size: 512

    Follow these principles when setting parameters:

    1. Set context length based on actual needs; do not max it out by default.
    2. The thread count should generally match the physical core count; exceeding it introduces scheduling overhead.
    3. Change only one parameter at a time and record the results, so the effect of each change is clear.

    4.4 Verify the Deployment

    After startup, watch three metrics: VRAM usage, RAM usage, and generation speed. Leave headroom in VRAM to avoid overflow at long contexts. If RAM usage nears its limit while speed drops sharply, frequent paging is usually the cause.

    5. Measuring Performance Correctly

    The subjective impression that “speed is fine” is easily skewed by context length and task type. A proper measurement should distinguish two phases:

    • Prefill: the speed of processing the input prompt in one pass, usually measured in tokens processed per second.
    • Decode: the speed of generating output tokens one by one, which is the output speed the user actually perceives.

    Measurement recommendations:

    • Fix the prompt and output length, repeat multiple times, and take the median.
    • Record decode speed at short and long contexts separately, and plot the curve of speed versus context growth.
    • Record temperature and power draw as well. Under sustained load, the GPU may throttle, causing speed to decline later in a session.

    In multi-turn conversation, each turn grows the KV cache, and decode speed usually declines with it. A single test result therefore cannot represent the experience of a long session.

    6. How to Evaluate Quality Claims

    Claims like “a model with fewer active parameters matches much larger dense models” deserve attention, but they need concrete verification.

    • Public benchmarks: check the model’s scores on general knowledge, reasoning, and coding benchmarks, and confirm that the comparison targets and evaluation settings are consistent.
    • Your own tasks: build a small evaluation set around real work, including reference answers, edge cases, and format requirements.
    • Quantization impact: compare the quantized version against the original-precision version on the same set of tasks.