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 (#12616)
Daniel Hane8f30ca11d46
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.pyindex 3921b44d057..4538c6f454d 100644--- a/studio/backend/core/inference/diffusion.py+++ b/studio/backend/core/inference/diffusion.py@@ -59,6 +59,7 @@ from .diffusion_families import (_is_local_path,canonical_base,cache_holds_files,+ comfy_flow_shift_for,default_generation_params,detect_family_for_pick,excluded_model_reason,@@ -240,6 +241,14 @@ 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_guidance_schedule,+ ideogram4_comfy_mu_std,+ flux_t5_kwarg,+ true_cfg_needs_empty_negative,+)from .diffusion_denoiser_prequant import (DENOISER_COMPONENT,PIPELINE_SEED_DECLINED,@@ -6987,6 +6996,10 @@ class DiffusionBackend:)self._raise_if_load_cancelled(_load_token)+ # Before from_pipe copies the scheduler.+ apply_comfy_flow_shift(+ pipe, comfy_flow_shift_for(fam, gguf_filename, repo_id, base), 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 +9418,19 @@ 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+ # ComfyUI preset for this step count; the 7 -> 3 CFG override only at guidance 7.+ mu, std = ideogram4_comfy_mu_std(steps)+ if "mu" in call_params:+ kwargs["mu"] = mu+ if "std" in call_params:+ kwargs["std"] = 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 +9462,11 @@ 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 true CFG needs a negative present; ComfyUI encodes an empty one.+ 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 +9665,10 @@ class DiffusionBackend:chunk_kwargs["negative_prompt"] = [chunk_kwargs["negative_prompt"]] * len(chunk)+ # Per chunk, since a prompts list varies in length.+ 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..1ed651f40ca 100644--- a/studio/backend/core/inference/diffusion_families.py+++ b/studio/backend/core/inference/diffusion_families.py@@ -18,7 +18,7 @@ import sysimport tempfilefrom dataclasses import dataclass, fieldfrom pathlib import Path, PurePosixPath-from typing import NamedTuple, Optional, Sequence+from typing import Any, NamedTuple, Optional, Sequencefrom utils.paths.path_utils import is_appledouble_metadatafrom .diffusion_nvfp4_flag import nvfp4_blocked@@ -113,6 +113,10 @@ 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)+ # ComfyUI's static sigma shift; None = keep the shipped scheduler.+ comfy_flow_shift: Optional[float] = None+ # (lowercased id substring, shift) for checkpoints whose template differs; first match wins.+ comfy_flow_shift_variants: tuple[tuple[str, float], ...] = field(default_factory = tuple)# 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 +329,9 @@ _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)+ # The 2509 template samples at ModelSamplingAuraFlow 3.+ comfy_flow_shift_variants = (("qwen-image-edit-2509", 3.0),),pipeline_class = "QwenImageEditPlusPipeline",transformer_class = "QwenImageTransformer2DModel",base_repo = "Qwen/Qwen-Image-Edit-2511",@@ -342,6 +349,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 +496,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 +1141,33 @@ 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, 0.0),+ # FLUX.1 Krea dev is a FLUX.1-dev finetune, NOT a Krea-2; 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),+ # Undistilled base runs real CFG; keep before the generic distilled key.+ ("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)+ # Before the generic qwen-image key (also the two below).+ ("qwen-image-2.1", 25, 1.0),+ ("qwen-image-21", 25, 1.0),+ ("qwen_image_21", 25, 1.0),+ ("qwenimage21", 25, 1.0),+ # 2509 template: 20 / 4; the generic key is the 2511 recipe (the family base).+ ("qwen-image-edit-2509", 20, 4.0),+ ("qwen-image-edit", 40, 4.0),+ ("qwen-image-2512", 50, 4.0),("qwen-image", 20, 4.0),- ("z-image", 20, 4.0),+ # diffusers Z-Image g = ComfyUI cfg - 1 (pos + g * (pos - neg)).+ ("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,18 +1177,28 @@ _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: 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)+def comfy_flow_shift_for(fam: Any, *identifiers: Optional[str]) -> Optional[float]:+ """ComfyUI's static shift for the loaded checkpoint: the first family variant whose key is in+ an identifier (repo id, GGUF file, base repo), else the family default."""+ for identifier in identifiers:+ needle = (identifier or "").lower()+ for key, shift in getattr(fam, "comfy_flow_shift_variants", ()) or ():+ if key in needle:+ return shift+ return getattr(fam, "comfy_flow_shift", None)++def default_generation_params(*identifiers: Optional[str]) -> tuple[int, float]:"""Default ``(steps, guidance)`` for a loaded model. The first identifier naming a known modelwins (repo id, then resolved base repo), so a local-path load still resolves via its basediff --git a/studio/backend/core/inference/diffusion_flow_shift.py b/studio/backend/core/inference/diffusion_flow_shift.pynew file mode 100644index 00000000000..7d1df3fed22--- /dev/null+++ b/studio/backend/core/inference/diffusion_flow_shift.py@@ -0,0 +1,55 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Rebuild the loaded scheduler at ComfyUI's static sigma shift (shipped schedulers differ, e.g.+Qwen-Image dynamic ~2.0 + terminal stretch vs 3.1). No torch/diffusers imports."""++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):+ 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..619e81e8bf8--- /dev/null+++ b/studio/backend/core/inference/diffusion_text_length.py@@ -0,0 +1,136 @@+# 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. FLUX.1 T5 runs unmasked, so padding changes the embeddings."""++from __future__ import annotations++import math+from typing import Any, Iterable, Optional++# ComfyUI's Ideogram 4 "Default" preset; plain flow (shift 1), so "last 30%" of the CFG override 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+# ComfyUI's other presets by step count (Quality 48 == the pipeline default); any other count runs "Default".+_IDEOGRAM4_COMFY_PRESETS = {48: (0.0, 1.5), 12: (0.5, 1.75)}+_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_mu_std(steps: int) -> tuple[float, float]:+ """``(mu, std)`` of the ComfyUI preset with this step count, else the "Default" preset."""+ return _IDEOGRAM4_COMFY_PRESETS.get(int(steps), (IDEOGRAM4_COMFY_MU, IDEOGRAM4_COMFY_STD))+++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."""+ mu, std = ideogram4_comfy_mu_std(steps)+ return [+ IDEOGRAM4_COMFY_TAIL_GUIDANCE+ if sigma <= IDEOGRAM4_COMFY_TAIL_SIGMA+ else IDEOGRAM4_COMFY_GUIDANCE+ for sigma in ideogram4_sigmas(steps, width, height, mu, 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 (not ComfyUI's exact length): each new length recompiles (~14 s) / recaptures CUDA graphs.+ 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 1b7fdfce757..48ef88f4a50 100644--- a/studio/backend/core/inference/sd_cpp_backend.py+++ b/studio/backend/core/inference/sd_cpp_backend.py@@ -2237,6 +2237,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 d573b98500c..ca60e99c5ff 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,@@ -6553,6 +6554,7 @@ class VideoBackend:})+ apply_comfy_flow_shift(pipe, getattr(fam, "comfy_flow_shift", None), logger)from . import diffusion_prompt_cachediffusion_prompt_cache.install(@@ -7520,6 +7522,7 @@ class VideoBackend:),})+ 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..52e464d071a 100644--- a/studio/backend/core/inference/video_families.py+++ b/studio/backend/core/inference/video_families.py@@ -130,6 +130,8 @@ class VideoFamily:modular_workflow: Optional[str] = None# Released video and audio sigma shifts, when configurable.default_flow_shift: Optional[float] = None+ # ComfyUI's static sigma shift (None = shipped); unlike default_flow_shift, no 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 +265,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 +278,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 +301,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 +319,8 @@ _FAMILIES: tuple[VideoFamily, ...] = (transformer2_class = "WanTransformer3DModel",is_moe = True,cfg2_kwarg = "guidance_scale_2",- default_steps = 50,- default_guidance = 5.0,+ 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 +339,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 +350,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 +369,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 +380,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 +815,11 @@ 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),+ # T2V-A14B before the generic Wan key.+ ("a14b", 20, 3.5),+ ("wan2.2-14b", 20, 3.5),+ ("wan", 20, 5.0),+ ("hunyuanvideo", 20, 6.0),)diff --git a/studio/backend/tests/test_diffusion_backend.py b/studio/backend/tests/test_diffusion_backend.pyindex 2d41b06e38e..2365db529b9 100644--- a/studio/backend/tests/test_diffusion_backend.py+++ b/studio/backend/tests/test_diffusion_backend.py@@ -14420,3 +14420,158 @@ 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"+++class _T5WordTokenizer:+ 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+++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):+ """A blank negative must not silently turn Qwen-Image true 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):+ """Ideogram 4 ComfyUI preset; other guidance stays constant, 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)+++def test_generate_ideogram_step_count_picks_its_comfy_preset(fake_runtime, tmp_path):+ # 48 steps at another guidance keeps the Quality preset (std 1.5, the pipeline default), 12 is Turbo.+ backend = DiffusionBackend()+ _load_ideogram(backend, tmp_path)+ pipe = _IdeogramScheduleFakePipe()+ object.__setattr__(backend._state, "pipe", pipe)+ backend.generate(prompt = "a sloth", steps = 48, guidance = 5.0)+ call = pipe.last_kwargs+ assert call["guidance_scale"] == 5.0 and (call["mu"], call["std"]) == (0.0, 1.5)+ backend.generate(prompt = "a sloth", width = 1024, height = 1024, steps = 12, guidance = 7.0)+ call = pipe.last_kwargs+ assert (call["mu"], call["std"]) == (0.5, 1.75)+ assert len(call["guidance_schedule"]) == 12 and call["guidance_schedule"][-1] == 3.0+++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..dc5c6992a26--- /dev/null+++ b/studio/backend/tests/test_diffusion_flow_shift.py@@ -0,0 +1,89 @@+# 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 comfy_flow_shift_for, 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.0+++def test_qwen_image_edit_2509_keeps_its_template_shift():+ # Comfy-Org image_qwen_image_edit_2509 uses ModelSamplingAuraFlow 3, the 2511 template 3.1.+ fam = detect_family("Qwen/Qwen-Image-Edit-2509")+ assert fam.name == "qwen-image-edit"+ assert comfy_flow_shift_for(fam, None, "Qwen/Qwen-Image-Edit-2509", None) == 3.0+ assert (+ comfy_flow_shift_for(+ fam, "qwen-image-edit-2509-Q4_K_M.gguf", "unsloth/Qwen-Image-Edit-2509-GGUF", None+ )+ == 3.0+ )+ assert comfy_flow_shift_for(fam, None, "Qwen/Qwen-Image-Edit-2511", None) == 3.1+ assert comfy_flow_shift_for(fam, None, "unsloth/Qwen-Image-Edit-2511-GGUF", None) == 3.1+ assert comfy_flow_shift_for(detect_family("Qwen/Qwen-Image"), "Qwen/Qwen-Image") == 3.1diff --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..7db593578ff--- /dev/null+++ b/studio/backend/tests/test_diffusion_flux_t5_length.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++"""FLUX.1 T5 sequence length follows ComfyUI (floor 256, cap 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+ 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..ca06524b347 100644--- a/studio/backend/tests/test_openai_images_generations_route.py+++ b/studio/backend/tests/test_openai_images_generations_route.py@@ -36,12 +36,18 @@ 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)),+ ("Qwen/Qwen-Image-Edit-2509", (20, 4.0)),+ ("unsloth/Qwen-Image-Edit-2509-GGUF", (20, 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 +66,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 +238,11 @@ 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.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 +303,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 +642,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 b13bf51aa97..f428f87d01f 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..44442c15c08 100644--- a/studio/backend/tests/test_video_families.py+++ b/studio/backend/tests/test_video_families.py@@ -240,13 +240,13 @@ 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)+ 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 +256,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 +268,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 +332,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..fc8829ffec2 100644--- a/studio/frontend/src/features/images/image-generation-defaults.ts+++ b/studio/frontend/src/features/images/image-generation-defaults.ts@@ -11,35 +11,38 @@ 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-2509", steps: 20, guidance: 4 },+ { 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..190e46467b2 100644--- a/studio/frontend/src/features/video/video-page.tsx+++ b/studio/frontend/src/features/video/video-page.tsx@@ -252,10 +252,12 @@ 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 },+ // T2V-A14B before the generic Wan key.+ { match: "a14b", steps: 20, guidance: 3.5 },+ { match: "wan2.2-14b", steps: 20, guidance: 3.5 },+ // The backend supplies the fps per family.+ { match: "wan", steps: 20, guidance: 5 },+ { 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..2bf0db66152 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,23 @@ 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-Edit-2509", { steps: 20, 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,});});