mirror of
https://github.com/mudler/LocalAI.git
synced 2026-08-01 02:49:51 -04:00
fix(llama-cpp): preserve GPU layers during option passthrough (#11193)
Stage the negative GPU-layer sentinels expected by the upstream argument parser, then restore LocalAI resolved values unless a passthrough flag explicitly overrides them. This avoids the parser assertion that terminated the backend for any generic option. Assisted-by: Codex:gpt-5 Co-authored-by: localai-org-maint-bot <306269227+localai-org-maint-bot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
79e88581c8
commit
5e541894df
68
backend/cpp/llama-cpp/passthrough_options_test.cpp
Normal file
68
backend/cpp/llama-cpp/passthrough_options_test.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "passthrough_options.h"
|
||||
|
||||
static int failures = 0;
|
||||
|
||||
static void check(bool ok, const char * name) {
|
||||
if (!ok) {
|
||||
++failures;
|
||||
std::fprintf(stderr, "FAIL: %s\n", name);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_stages_resolved_gpu_layers_for_upstream_parser() {
|
||||
int main_gpu_layers = 99;
|
||||
int draft_gpu_layers = 12;
|
||||
|
||||
const auto saved = llama_grpc::prepare_passthrough_gpu_layers(
|
||||
main_gpu_layers, draft_gpu_layers);
|
||||
|
||||
check(main_gpu_layers == -1, "main GPU layers use parser sentinel");
|
||||
check(draft_gpu_layers == -1, "draft GPU layers use parser sentinel");
|
||||
|
||||
llama_grpc::restore_passthrough_gpu_layers(
|
||||
main_gpu_layers, draft_gpu_layers, saved);
|
||||
|
||||
check(main_gpu_layers == 99, "main GPU layers restored");
|
||||
check(draft_gpu_layers == 12, "draft GPU layers restored");
|
||||
}
|
||||
|
||||
static void test_keeps_explicit_passthrough_overrides() {
|
||||
int main_gpu_layers = 99;
|
||||
int draft_gpu_layers = 12;
|
||||
|
||||
const auto saved = llama_grpc::prepare_passthrough_gpu_layers(
|
||||
main_gpu_layers, draft_gpu_layers);
|
||||
|
||||
main_gpu_layers = 4;
|
||||
draft_gpu_layers = 2;
|
||||
llama_grpc::restore_passthrough_gpu_layers(
|
||||
main_gpu_layers, draft_gpu_layers, saved);
|
||||
|
||||
check(main_gpu_layers == 4, "main passthrough override retained");
|
||||
check(draft_gpu_layers == 2, "draft passthrough override retained");
|
||||
}
|
||||
|
||||
static void test_keeps_explicit_auto_passthrough_overrides() {
|
||||
int main_gpu_layers = 99;
|
||||
int draft_gpu_layers = 12;
|
||||
|
||||
const auto saved = llama_grpc::prepare_passthrough_gpu_layers(
|
||||
main_gpu_layers, draft_gpu_layers);
|
||||
|
||||
llama_grpc::restore_passthrough_gpu_layers(
|
||||
main_gpu_layers, draft_gpu_layers, saved, true, true);
|
||||
|
||||
check(main_gpu_layers == -1, "main auto passthrough override retained");
|
||||
check(draft_gpu_layers == -1, "draft auto passthrough override retained");
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_stages_resolved_gpu_layers_for_upstream_parser();
|
||||
test_keeps_explicit_passthrough_overrides();
|
||||
test_keeps_explicit_auto_passthrough_overrides();
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user