Repository navigation
Replies: 1 comment
|
The dynamic routing strategy is sound, but the bottleneck often shifts from VRAM capacity to PCIe/NVMe bandwidth saturation during expert swapping. When offloading rarely used experts to flash, the latency penalty isn't just the raw read speed; it's the context switch overhead and the serialization of the KV cache if prefill and decode are split across devices. If the planner moves the decode phase to CPU because VRAM is full of active experts, the memory bandwidth of the CPU becomes the new constraint, potentially negating the speed gains of parallel device usage. Have you observed significant variance in throughput when the router's entropy changes, forcing a higher rate of expert swaps than the initial calibration assumed? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
in the last months I worked on BigMoeOnEdge, it's built on top of llama.cpp. It runs MoE models that are bigger then the memory of the device, and it configure itself for the machine where it runs.
It works with any MoE GGUF that llama.cpp can load, any quantization, no code per model.
OS: Android, iOS, macOS, Windows, Linux (arm64 and x86_64).
Backends: CPU, CUDA, ROCm (HIP), Vulkan, Metal, OpenCL, Hexagon NPU. Other llama.cpp backends load in the same way if you build them.
I would like to bring the main part inside llama.cpp, instead of keeping it as a separate layer.
16 GB Apple silicon laptop, Qwen3.6-35B-A3B Q4_K_M (22 GB, so bigger than the RAM). A coding agent made this page from one prompt, nobody touched anything, 35 minutes. Experts read from SSD all the time, prefill on GPU and decode on CPU, both chosen by the planner.
The idea
A MoE model uses only few experts for each token. So you don't need all the model in memory, but you need each part in the right place: the weights that every token reads, the experts used a lot, the experts used rarely. And the right place is different on every machine.
With
--autoit measures the machine (free RAM and VRAM, speed of the disk, how fast each device runs a real layer of the model) and the model (size, experts, how it routes), and then it decides:The target is the max prefill and decode speed that the machine can give, with the same output as the full model in memory. The settings that change only the speed are tested on the first answer and kept only if they are faster. For every choice it tells you why.
The rules are simple:
So on a phone the experts stay on flash and the prompt goes on the NPU, on a laptop the prompt goes on the GPU, on a desktop the most used experts stay in VRAM (with llama.cpp
llama_moe_cache).Speeds
Here there are only some models that I test often. It runs any MoE that llama.cpp loads, in any quantization: Qwen, Gemma, gpt-oss, DeepSeek, GLM, LFM, Ling, Flint, Kolibri etc. Which tensors are experts is read from the file, so a new architecture don't need new code.
Same machine and same file, vs llama.cpp today:
Vs Strata (it has its own GPU kernels), both with MTP, Qwen3.8-Flash-Next 125B Q2_0: 153 vs 226-330 tok/s on RTX 5090, 89 vs 150-177 on RTX 4090. The difference is in the GPU compute, not in the placement.
How I measured and all the runs: benchmarks.
What I propose, one PR at time
llama_moe_cache: an expert cache in RAM, filled from the GGUF on flash. So a model bigger than RAM + VRAM can run, without the page cache going crazy.--fit: it puts the weights on VRAM, RAM and flash, chooses the devices for prefill and decode, and sizes the caches from what it measures.There is already work on this:
llama_moe_cache(#29887, #30966) and disk streaming in #25294. I prefer to build on them and not add another thing.Questions
llama_moe_cacheor stay beside it?The project is Apache-2.0, what goes in llama.cpp I give it under MIT.
Thanks!
All reactions