From 3982ed4c6f5ff3134d783e071ec80b70b5a4ddb5 Mon Sep 17 00:00:00 2001 From: Akarshan Biswas Date: Fri, 25 Jul 2025 16:24:53 +0530 Subject: [PATCH] fix: Allow N-GPU Layers (NGL) to be set to 0 in llama.cpp (#5907) * fix: Allow N-GPU Layers (NGL) to be set to 0 in llama.cpp The `n_gpu_layers` (NGL) setting in the llama.cpp extension was incorrectly preventing users from disabling GPU layers by automatically defaulting to 100 when set to 0. This was caused by a condition that only pushed `cfg.n_gpu_layers` if it was greater than 0 (`cfg.n_gpu_layers > 0`). This commit updates the condition to `cfg.n_gpu_layers >= 0`, allowing 0 to be a valid and accepted value for NGL. This ensures that users can effectively disable GPU offloading when desired. * fix: default ngl --------- Co-authored-by: Louis --- extensions/llamacpp-extension/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/llamacpp-extension/src/index.ts b/extensions/llamacpp-extension/src/index.ts index 76912c5e3..13322bbe5 100644 --- a/extensions/llamacpp-extension/src/index.ts +++ b/extensions/llamacpp-extension/src/index.ts @@ -1182,7 +1182,9 @@ export default class llamacpp_extension extends AIEngine { // Add remaining options from the interface if (cfg.chat_template) args.push('--chat-template', cfg.chat_template) - args.push('-ngl', String(cfg.n_gpu_layers > 0 ? cfg.n_gpu_layers : 100)) + const gpu_layers = + parseInt(String(cfg.n_gpu_layers)) >= 0 ? cfg.n_gpu_layers : 100 + args.push('-ngl', String(gpu_layers)) if (cfg.threads > 0) args.push('--threads', String(cfg.threads)) if (cfg.threads_batch > 0) args.push('--threads-batch', String(cfg.threads_batch))