Black Friday week: local AI hardware on sale. See the list.

--n-cpu-moe Calculator

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.

How it works

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 by card at 32K context, 64GB RAM

Model (quant)8GB card12GB card16GB card24GB card32GB card
Qwen3.6 35B-A3B (UD-Q4_K_M)31 of 4022 of 4013 of 40all on GPUall on GPU
Ornith 1.5 35B-A3B (Q4_K_M)29 of 4020 of 4011 of 40all on GPUall on GPU
Gemma 4 26B-A4B (UD-Q4_K_M)22 of 3013 of 304 of 30all on GPUall on GPU
Qwen3-Coder-Next 80B-A3B (Q4_K_M)44 of 4839 of 4835 of 4826 of 4817 of 48
gpt-oss 120B (MXFP4)34 of 36 (RAM short)31 of 36 (RAM short)29 of 36 (RAM short)24 of 3619 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.

Is it fast enough after offload?

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.

Questions

What does --n-cpu-moe do in llama.cpp?

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.

How do I pick the --n-cpu-moe value?

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.

What is the difference between --cpu-moe and --n-cpu-moe?

--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.

Do I still need --n-cpu-moe with a current llama.cpp build?

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.

How much VRAM does gpt-oss 120B need with --n-cpu-moe?

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.

Related