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

fix(issue-1321): default LoRA frozen base to 8-bit QLoRA, never auto-bf16

[._.]/ Adam Eivy4b24ff3fe8a5
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index d60ccdc7d0..554537f6f9 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -378,6 +378,12 @@ to protect and largely stops firing.
free — so an oversubscribed run can't swap-thrash the box into a reboot. If a
run won't start with a "not enough free memory" error, stop other model servers
or close apps and retry.
+- The frozen base is **never auto-trained as unquantized bf16** (issue #1321):
+ the top tier is now 8-bit QLoRA even on a ≥96 GB box. Auto-bf16-9B was both
+ pathologically slow and the exact config that panicked this machine three
+ times, so it's opt-in only — a run that genuinely wants it sets **Base quant →
+ 16** in the training panel (or `LORA_TRAIN_MAX_QUANT_BITS=8`/`=4` still forces
+ an even lighter ceiling install-wide).
**What to do / how to investigate**: see the full incident record and checklist in
[`docs/research/2026-06-13-mflux-training-watchdog-panic.md`](research/2026-06-13-mflux-training-watchdog-panic.md).
diff --git a/server/services/loraTraining/runtimes.js b/server/services/loraTraining/runtimes.js
index 8021268ff5..25e85bea0d 100644
--- a/server/services/loraTraining/runtimes.js
+++ b/server/services/loraTraining/runtimes.js
@@ -80,26 +80,32 @@ const MFLUX_SCHED = Object.freeze({ steps: 40, guidance: 1.0, timestepLow: 25, t
* Memory-derived training knobs — mirrors the FFLF pixel-budget pattern
* (videoGen/local.js): pure, with total RAM injected by the caller.
* Training a bf16 base + in-RAM latent cache OOM-killed a 48 GB machine
- * during verification, so anything under 96 GB trains QLoRA-style against
- * an on-the-fly-quantized base. The encoded dataset cache ALWAYS spills to
+ * during verification, so every tier trains QLoRA-style against an
+ * on-the-fly-quantized base. The encoded dataset cache ALWAYS spills to
* disk (`low_ram`): keeping it in RAM bought nothing but pushed a 128 GB box
* to 122 GB used + 21 GB swap (the swap-thrash that coincided with GPU
* watchdog reboots — see docs/research/2026-06-13-mflux-training-watchdog-panic.md);
* disk-backing it costs only I/O, no training quality. Quantizing the FROZEN
* base is the standard QLoRA recipe — the LoRA weights stay full precision.
*
+ * Default tier never auto-selects unquantized bf16 (issue #1321): even a
+ * ≥96 GB box gets 8-bit QLoRA, not bf16. The bf16 9B path was pathologically
+ * slow (couldn't complete a step in 14 min on an M5 Max 128 GB) AND the config
+ * that GPU-watchdog-panicked the box three times
+ * (docs/research/2026-06-13-mflux-training-watchdog-panic.md) — so it's opt-in
+ * only, never the silent default. 8-bit QLoRA is the standard character-LoRA
+ * recipe with minimal fidelity loss; a run that genuinely wants a heavier base
+ * asks for it explicitly via `baseQuant: 16` (→ `quantize: null`).
+ *
* Callers feed the *available* memory budget (post-unload, see memoryPrep.js),
* not raw RAM, so the tier reflects real headroom on a shared box.
*
- * Override (`LORA_TRAIN_MAX_QUANT_BITS`): on new M5-class silicon the
- * unquantized-bf16 9B path is both pathologically slow (couldn't complete a
- * step in 14 min on an M5 Max 128 GB) AND the config that GPU-watchdog-panicked
- * the box three times (docs/research/2026-06-13-mflux-training-watchdog-panic.md).
- * Setting `LORA_TRAIN_MAX_QUANT_BITS=8` caps the top tier at 8-bit QLoRA even
- * when RAM would allow bf16 — far lighter, standard QLoRA recipe (frozen base
- * quantized, LoRA weights full precision), minimal fidelity loss for a
- * character LoRA. Unset → original memory-derived behavior (no change for other
- * installs). Accepts 8 or 4; anything else is ignored.
+ * Override (`LORA_TRAIN_MAX_QUANT_BITS`): a hard per-install ceiling on the
+ * frozen-base bit-width. Setting it to `4` forces every tier (and every per-run
+ * opt-in) down to 4-bit; setting it to `8` clamps an explicit `baseQuant: 16`
+ * bf16 opt-in back to 8-bit (the 8-bit default is already at/under the cap, so
+ * it's a no-op there). Unset → the memory-derived tier plus whatever a run opts
+ * into. Accepts 8 or 4; anything else is ignored.
*
* Per-run overrides (`overrides = { quantize?, low_ram? }`, issue #1321): a
* single run can opt into a heavier or lighter frozen base than its memory tier
@@ -112,11 +118,13 @@ const MFLUX_SCHED = Object.freeze({ steps: 40, guidance: 1.0, timestepLow: 25, t
*/
export function deriveMfluxMemoryConfig(totalMemGb, overrides = {}) {
const gb = Number.isFinite(totalMemGb) ? totalMemGb : 0; // unknown → most conservative
- const result = gb >= 96
- ? { quantize: null, low_ram: true }
- : gb >= 64
- ? { quantize: 8, low_ram: true }
- : { quantize: 4, low_ram: true };
+ // bf16 is never the auto default (issue #1321) — the top tier is 8-bit QLoRA,
+ // not unquantized bf16, even at ≥96 GB (bf16 9B was pathologically slow and
+ // GPU-watchdog-panicked the box). A run opts into bf16 explicitly via
+ // `baseQuant: 16`. Tighter budgets step down to 4-bit.
+ const result = gb >= 64
+ ? { quantize: 8, low_ram: true }
+ : { quantize: 4, low_ram: true };
// Request override wins over the memory-derived tier. hasOwnProperty (not a
// truthiness check) so an explicit `quantize: null` (bf16) is honored as a
// deliberate clear, not mistaken for "absent".
diff --git a/server/services/loraTraining/runtimes.test.js b/server/services/loraTraining/runtimes.test.js
index 0f50bade90..0086cbd0f2 100644
--- a/server/services/loraTraining/runtimes.test.js
+++ b/server/services/loraTraining/runtimes.test.js
@@ -120,9 +120,10 @@ describe('buildMfluxTrainConfig', () => {
it('derives quantize from the memory budget; latent cache always spills to disk', () => {
// low_ram is true at every tier — an in-RAM latent cache bought nothing
- // but risked swap-thrash (the 128 GB / 21 GB-swap incident). quantize still
- // steps down as the available budget shrinks.
- expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: null, low_ram: true });
+ // but risked swap-thrash (the 128 GB / 21 GB-swap incident). bf16 is never
+ // the auto default (issue #1321): even a 128 GB box gets 8-bit QLoRA, not
+ // unquantized bf16. quantize still steps down to 4-bit on tighter budgets.
+ expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: 8, low_ram: true });
expect(deriveMfluxMemoryConfig(64)).toEqual({ quantize: 8, low_ram: true });
expect(deriveMfluxMemoryConfig(48)).toEqual({ quantize: 4, low_ram: true });
expect(deriveMfluxMemoryConfig(null)).toEqual({ quantize: 4, low_ram: true });
@@ -134,20 +135,20 @@ describe('buildMfluxTrainConfig', () => {
it('LORA_TRAIN_MAX_QUANT_BITS caps the top tier (M5 bf16-panic mitigation)', () => {
const prev = process.env.LORA_TRAIN_MAX_QUANT_BITS;
try {
- // cap=8: a bf16 (null) box is capped to 8-bit; already-8 stays; smaller (4) is kept.
+ // cap=8: already at the 8-bit default (no-op); smaller (4) is kept.
process.env.LORA_TRAIN_MAX_QUANT_BITS = '8';
expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: 8, low_ram: true });
expect(deriveMfluxMemoryConfig(64)).toEqual({ quantize: 8, low_ram: true });
expect(deriveMfluxMemoryConfig(48)).toEqual({ quantize: 4, low_ram: true });
- // cap=4: everything capped to 4-bit.
+ // cap=4: everything (default 8-bit and the 4-bit tier) forced to 4-bit.
process.env.LORA_TRAIN_MAX_QUANT_BITS = '4';
expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: 4, low_ram: true });
expect(deriveMfluxMemoryConfig(64)).toEqual({ quantize: 4, low_ram: true });
- // garbage / unsupported values are ignored → original behavior.
+ // garbage / unsupported values are ignored → memory-derived default (8-bit).
process.env.LORA_TRAIN_MAX_QUANT_BITS = '16';
- expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: null, low_ram: true });
+ expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: 8, low_ram: true });
process.env.LORA_TRAIN_MAX_QUANT_BITS = 'banana';
- expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: null, low_ram: true });
+ expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: 8, low_ram: true });
} finally {
if (prev === undefined) delete process.env.LORA_TRAIN_MAX_QUANT_BITS;
else process.env.LORA_TRAIN_MAX_QUANT_BITS = prev;
@@ -159,8 +160,8 @@ describe('buildMfluxTrainConfig', () => {
// box, or lighter than the box would otherwise pick.
expect(deriveMfluxMemoryConfig(48, { quantize: null })).toEqual({ quantize: null, low_ram: true });
expect(deriveMfluxMemoryConfig(128, { quantize: 4 })).toEqual({ quantize: 4, low_ram: true });
- // low_ram override flips the spill independently of quantize.
- expect(deriveMfluxMemoryConfig(128, { low_ram: false })).toEqual({ quantize: null, low_ram: false });
+ // low_ram override flips the spill independently of quantize (128 GB → 8-bit default).
+ expect(deriveMfluxMemoryConfig(128, { low_ram: false })).toEqual({ quantize: 8, low_ram: false });
// Absent keys keep the memory-derived value; an empty override is a no-op.
expect(deriveMfluxMemoryConfig(64, {})).toEqual({ quantize: 8, low_ram: true });
// An explicit quantize: null (bf16) is honored as a deliberate clear, not
@@ -193,10 +194,10 @@ describe('buildMfluxTrainConfig', () => {
expect(buildMfluxTrainConfig({ ...base, params: { baseQuant: 8 } }).quantize).toBe(8);
expect(buildMfluxTrainConfig({ ...base, totalMemGb: 128, params: { baseQuant: 4 } }).quantize).toBe(4);
// lowRam alone flips the spill at the config-builder level, leaving the
- // memory-derived quant (128 GB → bf16) untouched.
+ // memory-derived quant (128 GB → 8-bit default) untouched.
expect(buildMfluxTrainConfig({ ...base, totalMemGb: 128, params: { lowRam: false } }).low_ram).toBe(false);
- // No override → memory-derived tier is untouched (128 GB → bf16).
- expect(buildMfluxTrainConfig({ ...base, totalMemGb: 128 }).quantize).toBeNull();
+ // No override → memory-derived tier is untouched (128 GB → 8-bit, never bf16; issue #1321).
+ expect(buildMfluxTrainConfig({ ...base, totalMemGb: 128 }).quantize).toBe(8);
});
it('treats null baseQuant/lowRam ("Auto") as no override (issue #1407)', () => {