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
feat([issue-1321]): expose per-run baseQuant/lowRam LoRA overrides
[._.]/ Adam Eivy99ba42ad26d8
diff --git a/server/lib/validation.js b/server/lib/validation.jsindex 014f77daa2..c2cc1f427b 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -839,6 +839,14 @@ const loraTrainingParamsSchema = z.object({checkpointEvery: z.number().int().min(0).max(5000).optional(),sampleEvery: z.number().int().min(0).max(5000).optional(),samplePrompt: z.string().max(2000).optional(),+ // Per-run frozen-base overrides (issue #1321), mflux runtime only. `baseQuant`+ // picks the quant of the frozen base — 16 = unquantized bf16, 8/4 = QLoRA+ // bit-width — letting a run opt into a heavier/lighter base than the+ // memory-derived default without a code change. `lowRam` toggles the on-disk+ // latent-cache spill. Both absent → the deriveMfluxMemoryConfig tier; an+ // explicit value still cannot exceed the LORA_TRAIN_MAX_QUANT_BITS cap.+ baseQuant: z.union([z.literal(4), z.literal(8), z.literal(16)]).optional(),+ lowRam: z.boolean().optional(),});// LoRA training settings slice (`settings.loraTraining`) — vision-captiondiff --git a/server/services/loraTraining/runtimes.js b/server/services/loraTraining/runtimes.jsindex a168ad84cd..8021268ff5 100644--- a/server/services/loraTraining/runtimes.js+++ b/server/services/loraTraining/runtimes.js@@ -100,22 +100,41 @@ const MFLUX_SCHED = Object.freeze({ steps: 40, guidance: 1.0, timestepLow: 25, t* 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.+ *+ * 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+ * without a code change (exposed as the `baseQuant`/`lowRam` request params).+ * `quantize` present — including `null` (bf16) — replaces the derived tier;+ * `low_ram` boolean replaces the derived spill setting; absent keys keep the+ * memory-derived value. The `LORA_TRAIN_MAX_QUANT_BITS` cap still applies AFTER+ * the override, so a per-run opt-in can never exceed a box's hard safety+ * ceiling (the cap only ever makes the base lighter, never heavier).*/-export function deriveMfluxMemoryConfig(totalMemGb) {+export function deriveMfluxMemoryConfig(totalMemGb, overrides = {}) {const gb = Number.isFinite(totalMemGb) ? totalMemGb : 0; // unknown → most conservative- const base = gb >= 96+ const result = gb >= 96? { quantize: null, low_ram: true }: 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".+ if (Object.prototype.hasOwnProperty.call(overrides, 'quantize')) {+ result.quantize = overrides.quantize;+ }+ if (typeof overrides.low_ram === 'boolean') {+ result.low_ram = overrides.low_ram;+ }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 };+ // (more aggressive) is kept. Lower bits = smaller = stays. Applied last so+ // it clamps the post-override value, not just the memory tier.+ const curBits = result.quantize == null ? 16 : result.quantize;+ if (curBits > capRaw) result.quantize = capRaw;}- return base;+ return result;}/**@@ -213,7 +232,15 @@ export function buildMfluxTrainConfig({const requestedSaveFrequency = p.checkpointEvery > 0 ? p.checkpointEvery : totalSteps;const maxSaveInterval = Math.max(1, Math.ceil(totalSteps / MFLUX_MIN_CHECKPOINTS));const saveFrequency = Math.min(requestedSaveFrequency, maxSaveInterval);- const memory = deriveMfluxMemoryConfig(totalMemGb);+ // Per-run base-tier overrides (issue #1321): `baseQuant` lets a run pick the+ // frozen-base quant — 16 = unquantized bf16 (mflux `quantize: null`), 8/4 =+ // QLoRA bit-width — and `lowRam` toggles the on-disk latent-cache spill,+ // independent of the memory-derived default. mflux-only knobs (the torch+ // runtime always trains the bf16 base); absent → memory-derived tier.+ const memoryOverride = {};+ if (p.baseQuant != null) memoryOverride.quantize = p.baseQuant >= 16 ? null : p.baseQuant;+ if (typeof p.lowRam === 'boolean') memoryOverride.low_ram = p.lowRam;+ const memory = deriveMfluxMemoryConfig(totalMemGb, memoryOverride);return {model: mfluxModel,data: dataDir,diff --git a/server/services/loraTraining/runtimes.test.js b/server/services/loraTraining/runtimes.test.jsindex 618c7d4b05..a360233985 100644--- a/server/services/loraTraining/runtimes.test.js+++ b/server/services/loraTraining/runtimes.test.js@@ -153,6 +153,48 @@ describe('buildMfluxTrainConfig', () => {else process.env.LORA_TRAIN_MAX_QUANT_BITS = prev;}});++ it('per-run overrides replace the memory-derived tier (issue #1321)', () => {+ // quantize override wins over the budget tier — heavier (bf16) on a 48 GB+ // 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 });+ // 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+ // mistaken for "absent" — distinguishes intentional-empty from absent.+ expect(deriveMfluxMemoryConfig(48, { quantize: null }).quantize).toBeNull();+ });++ it('LORA_TRAIN_MAX_QUANT_BITS clamps a per-run override (cap is the ceiling)', () => {+ const prev = process.env.LORA_TRAIN_MAX_QUANT_BITS;+ try {+ // A run asks for bf16 (heaviest) but the install caps at 8-bit — the cap+ // wins, so a per-run opt-in can never breach the box's panic guard.+ process.env.LORA_TRAIN_MAX_QUANT_BITS = '8';+ expect(deriveMfluxMemoryConfig(48, { quantize: null })).toEqual({ quantize: 8, low_ram: true });+ // A run can still go LIGHTER than the cap.+ expect(deriveMfluxMemoryConfig(128, { quantize: 4 })).toEqual({ quantize: 4, low_ram: true });+ } finally {+ if (prev === undefined) delete process.env.LORA_TRAIN_MAX_QUANT_BITS;+ else process.env.LORA_TRAIN_MAX_QUANT_BITS = prev;+ }+ });++ it('maps baseQuant/lowRam request params into the mflux config (issue #1321)', () => {+ // baseQuant 16 → unquantized bf16 (mflux quantize: null), overriding the+ // null-budget tier (which would otherwise be 4-bit).+ const bf16 = buildMfluxTrainConfig({ ...base, params: { baseQuant: 16, lowRam: false } });+ expect(bf16.quantize).toBeNull();+ expect(bf16.low_ram).toBe(false);+ // baseQuant 8/4 map straight through as the QLoRA bit-width.+ expect(buildMfluxTrainConfig({ ...base, params: { baseQuant: 8 } }).quantize).toBe(8);+ expect(buildMfluxTrainConfig({ ...base, totalMemGb: 128, params: { baseQuant: 4 } }).quantize).toBe(4);+ // No override → memory-derived tier is untouched (128 GB → bf16).+ expect(buildMfluxTrainConfig({ ...base, totalMemGb: 128 }).quantize).toBeNull();+ });});describe('buildMfluxTrainArgs / buildFlux2TrainArgs', () => {