Selective MoE offloading in llama.cpp on a 16 GB laptop GPU: faster for some models, much slower for others
- Hardware
- Acer Predator laptop running CachyOS (Arch Linux)
NVIDIA RTX 4090 Laptop GPU with 16 GB VRAM, Intel Core i9-14900HX (24 cores / 32 threads), 32 GB DDR5 - Models & engines
- llama.cpp with CUDA, run through llama-server, Flash Attention enabled
Five MoE models in GGUF format, 24 to 27 GB each - Key gotcha
- Putting all experts on the CPU with --cpu-moe caused heavy swapping on 32 GB RAM: about 3.14 tok/s and roughly 90 MB/s of swap activity.
What they built
The author wanted to run Mixture-of-Experts (MoE) models that don't fit in her laptop's 16 GB of VRAM. Instead of moving whole layers to system RAM, llama.cpp's --n-cpu-moe N option keeps only the expert weights of the first N layers on the CPU and leaves attention and the rest on the GPU.
She tested five GGUF models, all larger than her GPU memory: Phi-3.5-MoE (Q4_K_M, 24 GB), Apex-35B V1.0 (Q5_K_M, 24 GB), Qwen3.5-35B-A3B (Q6_K, 27 GB), Gemma 4 26B A4B (Q8_0, 26 GB) and LFM2.5-24B-A2B (Q8_0, 24 GB), each with selective MoE offloading and with traditional layer offloading.
She is clear that this was not an exhaustive scientific benchmark: one warm-up request and the same short prompt at a 4,096-token context, to see what actually happens on her hardware.
Setup
- Acer Predator laptop running CachyOS (Arch Linux)
- NVIDIA RTX 4090 Laptop GPU with 16 GB VRAM, Intel Core i9-14900HX (24 cores / 32 threads), 32 GB DDR5
- llama.cpp with CUDA, run through llama-server, Flash Attention enabled
- Five MoE models in GGUF format, 24 to 27 GB each
How it works
- Traditional offloading moves complete layers to the CPU until the model fits in VRAM.
- Selective offloading uses --n-cpu-moe N to keep the MoE expert weights (and their computation) of N layers on the CPU while non-expert work stays on the GPU.
- She tuned N per model to fit memory, then measured generation speed for each approach.
Results & numbers
- Selective MoE offloading was faster on Phi-3.5-MoE (5.67 vs 4.03 tok/s) and Apex-35B (5.18 vs 3.69 tok/s), roughly 40% better.
- Traditional offloading won on Qwen3.5-35B (5.23 vs 4.37 tok/s), Gemma 4 26B (5.77 vs 4.40 tok/s) and especially LFM2.5-24B (9.03 vs 2.11 tok/s, more than four times faster).
- On Phi-3.5-MoE, putting more experts on the CPU was faster: 13 CPU expert layers used 15,945 MiB VRAM at 5.29 tok/s, while 20 layers used 11,015 MiB at 5.67 tok/s.
- Raising the configured context from 4K to 16K on Phi-3.5-MoE took VRAM from 11,015 to 12,563 MiB with generation staying around 5.6 to 5.9 tok/s.
Gotchas
- Putting all experts on the CPU with --cpu-moe caused heavy swapping on 32 GB RAM: about 3.14 tok/s and roughly 90 MB/s of swap activity.
- A low active-parameter count does not guarantee a model suits expert offloading; LFM2.5 with about 2B active parameters was the worst case.
- The context tests only changed configured capacity; they did not process real 16,000-token prompts, which is a different workload.
- She suspects quantization level (CPU memory bandwidth for higher-precision experts) affects which method wins, but says this is unproven.
“getting a model to fit in memory is only half the problem.”— Jessica Doering
Do it yourself
- Build or install llama.cpp with GPU support and download an MoE model in GGUF format that is larger than your VRAM.
- Start llama-server with -ngl all and --n-cpu-moe set to a starting value (for example 20), with Flash Attention on.
- Send the same warm-up and test prompt and note tokens per second and VRAM use.
- Try a few different --n-cpu-moe values; the setting that uses the most VRAM is not necessarily the fastest.
- Run the same model with traditional layer offloading and compare before choosing.
- Watch system RAM and swap: a model that loads is not necessarily running comfortably.
llama-server \
-m /path/to/model.gguf \
-ngl all \
--n-cpu-moe 20 \
-c 8192 \
-fa onSimilar setups
Letting a coding agent tune llama.cpp on an 8 GB AMD GPU: 3x faster prompt reading for OpenCode
Cliff K had his coding agent benchmark llama.cpp backends and flags for a Qwen3.6 35B MoE on a Radeon RX 6600 XT, at the context depths OpenCode really uses, and turned the process into an open-source skill.
Running 80 GB MoE models on two 16 GB GPUs with llama.cpp 1.0
Gancho Stoychev measured five llama.cpp 1.0 settings one at a time on his homelab box with two RTX 5060 Ti 16 GB cards, running Qwen3.8-Flash-Next and DeepSeek V4 Flash, each about 80 GiB.
A local eve agent on a 4B model that keeps its pending approval through kill -9
@VarunChopr17597 ran Vercel's open-source eve 1.1 agent framework against Qwen3.5-4B on llama.cpp on a CPU-only Linux box, with no Vercel account, and tested whether a tool waiting for human approval survives the server being killed.
Re-benchmarking local GGUF models for a coding agent after a llama.cpp upgrade
Jordi Marçal re-ran his fixed coding-agent benchmark on seven local GGUF models after three weeks of llama.cpp updates, and found the harness's generation caps, not the models, explained a sudden score collapse.