Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: hold cudnn.benchmark off for Qwen-Image, HunyuanVideo-1.5, FLUX.1, Z-Image and SDXL (#12568)

Daniel Han45dd665624c4
diff --git a/studio/backend/core/inference/diffusion_families.py b/studio/backend/core/inference/diffusion_families.py
index 1ed651f40ca..f18ee27df7b 100644
--- a/studio/backend/core/inference/diffusion_families.py
+++ b/studio/backend/core/inference/diffusion_families.py
@@ -128,6 +128,8 @@ class DiffusionFamily:
fp16_guard: Optional[str] = None
# false only for a family whose denoiser block does not compile cleanly with regional torch.compile
supports_torch_compile: bool = True
+ # False keeps cudnn.benchmark off (as VideoFamily.cudnn_benchmark): its per-process conv pick changes pixels.
+ cudnn_benchmark: bool = True
# Optional pre-quantized transformer checkpoints as (scheme, repo_id): fetched instead of the dense bf16 (lower
# load VRAM + download).
prequant_repos: tuple[tuple[str, str], ...] = field(default_factory = tuple)
@@ -208,6 +210,7 @@ class DiffusionFamily:
_FAMILIES: tuple[DiffusionFamily, ...] = (
DiffusionFamily(
name = "flux.1",
+ cudnn_benchmark = False,
pipeline_class = "FluxPipeline",
transformer_class = "FluxTransformer2DModel",
base_repo = "black-forest-labs/FLUX.1-schnell",
@@ -373,6 +376,7 @@ _FAMILIES: tuple[DiffusionFamily, ...] = (
aliases = ("qwen_image", "qwenimage"),
# fp16 overflows to NaN latents (black images)
fp16_incompatible = True,
+ cudnn_benchmark = False,
trainable = True,
train_base_repos = ("unsloth/Qwen-Image-2512-unsloth-bnb-4bit", "Qwen/Qwen-Image"),
img2img_pipeline_class = "QwenImageImg2ImgPipeline",
@@ -496,6 +500,7 @@ _FAMILIES: tuple[DiffusionFamily, ...] = (
),
DiffusionFamily(
name = "z-image",
+ cudnn_benchmark = False,
comfy_flow_shift = 3.0, # ComfyUI shift 3 for Turbo and base (Turbo already ships 3.0)
pipeline_class = "ZImagePipeline",
transformer_class = "ZImageTransformer2DModel",
@@ -631,6 +636,8 @@ _FAMILIES: tuple[DiffusionFamily, ...] = (
# pipeline. img2img / inpaint / ControlNet are the standard SDXL pipelines. No GGUF path.
DiffusionFamily(
name = "sdxl",
+ # ~1.8% slower warm, but compiled-UNet renders then match across servers (ComfyUI's default)
+ cudnn_benchmark = False,
pipeline_class = "StableDiffusionXLPipeline",
transformer_class = "UNet2DConditionModel",
base_repo = "stabilityai/stable-diffusion-xl-base-1.0",
diff --git a/studio/backend/core/inference/diffusion_speed.py b/studio/backend/core/inference/diffusion_speed.py
index 1136f5dfe6a..f0a8071d74c 100644
--- a/studio/backend/core/inference/diffusion_speed.py
+++ b/studio/backend/core/inference/diffusion_speed.py
@@ -482,7 +482,11 @@ def apply_speed_optims(
if on_cuda:
applied["vae_fused"] = _install_fused_vae(pipe, logger)
- if on_cuda and not _cudnn_benchmark_pointless(pipe):
+ if (
+ on_cuda
+ and getattr(family, "cudnn_benchmark", True)
+ and not _cudnn_benchmark_pointless(pipe)
+ ):
applied["cudnn_benchmark"] = _enable_cudnn_benchmark(logger)
if on_cuda:
diff --git a/studio/backend/core/inference/video_families.py b/studio/backend/core/inference/video_families.py
index e3393833691..483efd29d7c 100644
--- a/studio/backend/core/inference/video_families.py
+++ b/studio/backend/core/inference/video_families.py
@@ -371,6 +371,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (
# DiT fp32 on disk (32.0 to 16.6 bf16); VAE 4.7 to 2.4; Qwen2.5-VL TE bf16 14.0 + ByT5 0.8
bf16_components_gb = (16.6, 14.8, 2.4),
fp16_guard = "native",
+ cudnn_benchmark = False,
),
# The 720p t2v repack: same architecture and footprint as the 480p entry, only the trained resolution differs. Its
# own family so a 720p load defaults to 720p sizes; the full-path alias outranks the generic token.
@@ -397,6 +398,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (
resolution_presets = ((1280, 720), (720, 1280), (960, 960)),
bf16_components_gb = (16.6, 14.8, 2.4),
fp16_guard = "native",
+ cudnn_benchmark = False,
),
)
diff --git a/studio/backend/tests/test_diffusion_speed.py b/studio/backend/tests/test_diffusion_speed.py
index 6043df89238..71a5c000ef9 100644
--- a/studio/backend/tests/test_diffusion_speed.py
+++ b/studio/backend/tests/test_diffusion_speed.py
@@ -565,6 +565,28 @@ def test_speed_default_skips_cudnn_benchmark_on_rocm(monkeypatch, hip, version):
assert torch.backends.cudnn.benchmark is False
+def test_speed_default_respects_family_cudnn_benchmark_opt_out(monkeypatch):
+ torch = _stub_torch(monkeypatch)
+ family = types.SimpleNamespace(supports_torch_compile = True, cudnn_benchmark = False)
+ applied = apply_speed_optims(
+ _Pipe(with_compile = True), _target(), is_gguf = False, family = family, speed_mode = SPEED_DEFAULT
+ )
+ assert applied["cudnn_benchmark"] is False
+ assert torch.backends.cudnn.benchmark is False
+ family = types.SimpleNamespace(supports_torch_compile = True, cudnn_benchmark = True)
+ applied = apply_speed_optims(
+ _Pipe(with_compile = True), _target(), is_gguf = False, family = family, speed_mode = SPEED_DEFAULT
+ )
+ assert applied["cudnn_benchmark"] is True and torch.backends.cudnn.benchmark is True
+
+
+def test_cudnn_benchmark_opt_out_image_families():
+ # Unmeasured families keep the benchmark.
+ from core.inference.diffusion_families import _FAMILIES
+ off = {fam.name for fam in _FAMILIES if not fam.cudnn_benchmark}
+ assert off == {"qwen-image", "flux.1", "z-image", "sdxl"}
+
+
def test_speed_max_enables_tf32_and_fused_qkv(monkeypatch):
torch = _stub_torch(monkeypatch)
pipe = _Pipe(with_compile = True, with_fuse = True)
diff --git a/studio/backend/tests/test_video_backend.py b/studio/backend/tests/test_video_backend.py
index 9f57cf2ff3e..9b5635c2ccb 100644
--- a/studio/backend/tests/test_video_backend.py
+++ b/studio/backend/tests/test_video_backend.py
@@ -12587,16 +12587,46 @@ def test_wan_load_turns_cudnn_benchmark_back_off(fake_runtime, monkeypatch):
def test_cudnn_benchmark_opt_out_families():
- # Every family on the Wan VAE opts out (reproducibility), LTX-2 keeps its re-tune opt-out, the rest keep the benchmark.
+ # Every family on the Wan or HunyuanVideo-1.5 VAE opts out (reproducibility), LTX-2 keeps its re-tune opt-out.
from core.inference.video_families import _FAMILIES
off = {fam.name for fam in _FAMILIES if not fam.cudnn_benchmark}
- assert {"wan2.2-ti2v-5b", "wan2.2-t2v-a14b", "ltx-2"} <= off
+ assert {
+ "wan2.2-ti2v-5b",
+ "wan2.2-t2v-a14b",
+ "ltx-2",
+ "hunyuanvideo-1.5",
+ "hunyuanvideo-1.5-720p",
+ } <= off
assert all(
- fam.vae_force_fp32 or fam.name == "ltx-2" for fam in _FAMILIES if not fam.cudnn_benchmark
+ fam.vae_force_fp32 or fam.name == "ltx-2" or fam.name.startswith("hunyuanvideo-1.5")
+ for fam in _FAMILIES
+ if not fam.cudnn_benchmark
)
+def test_hunyuanvideo15_load_keeps_cudnn_benchmark_off(fake_runtime, monkeypatch):
+ from core.inference import video as video_mod, video_ltx2
+
+ seen = []
+
+ def fake_speed(view, target, **kw):
+ seen.append(getattr(kw.get("family"), "cudnn_benchmark", True))
+ return {"cudnn_benchmark": True, "compiled": False}
+
+ monkeypatch.setattr(video_mod, "apply_speed_optims", fake_speed)
+ calls = []
+ monkeypatch.setattr(video_ltx2, "disable_cudnn_benchmark", lambda: calls.append(1) or True)
+ backend = VideoBackend()
+ status = backend.load_pipeline(
+ "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-480p_t2v", model_kind = "pipeline"
+ )
+ assert status["family"] == "hunyuanvideo-1.5"
+ assert seen and seen[0] is False
+ assert calls == [1]
+ assert "cudnn_benchmark" not in backend.status()["speed_optims"]
+
+
@pytest.mark.parametrize(
"plan_fields, filename, direct, te_direct",
[