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: HunyuanVideo-1.5 padded-text trim on the max speed tier (#11824)

Daniel Hane874b935e981
diff --git a/studio/backend/core/inference/diffusion_attention.py b/studio/backend/core/inference/diffusion_attention.py
index a6829b901fe..bfd24252c99 100644
--- a/studio/backend/core/inference/diffusion_attention.py
+++ b/studio/backend/core/inference/diffusion_attention.py
@@ -701,10 +701,8 @@ def _warn(logger: Any, what: str, exc: Exception) -> None:
# eager forward pre-hook (outside the compiled blocks): drop the all-zero image stream (t2v), trim the mllm/byt5
# streams to their globally-valid columns, and, when nothing partially-padded remains, flag the DiT so the processor
# skips the dense mask and runs the fused path. Mixed-padding batches fall back to the stock dense mask. SHAPE NOTE:
-# the trimmed text length is prompt-dependent, so the compiled blocks see a new shape per prompt. Free on the default
-# speed tier (dynamic=True) but not on ``max`` (dynamic=False), where each length is its own graph and a fullgraph
-# region hard-errors at dynamo's recompile limit. The caller therefore only installs the trim on a tier that compiles
-# dynamically; see the call site in video.py.
+# trimmed length varies per prompt; safe because ``max`` compiles with dynamic=None (one generalising recompile). A
+# static (dynamic=False) compile would recompile per prompt length and hit dynamo's recompile limit under fullgraph.
_HUNYUAN15_TRANSFORMER_CLS = "HunyuanVideo15Transformer3DModel"
_HUNYUAN15_PROCESSOR_CLS = "HunyuanVideo15AttnProcessor2_0"
_NULL_ATTN_FLAG = "_unsloth_null_attn_mask"
diff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.py
index 733a214e87b..5adeeb2dcb4 100644
--- a/studio/backend/core/inference/video.py
+++ b/studio/backend/core/inference/video.py
@@ -4487,11 +4487,10 @@ class VideoBackend:
attention_engaged = None
# HunyuanVideo-1.5 only, and once for the whole pipe (the installer fans out over every denoiser DiT itself).
# Before apply_attention_backend below, so the requested kernel pins onto the new processors. Held off on
- # SPEED_OFF (which must stay bit-identical) and on SPEED_MAX (its blocks compile static until a dimension
- # changes, and the trimmed text length varies per prompt, so the first prompts would each recompile).
+ # SPEED_OFF, which must stay bit-identical.
attention_trim_engaged = (
install_hunyuan_attention_trim(pipe, fam, logger = logger)
- if effective_speed not in (SPEED_OFF, SPEED_MAX)
+ if effective_speed != SPEED_OFF
else False
)
# Sets a flag the pipelines read when they first build their frequency tables, so it need only happen before
diff --git a/studio/backend/tests/test_video_backend.py b/studio/backend/tests/test_video_backend.py
index 1d644a25eb3..ea67c76a012 100644
--- a/studio/backend/tests/test_video_backend.py
+++ b/studio/backend/tests/test_video_backend.py
@@ -5546,18 +5546,27 @@ def test_attention_trim_installed_and_reported(fake_runtime, monkeypatch):
assert "hunyuan_attn_trim" in status["speed_optims"]
-def test_attention_trim_skipped_for_static_shape_and_off_tiers(fake_runtime, monkeypatch):
- # speed=off must stay bit-identical, and speed=max compiles the blocks with dynamic=False,
- # where the prompt-dependent trimmed text length would make every prompt a fresh graph.
- for mode in ("off", "max"):
- calls = _trim_spy(monkeypatch)
- backend = VideoBackend()
- status = backend.load_pipeline(
- "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", speed_mode = mode
- )
- assert status["loaded"] is True, mode
- assert calls == [], mode
- assert "hunyuan_attn_trim" not in status["speed_optims"], mode
+def test_attention_trim_skipped_on_the_off_tier(fake_runtime, monkeypatch):
+ calls = _trim_spy(monkeypatch)
+ backend = VideoBackend()
+ status = backend.load_pipeline(
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", speed_mode = "off"
+ )
+ assert status["loaded"] is True
+ assert calls == []
+ assert "hunyuan_attn_trim" not in status["speed_optims"]
+
+
[email protected]("mode", ["eager", "default", "max"])
+def test_attention_trim_installed_on_every_speed_tier(fake_runtime, monkeypatch, mode):
+ calls = _trim_spy(monkeypatch)
+ backend = VideoBackend()
+ status = backend.load_pipeline(
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", speed_mode = mode
+ )
+ assert status["loaded"] is True
+ assert len(calls) == 1
+ assert "hunyuan_attn_trim" in status["speed_optims"]
def test_every_video_fetch_resolves_both_cache_roots():