The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
merge: der Motor wird nach dem Start gefragt, ob er noch Text kann (fix/300-bug-a)
purpleda11e6fd059d
diff --cc src-tauri/src/commands/engine.rsindex 99456ebb,e272f37d..d3f637aa--- a/src-tauri/src/commands/engine.rs+++ b/src-tauri/src/commands/engine.rs@@@ -1910,16 -1889,23 +1911,23 @@@ fn start_after_stoplet deadline = health_timeout_for(model_path);let ctx = Some(ctx_size);- let first = spawn_engine_attempt(state, &binary, &desired_args, model_path, port, ctx, auto_layers);+ let first = spawn_engine_attempt(state, &binary, &desired_args, model_path, port, ctx, auto_layers, false);let failure = match first {- Ok(()) => {+ Ok(startup) => {tracing::info!(target: "engine", port, attempt = 1, "the LU Engine is serving");- return Ok(serde_json::json!({- "status": "started",- "port": port,- "model_path": model_path,- "ctx": ctx,- }));+ return Ok(serve_or_heal_garbled(+ state,+ &binary,+ model_path,+ tuning,+ port,+ slot_dir,+ mmproj,+ &desired_args,+ ctx,+ auto_layers,+ &startup,+ ));}Err(f) => f,};@@@ -1981,8 -1967,8 +1989,8 @@@// next start with the same settings has to be allowed to try the card// again.let retry_auto = auto_layers && !offload_was_tried;- match spawn_engine_attempt(state, &binary, &retry_args, model_path, retry_port, ctx, retry_auto) {+ match spawn_engine_attempt(state, &binary, &retry_args, model_path, retry_port, ctx, retry_auto, offload_was_tried) {- Ok(()) => {+ Ok(_) => {if offload_was_tried {tracing::warn!(target: "engine",@@@ -2005,6 -1991,173 +2013,176 @@@}}+ /// What a start answers when there is nothing to report about it. The exact+ /// object this function has always returned; the probe below only ever ADDS+ /// keys to it, so a healthy machine sees precisely what it saw before.+ fn started_answer(port: u16, model_path: &str, ctx: Option<u32>) -> serde_json::Value {+ serde_json::json!({+ "status": "started",+ "port": port,+ "model_path": model_path,+ "ctx": ctx,+ })+ }++ /// The same request with Flash Attention switched off, and nothing else moved.+ fn without_flash_attention(tuning: &EngineTuning) -> EngineTuning {+ EngineTuning { flash_attn: "off".into(), ..tuning.clone() }+ }++ /// The same request with the graphics card taken out of it.+ ///+ /// `gpu_layers: 0` rather than a smaller number on purpose. A card that+ /// answered unreadably has not proven it can be trusted with fewer layers, and+ /// halving a broken thing is a guess; the processor is the one part of the+ /// machine the three reports have never implicated. Everything else the user+ /// asked for (context, cache types, threads, mlock, mmap, the vision file)+ /// survives untouched, so only the one suspect variable moves.+ fn on_the_processor(tuning: &EngineTuning) -> EngineTuning {+ EngineTuning { gpu_layers: 0, ..tuning.clone() }+ }++ /// The sanity probe, and the restart it may decide on (bug a).+ ///+ /// Runs AFTER the engine has reported healthy, which is the whole point: a+ /// healthy port is what the three reporters already had. One fixed question at+ /// temperature 0, 24 tokens, and a look at the shape of the answer. Readable,+ /// or unreadable and the graphics card comes out.+ ///+ /// Costs nothing on a healthy machine that it would not have paid anyway: the+ /// probe's prompt is the warm-up the user's first message would otherwise have+ /// paid for, and it only ever runs at a start, never per message. A probe that+ /// times out, is refused, or answers something unjudgeable leaves the engine+ /// exactly where it is.+ #[allow(clippy::too_many_arguments)]+ fn serve_or_heal_garbled(+ state: &AppState,+ binary: &Path,+ model_path: &str,+ tuning: &EngineTuning,+ port: u16,+ slot_dir: Option<&str>,+ mmproj: Option<&str>,+ args: &[String],+ ctx: Option<u32>,+ auto_layers: bool,+ startup: &str,+ ) -> serde_json::Value {+ let mut answer = started_answer(port, model_path, ctx);+ // Measured once, from what llama-server itself printed on its way up. A+ // restart does not change the card, so this is not asked again.+ let no_matrix_cores = engine_sanity::device_without_matrix_cores(startup).unwrap_or(false);+ // What the engine currently runs with. Both move as the ladder is climbed,+ // and both are read back out of the argv that was actually spawned.+ let mut serving = tuning.clone();+ let mut serving_args = args.to_vec();+ // Three rungs at most (as it is, without flash attention, on the+ // processor), so a machine that is broken in some way this cannot mend+ // ends in seconds instead of restarting for ever.+ for _ in 0..3 {+ let Some(probe) = engine_sanity::probe_engine(port, engine_sanity::PROBE_TIMEOUT) else {+ tracing::info!(+ target: "engine",+ port,+ "the sanity probe got no usable answer, the LU Engine is left as it is"+ );+ return answer;+ };+ let facts = engine_sanity::EngineFacts {+ gpu_layers: gpu_layers_in(&serving_args),+ flash_attention_on: serving.flash_attn != "off",+ every_device_without_matrix_cores: no_matrix_cores,+ };+ tracing::info!(+ target: "engine",+ port,+ verdict = probe.verdict.label(),+ ms = probe.took.as_millis() as u64,+ ngl = facts.gpu_layers.map(|n| n.to_string()).unwrap_or_else(|| "none".into()),+ flash_attention = facts.flash_attention_on,+ matrix_cores = !no_matrix_cores,+ answer = %probe.sample,+ "sanity probe on the LU Engine"+ );- let next = match engine_sanity::decide(probe.verdict, &facts) {++ // `cpu_rung` is what the status line later reports as `cpuOnly`: the++ // processor rung is a fallback the user did not ask for, the flash++ // attention rung keeps whatever layer count was typed.++ let (next, cpu_rung) = match engine_sanity::decide(probe.verdict, &facts) {+ engine_sanity::AfterProbe::Serve => return answer,+ engine_sanity::AfterProbe::GiveUp => {+ tracing::error!(+ target: "engine",+ port,+ verdict = probe.verdict.label(),+ "the LU Engine answers unreadably without the graphics card, so the card is not the cause"+ );+ answer["garbled"] = serde_json::json!(true);+ answer["note"] = serde_json::json!(engine_sanity::GARBLED_ON_CPU_NOTE);+ return answer;+ }+ engine_sanity::AfterProbe::RestartWithoutFlashAttention => {+ tracing::warn!(+ target: "engine",+ port,+ verdict = probe.verdict.label(),+ "this card reports no matrix cores, restarting the LU Engine with Flash Attention off"+ );- without_flash_attention(&serving)++ (without_flash_attention(&serving), false)+ }+ engine_sanity::AfterProbe::RestartOnCpu => {+ tracing::warn!(+ target: "engine",+ port,+ verdict = probe.verdict.label(),+ "the graphics card produced unreadable output, restarting the LU Engine on the processor"+ );- on_the_processor(&serving)++ (on_the_processor(&serving), true)+ }+ };+ // A restart is a measurement thrown away: whatever `plan_offload` said+ // for the first start is not asked again, because the argument that is+ // being changed is not the layer count. `None` for `auto_ngl` keeps the+ // layer count out of the way, and the rung above puts the one value it+ // cares about into the tuning.+ let next_args = build_server_args(model_path, &next, port, slot_dir, mmproj, None);+ stop_engine_locked(state);+ // A restart is never an auto layer count, whatever the request said, so+ // the idempotence key must not remember it as one: the next start with+ // these settings has to be allowed to try the card again. Same rule as+ // the died-on-start retry.- if spawn_engine_attempt(state, binary, &next_args, model_path, port, ctx, false).is_err() {++ if spawn_engine_attempt(state, binary, &next_args, model_path, port, ctx, false, cpu_rung).is_err() {+ // The restart did not come up, and an engine that at least served+ // has just been torn down for it. Put the first one back rather+ // than leave the user with nothing; ONE attempt, for the same+ // reason `restore_engine` takes only one.+ tracing::error!(+ target: "engine",+ port,+ "the restart did not come up, bringing the first LU Engine back"+ );- let _ = spawn_engine_attempt(state, binary, args, model_path, port, ctx, auto_layers);++ let _ = spawn_engine_attempt(state, binary, args, model_path, port, ctx, auto_layers, false);+ answer["garbled"] = serde_json::json!(true);+ answer["note"] = serde_json::json!(engine_sanity::GARBLED_ON_CPU_NOTE);+ return answer;+ }+ answer["retried"] = serde_json::json!(true);+ answer["garbled"] = serde_json::json!(true);+ answer["cpuOnly"] = serde_json::json!(next.gpu_layers == 0);+ // The note tells the truth only after the next pass round this loop has+ // judged the new engine. Until then it says what was done, and the pass+ // that finds the answer readable returns it; a pass that does not+ // overwrites it.+ answer["note"] = serde_json::json!(if next.gpu_layers == 0 {+ engine_sanity::HEALED_ON_CPU_NOTE+ } else {+ engine_sanity::HEALED_WITHOUT_FLASH_ATTENTION_NOTE+ });+ serving = next;+ serving_args = next_args;+ }+ answer+ }+/// What one spawn-and-wait produced when it did not come up.pub(crate) struct StartFailure {/// The child was gone before the health budget ran out. Distinguishes a@@@ -2029,8 -2187,7 +2212,8 @@@ fn spawn_engine_attemptport: u16,ctx: Option<u32>,auto_layers: bool,+ cpu_fallback: bool,- ) -> Result<(), StartFailure> {+ ) -> Result<String, StartFailure> {// The one line a support log has to carry. Everything the start depends on// is in the argv: model path, context size, layer count, cache types,// thread count, mlock/mmap flags, the vision file and the port.