Running a ~30B MoE Model on 8GB VRAM and 16GB RAM: A Practical Guide

    This guide explains how to run a large Mixture-of-Experts (MoE) language model with roughly 30 billion parameters on a modest machine with 8GB of VRAM and 16GB of RAM. It covers why MoE architectures make this possible, how to choose a quantization format, how to configure expert offloading in llama.cpp, how to tune KV Cache usage, what performance to expect, and how to troubleshoot common errors.

    Why 8GB of VRAM Is Enough for a ~30B MoE Model

    For a dense model, every token must pass through all parameters, so if the weights don’t fit in VRAM, inference slows down significantly. Mixture-of-Experts (MoE) models work differently. Their total parameter count is large, but each token only activates a small subset of it—commonly around 30 billion total parameters with only about 3 billion active per token. Most expert weights sit idle during any single forward pass, so they don’t all need to reside in VRAM.

    This makes it practical to split the model into two parts: keep the compute hotspots on the GPU, and hold the remaining expert weights in system memory, letting the inference framework move them on demand. The practice described in this article follows this approach and was deployed on a machine with 8GB of VRAM and 16GB of RAM.

    Note that the speed and memory figures in this article come from the author’s own machine and were not collected through rigorous benchmarking. Your results will vary depending on the model, quantization format, CPU, and memory specifications—always rely on your own measurements.

    Preparation Before Deployment

    For hardware, 8GB of VRAM plus 16GB of RAM is workable, but more memory means more stable operation. The model files take up roughly 18GB, and with the OS and framework included, you should reserve at least 30GB of free disk space.

    When choosing a model, prefer MoE models with a small number of active parameters and a moderate total size—for example, models with around 30B total parameters and about 3B active. Download model files from official or trusted hosting platforms. Before downloading, confirm the license permits your intended use; after downloading, verify the SHA256 checksum published on the model page to avoid corrupted or tampered files.

    For the framework, use a llama.cpp-based inference framework that supports MoE expert offloading. Clone the repository and build it with CMake following the README. If you’re unfamiliar with the build process, an AI coding assistant can help—it usually doesn’t take long.

    Choosing a Quantization Format

    Quantization is a trade-off between quality and size. A 4-bit format like IQ4_NL typically compresses a ~30B parameter model down to around 18GB, with quality loss that is acceptable for most everyday conversation and coding tasks. If you want higher quality, you can choose a larger quantized file, but that requires more memory and disk space. With only 16GB of RAM, an oversized file will force frequent disk reads and noticeably degrade speed.

    Quantizing to too few bits damages the precision of expert weights, and precision-sensitive tasks like code generation and mathematical reasoning are more likely to produce errors. For this reason, avoid compressing to very low bit widths just to save space.

    Launch Parameters and CPU-MoE Offloading

    The following command uses a recent version of llama-server as an example. Parameter names change between versions, so run ./llama-server --help before executing to confirm your build supports these options.

    1. ./llama-server \
    2. -m ./models/your-moe-model-IQ4_NL.gguf \
    3. --host 127.0.0.1 \
    4. --port 1234 \
    5. --timeout 600 \
    6. -b 2048 \
    7. -c 65536 \
    8. -ngl 99 \
    9. --n-cpu-moe 33 \
    10. --flash-attn on \
    11. --cache-type-k q4_0 \
    12. --cache-type-v q4_0

    What each parameter means:

    • -m: path to the model file.
    • --host 127.0.0.1: allow local access only. Change to 0.0.0.0 for LAN access, but the server has no built-in authentication, so only use this on trusted networks.
    • -b 2048: batch size.
    • -c 65536: context length in tokens. The longer the context, the more VRAM the KV Cache consumes.
    • -ngl 99: offload as many layers as possible to the GPU. This is an upper bound on GPU layers; 99 means all layers, and the framework automatically truncates it if it exceeds the actual layer count. Note that this differs in meaning from the CPU offloading parameter below.
    • --n-cpu-moe 33: keep the expert weights of the first 33 layers in CPU memory, leaving the expert weights of remaining layers on the GPU. This is the key parameter for controlling VRAM usage. Its value is a layer count, not a GPU layer count.
    • --cache-type-k and --cache-type-v: quantize the KV Cache to q4_0. Quantizing the V Cache requires Flash Attention to be enabled.

    If your framework version is older and doesn’t support --n-cpu-moe, you can instead use a regex rule to override where tensors are stored:

    1. --override-tensor "blk\.([0-9]|[12][0-9]|3[0-2])\.ffn_.*_exps\.=CPU"

    This rule places the expert tensors of layers 0 through 32 on the CPU, which is equivalent to --n-cpu-moe 33.

    Tuning the Number of CPU-Offloaded Layers

    The tuning method is to adjust the value of --n-cpu-moe step by step while watching VRAM usage. Start with a large value (for example, the model’s total layer count) to confirm the model starts, then decrease it gradually to move more experts back to the GPU. Based on the author’s experience, keeping VRAM usage around 80% works well, leaving headroom for the KV Cache and compute buffers. If the model fails to start or reports insufficient VRAM after a decrease, back off by one or two layers.

    On the author’s machine, a value of 33 resulted in about 7.3GB of VRAM usage. This number depends on the specific model and framework version and cannot be applied directly to your setup.

    KV Cache Quantization

    KV Cache usage grows linearly with context length. After q4_0 quantization, the VRAM required for context drops significantly, making a 64K-level context feasible on 8GB of VRAM. However, quantization introduces some quality loss—for long-context Q&A and code editing tasks, compare outputs with and without it. If you run out of VRAM, lower -c first, then increase the number of CPU-offloaded layers.

    Performance and Memory Bandwidth

    During multi-turn conversations with the context accumulating to roughly 23,000 tokens, the author observed generation speeds close to 16 tokens/s. This is an approximate figure from repeated subjective observation and does not represent every scenario. For local inference, it falls into the “barely usable but acceptable” range. How it compares to certain cloud APIs depends on network latency and task type.

    During tuning, the author found that the main factor limiting generation speed was memory bandwidth, not memory capacity. In this hybrid mode, the expert weights hit by routing on each inference pass must be moved from system memory to the compute units, and the ceiling on that transfer speed is set by memory bandwidth.

    The author’s memory is dual-channel DDR4-2666, with a theoretical bandwidth of about 42.6GB/s. Dual-channel DDR5-5600 offers roughly 89.6GB/s—about twice as much. Under otherwise similar conditions, upgrading memory may improve generation speed for this kind of deployment. But this judgment only holds for the same model, quantization, CPU, and offloading ratio. Compare benchmarks on your own machine before upgrading, and don’t assume it is necessarily more cost-effective than upgrading your GPU.

    Common Errors and Fixes

    • CUDA out of memory on startup: reduce -c, or increase --n-cpu-moe to move more experts to the CPU.
    • Startup succeeds but speed is extremely slow with the disk light flashing constantly: model file reads exceed available memory and the system is paging continuously. Close memory-hungry programs, or switch to a smaller quantized file.
    • Unknown parameter error: your framework version is too old. Update and rebuild the repository, or use --override-tensor instead.
    • Error after enabling V Cache quantization: confirm --flash-attn is enabled and that your backend supports this combination.
    • Degraded output quality: first disable KV Cache quantization to check whether quantization is the cause.

    Safety and Risk Notes

    • Licensing: read the model’s license before downloading to confirm whether commercial use or redistribution is restricted.
    • File verification: check the SHA256 checksum, and never use model files from unknown sources.
    • Disk and memory: model files, build artifacts, and logs all need space. Watch thermals during long, high-load runs.
    • Network exposure: the server has no authentication by default. Listening on 0.0.0.0 makes it accessible to other devices on the same network—shut the service down when not in use.

    How to Get Started

    Start by running the full workflow with a smaller model, then move up to larger ones gradually. Change only one parameter at a time, and record VRAM usage, generation speed, and output quality so you can locate problems. Your context length requirements directly determine how much VRAM to reserve for the KV Cache—figure this out before you begin.