feat: edit validated per-model engine start profiles (#1070)

This commit is contained in:
2026-11-17 15:08:41 +01:00
parent 51604eebf6
commit 8ec8d6af7f
22 changed files with 1404 additions and 16 deletions

View File

@ -118,6 +118,43 @@ impl LlamaCppEngine {
}
args.extend(self.config.extra_args.iter().cloned());
args.extend(profile.extra_args.iter().cloned());
// Jede überschriebene Option kommt genau einmal vor, unabhängig vom
// Verhalten der Engine bei mehrfach angegebenen Optionen.
for spec in crate::startparams::start_parameters("llama.cpp")
.iter()
.filter(|p| {
profile.start_parameters.contains_key(p.name)
|| (p.name == "cpu_moe"
&& profile.start_parameters.contains_key("cpu_moe_layers"))
|| (p.name == "cpu_moe_layers"
&& profile
.start_parameters
.get("cpu_moe")
.is_some_and(|v| v == "true"))
})
{
let mut i = 0;
while i < args.len() {
let inline = args[i].starts_with(&format!("{}=", spec.flag));
if args[i] == spec.flag || inline {
args.remove(i);
if !inline
&& !matches!(spec.kind, crate::startparams::ParameterKind::Switch)
&& i < args.len()
{
args.remove(i);
}
} else {
i += 1;
}
}
}
// Geprüfte Profilwerte stehen zuletzt und überschreiben Vorgaben.
args.extend(crate::startparams::parameter_arguments(
"llama.cpp",
&profile.start_parameters,
false,
));
let mut env: Vec<(String, String)> = self
.config
@ -131,6 +168,12 @@ impl LlamaCppEngine {
}
fn validate(profile: &ProfileSpec) -> Result<()> {
crate::startparams::validate_start_parameters(
"llama.cpp",
&profile.start_parameters,
profile.gpus.len(),
)
.map_err(|e| AdapterError::InvalidProfile(e.into()))?;
if profile.gpus.is_empty() {
return Err(AdapterError::InvalidProfile(
"keine GPU angegeben".to_string(),
@ -546,6 +589,7 @@ mod tests {
fn profile() -> ProfileSpec {
ProfileSpec {
start_parameters: Default::default(),
model_alias: "bonsai".to_string(),
model_path: PathBuf::from("/srv/models/gguf/Bonsai-1.7B-Q1_0.gguf"),
gpus: vec![0, 1],
@ -554,6 +598,32 @@ mod tests {
}
}
#[test]
fn startprofil_baut_nur_freigegebene_argumente_und_behaelt_gateway_adresse() {
let engine = LlamaCppEngine::new(LlamaCppConfig::default());
let mut p = profile();
p.extra_args.clear();
let default = engine.build_command(&p, 18000);
assert!(!default.args.contains(&"-np".to_string()));
p.start_parameters = crate::startparams::StartParameters::from([
("context".into(), "8192".into()),
("slots".into(), "4".into()),
("cpu_moe_layers".into(), "1".into()),
]);
let line = engine.build_command(&p, 18000);
assert!(line.args.windows(2).any(|w| w == ["-np", "4"]));
assert!(line.args.windows(2).any(|w| w == ["-ncmoe", "1"]));
assert!(line.args.windows(2).any(|w| w == ["--host", "127.0.0.1"]));
assert!(line.args.windows(2).any(|w| w == ["--port", "18000"]));
assert_eq!(
line.args
.iter()
.rposition(|x| x == "-c")
.map(|i| line.args[i + 1].as_str()),
Some("8192")
);
}
#[test]
fn kommandozeile_bindet_nur_an_localhost_und_waehlt_gpus() {
let engine = LlamaCppEngine::new(LlamaCppConfig::default());