llama.cpp MoE expert cache slot sharing patch
by しゃもじ太郎 · Technique · Text & code
A small experimental patch for llama.cpp that shares expert cache slots so mixture-of-experts models run faster with less GPU memory.
Latest · Nov 22A one-file patch (42 lines added, 12 removed, src/llama-moe-cache.cpp) lets passes using the same weights share cache slots; enabled by LLAMA_MOE_CACHE_SHARE=1. Experimental, tested on one PC.
Evidence
- Nov 22At 7296 MiB cache, slot sharing raised cache hit rate from 81.54% to 94.77% and generation from 27.52 to 39.35 tok/s (1.43x) on Inkling 2 Mini.
- Nov 22A 4096 MiB shared-slot cache (29.84 tok/s) was faster than the unmodified 7296 MiB cache (27.52), freeing about 3GB of VRAM; prompt processing rose from 57.5 to 148.3 tok/s at 7296 MiB.
- Nov 22With slot sharing, the tuner's recommended CPU share of 0.95 became counterproductive at 7296 MiB (34.27 vs 39.35 tok/s); at 1472 and 2816 MiB the share still helped.
- Nov 22With temperature 0 and no CPU share, output before and after the patch was identical on three short prompts; with CPU share, outputs diverged, as they also do without the patch.