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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
add LORA_TRAIN_MAX_QUANT_BITS override to cap training base quant on M5
[._.]/ Adam Eivyefdc5dd3a946
diff --git a/server/services/loraTraining/runtimes.js b/server/services/loraTraining/runtimes.jsindex 79b2590656..e7d65d110a 100644--- a/server/services/loraTraining/runtimes.js+++ b/server/services/loraTraining/runtimes.js@@ -86,12 +86,32 @@ const MFLUX_SCHED = Object.freeze({ steps: 40, guidance: 1.0, timestepLow: 25, t** 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.*/export function deriveMfluxMemoryConfig(totalMemGb) {const gb = Number.isFinite(totalMemGb) ? totalMemGb : 0; // unknown → most conservative- if (gb >= 96) return { quantize: null, low_ram: true };- if (gb >= 64) return { quantize: 8, low_ram: true };- return { quantize: 4, low_ram: true };+ const base = gb >= 96+ ? { quantize: null, low_ram: true }+ : gb >= 64+ ? { quantize: 8, low_ram: true }+ : { quantize: 4, low_ram: true };+ const capRaw = Number.parseInt(process.env.LORA_TRAIN_MAX_QUANT_BITS ?? '', 10);+ if (capRaw === 8 || capRaw === 4) {+ // null (bf16) is "16+ bits" → always capped; an existing smaller quant+ // (more aggressive) is kept. Lower bits = smaller = stays.+ const curBits = base.quantize == null ? 16 : base.quantize;+ if (curBits > capRaw) return { ...base, quantize: capRaw };+ }+ return base;}/**diff --git a/server/services/loraTraining/runtimes.test.js b/server/services/loraTraining/runtimes.test.jsindex 40aa4af721..618c7d4b05 100644--- a/server/services/loraTraining/runtimes.test.js+++ b/server/services/loraTraining/runtimes.test.js@@ -130,6 +130,29 @@ describe('buildMfluxTrainConfig', () => {expect(config.quantize).toBe(4);expect(config.low_ram).toBe(true);});++ 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.+ 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.+ 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.+ process.env.LORA_TRAIN_MAX_QUANT_BITS = '16';+ expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: null, low_ram: true });+ process.env.LORA_TRAIN_MAX_QUANT_BITS = 'banana';+ expect(deriveMfluxMemoryConfig(128)).toEqual({ quantize: null, low_ram: true });+ } finally {+ if (prev === undefined) delete process.env.LORA_TRAIN_MAX_QUANT_BITS;+ else process.env.LORA_TRAIN_MAX_QUANT_BITS = prev;+ }+ });});describe('buildMfluxTrainArgs / buildFlux2TrainArgs', () => {