Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

surface the real mflux trainer error and pin mflux>=0.17 so FLUX.2 LoRA training works

[._.]/ Adam Eivydb6d7fdd3232
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 3990ee836d..32c558c971 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -18,6 +18,8 @@
## Fixed
+- **LoRA training that died with a bare "exited with code 2" now says what actually broke — and a stale mflux fails loudly instead** — A FLUX.2 LoRA training run could fail instantly with the useless message `Training exited with code 2 — ❌ mflux trainer exited with code 2`. The real cause was a stale **mflux 0.12.x** in the local image-gen venv: that version predates FLUX.2 LoRA training, so its `mflux-train` CLI rejected the wrapper's `--config` flag (it wants `--train-config`) and had no `flux2-klein-*` base models — argparse exited 2 before any work began. The actual argparse error was lost because the wrapper merges mflux's stderr into stdout, leaving the Node failure classifier's stderr window empty. Two fixes: (1) on a non-zero exit the wrapper now replays the trainer's last ~40 output lines to stderr (so tracebacks, argparse errors, and version-mismatch complaints reach the classifier instead of vanishing), and a new `CLI_MISMATCH` classification turns the argparse rejection into an actionable *"your mflux is too old for FLUX.2 LoRA training — `pip install -U 'mflux>=0.17'`"*; (2) `scripts/setup-image-video.sh` now pins **`mflux>=0.17`** (the first release with FLUX.2 training) and the matching **`transformers>=5,<6`** mflux 0.17+ requires — the old `transformers<5` pin would have broken the newer mflux on import. (`scripts/train_mflux_lora.py`, `server/services/loraTraining/failure.js`, `scripts/setup-image-video.sh`)
+
- **Concurrent LoRA caption runs no longer fan out parallel requests at a single-GPU backend** — Within one run the captioner already processes images one at a time, but nothing stopped several runs from overlapping (captioning two datasets at once, re-captioning multiple single images, or a double-click). Each run is a detached loop, so concurrent runs fired N parallel `/chat/completions` requests at the same local Ollama/LM Studio — and on one GPU that's pure downside: every Ollama parallel slot reserves its own 32K-token KV cache, so concurrent vision requests multiply VRAM and risk an OOM or model reload, while parallel decoding gives no throughput win (it just time-slices the same compute and makes each request slower). A module-level mutex now serializes every caption vision call across all runs, holding backend load at concurrency 1 regardless of how many runs are in flight. One-shot vision calls (voice `ui_describe_visually`, the vision-test page) stay off the lock so a long batch run can't FIFO-starve an interactive describe. (`server/services/loraDatasetCaption.js`)
- **LoRA caption failures now tell you they happened instead of failing silently** — The captioner already reported per-image failures and a final failure tally over its progress stream (a vision model refusing an image or returning an empty description), but the dataset workbench threw that away: the "Caption all" button just stopped spinning and the run looked done, even when half the images were never captioned. The terminal frame is now surfaced as a toast — an actionable error when the whole run failed up front, a "Captioned 8/10 — 2 images failed (model refused…). Re-caption individually or pick another vision model." summary when some failed, and a success confirmation when all landed. This also covers the per-image "Re-caption" button, whose failures were previously invisible. (`client/src/pages/LoraDatasetDetail.jsx`)
diff --git a/scripts/setup-image-video.sh b/scripts/setup-image-video.sh
index f8c2bb1e3e..d3039a3fac 100755
--- a/scripts/setup-image-video.sh
+++ b/scripts/setup-image-video.sh
@@ -78,7 +78,10 @@ INSTALL_VIDEO="${INSTALL_VIDEO:-$DEFAULT_INSTALL_VIDEO}"
if [[ "$INSTALL_MFLUX" == "1" ]]; then
# Install via pip --user so we don't pollute the system or require a venv.
# mflux comes with the mflux-generate CLI which the local image backend
- # spawns directly. transformers<5 is required for MLX compatibility.
+ # spawns directly. Pin >=0.17: that's the first release with FLUX.2 LoRA
+ # training (`mflux-train --config`, `flux2-klein-*` base models). Older
+ # mflux (0.12.x) wants `--train-config` and has no flux2 models, so its
+ # trainer dies with a bare "exited with code 2" — see train_mflux_lora.py.
#
# `--force-reinstall --no-deps` on mflux only — earlier setup runs could
# leave the user-site copy at the right version number but with stale file
@@ -86,12 +89,13 @@ if [[ "$INSTALL_MFLUX" == "1" ]]; then
# from a partial reinstall, breaking the entry-point shim). Forcing the
# reinstall flushes the file tree without re-resolving torch/mlx and friends.
echo "📦 Installing image generation packages (mflux + deps)..."
- "$PYTHON_BIN" -m pip install --upgrade --user --force-reinstall --no-deps mflux
+ "$PYTHON_BIN" -m pip install --upgrade --user --force-reinstall --no-deps 'mflux>=0.17'
# mflux above is installed with --no-deps to flush its file tree without
# re-resolving torch/mlx — but that means we must explicitly install mflux's
# own runtime deps here (notably `mlx` on macOS, which it imports at startup).
- # Without this, INSTALL_VIDEO=0 leaves mflux unable to import.
- MFLUX_DEPS=("transformers<5" safetensors huggingface_hub numpy opencv-python tqdm)
+ # Without this, INSTALL_VIDEO=0 leaves mflux unable to import. mflux >=0.17
+ # requires transformers 5.x (>=5,<6) — the old <5 pin breaks it on import.
+ MFLUX_DEPS=("transformers>=5,<6" safetensors huggingface_hub numpy opencv-python tqdm)
if is_macos; then
MFLUX_DEPS+=(mlx)
fi
diff --git a/scripts/train_mflux_lora.py b/scripts/train_mflux_lora.py
index 0c20449816..c4867d70ec 100644
--- a/scripts/train_mflux_lora.py
+++ b/scripts/train_mflux_lora.py
@@ -36,11 +36,17 @@ import subprocess
import sys
import threading
import zipfile
+from collections import deque
from pathlib import Path
CHILD = None
STOP_REQUESTED = False
+# How many of the trainer's recent non-progress output lines to retain and
+# replay to stderr on a non-zero exit (so the Node failure classifier sees the
+# real error, not just the exit code). See the loop in main().
+OUTPUT_TAIL_LINES = 40
+
def log(msg: str) -> None:
print(msg, flush=True)
@@ -111,6 +117,13 @@ FATAL_PATTERNS = [
("OOM", re.compile(r"out of memory|Insufficient Memory|Metal.*out of memory|std::bad_alloc", re.I)),
("MODULE_NOT_FOUND", re.compile(r"ModuleNotFoundError|No module named", re.I)),
("HF_AUTH", re.compile(r"GatedRepoError|401 Client Error|is restricted|Repo.*is gated", re.I)),
+ # argparse rejecting our flags / model choice means the installed mflux is
+ # too old for FLUX.2 LoRA training (e.g. 0.12.x wants `--train-config` and
+ # has no flux2 base models) — the exact failure that surfaced as a bare
+ # "exited with code 2". CLI_MISMATCH mirrors failure.js.
+ ("CLI_MISMATCH", re.compile(
+ r"unrecognized arguments|invalid choice|the following arguments are required|"
+ r"mflux-train: error", re.I)),
]
@@ -231,6 +244,14 @@ def main():
in_training = False
fatal_emitted = False
+ # Ring buffer of the trainer's recent non-progress output. mflux's stderr
+ # is merged into its stdout (so tqdm stays in order), which means the Node
+ # side tags every line `stream='stdout'` and the JS classifier's stderr
+ # tail — its only window into *why* a run died — stays empty. On a non-zero
+ # exit we replay this buffer to stderr so argparse errors, tracebacks, and
+ # version-mismatch complaints actually reach the classifier instead of the
+ # run failing with a bare "exited with code N".
+ output_tail = deque(maxlen=OUTPUT_TAIL_LINES)
for raw in stream_lines(CHILD.stdout):
line = raw.strip()
if not line or NOISE_RE.search(line):
@@ -266,6 +287,7 @@ def main():
# Forward everything else (truncated) — keeps the JS idle watchdog
# fed during model download/load phases and aids debugging.
+ output_tail.append(line[:300])
log(f"STATUS:{line[:300]}")
code = CHILD.wait()
@@ -277,6 +299,12 @@ def main():
sys.exit(143)
if code != 0:
+ # Replay the trainer's tail to stderr so the Node classifier sees the
+ # real error. Skip when a structured USER_ERROR already pinned the
+ # cause (its message is more actionable than raw tail lines).
+ if not fatal_emitted:
+ for tail_line in output_tail:
+ print(f"mflux: {tail_line}", file=sys.stderr, flush=True)
print(f"❌ mflux trainer exited with code {code}", file=sys.stderr, flush=True)
sys.exit(code or 1)
diff --git a/server/services/loraTraining/failure.js b/server/services/loraTraining/failure.js
index 539f3570f8..afd977d4b5 100644
--- a/server/services/loraTraining/failure.js
+++ b/server/services/loraTraining/failure.js
@@ -7,6 +7,10 @@
const OOM_RE = /MPS backend out of memory|CUDA out of memory|Insufficient Memory|Metal.*out of memory|std::bad_alloc/i;
const MODULE_NOT_FOUND_RE = /ModuleNotFoundError|No module named/i;
const HF_AUTH_RE = /GatedRepoError|401 Client Error|Repo.*is gated|Access to model .* is restricted/i;
+// argparse rejecting the trainer's flags / model choice → the installed mflux
+// predates FLUX.2 LoRA training (0.12.x wants `--train-config`, has no flux2
+// base models). This is the failure that surfaced as a bare "exited with code 2".
+const CLI_MISMATCH_RE = /unrecognized arguments|invalid choice|the following arguments are required|mflux-train: error/i;
export function classifyTrainingFailure({ stderrTail = [], exitCode = null, signal = null, userError = null } = {}) {
if (userError?.message) {
@@ -31,6 +35,12 @@ export function classifyTrainingFailure({ stderrTail = [], exitCode = null, sign
message: 'Hugging Face rejected the model download — set HUGGINGFACE_API_KEY and accept the model license on huggingface.co.',
};
}
+ if (CLI_MISMATCH_RE.test(tail)) {
+ return {
+ code: 'CLI_MISMATCH',
+ message: 'The mflux trainer rejected its arguments — your installed mflux is too old for FLUX.2 LoRA training. Upgrade with `pip install -U "mflux>=0.17"` (or re-run `bash scripts/setup-image-video.sh`).',
+ };
+ }
if (signal === 'SIGKILL') {
return {
code: 'KILLED',
diff --git a/server/services/loraTraining/failure.test.js b/server/services/loraTraining/failure.test.js
index 8429f83690..a43a115873 100644
--- a/server/services/loraTraining/failure.test.js
+++ b/server/services/loraTraining/failure.test.js
@@ -22,6 +22,17 @@ describe('classifyTrainingFailure', () => {
expect(classifyTrainingFailure({ stderrTail: ['GatedRepoError: 403'] }).code).toBe('HF_AUTH');
});
+ it('classifies argparse CLI mismatch as a stale-mflux upgrade hint', () => {
+ // The exact tail the wrapper replays when mflux 0.12.x rejects --config.
+ const tail = [
+ 'mflux: usage: mflux-train [-h] ...',
+ 'mflux: mflux-train: error: unrecognized arguments: --config /run/mflux-train.json',
+ ];
+ const out = classifyTrainingFailure({ exitCode: 2, stderrTail: tail });
+ expect(out.code).toBe('CLI_MISMATCH');
+ expect(out.message).toMatch(/mflux>=0\.17/);
+ });
+
it('flags SIGKILL as memory reclaim', () => {
expect(classifyTrainingFailure({ signal: 'SIGKILL' }).code).toBe('KILLED');
});