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
Video: verify the H3 denoiser artifact before the pull drops its dense shards (#8337)
Daniel Hanf57c05d13cfe
diff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.pyindex 26bf6a1b912..b3a655e09c4 100644--- a/studio/backend/core/inference/video.py+++ b/studio/backend/core/inference/video.py@@ -669,6 +669,40 @@ class _SecondDiTView:setattr(pipe, "transformer_2" if name == "transformer" else name, value)+class _NamedDiTView:+ """``_SecondDiTView`` for an arbitrary attribute: presents ``pipe.<attr>`` as+ ``pipe.transformer`` to the helpers that hardcode that name, reading everything else through.++ MiniMax-H3 keeps one denoiser per workflow partition, so a reference load's DiT is+ ``transformer_ref``. ``_denoiser_dits`` / ``_attention_dits`` enumerate only ``transformer``,+ ``transformer_2`` and ``unconditional_transformer``, so without this the partition that load+ actually denoises with gets neither the selected attention backend nor the regional compile,+ while the resolved record still reports the profile that was asked for -- exactly the+ over-reporting those two helpers' docstrings exist to rule out.+ """++ def __init__(self, pipe: Any, attr: str) -> None:+ object.__setattr__(self, "_pipe", pipe)+ object.__setattr__(self, "_attr", attr)++ @property+ def transformer(self) -> Any:+ return getattr(self._pipe, object.__getattribute__(self, "_attr"), None)++ def __getattr__(self, name: str) -> Any:+ return getattr(object.__getattribute__(self, "_pipe"), name)++ def __setattr__(self, name: str, value: Any) -> None:+ pipe = object.__getattribute__(self, "_pipe")+ attr = object.__getattribute__(self, "_attr")+ setattr(pipe, attr if name == "transformer" else name, value)+++def _denoiser_view(pipe: Any, component: str) -> Any:+ """``pipe`` itself for the usual ``transformer``; a view onto ``component`` otherwise."""+ return pipe if component == "transformer" else _NamedDiTView(pipe, component)++def _views_for(pipe: Any, fam: VideoFamily) -> tuple[Any, ...]:"""The pipe view(s) to pass through the ``getattr(pipe, "transformer")`` helpers sothey cover every denoiser: the real pipe (its ``transformer``), plus a@@ -1099,9 +1133,16 @@ class VideoBackend:# An fp8 encoder request loads a hosted pre-cast checkpoint, so neither the estimate nor the pull includes those dense shards.te_sources = self._te_prequant_sources(fam, kwargs.get("text_encoder_quant"))# The same deal for the denoiser: a hosted pre-quantized checkpoint replaces the dense- # DiT shards, so the estimate and the scoped pull below both drop them.- skip_transformer_weights = self._denoiser_prequant_covered(- fam, kwargs.get("transformer_quant"), base, kwargs.get("h3_task")+ # DiT shards, so the estimate and the scoped pull below both drop them. VERIFIED, like+ # the conditioner below and like the plan: this flag both REMOVES 66 GB from the pull+ # and is never re-checked, so an artifact that does not resolve has to keep the dense+ # shards rather than strand the load's own bf16 fallback with nothing to open.+ skip_transformer_weights = self._denoiser_prequant_verified(+ fam,+ kwargs.get("transformer_quant"),+ base,+ kwargs.get("h3_task"),+ kwargs.get("hf_token"),)# And for MiniMax-H3's conditioner, whose hosted quantized artifact replaces the base# repo's 62 GB dense text_encoder/ shards outright.@@ -1556,6 +1597,45 @@ class VideoBackend:except Exception: # noqa: BLE001 -- unanswerable keeps the dense shardsreturn None+ def _denoiser_prequant_verified(+ self,+ fam: Any,+ transformer_quant: Optional[str],+ base: Optional[str],+ h3_task: Optional[str],+ hf_token: Optional[str],+ ) -> bool:+ """``_denoiser_prequant_covered`` plus the Hub check, for the decisions that COMMIT.++ The pure probe answers from the registry, which is right where it must not raise or touch+ the network. It is NOT enough to drop the dense shards from the pull: a task-specific row+ gets no filename fallback, so a Ref2VA artifact that is renamed, unpublished or gated+ resolves to nothing while the registry still says the scheme is covered. Skipping on that+ word alone stages neither denoiser, and the bf16 fallback the loader documents then has+ nothing to open offline (or pulls 66 GB inline, outside this load's progress, cancel and+ disk budget).++ Same rule as ``_h3_te_quant_scheme_verified`` next door, and the same fail-closed+ direction: unanswerable keeps the dense shards."""+ if not self._denoiser_prequant_covered(fam, transformer_quant, base, h3_task):+ return False+ try:+ from huggingface_hub import HfApi+ repo, _files = self._denoiser_prequant_hub_files(+ fam, transformer_quant, base, HfApi(token = hf_token), h3_task+ )+ except Exception: # noqa: BLE001 -- an unanswerable probe keeps the dense shards+ return False+ if repo is None:+ logger.info(+ "video.denoiser_prequant: no hosted %s checkpoint resolved for %s %s; keeping its "+ "dense denoiser shards",+ transformer_quant,+ getattr(fam, "name", None),+ h3_task or getattr(fam, "modular_workflow", None),+ )+ return repo is not None+def _h3_te_quant_scheme_verified(self,fam: Any,@@ -3744,9 +3824,15 @@ class VideoBackend:self._precommit_globals = (_load_token, backend_flags)attention_engaged = Nonespeed_optims: tuple = ()+ # Both helpers reach the denoiser through ``pipe.transformer``, and a reference load's DiT+ # is ``transformer_ref``. Handed the bare pipe they would enumerate no denoiser at all, so+ # the partition this run denoises with would keep native attention and stay uncompiled+ # while the resolved record below still reported the requested profile -- and the pin+ # above is what removes the eager downgrade that used to hide it.+ speed_view = _denoiser_view(pipe, denoiser_component)try:attention_engaged = apply_attention_backend(- pipe,+ speed_view,select_attention_backend(umem_target, attention_backend, speed_active = effective_speed != SPEED_OFF),@@ -3755,7 +3841,7 @@ class VideoBackend:target = types.SimpleNamespace(device = device, dtype = dtype),)applied = apply_speed_optims(- pipe,+ speed_view,types.SimpleNamespace(device = device,dtype = dtype,diff --git a/studio/backend/tests/test_video_backend.py b/studio/backend/tests/test_video_backend.pyindex dd5892faa3b..7836848812a 100644--- a/studio/backend/tests/test_video_backend.py+++ b/studio/backend/tests/test_video_backend.py@@ -2812,6 +2812,152 @@ def test_download_plan_still_drops_the_reference_shards_its_artifact_replaces(moassert plan["total_bytes"] == sum(e["bytes"] for e in plan["entries"])+def test_the_verified_probe_keeps_the_dense_shards_when_the_artifact_is_absent(monkeypatch):+ # The load path drops 66 GB from the pull and never re-checks, so the registry's word is not+ # enough: only an artifact that really resolves on the Hub earns that skip. Same rule the+ # conditioner already follows through _h3_te_quant_scheme_verified.+ from core.inference.video import _detect_load_family as _fam++ fam = _fam("MiniMaxAI/MiniMax-H3", None, "minimax-h3")+ backend = VideoBackend()++ class _Api:+ def __init__(self, names):+ self._names = names++ def model_info(+ self,+ repo_id,+ files_metadata = False,+ token = None,+ ):+ return _PlanInfo([_PlanSibling(n, 20) for n in self._names])++ def _use(names):+ monkeypatch.setattr("huggingface_hub.HfApi", lambda *a, **k: _Api(names))++ # The keyframe artifacts exist, the reference one does not.+ _use(["MiniMax-H3-FP8.pt", "MiniMax-H3-INT8-ConvRot.pt"])+ assert (+ backend._denoiser_prequant_verified(fam, "fp8", "MiniMaxAI/MiniMax-H3", "ref2va", None)+ is False+ )+ assert (+ backend._denoiser_prequant_verified(fam, "fp8", "MiniMaxAI/MiniMax-H3", "fl2va", None)+ is True+ )++ # Once the reference artifact is published the skip is earned again.+ _use(["MiniMax-H3-FP8.pt", "MiniMax-H3-Ref2VA-FP8.pt"])+ assert (+ backend._denoiser_prequant_verified(fam, "fp8", "MiniMaxAI/MiniMax-H3", "ref2va", None)+ is True+ )++ # An unreadable repo is a refusal, not a pass: the dense shards stay.+ class _Boom:+ def model_info(self, *a, **k):+ raise RuntimeError("404 gated")++ monkeypatch.setattr("huggingface_hub.HfApi", lambda *a, **k: _Boom())+ assert (+ backend._denoiser_prequant_verified(fam, "fp8", "MiniMaxAI/MiniMax-H3", "ref2va", None)+ is False+ )+ # And bf16 never asks in the first place.+ assert (+ backend._denoiser_prequant_verified(fam, None, "MiniMaxAI/MiniMax-H3", "ref2va", None)+ is False+ )+++def test_the_load_path_gates_its_dense_skip_on_the_verified_probe():+ """``_run_load`` must ask the VERIFIED probe, not the registry-only one.++ This is the flag that removes the dense denoiser from the actual pull, so a registry-only+ answer stages neither denoiser and leaves the loader's documented bf16 fallback with nothing+ to open offline.+ """+ import ast+ import inspect+ import textwrap++ from core.inference.video import VideoBackend as _VB++ tree = ast.parse(textwrap.dedent(inspect.getsource(_VB._run_load)))+ assigned = [+ n+ for n in ast.walk(tree)+ if isinstance(n, ast.Assign)+ and any(getattr(t, "id", None) == "skip_transformer_weights" for t in n.targets)+ ]+ assert assigned, "skip_transformer_weights is no longer assigned in _run_load"+ called = {+ n.func.attr+ for a in assigned+ for n in ast.walk(a)+ if isinstance(n, ast.Call) and isinstance(n.func, ast.Attribute)+ }+ assert "_denoiser_prequant_verified" in called+ assert "_denoiser_prequant_covered" not in called+++def test_a_named_dit_view_presents_the_reference_denoiser_as_the_transformer():+ # The speed and attention helpers enumerate transformer / transformer_2 /+ # unconditional_transformer only. H3 keeps one denoiser per partition, so a reference load's+ # DiT is invisible to both without this view.+ from core.inference.diffusion_attention import _attention_dits+ from core.inference.diffusion_speed import _denoiser_dits+ from core.inference.video import _denoiser_view++ ref = object()+ pipe = types.SimpleNamespace(transformer_ref = ref, vae = "vae")++ assert _denoiser_dits(pipe) == [] and _attention_dits(pipe) == []++ view = _denoiser_view(pipe, "transformer_ref")+ assert view.transformer is ref+ assert _denoiser_dits(view) == [ref]+ assert _attention_dits(view) == [ref]+ # Everything else reads through, and a helper's reassignment lands on the real partition.+ assert view.vae == "vae"+ replacement = object()+ view.transformer = replacement+ assert pipe.transformer_ref is replacement+ assert not hasattr(pipe, "transformer")++ # A keyframe load is handed the pipe itself, so its behaviour is byte-for-byte unchanged.+ keyframe = types.SimpleNamespace(transformer = ref)+ assert _denoiser_view(keyframe, "transformer") is keyframe+++def test_the_h3_loader_optimises_the_partition_it_denoises_with():+ """``apply_attention_backend`` / ``apply_speed_optims`` must see this workflow's denoiser.++ The pre-quantized reference pin keeps the profile out of the eager downgrade, so handing these+ the bare pipe leaves the reference DiT native and uncompiled while the resolved record still+ reports the requested profile.+ """+ import ast+ import inspect+ import textwrap++ from core.inference.video import VideoBackend as _VB++ tree = ast.parse(textwrap.dedent(inspect.getsource(_VB._load_h3_modular_pipeline)))+ for helper in ("apply_attention_backend", "apply_speed_optims"):+ calls = [+ n+ for n in ast.walk(tree)+ if isinstance(n, ast.Call) and getattr(n.func, "id", None) == helper+ ]+ assert len(calls) == 1, f"{helper} is called {len(calls)} times"+ first = calls[0].args[0]+ assert (+ getattr(first, "id", None) == "speed_view"+ ), f"{helper} is handed {ast.dump(first)}, not the denoiser view"++def test_download_plan_adds_no_prequant_entry_without_a_scheme(monkeypatch):# bf16 keeps the dense shards, so there is nothing to replace and no third repo to stage._cuda_bf16_target(monkeypatch)