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: auto step cache (FBCache) only on the max speed tier (#11791)

Daniel Han8a24eb07141c
diff --git a/scripts/image_speedmem_bench.py b/scripts/image_speedmem_bench.py
index 6937281b4c2..bf30d0c80ed 100644
--- a/scripts/image_speedmem_bench.py
+++ b/scripts/image_speedmem_bench.py
@@ -56,7 +56,7 @@ _CONFIGS: dict[str, dict[str, Any]] = {
"compile": dict(te = "none", speed = "default", attn = "auto", cache = "off"),
# max tier (max-autotune regional compile + TF32 + fused QKV), uncached
"speedmax": dict(te = "none", speed = "max", attn = "auto", cache = "off"),
- # default tier + FBCache (the auto path for 20+ step schedules)
+ # default tier + explicit FBCache (auto engages it only on the max tier)
"fbcache": dict(te = "none", speed = "default", attn = "auto", cache = "fbcache"),
# FBCache without compile: isolates the cache's drift from the compile floor
"fbcache_eager": dict(te = "none", speed = "eager", attn = "auto", cache = "fbcache"),
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py
index b976969570b..89d88ebd30d 100644
--- a/studio/backend/core/inference/diffusion.py
+++ b/studio/backend/core/inference/diffusion.py
@@ -160,12 +160,14 @@ from .diffusion_batched import (
from .diffusion_cache import (
FBCACHE_MIN_STEPS,
TC_AUTO,
- TC_FBCACHE,
apply_step_cache,
+ auto_step_cache_allowed,
effective_denoise_steps,
effective_request_strength,
maybe_toggle_step_cache,
normalize_transformer_cache,
+ resolve_auto_step_cache,
+ step_cache_supported,
)
from .diffusion_precision import (
TE_QUANT_FP8,
@@ -957,9 +959,8 @@ class _LoadState:
attention_backend: Optional[str] = None
# Caller original attention request, so deferred engagement re-runs the same selection.
attention_request: Optional[str] = None
- # Step cache engaged ("fbcache") or None. Opt-in, for many-step models.
transformer_cache: Optional[str] = None
- # AUTO: generate() toggles FBCache across FBCACHE_MIN_STEPS; an explicit request never toggles
+ # Auto only: generate() toggles it across FBCACHE_MIN_STEPS; explicit never toggles
cache_auto: bool = False
# Inputs the generation-time toggle re-applies (quantised threshold + override).
cache_quant_active: bool = False
@@ -5595,9 +5596,10 @@ class DiffusionBackend:
)
self._raise_if_load_cancelled(_load_token)
# Step caching (First-Block-Cache), also before compile: reuses the transformer tail across steps and
- # drops compile fullgraph. Tri-state: unset/auto -> FBCACHE_MIN_STEPS policy; off/fbcache pinned.
+ # drops compile fullgraph. Tri-state: off/fbcache pinned; unset/auto only on max, by FBCACHE_MIN_STEPS.
cache_request = normalize_transformer_cache(transformer_cache)
cache_auto = transformer_cache is None or cache_request == TC_AUTO
+ cache_auto_live = cache_auto and auto_step_cache_allowed(effective_speed)
cache_quant_active = transformer_quant_engaged is not None or bool(
gguf_filename
)
@@ -5606,7 +5608,7 @@ class DiffusionBackend:
default_steps, _ = default_generation_params(
gguf_filename, repo_id, base, fam.name
)
- cache_request = TC_FBCACHE if default_steps >= FBCACHE_MIN_STEPS else None
+ cache_request = resolve_auto_step_cache(effective_speed, default_steps)
cache_engaged = apply_step_cache(
pipe,
mode = cache_request,
@@ -5619,17 +5621,25 @@ class DiffusionBackend:
logger = logger,
)
self._raise_if_load_cancelled(_load_token)
- # An auto decision can flip at generation time, but only on a cache-capable transformer
- cache_may_toggle = cache_auto and callable(
- getattr(getattr(pipe, "transformer", None), "enable_cache", None)
+ # Arm only where FBCache can engage: a live toggle drops fullgraph and retries every generation.
+ cache_may_toggle = cache_auto_live and (
+ cache_engaged is not None
+ or (cache_request is None and step_cache_supported(pipe, logger = logger))
)
if cache_auto:
- if cache_engaged:
+ if not cache_auto_live:
+ # Only name the max tier where it would help: SDXL / LTX-2 never cache on any tier.
+ cache_reason = (
+ "auto: step caching engages on the max speed tier only"
+ if step_cache_supported(pipe, logger = logger)
+ else "auto: model does not support step caching"
+ )
+ elif cache_engaged:
cache_reason = (
f"auto: {default_steps}-step default schedule reaches "
f"{FBCACHE_MIN_STEPS}; re-checked per generation"
)
- elif cache_request is not None:
+ elif cache_request is not None or not cache_may_toggle:
cache_reason = "auto: model does not support step caching"
else:
cache_reason = (
diff --git a/studio/backend/core/inference/diffusion_cache.py b/studio/backend/core/inference/diffusion_cache.py
index e18d269aa63..1ad2603608d 100644
--- a/studio/backend/core/inference/diffusion_cache.py
+++ b/studio/backend/core/inference/diffusion_cache.py
@@ -11,9 +11,8 @@ diffusers ships it natively (``transformer.enable_cache(FirstBlockCacheConfig(..
Measured on Flux.1-dev (28 steps, 1024px, B200): ~1.4x on top of torch.compile (2.83 -> 2.03 s)
at LPIPS ~0.08 -- deep inside the speed-for-quality bar.
-OFF by default: the win scales with step count, so a few-step distilled model (Z-Image-Turbo
-~8 steps) has almost no headroom and caching is for many-step models (Flux / Qwen-Image). It
-composes with torch.compile only at ``fullgraph=False`` (the cache's compiler-disabled decision
+Explicit ``fbcache`` works on every tier; unset / ``auto`` engages only on ``max`` with 20+ steps.
+It composes with torch.compile only at ``fullgraph=False`` (the cache's compiler-disabled decision
is a graph break), which the speed layer switches to automatically. Best-effort: an incompatible
model is caught and the load proceeds uncached. torch / diffusers imported lazily.
"""
@@ -36,6 +35,20 @@ QUANT_FBCACHE_THRESHOLD = 0.12
# qualify, distilled turbo never does).
FBCACHE_MIN_STEPS = 20
+# == diffusion_speed.SPEED_MAX, spelled out to keep this module import-free.
+AUTO_STEP_CACHE_TIER = "max"
+
+
+def auto_step_cache_allowed(speed_mode: Optional[str]) -> bool:
+ """Takes the EFFECTIVE speed tier."""
+ return speed_mode == AUTO_STEP_CACHE_TIER
+
+
+def resolve_auto_step_cache(speed_mode: Optional[str], default_steps: int) -> Optional[str]:
+ if auto_step_cache_allowed(speed_mode) and int(default_steps) >= FBCACHE_MIN_STEPS:
+ return TC_FBCACHE
+ return None
+
def normalize_transformer_cache(value: Optional[str]) -> Optional[str]:
"""Lower/strip a cache mode; None / "" / "none" / "off" -> None, "auto" -> TC_AUTO (loader
@@ -301,6 +314,47 @@ def _pipeline_opens_cache_context(pipe: Any) -> bool:
return "cache_context(" in src
+def _transformer_blocks_registered(transformer: Any, logger: Any = None) -> bool:
+ """True when the registry cannot be read, so enable_cache stays the judge."""
+ try:
+ import torch
+ from diffusers.hooks._common import _ALL_TRANSFORMER_BLOCK_IDENTIFIERS
+ from diffusers.hooks._helpers import TransformerBlockRegistry
+ except Exception: # noqa: BLE001 - no registry to ask
+ return True
+ named_children = getattr(transformer, "named_children", None)
+ if not callable(named_children):
+ return True
+ register_unregistered_transformer_blocks(logger)
+ blocks = [
+ getattr(block, "_orig_mod", block)
+ for name, child in named_children()
+ if name in _ALL_TRANSFORMER_BLOCK_IDENTIFIERS and isinstance(child, torch.nn.ModuleList)
+ for block in child
+ ]
+ # FBCache needs a head and a tail block.
+ if len(blocks) < 2:
+ return False
+ try:
+ for cls in {type(block) for block in blocks}:
+ TransformerBlockRegistry.get(cls)
+ except Exception: # noqa: BLE001 - unregistered, or the registry itself failed to load
+ return False
+ return True
+
+
+def step_cache_supported(pipe: Any, *, logger: Any = None) -> bool:
+ """Mirrors apply_step_cache's refusals for an auto request, without engaging the cache."""
+ transformer = getattr(pipe, "transformer", None)
+ if transformer is None or not callable(getattr(transformer, "enable_cache", None)):
+ return False
+ if not _pipeline_opens_cache_context(pipe):
+ return False
+ if _reuses_prefix_kv(pipe, transformer):
+ return False
+ return _transformer_blocks_registered(transformer, logger)
+
+
def install_fbcache_length_guard() -> bool:
"""Make First-Block-Cache recompute, instead of raise, when the block sequence length changes.
diff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.py
index fce79d8d0da..58c06f7f3f4 100644
--- a/studio/backend/core/inference/video.py
+++ b/studio/backend/core/inference/video.py
@@ -55,10 +55,12 @@ from .diffusion_attention import (
from .diffusion_cache import (
FBCACHE_MIN_STEPS,
TC_AUTO,
- TC_FBCACHE,
apply_step_cache,
+ auto_step_cache_allowed,
maybe_toggle_step_cache,
normalize_transformer_cache,
+ resolve_auto_step_cache,
+ step_cache_supported,
)
from .diffusion_device import (
DiffusionDeviceTarget,
@@ -824,8 +826,7 @@ class _VideoLoadState:
backend_flags: Optional[dict] = None
attention_backend: Optional[str] = None
transformer_cache: Optional[str] = None
- # AUTO on a cache-capable DiT: generate() toggles FBCache across FBCACHE_MIN_STEPS; an explicit request is never
- # toggled.
+ # Auto only: generate() toggles it across FBCACHE_MIN_STEPS; explicit never toggles.
cache_auto: bool = False
# Inputs the generation-time toggle re-applies (quantised threshold + override).
cache_quant_active: bool = False
@@ -4442,16 +4443,16 @@ class VideoBackend:
"(quantized transformer must be compiled; eager is ~30x slower)"
)
effective_speed = SPEED_DEFAULT
- # Step cache tri-state: unset/"auto" -> FBCACHE_MIN_STEPS policy (re-checked per generation); "off"/"fbcache"
- # pinned. Run per expert.
+ # "off"/"fbcache" pinned; unset/"auto" only on max, by FBCACHE_MIN_STEPS. Run per expert.
cache_request = normalize_transformer_cache(transformer_cache)
cache_auto = transformer_cache is None or cache_request == TC_AUTO
+ cache_auto_live = cache_auto and auto_step_cache_allowed(effective_speed)
# GGUF and torchao-quantised DiTs need the higher threshold to trigger over quant noise
cache_quant_active = kind == "gguf" or transformer_quant_engaged is not None
default_cache_steps: Optional[int] = None
if cache_auto:
default_cache_steps, _ = default_video_generation_params(gguf_filename, repo_id, base)
- cache_request = TC_FBCACHE if default_cache_steps >= FBCACHE_MIN_STEPS else None
+ cache_request = resolve_auto_step_cache(effective_speed, default_cache_steps)
cache_engaged = None
for view in views:
engaged = apply_step_cache(
@@ -4465,17 +4466,25 @@ class VideoBackend:
)
if view is pipe:
cache_engaged = engaged
- # The auto decision can flip at generation time, but only on a cache-capable DiT.
- cache_may_toggle = cache_auto and callable(
- getattr(getattr(pipe, "transformer", None), "enable_cache", None)
+ # Arm only where FBCache can engage: a live toggle drops fullgraph and retries every generation.
+ cache_may_toggle = cache_auto_live and (
+ cache_engaged is not None
+ or (cache_request is None and step_cache_supported(pipe, logger = logger))
)
if cache_auto:
- if cache_engaged:
+ if not cache_auto_live:
+ # Only name the max tier where it would help: SDXL / LTX-2 never cache on any tier.
+ cache_reason = (
+ "auto: step caching engages on the max speed tier only"
+ if step_cache_supported(pipe, logger = logger)
+ else "auto: model does not support step caching"
+ )
+ elif cache_engaged:
cache_reason = (
f"auto: {default_cache_steps}-step default schedule reaches "
f"{FBCACHE_MIN_STEPS}; re-checked per generation"
)
- elif cache_request is not None:
+ elif cache_request is not None or not cache_may_toggle:
cache_reason = "auto: model does not support step caching"
else:
cache_reason = (
diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.py
index 54342cf2867..f1a84494804 100644
--- a/studio/backend/models/inference.py
+++ b/studio/backend/models/inference.py
@@ -3888,12 +3888,12 @@ class DiffusionLoadRequest(BaseModel):
)
transformer_cache: Optional[Literal["off", "fbcache"]] = Field(
None,
- description = "Opt-in step caching (off by default). fbcache = First-Block-Cache: "
- "reuse the transformer tail across denoise steps when the first block's residual "
- "barely changes (~1.4x on Flux 28-step at LPIPS ~0.08). For MANY-step models "
- "(Flux / Qwen-Image); leave off for few-step distilled models (e.g. Z-Image-Turbo), "
- "which have no caching headroom. Composes with compile (drops fullgraph "
- "automatically); incompatible models run uncached.",
+ description = "Step caching. fbcache = First-Block-Cache: reuse the transformer tail "
+ "across denoise steps when the first block's residual barely changes (~1.4x on Flux "
+ "28-step at LPIPS ~0.08). Unset = auto: engages only on speed_mode=max with a 20+ step "
+ "schedule, otherwise uncached. An explicit fbcache engages on every speed tier; off "
+ "never caches. Composes with compile (drops fullgraph automatically); incompatible "
+ "models run uncached.",
)
transformer_cache_threshold: Optional[float] = Field(
None,
@@ -4855,10 +4855,10 @@ class VideoLoadRequest(BaseModel):
)
transformer_cache: Optional[Literal["off", "fbcache"]] = Field(
None,
- description = "Opt-in step caching (off by default). fbcache = First-Block-Cache: "
- "reuse the transformer tail across denoise steps when the first block's residual "
- "barely changes. Engages on many-step schedules only; incompatible models run "
- "uncached.",
+ description = "Step caching. fbcache = First-Block-Cache: reuse the transformer tail "
+ "across denoise steps when the first block's residual barely changes. Unset = auto: "
+ "engages only on speed_mode=max with a 20+ step schedule, otherwise uncached. An "
+ "explicit fbcache engages on every speed tier; incompatible models run uncached.",
)
transformer_cache_threshold: Optional[float] = Field(
None,
diff --git a/studio/backend/tests/test_diffusion_backend.py b/studio/backend/tests/test_diffusion_backend.py
index c63eef48ca6..0dd91819f9f 100644
--- a/studio/backend/tests/test_diffusion_backend.py
+++ b/studio/backend/tests/test_diffusion_backend.py
@@ -12067,6 +12067,104 @@ def test_a_prequant_repo_missing_its_artifact_marks_the_plan_incomplete(monkeypa
assert "prequant artifact missing" in str(failures[0])
+def _record_step_cache(
+ monkeypatch,
+ *,
+ supported = True,
+ engages = True,
+):
+ calls = {"apply": [], "toggle": []}
+
+ def _apply(pipe, *, mode, **kwargs):
+ calls["apply"].append(mode)
+ return mode if (mode == "fbcache" and engages) else None
+
+ def _toggle(pipe, *, steps, **kwargs):
+ calls["toggle"].append(steps)
+ return "fbcache" if steps >= 20 else None
+
+ monkeypatch.setattr("core.inference.diffusion.apply_step_cache", _apply)
+ monkeypatch.setattr("core.inference.diffusion.maybe_toggle_step_cache", _toggle)
+ monkeypatch.setattr(
+ "core.inference.diffusion.step_cache_supported", lambda pipe, logger = None: supported
+ )
+ return calls
+
+
[email protected]("speed_mode", [None, "off", "eager", "default"])
+def test_image_step_cache_auto_stays_off_below_max(fake_runtime, tmp_path, monkeypatch, speed_mode):
+ calls = _record_step_cache(monkeypatch)
+ backend = _loaded_backend(tmp_path, family_override = "qwen-image", speed_mode = speed_mode)
+ status = backend.status()
+ assert calls["apply"] == [None]
+ assert status["transformer_cache"] is None
+ assert status["resolved"]["transformer_cache"]["source"] == "auto"
+ assert "max speed tier" in status["resolved"]["transformer_cache"]["reason"]
+ assert backend._state.cache_auto is False
+ backend.generate(prompt = "a sloth", steps = 30)
+ assert calls["toggle"] == []
+ assert backend.status()["transformer_cache"] is None
+
+
+def test_image_step_cache_auto_engages_on_max(fake_runtime, tmp_path, monkeypatch):
+ calls = _record_step_cache(monkeypatch)
+ backend = _loaded_backend(tmp_path, family_override = "qwen-image", speed_mode = "max")
+ assert calls["apply"] == ["fbcache"]
+ assert backend.status()["transformer_cache"] == "fbcache"
+ assert backend._state.cache_auto is True
+ backend.generate(prompt = "a sloth", steps = 8)
+ assert calls["toggle"] == [8]
+ assert backend.status()["transformer_cache"] is None
+
+
+def test_image_explicit_step_cache_is_honoured_on_the_default_tier(
+ fake_runtime, tmp_path, monkeypatch
+):
+ calls = _record_step_cache(monkeypatch)
+ backend = _loaded_backend(
+ tmp_path, family_override = "qwen-image", speed_mode = "default", transformer_cache = "fbcache"
+ )
+ assert calls["apply"] == ["fbcache"]
+ assert backend.status()["transformer_cache"] == "fbcache"
+ assert backend._state.cache_auto is False
+ backend.generate(prompt = "a sloth", steps = 8)
+ assert calls["toggle"] == []
+
+
+def test_image_auto_toggle_armed_only_where_the_cache_can_engage(
+ fake_runtime, tmp_path, monkeypatch
+):
+ _record_step_cache(monkeypatch, engages = False)
+ backend = _loaded_backend(tmp_path, family_override = "qwen-image", speed_mode = "max")
+ assert backend._state.cache_auto is False
+ assert (
+ backend.status()["resolved"]["transformer_cache"]["reason"]
+ == "auto: model does not support step caching"
+ )
+ backend.unload()
+
+ turbo = dict(
+ gguf_filename = "z-image-turbo-Q4_K_M.gguf",
+ base_repo = "Tongyi-MAI/Z-Image-Turbo",
+ speed_mode = "max",
+ )
+ for supported in (False, True):
+ _record_step_cache(monkeypatch, supported = supported)
+ backend = _loaded_backend(tmp_path, **turbo)
+ assert backend.status()["transformer_cache"] is None
+ assert backend._state.cache_auto is supported
+ backend.unload()
+
+
+def test_image_auto_below_max_names_an_uncacheable_model(fake_runtime, tmp_path, monkeypatch):
+ _record_step_cache(monkeypatch, supported = False)
+ backend = _loaded_backend(tmp_path, family_override = "qwen-image", speed_mode = "default")
+ assert (
+ backend.status()["resolved"]["transformer_cache"]["reason"]
+ == "auto: model does not support step caching"
+ )
+
+
def test_unload_drains_pinned_host_memory_after_the_pipeline_is_gone(
fake_runtime, tmp_path, monkeypatch
):
diff --git a/studio/backend/tests/test_diffusion_cache.py b/studio/backend/tests/test_diffusion_cache.py
index afdc408f5c3..1e7bc6caec4 100644
--- a/studio/backend/tests/test_diffusion_cache.py
+++ b/studio/backend/tests/test_diffusion_cache.py
@@ -1315,3 +1315,28 @@ def test_the_hook_probe_sees_the_names_the_low_level_api_installs(monkeypatch):
modules = lambda block = block: [_types.SimpleNamespace(), block]
)
assert _first_block_cache_is_hooked(hooked) is True
+
+
+def test_auto_tier_is_the_speed_layers_max():
+ from core.inference.diffusion_speed import SPEED_MAX
+ assert dc.AUTO_STEP_CACHE_TIER == SPEED_MAX
+
+
[email protected]("tier", ["off", "eager", "default", None])
+def test_auto_resolves_uncached_below_max(tier):
+ assert not dc.auto_step_cache_allowed(tier)
+ assert dc.resolve_auto_step_cache(tier, 50) is None
+
+
+def test_auto_resolves_fbcache_on_max_at_the_step_bar():
+ assert dc.resolve_auto_step_cache("max", dc.FBCACHE_MIN_STEPS) == TC_FBCACHE
+ assert dc.resolve_auto_step_cache("max", dc.FBCACHE_MIN_STEPS - 1) is None
+
+
+def test_step_cache_supported_mirrors_the_engage_refusals(monkeypatch):
+ _stub_diffusers(monkeypatch)
+ assert dc.step_cache_supported(_pipe(_MixinTransformer()))
+ assert not dc.step_cache_supported(_pipe(_NonCacheMixinTransformer()))
+ assert not dc.step_cache_supported(_NoCtxPipe(_MixinTransformer()))
+ assert not dc.step_cache_supported(_PrefixKVPipe(_PrefixKVTransformer()))
+ assert not dc.step_cache_supported(types.SimpleNamespace(transformer = None))
diff --git a/studio/backend/tests/test_diffusion_cache_block_registry.py b/studio/backend/tests/test_diffusion_cache_block_registry.py
index 96aabf1cd06..c26bdbf6b01 100644
--- a/studio/backend/tests/test_diffusion_cache_block_registry.py
+++ b/studio/backend/tests/test_diffusion_cache_block_registry.py
@@ -58,3 +58,25 @@ def test_registration_is_idempotent_and_never_overwrites_diffusers_own():
before = registry.get(QwenImageTransformerBlock)
dc.register_unregistered_transformer_blocks()
assert registry.get(QwenImageTransformerBlock) is before
+
+
+def test_step_cache_probe_refuses_unregistered_blocks():
+ registry, _ = _registry_and_block()
+ import torch
+ from diffusers.hooks._helpers import TransformerBlockMetadata
+
+ class _Block(torch.nn.Module):
+ def forward(self, x):
+ return x
+
+ class _Transformer(torch.nn.Module):
+ def __init__(self):
+ super().__init__()
+ self.transformer_blocks = torch.nn.ModuleList([_Block(), _Block()])
+
+ assert not dc._transformer_blocks_registered(_Transformer())
+ registry.register(model_class = _Block, metadata = TransformerBlockMetadata(0, None))
+ try:
+ assert dc._transformer_blocks_registered(_Transformer())
+ finally:
+ registry._registry.pop(_Block, None)
diff --git a/studio/backend/tests/test_video_backend.py b/studio/backend/tests/test_video_backend.py
index ea67c76a012..648dc72baba 100644
--- a/studio/backend/tests/test_video_backend.py
+++ b/studio/backend/tests/test_video_backend.py
@@ -1950,9 +1950,10 @@ def test_video_explicit_quant_is_honoured_while_resident(fake_runtime, monkeypat
def test_video_step_cache_auto_from_default_schedule(fake_runtime, tmp_path):
- # Unset step cache is AUTO, from the model's default schedule: Wan's 50-step default engages FBCache, LTX's 8-step does not.
backend = VideoBackend()
- status = backend.load_pipeline("Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline")
+ status = backend.load_pipeline(
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", speed_mode = "max"
+ )
assert status["transformer_cache"] == "fbcache"
assert status["resolved"]["transformer_cache"]["source"] == "auto"
backend.unload()
@@ -1963,12 +1964,63 @@ def test_video_step_cache_auto_from_default_schedule(fake_runtime, tmp_path):
gguf_filename = "ltx-2.3-22b-distilled-1.1-Q4_K_M.gguf",
base_repo = "Lightricks/LTX-2",
family_override = "ltx-2",
+ speed_mode = "max",
)
assert status2["transformer_cache"] is None
assert status2["resolved"]["transformer_cache"]["source"] == "auto"
backend.unload()
[email protected]("speed_mode", [None, "default", "eager", "off"])
+def test_video_step_cache_auto_stays_off_below_max(fake_runtime, speed_mode):
+ backend = VideoBackend()
+ status = backend.load_pipeline(
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", speed_mode = speed_mode
+ )
+ assert status["transformer_cache"] is None
+ assert status["resolved"]["transformer_cache"]["source"] == "auto"
+ assert "max speed tier" in status["resolved"]["transformer_cache"]["reason"]
+ assert backend._state.cache_auto is False
+ backend.generate(prompt = "a sloth", steps = 30)
+ assert backend.status()["transformer_cache"] is None
+ backend.unload()
+
+
+def test_video_explicit_step_cache_is_honoured_on_the_default_tier(fake_runtime):
+ backend = VideoBackend()
+ status = backend.load_pipeline(
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", transformer_cache = "fbcache"
+ )
+ assert status["speed_mode"] == "default"
+ assert status["transformer_cache"] == "fbcache"
+ assert backend._state.cache_auto is False
+ backend.generate(prompt = "a sloth", steps = 8)
+ assert backend.status()["transformer_cache"] == "fbcache"
+ backend.unload()
+
+
+def test_video_auto_toggle_not_armed_when_the_dit_cannot_cache(fake_runtime, tmp_path, monkeypatch):
+ monkeypatch.setattr(
+ "core.inference.video.step_cache_supported", lambda pipe, logger = None: False
+ )
+ (tmp_path / "ltx-2.3-22b-distilled-1.1-Q4_K_M.gguf").write_bytes(b"w")
+ backend = VideoBackend()
+ status = backend.load_pipeline(
+ str(tmp_path),
+ gguf_filename = "ltx-2.3-22b-distilled-1.1-Q4_K_M.gguf",
+ base_repo = "Lightricks/LTX-2",
+ family_override = "ltx-2",
+ speed_mode = "max",
+ )
+ assert status["transformer_cache"] is None
+ assert backend._state.cache_auto is False
+ assert (
+ status["resolved"]["transformer_cache"]["reason"]
+ == "auto: model does not support step caching"
+ )
+ backend.unload()
+
+
def test_video_gguf_status_reports_selected_quant_instead_of_only_compute_dtype(
fake_runtime, tmp_path
):
@@ -2003,7 +2055,9 @@ def test_video_status_response_carries_gguf_variant():
def test_video_step_cache_auto_toggles_on_actual_steps(fake_runtime):
# The AUTO decision follows each generation's ACTUAL step count; an explicit "off" never toggles.
backend = VideoBackend()
- backend.load_pipeline("Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline")
+ backend.load_pipeline(
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", speed_mode = "max"
+ )
assert backend.status()["transformer_cache"] == "fbcache"
backend.generate(prompt = "a sloth", steps = 8)
assert backend.status()["transformer_cache"] is None
@@ -2012,7 +2066,10 @@ def test_video_step_cache_auto_toggles_on_actual_steps(fake_runtime):
backend.unload()
backend.load_pipeline(
- "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", transformer_cache = "off"
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers",
+ model_kind = "pipeline",
+ transformer_cache = "off",
+ speed_mode = "max",
)
assert backend.status()["transformer_cache"] is None
backend.generate(prompt = "a sloth", steps = 30)
@@ -9807,6 +9864,20 @@ def test_the_boundary_marker_waits_out_a_busy_capture_lock(fake_runtime, monkeyp
assert at_decode.get("phase") == "decode"
+def test_video_auto_below_max_names_an_uncacheable_dit(fake_runtime, monkeypatch):
+ monkeypatch.setattr(
+ "core.inference.video.step_cache_supported", lambda pipe, logger = None: False
+ )
+ backend = VideoBackend()
+ status = backend.load_pipeline(
+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers", model_kind = "pipeline", speed_mode = "default"
+ )
+ assert status["resolved"]["transformer_cache"]["reason"] == (
+ "auto: model does not support step caching"
+ )
+ backend.unload()
+
+
def test_teardown_drains_pinned_host_memory_after_the_pipeline_is_gone(
fake_runtime, tmp_path, monkeypatch
):
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsx
index 665c84a0e38..86831bab290 100644
--- a/studio/frontend/src/features/images/images-page.tsx
+++ b/studio/frontend/src/features/images/images-page.tsx
@@ -4273,7 +4273,7 @@ export function ImagesPage({
/>
<AdvancedSelect
label="Speed"
- hint="Auto picks per model: GGUF compiles at load; a dense model keeps the first two images exact and eager, then compiles from the 3rd (~2x from there). eager = fused kernels, no compile. default/max add torch.compile (max also TF32 + fused QKV)."
+ hint="Auto picks per model: GGUF compiles at load; a dense model keeps the first two images exact and eager, then compiles from the 3rd (~2x from there). eager = fused kernels, no compile. default/max add torch.compile (max also TF32 + fused QKV, plus the step cache on 20+ step models)."
badge={<ResolvedBadge status={status} controlKey="speed_mode" />}
value={speedMode}
onValueChange={(v) => setSpeedMode(v as typeof speedMode)}
@@ -4386,7 +4386,7 @@ export function ImagesPage({
)}
<AdvancedSelect
label="Step cache"
- hint="First-Block-Cache reuses the transformer tail across steps for many-step models (~1.4x). Auto turns it on at 20+ steps and off for few-step distilled models, re-checked per image."
+ hint="First-Block-Cache reuses the transformer tail across steps for many-step models (~1.4x, small quality cost). Auto turns it on only on the Max speed tier at 20+ steps, re-checked per image."
badge={<ResolvedBadge status={status} controlKey="transformer_cache" />}
value={transformerCache}
onValueChange={(v) => setTransformerCache(v as typeof transformerCache)}
diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsx
index 0142fd85c32..110c764fddd 100644
--- a/studio/frontend/src/features/video/video-page.tsx
+++ b/studio/frontend/src/features/video/video-page.tsx
@@ -3384,7 +3384,7 @@ function VideoGenerator({
/>
<AdvancedSelect
label="Speed"
- hint="Auto compiles every model at load: a clip takes minutes to denoise, so the one-time compile always pays for itself within a single run. eager = fused kernels, no compile. max adds TF32 + fused QKV."
+ hint="Auto compiles every model at load: a clip takes minutes to denoise, so the one-time compile always pays for itself within a single run. eager = fused kernels, no compile. max adds TF32 + fused QKV, plus the step cache on 20+ step models."
badge={<ResolvedBadge status={status} controlKey="speed_mode" />}
value={speedMode}
onValueChange={(v) => setSpeedMode(v as typeof speedMode)}
@@ -3462,7 +3462,7 @@ function VideoGenerator({
)}
<AdvancedSelect
label="Step cache"
- hint="First-Block-Cache reuses the transformer tail across steps for many-step models. Auto turns it on at 20+ steps and off for few-step distilled models, re-checked per clip."
+ hint="First-Block-Cache reuses the transformer tail across steps for many-step models (small quality cost). Auto turns it on only on the Max speed tier at 20+ steps, re-checked per clip."
badge={<ResolvedBadge status={status} controlKey="transformer_cache" />}
value={transformerCache}
onValueChange={(v) => setTransformerCache(v as typeof transformerCache)}