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.

Images: refuse Flux base / max shift values that build NaN sigmas (#14613)

Daniel Hanef990d2e444a
diff --git a/studio/backend/core/inference/diffusion_flow_shift.py b/studio/backend/core/inference/diffusion_flow_shift.py
index 4c954b72aa0..f6db66a0c8c 100644
--- a/studio/backend/core/inference/diffusion_flow_shift.py
+++ b/studio/backend/core/inference/diffusion_flow_shift.py
@@ -19,6 +19,11 @@ def comfy_sigmas_enabled() -> bool:
return os.environ.get(COMFY_SIGMAS_ENV, "1").strip().lower() not in ("0", "false", "no", "off")
+# The scheduler's float32 s*t / (1 + (s - 1)*t): e^mu past 80 overflows to NaN sigmas; below -5, 1 + (s - 1) cancels
+# (sigma_max already 1.07 at mu -8, inf at -20).
+FLUX_MU_RANGE = (-5.0, 80.0)
+
+
def flux_mu_shift(mu: float) -> float:
"""Static shift equal to ComfyUI's ModelSamplingFlux at a fixed ``mu``:
e^mu / (e^mu + 1/t - 1) == s*t / (1 + (s - 1)*t) for s = e^mu, at every resolution."""
@@ -215,7 +220,13 @@ def requested_flow_shift(
raise ValueError(f"Base and max shift must be between 0 and {SHIFT_MAX:g}.")
if not width or not height:
raise ValueError("Base / max shift needs the output width and height.")
- return flux_mu_shift(comfy_model_sampling_flux_mu(hi, lo, int(width), int(height)))
+ mu = comfy_model_sampling_flux_mu(hi, lo, int(width), int(height))
+ if not FLUX_MU_RANGE[0] <= mu <= FLUX_MU_RANGE[1]:
+ raise ValueError(
+ f"Base {lo:g} / max shift {hi:g} at {int(width)}x{int(height)} gives no usable noise "
+ "schedule; bring them closer to the defaults (0.5 / 1.15)."
+ )
+ return flux_mu_shift(mu)
def scheduler_with_flow_shift(scheduler: Any, shift: float) -> Any:
diff --git a/studio/backend/tests/test_diffusion_shift_override.py b/studio/backend/tests/test_diffusion_shift_override.py
index 1f52ab1a930..153281487b9 100644
--- a/studio/backend/tests/test_diffusion_shift_override.py
+++ b/studio/backend/tests/test_diffusion_shift_override.py
@@ -142,6 +142,8 @@ def test_flux_node_resolves_mu_at_the_output_size():
(SHIFT_NODE_SD3, {"shift": float("nan")}, "above 0"),
(SHIFT_NODE_FLUX, {"shift": 3.0}, "base / max"),
(SHIFT_NODE_FLUX, {"max_shift": -1.0}, "between 0"),
+ (SHIFT_NODE_FLUX, {"base_shift": 89.0, "max_shift": 89.0}, "no usable"),
+ (SHIFT_NODE_FLUX, {"base_shift": 0.0, "max_shift": 100.0}, "no usable"),
],
)
def test_invalid_requests_are_refused(node, kwargs, needle):
@@ -149,6 +151,33 @@ def test_invalid_requests_are_refused(node, kwargs, needle):
requested_flow_shift(node, width = 1024, height = 1024, **kwargs)
+ "hi, lo, w, h",
+ [
+ (80.0, 80.0, 1024, 1024),
+ (100.0, 0.0, 4096, 4096),
+ (100.0, 0.0, 512, 512),
+ (100.0, 0.0, 128, 128),
+ (0.0, 100.0, 1024, 1216),
+ (0.0, 100.0, 1024, 1056),
+ ],
+)
+def test_extreme_flux_shift_is_refused_or_builds_a_sane_schedule(hi, lo, w, h):
+ resident = _flow_euler(shift = 3.0, use_dynamic_shifting = True, base_shift = 0.5, max_shift = 1.15)
+ try:
+ shift = requested_flow_shift(
+ SHIFT_NODE_FLUX, base_shift = lo, max_shift = hi, width = w, height = h
+ )
+ except ValueError as exc:
+ assert "no usable" in str(exc)
+ return
+ built = scheduler_with_flow_shift(resident, shift)
+ built.set_timesteps(8, device = "cpu")
+ sigmas = built.sigmas.tolist()
+ assert all(0.0 <= x <= 1.0 + 1e-4 for x in sigmas), sigmas
+ assert all(a >= b for a, b in zip(sigmas, sigmas[1:])), sigmas
+
+
def _flow_euler(**config):
diffusers = pytest.importorskip("diffusers")
return diffusers.FlowMatchEulerDiscreteScheduler(**config)