How many expert layers should llama.cpp keep in RAM so an MoE model fits your GPU? Pick the model, quant, card, RAM and context. The answer is the smallest --n-cpu-moe that fits, from the size of every tensor in the GGUF file, not from a guess per layer. For a PC with an NVIDIA or AMD card. On a Mac the memory is shared, so use the local model calculator instead.
GPU side(N) = non-expert weights + experts of layers N..L-1 + KV cache at -c RAM side(N) = token embedding + experts of layers 0..N-1 answer = smallest N with GPU side(N) <= VRAM - 1 GiB RAM check = RAM side(N) <= 70% of system RAM
--n-cpu-moe N adds a CPU override for every tensor matching blk.<i>.ffn_(up|down|gate|gate_up)_(ch|)exps for i below N (common/common.h, llama.cpp master af5c58347f, read 2026-11-23). --cpu-moe does the same for every layer.src/llama-model.cpp). Models with tied embeddings (Gemma 4) load it a second time as the output head on the GPU; the math counts both.--spec-type draft-mtp.--fit-target llama.cpp keeps free per GPU. It covers the compute buffer at the default batch size. Raise -ub and you need more.config.json. It stays on the GPU whatever N is.| Model (quant) | 8GB card | 12GB card | 16GB card | 24GB card | 32GB card |
|---|---|---|---|---|---|
| Qwen3.6 35B-A3B (UD-Q4_K_M) | 31 of 40 | 22 of 40 | 13 of 40 | all on GPU | all on GPU |
| Ornith 1.5 35B-A3B (Q4_K_M) | 29 of 40 | 20 of 40 | 11 of 40 | all on GPU | all on GPU |
| Gemma 4 26B-A4B (UD-Q4_K_M) | 22 of 30 | 13 of 30 | 4 of 30 | all on GPU | all on GPU |
| Qwen3-Coder-Next 80B-A3B (Q4_K_M) | 44 of 48 | 39 of 48 | 35 of 48 | 26 of 48 | 17 of 48 |
| gpt-oss 120B (MXFP4) | 34 of 36 (RAM short) | 31 of 36 (RAM short) | 29 of 36 (RAM short) | 24 of 36 | 19 of 36 |
Each cell is the --n-cpu-moe value: expert layers kept in RAM out of the model's total. "RAM short" means the experts left in RAM need more than 70% of 64GB.
This page does not estimate speed, because it depends on your RAM bandwidth and PCIe link, and the two vary more than the GPU does. Each token reads its active experts from RAM for every offloaded layer, so speed falls as N grows. Measure it: llama-bench -m model.gguf -ngl 99 -ncmoe 10,14,18 tests three values of N in one run. For a start before you buy, the tokens per second calculator estimates the all-GPU speed. The MoE cache flags can win some speed back.
It keeps the expert weights of the first N layers in system RAM and puts everything else on the GPU. llama.cpp's help text: "keep the Mixture of Experts (MoE) weights of the first N layers in the CPU". The attention weights, the shared experts and the KV cache stay on the GPU, so a 16GB card can run a model whose file is bigger than 16GB.
Use the smallest N that fits, because every layer you move to RAM makes each token slower. The GPU side is the non-expert weights, plus the experts of layers N and up, plus the KV cache at your context, plus about 1 GiB for buffers. Qwen3.6 35B-A3B UD-Q4_K_M at 32K on a 16GB card needs --n-cpu-moe 13 of 40. The calculator above does this sum per layer from the GGUF file.
--cpu-moe keeps every expert layer in RAM. --n-cpu-moe N keeps only the first N. --cpu-moe is the same as --n-cpu-moe set to the layer count. It is the simple choice when the card is small, and the slow one when the card could hold some experts.
Often not. Current builds run --fit on by default: it adjusts the settings you did not set to fit free device memory, keeping a 1024 MiB margin per GPU, and for MoE models it can move expert weights to the CPU. Set --n-cpu-moe yourself when you want a fixed, repeatable split, when you run an older build, or when you set -c and want to see what that context costs before you download.
On a 24GB card at 32K context, --n-cpu-moe 24 of 36 leaves 21.7 GiB on the GPU and 38.5 GiB of experts in RAM, so the PC needs 64GB of RAM. Holding all of it on the GPU takes about 60.6 GiB.