llama.cpp MoE Cache Explained (2026): 2.2x on an RTX 5090
The llama.cpp MoE cache keeps the most-used experts of a mixture-of-experts model in GPU memory while the rest stay in system RAM. Its author measured 2.2 times the speed on an RTX 5090. Other testers measured a slow-down on dual-GPU rigs. This page decodes the two flags, names the build that has each part, and gives the method to find your own numbers.
Jump to 10 sections
See also: Qwen3-Next-80B-A3B-Instruct layer_types Explained.
Bottom Line
The MoE cache is a GPU cache for experts that live in system RAM. It is off by default. It can double the output speed of a large mixture-of-experts model on one fast card, and it can slow down a dual-GPU rig.
| Flag | What it does | Default | First build |
|---|---|---|---|
--moe-cache-mib N | Size of the GPU cache for experts kept in RAM, in MiB | 0 (off) | b11480 (7 Oct 2026) |
--moe-cache-cpu-share F | Share of cache misses the CPU computes, 0 to 1, once the cache is full | 0.00 | b12191 (7 Nov 2026) |
-cmoe, --cpu-moe | Keeps all expert weights in RAM. The cache needs this, -ncmoe or -ot. | off | older |
-ncmoe N, --n-cpu-moe N | Keeps the experts of the first N layers in RAM | off | older |
scripts/moe-cache-tune.py | Starts the server 6 times and prints the best pair of flags | n/a | b12191 |
Neither cache flag has a short form. Both are marked experimental in llama.h.
Three facts decide whether it helps you:
- It speeds up output, not prompt reading. The cache fills only on batches of 32 tokens or fewer.
- The stable release does not have all of it. llama.cpp v0.9.0 (4 November 2026) has
--moe-cache-mibonly. The CPU share and the tuning script need a rolling build, b12191 or newer. - Hit rate and PCIe speed set the result. The author measured 2.2 times on an RTX 5090 at an 89% hit rate. One tester with two cards measured a slow-down at 47% and 58%.
Where the mechanism points at hardware, it is the VRAM left over after the layers and the PCIe link. See the cards this matters for.
How the Cache Works
A mixture-of-experts model uses a few experts for each token. That is why you can keep the experts in RAM and the rest of the model on the GPU. Our MoE offload flags guide covers that static split.
The static split has a cost. Every expert in RAM runs on the CPU. The MoE cache changes that:
| Step | What happens |
|---|---|
| Load | llama.cpp reserves the cache on the GPU, in slots. Layers with the same expert layout share one cache. |
| A token needs an expert that is in the cache (a hit) | The GPU runs it. No copy. |
| A token needs an expert that is not in the cache (a miss) | llama.cpp uploads it from RAM to the GPU over PCIe, then runs it. |
| The cache is full | It evicts a slot. The policy is ClassLRU: 8 frequency classes, with a score that halves every 128 tokens. |
The cache is full and --moe-cache-cpu-share is above 0 | That share of the misses runs on the CPU and is not cached. The least-used misses go to the CPU. |
| A batch is larger than 32 tokens | It reads the cache but does not fill it. |
The rule for the last row is in the source: large batches “use most experts of a layer, so they gain little from the cache and would evict the experts used in generation”.
Which layers the cache acts on. Only a layer that sits on a GPU while all of its experts sit in host memory. So you need -ngl high enough to put the layer on the card, plus -cmoe, -ncmoe or -ot to keep its experts in RAM. If no layer qualifies, llama.cpp warns: “no layer has all of its experts in host memory, MoE cache is disabled”.
The smallest cache. The cache must hold the experts of one token. Below that, llama.cpp stops with “MoE cache is too small to hold the experts of one token”.
Which Build Has What
| Change | Pull request | Merged | First build |
|---|---|---|---|
The cache, --moe-cache-mib | #29887 | 7 Oct 2026 | b11480 |
| SLRU eviction | #30637 | 19 Oct 2026 | not checked |
| ClassLRU eviction | #31233 | 6 Nov 2026 | b12170 |
--moe-cache-cpu-share and the tuning script | #30966 | 7 Nov 2026 | b12191 |
No cache on the draft model in llama-speculative | #31497 | 8 Nov 2026 | b12201 |
| The CPU part no longer waits for cached experts | #31888 | 8 Nov 2026 | b12206 |
llama.cpp v0.9.0 sits at build b12110. It has the first row only. The newest build release on 11 November 2026 is b12292. If your llama-server --help does not list --moe-cache-cpu-share, your build is older than b12191.
Measured Results
Every number in this section is from the llama.cpp pull request threads. None is ours. The numbers do not transfer between machines: the CPU, the RAM speed and the PCIe link all change them.
The author’s benchmark (pull request #29887). Qwen3.8-Flash-Next Q4_0, 93.7 GiB with 65.4 GiB of experts, EPYC 7742 with 16 threads, PCIe 4.0 x16, 32,768 context.
| GPU | Config | Experts in VRAM (layers + cache) | Output | Speed-up | Hit rate |
|---|---|---|---|---|---|
| RTX 4090 | --fit, no cache | 16.5 + 0.0 GB | 25.0 t/s | 1.00x | n/a |
| RTX 4090 | --fit --moe-cache-mib 6544 | 10.4 + 6.4 GB | 39.4 t/s | 1.57x | 72% |
| RTX 4090 | -cmoe --moe-cache-mib 11000 | 0.0 + 10.7 GB | 40.7 t/s | 1.62x | 77% |
| RTX 5090 | --fit, no cache | 24.5 + 0.0 GB | 30.8 t/s | 1.00x | n/a |
| RTX 5090 | --fit --moe-cache-mib 6544 | 17.9 + 6.4 GB | 54.5 t/s | 1.77x | 77% |
| RTX 5090 | -cmoe --moe-cache-mib 19000 | 0.0 + 18.6 GB | 67.8 t/s | 2.20x | 89% |
Read the last row. The fastest setup puts no whole expert layer on the card. All experts stay in RAM, and 18.6 GB of VRAM holds the cache. A cache of the hot experts beat a static split of whole layers.
Where the cache was slower (community reports, same thread).
| Tester, date | Hardware | Model | With cache | Without | Hit rate |
|---|---|---|---|---|---|
| paulp83, 7 Oct | 2x RTX 5090, PCIe 4, Threadripper PRO 3975WX | GLM-5.3-Flash UD-IQ3_XXS | 14.23 t/s (11,000 MiB) | 17.75 t/s | 47% |
| paulp83, 7 Oct | Same, two-GPU layout | Same | 21.50 t/s (15,000 MiB) | 24.08 t/s | 58.4% |
| Volunteer-1, 7 Oct | 2x RTX 3090, PCIe 4 x8 | not stated | 11.89 t/s (18,000 MiB) | 18.05 t/s | not stated |
| LeoBorcherding, 7 Oct | Radeon AI PRO R9700 32GB, Windows | Qwen3.8-Flash-Next IQ1_M | 11.9 t/s (8,000 MiB) | 11.8 t/s | 85.3% |
LeoBorcherding wrote: “At 85% hits the cache breaks even with the CPU path here”. With a 16,000 MiB cache and 94.4% hits, the same card reached 23.2 t/s. These tests ran in October, before ClassLRU and the CPU share. They show the rule, not today’s exact numbers: a low hit rate on a slow link costs more than the CPU path.
ClassLRU (pull request #31233). The author measured +6% output on Qwen3.8-Flash-Next and +7% on GLM against the older SLRU policy, with 8% fewer uploads. Hit rates in the description: SLRU 86.5%, ClassLRU 87.6%, and 93.8% for the theoretical best policy. The gain is against SLRU, not against a run with no cache.
What the CPU Share Changes
With a share of 0, every miss waits for an upload. With a share above 0, the CPU computes part of the misses from the copy in RAM. That helps most when the cache is small.
The author’s example (pull request #30966). Qwen3.8-Flash-Next IQ4_NL, 64,800 MiB of experts in host memory, -ngl 999 -fa on -cmoe -t 8 -c 128000. The description names no GPU or CPU.
| Cache | Share 0 | Share 0.5 | Share 0.95 |
|---|---|---|---|
| 6,464 MiB | 24.2 t/s (73.3% hits) | 29.6 t/s | 47.6 t/s |
| 19,392 MiB | 65.5 t/s (93.5% hits) | 66.4 t/s | 54.1 t/s |
A small cache wants a high share. A large cache wants a share near 0. At 19,392 MiB the 0.95 share was 17% slower than share 0.
Community reports on 8GB and 11GB cards (same thread, builds before the merge):
| Tester, date | Card | Model | No cache | Small cache: share 0 / 0.95 | Larger cache: share 0 / 0.95 |
|---|---|---|---|---|---|
| MichaelDietzel, 23 Oct | RTX 2080 Ti 11GB | Qwen3.6-35B-A3B UD-Q6_K_XL | 42.11 t/s | 2,752 MiB: 23.5 / 51.9 | 6,784 MiB: 50.2 / 64.5 |
| marceldev89, 24 Oct | RTX 3070 8GB | Cyber-Tiel-Coder-35B-A3B UD-Q4_K_S | about 35 t/s | 1,728 MiB: 32.0 / 48.8 | 3,136 MiB: 41.0 / 62.4 |
On the RTX 2080 Ti, a 2,752 MiB cache at share 0 was slower than no cache (23.5 against 42.11 t/s). The same cache at share 0.95 was faster (51.9). On small cards the share is not optional.
One tester (sasa7812, 26 October) reported the opposite on an R9700 on PCIe 5 x16 with Vulkan: any share above 0 made output about 15% slower. A fast link makes uploads cheap.
Pinned memory matters. The llama.cpp docs state that the experts in RAM are pinned with -lm none, -lm mlock and -lm dio, and not with the default mmap. Pinned experts upload at the full speed of the link, “so the CPU share often does not help then”.
Find Your Own Numbers
Use a build at b12206 or newer. Then run the tuning script with your normal server command after --:
python3 scripts/moe-cache-tune.py -- build/bin/llama-server -m model.gguf -cmoe -t 8 -c 32768
What the script does, from the llama.cpp docs and the script:
- It starts the server 6 times: two cache sizes, each at shares 0, 0.5 and 0.95.
- The small size is 10% of the experts. The large size is 30% of the experts, or what fits on the card.
- It prints a measured table, a
machine:line with the upload speed and the CPU speed, and a predicted table. - It ends with
recommended: --moe-cache-mib N --moe-cache-cpu-share F. The rule is the lowest share within 5% of the fastest result. - If every expert fits on the card, it tells you to drop
-cmoe.
To check before the run if your model fits on your card, enter your VRAM and system RAM in the local model calculator. If the model fits on the GPU, you do not need -cmoe or the cache.
Options: --max-mib N sets the largest cache, --out DIR sets the run folder, --markdown prints Markdown tables. The run takes a few minutes, and most of that is model loading.
To check by hand, add -lv 4 to your server command. At exit llama.cpp prints a line that starts with llama_moe_cache: and gives hits, misses, misses on the CPU, the hit rate and the MiB uploaded. Compare the output speed and the hit rate with and without the cache. If the hit rate is low and the speed drops, raise the cache size or the share, or turn the cache off.
A starting command for one 24GB or 32GB card and a large MoE model:
llama-server -m model.gguf -ngl 999 -cmoe -fa on -lm none \
--moe-cache-mib 6544 --moe-cache-cpu-share 0 -c 32768
6,544 MiB is the size the author used for a model with 65.4 GiB of experts, close to the 10% rule. Use 10% of your own model’s expert size, then run the tuner.
Known Problems (Open on 11 November 2026)
| Issue | Backend | Problem |
|---|---|---|
| #32041 | Windows | The tuning script crashes with ValueError: Unsupported signal: 2 and leaves llama-server running |
| #31911 | ROCm, with a draft model | The script under-reports free VRAM. It capped the cache at 1,691 MiB where 5,696 MiB runs |
| #31675 | ROCm, RX 6800 XT | --moe-cache-mib aborts at load at 2,048, 4,096 and 6,144 MiB |
| #31510 | SYCL, 2x Arc Pro B60 | A 40,000 MiB cache stalls; 15,000 MiB completes |
| #31421 | Metal, M3 Max | Default weight repacking disables the cache for Q4_0 experts; the tester needed -nr |
Two more limits from the source: -sm tensor stops with “MoE cache does not support tensor parallelism”, and there is no cache flag for a draft model. The source accepts any GPU backend. We found no official list of supported backends.
An open pull request (#32076, 11 November) removes sync points. Its author expects a large gain on Vulkan and Windows and about 10% on CUDA on Linux. It is not merged.
Common Mistakes
- Setting
--moe-cache-mibwith all experts on the GPU. The cache then has nothing to act on. It needs-cmoe,-ncmoeor-ot. - Expecting faster prompt reading. Large batches do not fill the cache.
- Using v0.9.0 and typing
--moe-cache-cpu-share. That flag is in b12191 and newer. - Copying a cache size from another machine. The 4090 and 5090 rows above came from a PCIe 4.0 x16 slot. An x8 slot or a riser changes the result.
- Leaving the share at 0 on an 8GB or 11GB card. On two such cards a small cache at share 0 was slower than no cache.
Sources
- llama.cpp pull requests #29887 (cache, merged 2026-10-07), #31233 (ClassLRU, 2026-11-06), #30966 (CPU share and script, 2026-11-07), #31497 and #31888 (2026-11-08): descriptions, benchmark tables and thread comments, read 2026-11-11 through the GitHub API
- llama.cpp master:
common/arg.cpp(flag names, defaults, help text),docs/moe-cache.md,src/llama-moe-cache.cpp(batch limit, eviction, log lines, error text),scripts/moe-cache-tune.py,include/llama.h; read 2026-11-11 - llama.cpp releases: v0.9.0 (2026-11-04, build b12110) and build b12292 (2026-11-11); first-build tags from
git tag --contains - Issues #32041, #31911, #31675, #31510, #31421 and pull request #32076; read 2026-11-11
- Community measurements are quoted with the tester’s name and date. They are community-reported, not verified by OpenClaw DC.
See Also
- llama.cpp MoE offload flags explained —
--n-cpu-moe, the static split this cache builds on - llama.cpp flags explained — every flag that matters, in one table
- llama.cpp mmap vs mlock: —load-mode explained — which load modes pin the experts in RAM
- Can I run Qwen3.8 Flash Next locally? — the model in most of these benchmarks
- KV cache quantization: Q8 vs Q4 — the other cache that takes VRAM
- Best local LLM for 24GB VRAM — what one RTX 3090 or 4090 runs
- Best local LLM for 12GB VRAM — where a small cache and a high CPU share apply
Before you buy a card for MoE models, check the tested hardware list for current prices by tier.