Repository navigation
Conversation
…gpu_layers, keeping the KV cache on the device
…before the rest of the layers
…he rest of the layers
|
Sorry, but if this PR does what I think it does I consider it out-of-scope. The number one priority for the |
The PR leaves multi GPU path untouched via the last commit. What the code does is similar to how MoE fits (FFN tensors to CPU while KV stays on GPU), though I order the layers largest first vs MoE's back to front. The current implementation of fit makes dense models very slow for anyone needing CPU's help to run them (as you can see in the charts). My goal is to make models like 27B usable for people having <16GB VRAM. How could we make this more robust? The simplest form we can do is by putting layers (same as ngl) on the CPU, while at the same time leaving KV on the GPU (basically ngl but without the KV part). That should fix most of the degradation, but will leave out some performance. |
|
Look, I'll be straight with you: as of right now I am completely overloaded when it comes to code review. I consider this PR to be low priority vs. the other things in my backlog and based on the first review I think reviewing this PR will be more work than trying to implement something equivalent myself. |
|
Can I open up a new PR that is very simple and still improves performance by a lot? I would like to mirror the MoE's implementation but for dense models, dropping all the complexity of this PR. |
|
No, because the code itself is only half the equation. I'm not convinced that the approach you're using is generally applicable to all or most setups rather than just your own and properly determining that will be where most of the effort will be needed. |
|
Well, people liked my I would have preferred being told that this is a no go in the issue before I wasted time trying this. |


Overview
For dense models,
--fitmoves whole layers to the CPU-nglstyle, which is slow. This PR adds prioritization of what gets put on the CPU.The plateau is because the output tensor is large, so it leaves a lot of slack for context, at the same tensor placement.
The drop at the end is where the regular
-nglkicks in and performance nears the original behaviour.Additional information
This PR is a follow-up to my issue #27987, where doing the ordering automatically in
--fitwas suggested. Through testing I learned about other possible optimizations, so this PR includes a bit more than the issue proposed (like "output tensor" or "rest of layer" on the CPU, not just FFNs).--fitorderingLargest FFNs go first, then the rest of those layers (attention weights, norms, recurrent state) in the same order, then the output tensor, then the MTP layer, and then
-nglgets lowered only as a last resort, which causes the usual performance drop.Ordering cost
Measured on Qwen3.8 27B UD3-Q4_K_M at 60k context as tg cost per MiB moved to the CPU (
-ot, one at a time):-ngl(scales with context length)-ngl. For tied embeddings (Gemma) it moves the GPU copy oftoken_embd.MoE fit ordering is unchanged.
The fit takes up to about twice the test loads of master, ~1.5 s for me.
Testing
I have 1 GPU, so I added a guard against multiple GPU systems because I couldn't test that. Multiple GPU systems keep the previous
-nglbehaviour. If someone tests this on multiple GPUs, the guard can be removed.Checked 18 GGUFs (Qwen 3.x dense/MoE, TinyLlama, phi 2, gemma 2-4,
mamba, rwkv 6, OLMoE, falcon h1, LFM2, MiMo) via
llama-fit-paramsto make sure the ordering holds.Loaded and filled Qwen 3.8 27B and Gemma 4 12B as seen in the charts.
Not PR related issue that could affect performance
--fitincorrectly calculates free VRAM. For me, the correct--fit-targetvalues are between -400 and +200 (depending on the model and MTP use) to fully utilize my VRAM and not OOM crash upon use. Rough workaround: run the server, give it a big file to chew on, tell it to write a story, if it OOM crashes then raise--fit-target, if it doesn't then lower the value till it does, then raise it a step back.Requirements