llama: offload output layer to GPU first#18148
Merged
JohannesGaessler merged 1 commit intoggml-org:masterfrom Dec 18, 2025
Merged
llama: offload output layer to GPU first#18148JohannesGaessler merged 1 commit intoggml-org:masterfrom
JohannesGaessler merged 1 commit intoggml-org:masterfrom
Conversation
ggerganov
approved these changes
Dec 18, 2025
LostRuins
added a commit
to LostRuins/koboldcpp
that referenced
this pull request
Dec 19, 2025
This was referenced Dec 21, 2025
Anico2
added a commit
to Anico2/llama.cpp
that referenced
this pull request
Jan 15, 2026
Closed
Contributor
|
@JohannesGaessler Could you help check it? I guess it will impact all backends. Thank you! |
Contributor
Author
|
This PR did impact all backends but if you cannot move the output layer to VRAM that is a SYCL bug and needs to fixed regardless. I don't even have any Intel hardware so I don't know how I would be of any help for that. |
Contributor
OK, I will check and fix it. Thank you! |
blime4
referenced
this pull request
in blime4/llama.cpp
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18119 .
As of right now llama.cpp first moves all repeating layers from RAM to VRAM before finally moving the non-repeating output layer. However, it seems to be better to instead move the output layer first and to move the repeating layers afterwards. Specifically:
--n-gpu-layersis increased. So for a graph evaluation the backend scheduler needs fewer splits.llama_params_fitdoes not handle the case correctly where there is sufficient total VRAM for a dense model but the layers need to be rebalanced vs. the initial guess that llama.cpp produces with-fit off. It becomes by comparison much easier to handle if the output layer is being offloaded first because then there is no sudden change to memory allocation on the last layer.Benchmark
Because this PR changes the memory use for a given
-nglvalue I collected data like this:-nglvalue, runllama-perplexityand note down the "self" memory use as the memory use for a context of size 512.-nglvalue, runllama-benchand note down the performance numbers.Results
For pp512 there is basically no change. For tg128 however, there is a sizable improvement however in the performance at a given VRAM use though.