Why whole-layer offload (-ngl) wastes MoE speed
In a Mixture-of-Experts checkpoint, routed feed-forward experts hold 85–95% of total weight bytes, yet each generated token activates only a small fraction (for example, 3B active out of 30B total in Qwen3 30B-A3B). Lowering -ngl pushes entire transformer blocks — including dense attention projections and their KV cache — onto the CPU, forcing PCIe transfers and slow CPU attention on every layer. Passing -ngl 99 together with --n-cpu-moe N keeps all attention layers, shared experts, embeddings, and the full KV cache on the GPU, moving only the routed expert tensor (ffn_.*_exps) of N layers to system RAM.
Size the split before launching
Qwen3 30B-A3B at Q4_K_M with an 8K context needs about 20.2 GB in full GPU memory — comfortable on 24 GB cards (140 of the 177 models in this index fit 24 GB comfortably at 4K), but about 5.7 GB over a 16 GB card once Windows reserves 1.5 GB. Offloading 18 of its 48 MoE layers via --n-cpu-moe 18 moves roughly 6.4 GB of routed experts to DDR5 RAM while keeping every attention head and the 8K KV cache on an RTX 4060 Ti 16GB. Likewise, GLM-4.5 Air at Q4_K_M with an 8K context needs about 68.7 GB total; on a single 24 GB card with 96 GB DDR5, --n-cpu-moe 36 keeps attention on the GPU and streams only the active experts per token from RAM.
# 1) Partial expert offload: Qwen3 30B-A3B Q4_K_M on a 16 GB GPU + 32 GB RAM
./build/bin/llama-server \
-m ./models/Qwen3-30B-A3B-Q4_K_M.gguf \
-ngl 99 --n-cpu-moe 18 -c 8192 --flash-attn on \
--host 127.0.0.1 --port 8080
# 2) Move ALL routed experts to CPU RAM (--cpu-moe) for 100B+ MoE on 16–24 GB VRAM
./build/bin/llama-server \
-m ./models/GLM-4.5-Air-Q4_K_M-00001-of-00002.gguf \
-ngl 99 --cpu-moe -c 16384 --flash-attn on \
--host 127.0.0.1 --port 8080Equivalent -ot regex override for older builds or custom layer ranges
Under the hood, --cpu-moe is shorthand for -ot ".ffn_.*_exps.=CPU", and --n-cpu-moe N maps the first N expert blocks to CPU. If you want to pin specific layer ranges across heterogeneous GPUs and CPU RAM (for example, layers 0–19 on CUDA0, 20–34 on CUDA1, and 35–47 on CPU), pass explicit -ot rules evaluated from first to last.
# Explicit tensor-override equivalent:
./build/bin/llama-server \
-m ./models/Qwen3-Coder-30B-A3B-Instruct-Q4_K_M.gguf \
-ngl 99 -ot "blk\.(3[0-9]|4[0-7])\.ffn_.*_exps\..*=CPU" \
-c 16384 --flash-attn on --host 127.0.0.1 --port 8080Tuning CPU threads and DDR5 bandwidth
When experts execute on the CPU, token generation is paced by system RAM bandwidth (about 75–90 GB/s on dual-channel DDR5-5600/6000) divided by the active expert bytes per token — not total file size. Set -t to physical performance cores (not hyperthreads) so memory controllers saturate without cache contention, and enable --flash-attn on so GPU-resident attention stays fast at 16K–64K context.
Common questions
Does Ollama support --n-cpu-moe?
Ollama manages layer placement automatically and does not expose llama.cpp’s --n-cpu-moe or -ot flags in Modelfile parameters. Use llama-server directly when an MoE model exceeds your VRAM.
How do I get the exact --n-cpu-moe count for my card?
Open the VRAM Calculator in Model → GPU mode, pick the MoE model and your GPU, and enter your free VRAM if other apps are open. When the model exceeds your card, the Run Plan automatically computes the exact --n-cpu-moe N flag and system RAM required.
What this guide uses
Next steps
See everything that fits 🟢 RTX 4060 Ti 16GReverse lookup — 16GB at 8192 context, ranked by qualityModels covered in this guide
Did this actually run?
Copying a command is not the same as it working, so this is the only place the site asks. Nothing is collected beyond the answer itself.
Related guides
Run GPT-OSS 20B (and 120B) locally without re-quantizing
GPT-OSS ships natively in MXFP4, so the usual "download the Q4_K_M" habit makes it bigger and worse. Sizing, the right flags, and how MoE expert-offload puts the 120B on a 24GB card.
Set Up llama.cpp on Intel Arc with SYCL or Vulkan
Check your Intel Arc GPU and driver, then choose SYCL or Vulkan for llama.cpp. Use a prebuilt ZIP on Windows or build on Linux and list devices.
RTX 5090: What 32GB Actually Buys for Local LLMs
What fits on an RTX 5090 that does not fit on a 24GB card: not many more models, but much longer context and higher speed ceilings. Sizes from the calculator, setup for Blackwell.