Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Pair the diffusion warmup presets with a scheduler that uses them (#8593)
Vineeth Sai Varikuntla4b18f07226ca
diff --git a/studio/backend/tests/test_diffusion_train_extras.py b/studio/backend/tests/test_diffusion_train_extras.pyindex 2987a73faed..4c1008dc11c 100644--- a/studio/backend/tests/test_diffusion_train_extras.py+++ b/studio/backend/tests/test_diffusion_train_extras.py@@ -238,6 +238,27 @@ def test_flow_families_carry_warmup_presets():assert "lr_warmup_steps" not in FAMILY_TRAIN_DEFAULTS["sdxl"]+# diffusers' get_scheduler returns before it reads num_warmup_steps for these, so a warmup+# preset paired with one of them is silently discarded.+_SCHEDULERS_THAT_IGNORE_WARMUP = {"constant", "piecewise_constant"}+++def test_warmup_presets_survive_into_a_built_config():+ """What /training/diffusion/info advertises has to be constructible as-is.++ test_diffusion_warmup_defaults.py owns the pairing invariant itself. This is the one guard+ it does not give: its own helper filters train_defaults() down to the dataclass fields, so+ a key added to FAMILY_TRAIN_DEFAULTS that DiffusionLoraConfig refuses would pass there and+ still break every client that posts the advertised defaults back verbatim.+ """+ for family, defaults in FAMILY_TRAIN_DEFAULTS.items():+ if not defaults.get("lr_warmup_steps"):+ continue+ cfg = _cfg(**train_defaults(family))+ assert cfg.lr_warmup_steps == defaults["lr_warmup_steps"]+ assert cfg.lr_scheduler not in _SCHEDULERS_THAT_IGNORE_WARMUP++def _cfg(**kw):return DiffusionLoraConfig(base_model = "stabilityai/stable-diffusion-xl-base-1.0",diff --git a/studio/frontend/src/features/images/api.ts b/studio/frontend/src/features/images/api.tsindex 029a996dc6f..cf7e7f5b84d 100644--- a/studio/frontend/src/features/images/api.ts+++ b/studio/frontend/src/features/images/api.ts@@ -655,6 +655,10 @@ export interface DiffusionTrainableFamily {train_steps?: number;train_batch_size?: number;mixed_precision?: "bf16" | "fp16" | "no";+ // The LR ramp, as one pair: a warmup count only ramps under a scheduler that reads it, so+ // the backend advertises both or neither. Absent on a backend older than that pairing.+ lr_scheduler?: string;+ lr_warmup_steps?: number;} | null;vram_note?: string | null;gated?: boolean | null;diff --git a/studio/frontend/src/features/images/train/diffusion-train-lr-schedule.ts b/studio/frontend/src/features/images/train/diffusion-train-lr-schedule.tsnew file mode 100644index 00000000000..6505eb1abf3--- /dev/null+++ b/studio/frontend/src/features/images/train/diffusion-train-lr-schedule.ts@@ -0,0 +1,32 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import type { DiffusionTrainableFamily } from "../api";++/** The LR schedules the Train panel offers. The backend accepts more (cosine_with_restarts,+ * polynomial), so a family naming one of those is dropped rather than seeded into a Select that+ * cannot show it. */+export type LrScheduler = "constant" | "constant_with_warmup" | "cosine" | "linear";++export const LR_SCHEDULERS: readonly LrScheduler[] = [+ "constant",+ "constant_with_warmup",+ "cosine",+ "linear",+];++/** A family's LR ramp, as one unit. The backend pairs `lr_scheduler` with `lr_warmup_steps`+ * because diffusers' `get_scheduler` returns before it reads `num_warmup_steps` under+ * "constant", so a warmup count on its own ramps nothing. Half a pair is therefore dropped:+ * a schedule with no ramp, or a ramp its schedule ignores, is exactly what the pairing exists to+ * prevent. Returns {} for a family that recommends no ramp, so a spread of it leaves the fields+ * undefined rather than null. */+export function lrSchedulePreset(+ defaults: DiffusionTrainableFamily["defaults"],+): { lrScheduler: LrScheduler; lrWarmupSteps: number } | Record<string, never> {+ const scheduler = defaults?.lr_scheduler;+ const warmup = defaults?.lr_warmup_steps;+ if (!LR_SCHEDULERS.includes(scheduler as LrScheduler)) return {};+ if (typeof warmup !== "number" || !Number.isFinite(warmup) || warmup < 0) return {};+ return { lrScheduler: scheduler as LrScheduler, lrWarmupSteps: Math.floor(warmup) };+}diff --git a/studio/frontend/src/features/images/train/diffusion-train-panel.tsx b/studio/frontend/src/features/images/train/diffusion-train-panel.tsxindex 2f723f51a30..5cb0c982679 100644--- a/studio/frontend/src/features/images/train/diffusion-train-panel.tsx+++ b/studio/frontend/src/features/images/train/diffusion-train-panel.tsx@@ -106,13 +106,24 @@ import {resolveDiffusionTrainingBase,} from "./diffusion-train-deploy";import { resolveDiffusionTrainingFacts } from "./diffusion-train-family-facts";+import { type LrScheduler, lrSchedulePreset } from "./diffusion-train-lr-schedule";// The families the Train tab can train, in popularity order; a fallback for an older backend whose /info reports none.type FamilyPreset = {name: string;label: string;base_repos: string[];- defaults: { rank: number; lr: number; resolution: number };+ defaults: {+ rank: number;+ lr: number;+ resolution: number;+ // The family's LR ramp, when it recommends one. Both or neither: a warmup count is inert+ // under "constant", so seeding one without the other reinstates the bug this carries.+ // Only the backend reports them, so the static presets below leave the pair unset rather+ // than keeping a second copy of a pairing that can drift.+ lrScheduler?: LrScheduler;+ lrWarmupSteps?: number;+ };vram_note: string;gated?: boolean;// The note's facts, one per chip. Absent on an older backend, which falls back to vram_note prose.@@ -312,6 +323,9 @@ function mergeFamilies(reported?: DiffusionTrainableFamily[]): FamilyPreset[] {rank: r.defaults?.lora_rank ?? p.defaults.rank,lr: r.defaults?.learning_rate ?? p.defaults.lr,resolution: r.defaults?.resolution ?? p.defaults.resolution,+ // No preset fallback for the ramp: a reported family owns it outright, so a backend that+ // drops its warmup preset drops the ramp here too instead of a stale copy resurrecting it.+ ...lrSchedulePreset(r.defaults),},vram_note: r.vram_note || p.vram_note,gated: r.gated ?? p.gated,@@ -337,6 +351,7 @@ function mergeFamilies(reported?: DiffusionTrainableFamily[]): FamilyPreset[] {rank: r.defaults?.lora_rank ?? 16,lr: r.defaults?.learning_rate ?? 0.0001,resolution: r.defaults?.resolution ?? 768,+ ...lrSchedulePreset(r.defaults),},vram_note: r.vram_note ?? "",gated: r.gated ?? false,@@ -472,9 +487,8 @@ export function DiffusionTrainPanel({// so nothing is spent on disk unless the user asks to survive a crash.const [saveSteps, setSaveSteps] = useState(0);// LR schedule. Warmup only applies to the non-constant schedules; plain "constant" ignores it.- const [lrScheduler, setLrScheduler] = useState<- "constant" | "constant_with_warmup" | "cosine" | "linear"- >("constant");+ // Seeded from the family below, which is where the flow-matching DiTs' short ramp comes from.+ const [lrScheduler, setLrScheduler] = useState<LrScheduler>("constant");const [lrWarmupSteps, setLrWarmupSteps] = useState(0);// Gradient checkpointing trades ~20-30% step time for a large activation-VRAM saving.const [gradCheckpoint, setGradCheckpoint] = useState(true);@@ -490,6 +504,12 @@ export function DiffusionTrainPanel({);// Track whether the user hand-edited the numeric settings; if not, a family change re-seeds them from that family defaults.const settingsDirty = useRef(false);+ // The LR schedule pair tracks its own edits rather than riding on settingsDirty. It is the one+ // setting whose control DISAPPEARS -- "Warmup steps" is hidden under plain "constant" -- so a+ // value carried past a family change is invisible rather than merely stale, and an edit to+ // something unrelated like Steps or Seed would otherwise leave a flow-matching DiT on+ // "constant" with the family's ramp silently never applied.+ const lrScheduleDirty = useRef(false);// Track whether the user hand-picked a base precision; if not, a family change re-seeds it from recommended_precision.const precisionDirty = useRef(false);// Same for the base repo: once the user picks one, only a real family change may re-seed it. `family` is a fresh object after every@@ -623,6 +643,13 @@ export function DiffusionTrainPanel({setRank(family.defaults.rank);setResolution(family.defaults.resolution);}+ // The ramp is seeded from the family or reset with it: a family with no warmup preset goes+ // back to the plain default, or the 20 steps recommended for a flow-matching DiT ride along+ // into SDXL, which never asked for one.+ if (!lrScheduleDirty.current) {+ setLrScheduler(family.defaults.lrScheduler ?? "constant");+ setLrWarmupSteps(family.defaults.lrWarmupSteps ?? 0);+ }// Re-seed the DiT base precision from the family recommendation (unless the user picked one); "auto" is always safe.if (!precisionDirty.current) {const rec = reportedFamily?.recommended_precision;@@ -1224,7 +1251,11 @@ export function DiffusionTrainPanel({value: number,set: (n: number) => void,fallback: number,- extra?: { min?: number; step?: number; hint?: ReactNode },+ // markDirty overrides which dirty flag an edit claims. Only "Warmup steps" passes one: it is+ // seeded from the family like rank/LR/resolution but tracked by lrScheduleDirty, so charging+ // it to the shared flag would mean tuning the ramp froze the OTHER three at the previous+ // family's values. That field is newly visible by default, so this is reachable now.+ extra?: { min?: number; step?: number; hint?: ReactNode; markDirty?: () => void },) => (<div className={fieldClass}><FieldLabel hint={extra?.hint}>{label}</FieldLabel>@@ -1234,7 +1265,8 @@ export function DiffusionTrainPanel({step={extra?.step}value={value}onChange={(e) => {- settingsDirty.current = true;+ if (extra?.markDirty) extra.markDirty();+ else settingsDirty.current = true;// Only fall back when the input parses to NaN; a real 0 is legal for zero-legal fields (Seed, LR warmup steps).const parsed = Number(e.target.value);set(Number.isNaN(parsed) ? fallback : parsed);@@ -1354,7 +1386,12 @@ export function DiffusionTrainPanel({</FieldLabel><Selectvalue={lrScheduler}- onValueChange={(v) => setLrScheduler(v as typeof lrScheduler)}+ onValueChange={(v) => {+ // The family re-seed now writes this field, so without a dirty mark a hand-picked+ // schedule is replaced on the next family switch.+ lrScheduleDirty.current = true;+ setLrScheduler(v as LrScheduler);+ }}><SelectTrigger className={selectClass} aria-label="LR schedule"><SelectValue />@@ -1371,6 +1408,12 @@ export function DiffusionTrainPanel({numberField("Warmup steps", lrWarmupSteps, setLrWarmupSteps, 0, {min: 0,hint: "Ramps the learning rate up over the first steps instead of starting at full size.",+ // The other half of the pair, so an edit claims the pair's flag and only that: a+ // hand-typed ramp length survives the next family change the way the schedule does,+ // without freezing rank/LR/resolution on their way to the new family.+ markDirty: () => {+ lrScheduleDirty.current = true;+ },})}</div>diff --git a/studio/frontend/tests/diffusion-train-warmup-preset.test.ts b/studio/frontend/tests/diffusion-train-warmup-preset.test.tsnew file mode 100644index 00000000000..f8f553fc943--- /dev/null+++ b/studio/frontend/tests/diffusion-train-warmup-preset.test.ts@@ -0,0 +1,132 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// The six flow-matching DiT families recommend a 20-step LR ramp, and the backend now pairs that+// count with `constant_with_warmup` because diffusers' get_scheduler returns before it reads+// num_warmup_steps under plain "constant". The Train panel is where that recommendation has to+// land: it seeds its own state from the family and always sends lr_scheduler + lr_warmup_steps+// explicitly, so a pair it never reads is a pair the primary training flow never applies.+// mergeFamilies and the seeding effect are inline in the panel, so the wiring is asserted against+// the source the same way the batch cap is in diffusion-train-batch-cap.test.ts; the pair's+// normalization lives in its own module and is exercised directly.++import assert from "node:assert/strict";+import { readFile } from "node:fs/promises";+import test from "node:test";++import {+ LR_SCHEDULERS,+ lrSchedulePreset,+} from "../src/features/images/train/diffusion-train-lr-schedule.ts";++const source = await readFile(+ new URL("../src/features/images/train/diffusion-train-panel.tsx", import.meta.url),+ "utf8",+);++test("a family that recommends a ramp carries both halves of it", () => {+ assert.deepEqual(+ lrSchedulePreset({+ lora_rank: 16,+ learning_rate: 0.0001,+ resolution: 512,+ lr_scheduler: "constant_with_warmup",+ lr_warmup_steps: 20,+ }),+ { lrScheduler: "constant_with_warmup", lrWarmupSteps: 20 },+ );+});++test("a family that recommends none contributes nothing to seed", () => {+ // sdxl / z-image / krea-2: no warmup preset, so the panel keeps its own "constant" default.+ assert.deepEqual(+ lrSchedulePreset({ lora_rank: 16, learning_rate: 0.0001, resolution: 1024 }),+ {},+ );+ assert.deepEqual(lrSchedulePreset(null), {});+ assert.deepEqual(lrSchedulePreset(undefined), {});+});++test("half a pair is dropped rather than seeded", () => {+ // A warmup count with no scheduler is the bug the backend pairing fixes: under "constant" it+ // ramps nothing. Seeding it alone would put the count back in the UI with the same outcome.+ assert.deepEqual(lrSchedulePreset({ lr_warmup_steps: 20 }), {});+ // And a scheduler with no count would advertise a ramp of zero steps.+ assert.deepEqual(lrSchedulePreset({ lr_scheduler: "constant_with_warmup" }), {});+});++test("a scheduler the panel cannot show is not seeded into its Select", () => {+ // The backend's Literal is wider than the four options the panel offers. Seeding one of the+ // others leaves the Select on a value with no item, which renders blank.+ for (const name of ["cosine_with_restarts", "polynomial", "", "linear "]) {+ assert.deepEqual(lrSchedulePreset({ lr_scheduler: name, lr_warmup_steps: 20 }), {});+ }+ for (const name of LR_SCHEDULERS) {+ assert.deepEqual(lrSchedulePreset({ lr_scheduler: name, lr_warmup_steps: 20 }), {+ lrScheduler: name,+ lrWarmupSteps: 20,+ });+ }+});++test("a warmup count that is not a usable step number is dropped", () => {+ for (const warmup of [-1, Number.NaN, Number.POSITIVE_INFINITY]) {+ assert.deepEqual(+ lrSchedulePreset({ lr_scheduler: "constant_with_warmup", lr_warmup_steps: warmup }),+ {},+ );+ }+ // The field is an integer step count on the way out; a float would be sent as typed.+ assert.deepEqual(+ lrSchedulePreset({ lr_scheduler: "constant_with_warmup", lr_warmup_steps: 20.7 }),+ { lrScheduler: "constant_with_warmup", lrWarmupSteps: 20 },+ );+});++test("mergeFamilies carries the reported ramp instead of narrowing it away", () => {+ // Both merge arms: the preset-matched family and the backend-only one that goes last.+ assert.equal(source.match(/\.\.\.lrSchedulePreset\(r\.defaults\),/g)?.length, 2);+ // No preset fallback for the ramp, unlike rank/lr/resolution: a reported family owns it, so a+ // backend that drops its warmup preset drops the ramp here rather than a stale copy of it.+ assert.doesNotMatch(source, /lrScheduler:\s*r\.defaults\?\.lr_scheduler\s*\?\?\s*p\./);+});++test("the family re-seed writes the ramp, and resets it for a family without one", () => {+ assert.match(source, /setLrScheduler\(family\.defaults\.lrScheduler \?\? "constant"\);/);+ assert.match(source, /setLrWarmupSteps\(family\.defaults\.lrWarmupSteps \?\? 0\);/);+});++test("an edit to an unrelated setting cannot suppress the family ramp", () => {+ // settingsDirty is one flag over every numeric control, Steps and Seed included. Gating the+ // ramp on it meant typing a step count and then switching to a flow-matching DiT left the+ // panel on "constant" with the Warmup steps field hidden, so the ramp this panel exists to+ // seed silently never ran. The pair gets its own flag, outside the settingsDirty block.+ assert.match(source, /const lrScheduleDirty = useRef\(false\);/);+ assert.match(+ source,+ /\}\s*\n\s*\/\/[\s\S]{0,400}?if \(!lrScheduleDirty\.current\) \{\s*\n\s*setLrScheduler\(/,+ );+ // And it is NOT re-gated on settingsDirty anywhere.+ assert.doesNotMatch(source, /settingsDirty\.current = true;\s*\n\s*setLrScheduler\(/);+});++test("a hand-edited ramp survives a family switch", () => {+ // Both halves mark the pair dirty, or the re-seed replaces the user's pick on the next switch.+ assert.match(+ source,+ /onValueChange=\{\(v\) => \{[\s\S]{0,400}?lrScheduleDirty\.current = true;\s*\n\s*setLrScheduler\(v as LrScheduler\);/,+ );+ assert.match(+ source,+ /markDirty: \(\) => \{\s*\n\s*lrScheduleDirty\.current = true;\s*\n\s*\},\s*\n\s*\}\)\}/,+ );+});++test("tuning the ramp does not freeze the other family-seeded settings", () => {+ // "Warmup steps" is newly visible by default for the six flow families, so it now reaches+ // numberField's dirty mark in normal use. Charging it to the shared settingsDirty would mean+ // typing a ramp length pinned rank/LR/resolution to the previous family: switch flux.1 ->+ // qwen-image afterwards and the LR stays 1e-4 instead of re-seeding to 5e-5.+ assert.match(source, /if \(extra\?\.markDirty\) extra\.markDirty\(\);\s*\n\s*else settingsDirty\.current = true;/);+ assert.match(source, /markDirty\?: \(\) => void/);+});