Skip to content

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.

fix(trainer): der Schrittzaehler folgt jedem Schritt, nicht jeder Epoche

David16b2b0f65adf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5d21ae73..1f46e7ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -263,7 +263,9 @@ and the built-in engine has a name of its own, the LU Engine.
ten minutes of caching; the local chat model is paused for the run and
comes back afterwards, so it no longer squats the memory the recipe needs;
and a run that still runs out of memory on the card says what to close.
- Lines from winget stay out of the note under the button.
+ The step counter moves with every training step instead of once per epoch
+ (it used to sit on 0 for twenty minutes). Lines from winget stay out of the
+ note under the button.
- **AMD on Windows is read from the HIP SDK itself.** The only ROCm probe ran
rocm-smi, which the Windows SDK does not ship, so an installed ROCm went
unseen. LU reads HIP_PATH and hipinfo now and names the card architecture,
diff --git a/src-tauri/src/commands/trainer.rs b/src-tauri/src/commands/trainer.rs
index 5fd23c88..df4dad04 100644
--- a/src-tauri/src/commands/trainer.rs
+++ b/src-tauri/src/commands/trainer.rs
@@ -24,7 +24,7 @@ use crate::os_error;
use crate::state::AppState;
use std::fs;
-use std::io::{BufRead, BufReader, Read};
+use std::io::{BufReader, Read};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::atomic::Ordering;
@@ -880,6 +880,36 @@ fn pip_with_retry(
}
}
+/// Feed a child's output to `on_line` one segment at a time, where a segment
+/// ends at a newline OR a carriage return. Progress bars (tqdm) redraw their
+/// line with \r and never send \n until the bar is done, so `BufRead::lines`
+/// delivers a whole epoch of updates as one line, long after they happened.
+fn for_each_progress_line<R: Read>(mut stream: R, mut on_line: impl FnMut(String)) {
+ let mut pending: Vec<u8> = Vec::new();
+ let mut buf = [0u8; 4096];
+ loop {
+ let n = match stream.read(&mut buf) {
+ Ok(0) => break,
+ Ok(n) => n,
+ Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
+ Err(_) => break,
+ };
+ for &b in &buf[..n] {
+ if b == b'\n' || b == b'\r' {
+ if !pending.is_empty() {
+ on_line(String::from_utf8_lossy(&pending).into_owned());
+ pending.clear();
+ }
+ } else {
+ pending.push(b);
+ }
+ }
+ }
+ if !pending.is_empty() {
+ on_line(String::from_utf8_lossy(&pending).into_owned());
+ }
+}
+
fn run_child(
mut cmd: Command,
label: &str,
@@ -915,8 +945,12 @@ fn run_child(
let run = run.clone();
let tail = tail.clone();
handles.push(std::thread::spawn(move || {
- let reader = BufReader::new(stream);
- for line in reader.lines().map_while(Result::ok) {
+ // Split on carriage returns as well as newlines: tqdm rewrites its
+ // progress line in place with \r and only ends it with \n at the
+ // end of an epoch, so a reader that waits for \n saw the step
+ // counter jump in blocks of one epoch (measured on the box on
+ // 06.09.2026: "Training 0/400" for 23 minutes, then 48 at a time).
+ for_each_progress_line(stream, |line| {
// Der Schwanz dieses Protokolls steht in der Oberflaeche, also
// gilt hier dieselbe Regel wie beim Installer: was das
// Betriebssystem geschrieben hat, steht englisch da, was der
@@ -924,7 +958,7 @@ fn run_child(
let line = os_error::english_child_text(&line).into_owned();
let trimmed = line.trim();
if trimmed.is_empty() {
- continue;
+ return;
}
if let Ok(mut t) = tail.lock() {
t.push(trimmed.to_string());
@@ -933,7 +967,7 @@ fn run_child(
}
}
if echo == Echo::Quiet {
- continue;
+ return;
}
// Step counter for the UI meter: musubi/tqdm emit
// "steps: NN%|...| 123/1600 [...]" style lines.
@@ -944,7 +978,7 @@ fn run_child(
}
}
push_log(&run, trimmed);
- }
+ });
}));
}
@@ -3261,3 +3295,37 @@ mod journey_tests {
}
}
+#[cfg(test)]
+mod progress_line_tests {
+ use super::*;
+ use std::io::Cursor;
+
+ fn collect(bytes: &[u8]) -> Vec<String> {
+ let mut out = Vec::new();
+ for_each_progress_line(Cursor::new(bytes.to_vec()), |l| out.push(l));
+ out
+ }
+
+ #[test]
+ fn a_carriage_return_ends_a_line_like_a_newline_does() {
+ assert_eq!(collect(b"a\rb\rc\nd"), ["a", "b", "c", "d"]);
+ assert_eq!(collect(b"\r\n\r"), Vec::<String>::new(), "empty segments are not lines");
+ assert_eq!(collect(b"tail without newline"), ["tail without newline"]);
+ }
+
+ #[test]
+ fn every_tqdm_redraw_reaches_the_step_counter() {
+ let stream = b"steps: 0%| | 0/400 [00:00<?, ?it/s]\rsteps: 0%| | 1/400 [00:11<1:16:00, 11.4s/it]\rsteps: 0%| | 2/400 [00:23<1:16:00, 11.4s/it]\n";
+ let steps: Vec<(u64, u64)> = collect(stream).iter().filter_map(|l| parse_step_counter(l)).collect();
+ assert_eq!(steps, [(0, 400), (1, 400), (2, 400)], "each \\r update is its own line");
+ }
+
+ #[test]
+ fn the_child_reader_no_longer_waits_for_a_newline() {
+ let src = include_str!("trainer.rs");
+ let body = &src[src.find("fn run_child(").expect("run_child")..];
+ let body = &body[..body.find("let exit = loop").expect("wait loop")];
+ assert!(body.contains("for_each_progress_line(stream"), "the reader goes through the \\r-aware splitter");
+ assert!(!body.contains(".lines()"), "BufRead::lines would hide tqdm updates until the epoch ends");
+ }
+}
diff --git a/src/lib/release-notes.ts b/src/lib/release-notes.ts
index 3205bfae..d97fe4f6 100644
--- a/src/lib/release-notes.ts
+++ b/src/lib/release-notes.ts
@@ -86,7 +86,7 @@ export const RELEASE_NOTES: ReleaseNote[] = [
'The ComfyUI installer checks that the environment it just built can import ComfyUI, installs what is missing, and names a missing Visual C++ runtime instead of ending in a silent crash.',
'Repair environment runs the same check with a time limit and a Cancel button that stops it, and the trainer setup stopped blaming the network for failures that had nothing to do with the network.',
'Character Studio sets itself up on a machine whose Python is too new. The trainer needs Python 3.10 to 3.12, and LU built its environment from whatever Python was newest, so a machine with 3.14 failed at the last step on every update since August. The setup now picks a Python from that range by itself, installs 3.12 on Windows if there is none, and rebuilds an environment that came from the wrong one. The failure text under the button also stopped being cut after one line. Reported in Discord ticket 0004.',
- 'The local trainer no longer hands out instructions. On the way from Set up trainer to a finished character every dead end fixes itself or names its cause: the trainer source comes as an archive and needs no git on the machine, the drive is checked for room before the first byte, a download that breaks off is retried twice, a missing Windows runtime library for PyTorch is installed by LU through winget instead of a link to microsoft.com, the setup proves that PyTorch loads before it calls the environment ready, a card with less than 12 GB hears that before ten minutes of caching, the local chat model is paused for the run and comes back afterwards instead of squatting the memory the recipe needs, and a run that still runs out of memory on the card says what to close. winget output stays out of the note under the button.',
+ 'The local trainer no longer hands out instructions. On the way from Set up trainer to a finished character every dead end fixes itself or names its cause: the trainer source comes as an archive and needs no git on the machine, the drive is checked for room before the first byte, a download that breaks off is retried twice, a missing Windows runtime library for PyTorch is installed by LU through winget instead of a link to microsoft.com, the setup proves that PyTorch loads before it calls the environment ready, a card with less than 12 GB hears that before ten minutes of caching, the local chat model is paused for the run and comes back afterwards instead of squatting the memory the recipe needs, and a run that still runs out of memory on the card says what to close. The step counter moves with every training step instead of once per epoch, and winget output stays out of the note under the button.',
'A ComfyUI that will not start names the cause. A missing Visual C++ runtime, or a graphics driver older than the PyTorch that was installed, used to arrive as "the Python environment looks broken" next to a Repair button, and neither of those lives in the folder Repair rebuilds. The message now says which of the two it is, and LU no longer starts a repair that cannot fix it.',
'AMD on Windows is read from the HIP SDK itself. The only ROCm probe ran rocm-smi, which the Windows SDK does not ship, so an installed ROCm went unseen. LU reads HIP_PATH and hipinfo now and names the card architecture, and an image run that fails names that architecture and get_arch_list instead of a HIP traceback. This is marked as researched rather than proven, because there is no RDNA4 card here.',
'The Model Manager stopped putting system RAM in the GPU field. ComfyUI reports system memory on a CPU device in a field called vram_total, so a machine with 64 GB of RAM read as if it had 62 GB of video memory.',