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 NVFP4: keep ungated and gate-failing video builds out of Auto, check flashinfer against the gate record (#14659)
Daniel Han031a11775704
diff --git a/studio/backend/core/inference/diffusion_nvfp4_gate.py b/studio/backend/core/inference/diffusion_nvfp4_gate.pyindex afa85dfa5c2..8fb9a6eff48 100644--- a/studio/backend/core/inference/diffusion_nvfp4_gate.py+++ b/studio/backend/core/inference/diffusion_nvfp4_gate.py@@ -36,6 +36,9 @@ RECORD_FIELDS = RECORD_KEY_FIELDS + (_CACHE: dict[tuple, tuple] = {}+FLASHINFER_DIST = "flashinfer-python"+_WARNED: set = set()+def _canonical(value: Any) -> str:try:@@ -173,3 +176,97 @@ def nvfp4_gate_backend("""The first passing record's backend. Coverage wants ``nvfp4_gate_backends``."""backends = nvfp4_gate_backends(family, base_repo, path = path)return backends[0] if backends else None+++def installed_flashinfer_version() -> Optional[str]:+ """The installed ``flashinfer-python`` version from its metadata (no import), else an already imported module's+ ``__version__`` (a source or vendored copy has no dist metadata), else None."""+ try:+ from importlib.metadata import version+ found = str(version(FLASHINFER_DIST)).strip()+ if found:+ return found+ except Exception: # noqa: BLE001 -- missing or broken metadata reads as "unknown", never a load error+ pass+ try:+ import sys+ found = str(getattr(sys.modules.get("flashinfer"), "__version__", "") or "").strip()+ return found or None+ except Exception: # noqa: BLE001+ return None+++def record_flashinfer_versions(record: Any) -> tuple:+ """Versions whose kernels this record covers: the one it was measured on, plus any later shown bit-identical on+ the gated checkpoints' own layers (``versions.flashinfer_bit_identical``)."""+ versions = record.get("versions") if isinstance(record, dict) else None+ if not isinstance(versions, dict):+ return ()+ covered: list[str] = []+ measured = versions.get("flashinfer")+ if measured:+ covered.append(str(measured).strip())+ for extra in versions.get("flashinfer_bit_identical") or ():+ if extra and str(extra).strip() not in covered:+ covered.append(str(extra).strip())+ return tuple(covered)+++def nvfp4_gate_flashinfer_mismatch(+ family: Any,+ base_repo: Any,+ *,+ installed: Any = None,+ path: Any = None,+ backend_active: bool = False,+) -> Optional[str]:+ """Why the installed flashinfer is not one a passing flashinfer record covers, or None (covered, no flashinfer+ record, or flashinfer absent: the backend probe answers that case). ``installed`` overrides the metadata read.+ ``backend_active``: the caller knows flashinfer's kernels run, so a version that cannot be read is NOT covered+ (fail closed) rather than read as "flashinfer absent"."""+ current = installed_flashinfer_version() if installed is None else str(installed).strip()+ if not current and not backend_active:+ return None+ covered: list[str] = []+ for record in _passing_records(family, base_repo, path = path):+ if str(record.get("backend") or "").strip().lower() != "flashinfer":+ continue+ versions = record_flashinfer_versions(record)+ if not versions:+ # A record that names no version predates the field; nothing to compare against.+ return None+ if current and current in versions:+ return None+ covered.extend(v for v in versions if v not in covered)+ if not covered:+ return None+ if not current:+ return (+ f"flashinfer's version could not be read, but the NVFP4 accuracy gate for {base_repo} was measured on "+ f"flashinfer {', '.join(covered)}; its kernels were not checked on this install"+ )+ return (+ f"flashinfer {current} is installed, but the NVFP4 accuracy gate for {base_repo} was measured on "+ f"flashinfer {', '.join(covered)}; its kernels were not checked on this version"+ )+++def warn_flashinfer_mismatch_once(+ family: Any,+ base_repo: Any,+ logger: Any = None,+ *,+ backend_active: bool = False,+) -> Optional[str]:+ """Log ``nvfp4_gate_flashinfer_mismatch`` once per (family, base, version); returns the message."""+ message = nvfp4_gate_flashinfer_mismatch(family, base_repo, backend_active = backend_active)+ if message is None:+ return None+ key = (str(family or "").lower(), _canonical(base_repo), installed_flashinfer_version())+ if key not in _WARNED:+ _WARNED.add(key)+ if logger is None:+ import logging+ logger = logging.getLogger(__name__)+ logger.warning(f"nvfp4.gate: {message}")+ return messagediff --git a/studio/backend/core/inference/diffusion_prequant.py b/studio/backend/core/inference/diffusion_prequant.pyindex acb65d36a07..41bfefb07ed 100644--- a/studio/backend/core/inference/diffusion_prequant.py+++ b/studio/backend/core/inference/diffusion_prequant.py@@ -2274,6 +2274,40 @@ def _reports_rejected_cache_entry(fn: Any) -> Any:return wrapper+def _engage_nvfp4_backend(+ transformer: Any,+ metadata: Any,+ device: Any,+ *,+ family: Optional[str] = None,+ base: Optional[str] = None,+ logger: Any = None,+) -> int:+ """Move a loaded NVFP4 transformer onto the backend ``device`` selects; returns the layers moved to flashinfer.++ The flashinfer coverage warning fires here, once layers really run flashinfer's kernels: scheme selection also+ runs for planning and validation, which load nothing and must not use up the once-only warning."""+ from .diffusion_nvfp4_linear import convert_nvfp4_backend+ from .diffusion_nvfp4_ops import select_nvfp4_backend++ converted = convert_nvfp4_backend(+ transformer, metadata, select_nvfp4_backend(device), logger = logger+ )+ if converted:+ try:+ from .diffusion_nvfp4_gate import warn_flashinfer_mismatch_once+ md = metadata if isinstance(metadata, dict) else {}+ # The checkpoint's own base first: ``base`` can be the ungated mirror the weights were fetched from.+ for base_repo in dict.fromkeys(b for b in (md.get("base_model_id"), base) if b):+ if warn_flashinfer_mismatch_once(+ family or md.get("family"), base_repo, logger, backend_active = True+ ):+ break+ except Exception: # noqa: BLE001 -- a warning, never a load error+ pass+ return converted++@_reports_rejected_cache_entrydef load_prequantized_transformer(transformer_cls: Any,@@ -2477,14 +2511,16 @@ def load_prequantized_transformer(if scheme == "nvfp4":from .diffusion_nvfp4_act_quant import install_nvfp4_act_quant_patch- from .diffusion_nvfp4_linear import convert_nvfp4_backend# Layers left on torchao quantise activations through NVFP4Tensor.to_nvfp4 at run time.install_nvfp4_act_quant_patch(logger)- from .diffusion_nvfp4_ops import select_nvfp4_backend-- convert_nvfp4_backend(- transformer, metadata, select_nvfp4_backend(device), logger = logger+ _engage_nvfp4_backend(+ transformer,+ metadata,+ device,+ family = family,+ base = base,+ logger = logger,)# assign=True shares the tensors: a live reference doubles the peak on unified memory.del state_dictdiff --git a/studio/backend/core/inference/diffusion_transformer_quant.py b/studio/backend/core/inference/diffusion_transformer_quant.pyindex ad1ff8e1c08..cef4afba60a 100644--- a/studio/backend/core/inference/diffusion_transformer_quant.py+++ b/studio/backend/core/inference/diffusion_transformer_quant.py@@ -445,10 +445,17 @@ def _nvfp4_gate_backend_ok(family, base_repo, device: Any) -> bool:if not nvfp4_diffusion_enabled():return Falsetry:- from .diffusion_nvfp4_gate import nvfp4_gate_backends+ from .diffusion_nvfp4_gate import nvfp4_gate_backends, nvfp4_gate_flashinfer_mismatchfrom .diffusion_nvfp4_ops import select_nvfp4_backend- return str(select_nvfp4_backend(device)).strip().lower() in nvfp4_gate_backends(- family, base_repo++ backend = str(select_nvfp4_backend(device)).strip().lower()+ if backend not in nvfp4_gate_backends(family, base_repo):+ return False+ # Auto takes a gated head only on a flashinfer whose kernels the record covers; an unreadable version is not+ # covered. Silent: auto then runs another scheme, and the warning belongs to a load that runs those kernels.+ return (+ backend != "flashinfer"+ or nvfp4_gate_flashinfer_mismatch(family, base_repo, backend_active = True) is None)except Exception: # noqa: BLE001 -- see the docstring: an unanswerable probe keeps the denyreturn False@@ -478,6 +485,15 @@ def _family_denied(return True+def _nvfp4_gate_failure(family) -> Optional[str]:+ """The measured gate failure behind a family's nvfp4 deny, or None; lazy, the video registry imports late."""+ try:+ from .video_families import nvfp4_gate_failure+ return nvfp4_gate_failure(family)+ except Exception: # noqa: BLE001 -- no reason on file falls back to the generic deny text+ return None++_TRAIN_DENY_NVFP4_REASON = ("nvfp4 is inference-only: the accuracy gate behind it measures a frozen forward at a ""per-layer policy, and no training run has been measured on 4-bit frozen linears"@@ -542,6 +558,13 @@ def explain_unusable_scheme(return nvfp4_disabled_message()if family_denies_scheme(family, scheme, base_repo):if scheme == TQ_NVFP4:+ failure = _nvfp4_gate_failure(family)+ if failure is not None:+ return (+ f"'{scheme}' is ruled out for family '{family}'"+ + (f" on base '{base_repo}'" if base_repo else "")+ + f": it was measured and failed the NVFP4 accuracy gate ({failure})"+ )return (f"'{scheme}' is ruled out for family '{family}'"+ (f" on base '{base_repo}'" if base_repo else "")@@ -1050,7 +1073,9 @@ def select_transformer_quant_scheme(if requested != TQ_AUTO:if _family_denied(family, requested, base_repo):return None- return requested if _scheme_supported(requested, device, unproven_ok = unproven_ok) else None+ if not _scheme_supported(requested, device, unproven_ok = unproven_ok):+ return None+ return requestedcap = _capability()if cap is None:return Nonediff --git a/studio/backend/core/inference/nvfp4_gate_record.json b/studio/backend/core/inference/nvfp4_gate_record.jsonindex fbc7b13621e..5d99570394a 100644--- a/studio/backend/core/inference/nvfp4_gate_record.json+++ b/studio/backend/core/inference/nvfp4_gate_record.json@@ -1,6 +1,6 @@{"version": 1,- "comment": "Reviewed NVFP4 accuracy-gate verdicts, one entry per (family, base_repo, policy_id, policy_version, checkpoint_sha256). One entry says that ONE published checkpoint rendered the gate's prompt/resolution pairs within the recorded thresholds of its dense reference, on the backend, GPU and toolchain the entry names. Read by core/inference/diffusion_nvfp4_gate.py, which re-derives the verdict rather than trusting it as stored. Entries are measured out of band and committed after review; nothing writes this file at run time. Empty means no checkpoint has been gated yet, which keeps nvfp4 out of the auto ladder for every family.",+ "comment": "Reviewed NVFP4 accuracy-gate verdicts, one entry per (family, base_repo, policy_id, policy_version, checkpoint_sha256). One entry says that ONE published checkpoint rendered the gate's prompt/resolution pairs within the recorded thresholds of its dense reference, on the backend, GPU and toolchain the entry names. Read by core/inference/diffusion_nvfp4_gate.py, which re-derives the verdict rather than trusting it as stored. Entries are measured out of band and committed after review; nothing writes this file at run time. Empty means no checkpoint has been gated yet, which keeps nvfp4 out of the auto ladder for every family. versions.flashinfer is the version a record was measured on; versions.flashinfer_bit_identical lists versions whose NVFP4 quantize + GEMM outputs were shown bit-identical on the gated checkpoints' own layers (0.6.6 vs 0.6.18.post1, B200: 144 of 144 layer / M cases, 36 on each of the four gated checkpoints). On any other installed flashinfer, or one whose version cannot be read, auto does not take a gated nvfp4 head, and an explicit nvfp4 load that moves layers onto flashinfer logs one warning.","records": [{"family": "z-image",@@ -44,7 +44,10 @@"torch": "2.12.1+cu130","torchao": "0.18.0","diffusers": "0.41.0.dev0",- "flashinfer": "0.6.18.post1"+ "flashinfer": "0.6.18.post1",+ "flashinfer_bit_identical": [+ "0.6.6"+ ]},"gate_script_sha256": "d0b423658874f8430b1508f839cbc7fe39b1ee04d73931ffe4f24c444b11d3b5","run_date": "2026-09-24",@@ -121,7 +124,10 @@"torch": "2.12.1+cu130","torchao": "0.18.0","diffusers": "0.41.0.dev0",- "flashinfer": "0.6.18.post1"+ "flashinfer": "0.6.18.post1",+ "flashinfer_bit_identical": [+ "0.6.6"+ ]},"gate_script_sha256": "d0b423658874f8430b1508f839cbc7fe39b1ee04d73931ffe4f24c444b11d3b5","run_date": "2026-09-24",@@ -198,7 +204,10 @@"torch": "2.12.1+cu130","torchao": "0.18.0","diffusers": "0.41.0.dev0",- "flashinfer": "0.6.18.post1"+ "flashinfer": "0.6.18.post1",+ "flashinfer_bit_identical": [+ "0.6.6"+ ]},"gate_script_sha256": "d0b423658874f8430b1508f839cbc7fe39b1ee04d73931ffe4f24c444b11d3b5","run_date": "2026-09-24",@@ -275,7 +284,10 @@"torch": "2.12.1+cu130","torchao": "0.18.0","diffusers": "0.41.0.dev0",- "flashinfer": "0.6.18.post1"+ "flashinfer": "0.6.18.post1",+ "flashinfer_bit_identical": [+ "0.6.6"+ ]},"gate_script_sha256": "d0b423658874f8430b1508f839cbc7fe39b1ee04d73931ffe4f24c444b11d3b5","run_date": "2026-09-24",diff --git a/studio/backend/core/inference/video_families.py b/studio/backend/core/inference/video_families.pyindex 58b16e3cf73..ebde2871f28 100644--- a/studio/backend/core/inference/video_families.py+++ b/studio/backend/core/inference/video_families.py@@ -437,6 +437,28 @@ _HUNYUAN15_INT8_EXCLUDES = ("to_add_out","ff_context",)+# Measured failing the NVFP4 accuracy gate (LPIPS mean vs bf16 <= 0.25), so nvfp4 is denied outright, as the image+# families deny an ungated base. HunyuanVideo-1.5: hosted 480p / 720p 0.62 / 0.59 (Studio main, 20 steps); the 50-step+# campaign put GPTQ NVFP4 at 0.44 and fp8 itself at 0.35 to 0.37, so no NVFP4 rebuild clears the bar.+# Wan2.2-TI2V-5B: hosted 0.29; weight-only 4-bit (bf16 activations) is already 0.29 at the default grid, and the+# layer keep-sets that come near 0.25 save about 10% of fp8's bytes, where fp8 (0.17) already passes.+_NVFP4_GATE_FAILED = frozenset({"nvfp4"})+# What a refused explicit nvfp4 request says for those families: measured and failed, not merely unmeasured.+NVFP4_GATE_FAILURES: dict[str, str] = {+ "hunyuanvideo-1.5": "the hosted NVFP4 build measured LPIPS 0.62 against bf16 (bar 0.25), and no NVFP4 rebuild "+ "clears it: GPTQ reached 0.44 and fp8 itself 0.35 to 0.37",+ "hunyuanvideo-1.5-720p": "the hosted NVFP4 build (RTN) measured LPIPS 0.59 against bf16 (bar 0.25), and no NVFP4 "+ "rebuild clears it: on the 480p weights GPTQ reached 0.44 and fp8 itself 0.35 to 0.37",+ "wan2.2-ti2v-5b": "the hosted NVFP4 build measured LPIPS 0.29 to 0.30 against bf16 (bar 0.25); weight-only 4-bit is "+ "already 0.29, while fp8 passes at 0.17",+}+++def nvfp4_gate_failure(family: Optional[str]) -> Optional[str]:+ """Why ``family``'s nvfp4 builds were measured and failed the accuracy gate, or None (not a measured failure)."""+ return NVFP4_GATE_FAILURES.get(str(family or "").strip().lower())++# nvfp4 raises on an empty activation; HunyuanVideo-1.5's attention trim hits it every t2v render._HUNYUAN15_NVFP4_ZERO_ROW_TOKENS = ("image_embedder", "context_embedder_2")# LTX-2 is audiovisual: every block carries an audio-side stream (audio_attn1 / audio_attn2 / audio_ff, fed by@@ -704,6 +726,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (trainable = True,label = "Wan2.2 TI2V 5B",profile = FamilyProfile(+ scheme_deny = _NVFP4_GATE_FAILED,untiled_vae = UntiledVae(bytes_per_latent_pixel = 2.5 * 2**20, output_scale = (16, 4)),preview_factors = "wan22_5b",auto_static_skip = (@@ -760,9 +783,14 @@ _FAMILIES: tuple[VideoFamily, ...] = (VideoFamily(name = "wan2.2-t2v-a14b",profile = FamilyProfile(+ # gated: auto leads with nvfp4 only once a passing accuracy-gate record exists for this base and+ # backend, the rule the image families follow. None exists yet (no bf16 reference was measured; the+ # hosted NVFP4 experts were only compared with the FP8 build), so auto takes the ladder (int8) here and+ # nvfp4 stays an explicit pick.auto_prefer = AutoPrefer(floor = (10, 0),schemes = ("nvfp4", "int8", "fp8", "mxfp8"),+ gated = True,backend = "flashinfer",),untiled_vae = _WAN21_VAE_UNTILED,@@ -877,6 +905,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (VideoFamily(name = "hunyuanvideo-1.5",profile = FamilyProfile(+ scheme_deny = _NVFP4_GATE_FAILED,int8_exclude_tokens = _HUNYUAN15_INT8_EXCLUDES,nvfp4_zero_row_tokens = _HUNYUAN15_NVFP4_ZERO_ROW_TOKENS,preview_factors = "hv15",@@ -929,6 +958,7 @@ _FAMILIES: tuple[VideoFamily, ...] = (VideoFamily(name = "hunyuanvideo-1.5-720p",profile = FamilyProfile(+ scheme_deny = _NVFP4_GATE_FAILED,int8_exclude_tokens = _HUNYUAN15_INT8_EXCLUDES,nvfp4_zero_row_tokens = _HUNYUAN15_NVFP4_ZERO_ROW_TOKENS,preview_factors = "hv15",@@ -1262,7 +1292,9 @@ def video_family_prequant_schemes(fam: VideoFamily, task: Optional[str] = None)schemes.append(entry[1])if task:schemes = [s for s in schemes if video_family_prequant_available(fam, s, task = task)]- return without_nvfp4(schemes)+ denied = getattr(getattr(fam, "profile", None), "scheme_deny", None) or frozenset()+ # A family-denied scheme (a measured gate failure) is never offered, even though its build is hosted.+ return without_nvfp4([s for s in schemes if s not in denied])def snap_num_frames(fam: VideoFamily, num_frames: int) -> int:diff --git a/studio/backend/tests/fixtures/diffusion_family_data_freeze.json b/studio/backend/tests/fixtures/diffusion_family_data_freeze.jsonindex f125876c89b..472aa6549be 100644--- a/studio/backend/tests/fixtures/diffusion_family_data_freeze.json+++ b/studio/backend/tests/fixtures/diffusion_family_data_freeze.json@@ -3475,7 +3475,7 @@10,0],- "gated": false,+ "gated": true,"schemes": ["nvfp4","int8",@@ -3506,6 +3506,12 @@"flux.3-klein-base": ["nvfp4"],+ "hunyuanvideo-1.5": [+ "nvfp4"+ ],+ "hunyuanvideo-1.5-720p": [+ "nvfp4"+ ],"qwen-image": ["mxfp8","nvfp4"@@ -3517,6 +3523,9 @@"qwen-image-layered": ["mxfp8","nvfp4"+ ],+ "wan2.2-ti2v-5b": [+ "nvfp4"]},"family_train_scheme_deny": {diff --git a/studio/backend/tests/test_diffusion_backend.py b/studio/backend/tests/test_diffusion_backend.pyindex 05849d16a1c..420f8fc338f 100644--- a/studio/backend/tests/test_diffusion_backend.py+++ b/studio/backend/tests/test_diffusion_backend.py@@ -11707,6 +11707,12 @@ def test_the_download_plan_resolves_the_same_nvfp4_rung_the_load_does(monkeypatc)monkeypatch.setattr(dmod, "prequant_checkpoint_cached", lambda source, **kw: False)monkeypatch.setattr(ops, "select_nvfp4_backend", lambda device = None: "flashinfer")+ from core.inference import diffusion_nvfp4_gate as gate+ from core.inference.diffusion_nvfp4_install import FLASHINFER_VERSION++ # The gate covers only the flashinfer its record was measured on; pin the version Studio installs so the+ # answer does not depend on this host's flashinfer (CI runners have none).+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: FLASHINFER_VERSION)target = SimpleNamespace(device = "cuda", dtype = None)assert (@@ -11718,6 +11724,17 @@ def test_the_download_plan_resolves_the_same_nvfp4_rung_the_load_does(monkeypatc== "unsloth/FLUX.1-schnell-NVFP4")+ # An unreadable version is not covered: the plan and the load both drop the nvfp4 rung, so nothing fetches it.+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: None)+ assert (+ dmod._planned_quant_scheme(fam, target, "auto", base_repo = base, prequant_path = None)+ != "nvfp4"+ )+ assert (+ dmod._uncached_prequant_repo(fam, target, "auto", base_repo = base, prequant_path = None)+ != "unsloth/FLUX.1-schnell-NVFP4"+ )+class _FakeDenoiser:"""A denoiser whose parameters expose a dtype to the quantisation gate."""diff --git a/studio/backend/tests/test_diffusion_transformer_quant.py b/studio/backend/tests/test_diffusion_transformer_quant.pyindex 6b2ea1e202f..c5a40155016 100644--- a/studio/backend/tests/test_diffusion_transformer_quant.py+++ b/studio/backend/tests/test_diffusion_transformer_quant.py@@ -1283,6 +1283,8 @@ def test_the_guard_list_does_not_double_up_with_the_pad_or_exclude_lists():def test_quantize_transformer_guards_after_padding(monkeypatch):_stub_torch(monkeypatch, cc = (10, 0))_allow(monkeypatch, {TQ_NVFP4})+ # The ordering under test, not the family's measured nvfp4 deny (HunyuanVideo-1.5 failed the gate).+ monkeypatch.setattr(tq, "_FAMILY_SCHEME_DENY", {})order = []tqz = types.ModuleType("torchao.quantization")tqz.quantize_ = lambda module, config, filter_fn = None: order.append("quantize_")@@ -1526,10 +1528,14 @@ def test_the_shipped_prefer_table_keeps_the_ladder_as_it_was(monkeypatch):"qwen-image-2.1","wan2.2-t2v-a14b",}- ungated = {name for name, row in tq._FAMILY_AUTO_PREFER.items() if not row.gated}- assert ungated == {"wan2.2-t2v-a14b"}- for name in ungated:- assert tq._FAMILY_AUTO_PREFER[name].backend+ # An nvfp4-bearing auto head needs a passing gate record, the image rule; none ships ungated.+ ungated = {+ name+ for name, row in tq._FAMILY_AUTO_PREFER.items()+ if not row.gated and TQ_NVFP4 in row.schemes+ }+ assert ungated == set()+ assert tq._FAMILY_AUTO_PREFER["wan2.2-t2v-a14b"].backend == "flashinfer"families = (None,"hunyuanvideo-1.5",@@ -1649,9 +1655,34 @@ def test_the_floor_and_the_consumer_rule_still_outrank_the_backend(monkeypatch):)-def test_the_a14b_row_leads_with_nvfp4_only_where_flashinfer_serves_it(monkeypatch):+def _gate_lifted(monkeypatch, passed = True):+ """A passing gate record on every backend (or none): what a measured A14B record would read as."""+ monkeypatch.setattr(tq, "_nvfp4_gate_passed", lambda family, base_repo: passed)+ monkeypatch.setattr(tq, "_nvfp4_gate_backend_ok", lambda family, base_repo, device: passed)+++def test_the_a14b_row_does_not_lead_with_nvfp4_without_a_gate_record(monkeypatch):+ _stub_torch(monkeypatch, cc = (10, 0))+ _allow(monkeypatch, {TQ_NVFP4, TQ_FP8, TQ_MXFP8, TQ_INT8})+ base = "Wan-AI/Wan2.2-T2V-A14B-Diffusers"+ _stub_nvfp4_backend(monkeypatch, "flashinfer")+ assert (+ select_transformer_quant_scheme(+ _target(), "auto", family = "wan2.2-t2v-a14b", base_repo = base, **_HAS_PREQUANT+ )+ == TQ_INT8+ )+ assert tq.auto_scheme_candidates(+ _target(), "wan2.2-t2v-a14b", base_repo = base, **_HAS_PREQUANT+ ) == (TQ_INT8, TQ_FP8, TQ_MXFP8)+++def test_the_a14b_row_leads_with_nvfp4_only_where_a_gate_record_and_flashinfer_serve_it(+ monkeypatch,+):_stub_torch(monkeypatch, cc = (10, 0))_allow(monkeypatch, {TQ_NVFP4, TQ_FP8, TQ_MXFP8, TQ_INT8})+ _gate_lifted(monkeypatch)base = "Wan-AI/Wan2.2-T2V-A14B-Diffusers"_stub_nvfp4_backend(monkeypatch, "flashinfer")diff --git a/studio/backend/tests/test_nvfp4_gate_coverage.py b/studio/backend/tests/test_nvfp4_gate_coverage.pynew file mode 100644index 00000000000..1f1f32d092c--- /dev/null+++ b/studio/backend/tests/test_nvfp4_gate_coverage.py@@ -0,0 +1,474 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Every hosted NVFP4 denoiser Studio references is either gated or kept away from auto, and a gate record only+covers the flashinfer kernels it was measured (or shown bit-identical) on."""++from __future__ import annotations++import json+import types++import pytest++import core.inference.diffusion_nvfp4_gate as gate+import core.inference.diffusion_transformer_quant as tq+from core.inference.diffusion_families import _FAMILIES as FAMILIES, family_prequant_repo+from core.inference.diffusion_nvfp4_gate import load_gate_records, nvfp4_gate_passed+from core.inference.video_families import _FAMILIES as VIDEO_FAMILIES+from core.inference.video_families import (+ detect_video_family,+ video_family_prequant_schemes,+)++_FAILED_VIDEO_REPOS = (+ "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-480p_t2v",+ "hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-720p_t2v",+ "Wan-AI/Wan2.2-TI2V-5B-Diffusers",+)+_A14B = "Wan-AI/Wan2.2-T2V-A14B-Diffusers"+_ZIMAGE = "Tongyi-MAI/Z-Image-Turbo"+++def enabled(monkeypatch):+ monkeypatch.setenv("UNSLOTH_NVFP4_DIFFUSION", "1")+++def _blackwell(monkeypatch, backend = "flashinfer"):+ import core.inference.diffusion_nvfp4_ops as ops++ monkeypatch.setattr(tq, "dense_transformer_supported", lambda target: True)+ monkeypatch.setattr(tq, "_capability", lambda *a, **k: (10, 0))+ monkeypatch.setattr(tq, "_is_consumer_gpu", lambda *a, **k: False)+ monkeypatch.setattr(tq, "_scheme_supported", lambda scheme, device, **kw: True)+ monkeypatch.setattr(ops, "select_nvfp4_backend", lambda device = None: backend)+ return types.SimpleNamespace(device = "cuda:0", dtype = "bfloat16")+++def _hosted(scheme):+ return True+++def _image_nvfp4_rows():+ rows = []+ for fam in FAMILIES:+ bases = {fam.base_repo} | {+ entry[0]+ for entry in (getattr(fam, "prequant_variant_repos", ()) or ())+ if entry[1] == "nvfp4"+ }+ for base in sorted(b for b in bases if b):+ repo = family_prequant_repo(fam, "nvfp4", base)+ if repo:+ rows.append((fam.name, base, repo))+ return rows+++def test_every_hosted_image_nvfp4_build_has_a_passing_gate_record_for_that_repo(enabled):+ rows = _image_nvfp4_rows()+ assert rows+ recorded = {+ (r["family"], r["repo_id"]) for r in load_gate_records() if r.get("all_pass") is True+ }+ for family, base, repo in rows:+ assert nvfp4_gate_passed(family, base), (family, base, repo)+ assert (family, repo) in recorded, (family, repo)+++def test_no_family_can_auto_pick_nvfp4_without_a_gate_record():+ for name, row in tq._FAMILY_AUTO_PREFER.items():+ if "nvfp4" in row.schemes:+ assert row.gated, name+++def test_the_ungated_a14b_build_never_leads_auto_but_stays_an_explicit_pick(monkeypatch, enabled):+ target = _blackwell(monkeypatch)+ fam = detect_video_family(_A14B)+ assert "nvfp4" in video_family_prequant_schemes(fam)+ assert (+ tq.select_transformer_quant_scheme(+ target, "auto", family = fam.name, base_repo = _A14B, has_prequant = _hosted+ )+ == "int8"+ )+ assert (+ tq.select_transformer_quant_scheme(+ target, "nvfp4", family = fam.name, base_repo = _A14B, has_prequant = _hosted+ )+ == "nvfp4"+ )++[email protected]("repo", _FAILED_VIDEO_REPOS)+def test_video_builds_that_failed_the_gate_are_denied_and_not_advertised(+ monkeypatch, enabled, repo+):+ target = _blackwell(monkeypatch)+ fam = detect_video_family(repo)+ assert fam is not None+ assert "nvfp4" not in video_family_prequant_schemes(fam)+ for requested in ("nvfp4", "auto"):+ assert (+ tq.select_transformer_quant_scheme(+ target, requested, family = fam.name, base_repo = fam.base_repo, has_prequant = _hosted+ )+ != "nvfp4"+ ), (repo, requested)+ assert tq.family_denies_scheme(fam.name, "nvfp4", fam.base_repo)+ reason = tq.explain_unusable_scheme(fam.name, "nvfp4", fam.base_repo)+ # A measured failure, not an unmeasured base: the refusal must not say nothing was measured.+ assert "measured and failed the NVFP4 accuracy gate" in reason+ assert "LPIPS" in reason+ assert "nothing has measured" not in reason+++def test_every_video_family_with_a_hosted_nvfp4_build_is_denied_or_kept_out_of_auto():+ for fam in VIDEO_FAMILIES:+ hosted = any(entry[0] == "nvfp4" for entry in (fam.prequant_repos or ()))+ if not hosted:+ continue+ prefer = getattr(fam.profile, "auto_prefer", None)+ denied = "nvfp4" in fam.profile.scheme_deny+ assert denied or prefer is None or prefer.gated, fam.name+++def _gate_file(tmp_path, *records):+ path = tmp_path / "nvfp4_gate_record.json"+ path.write_text(json.dumps({"version": 1, "records": list(records)}), encoding = "utf-8")+ return path+++def _zimage_record(**versions):+ return {+ "family": "z-image",+ "base_repo": _ZIMAGE,+ "policy_id": "zimg_rg76_v1",+ "policy_version": 1,+ "checkpoint_sha256": "a" * 64,+ "all_pass": True,+ "backend": "flashinfer",+ "versions": versions,+ }+++def test_the_shipped_records_cover_the_flashinfer_studio_installs():+ from core.inference.diffusion_nvfp4_install import FLASHINFER_VERSION++ records = [r for r in load_gate_records() if r.get("backend") == "flashinfer"]+ assert records+ for record in records:+ assert FLASHINFER_VERSION in gate.record_flashinfer_versions(record), record["repo_id"]+++def test_a_flashinfer_the_record_names_or_lists_bit_identical_is_covered(tmp_path):+ path = _gate_file(+ tmp_path, _zimage_record(flashinfer = "0.6.18.post1", flashinfer_bit_identical = ["0.6.6"])+ )+ for version in ("0.6.18.post1", "0.6.6"):+ assert (+ gate.nvfp4_gate_flashinfer_mismatch("z-image", _ZIMAGE, installed = version, path = path)+ is None+ )+++def test_an_unchecked_flashinfer_is_named_in_the_mismatch(tmp_path):+ path = _gate_file(+ tmp_path, _zimage_record(flashinfer = "0.6.18.post1", flashinfer_bit_identical = ["0.6.6"])+ )+ message = gate.nvfp4_gate_flashinfer_mismatch("z-image", _ZIMAGE, installed = "0.7.0", path = path)+ assert message and "0.7.0" in message and "0.6.18.post1" in message and "0.6.6" in message+++def test_no_installed_flashinfer_or_no_recorded_version_is_not_a_mismatch(tmp_path):+ path = _gate_file(tmp_path, _zimage_record(flashinfer = "0.6.6"))+ assert gate.nvfp4_gate_flashinfer_mismatch("z-image", _ZIMAGE, installed = "", path = path) is None+ bare = _gate_file(tmp_path, _zimage_record())+ assert (+ gate.nvfp4_gate_flashinfer_mismatch("z-image", _ZIMAGE, installed = "0.7.0", path = bare)+ is None+ )+++def test_auto_drops_the_gated_head_on_an_unchecked_flashinfer_but_explicit_still_loads(+ monkeypatch, enabled, tmp_path+):+ target = _blackwell(monkeypatch)+ path = _gate_file(tmp_path, _zimage_record(flashinfer = "0.6.6"))+ monkeypatch.setattr(gate, "GATE_RECORD_PATH", path)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.6.6")+ assert tq._nvfp4_gate_backend_ok("z-image", _ZIMAGE, "cuda:0") is True+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ assert tq._nvfp4_gate_backend_ok("z-image", _ZIMAGE, "cuda:0") is False+ assert (+ tq.select_transformer_quant_scheme(+ target, "nvfp4", family = "z-image", base_repo = _ZIMAGE, has_prequant = _hosted+ )+ == "nvfp4"+ )+++def test_the_mismatch_warning_is_logged_once(monkeypatch, tmp_path, caplog):+ path = _gate_file(tmp_path, _zimage_record(flashinfer = "0.6.6"))+ monkeypatch.setattr(gate, "GATE_RECORD_PATH", path)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ monkeypatch.setattr(+ gate,+ "_passing_records",+ lambda family, base_repo, path = None: (_zimage_record(flashinfer = "0.6.6"),),+ )+ with caplog.at_level("WARNING"):+ for _ in range(3):+ assert gate.warn_flashinfer_mismatch_once("z-image", _ZIMAGE) is not None+ assert sum("flashinfer 0.7.0" in r.getMessage() for r in caplog.records) == 1+++def test_the_installed_version_read_never_raises():+ value = gate.installed_flashinfer_version()+ assert value is None or isinstance(value, str)+++def test_an_ungated_base_that_was_never_measured_keeps_the_generic_refusal(enabled):+ reason = tq.explain_unusable_scheme("qwen-image", "nvfp4", "Qwen/Qwen-Image")+ assert "no reviewed NVFP4 accuracy-gate record" in reason+ assert "measured and failed" not in reason+++def _engage(+ monkeypatch,+ backend = "flashinfer",+ layers = 4,+):+ """``_engage_nvfp4_backend`` with the conversion stubbed: ``layers`` move only when the backend is flashinfer."""+ import core.inference.diffusion_nvfp4_linear as lin+ import core.inference.diffusion_nvfp4_ops as ops+ import core.inference.diffusion_prequant as pq++ monkeypatch.setattr(ops, "select_nvfp4_backend", lambda device = None: backend)+ monkeypatch.setattr(+ lin,+ "convert_nvfp4_backend",+ lambda transformer, metadata, chosen, logger = None: layers if chosen == "flashinfer" else 0,+ )++ def run(+ family,+ base,+ metadata = None,+ ):+ return pq._engage_nvfp4_backend(+ object(), metadata or {}, "cuda:0", family = family, base = base+ )++ return run+++def _gate_warnings(caplog):+ return [r.getMessage() for r in caplog.records if "nvfp4.gate" in r.getMessage()]+++ ("family", "base"),+ [("z-image", _ZIMAGE), ("qwen-image", "Qwen/Qwen-Image-2512")],+)+def test_an_unchecked_flashinfer_warns_once_when_an_nvfp4_load_engages_it(+ monkeypatch, enabled, caplog, family, base+):+ """z-image has no nvfp4 deny entry (its record only feeds auto); qwen-image does. Both warn, once, at the load."""+ target = _blackwell(monkeypatch)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ assert family not in tq._FAMILY_SCHEME_DENY or "nvfp4" in tq._FAMILY_SCHEME_DENY[family]+ engage = _engage(monkeypatch)+ with caplog.at_level("WARNING"):+ assert (+ tq.select_transformer_quant_scheme(+ target, "nvfp4", family = family, base_repo = base, has_prequant = _hosted+ )+ == "nvfp4"+ )+ assert not _gate_warnings(caplog)+ for _ in range(2):+ assert engage(family, base) == 4+ hits = [m for m in _gate_warnings(caplog) if "flashinfer 0.7.0" in m]+ assert len(hits) == 1, _gate_warnings(caplog)+++def test_planning_and_validation_selects_do_not_use_up_the_load_warning(+ monkeypatch, enabled, caplog+):+ """Scheme selection runs for planning, the pre-eviction gate and validation, none of which loads kernels."""+ target = _blackwell(monkeypatch)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ with caplog.at_level("WARNING"):+ for unproven_ok in (False, True, False):+ tq.select_transformer_quant_scheme(+ target,+ "nvfp4",+ family = "z-image",+ base_repo = _ZIMAGE,+ has_prequant = _hosted,+ unproven_ok = unproven_ok,+ )+ assert not _gate_warnings(caplog)+ assert gate._WARNED == set()+ with caplog.at_level("WARNING"):+ _engage(monkeypatch)("z-image", _ZIMAGE)+ assert len([m for m in _gate_warnings(caplog) if "flashinfer 0.7.0" in m]) == 1+++def test_a_covered_flashinfer_loads_explicit_nvfp4_silently(monkeypatch, enabled, caplog):+ target = _blackwell(monkeypatch)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.6.6")+ with caplog.at_level("WARNING"):+ assert (+ tq.select_transformer_quant_scheme(+ target, "nvfp4", family = "z-image", base_repo = _ZIMAGE, has_prequant = _hosted+ )+ == "nvfp4"+ )+ assert _engage(monkeypatch)("z-image", _ZIMAGE) == 4+ assert not _gate_warnings(caplog)++[email protected]("backend", ["torchao", "raises"])+def test_an_explicit_nvfp4_pick_on_torchao_never_warns_about_flashinfer(+ monkeypatch, enabled, caplog, backend+):+ """UNSLOTH_NVFP4_BACKEND=torchao or a failed flashinfer preflight runs torchao kernels: the flashinfer coverage+ warning would name kernels this load does not use."""+ import core.inference.diffusion_nvfp4_ops as ops++ target = _blackwell(monkeypatch)++ def _select(device = None):+ if backend == "raises":+ raise RuntimeError("preflight blew up")+ return backend++ monkeypatch.setattr(ops, "select_nvfp4_backend", _select)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ with caplog.at_level("WARNING"):+ assert (+ tq.select_transformer_quant_scheme(+ target, "nvfp4", family = "z-image", base_repo = _ZIMAGE, has_prequant = _hosted+ )+ == "nvfp4"+ )+ if backend == "torchao":+ assert _engage(monkeypatch, backend = "torchao")("z-image", _ZIMAGE) == 0+ assert not _gate_warnings(caplog)+++def test_a_load_that_moves_no_layer_onto_flashinfer_never_warns(monkeypatch, enabled, caplog):+ """A checkpoint without baked activation scales stays on torchao even when flashinfer is selected."""+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ with caplog.at_level("WARNING"):+ assert _engage(monkeypatch, layers = 0)("z-image", _ZIMAGE) == 0+ assert not _gate_warnings(caplog)+ assert gate._WARNED == set()+++def test_the_load_warning_keys_on_the_checkpoint_base_not_the_fetch_mirror(+ monkeypatch, enabled, caplog+):+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ with caplog.at_level("WARNING"):+ _engage(monkeypatch)(+ "z-image", "someone/z-image-mirror", metadata = {"base_model_id": _ZIMAGE}+ )+ assert len([m for m in _gate_warnings(caplog) if _ZIMAGE in m]) == 1+++def test_the_backend_probe_is_skipped_by_an_explicit_select(monkeypatch, enabled):+ import core.inference.diffusion_nvfp4_ops as ops++ target = _blackwell(monkeypatch)+ probed = []+ monkeypatch.setattr(+ ops, "select_nvfp4_backend", lambda device = None: probed.append(device) or "flashinfer"+ )+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ assert (+ tq.select_transformer_quant_scheme(+ target, "nvfp4", family = "z-image", base_repo = _ZIMAGE, has_prequant = _hosted+ )+ == "nvfp4"+ )+ assert probed == []+++def test_auto_rejects_an_unchecked_flashinfer_silently_and_the_explicit_load_still_warns(+ monkeypatch, enabled, caplog+):+ """Auto falls back to the ladder without the warning (it never runs those kernels), and does not use up the+ once-only warning a later explicit nvfp4 load on the same base owes the user."""+ target = _blackwell(monkeypatch)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: "0.7.0")+ with caplog.at_level("WARNING"):+ assert tq._nvfp4_gate_backend_ok("z-image", _ZIMAGE, "cuda:0") is False+ tq.select_transformer_quant_scheme(+ target, "auto", family = "z-image", base_repo = _ZIMAGE, has_prequant = _hosted+ )+ assert not _gate_warnings(caplog)+ engage = _engage(monkeypatch)+ with caplog.at_level("WARNING"):+ assert (+ tq.select_transformer_quant_scheme(+ target, "nvfp4", family = "z-image", base_repo = _ZIMAGE, has_prequant = _hosted+ )+ == "nvfp4"+ )+ engage("z-image", _ZIMAGE)+ assert len([m for m in _gate_warnings(caplog) if "flashinfer 0.7.0" in m]) == 1+++def test_an_unreadable_flashinfer_version_is_not_covered_when_flashinfer_runs(tmp_path):+ path = _gate_file(tmp_path, _zimage_record(flashinfer = "0.6.6"))+ message = gate.nvfp4_gate_flashinfer_mismatch(+ "z-image", _ZIMAGE, installed = "", path = path, backend_active = True+ )+ assert message and "could not be read" in message and "0.6.6" in message+ bare = _gate_file(tmp_path, _zimage_record())+ assert (+ gate.nvfp4_gate_flashinfer_mismatch(+ "z-image", _ZIMAGE, installed = "", path = bare, backend_active = True+ )+ is None+ )+++def test_auto_drops_the_gated_head_when_the_flashinfer_version_is_unreadable(+ monkeypatch, enabled, caplog+):+ _blackwell(monkeypatch)+ monkeypatch.setattr(gate, "_WARNED", set())+ monkeypatch.setattr(gate, "installed_flashinfer_version", lambda: None)+ with caplog.at_level("WARNING"):+ assert tq._nvfp4_gate_backend_ok("z-image", _ZIMAGE, "cuda:0") is False+ assert not _gate_warnings(caplog)+ with caplog.at_level("WARNING"):+ _engage(monkeypatch)("z-image", _ZIMAGE)+ assert len([m for m in _gate_warnings(caplog) if "could not be read" in m]) == 1+++def test_the_installed_version_falls_back_to_an_imported_module(monkeypatch):+ import importlib.metadata as md+ import sys++ def _missing(name):+ raise md.PackageNotFoundError(name)++ monkeypatch.setattr(md, "version", _missing)+ monkeypatch.setitem(sys.modules, "flashinfer", types.SimpleNamespace(__version__ = "0.6.6"))+ assert gate.installed_flashinfer_version() == "0.6.6"+ monkeypatch.setitem(sys.modules, "flashinfer", types.SimpleNamespace())+ assert gate.installed_flashinfer_version() is Nonediff --git a/studio/backend/tests/test_video_prequant.py b/studio/backend/tests/test_video_prequant.pyindex 6bef32a4ac5..2c86ec18f03 100644--- a/studio/backend/tests/test_video_prequant.py+++ b/studio/backend/tests/test_video_prequant.py@@ -1278,6 +1278,7 @@ def _a14b_auto(backend,fam = None,allowed = None,+ gated = False,):import types@@ -1295,6 +1296,10 @@ def _a14b_auto(monkeypatch.setattr(tq, "_scheme_supported", lambda scheme, device, **kw: scheme in allowed)monkeypatch.setattr(ops, "select_nvfp4_backend", lambda device = None: backend)monkeypatch.setattr(pq, "restricted_prequant_load_supported", lambda scheme = None: True)+ if gated:+ # What a measured, passing A14B gate record would read as (none ships).+ monkeypatch.setattr(tq, "_nvfp4_gate_passed", lambda family, base_repo: True)+ monkeypatch.setattr(tq, "_nvfp4_gate_backend_ok", lambda family, base_repo, device: True)fam = fam if fam is not None else detect_video_family("Wan-AI/Wan2.2-T2V-A14B-Diffusers")base = fam.base_reporeturn (@@ -1315,8 +1320,17 @@ def _a14b_auto()-def test_the_a14b_auto_plan_seeds_nvfp4_where_flashinfer_serves_the_device(monkeypatch):+def test_the_a14b_auto_plan_never_seeds_ungated_nvfp4(monkeypatch):+ """No accuracy-gate record covers the hosted A14B NVFP4 experts, so auto keeps the ladder even on flashinfer."""seeded, chosen = _a14b_auto(monkeypatch, backend = "flashinfer")+ assert chosen == "int8"+ assert seeded == "int8"+++def test_the_a14b_auto_plan_seeds_nvfp4_where_a_gate_record_and_flashinfer_serve_the_device(+ monkeypatch,+):+ seeded, chosen = _a14b_auto(monkeypatch, backend = "flashinfer", gated = True)assert seeded == "nvfp4"assert chosen == "nvfp4"diff --git a/studio/backend/tests/test_video_quantised_offload.py b/studio/backend/tests/test_video_quantised_offload.pyindex b61a6aa5608..e12b1e59f14 100644--- a/studio/backend/tests/test_video_quantised_offload.py+++ b/studio/backend/tests/test_video_quantised_offload.py@@ -267,9 +267,36 @@ def test_speed_off_keeps_bf16_under_offload(fake_runtime, monkeypatch):assert not spy.quant+def test_explicit_nvfp4_is_refused_on_the_wan_5b_that_failed_the_gate(fake_runtime, monkeypatch):+ """Wan2.2-TI2V-5B's hosted NVFP4 build measured above the accuracy-gate bar, so an explicit pick is refused."""+ monkeypatch.setenv("UNSLOTH_NVFP4_DIFFUSION", "1")+ spy = _spoof(monkeypatch, tier_gib = 32)+ with pytest.raises(RuntimeError, match = "measured deny list"):+ VideoBackend().load_pipeline(FAMILIES["wan2.2-ti2v-5b"], transformer_quant = "nvfp4")+ assert not spy.seeded+++def _lift_wan5b_nvfp4_deny(monkeypatch):+ """The placement tests below exercise a hosted NVFP4 seed, which only Wan2.2-5B's size class shows; lift its+ measured nvfp4 deny (both the selection table and the profile the hosted-scheme list filters on)."""+ import core.inference.diffusion_transformer_quant as tq+ from core.inference import video_families as vf++ deny = {k: v for k, v in tq._FAMILY_SCHEME_DENY.items() if k != "wan2.2-ti2v-5b"}+ monkeypatch.setattr(tq, "_FAMILY_SCHEME_DENY", deny)+ families = tuple(+ dataclasses.replace(fam, profile = dataclasses.replace(fam.profile, scheme_deny = frozenset()))+ if fam.name == "wan2.2-ti2v-5b"+ else fam+ for fam in vf._FAMILIES+ )+ monkeypatch.setattr(vf, "_FAMILIES", families)++def test_hosted_nvfp4_seeds_beside_streamed_text_encoder(fake_runtime, monkeypatch):"""Wan2.2-5B NVFP4 on 32 GiB: the split keeps the DiT resident and streams the 11.4 GB encoder."""monkeypatch.setenv("UNSLOTH_NVFP4_DIFFUSION", "1")+ _lift_wan5b_nvfp4_deny(monkeypatch)spy = _spoof(monkeypatch, tier_gib = 32)status = VideoBackend().load_pipeline(FAMILIES["wan2.2-ti2v-5b"], transformer_quant = "nvfp4")assert spy.seeded == ["nvfp4"]@@ -279,6 +306,7 @@ def test_hosted_nvfp4_seeds_beside_streamed_text_encoder(fake_runtime, monkeypatdef test_hosted_nvfp4_refused_where_the_dit_must_stream(fake_runtime, monkeypatch):monkeypatch.setenv("UNSLOTH_NVFP4_DIFFUSION", "1")+ _lift_wan5b_nvfp4_deny(monkeypatch)spy = _spoof(monkeypatch, tier_gib = 16)with pytest.raises(RuntimeError, match = "moves the DiT"):VideoBackend().load_pipeline(FAMILIES["wan2.2-ti2v-5b"], transformer_quant = "nvfp4")