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
Studio: use ComfyUI's default settings for FLUX.1, Qwen-Image, Z-Image, Ideogram 4, Wan2.2 and HunyuanVideo-1.5 (#12516)
Daniel Hanfd2522bfc599
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.pyindex 3921b44d057..0def3f744e2 100644--- a/studio/backend/core/inference/diffusion.py+++ b/studio/backend/core/inference/diffusion.py@@ -240,6 +240,15 @@ from .diffusion_precision import (torchao_quantize_importable,)from .diffusion_te_prequant import te_prequant_pipe_kwargs+from .diffusion_flow_shift import apply_comfy_flow_shift+from .diffusion_text_length import (+ IDEOGRAM4_COMFY_GUIDANCE,+ IDEOGRAM4_COMFY_MU,+ IDEOGRAM4_COMFY_STD,+ ideogram4_comfy_guidance_schedule,+ flux_t5_kwarg,+ true_cfg_needs_empty_negative,+)from .diffusion_denoiser_prequant import (DENOISER_COMPONENT,PIPELINE_SEED_DECLINED,@@ -6987,6 +6996,8 @@ class DiffusionBackend:)self._raise_if_load_cancelled(_load_token)+ # Sample at ComfyUI's static sigma shift where the shipped scheduler differs (before from_pipe copies it).+ apply_comfy_flow_shift(pipe, getattr(fam, "comfy_flow_shift", None), logger)# Before the speed optims so their decode compile lands inside the non-finite check; `off` keeps fp32.vae_fp16 = str(speed_mode or ""@@ -9405,7 +9416,20 @@ class DiffusionBackend:if steps == 48 and abs(float(guidance) - 7.0) < 1e-6:kwargs.pop(state.family.cfg_kwarg, None)else:- kwargs["guidance_schedule"] = None+ # Otherwise ComfyUI's template: its "Default" schedule (mu 0.0, std 1.75; the card taper above+ # keeps the pipeline's mu 0 / std 1.5) and, at the default guidance 7, its CFG override to 3+ # over the last 30% of sampling, as a per-step schedule. Any other guidance stays constant.+ if "mu" in call_params:+ kwargs["mu"] = IDEOGRAM4_COMFY_MU+ if "std" in call_params:+ kwargs["std"] = IDEOGRAM4_COMFY_STD+ if abs(float(guidance) - IDEOGRAM4_COMFY_GUIDANCE) < 1e-6:+ kwargs.pop(state.family.cfg_kwarg, None)+ kwargs["guidance_schedule"] = ideogram4_comfy_guidance_schedule(+ steps, width, height+ )+ else:+ kwargs["guidance_schedule"] = Noneif state.family.name == LUMINA2_FAMILY_NAME and "cfg_trunc_ratio" in call_params:# Lumina 2's card recipe truncates the CFG double-forward to the first quarter# (cfg_trunc_ratio=0.25); the 1.0 default oversaturates.@@ -9437,6 +9461,13 @@ class DiffusionBackend:kwargs["height"] = ihif negative_prompt and "negative_prompt" in call_params:kwargs["negative_prompt"] = negative_prompt+ elif "negative_prompt" in call_params and true_cfg_needs_empty_negative(+ state.family.cfg_kwarg, guidance+ ):+ # Qwen-Image style pipelines run true CFG only when a negative is PRESENT, so a blank negative+ # silently dropped CFG while the UI showed guidance 4. ComfyUI encodes an empty negative and+ # applies CFG; do the same.+ kwargs["negative_prompt"] = ""if workflow == "controlnet" and control_pil is not None:# CN pipeline takes the control map + scale; guidance start/end bound its step range. Every kwarg# is signature-gated.@@ -9635,6 +9666,11 @@ class DiffusionBackend:chunk_kwargs["negative_prompt"] = [chunk_kwargs["negative_prompt"]] * len(chunk)+ # FLUX.1 T5 length as ComfyUI pads it: 256 for prompts up to 256 tokens (diffusers pads every+ # prompt to 512); longer prompts keep the 512 bucket. Per chunk, since a prompts list varies.+ t5_len = flux_t5_kwarg(state.family.name, pipe, call_params, chunk_kwargs)+ if t5_len is not None:+ chunk_kwargs["max_sequence_length"] = t5_len# A step cache keys residuals on the cond/uncond context, which a graph key# cannot see. Per chunk because an AUTO decision is re-taken per generation.if state.cuda_graphs:diff --git a/studio/backend/core/inference/diffusion_families.py b/studio/backend/core/inference/diffusion_families.pyindex 8889e1158e0..21bc614705e 100644--- a/studio/backend/core/inference/diffusion_families.py+++ b/studio/backend/core/inference/diffusion_families.py@@ -113,6 +113,9 @@ class DiffusionFamily:max_output_pixels: int = 2048 * 2048# Accepted condition-image preprocessing resolutions (square side, by area); empty = no such control.reference_resolutions: tuple[int, ...] = field(default_factory = tuple)+ # Static sigma shift ComfyUI samples this family with; the loader rebuilds the scheduler at it. None = keep the+ # shipped scheduler.+ comfy_flow_shift: Optional[float] = None# Activation-guard cost of one condition pixel relative to one output pixel.condition_pixel_weight: float = 1.0# Extra lowercased substrings (besides ``name``) that map a repo id here.@@ -325,6 +328,7 @@ _FAMILIES: tuple[DiffusionFamily, ...] = (# Qwen instruction editing: the 2511 checkpoint ships as QwenImageEditPlusPipeline. Specific aliases first so# detect_family prefers this over "qwen-image".name = "qwen-image-edit",+ comfy_flow_shift = 3.1, # ComfyUI ModelSamplingAuraFlow 3.1 (Qwen-Image-Edit 2511 template)pipeline_class = "QwenImageEditPlusPipeline",transformer_class = "QwenImageTransformer2DModel",base_repo = "Qwen/Qwen-Image-Edit-2511",@@ -342,6 +346,7 @@ _FAMILIES: tuple[DiffusionFamily, ...] = (),DiffusionFamily(name = "qwen-image",+ comfy_flow_shift = 3.1, # ComfyUI ModelSamplingAuraFlow 3.1 (Qwen-Image templates)pipeline_class = "QwenImagePipeline",transformer_class = "QwenImageTransformer2DModel",base_repo = "Qwen/Qwen-Image",@@ -488,6 +493,7 @@ _FAMILIES: tuple[DiffusionFamily, ...] = (),DiffusionFamily(name = "z-image",+ comfy_flow_shift = 3.0, # ComfyUI shift 3 for Turbo and base (Turbo already ships 3.0)pipeline_class = "ZImagePipeline",transformer_class = "ZImageTransformer2DModel",base_repo = "Tongyi-MAI/Z-Image-Turbo",@@ -1132,29 +1138,37 @@ def prefer_ungated_mirror(# Default (steps, guidance) per model for callers that cannot pass them. Matched by substring, most specific first;# same values as the UI MODEL_DEFAULTS table, keep in sync._GENERATION_DEFAULTS: tuple[tuple[str, int, float], ...] = (- ("z-image-turbo", 9, 0.0),- # FLUX.1 Krea dev is a FLUX.1-dev finetune, NOT a Krea-2: 28 steps at guidance 4.5. Must precede the generic- # "krea" key.- ("flux.1-krea", 28, 4.5),+ # Values follow ComfyUI's official templates for the same model (our baseline).+ # Z-Image-Turbo: 8 steps (ComfyUI runs 8 sampler steps; diffusers runs one forward per step).+ ("z-image-turbo", 8, 0.0),+ # FLUX.1 Krea dev is a FLUX.1-dev finetune, NOT a Krea-2: 20 steps at the FLUX guidance default 3.5, as ComfyUI.+ # Must precede the generic "krea" key.+ ("flux.1-krea", 20, 3.5),# Krea 2 Raw (undistilled): 52 steps / guidance 3.5. Must precede the generic "krea" key.("krea-2-raw", 52, 3.5),# Krea 2 Turbo (distilled): 8 steps, no CFG. "krea" then covers Turbo and other krea ids but Raw.("krea", 8, 0.0),("flux.1-schnell", 4, 0.0),- ("kontext", 28, 2.5), # editing: before the generic flux.1- ("flux.1", 28, 3.5),- # The undistilled base variants need their model-card 50-step CFG recipe. Keep this before the generic distilled- # key, which covers both 4B and 9B 4-step checkpoints.- ("flux.2-klein-base", 50, 4.0),+ ("kontext", 20, 2.5), # editing: before the generic flux.1+ ("flux.1", 20, 3.5),+ # The undistilled base variants run real CFG: 20 steps at CFG 5, as ComfyUI. Keep this before the generic+ # distilled key, which covers both 4B and 9B 4-step checkpoints.+ ("flux.2-klein-base", 20, 5.0),("flux.2-klein", 4, 1.0),- ("flux.2-dev", 28, 4.0), # full (non-distilled)- # Qwen-Image-2.1: 40 steps, no guidance. Before the generic qwen-image key.- ("qwen-image-2.1", 40, 1.0),- ("qwen-image-21", 40, 1.0),- ("qwen_image_21", 40, 1.0),- ("qwenimage21", 40, 1.0),+ ("flux.2-dev", 20, 4.0), # full (non-distilled)+ # Qwen-Image-2.1: 25 steps, no guidance. Before the generic qwen-image key.+ ("qwen-image-2.1", 25, 1.0),+ ("qwen-image-21", 25, 1.0),+ ("qwen_image_21", 25, 1.0),+ ("qwenimage21", 25, 1.0),+ # Qwen-Image-Edit 2511: 40 steps at CFG 4. Before the generic qwen-image key.+ ("qwen-image-edit", 40, 4.0),+ # Qwen-Image-2512: 50 steps at CFG 4 (its own ComfyUI template; the original Qwen-Image runs 20).+ ("qwen-image-2512", 50, 4.0),("qwen-image", 20, 4.0),- ("z-image", 20, 4.0),+ # Z-Image base: 25 steps at ComfyUI CFG 4. diffusers Z-Image computes pos + g * (pos - neg), so its g is+ # ComfyUI's cfg - 1.+ ("z-image", 25, 3.0),# Lumina Image 2.0 card: 50 steps, guidance 4 (plus cfg_trunc_ratio 0.25, which the loader passes itself).("lumina", 50, 4.0),# HunyuanImage 2.1 card: 50 steps; guidance feeds distilled_guidance_scale, while real CFG runs inside the@@ -1164,13 +1178,13 @@ _GENERATION_DEFAULTS: tuple[tuple[str, int, float], ...] = (("hidream-i1-dev", 28, 0.0),("hidream-i1-fast", 16, 0.0),("hidream", 50, 5.0),- # Ideogram 4 card: 48 steps, guidance 7 (its schedule tapers the last 3 steps; the loader keeps that taper at- # these defaults).- ("ideogram", 48, 7.0),+ # Ideogram 4: ComfyUI's Default preset, 20 steps at guidance 7 (3 once sigma <= 0.3), logit-normal mu 0.0 / std 1.75.+ # An explicit 48 steps at 7 still runs the card's tapered schedule.+ ("ideogram", 20, 7.0),# SDXL: Turbo distilled; base wants ~30 steps + CFG ~7. "sdxl-turbo" precedes "sdxl".("sdxl-turbo", 3, 0.0),- ("stable-diffusion-xl", 30, 7.0),- ("sdxl", 30, 7.0),+ ("stable-diffusion-xl", 25, 7.0),+ ("sdxl", 25, 7.0),)# Unrecognised model: distilled few-step / no-CFG shape, matching the UI fallback._GENERATION_DEFAULT_FALLBACK = (9, 0.0)diff --git a/studio/backend/core/inference/diffusion_flow_shift.py b/studio/backend/core/inference/diffusion_flow_shift.pynew file mode 100644index 00000000000..e12d3cb0c2b--- /dev/null+++ b/studio/backend/core/inference/diffusion_flow_shift.py@@ -0,0 +1,64 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Static sigma shift a family samples with in ComfyUI, applied to the loaded scheduler. No+torch/diffusers imports: it only rebuilds ``pipe.scheduler`` from its own config.++Several shipped schedulers shift sigmas differently from ComfyUI's defaults for the same model:+Qwen-Image resolves a resolution-dependent exponential shift (about 2.0 at 1024 px) and stretches+the tail to 0.02 where ComfyUI samples a constant 3.1, Z-Image base ships 6.0 against 3.0, Wan2.2+ships 5.0 / 3.0 against 8 / 5 and HunyuanVideo-1.5 5.0 / 9.0 against 7. A flow-matching shift ``s``+maps sigma to ``s * sigma / (1 + (s - 1) * sigma)`` in both, so setting the static shift (and+dropping the dynamic shift and terminal stretch) reproduces ComfyUI's schedule.+"""++from __future__ import annotations++from typing import Any, Optional+++def flow_shift_overrides(config: Any, shift: float) -> Optional[dict]:+ """Scheduler config overrides that sample at static ``shift``, or None when the scheduler has+ no flow shift Studio knows how to set."""+ try:+ keys = set(config.keys())+ except Exception: # noqa: BLE001 - an exotic config just keeps its scheduler+ return None+ if "flow_shift" in keys and config.get("use_flow_sigmas", True):+ # UniPC / DPM-Solver in flow mode (Wan).+ return {"flow_shift": float(shift)}+ if "shift" in keys and "use_dynamic_shifting" in keys:+ # FlowMatchEulerDiscrete: static shift, no resolution-dependent mu, no terminal stretch.+ overrides = {"shift": float(shift), "use_dynamic_shifting": False}+ if "shift_terminal" in keys:+ overrides["shift_terminal"] = None+ return overrides+ return None+++def apply_comfy_flow_shift(+ pipe: Any,+ shift: Optional[float],+ logger: Any = None,+) -> bool:+ """Rebuild ``pipe.scheduler`` at ComfyUI's static ``shift``. True when it changed."""+ if shift is None:+ return False+ scheduler = getattr(pipe, "scheduler", None)+ config = getattr(scheduler, "config", None)+ if scheduler is None or config is None:+ return False+ overrides = flow_shift_overrides(config, shift)+ if not overrides:+ return False+ if all(config.get(k) == v for k, v in overrides.items()):+ return False+ try:+ pipe.scheduler = type(scheduler).from_config(config, **overrides)+ except Exception as exc: # noqa: BLE001 - keep the shipped schedule rather than fail the load+ if logger is not None:+ logger.warning("flow shift %s not applied: %s", shift, exc)+ return False+ if logger is not None:+ logger.info("scheduler flow shift set to %s (ComfyUI default)", shift)+ return Truediff --git a/studio/backend/core/inference/diffusion_text_length.py b/studio/backend/core/inference/diffusion_text_length.pynew file mode 100644index 00000000000..0ece9c90116--- /dev/null+++ b/studio/backend/core/inference/diffusion_text_length.py@@ -0,0 +1,147 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Text-conditioning defaults that follow ComfyUI. No torch/diffusers imports.++FLUX.1 T5 sequence length:++diffusers pads (and truncates) the FLUX.1 T5 prompt to ``max_sequence_length=512`` and runs T5+without an attention mask, so every pad token takes part in the encoder's self-attention. ComfyUI,+our baseline, pads the same T5 prompt only up to 256 tokens and otherwise uses its real length+(again with no mask). Both the embeddings and the text tokens the DiT attends over therefore differ,+and 512 costs 256 extra joint-attention tokens per step for a short prompt.++``flux_t5_sequence_length`` reproduces the ComfyUI length (256) for every prompt of at most 256 T5+tokens (EOS included). Longer prompts pad to 512 as before (bucketed, see the function), and a prompt+past 512 tokens truncates exactly as before.+"""++from __future__ import annotations++import math+from typing import Any, Iterable, Optional++# ComfyUI's Ideogram 4 template ("Default" preset): 20 steps, logit-normal mean 0.0 and spread 1.75 before the+# resolution term (both implementations add it the same way), and guidance 7 overridden to 3 over the last 30% of+# sampling (CFG override, start 0.7 / end 1.0). Ideogram 4 samples a plain flow model (shift 1), so that range is+# sigma <= 0.3.+IDEOGRAM4_COMFY_STEPS = 20+IDEOGRAM4_COMFY_MU = 0.0+IDEOGRAM4_COMFY_STD = 1.75+IDEOGRAM4_COMFY_GUIDANCE = 7.0+IDEOGRAM4_COMFY_TAIL_GUIDANCE = 3.0+IDEOGRAM4_COMFY_TAIL_SIGMA = 0.3+_IDEOGRAM4_LOGSNR_MIN = -15.0+_IDEOGRAM4_LOGSNR_MAX = 18.0+++def ideogram4_sigmas(steps: int, width: int, height: int, mu: float, std: float) -> list[float]:+ """The ``steps`` sigmas the Ideogram 4 logit-normal schedule visits (terminal 0 excluded), highest first."""+ from statistics import NormalDist++ mean = float(mu) + 0.5 * math.log((int(width) * int(height)) / (512 * 512))+ t_min = 1.0 / (1.0 + math.exp(0.5 * _IDEOGRAM4_LOGSNR_MAX))+ t_max = 1.0 / (1.0 + math.exp(0.5 * _IDEOGRAM4_LOGSNR_MIN))+ out = []+ for i in range(int(steps)):+ u = 1.0 - i / int(steps) # the schedule is built on linspace(0, 1) and flipped+ if u >= 1.0:+ t = 0.0+ else:+ y = mean + float(std) * NormalDist().inv_cdf(u)+ t = 1.0 - 1.0 / (1.0 + math.exp(-y))+ out.append(1.0 - min(max(t, t_min), t_max))+ return out+++def ideogram4_comfy_guidance_schedule(steps: int, width: int, height: int) -> list[float]:+ """Per-step guidance ComfyUI's template applies: 7, then 3 on every step whose sigma is <= 0.3."""+ return [+ IDEOGRAM4_COMFY_TAIL_GUIDANCE+ if sigma <= IDEOGRAM4_COMFY_TAIL_SIGMA+ else IDEOGRAM4_COMFY_GUIDANCE+ for sigma in ideogram4_sigmas(steps, width, height, IDEOGRAM4_COMFY_MU, IDEOGRAM4_COMFY_STD)+ ]+++# FLUX.1 families on a FluxPipeline-style ``max_sequence_length`` whose ComfyUI tokenizer is the FLUX T5 one.+FLUX_T5_FAMILIES = frozenset({"flux.1", "flux.1-kontext"})+FLUX_T5_MIN_TOKENS = 256+FLUX_T5_MAX_TOKENS = 512+++def _texts(value: Any) -> list[str]:+ if value is None:+ return []+ if isinstance(value, str):+ return [value]+ if isinstance(value, (list, tuple)):+ return [v for v in value if isinstance(v, str)]+ return []+++def t5_token_count(tokenizer: Any, text: str) -> int:+ """T5 tokens for ``text`` including the EOS the tokenizer appends."""+ ids = tokenizer(text, add_special_tokens = True)["input_ids"]+ return len(ids)+++def flux_t5_sequence_length(+ tokenizer: Any,+ prompts: Iterable[Any],+ *,+ floor: int = FLUX_T5_MIN_TOKENS,+ cap: int = FLUX_T5_MAX_TOKENS,+) -> Optional[int]:+ """``max_sequence_length`` for one FLUX.1 call, or None when it cannot be measured (keep the+ pipeline default). ``prompts`` holds each str / list-of-str the call encodes with T5."""+ if tokenizer is None or not callable(tokenizer):+ return None+ texts: list[str] = []+ for value in prompts:+ texts.extend(_texts(value))+ if not texts:+ return None+ try:+ longest = max(t5_token_count(tokenizer, t) for t in texts)+ except Exception: # noqa: BLE001 - an odd tokenizer only keeps the pipeline default+ return None+ # Bucketed, a deliberate deviation from ComfyUI's exact length: every distinct text length is a new denoiser shape,+ # and on the compiled default path the first one past 256 measured a 14 s recompile, each further one a CUDA graph+ # recapture (0.4 to 1 s) until the 4-graph cap made later shapes run eager. So a prompt past 256 tokens pads to the+ # cap (exactly the old behaviour); T5 runs unmasked, so that padding shifts the embeddings of those prompts only.+ return int(floor) if longest <= int(floor) else int(cap)+++def flux_t5_kwarg(+ family_name: str, pipe: Any, call_params: Any, chunk_kwargs: dict+) -> Optional[int]:+ """The ``max_sequence_length`` to pass for this chunk, or None to leave the kwarg alone.++ Only FLUX.1 families, only when the pipeline accepts the kwarg, and never over a value the+ caller already set. The negative prompt counts only when true CFG actually encodes it."""+ if family_name not in FLUX_T5_FAMILIES:+ return None+ if "max_sequence_length" not in call_params or "max_sequence_length" in chunk_kwargs:+ return None+ prompts: list[Any] = [chunk_kwargs.get("prompt_2") or chunk_kwargs.get("prompt")]+ negative = chunk_kwargs.get("negative_prompt_2") or chunk_kwargs.get("negative_prompt")+ try:+ true_cfg = float(chunk_kwargs.get("true_cfg_scale", 1.0) or 1.0)+ except (TypeError, ValueError):+ true_cfg = 1.0+ if negative and true_cfg > 1.0:+ prompts.append(negative)+ return flux_t5_sequence_length(getattr(pipe, "tokenizer_2", None), prompts)+++def true_cfg_needs_empty_negative(cfg_kwarg: str, guidance: Any) -> bool:+ """True when a ``true_cfg_scale`` pipeline (Qwen-Image family) would skip CFG for want of a+ negative prompt. diffusers enables true CFG only when ``true_cfg_scale > 1`` AND a negative is+ given; ComfyUI always encodes the (possibly empty) negative and applies CFG above 1."""+ if cfg_kwarg != "true_cfg_scale":+ return False+ try:+ return float(guidance) > 1.0+ except (TypeError, ValueError):+ return Falsediff --git a/studio/backend/core/inference/sd_cpp_backend.py b/studio/backend/core/inference/sd_cpp_backend.pyindex e94b068d6ad..7cf0df65f55 100644--- a/studio/backend/core/inference/sd_cpp_backend.py+++ b/studio/backend/core/inference/sd_cpp_backend.py@@ -2175,6 +2175,9 @@ def _map_guidance(``--cfg-scale``. A distilled 0/1 means CFG off (sd-cli's 1.0); a value > 1 is real CFG."""if fam.name in ("flux.1", "flux.2-klein", "flux.2-dev"):return None, (float(guidance) if guidance is not None else None)+ if fam.name == "z-image":+ # diffusers Z-Image computes pos + g * (pos - neg), so its g is standard CFG minus 1 (sd.cpp's cfg 4 == g 3).+ return (float(guidance) + 1.0 if guidance is not None and guidance > 0.0 else 1.0), Nonecfg = float(guidance) if (guidance is not None and guidance > 1.0) else 1.0return cfg, Nonediff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.pyindex 44b1ec385a2..388f4977765 100644--- a/studio/backend/core/inference/video.py+++ b/studio/backend/core/inference/video.py@@ -55,6 +55,7 @@ from .diffusion_attention import (sdpa_math_only,select_attention_backend,)+from .diffusion_flow_shift import apply_comfy_flow_shiftfrom .diffusion_cache import (FBCACHE_MIN_STEPS,TC_AUTO,@@ -6532,6 +6533,8 @@ class VideoBackend:})+ # Sample at ComfyUI's static sigma shift where the shipped scheduler differs.+ apply_comfy_flow_shift(pipe, getattr(fam, "comfy_flow_shift", None), logger)from . import diffusion_prompt_cachediffusion_prompt_cache.install(@@ -7499,6 +7502,8 @@ class VideoBackend:),})+ # Sample at ComfyUI's static sigma shift where the shipped scheduler differs.+ apply_comfy_flow_shift(pipe, getattr(fam, "comfy_flow_shift", None), logger)from . import diffusion_prompt_cachediffusion_prompt_cache.install(diff --git a/studio/backend/core/inference/video_families.py b/studio/backend/core/inference/video_families.pyindex 0739f3c2e61..a3d5bad2f7d 100644--- a/studio/backend/core/inference/video_families.py+++ b/studio/backend/core/inference/video_families.py@@ -130,6 +130,9 @@ class VideoFamily:modular_workflow: Optional[str] = None# Released video and audio sigma shifts, when configurable.default_flow_shift: Optional[float] = None+ # Static sigma shift ComfyUI samples this family with by default; the loader rebuilds the scheduler at it. None =+ # keep the shipped scheduler. Distinct from default_flow_shift, which also exposes a user control.+ comfy_flow_shift: Optional[float] = Nonedefault_audio_flow_shift: Optional[float] = None# First/last-frame conditioning: the request may carry keyframe images.supports_keyframes: bool = False@@ -263,9 +266,10 @@ _FAMILIES: tuple[VideoFamily, ...] = (prequant_variant_repos = (("lightricks/ltx-2.3", "fp8", "unsloth/LTX-2.3-FP8"),),),# Wan2.2-TI2V-5B (diffusers >= 0.35, verified on 0.39): ~5B single-stream DiT (UMT5 encoder), no audio. Its VAE's- # temporal compression 4 gives valid frame counts 4k+1. Defaults 50 steps / CFG 5.+ # temporal compression 4 gives valid frame counts 4k+1. Defaults 20 steps / CFG 5 (ComfyUI's template).VideoFamily(name = "wan2.2-ti2v-5b",+ comfy_flow_shift = 8.0, # ComfyUI ModelSamplingSD3 8 (TI2V-5B template)pipeline_class = "WanPipeline",transformer_class = "WanTransformer3DModel",base_repo = "Wan-AI/Wan2.2-TI2V-5B-Diffusers",@@ -275,7 +279,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (# "wan2.2-5b"/"wan-ti2v" are the picker/GGUF short ids; "wan2.2-ti2v" catches the repo stemaliases = ("wan2.2-5b", "wan-ti2v", "wan2.2-ti2v", "wan-ti2v-5b"),has_audio = False,- default_steps = 50,+ default_steps = 20,default_guidance = 5.0,default_num_frames = 121,default_fps = 24,@@ -298,6 +302,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (# transformer_2, so cfg2_kwarg is threaded only here.VideoFamily(name = "wan2.2-t2v-a14b",+ comfy_flow_shift = 5.0, # ComfyUI ModelSamplingSD3 5 (T2V-A14B template)pipeline_class = "WanPipeline",transformer_class = "WanTransformer3DModel",base_repo = "Wan-AI/Wan2.2-T2V-A14B-Diffusers",@@ -315,8 +320,9 @@ _FAMILIES: tuple[VideoFamily, ...] = (transformer2_class = "WanTransformer3DModel",is_moe = True,cfg2_kwarg = "guidance_scale_2",- default_steps = 50,- default_guidance = 5.0,+ # ComfyUI's A14B template without the Lightning LoRA: 20 steps at CFG 3.5 on both experts.+ default_steps = 20,+ default_guidance = 3.5,# 81 frames at 16 fps ~5s (81 = 4*20 + 1), the A14B card's default clip.default_num_frames = 81,default_fps = 16, # A14B runs at 16 fps (vs TI2V-5B's 24)@@ -335,6 +341,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (# so only the community repacks load.VideoFamily(name = "hunyuanvideo-1.5",+ comfy_flow_shift = 7.0, # ComfyUI model default and template shift 7pipeline_class = "HunyuanVideo15Pipeline",transformer_class = "HunyuanVideo15Transformer3DModel",base_repo = "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-480p_t2v",@@ -345,7 +352,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (aliases = ("hunyuanvideo-1-5", "hunyuanvideo1.5", "hunyuanvideo1-5", "hv15"),has_audio = False,guidance_via_guider = True,- default_steps = 50,+ default_steps = 20,default_guidance = 6.0,default_num_frames = 121,default_fps = 24,@@ -364,6 +371,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (# own family so a 720p load defaults to 720p sizes; the full-path alias outranks the generic token.VideoFamily(name = "hunyuanvideo-1.5-720p",+ comfy_flow_shift = 7.0, # ComfyUI model default and template shift 7pipeline_class = "HunyuanVideo15Pipeline",transformer_class = "HunyuanVideo15Transformer3DModel",base_repo = "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-720p_t2v",@@ -374,7 +382,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (aliases = ("hunyuanvideo-1.5-diffusers-720p_t2v", "hv15-720p"),has_audio = False,guidance_via_guider = True,- default_steps = 50,+ default_steps = 20,default_guidance = 6.0,default_num_frames = 121,default_fps = 24,@@ -809,10 +817,14 @@ def validate_video_reference_conditioning(_VIDEO_GENERATION_DEFAULTS: tuple[tuple[str, int, float], ...] = (("distilled", 8, 1.0),("ltx", 40, 4.0),- # Wan2.2 pipelines default to 50 steps / CFG 5.0; both TI2V-5B and A14B share these.- ("wan", 50, 5.0),- # HunyuanVideo-1.5: 50 steps with the guider's shipped CFG 6.0.- ("hunyuanvideo", 50, 6.0),+ # ComfyUI's templates for the same models (our baseline). Wan2.2-T2V-A14B: 20 steps at CFG 3.5 (Lightning LoRA+ # off); before the generic Wan key.+ ("a14b", 20, 3.5),+ ("wan2.2-14b", 20, 3.5),+ # Wan2.2-TI2V-5B: 20 steps at CFG 5.+ ("wan", 20, 5.0),+ # HunyuanVideo-1.5: 20 steps with the guider's shipped CFG 6.0.+ ("hunyuanvideo", 20, 6.0),)diff --git a/studio/backend/tests/test_diffusion_backend.py b/studio/backend/tests/test_diffusion_backend.pyindex 2d41b06e38e..ba78ff05810 100644--- a/studio/backend/tests/test_diffusion_backend.py+++ b/studio/backend/tests/test_diffusion_backend.py@@ -14420,3 +14420,148 @@ def test_diffusion_status_response_keeps_the_gguf_a_swap_replaced():]assert dumped["replaced"] == "gguf:m-Q4_K_M.gguf"assert dumped["artifact"] == "prequant:o/r/f.safetensors"+++# FLUX.1 T5 length (ComfyUI parity): real prompt length floored at 256, capped at 512.+class _T5WordTokenizer:+ """One id per whitespace word plus EOS, like T5TokenizerFast on plain words."""++ def __call__(+ self,+ text,+ add_special_tokens = True,+ **_,+ ):+ return {"input_ids": [5] * len(text.split()) + ([1] if add_special_tokens else [])}+++class _FluxFakePipe(_FakePipe):+ def __init__(self):+ super().__init__()+ self.tokenizer_2 = _T5WordTokenizer()++ def __call__(+ self,+ *,+ prompt = None,+ max_sequence_length = 512,+ **kwargs,+ ):+ return super().__call__(prompt = prompt, max_sequence_length = max_sequence_length, **kwargs)+++def test_generate_passes_flux1_t5_length_like_comfy(fake_runtime, tmp_path, monkeypatch):+ diffusers = sys.modules["diffusers"]+ monkeypatch.setattr(diffusers, "FluxPipeline", _FakePipeline, raising = False)+ monkeypatch.setattr(diffusers, "FluxTransformer2DModel", _FakeTransformer, raising = False)+ _no_cache(monkeypatch)+ backend = _loaded_backend(tmp_path, family_override = "flux.1")+ pipe = _FluxFakePipe()+ object.__setattr__(backend._state, "pipe", pipe)+ backend.generate(prompt = "a sloth on a branch", steps = 4, guidance = 0.0)+ assert pipe.last_kwargs["max_sequence_length"] == 256+ backend.generate(prompt = " ".join(["w"] * 320), steps = 4, guidance = 0.0)+ assert pipe.last_kwargs["max_sequence_length"] == 512 # past 256 tokens: the 512 bucket+++def test_generate_leaves_t5_length_alone_off_flux1(fake_runtime, tmp_path):+ backend = _loaded_backend(tmp_path, family_override = "z-image")+ pipe = _FluxFakePipe()+ object.__setattr__(backend._state, "pipe", pipe)+ backend.generate(prompt = "a sloth", steps = 4, guidance = 0.0)+ assert pipe.last_kwargs["max_sequence_length"] == 512 # pipeline default, nothing passed+++def test_qwen_true_cfg_gets_an_empty_negative_like_comfy(fake_runtime, tmp_path, monkeypatch):+ """diffusers runs Qwen-Image true CFG only when a negative is present; ComfyUI always encodes the+ empty negative and applies CFG. A blank negative must not silently turn CFG off."""+ diffusers = sys.modules["diffusers"]+ monkeypatch.setattr(diffusers, "QwenImagePipeline", _FakePipeline, raising = False)+ monkeypatch.setattr(diffusers, "QwenImageTransformer2DModel", _FakeTransformer, raising = False)+ _no_cache(monkeypatch)+ backend = _loaded_backend(tmp_path, family_override = "qwen-image")+ backend.generate(prompt = "a sloth", steps = 4, guidance = 4.0)+ call = backend._state.pipe.last_kwargs+ assert call["true_cfg_scale"] == 4.0 and call["negative_prompt"] == ""+ # An explicit negative is kept; guidance <= 1 never asks for CFG.+ backend.generate(prompt = "a sloth", negative_prompt = "blurry", steps = 4, guidance = 4.0)+ assert backend._state.pipe.last_kwargs["negative_prompt"] == "blurry"+ backend.generate(prompt = "a sloth", steps = 4, guidance = 1.0)+ assert backend._state.pipe.last_kwargs["negative_prompt"] is None+++def test_guidance_scale_families_get_no_injected_negative(fake_runtime, tmp_path):+ backend = _loaded_backend(tmp_path) # z-image: guidance_scale, its own CFG handling+ backend.generate(prompt = "a sloth", steps = 4, guidance = 4.0)+ assert backend._state.pipe.last_kwargs["negative_prompt"] is None+++class _IdeogramScheduleFakePipe(_FakePipe):+ def __call__(+ self,+ *,+ prompt = None,+ mu = 0.0,+ std = 1.5,+ guidance_schedule = "card",+ **kwargs,+ ):+ return super().__call__(+ prompt = prompt, mu = mu, std = std, guidance_schedule = guidance_schedule, **kwargs+ )+++def test_generate_ideogram_defaults_follow_comfy_template(fake_runtime, tmp_path):+ """ComfyUI's Ideogram 4 template: 20 steps, mu 0.0 / std 1.75, guidance 7 overridden to 3 where sigma <= 0.3+ (the last 3 of 20 steps at 1024^2). Another guidance stays constant; an explicit 48 / 7 keeps the card taper."""+ backend = DiffusionBackend()+ _load_ideogram(backend, tmp_path)+ pipe = _IdeogramScheduleFakePipe()+ object.__setattr__(backend._state, "pipe", pipe)+ backend.generate(prompt = "a sloth", width = 1024, height = 1024, steps = 20, guidance = 7.0)+ call = pipe.last_kwargs+ assert call["guidance_scale"] is None+ assert call["guidance_schedule"] == [7.0] * 17 + [3.0] * 3+ assert (call["mu"], call["std"]) == (0.0, 1.75)+ backend.generate(prompt = "a sloth", width = 512, height = 512, steps = 20, guidance = 7.0)+ assert pipe.last_kwargs["guidance_schedule"] == [7.0] * 14 + [3.0] * 6+ backend.generate(prompt = "a sloth", width = 1024, height = 1024, steps = 20, guidance = 5.0)+ call = pipe.last_kwargs+ assert call["guidance_scale"] == 5.0 and call["guidance_schedule"] is None+ assert (call["mu"], call["std"]) == (0.0, 1.75)+ backend.generate(prompt = "a sloth", steps = 48, guidance = 7.0)+ call = pipe.last_kwargs+ assert call["guidance_schedule"] == "card" and (call["mu"], call["std"]) == (0.0, 1.5)+++class _ShiftSchedulerConfig(dict):+ pass+++class _ShiftFakeScheduler:+ def __init__(self, **config):+ self.config = _ShiftSchedulerConfig(config)++ @classmethod+ def from_config(cls, config, **overrides):+ return cls(**{**config, **overrides})+++class _QwenShiftFakePipeline(_FakePipeline):+ @classmethod+ def from_pretrained(cls, base, **kwargs):+ pipe = super().from_pretrained(base, **kwargs)+ pipe.scheduler = _ShiftFakeScheduler(+ shift = 1.0, use_dynamic_shifting = True, shift_terminal = 0.02+ )+ return pipe+++def test_qwen_load_samples_at_comfy_static_shift(fake_runtime, tmp_path, monkeypatch):+ diffusers = sys.modules["diffusers"]+ monkeypatch.setattr(diffusers, "QwenImagePipeline", _QwenShiftFakePipeline, raising = False)+ monkeypatch.setattr(diffusers, "QwenImageTransformer2DModel", _FakeTransformer, raising = False)+ _no_cache(monkeypatch)+ backend = _loaded_backend(tmp_path, family_override = "qwen-image")+ cfg = backend._state.pipe.scheduler.config+ assert (cfg["shift"], cfg["use_dynamic_shifting"], cfg["shift_terminal"]) == (3.1, False, None)diff --git a/studio/backend/tests/test_diffusion_flow_shift.py b/studio/backend/tests/test_diffusion_flow_shift.pynew file mode 100644index 00000000000..a50392db789--- /dev/null+++ b/studio/backend/tests/test_diffusion_flow_shift.py@@ -0,0 +1,73 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Families sample at ComfyUI's static sigma shift: the loader rebuilds the shipped scheduler."""++from __future__ import annotations++import types++from core.inference.diffusion_families import detect_family+from core.inference.diffusion_flow_shift import apply_comfy_flow_shift, flow_shift_overrides+from core.inference.video_families import detect_video_family+++class _Config(dict):+ pass+++class _FakeScheduler:+ def __init__(self, **config):+ self.config = _Config(config)++ @classmethod+ def from_config(cls, config, **overrides):+ return cls(**{**config, **overrides})+++# Shipped configs (the fields that matter) of the Qwen-Image, Wan2.2-TI2V-5B and HunyuanVideo-1.5 720p repos.+_QWEN = dict(+ shift = 1.0, use_dynamic_shifting = True, shift_terminal = 0.02, time_shift_type = "exponential"+)+_WAN = dict(flow_shift = 5.0, use_flow_sigmas = True, solver_order = 2)+_HV15 = dict(shift = 9.0, use_dynamic_shifting = False, shift_terminal = None)+++def test_flow_match_gets_a_static_shift_without_terminal_stretch():+ pipe = types.SimpleNamespace(scheduler = _FakeScheduler(**_QWEN))+ assert apply_comfy_flow_shift(pipe, 3.1) is True+ cfg = pipe.scheduler.config+ assert (cfg["shift"], cfg["use_dynamic_shifting"], cfg["shift_terminal"]) == (3.1, False, None)+ assert cfg["time_shift_type"] == "exponential" # untouched keys survive+ assert apply_comfy_flow_shift(pipe, 3.1) is False # idempotent+++def test_unipc_flow_shift_and_static_euler():+ wan = types.SimpleNamespace(scheduler = _FakeScheduler(**_WAN))+ assert apply_comfy_flow_shift(wan, 8.0) and wan.scheduler.config["flow_shift"] == 8.0+ hv = types.SimpleNamespace(scheduler = _FakeScheduler(**_HV15))+ assert apply_comfy_flow_shift(hv, 7.0) and hv.scheduler.config["shift"] == 7.0+++def test_no_shift_or_unknown_scheduler_is_a_no_op():+ pipe = types.SimpleNamespace(scheduler = _FakeScheduler(**_QWEN))+ assert apply_comfy_flow_shift(pipe, None) is False+ other = types.SimpleNamespace(scheduler = _FakeScheduler(beta_schedule = "scaled_linear"))+ assert apply_comfy_flow_shift(other, 3.0) is False+ assert flow_shift_overrides(_Config(beta_schedule = "x"), 3.0) is None+ assert apply_comfy_flow_shift(types.SimpleNamespace(), 3.0) is False+++def test_family_shifts_match_comfy_defaults():+ assert detect_family("Qwen/Qwen-Image").comfy_flow_shift == 3.1+ assert detect_family("Qwen/Qwen-Image-Edit-2511").comfy_flow_shift == 3.1+ assert detect_family("Tongyi-MAI/Z-Image").comfy_flow_shift == 3.0+ # Families whose shipped schedule already matches keep it.+ assert detect_family("black-forest-labs/FLUX.1-schnell").comfy_flow_shift is None+ assert detect_video_family("Wan-AI/Wan2.2-TI2V-5B-Diffusers").comfy_flow_shift == 8.0+ assert detect_video_family("Wan-AI/Wan2.2-T2V-A14B-Diffusers").comfy_flow_shift == 5.0+ for repo in (+ "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-480p_t2v",+ "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-720p_t2v",+ ):+ assert detect_video_family(repo).comfy_flow_shift == 7.0diff --git a/studio/backend/tests/test_diffusion_flux_t5_length.py b/studio/backend/tests/test_diffusion_flux_t5_length.pynew file mode 100644index 00000000000..993b7ea29d0--- /dev/null+++ b/studio/backend/tests/test_diffusion_flux_t5_length.py@@ -0,0 +1,84 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""FLUX.1 T5 sequence length follows ComfyUI: the prompt's real T5 length (EOS included), floored+at 256 and capped at the pipeline's 512, instead of diffusers' fixed 512."""++from __future__ import annotations++import types++import pytest++from core.inference.diffusion_text_length import (+ flux_t5_kwarg,+ flux_t5_sequence_length,+)+++class _WordTokenizer:+ """One id per whitespace word plus EOS, like T5TokenizerFast on plain words."""++ def __call__(+ self,+ text,+ add_special_tokens = True,+ **_,+ ):+ ids = [5] * len(text.split())+ return {"input_ids": ids + ([1] if add_special_tokens else [])}+++def _words(n):+ return " ".join(["w"] * n)+++ "words, expected",+ [(3, 256), (255, 256), (256, 512), (300, 512), (511, 512), (700, 512)],+)+def test_length_is_256_up_to_256_tokens_else_the_512_bucket(words, expected):+ assert flux_t5_sequence_length(_WordTokenizer(), [_words(words)]) == expected+++def test_longest_prompt_of_a_list_sets_the_length():+ assert flux_t5_sequence_length(_WordTokenizer(), [["a", _words(200)]]) == 256+ assert flux_t5_sequence_length(_WordTokenizer(), [["a", _words(400)]]) == 512+++def test_no_tokenizer_keeps_the_pipeline_default():+ assert flux_t5_sequence_length(None, ["a"]) is None+++def test_only_flux1_families_and_only_when_accepted():+ pipe = types.SimpleNamespace(tokenizer_2 = _WordTokenizer())+ params = {"max_sequence_length": None}+ assert flux_t5_kwarg("flux.1", pipe, params, {"prompt": "a"}) == 256+ assert flux_t5_kwarg("flux.1-kontext", pipe, params, {"prompt": "a"}) == 256+ assert flux_t5_kwarg("flux.2-klein", pipe, params, {"prompt": "a"}) is None+ assert flux_t5_kwarg("flux.1", pipe, {}, {"prompt": "a"}) is None+ # An explicit value is never overridden.+ assert flux_t5_kwarg("flux.1", pipe, params, {"prompt": "a", "max_sequence_length": 77}) is None+++def test_negative_counts_only_under_true_cfg():+ pipe = types.SimpleNamespace(tokenizer_2 = _WordTokenizer())+ params = {"max_sequence_length": None}+ kw = {"prompt": "a", "negative_prompt": _words(300)}+ assert flux_t5_kwarg("flux.1", pipe, params, kw) == 256+ assert flux_t5_kwarg("flux.1", pipe, params, {**kw, "true_cfg_scale": 4.0}) == 512+ # prompt_2 is what FLUX.1 feeds T5 when given.+ assert flux_t5_kwarg("flux.1", pipe, params, {"prompt": "a", "prompt_2": _words(280)}) == 512+++def test_ideogram4_comfy_guidance_switches_where_sigma_falls_to_0_3():+ from core.inference.diffusion_text_length import (+ ideogram4_comfy_guidance_schedule,+ ideogram4_sigmas,+ )++ sigmas = ideogram4_sigmas(20, 1024, 1024, 0.0, 1.75)+ assert sigmas == sorted(sigmas, reverse = True) and sigmas[0] > 0.999 # clamped at logSNR -15+ schedule = ideogram4_comfy_guidance_schedule(20, 1024, 1024)+ assert schedule == [7.0] * 17 + [3.0] * 3+ assert sigmas[16] > 0.3 >= sigmas[17]diff --git a/studio/backend/tests/test_diffusion_more_families.py b/studio/backend/tests/test_diffusion_more_families.pyindex 66a6700b490..286049f50d5 100644--- a/studio/backend/tests/test_diffusion_more_families.py+++ b/studio/backend/tests/test_diffusion_more_families.py@@ -81,8 +81,8 @@ def test_flux1_krea_dev_is_trusted_non_gguf():def test_flux1_krea_dev_generation_defaults():# Model-card recipe: 28 steps at guidance 4.5. The generic "krea" key (Turbo's 8-step no-CFG shape) must NOT swallow it, and the krea-2 defaults must stay intact.- assert default_generation_params("black-forest-labs/FLUX.1-Krea-dev") == (28, 4.5)- assert default_generation_params("QuantStack/FLUX.1-Krea-dev-GGUF") == (28, 4.5)+ assert default_generation_params("black-forest-labs/FLUX.1-Krea-dev") == (20, 3.5)+ assert default_generation_params("QuantStack/FLUX.1-Krea-dev-GGUF") == (20, 3.5)assert default_generation_params("krea/Krea-2-Turbo") == (8, 0.0)assert default_generation_params("krea/Krea-2-Raw") == (52, 3.5)@@ -108,7 +108,7 @@ def test_flux_dev_and_krea_do_not_inherit_the_schnell_nvfp4_checkpoint():def test_flux2_klein_generation_defaults_distinguish_base_from_distilled():for size in ("4B", "9B"):- assert default_generation_params(f"unsloth/FLUX.2-klein-base-{size}") == (50, 4.0)+ assert default_generation_params(f"unsloth/FLUX.2-klein-base-{size}") == (20, 5.0)assert default_generation_params(f"unsloth/FLUX.2-klein-{size}") == (4, 1.0)@@ -167,10 +167,10 @@ def test_prequant_exclusion_does_not_break_a_family_type_that_lacks_the_field():def test_zimage_base_generation_defaults_are_not_the_distilled_recipe():# The base is undistilled: 20 steps at guidance 4. The more specific "z-image-turbo" key sits# ahead of "z-image", so the 9-step CFG-free Turbo recipe must not swallow it.- assert default_generation_params("Tongyi-MAI/Z-Image") == (20, 4.0)- assert default_generation_params("unsloth/Z-Image-GGUF") == (20, 4.0)- assert default_generation_params("Tongyi-MAI/Z-Image-Turbo") == (9, 0.0)- assert default_generation_params("unsloth/Z-Image-Turbo-GGUF") == (9, 0.0)+ assert default_generation_params("Tongyi-MAI/Z-Image") == (25, 3.0)+ assert default_generation_params("unsloth/Z-Image-GGUF") == (25, 3.0)+ assert default_generation_params("Tongyi-MAI/Z-Image-Turbo") == (8, 0.0)+ assert default_generation_params("unsloth/Z-Image-Turbo-GGUF") == (8, 0.0)# ── lumina-2 family ──────────────────────────────────────────────────────────@@ -346,8 +346,8 @@ def test_hidream_bf16_component_table_present():def test_ideogram4_generation_defaults():- # Model-card settings: 48 steps, guidance 7 (an exact match keeps the pipeline's recommended tapered schedule).- assert default_generation_params("ideogram-ai/ideogram-4-fp8") == (48, 7.0)+ # ComfyUI's template: 20 steps at constant guidance 7 (an explicit 48 / 7 still keeps the card's tapered schedule).+ assert default_generation_params("ideogram-ai/ideogram-4-fp8") == (20, 7.0)def test_ideogram4_bf16_reservation_table_present():diff --git a/studio/backend/tests/test_diffusion_unified_edit.py b/studio/backend/tests/test_diffusion_unified_edit.pyindex fcd53a6712b..d289bd40a34 100644--- a/studio/backend/tests/test_diffusion_unified_edit.py+++ b/studio/backend/tests/test_diffusion_unified_edit.py@@ -139,9 +139,9 @@ def test_sampling_defaults_resolve_for_every_21_artifact_name():"unsloth/Qwen-Image-2.1-GGUF","unsloth/Qwen-Image-2.1-FP8",):- assert default_generation_params(name) == (40, 1.0), name+ assert default_generation_params(name) == (25, 1.0), name# The generic key still owns the other Qwen-Image checkpoints.- assert default_generation_params("Qwen/Qwen-Image-2512") == (20, 4.0)+ assert default_generation_params("Qwen/Qwen-Image-2512") == (50, 4.0)def test_explicit_edit_hands_ordered_rgba_images_and_explicit_geometry(backend21):diff --git a/studio/backend/tests/test_openai_images_generations_route.py b/studio/backend/tests/test_openai_images_generations_route.pyindex d054fcd2640..6ec61c01c76 100644--- a/studio/backend/tests/test_openai_images_generations_route.py+++ b/studio/backend/tests/test_openai_images_generations_route.py@@ -36,12 +36,16 @@ from utils.api_errors import install_api_error_handlers@pytest.mark.parametrize("repo_id, expected",[- ("unsloth/Z-Image-Turbo-GGUF", (9, 0.0)), # turbo entry, before the z-image fallback- ("unsloth/Z-Image-GGUF", (20, 4.0)),+ ("unsloth/Z-Image-Turbo-GGUF", (8, 0.0)), # turbo entry, before the z-image fallback+ ("unsloth/Z-Image-GGUF", (25, 3.0)),("unsloth/FLUX.1-schnell-GGUF", (4, 0.0)), # schnell entry, before the flux.1 entry- ("black-forest-labs/FLUX.1-dev", (28, 3.5)),+ ("black-forest-labs/FLUX.1-dev", (20, 3.5)),("unsloth/FLUX.2-klein-4B-GGUF", (4, 1.0)),- ("unsloth/Qwen-Image-2512-GGUF", (20, 4.0)),+ ("unsloth/Qwen-Image-2512-GGUF", (50, 4.0)),+ ("Qwen/Qwen-Image-Edit-2511", (40, 4.0)),+ ("black-forest-labs/FLUX.1-Kontext-dev", (20, 2.5)),+ ("black-forest-labs/FLUX.2-dev", (20, 4.0)),+ ("stabilityai/stable-diffusion-xl-base-1.0", (25, 7.0)),("some/unknown-model", (9, 0.0)), # fallback("", (9, 0.0)),],@@ -60,14 +64,14 @@ def test_default_generation_params_specificity_ordering():def test_default_generation_params_falls_back_to_base_repo():# A local-path load: repo_id names no model, so the resolved base repo identifies it (and separates dev from schnell).- assert default_generation_params("/models/my-ckpt", "black-forest-labs/FLUX.1-dev") == (28, 3.5)+ assert default_generation_params("/models/my-ckpt", "black-forest-labs/FLUX.1-dev") == (20, 3.5)assert default_generation_params("/models/my-ckpt", "black-forest-labs/FLUX.1-schnell") == (4,0.0,)assert default_generation_params("/models/my-ckpt", "Qwen/Qwen-Image") == (20, 4.0)# repo_id wins when it already names the model; base repo is only a fallback.- assert default_generation_params("unsloth/Z-Image-Turbo-GGUF", "Tongyi-MAI/Z-Image") == (9, 0.0)+ assert default_generation_params("unsloth/Z-Image-Turbo-GGUF", "Tongyi-MAI/Z-Image") == (8, 0.0)# Nothing identifiable -> fallback; None identifiers are skipped.assert default_generation_params(None, None) == (9, 0.0)assert default_generation_params("/models/x", None) == (9, 0.0)@@ -232,12 +236,12 @@ def test_url_response_shape(client):assert "url" in item and "b64_json" not in item # exclude_none drops the unused key# Signed link, not the bearer-gated /file route: an OpenAI client downloads this URL with a plain GET and no auth header.assert "/images/gallery/img0/file-signed?token=" in item["url"]- # Z-Image-Turbo defaults (9 steps, 0 guidance) flow into the backend call.+ # Z-Image-Turbo defaults (8 steps, 0 guidance) flow into the backend call.assert client.backend.calls[0] == dict(prompt = "a sloth",width = 256,height = 256,- steps = 9,+ steps = 8,guidance = 0.0,batch_size = 1,expected_load = load_identity("unsloth/Z-Image-Turbo-GGUF", None, "z-image"),@@ -298,7 +302,7 @@ def test_local_load_uses_base_repo_for_defaults(monkeypatch):monkeypatch.setattr(gallery_module, "save", _save)resp = cli.post("/v1/images/generations", json = {"prompt": "p", "size": "256x256"})assert resp.status_code == 200- assert backend.calls[0]["steps"] == 28 and backend.calls[0]["guidance"] == 3.5+ assert backend.calls[0]["steps"] == 20 and backend.calls[0]["guidance"] == 3.5def test_pipeline_runtime_error_is_sanitized_500(monkeypatch):@@ -637,14 +641,14 @@ def test_generation_pins_the_status_read_it_derived_its_params_from(monkeypatch)def test_replacement_retries_once_with_the_new_models_params(monkeypatch):- # Z-Image-Turbo (9 steps, guidance 0) is replaced by Z-Image (20 steps, guidance 4). The first+ # Z-Image-Turbo (8 steps, guidance 0) is replaced by Z-Image (25 steps, guidance 3). The first# attempt is refused in-lock; the retry must re-derive from fresh state, not reuse the turbo's.backend = _FakeBackend(replaced_by = [("unsloth/Z-Image-GGUF", None)])cli, _ = _replacement_client(monkeypatch, backend)resp = cli.post("/v1/images/generations", json = {"prompt": "p", "size": "256x256"})assert resp.status_code == 200assert len(backend.calls) == 1 # the refused attempt never generated- assert (backend.calls[0]["steps"], backend.calls[0]["guidance"]) == (20, 4.0)+ assert (backend.calls[0]["steps"], backend.calls[0]["guidance"]) == (25, 3.0)def test_second_replacement_is_a_503_not_a_sanitized_500(monkeypatch):diff --git a/studio/backend/tests/test_sd_cpp_backend.py b/studio/backend/tests/test_sd_cpp_backend.pyindex 533c285f7fc..866c2fded01 100644--- a/studio/backend/tests/test_sd_cpp_backend.py+++ b/studio/backend/tests/test_sd_cpp_backend.py@@ -754,6 +754,12 @@ def test_map_guidance_cfg_family_off_when_distilled():assert _map_guidance(detect_family("qwen-image"), 4.0) == (4.0, None)+def test_map_guidance_z_image_converts_diffusers_g_to_standard_cfg():+ # The shared default is diffusers' g = 3 (ComfyUI cfg 4); sd.cpp's standard CFG must get 4, Turbo's 0 stays off.+ assert _map_guidance(detect_family("Tongyi-MAI/Z-Image"), 3.0) == (4.0, None)+ assert _map_guidance(detect_family("Tongyi-MAI/Z-Image-Turbo"), 0.0) == (1.0, None)++# ── status ────────────────────────────────────────────────────────────────────diff --git a/studio/backend/tests/test_video_backend.py b/studio/backend/tests/test_video_backend.pyindex fa21e258088..668989a84da 100644--- a/studio/backend/tests/test_video_backend.py+++ b/studio/backend/tests/test_video_backend.py@@ -2203,12 +2203,12 @@ def test_wan_frame_snapping_4k_plus_1(fake_runtime):def test_wan_ti2v_defaults_applied(fake_runtime):- # No steps/guidance passed -> the Wan pipeline defaults (50 / 5.0).+ # No steps/guidance passed -> ComfyUI's TI2V-5B template defaults (20 / 5.0).backend = VideoBackend()backend.load_pipeline("Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline")backend.generate(prompt = "a sloth")call = backend._state.pipe.last_kwargs- assert call["num_inference_steps"] == 50+ assert call["num_inference_steps"] == 20assert call["guidance_scale"] == 5.0diff --git a/studio/backend/tests/test_video_families.py b/studio/backend/tests/test_video_families.pyindex 26400463eaa..f03a1a3f444 100644--- a/studio/backend/tests/test_video_families.py+++ b/studio/backend/tests/test_video_families.py@@ -240,13 +240,14 @@ def test_wan_snap_video_size_16():def test_wan_generation_defaults():- # Both Wan families default to the pipeline's 50 steps / CFG 5.0.- assert default_video_generation_params(None, "Wan-AI/Wan2.2-TI2V-5B-Diffusers") == (50, 5.0)- assert default_video_generation_params(None, "Wan-AI/Wan2.2-T2V-A14B-Diffusers") == (50, 5.0)+ # ComfyUI's templates: TI2V-5B 20 steps / CFG 5, T2V-A14B 20 steps / CFG 3.5 (Lightning LoRA off).+ assert default_video_generation_params(None, "Wan-AI/Wan2.2-TI2V-5B-Diffusers") == (20, 5.0)+ assert default_video_generation_params(None, "Wan-AI/Wan2.2-T2V-A14B-Diffusers") == (20, 3.5)+ assert default_video_generation_params("wan2.2-14b") == (20, 3.5)# A GGUF filename carrying the family name still lands on the Wan defaults.assert default_video_generation_params("wan2.2-ti2v-5b-Q4_K_M.gguf", "Wan-AI/Wan2.2-TI2V-5B-Diffusers"- ) == (50, 5.0)+ ) == (20, 5.0)def test_generation_defaults_fallback_honors_family():@@ -256,7 +257,7 @@ def test_generation_defaults_fallback_honors_family():"/models/my-clip", "/models/my-clip", fallback = (50, 5.0)) == (50, 5.0)# A recognised token still wins over the fallback.- assert default_video_generation_params("wan2.2-ti2v-5b", fallback = (8, 1.0)) == (50, 5.0)+ assert default_video_generation_params("wan2.2-ti2v-5b", fallback = (8, 1.0)) == (20, 5.0)def test_generation_defaults_wan_is_segment_not_substring():@@ -268,8 +269,8 @@ def test_generation_defaults_wan_is_segment_not_substring():"taiwan-clips.gguf", "user/taiwan-clips", fallback = (40, 4.0)) == (40, 4.0)# Genuine Wan identifiers (segment-initial, with a version suffix or separator) still match.- assert default_video_generation_params("wan2.2-ti2v-5b-Q4_K_M.gguf") == (50, 5.0)- assert default_video_generation_params(None, "Wan-AI/Wan2.2-T2V-A14B") == (50, 5.0)+ assert default_video_generation_params("wan2.2-ti2v-5b-Q4_K_M.gguf") == (20, 5.0)+ assert default_video_generation_params(None, "Wan-AI/Wan2.2-T2V-A14B") == (20, 3.5)# An "ltxv" style name still resolves to LTX (trailing letters stay free).assert default_video_generation_params("ltxv-2.3-distilled") == (8, 1.0)assert default_video_generation_params("Lightricks/LTXV-2.3") == (40, 4.0)@@ -332,10 +333,10 @@ def test_hv15_detection_and_flags():def test_hv15_generation_defaults():- # The community repacks ship a guider with guidance_scale 6.0 and the pipeline's own 50-step schedule.+ # The community repacks ship a guider with guidance_scale 6.0; ComfyUI's template samples 20 steps.assert default_video_generation_params(None, "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-480p_t2v"- ) == (50, 6.0)+ ) == (20, 6.0)def test_hv15_720p_checkpoints_never_route_to_the_480p_family():diff --git a/studio/frontend/src/features/images/image-generation-defaults.ts b/studio/frontend/src/features/images/image-generation-defaults.tsindex 8f440c27fbb..8fd65115e34 100644--- a/studio/frontend/src/features/images/image-generation-defaults.ts+++ b/studio/frontend/src/features/images/image-generation-defaults.ts@@ -11,35 +11,37 @@ const MODEL_DEFAULTS: Array<{steps: number;guidance: number;}> = [- { match: "z-image-turbo", steps: 9, guidance: 0 },+ { match: "z-image-turbo", steps: 8, guidance: 0 },// Krea 2 Raw is the undistilled base, so it must precede the distilled Krea key below.{ match: "krea-2-raw", steps: 52, guidance: 3.5 },{ match: "krea-2", steps: 8, guidance: 0 },{ match: "flux.1-schnell", steps: 4, guidance: 0 },// Kontext and the Krea dev finetune must precede generic FLUX.1.- { match: "kontext", steps: 28, guidance: 2.5 },- { match: "flux.1-krea", steps: 28, guidance: 4.5 },- { match: "flux.1", steps: 28, guidance: 3.5 },+ { match: "kontext", steps: 20, guidance: 2.5 },+ { match: "flux.1-krea", steps: 20, guidance: 3.5 },+ { match: "flux.1", steps: 20, guidance: 3.5 },// Klein base is undistilled. The generic key below covers both distilled sizes.- { match: "flux.2-klein-base", steps: 50, guidance: 4 },+ { match: "flux.2-klein-base", steps: 20, guidance: 5 },{ match: "flux.2-klein", steps: 4, guidance: 1 },- { match: "flux.2-dev", steps: 28, guidance: 4 },+ { match: "flux.2-dev", steps: 20, guidance: 4 },// Qwen-Image-2.1 and its aliases, before the generic key.- { match: "qwen-image-2.1", steps: 40, guidance: 1 },- { match: "qwen-image-21", steps: 40, guidance: 1 },- { match: "qwen_image_21", steps: 40, guidance: 1 },- { match: "qwenimage21", steps: 40, guidance: 1 },+ { match: "qwen-image-2.1", steps: 25, guidance: 1 },+ { match: "qwen-image-21", steps: 25, guidance: 1 },+ { match: "qwen_image_21", steps: 25, guidance: 1 },+ { match: "qwenimage21", steps: 25, guidance: 1 },+ { match: "qwen-image-edit", steps: 40, guidance: 4 },+ { match: "qwen-image-2512", steps: 50, guidance: 4 },{ match: "qwen-image", steps: 20, guidance: 4 },- { match: "z-image", steps: 20, guidance: 4 },- { match: "ideogram", steps: 48, guidance: 7 },+ { match: "z-image", steps: 25, guidance: 3 },+ { match: "ideogram", steps: 20, guidance: 7 },{ match: "lumina", steps: 50, guidance: 4 },{ match: "hunyuanimage", steps: 50, guidance: 3.25 },{ match: "hidream-i1-dev", steps: 28, guidance: 0 },{ match: "hidream-i1-fast", steps: 16, guidance: 0 },{ match: "hidream", steps: 50, guidance: 5 },{ match: "sdxl-turbo", steps: 3, guidance: 0 },- { match: "stable-diffusion-xl", steps: 30, guidance: 7 },- { match: "sdxl", steps: 30, guidance: 7 },+ { match: "stable-diffusion-xl", steps: 25, guidance: 7 },+ { match: "sdxl", steps: 25, guidance: 7 },];export function defaultsFor(repoId: string): {diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsxindex ea22585783c..326fe912827 100644--- a/studio/frontend/src/features/video/video-page.tsx+++ b/studio/frontend/src/features/video/video-page.tsx@@ -252,10 +252,13 @@ const MODEL_DEFAULTS: Array<{ match: string; steps: number; guidance: number }>// "distilled" before the generic "ltx": the distilled model runs at 8 steps, guidance 1.{ match: "distilled", steps: 8, guidance: 1 },{ match: "ltx", steps: 40, guidance: 4 },- // Wan2.2 pipelines default to 50 steps at CFG 5.0 (diffusers 0.39). The backend supplies the fps per family.- { match: "wan", steps: 50, guidance: 5 },- // HunyuanVideo-1.5 runs 50 steps; guidance 6 matches the guider the repo ships.- { match: "hunyuanvideo", steps: 50, guidance: 6 },+ // ComfyUI's templates for the same models. Wan2.2-T2V-A14B: 20 steps at CFG 3.5, before the generic Wan key.+ { match: "a14b", steps: 20, guidance: 3.5 },+ { match: "wan2.2-14b", steps: 20, guidance: 3.5 },+ // Wan2.2-TI2V-5B: 20 steps at CFG 5. The backend supplies the fps per family.+ { match: "wan", steps: 20, guidance: 5 },+ // HunyuanVideo-1.5 runs 20 steps; guidance 6 matches the guider the repo ships.+ { match: "hunyuanvideo", steps: 20, guidance: 6 },];function defaultsFor(repoId: string): { steps: number; guidance: number } {diff --git a/studio/frontend/tests/image-generation-defaults.test.ts b/studio/frontend/tests/image-generation-defaults.test.tsindex 5693f061710..78d115c528b 100644--- a/studio/frontend/tests/image-generation-defaults.test.ts+++ b/studio/frontend/tests/image-generation-defaults.test.ts@@ -17,8 +17,8 @@ import { readSrc } from "./helpers/kit.ts";test("distinguishes Klein base checkpoints from distilled checkpoints", () => {for (const size of ["4B", "9B"]) {assert.deepEqual(defaultsFor(`unsloth/FLUX.2-klein-base-${size}`), {- steps: 50,- guidance: 4,+ steps: 20,+ guidance: 5,});assert.deepEqual(defaultsFor(`unsloth/FLUX.2-klein-${size}`), {steps: 4,@@ -33,7 +33,7 @@ test("keeps the existing family defaults and fallback", () => {guidance: 3.5,});assert.deepEqual(defaultsFor("black-forest-labs/FLUX.1-dev"), {- steps: 28,+ steps: 20,guidance: 3.5,});assert.deepEqual(defaultsFor("local/unknown-image-model"), {@@ -158,3 +158,22 @@ test("every images-page canvas seed passes the quant provenance", () => {assert.match(call.slice(0, 400), /transformerQuantSource: status\??\.resolved\?\.transformer_quant\?\.source/);}});++test("defaults follow ComfyUI's official templates for the same model", () => {+ for (const [id, want] of [+ ["black-forest-labs/FLUX.1-dev", { steps: 20, guidance: 3.5 }],+ ["black-forest-labs/FLUX.1-Krea-dev", { steps: 20, guidance: 3.5 }],+ ["black-forest-labs/FLUX.1-Kontext-dev", { steps: 20, guidance: 2.5 }],+ ["black-forest-labs/FLUX.2-dev", { steps: 20, guidance: 4 }],+ ["Qwen/Qwen-Image-Edit-2511", { steps: 40, guidance: 4 }],+ ["Qwen/Qwen-Image-2512", { steps: 50, guidance: 4 }],+ ["Qwen/Qwen-Image", { steps: 20, guidance: 4 }],+ ["Tongyi-MAI/Z-Image-Turbo", { steps: 8, guidance: 0 }],+ // diffusers Z-Image guidance g equals ComfyUI cfg g + 1.+ ["Tongyi-MAI/Z-Image", { steps: 25, guidance: 3 }],+ ["stabilityai/stable-diffusion-xl-base-1.0", { steps: 25, guidance: 7 }],+ ["ideogram-ai/ideogram-4-fp8", { steps: 20, guidance: 7 }],+ ] as const) {+ assert.deepEqual(defaultsFor(id), want, id);+ }+});diff --git a/studio/frontend/tests/image-unified-edit.test.ts b/studio/frontend/tests/image-unified-edit.test.tsindex d1485b96f38..6bd27846eef 100644--- a/studio/frontend/tests/image-unified-edit.test.ts+++ b/studio/frontend/tests/image-unified-edit.test.ts@@ -200,16 +200,16 @@ test("prompt helpers edit the visible instruction idempotently", () => {);});-test("Qwen-Image-2.1 samples at 40 steps without guidance under every artifact name", () => {+test("Qwen-Image-2.1 samples at 25 steps without guidance under every artifact name", () => {for (const id of ["Qwen/Qwen-Image-2.1","unsloth/Qwen-Image-2.1-GGUF","unsloth/Qwen-Image-2.1-FP8",]) {- assert.deepEqual(defaultsFor(id), { steps: 40, guidance: 1 }, id);+ assert.deepEqual(defaultsFor(id), { steps: 25, guidance: 1 }, id);}assert.deepEqual(defaultsFor("Qwen/Qwen-Image-2512"), {- steps: 20,+ steps: 50,guidance: 4,});});