Skip to content

fix(sdk): enable clip GPU backend when n_gpu_layers is -1#1198

Merged
RemiliaForever (RemiliaForever) merged 1 commit into
mainfrom
fix/vlm-clip-cpu-fallback
Jul 17, 2026
Merged

fix(sdk): enable clip GPU backend when n_gpu_layers is -1#1198
RemiliaForever (RemiliaForever) merged 1 commit into
mainfrom
fix/vlm-clip-cpu-fallback

Conversation

@RemiliaForever

Copy link
Copy Markdown
Contributor

What

The mtmd/clip vision encoder was silently falling back to CPU on the default npu/hybrid device path.

Why

vlm.cpp set mtmd_context_params.use_gpu = config.n_gpu_layers > 0. But in llama.cpp n_gpu_layers < 0 means "all layers", and the CLI/binding default for npu/hybrid/gpu is -1. Since -1 > 0 is false, use_gpu was false, so clip_ctx never initialized a GPU/HTP backend and dropped to CPU (clip.cpp backend selection).

Fix

Treat any non-zero n_gpu_layers as GPU-enabled (!= 0). Only the cpu alias (ngl = 0) forces clip to CPU, matching the intended semantics.

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 AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 > 0 to a non-zero check to treat -1 as 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;
@RemiliaForever
RemiliaForever (RemiliaForever) merged commit 4c65ec3 into main Jul 17, 2026
19 checks passed
@RemiliaForever
RemiliaForever (RemiliaForever) deleted the fix/vlm-clip-cpu-fallback branch July 17, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants