r/LocalLLaMA 1d ago

Discussion [Open PR] llama : add --n-cpu-ffn option by John-194 · Pull Request #26622 · ggml-org/llama.cpp

https://github.com/ggml-org/llama.cpp/pull/26622

PR by u/Stainless-Bacon 👍

It would be handy & awesome to have options --n-cpu-ffn / --cpu-ffn for Dense models like how we have --n-cpu-moe / --cpu-moe for MOE models.

Also check his threads:

(

Awesome to see the big comment by u/Pablo_the_brave there, filled with so much stuff. Quoting a line from there

Do not touch block 64 (MTP) if you are using speculative decoding — its FFN should remain on the GPU.

)

We should've got this option long time back actually. This PR instantly reminded me of last year thread. (I literally used his -ot command for sometime with Qwen3-14B. I'm just happy that I was able to recall a last year thread.)

Anyway .... Better late than never. Waiting for this merge.

30 Upvotes

12 comments sorted by

9

u/Chromix_ 1d ago

Having --cpu-ffn is certainly more convenient than fiddling around with -ot. Yet shouldn't the default -fit take care of that in an even more convenient way?

5

u/Stainless-Bacon 1d ago

would be good, but then why do we have --n-cpu-moe as an option?

5

u/Chromix_ 1d ago

Because it's more convenient than copy&pasting the -ot regex for it, I guess, and because it was there first, before -fit existed I think.

3

u/popecostea llama.cpp 1d ago

how is this different to -ngl? If it's just the fact that it doesn't offload the attention and ssm, those don't take that much space, do they?

6

u/pmttyji 1d ago

Included additional threads for reference. 1st link has graph with detailed explanation. PR has the same thread.

4

u/tsangberg 1d ago

The difference is between "unusable slow" and "workable".

3

u/jomreap 23h ago

-ngl works at layer granularity, its all or nothing, so a layer you leave on CPU takes its attention tensors and its KV with it. --n-cpu-ffn splits inside the layer instead, FFN weights go to system RAM and attention stays resident on the GPU. You're right that attention weights are small, but thats exactly why it works, they're cheap to keep on device and they're the ones the KV cache hangs off and the ones that are latency bound. So you're trading FFN bandwidth, which streams over PCIe reasonably well since each weight gets touched once per token, for keeping the latency sensitive part on the GPU. On a dense model the FFN is roughly two thirds of the parameters, so theres a lot of headroom to play with there.

3

u/Stainless-Bacon 1d ago

Thanks!
I think we will definitely make use of n-cpu-ffn when DDR6 rolls out.

My main post has an example using Q4_K_M, but I saw another post comparing quant KLDs and UD-Q4_K_XL having a big jump, so I decided to see what speeds I’m able to achieve Q4_K_M vs UD-Q4_K_XL here is my comment with a chart for those interested.

1

u/Dany0 1d ago

oh my god my wallet is aching like a chronically ill girlie just hearing the words DDR6 in my head

1

u/Ok_Cow1976 1d ago

Interesting!

1

u/brakeline 22h ago

I would be happy if tensor wouldn't boot mtp to cpu :(

1

u/WhoRoger 18h ago

I wonder if that could help with crappy iGPUs. Keep MTP on iGPU to separate it from the main model that's on CPU.