Hacker News new | ask | show | jobs
by Eisenstein 12 days ago
> A MoE can breeze through that same prefill since it doesn't need as much compute.

Important caveat: if not fully offloading[0] then the MoE model's prefill speed completely tanks, as prefill is heavily dependent FLOPS and parallelization and CPUs suck at that compared to GPUs.[1]

[0] 'Offload' is being used in the llamacpp sense of using the GPU instead of CPU

[1] Generally, prefill is bottlenecked by compute while generation is bottlenecked by memory bandwidth

1 comments

Fortunately, that's not really how it works anymore.

When you're prefilling, you can afford to amortize the cost of sending the experts to a scratch space on the GPU then running a bunch of tokens through that set of experts, then repeating with the next set of experts, and so on. There's no reason to compute those on the CPU, and llama.cpp already does move prefill to the GPU by default for partially-offloaded MoEs.

Where performance would still tank is if you don't ensure the microbatch (ubatch) is large enough to amortize that cost, and if you're prefilling only a small input, it's not going to reach full speed. For a large input, you can think of each expert as visiting the GPU once for every ubatch of input tokens. A larger ubatch means fewer transfers.

Try increasing `-ub` (2048 is a sane default, but 4096 or higher can sometimes be desirable), and watch the partially-offloaded MoE prefill performance magically go way up on llama.cpp for large inputs.

EDIT: Also, if you haven't tried replacing `--n-cpu-moe` with `--cpu-moe` + `--moe-cache-mib` (with all of your GPU memory that you can spare), it is even better than `--n-cpu-moe`, since real world models don't distribute work over the experts in a perfectly random way. The moe-cache speeds up decode/output tokens per second.

Thanks. Playing around with this got me around twice the prefill performance with Qwen-Flash-Next.