Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
test(loaders): refuse a degraded nvfp4 payload before the reservation, at four seams
Alexander Eichhorn83cb15ecee3e
diff --git a/tests/backend/model_manager/load/test_ltx2_loader.py b/tests/backend/model_manager/load/test_ltx2_loader.pyindex 2ad939ebf0..ed38d16adb 100644--- a/tests/backend/model_manager/load/test_ltx2_loader.py+++ b/tests/backend/model_manager/load/test_ltx2_loader.py@@ -595,3 +595,28 @@ def test_the_encoder_sizes_its_weight_file_one_directory_down(tmp_path) -> None:loader = object.__new__(LTX2Gemma4EncoderModel)assert loader.get_size_fs(config, tmp_path, SubModelType.TextEncoder) == 5000assert loader.get_size_fs(config, tmp_path, SubModelType.Tokenizer) == 40+++def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_evicted(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ """The degraded half-state, at this seam rather than at the detector.++ A packed uint8 weight with a block-scale grid and no `weight_scale_2` is what a guard keyed on+ `weight_scale_2` -- the key the decode keys on -- lets straight through. `_find_nvfp4_layers`+ refuses it and `test_nvfp4.py` pins that; what only a seam can answer is whether this loader+ reaches the detector before it asks the cache for room, and this seam has the longest run between+ the two -- `pop_nvfp4_layers` to the reservation is 24 lines and a key conversion.+ """+ sd = _tiny_transformer_checkpoint()+ target = _official_name(f"{NVFP4_LAYER}.weight")[: -len(".weight")]+ rows, packed = sd[f"{target}.weight"].shape[0], sd[f"{target}.weight"].shape[1] // 2+ sd[f"{target}.weight"] = torch.zeros(rows, packed, dtype=torch.uint8)+ sd[f"{target}.weight_scale"] = torch.zeros(rows, packed // 8).to(torch.float8_e4m3fn)+ _tiny_geometry(monkeypatch)+ run = prepare(_transformer_seam(), monkeypatch)++ with pytest.raises(ValueError, match="no weight_scale_2"):+ run.load(_checkpoint_config(tmp_path, sd))++ assert run.reserved == []diff --git a/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.py b/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.pyindex b38f65e8ea..3657a25e80 100644--- a/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.py+++ b/tests/backend/model_manager/load/test_mistral_encoder_checkpoint_loader.py@@ -293,3 +293,29 @@ def test_the_config_reads_layer_and_head_counts_through_packed_projections() ->assert (config.num_hidden_layers, config.num_attention_heads, config.num_key_value_heads) == (40, 40, 16)assert config.intermediate_size == 16384++[email protected]("keep_fp8", [False, True], ids=["fp8_dequantized", "fp8_kept"])+def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_evicted(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path, keep_fp8: bool+) -> None:+ """The degraded half-state, at this seam rather than at the detector.++ A packed uint8 weight with a block-scale grid and no `weight_scale_2` is what a guard keyed on+ `weight_scale_2` -- the key the decode itself keys on -- lets straight through. `_find_nvfp4_layers`+ refuses it and `test_nvfp4.py` pins that; what only a seam can answer is whether this loader still+ reaches the detector before it asks the cache for room, and on both fp8 branches. Nothing but the+ order of two statements keeps `pop_nvfp4_layers` above the reservation here.+ """+ checkpoint, _, _ = _write_checkpoint(tmp_path, evidence="none")+ tensors = load_file(checkpoint)+ target = f"model.layers.0.{FP8_PROJECTION}"+ tensors[f"{target}.weight"] = torch.zeros(KV_ROWS, HIDDEN // 2, dtype=torch.uint8)+ tensors[f"{target}.weight_scale"] = torch.zeros(KV_ROWS, HIDDEN // 16).to(torch.float8_e4m3fn)+ save_file(tensors, checkpoint)+ run = prepare(SEAM, monkeypatch, geometry=_fp8_matmul(keep_fp8))++ with pytest.raises(ValueError, match="no weight_scale_2"):+ run.load(_config(checkpoint))++ assert run.reserved == []diff --git a/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.py b/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.pyindex 1a33a64bf5..33209b5364 100644--- a/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.py+++ b/tests/backend/model_manager/load/test_qwen_image_nvfp4_loader.py@@ -308,3 +308,35 @@ def test_an_int8_convrot_checkpoint_is_refused_before_the_cache_is_evicted(monkerun.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))assert run.reserved == []+++def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_evicted(monkeypatch, tmp_path) -> None:+ """The degraded half-state, at the seam rather than at the detector.++ A packed uint8 weight with a block-scale grid and no `weight_scale_2` is the shape a guard keyed+ on `weight_scale_2` -- what the decode keys on -- lets straight through. `_find_nvfp4_layers`+ refuses it, and `test_nvfp4.py` pins that; what only a seam can answer is whether this loader+ still reaches the detector *before* it asks the cache for room. The pop happens 26 lines above+ the reservation today, and nothing but call order keeps it there.+ """+ state_dict = {+ "model.layers.0.self_attn.q_proj.weight": torch.zeros(64, 128, dtype=torch.uint8),+ "model.layers.0.self_attn.q_proj.weight_scale": torch.zeros(64, 16).to(torch.float8_e4m3fn),+ }+ checkpoint = tmp_path / "qwen_2.5_vl_7b_nvfp4_half.safetensors"+ checkpoint.touch()+ seam = Seam(+ loader=QwenVLEncoderCheckpointLoader,+ module=qwen_image,+ entry="_load_text_encoder_from_singlefile",+ load_file_host=safetensors.torch,+ patches_device=True,+ sets_torch_dtype=False,+ casts_fp8_storage=False,+ )+ run = prepare(seam, monkeypatch, state_dict=state_dict, metadata=None)++ with pytest.raises(ValueError, match="no weight_scale_2"):+ run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))++ assert run.reserved == []diff --git a/tests/backend/model_manager/load/test_z_image_loader_boundaries.py b/tests/backend/model_manager/load/test_z_image_loader_boundaries.pyindex 2548d04e6c..654b22c2da 100644--- a/tests/backend/model_manager/load/test_z_image_loader_boundaries.py+++ b/tests/backend/model_manager/load/test_z_image_loader_boundaries.py@@ -410,3 +410,25 @@ def test_a_comfyui_prefixed_checkpoint_loads_the_same_as_a_bare_one(monkeypatch,assert set(from_prefixed) == set(from_bare)for key, value in from_bare.items():assert torch.equal(from_prefixed[key], value), key+++def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_evicted(monkeypatch, tmp_path) -> None:+ """The degraded half-state, at this seam rather than at the detector.++ A packed uint8 weight with a block-scale grid and no `weight_scale_2` is the shape a guard keyed+ on `weight_scale_2` -- the key the decode keys on -- lets straight through. `_find_nvfp4_layers`+ refuses it and `test_nvfp4.py` pins that; what only a seam can answer is whether this loader+ reaches the detector before it asks the cache for room. Here `pop_nvfp4_layers` sits 68 lines+ above the reservation, and nothing but that order keeps it there.+ """+ state_dict = {+ "x_embedder.weight": torch.randn(4, 4),+ "layers.0.attention.qkv.weight": torch.zeros(384, 32, dtype=torch.uint8),+ "layers.0.attention.qkv.weight_scale": torch.zeros(384, 4).to(torch.float8_e4m3fn),+ }+ run, config = _driver(monkeypatch, tmp_path, state_dict)++ with pytest.raises(ValueError, match="no weight_scale_2"):+ run.load(config)++ assert run.reserved == []