Skip to content

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.

Fix silent lr_warmup_steps no-op under the default constant scheduler (#8464)

Eoin-Houstoun6a0a5b627b2d
diff --git a/studio/backend/core/training/diffusion_train_common.py b/studio/backend/core/training/diffusion_train_common.py
index 70d5c3238ff..f9d3310c329 100644
--- a/studio/backend/core/training/diffusion_train_common.py
+++ b/studio/backend/core/training/diffusion_train_common.py
@@ -498,12 +498,20 @@ def get_trainer(family: str) -> Callable[..., str]:
# Per-family training defaults surfaced by the Train UI: starting points, not hard limits. Families absent here fall back to the DiffusionLoraConfig defaults.
FAMILY_TRAIN_DEFAULTS: dict[str, dict[str, Any]] = {
"sdxl": {"lora_rank": 16, "learning_rate": 1e-4, "resolution": 1024},
- # Warmup defaults: a short LR ramp keeps the first adapter updates from overshooting on the big flow-matching DiTs.
- "flux.1": {"lora_rank": 16, "learning_rate": 1e-4, "resolution": 512, "lr_warmup_steps": 20},
+ # Plain "constant" ignores lr_warmup_steps, so warmup defaults must use a
+ # warmup-capable scheduler.
+ "flux.1": {
+ "lora_rank": 16,
+ "learning_rate": 1e-4,
+ "resolution": 512,
+ "lr_scheduler": "constant_with_warmup",
+ "lr_warmup_steps": 20,
+ },
"qwen-image": {
"lora_rank": 16,
"learning_rate": 5e-5,
"resolution": 512,
+ "lr_scheduler": "constant_with_warmup",
"lr_warmup_steps": 20,
},
"z-image": {"lora_rank": 16, "learning_rate": 1e-4, "resolution": 768},
@@ -514,12 +522,14 @@ FAMILY_TRAIN_DEFAULTS: dict[str, dict[str, Any]] = {
"lora_rank": 16,
"learning_rate": 1e-4,
"resolution": 512,
+ "lr_scheduler": "constant_with_warmup",
"lr_warmup_steps": 20,
},
"flux.2-dev": {
"lora_rank": 16,
"learning_rate": 1e-4,
"resolution": 512,
+ "lr_scheduler": "constant_with_warmup",
"lr_warmup_steps": 20,
},
# LTX-2, from Lightricks' own ltx-trainer LoRA configs: rank/alpha 32, lr 1e-4. The
@@ -529,6 +539,7 @@ FAMILY_TRAIN_DEFAULTS: dict[str, dict[str, Any]] = {
"lora_rank": 32,
"learning_rate": 1e-4,
"resolution": 512,
+ "lr_scheduler": "constant_with_warmup",
"lr_warmup_steps": 20,
},
# MiniMax-H3. ``resolution`` is the canvas SHORT EDGE, and 768 is the one the released
@@ -540,6 +551,7 @@ FAMILY_TRAIN_DEFAULTS: dict[str, dict[str, Any]] = {
"lora_rank": 16,
"learning_rate": 1e-4,
"resolution": 768,
+ "lr_scheduler": "constant_with_warmup",
"lr_warmup_steps": 20,
"train_batch_size": 1,
},
@@ -1047,6 +1059,16 @@ class DiffusionLoraConfig:
f"lr_scheduler must be one of {', '.join(sorted(_LR_SCHEDULERS))}; "
f"got {self.lr_scheduler!r}"
)
+ # Do not rewrite the scheduler here: it is part of checkpoint identity, so doing so would
+ # make legacy runs with ("constant", warmup > 0) impossible to resume.
+ try:
+ lr_warmup_steps = int(self.lr_warmup_steps or 0)
+ except (TypeError, ValueError) as exc:
+ raise ValueError(
+ f"lr_warmup_steps must be a whole number, got {self.lr_warmup_steps!r}"
+ ) from exc
+ if lr_warmup_steps < 0:
+ raise ValueError("lr_warmup_steps must be >= 0")
if not 1 <= int(self.cache_variants) <= 16:
raise ValueError("cache_variants must be between 1 and 16")
# Checkpointing knobs. Rejected here, before the route evicts resident GPU models, rather than deep in the loop.
@@ -1228,6 +1250,7 @@ class DiffusionLoraConfig:
return replace(
self,
learning_rate = learning_rate,
+ lr_warmup_steps = lr_warmup_steps,
lora_alpha = alpha,
lora_target_modules = targets,
max_grad_norm = float(self.max_grad_norm),
diff --git a/studio/backend/tests/test_diffusion_warmup_defaults.py b/studio/backend/tests/test_diffusion_warmup_defaults.py
new file mode 100644
index 00000000000..258a905281c
--- /dev/null
+++ b/studio/backend/tests/test_diffusion_warmup_defaults.py
@@ -0,0 +1,82 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""Tests for diffusion learning-rate warmup defaults and resume compatibility."""
+
+from __future__ import annotations
+
+import pytest
+
+from core.training.diffusion_train_common import (
+ FAMILY_TRAIN_DEFAULTS,
+ DiffusionLoraConfig,
+ train_defaults,
+)
+
+# Derive this list so every family with positive warmup is covered.
+WARMUP_FAMILIES = [
+ family
+ for family, defaults in FAMILY_TRAIN_DEFAULTS.items()
+ if int(defaults.get("lr_warmup_steps", 0) or 0) > 0
+]
+NO_WARMUP_FAMILIES = [family for family in FAMILY_TRAIN_DEFAULTS if family not in WARMUP_FAMILIES]
+
+
+def _cfg(family, **overrides):
+ d = train_defaults(family)
+ kwargs = {k: v for k, v in d.items() if k in DiffusionLoraConfig.__dataclass_fields__}
+ kwargs.update(overrides)
+ return DiffusionLoraConfig(
+ base_model = f"stub/{family}",
+ data_dir = "/tmp/data",
+ output_dir = "/tmp/out",
+ model_family = family,
+ **kwargs,
+ )
+
+
+def test_warmup_families_advertise_a_warmup_capable_scheduler():
+ assert WARMUP_FAMILIES, "no family advertises lr_warmup_steps; the invariant tests nothing"
+ for family in WARMUP_FAMILIES:
+ d = FAMILY_TRAIN_DEFAULTS[family]
+ assert (
+ d.get("lr_scheduler") == "constant_with_warmup"
+ ), f"{family} advertises lr_warmup_steps but not a scheduler that realizes it"
+
+
+def test_no_warmup_families_are_untouched():
+ for family in NO_WARMUP_FAMILIES:
+ d = FAMILY_TRAIN_DEFAULTS[family]
+ assert "lr_warmup_steps" not in d
+ assert "lr_scheduler" not in d
+ cfg = _cfg(family).normalized()
+ assert cfg.lr_scheduler == "constant"
+ assert cfg.lr_warmup_steps == 0
+
+
+def test_normalized_leaves_the_requested_scheduler_alone():
+ for scheduler in ("constant", "constant_with_warmup", "cosine", "linear"):
+ cfg = _cfg("sdxl", lr_scheduler = scheduler, lr_warmup_steps = 20).normalized()
+ assert cfg.lr_scheduler == scheduler
+ assert cfg.lr_warmup_steps == 20
+ cfg = _cfg("sdxl", lr_scheduler = "constant", lr_warmup_steps = 0).normalized()
+ assert cfg.lr_scheduler == "constant"
+
+
+def test_a_constant_schedule_with_warmup_still_resumes_its_own_bundle():
+ """Scheduler normalization must preserve legacy checkpoint identity."""
+ from core.training.diffusion_checkpoint import CheckpointIdentity, identity_for_config
+
+ cfg = _cfg("sdxl", lr_scheduler = "constant", lr_warmup_steps = 20).normalized()
+ incoming = identity_for_config(cfg)
+ assert incoming.lr_scheduler == "constant"
+ stored = CheckpointIdentity.from_dict(
+ {**incoming.as_dict(), "lr_scheduler": "constant", "lr_warmup_steps": 20}
+ )
+ assert stored is not None
+ assert stored.mismatch_reason(incoming) is None
+
+
+def test_negative_warmup_is_rejected():
+ with pytest.raises(ValueError, match = "lr_warmup_steps"):
+ _cfg("sdxl", lr_warmup_steps = -1).normalized()