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
fix(trainer): der Schrittzaehler nimmt nur die Trainingsleiste, die Notiz zeigt die Summe
Davidb43ad97cc7c1
diff --git a/src-tauri/src/commands/trainer.rs b/src-tauri/src/commands/trainer.rsindex df4dad04..5e26d140 100644--- a/src-tauri/src/commands/trainer.rs+++ b/src-tauri/src/commands/trainer.rs@@ -944,6 +944,7 @@ fn run_child({let run = run.clone();let tail = tail.clone();+ let cancel = cancel.clone();handles.push(std::thread::spawn(move || {// 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@@ -951,6 +952,13 @@ fn run_child(// 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| {+ // After a cancel the tree is being killed; what the dying+ // Python still prints (a KeyboardInterrupt traceback) is not+ // this run's log. The box showed one under a status of+ // "cancelled" (06.09.2026).+ if cancel.load(Ordering::SeqCst) {+ return;+ }// 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@@ -1022,6 +1030,15 @@ fn run_child(/// Pull "123/1600" out of a tqdm-ish progress line.pub fn parse_step_counter(line: &str) -> Option<(u64, u64)> {+ // Only the training bar counts. musubi labels it "steps: NN%|...| cur/total+ // [...]". The weight loader right before it draws a tqdm bar of its own+ // (521 tensors on the box, 06.09.2026) and the epoch line carries a total+ // of its own: the meter read "Training 27/521 ... 521/521" for three+ // minutes against a 400-step run, then fell back to 0/400.+ let line = line.trim_start();+ if !line.get(..5).is_some_and(|p| p.eq_ignore_ascii_case("steps")) {+ return None;+ }// Cheap scan without regex: find "N/M" where both sides are digits and M// looks like a step total (>= 10, filters version strings like 2/3).let bytes = line.as_bytes();@@ -2172,7 +2189,11 @@ mod tests {#[test]fn the_cancel_branch_does_not_join_the_reader_threads() {let src = include_str!("trainer.rs");- let zweig = src+ // The reader closure above the wait loop checks the same flag (it+ // drops what the dying child prints), so anchor on the loop itself.+ let warte = &src[src.find("fn run_child(").expect("run_child")..];+ let warte = &warte[warte.find("let exit = loop {").expect("wait loop")..];+ let zweig = warte.split("if cancel.load(Ordering::SeqCst) {").nth(1).expect("cancel branch")@@ -2604,10 +2625,21 @@ mod tests {#[test]fn step_counter_parses_tqdm_lines() {assert_eq!(parse_step_counter("steps: 8%|▊| 123/1600 [02:10<26:04]"), Some((123, 1600)));- assert_eq!(parse_step_counter("epoch 1/16"), Some((1, 16)));+ assert_eq!(parse_step_counter("steps: 9%|▉ | 35/400 [06:34<1:08:38, 11.28s/it]"), Some((35, 400)));assert_eq!(parse_step_counter("no counter here"), None);// version-ish fragments with tiny totals are ignored- assert_eq!(parse_step_counter("python 3/4 things"), None);+ assert_eq!(parse_step_counter("steps: python 3/4 things"), None);+ }++ #[test]+ fn only_the_training_bar_moves_the_step_counter() {+ // The DiT loader draws its own tqdm bar right before training starts+ // (521 tensors on the box, 06.09.2026); for three minutes the meter+ // counted it up to 521/521 against a 400-step run. Epoch lines carry+ // a total of their own as well.+ assert_eq!(parse_step_counter("41/521 [00:10<02:00, 4.0it/s]"), None);+ assert_eq!(parse_step_counter("Loading: 100%|██████████| 521/521 [02:10<00:00]"), None);+ assert_eq!(parse_step_counter("epoch 1/16"), None);}#[test]@@ -3320,6 +3352,20 @@ mod progress_line_tests {assert_eq!(steps, [(0, 400), (1, 400), (2, 400)], "each \\r update is its own line");}+ #[test]+ fn what_the_dying_child_prints_after_a_cancel_is_not_the_log() {+ // The box showed a raw KeyboardInterrupt traceback in the live log+ // under a status of "cancelled" (06.09.2026): the tree was being+ // killed and the reader kept forwarding its last breaths.+ 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")];+ let reader = &body[body.find("for_each_progress_line(stream").expect("reader")..];+ let gate = reader.find("if cancel.load(Ordering::SeqCst)").expect("the reader checks the cancel flag");+ let log = reader.find("push_log(&run, trimmed)").expect("the reader logs");+ assert!(gate < log, "the cancel check comes before anything reaches the log");+ }+#[test]fn the_child_reader_no_longer_waits_for_a_newline() {let src = include_str!("trainer.rs");diff --git a/src/api/__tests__/base-download-running.test.ts b/src/api/__tests__/base-download-running.test.tsindex a6323b58..8286feaf 100644--- a/src/api/__tests__/base-download-running.test.ts+++ b/src/api/__tests__/base-download-running.test.ts@@ -8,7 +8,7 @@import { describe, it, expect } from 'vitest'import fs from 'node:fs'import path from 'node:path'-import { baseDownloadRunning, TRAINER_BASE_FILES } from '../trainer'+import { baseDownloadRunning, baseDownloadPercent, TRAINER_BASE_FILES } from '../trainer'describe('baseDownloadRunning', () => {it('is true while any base file downloads or connects', () => {@@ -33,3 +33,33 @@ describe('baseDownloadRunning', () => {expect(button).toBeGreaterThan(mount)})})++describe('baseDownloadPercent', () => {+ const [dit, enc, vae] = TRAINER_BASE_FILES.map((f) => f.filename)++ it('sums all three files, finished ones included, like the tray does', () => {+ // 0.335 GB done, 4 of 8 GB, 1.2 of 12 GB: 5.535 of 20.335 GB is 27 percent.+ const pct = baseDownloadPercent({+ [vae]: { status: 'complete', progress: 335, total: 335 },+ [enc]: { status: 'downloading', progress: 4000, total: 8000 },+ [dit]: { status: 'downloading', progress: 1200, total: 12000 },+ })+ expect(pct).toBe(27)+ })++ it('is null when nothing moves, and 0 while the sizes are still unknown', () => {+ expect(baseDownloadPercent({})).toBeNull()+ expect(baseDownloadPercent({ [vae]: { status: 'complete', progress: 335, total: 335 } })).toBeNull()+ expect(baseDownloadPercent({ [dit]: { status: 'connecting', progress: 0, total: 0 } })).toBe(0)+ })++ it('never runs past 100', () => {+ expect(baseDownloadPercent({ [dit]: { status: 'downloading', progress: 999, total: 100 } })).toBe(100)+ })++ it('feeds the note under the button', () => {+ const src = fs.readFileSync(path.join(__dirname, '..', '..', 'components', 'create', 'experimental', 'SpecialIntentControls.tsx'), 'utf8')+ expect(src).toContain('const pct = baseDownloadPercent(prog)')+ expect(src).toContain('Downloading base files (${pct}% of about 19 GB)...')+ })+})diff --git a/src/api/trainer.ts b/src/api/trainer.tsindex 48959bc2..0ca3745b 100644--- a/src/api/trainer.ts+++ b/src/api/trainer.ts@@ -70,6 +70,23 @@ export function baseDownloadRunning(})}+/**+ * Progress over the three base files together, the way the tray sums its+ * group. The note under the button used to quote the first running file only+ * ("z_image 3%") while 15 percent of the 19 GB were already on disk (Phase G,+ * 06.09.2026). null when none of them is moving.+ */+export function baseDownloadPercent(+ progress: Record<string, { progress: number; total: number; status: string } | undefined>,+): number | null {+ if (!baseDownloadRunning(progress)) return null+ const rows = TRAINER_BASE_FILES.flatMap((f) => { const r = progress[f.filename]; return r ? [r] : [] })+ const total = rows.reduce((a, r) => a + Math.max(r.total, 0), 0)+ if (total <= 0) return 0+ const done = rows.reduce((a, r) => a + Math.min(Math.max(r.progress, 0), Math.max(r.total, 0)), 0)+ return Math.min(100, Math.round((done / total) * 100))+}+export async function installCharacterTrainer(installPath?: string): Promise<{ status: string }> {return backendCall('install_character_trainer', { installPath: installPath ?? null })}diff --git a/src/components/create/experimental/SpecialIntentControls.tsx b/src/components/create/experimental/SpecialIntentControls.tsxindex d4ae5c23..b8c4f21e 100644--- a/src/components/create/experimental/SpecialIntentControls.tsx+++ b/src/components/create/experimental/SpecialIntentControls.tsx@@ -16,7 +16,7 @@ import { useCloudCatalogStore, cloudModelById, modelForOp } from '../../../storeimport { listLoras, deleteLora, type CloudLora } from '../../../api/cloud/loras'import {characterTrainerStatus, installCharacterTrainer, parseLocalCharacterLora,- TRAINER_BASE_FILES, baseDownloadRunning, type TrainerStatus,+ TRAINER_BASE_FILES, baseDownloadRunning, baseDownloadPercent, type TrainerStatus,} from '../../../api/trainer'import { startModelDownload, getDownloadProgress } from '../../../api/discover'import { useDownloadStore } from '../../../stores/downloadStore'@@ -300,14 +300,12 @@ function LocalTrainControls() {}} else {const prog = await getDownloadProgress().catch(() => ({} as Record<string, { progress: number; total: number; status: string; filename: string; error?: string }>))- const rows = TRAINER_BASE_FILES.map((f) => prog[f.filename]).filter(Boolean)- const active = rows.find((r) => r.status === 'downloading' || r.status === 'connecting')- if (active) {- const pct = active.total > 0 ? Math.round((active.progress / active.total) * 100) : 0- setNote(`Downloading ${active.filename} (${pct}%)...`)+ const pct = baseDownloadPercent(prog)+ if (pct !== null) {+ setNote(`Downloading base files (${pct}% of about 19 GB)...`)return}- const failed = rows.find((r) => r.status === 'error')+ const failed = TRAINER_BASE_FILES.map((f) => prog[f.filename]).find((r) => r?.status === 'error')const s = await characterTrainerStatus().catch(() => null)if (s) setStatus(s)if (failed) {