fix(sdk): enable clip GPU backend when n_gpu_layers is -1#1198
Merged
Conversation
n_gpu_layers < 0 means all layers in llama.cpp, but the mtmd use_gpu check only accepted > 0, so the default npu/hybrid path (ngl = -1) made clip fall back to CPU. Treat any non-zero value as GPU-enabled. Signed-off-by: RemiliaForever <remilia@koumakan.cc>
Copilot started reviewing on behalf of
RemiliaForever (RemiliaForever)
July 17, 2026 14:52
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the llama_cpp VLM plugin so the mtmd/CLIP vision encoder correctly initializes a GPU/HTP backend when n_gpu_layers uses llama.cpp’s “all layers” sentinel (-1), preventing an unintended CPU fallback on the default npu/hybrid path.
Changes:
- Update CLIP/mtmd GPU enablement logic from
n_gpu_layers > 0to a non-zero check to treat-1as GPU-enabled.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
84
to
86
| mtmd_context_params mparams = mtmd_context_params_default(); | ||
| mparams.use_gpu = config.n_gpu_layers > 0; | ||
| mparams.use_gpu = config.n_gpu_layers != 0; | ||
| mparams.print_timings = false; |
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.
What
The mtmd/clip vision encoder was silently falling back to CPU on the default
npu/hybriddevice path.Why
vlm.cppsetmtmd_context_params.use_gpu = config.n_gpu_layers > 0. But in llama.cppn_gpu_layers < 0means "all layers", and the CLI/binding default fornpu/hybrid/gpuis-1. Since-1 > 0is false,use_gpuwas false, soclip_ctxnever initialized a GPU/HTP backend and dropped to CPU (clip.cppbackend selection).Fix
Treat any non-zero
n_gpu_layersas GPU-enabled (!= 0). Only thecpualias (ngl = 0) forces clip to CPU, matching the intended semantics.