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: load Wan2.2 hosted FP8 / INT8 files, and hosted files under low_vram (#12888)
Daniel Han252fd53a0ef4
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.pyindex ca5aef26585..2728692e350 100644--- a/studio/backend/core/inference/diffusion.py+++ b/studio/backend/core/inference/diffusion.py@@ -3743,8 +3743,12 @@ class DiffusionBackend:return Noneif _has_active_lora(loras):return None- if _memory_request_forces_offload(memory_mode, cpu_offload):+ # 'balanced' group-offload hooks refuse torchao weights. low_vram / cpu_offload (whole-module) seed on the+ # host when the weights survive, only the winning rung (a lower one would change the runtime's scheme),+ # and never a pinned scheme the loader serves torchao-free (native int8).+ if normalize_memory_mode(memory_mode) == MEMORY_MODE_BALANCED:return None+ forced_offload = _memory_request_forces_offload(memory_mode, cpu_offload)# SCOPED, not pinned: the pooled asyncio.to_thread thread must not be handed back set to this card.with diffusion_device_scope(gpu_ordinal):target = self._target_for_ordinal(fam, gpu_ordinal)@@ -3804,7 +3808,7 @@ class DiffusionBackend:# (Qwen-Image int8 on a 32 GB card) yields to the next resident rung instead of pinning a decline.# An explicit scheme is honored or refused, never swapped.rungs: list[str] = [scheme]- if auto:+ if auto and not forced_offload:try:from .diffusion_transformer_quant import auto_scheme_candidatesbelow = list(@@ -3832,6 +3836,15 @@ class DiffusionBackend:getattr(getattr(self, "_state", None), "pipe", None))for rung in rungs:+ if (+ forced_offload+ and not auto+ and native_quant_scheme(+ target, rung, family = getattr(fam, "name", None), offload = True+ )+ is not None+ ):+ continuesource = denoiser_prequant_source(fam,rung,diff --git a/studio/backend/core/inference/diffusion_prequant.py b/studio/backend/core/inference/diffusion_prequant.pyindex cc852114d0f..5d7037b0acf 100644--- a/studio/backend/core/inference/diffusion_prequant.py+++ b/studio/backend/core/inference/diffusion_prequant.py@@ -2480,8 +2480,9 @@ def _validate_checkpoint()return False# The int8 exclusion set is scheme-derived, so a token-list change would leave old checkpoints with a stale baked- # set that passes scheme+min_features then crashes at the first denoise. Reject a recorded mismatch; absent is- # accepted.+ # set that passes scheme+min_features then crashes at the first denoise. Reject a checkpoint that quantised a+ # layer the runtime excludes; absent is accepted, and so is a superset (extra bf16 Linears load as stored; the+ # hosted Wan2.2 fp8 files keep ``condition_embedder`` bf16).ckpt_excludes = meta.get("exclude_name_tokens")if ckpt_excludes is not None:from .diffusion_transformer_quant import exclude_tokens_for_scheme@@ -2489,12 +2490,12 @@ def _validate_checkpoint(# The exclude set derives from scheme AND family, so use the recorded family: an artifact baked under an older# token list is rejected and re-quantised, not loaded crashing.expected = tuple(exclude_tokens_for_scheme(scheme, meta.get("family")))- if tuple(ckpt_excludes) != expected:+ if not isinstance(ckpt_excludes, (list, tuple)) or not set(expected) <= set(ckpt_excludes):_warn(logger,scheme,ValueError(- f"checkpoint exclude_name_tokens {tuple(ckpt_excludes)!r} != {expected!r}"+ f"checkpoint exclude_name_tokens {ckpt_excludes!r} do not cover the runtime {expected!r}"),)return Falsediff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.pyindex 9b8ef1aef9d..2c1b86b3346 100644--- a/studio/backend/core/inference/video.py+++ b/studio/backend/core/inference/video.py@@ -164,6 +164,7 @@ from .diffusion_transformer_quant import (TQ_AUTO,TQ_FP8,TQ_INT8,+ TQ_NVFP4,dense_transformer_supported,dense_transformer_unsupported_reason,explain_unusable_scheme,@@ -1786,33 +1787,65 @@ def _pipeline_device_mib(pipe: Any, ordinal: Optional[int] = None) -> int:return total // (1024 * 1024)+def _auto_seed_yields_to_resident_bf16(scheme: Optional[str], requested: Optional[str]) -> bool:+ """Whether an AUTO seed of ``scheme`` is bound by "auto keeps a resident bf16 DiT".++ nvfp4 is exempt: it reaches auto only through a gated family preference (``_FAMILY_AUTO_PREFER``) that is+ measured to be worth taking on a card that holds bf16. An explicit scheme is a request, honored as asked."""+ if scheme is None or scheme == DENOISER_SEED_DECLINED or scheme == TQ_NVFP4:+ return False+ return requested is None or normalize_transformer_quant(requested) == TQ_AUTO+++def _auto_keeps_resident_bf16(plan: Any, target: Any) -> bool:+ """The bf16 plan keeps the DiT resident on a measured budget, so auto runs bf16 (int8 fails the LPIPS bar there)."""+ if plan is None or not plan_keeps_transformer_resident(plan):+ return False+ estimates = getattr(plan, "estimates", None) or {}+ # An unmeasured budget also plans "none" without proving a fit.+ return (+ estimates.get("safe_device_budget_mib") is not None+ and estimates.get("resident_required_mib") is not None+ and bool(dense_transformer_supported(target))+ )++def _video_seed_stays_resident(fam: Any,*,target: Any,- scheme: str,+ scheme: Optional[str],memory_mode: Optional[str],text_encoder_quant: Optional[str],base_repo: Optional[str],reclaimable_mib: int = 0,) -> bool:- """True when an artifact-sized plan keeps the denoiser resident (text encoders may stream)."""+ """True when an artifact-sized plan keeps the denoiser resident (text encoders may stream).++ ``scheme=None`` sizes the released bf16 DiT instead, and then also requires a measured budget (see+ ``_auto_keeps_resident_bf16``)."""components = getattr(fam, "bf16_components_gb", None)if not components:- return True- measured = video_family_prequant_resident_gb(fam, scheme)- factor = _QUANT_STEADY_FACTOR.get(scheme)- if measured:- denoiser_gb = float(measured)- elif factor is not None:- denoiser_gb = components[0] * factor- else:- return True+ return scheme is not Noneimport torch+ dtype = getattr(target, "dtype", None)+ if scheme is None:+ denoiser_gb = components[0] * (+ 2.0 if getattr(target, "device", None) != "cpu" and dtype is torch.float32 else 1.0+ )+ else:+ measured = video_family_prequant_resident_gb(fam, scheme)+ factor = _QUANT_STEADY_FACTOR.get(scheme)+ if measured:+ denoiser_gb = float(measured)+ elif factor is not None:+ denoiser_gb = components[0] * factor+ else:+ return True+from .diffusion_te_prequant import te_prequant_budget_scale- dtype = getattr(target, "dtype", None)dtype_scale = (2.0 if getattr(target, "device", None) != "cpu" and dtype is torch.float32 else 1.0)@@ -1846,6 +1879,8 @@ def _video_seed_stays_resident(text_encoder_dense_mib = int(text_encoder_gb * mib_per_gb),requested_mode = normalize_memory_mode(memory_mode),)+ if scheme is None:+ return _auto_keeps_resident_bf16(planned, target)return plan_keeps_transformer_resident(planned)@@ -4276,6 +4311,23 @@ class VideoBackend:if scheme is None:return Noneresident = self._state+ reclaimable = _pipeline_device_mib(+ getattr(resident, "pipe", None),+ ordinal = _target_ordinal(target),+ )+ if _auto_seed_yields_to_resident_bf16(+ scheme, transformer_quant+ ) and _video_seed_stays_resident(+ fam,+ target = target,+ scheme = None,+ memory_mode = memory_mode,+ text_encoder_quant = text_encoder_quant,+ base_repo = base,+ reclaimable_mib = reclaimable,+ ):+ # auto keeps a resident bf16 DiT, so the dense shards are what this load runs.+ return Noneif not _video_seed_stays_resident(fam,target = target,@@ -6160,6 +6212,18 @@ class VideoBackend:denoiser_seed_scheme = Nonedenoiser_seed_gb = Noneplan, bf16_plan, quant_replanned = _plan_for_te_scale(te_scale, log = False)+ if _auto_seed_yields_to_resident_bf16(+ denoiser_seed_scheme, transformer_quant+ ) and _auto_keeps_resident_bf16(_plan_for_te_scale(te_scale, log = False)[1], target):+ # Auto keeps a resident bf16 DiT; seeding would change auto's precision wherever bf16 fits.+ logger.info(+ "video.denoiser_prequant: auto keeps the bf16 DiT (it fits resident), so the hosted "+ "%s checkpoint is not seeded",+ denoiser_seed_scheme,+ )+ denoiser_seed_scheme = None+ denoiser_seed_gb = None+ plan, bf16_plan, quant_replanned = _plan_for_te_scale(te_scale, log = False)if comfy_scan is not None and not _video_comfy_resident(plan, bf16_plan):# Offloaded, fp8 layers dequantize on NVIDIA: price the DiT the load will actually build.offload_mib = _video_comfy_resident_mib(@@ -6556,11 +6620,7 @@ class VideoBackend:and normalize_transformer_quant(transformer_quant) == TQ_AUTOand not quant_replannedand not denoiser_injected- and plan_keeps_transformer_resident(plan)- # An unmeasured budget also plans "none" without proving a fit.- and plan.estimates.get("safe_device_budget_mib") is not None- and plan.estimates.get("resident_required_mib") is not None- and dense_transformer_supported(target)+ and _auto_keeps_resident_bf16(plan, target)):logger.info("video.transformer_quant: auto keeps the bf16 DiT (it fits resident)")transformer_quant = "off"diff --git a/studio/backend/core/inference/video_families.py b/studio/backend/core/inference/video_families.pyindex a3c6c28a24e..a7939b3665d 100644--- a/studio/backend/core/inference/video_families.py+++ b/studio/backend/core/inference/video_families.py@@ -292,9 +292,14 @@ _FAMILIES: tuple[VideoFamily, ...] = (pipeline_class = "WanPipeline",transformer_class = "WanTransformer3DModel",base_repo = "Wan-AI/Wan2.2-TI2V-5B-Diffusers",- prequant_repos = (("nvfp4", "unsloth/Wan2.2-TI2V-5B-NVFP4"),),+ # fp8 / int8 share one repo, files Wan2.2-TI2V-5B-<SCHEME>.pt. Sizes from Hub metadata (2026-08-04).+ prequant_repos = (+ ("nvfp4", "unsloth/Wan2.2-TI2V-5B-NVFP4"),+ ("fp8", "unsloth/Wan2.2-TI2V-5B-FP8"),+ ("int8", "unsloth/Wan2.2-TI2V-5B-FP8"),+ ),prequant_filenames = (("nvfp4", "Wan2.2-TI2V-5B-NVFP4.pt"),),- prequant_resident_gb_by_scheme = (("nvfp4", 2.9),),+ prequant_resident_gb_by_scheme = (("nvfp4", 2.9), ("fp8", 5.1), ("int8", 5.0)),# "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,@@ -328,13 +333,20 @@ _FAMILIES: tuple[VideoFamily, ...] = (pipeline_class = "WanPipeline",transformer_class = "WanTransformer3DModel",base_repo = "Wan-AI/Wan2.2-T2V-A14B-Diffusers",- prequant_repos = (("nvfp4", "unsloth/Wan2.2-T2V-A14B-NVFP4"),),+ # fp8 / int8: expert 2 is <name>-2.pt, not the derived transformer_2 name, so it needs its own row.+ prequant_repos = (+ ("nvfp4", "unsloth/Wan2.2-T2V-A14B-NVFP4"),+ ("fp8", "unsloth/Wan2.2-T2V-A14B-FP8"),+ ("int8", "unsloth/Wan2.2-T2V-A14B-FP8"),+ ),prequant_filenames = (("nvfp4", "Wan2.2-T2V-A14B-NVFP4.pt"),("nvfp4", "transformer_2", "Wan2.2-T2V-A14B-transformer_2-NVFP4.pt"),+ ("fp8", "transformer_2", "Wan2.2-T2V-A14B-FP8-2.pt"),+ ("int8", "transformer_2", "Wan2.2-T2V-A14B-INT8-2.pt"),),# BOTH experts: the plan subtracts one denoiser term and this family builds two.- prequant_resident_gb_by_scheme = (("nvfp4", 16.2),),+ prequant_resident_gb_by_scheme = (("nvfp4", 16.2), ("fp8", 29.2), ("int8", 28.8)),# "wan2.2_t2v": ComfyUI's expert files (wan2.2_t2v_high_noise_14B_*.safetensors), paired at load.aliases = ("wan2.2-14b", "wan-t2v", "wan2.2-t2v", "wan2.2_t2v", "wan-t2v-a14b", "wan-a14b"),has_audio = False,diff --git a/studio/backend/tests/test_diffusion_pipeline_prequant.py b/studio/backend/tests/test_diffusion_pipeline_prequant.pyindex 7039e012e0b..813d58f8efd 100644--- a/studio/backend/tests/test_diffusion_pipeline_prequant.py+++ b/studio/backend/tests/test_diffusion_pipeline_prequant.py@@ -374,9 +374,66 @@ def test_a_baked_lora_keeps_the_dense_path(monkeypatch):assert _settle(backend, loras = [("adapter", 0.0)]) == "fp8"[email protected]("mode", ["balanced", "low_vram"])-def test_a_definite_offload_request_keeps_the_released_weights(monkeypatch, mode):- assert _settle(_settle_backend(monkeypatch), memory_mode = mode) is None+def test_balanced_keeps_the_released_weights(monkeypatch):+ """balanced streams through group-offload hooks the preflight refuses torchao weights under."""+ assert _settle(_settle_backend(monkeypatch), memory_mode = "balanced") is None+++def _forced_offload_backend(+ monkeypatch,+ *,+ scheme = "fp8",+ survives = True,+ native = None,+):+ """low_vram's whole-module plan: the denoiser is offloaded, and ``survives`` says whether its torchao weights+ survive that placement. ``native`` is the scheme the loader would serve torchao-free under offload."""+ backend = _settle_backend(monkeypatch, offload = "model", scheme = scheme)+ monkeypatch.setattr(dmod, "torchao_survives_plan", lambda *_a, **_k: survives)+ monkeypatch.setattr(+ dmod,+ "native_quant_scheme",+ lambda target, requested, family = None, offload = False: (+ requested if offload and requested == native else None+ ),+ )+ return backend++[email protected]("request_kwargs", [{"memory_mode": "low_vram"}, {"cpu_offload": True}])+def test_a_whole_module_offload_request_seeds_the_hosted_checkpoint(monkeypatch, request_kwargs):+ """low_vram (and the legacy flag) offload whole modules, which the runtime fp8 quantise already runs torchao+ under; the artifact is seeded on the host instead of quantising the released bf16 shards."""+ assert _settle(_forced_offload_backend(monkeypatch), **request_kwargs) == "fp8"+++def test_a_whole_module_offload_request_never_seeds_a_torchao_free_rung(monkeypatch):+ """A PINNED int8 under offload runs torchao-free (native kernels); a torchao artifact cannot feed that path."""+ backend = _forced_offload_backend(monkeypatch, scheme = "int8", native = "int8")+ assert _settle(backend, memory_mode = "low_vram", transformer_quant = "int8") is None+++def test_auto_under_a_whole_module_offload_seeds_the_winner_it_quantises(monkeypatch):+ """AUTO under low_vram quantises its winner with torchao (the native path is for a pinned scheme only), so the+ winner's artifact is seeded."""+ backend = _forced_offload_backend(monkeypatch, scheme = "int8", native = "int8")+ assert _settle(backend, memory_mode = "low_vram") == "int8"+++def test_auto_under_a_whole_module_offload_never_walks_to_a_lower_rung(monkeypatch):+ """Under a forced offload a lower rung would change the scheme the runtime picks, so a winner whose artifact does+ not survive the placement declines instead of seeding the next rung."""+ from core.inference import diffusion_transformer_quant as tq++ backend = _forced_offload_backend(monkeypatch, scheme = "int8")+ monkeypatch.setattr(tq, "auto_scheme_candidates", lambda *_a, **_k: ("int8", "fp8"))+ monkeypatch.setattr(dmod, "torchao_survives_plan", lambda _plan, rung, **_k: rung == "fp8")+ assert _settle(backend, memory_mode = "low_vram") == PIPELINE_SEED_DECLINED+++def test_a_whole_module_offload_request_declines_when_torchao_does_not_survive(monkeypatch):+ backend = _forced_offload_backend(monkeypatch, survives = False)+ assert _settle(backend, memory_mode = "low_vram") == PIPELINE_SEED_DECLINEDdef test_an_artifact_sized_plan_that_still_offloads_declines(monkeypatch):diff --git a/studio/backend/tests/test_diffusion_prequant.py b/studio/backend/tests/test_diffusion_prequant.pyindex 03ee3143342..43d93f22abc 100644--- a/studio/backend/tests/test_diffusion_prequant.py+++ b/studio/backend/tests/test_diffusion_prequant.py@@ -792,6 +792,39 @@ def test_load_exclude_tokens_match_ok(monkeypatch, tmp_path):assert _load(monkeypatch, tmp_path, ckpt, scheme = "int8") is not None+def test_load_exclude_tokens_superset_ok(monkeypatch, tmp_path):+ # Excluding MORE than the runtime keeps extra Linears bf16, which load as stored (assign=True) and run at any M. The+ # hosted Wan2.2 fp8 artifacts record ['condition_embedder'] against the runtime's empty fp8 set.+ from core.inference.diffusion_transformer_quant import exclude_tokens_for_scheme++ fp8 = _good_ckpt(scheme = "fp8")+ fp8["metadata"]["exclude_name_tokens"] = ["condition_embedder"]+ assert _load(monkeypatch, tmp_path, fp8, scheme = "fp8") is not None++ int8 = _good_ckpt(scheme = "int8")+ int8["metadata"]["exclude_name_tokens"] = list(exclude_tokens_for_scheme("int8")) + [+ "extra_bf16"+ ]+ assert _load(monkeypatch, tmp_path, int8, scheme = "int8") is not None+++def test_load_exclude_tokens_subset_is_none(monkeypatch, tmp_path):+ # Missing one runtime token means the artifact quantised a layer the runtime keeps bf16 (the int8 crash case).+ from core.inference.diffusion_transformer_quant import exclude_tokens_for_scheme++ ckpt = _good_ckpt(scheme = "int8")+ ckpt["metadata"]["exclude_name_tokens"] = list(exclude_tokens_for_scheme("int8"))[1:]+ assert _load(monkeypatch, tmp_path, ckpt, scheme = "int8") is None++[email protected]("recorded", ["norm", {"norm": 1}, 7])+def test_load_exclude_tokens_not_a_list_is_none(monkeypatch, tmp_path, recorded):+ # A bare string would pass a naive subset test character by character.+ ckpt = _good_ckpt(scheme = "int8")+ ckpt["metadata"]["exclude_name_tokens"] = recorded+ assert _load(monkeypatch, tmp_path, ckpt, scheme = "int8") is None++def test_load_exclude_tokens_need_the_recorded_family(monkeypatch, tmp_path):# int8 carries PER-FAMILY exclusions (Qwen's unpadded text stream runs at M = prompt tokens, under _int_mm's floor of 16), so an artifact# recording the family but building its set with family=None is rejected. Pins the offline builder to exclude_tokens_for_scheme(scheme, fam.name).diff --git a/studio/backend/tests/test_nvfp4_diffusion_flag.py b/studio/backend/tests/test_nvfp4_diffusion_flag.pyindex f376a561135..e47e82d0740 100644--- a/studio/backend/tests/test_nvfp4_diffusion_flag.py+++ b/studio/backend/tests/test_nvfp4_diffusion_flag.py@@ -53,10 +53,17 @@ def test_a_video_family_without_a_usable_hosted_seed_spends_no_smoke_probe(monkemonkeypatch.setattr(tq, "dense_transformer_supported", lambda t: True)monkeypatch.setattr(tq, "_capability", lambda ordinal = None: (10, 0))monkeypatch.setattr(torch.cuda, "is_available", lambda: True)+ from core.inference.video_families import video_family_prequant_schemes+target = types.SimpleNamespace(device = "cuda", dtype = torch.bfloat16, ordinal = 0)- for fam in _FAMILIES:- if getattr(fam, "modular_workflow", None):- continue+ # Families with a hosted fp8 / int8 seed (Wan2.2) legitimately probe; the rest must not.+ unseeded = [+ fam+ for fam in _FAMILIES+ if not getattr(fam, "modular_workflow", None) and not video_family_prequant_schemes(fam)+ ]+ assert unseeded+ for fam in unseeded:assert (vid._video_auto_denoiser_scheme(fam, target = target, requested = requested, base_repo = fam.base_repodiff --git a/studio/backend/tests/test_video_families.py b/studio/backend/tests/test_video_families.pyindex 44442c15c08..27c12b9ed79 100644--- a/studio/backend/tests/test_video_families.py+++ b/studio/backend/tests/test_video_families.py@@ -525,7 +525,7 @@ def test_the_a14b_row_prices_both_experts_not_one():fam = detect_video_family("Wan-AI/Wan2.2-T2V-A14B-Diffusers")assert fam.is_moe- names = {entry[-1] for entry in fam.prequant_filenames}+ names = {entry[-1] for entry in fam.prequant_filenames if entry[0] == "nvfp4"}assert len(names) == 2measured = video_family_prequant_resident_gb(fam, "nvfp4")assert measured == pytest.approx(16.2)diff --git a/studio/backend/tests/test_video_prequant.py b/studio/backend/tests/test_video_prequant.pyindex 0cc289bc83f..7674672ec74 100644--- a/studio/backend/tests/test_video_prequant.py+++ b/studio/backend/tests/test_video_prequant.py@@ -1547,9 +1547,10 @@ def test_the_a14b_auto_plan_seeds_nvfp4_where_flashinfer_serves_the_device(monkedef test_the_a14b_auto_plan_stays_on_the_ladder_on_the_torchao_backend(monkeypatch):+ # The ladder's int8 is hosted, so the plan seeds the scheme auto would otherwise quantise at load.seeded, chosen = _a14b_auto(monkeypatch, backend = "torchao")assert chosen == "int8"- assert seeded is None+ assert seeded == "int8"def test_the_a14b_auto_plan_stays_on_the_ladder_with_only_one_expert_hosted(monkeypatch):@@ -1570,7 +1571,7 @@ def test_the_a14b_auto_plan_stays_on_the_ladder_with_only_one_expert_hosted(monkdef test_the_a14b_auto_plan_falls_through_when_the_fp4_kernel_is_missing(monkeypatch):seeded, chosen = _a14b_auto(monkeypatch, backend = "flashinfer", allowed = {"fp8", "mxfp8", "int8"})- assert seeded is None+ assert seeded == "int8"assert chosen == "int8"@@ -1698,7 +1699,9 @@ def test_both_experts_of_an_moe_resolve_to_one_claimed_repo():assert VideoBackend._denoiser_prequant_repo_ids(a14b, "nvfp4", a14b.base_repo) == ("unsloth/Wan2.2-T2V-A14B-NVFP4",)- assert VideoBackend._denoiser_prequant_repo_ids(a14b, "int8", a14b.base_repo) == ()+ assert VideoBackend._denoiser_prequant_repo_ids(a14b, "int8", a14b.base_repo) == (+ "unsloth/Wan2.2-T2V-A14B-FP8",+ )assert VideoBackend._denoiser_prequant_repo_ids(a14b, "auto", a14b.base_repo) == ()@@ -1797,8 +1800,11 @@ def test_the_planner_hands_the_resident_pipelines_bytes_to_the_seed_plan(monkeyp)[1],)captured: dict = {}+ # The artifact-sized plan stays resident; the bf16 one (scheme=None) does not, so auto would quantise.monkeypatch.setattr(- vid, "_video_seed_stays_resident", lambda fam, **kw: captured.update(kw) or True+ vid,+ "_video_seed_stays_resident",+ lambda fam, **kw: captured.update(kw) or kw["scheme"] is not None,)monkeypatch.setattr(vid,@@ -1814,6 +1820,32 @@ def test_the_planner_hands_the_resident_pipelines_bytes_to_the_seed_plan(monkeypassert captured["reclaimable_mib"] == 12_345[email protected]("requested, expected", [("auto", None), ("fp8", "fp8")])+def test_the_planner_keeps_the_dense_shards_where_auto_keeps_bf16(monkeypatch, requested, expected):+ """bf16 fits resident: auto runs the released bf16 DiT, so neither the artifact nor a shard skip is planned. An+ explicit scheme is a request and still seeds."""+ import core.inference.video as vid+ from core.inference.video_families import detect_video_family++ fam = detect_video_family("Wan-AI/Wan2.2-TI2V-5B-Diffusers")+ backend = vid.VideoBackend()+ backend._state = types.SimpleNamespace(pipe = None)+ monkeypatch.setattr(vid, "_video_auto_denoiser_scheme", lambda fam, **kw: "fp8")+ monkeypatch.setattr(vid, "_pipeline_device_mib", lambda pipe, ordinal = None: 0)+ monkeypatch.setattr(vid, "_video_seed_stays_resident", lambda fam, **kw: True)+ monkeypatch.setattr(+ vid,+ "resolve_diffusion_device_target",+ lambda **_k: types.SimpleNamespace(device = "cuda", dtype = None, ordinal = None),+ )+ assert (+ backend._video_planned_auto_denoiser_scheme(+ fam, base = None, kind = "pipeline", transformer_quant = requested, speed_mode = None+ )+ == expected+ )++def test_only_the_resident_bytes_on_the_target_card_are_credited():"""Only bytes on the target card are credited; a storage shared by two tensors counts once."""import core.inference.video as viddiff --git a/studio/backend/tests/test_video_quantised_offload.py b/studio/backend/tests/test_video_quantised_offload.pyindex 1f85c26c1ed..2d426846a2c 100644--- a/studio/backend/tests/test_video_quantised_offload.py+++ b/studio/backend/tests/test_video_quantised_offload.py@@ -210,14 +210,43 @@ def test_auto_keeps_bf16_where_the_dit_stays_resident_at_80(fake_runtime, monkeydef test_explicit_fp8_resident_dit_beside_streamed_text_encoder(fake_runtime, monkeypatch):- """A torchao fp8 DiT on 24 GiB engages once the text encoder streams."""+ """A torchao fp8 DiT on 24 GiB engages once the text encoder streams. Wan hosts its fp8 artifact, so the explicit+ request seeds it rather than quantising the released shards at load."""spy = _spoof(monkeypatch, tier_gib = 24)status = VideoBackend().load_pipeline(FAMILIES["wan2.2-ti2v-5b"], transformer_quant = "fp8")assert _tier_code(spy.plans[-1]) == "dit"assert status["transformer_quant"] == "fp8"+ assert spy.seeded == ["fp8"]+ assert not spy.quant+++def test_explicit_fp8_runtime_quant_without_a_hosted_artifact(fake_runtime, monkeypatch):+ """Where no fp8 artifact is hosted (HunyuanVideo-1.5) the same request quantises at load, DiT resident."""+ spy = _spoof(monkeypatch, tier_gib = 24)+ status = VideoBackend().load_pipeline(FAMILIES["hv15-480p"], transformer_quant = "fp8")+ assert _tier_code(spy.plans[-1]) == "dit"+ assert status["transformer_quant"] == "fp8"+ assert not spy.seededassert spy.quant and not spy.quant[0].get("offload")[email protected]("family", ["wan2.2-ti2v-5b", "wan2.2-t2v-a14b"])[email protected]("tier_gib", [24, 48])+def test_auto_seeds_the_hosted_artifact_only_where_it_would_quantise(+ fake_runtime, monkeypatch, family, tier_gib+):+ """Auto quantises a Wan DiT only where bf16 does not stay resident; there the hosted int8 is seeded instead of a+ runtime quantise, and where bf16 fits (the planner table) nothing is seeded."""+ spy = _spoof(monkeypatch, tier_gib = tier_gib)+ status = VideoBackend().load_pipeline(FAMILIES[family])+ tier, precision = EXPECTED[family][tier_gib]+ if precision == _BF:+ assert not spy.seeded and status["transformer_quant"] in (None, "off")+ elif precision == _AO:+ assert spy.seeded == ["int8"] and not spy.quant+ assert status["transformer_quant"] == "int8"++def test_explicit_fp8_refused_with_reason_when_the_dit_must_move(fake_runtime, monkeypatch):_spoof(monkeypatch, tier_gib = 16)with pytest.raises(RuntimeError, match = r"moves the DiT .*int8 runs torchao-free"):diff --git a/studio/backend/tests/test_video_wan_hosted_prequant.py b/studio/backend/tests/test_video_wan_hosted_prequant.pynew file mode 100644index 00000000000..ce6bc056928--- /dev/null+++ b/studio/backend/tests/test_video_wan_hosted_prequant.py@@ -0,0 +1,92 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""The Wan2.2 video families resolve their hosted fp8 / int8 denoiser artifacts, so a conventional load seeds them+instead of quantising the released fp32 shards at load. Hermetic: registry reads only, no torch, no Hub."""++from __future__ import annotations++import pytest++from core.inference.video_denoiser_prequant import denoiser_prequant_sources+from core.inference.video_families import (+ detect_video_family,+ video_family_prequant_repo,+ video_family_prequant_resident_gb,+ video_family_prequant_schemes,+)++TI2V_5B = "Wan-AI/Wan2.2-TI2V-5B-Diffusers"+T2V_A14B = "Wan-AI/Wan2.2-T2V-A14B-Diffusers"+++def _names(source) -> tuple[str, ...]:+ return (source.filename,) + tuple(getattr(source, "fallback_filenames", ()) or ())++[email protected]("scheme", ["fp8", "int8"])+def test_ti2v_5b_resolves_its_hosted_artifact(scheme):+ fam = detect_video_family(TI2V_5B)+ assert fam is not None and fam.name == "wan2.2-ti2v-5b"+ assert video_family_prequant_repo(fam, scheme, TI2V_5B) == "unsloth/Wan2.2-TI2V-5B-FP8"+ assert scheme in video_family_prequant_schemes(fam)+ sources = denoiser_prequant_sources(fam, scheme, TI2V_5B)+ assert sources is not None and set(sources) == {"transformer"}+ names = _names(sources["transformer"])+ stem = f"Wan2.2-TI2V-5B-{scheme.upper()}"+ # A safetensors twin, once hosted, is tried first; today's pickle is next.+ assert names[:2] == (f"{stem}.safetensors", f"{stem}.pt")++[email protected]("scheme", ["fp8", "int8"])+def test_t2v_a14b_seeds_both_experts_from_their_own_files(scheme):+ fam = detect_video_family(T2V_A14B)+ assert fam is not None and fam.name == "wan2.2-t2v-a14b"+ sources = denoiser_prequant_sources(fam, scheme, T2V_A14B)+ assert sources is not None and set(sources) == {"transformer", "transformer_2"}+ tag = scheme.upper()+ assert f"Wan2.2-T2V-A14B-{tag}.pt" in _names(sources["transformer"])+ # Expert 2 is served by its own row only: falling back to expert 1's name would load the wrong weights.+ assert _names(sources["transformer_2"]) == (f"Wan2.2-T2V-A14B-{tag}-2.pt",)+ assert sources["transformer_2"].location == "unsloth/Wan2.2-T2V-A14B-FP8"+++ "repo, scheme, gb",+ [+ (TI2V_5B, "fp8", 5.1),+ (TI2V_5B, "int8", 5.0),+ (T2V_A14B, "fp8", 29.2),+ (T2V_A14B, "int8", 28.8),+ ],+)+def test_resident_sizes_price_the_artifact(repo, scheme, gb):+ assert video_family_prequant_resident_gb(detect_video_family(repo), scheme) == pytest.approx(gb)+++def test_nvfp4_rows_are_unchanged():+ # Raw rows: the NVFP4 switch hides the scheme from the resolver, not from the table.+ assert ("nvfp4", "unsloth/Wan2.2-TI2V-5B-NVFP4") in detect_video_family(TI2V_5B).prequant_repos+ a14b = detect_video_family(T2V_A14B)+ assert ("nvfp4", "unsloth/Wan2.2-T2V-A14B-NVFP4") in a14b.prequant_repos+ assert (+ "nvfp4",+ "transformer_2",+ "Wan2.2-T2V-A14B-transformer_2-NVFP4.pt",+ ) in a14b.prequant_filenames+++ "repo",+ [+ "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-480p_t2v",+ "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-720p_t2v",+ ],+)[email protected]("scheme", ["fp8", "int8"])+def test_families_without_a_hosted_artifact_resolve_none(repo, scheme):+ """No fp8 / int8 denoiser is hosted for HunyuanVideo-1.5, so nothing may be seeded (it would 404 after the plan+ dropped the released shards)."""+ fam = detect_video_family(repo)+ assert video_family_prequant_repo(fam, scheme, repo) is None+ assert denoiser_prequant_sources(fam, scheme, repo) is None