Skip to content

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.

test(loaders): make the nvfp4 seam cells match only the guard they mean

Alexander Eichhornee29ab73f8d8
diff --git a/tests/backend/model_manager/load/test_krea2_loader_boundaries.py b/tests/backend/model_manager/load/test_krea2_loader_boundaries.py
index 88c3b568a2..eb0b4516e1 100644
--- a/tests/backend/model_manager/load/test_krea2_loader_boundaries.py
+++ b/tests/backend/model_manager/load/test_krea2_loader_boundaries.py
@@ -867,15 +867,18 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
*native* keys, before the conversion that remaps the payload paths, so the refusal has to survive
being upstream of the rename as well as upstream of the reservation.
"""
- width = _TinyNativeKrea2.WIDTH
+ # A whole number of cuBLAS tiles -- 128 rows, 8 blocks of 16 -- rather than the tiny model's
+ # width, which would give an empty grid. The refusal reads only the key pairing and the uint8
+ # dtype, so it fires either way; a layer no nvfp4 build could contain is the wrong thing to
+ # assert against, and it would stop representing the state if that check is ever tightened.
state_dict = {
- **_native_block(width),
- "blocks.0.attn.wq.weight": torch.zeros(width, width // 2, dtype=torch.uint8),
- "blocks.0.attn.wq.weight_scale": torch.zeros(width, width // 16).to(torch.float8_e4m3fn),
+ **_native_block(_TinyNativeKrea2.WIDTH),
+ "blocks.0.attn.wq.weight": torch.zeros(128, 64, dtype=torch.uint8),
+ "blocks.0.attn.wq.weight_scale": torch.zeros(128, 8).to(torch.float8_e4m3fn),
}
run, config = _native_fp8_driver(monkeypatch, tmp_path, state_dict)
- with pytest.raises(ValueError, match="no weight_scale_2"):
+ with pytest.raises(ValueError, match="with a weight_scale but no weight_scale_2"):
run.load(config)
assert run.reserved == []
diff --git a/tests/backend/model_manager/load/test_ltx2_loader.py b/tests/backend/model_manager/load/test_ltx2_loader.py
index ed38d16adb..1a64448534 100644
--- a/tests/backend/model_manager/load/test_ltx2_loader.py
+++ b/tests/backend/model_manager/load/test_ltx2_loader.py
@@ -605,8 +605,8 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
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.
+ reaches the detector before it asks the cache for room. Here a key conversion stands between the
+ pop and the reservation, and nothing but their order keeps them that way round.
"""
sd = _tiny_transformer_checkpoint()
target = _official_name(f"{NVFP4_LAYER}.weight")[: -len(".weight")]
@@ -616,7 +616,7 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
_tiny_geometry(monkeypatch)
run = prepare(_transformer_seam(), monkeypatch)
- with pytest.raises(ValueError, match="no weight_scale_2"):
+ with pytest.raises(ValueError, match="with a weight_scale but 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.py
index 3657a25e80..e51492bde7 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
@@ -315,7 +315,7 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
save_file(tensors, checkpoint)
run = prepare(SEAM, monkeypatch, geometry=_fp8_matmul(keep_fp8))
- with pytest.raises(ValueError, match="no weight_scale_2"):
+ with pytest.raises(ValueError, match="with a weight_scale but no weight_scale_2"):
run.load(_config(checkpoint))
assert run.reserved == []
diff --git a/tests/backend/model_manager/load/test_qwen3_encoder_checkpoint_loader.py b/tests/backend/model_manager/load/test_qwen3_encoder_checkpoint_loader.py
index 94c091faf5..9982f04079 100644
--- a/tests/backend/model_manager/load/test_qwen3_encoder_checkpoint_loader.py
+++ b/tests/backend/model_manager/load/test_qwen3_encoder_checkpoint_loader.py
@@ -278,7 +278,7 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
loader._ram_cache = SimpleNamespace(make_room=MagicMock())
config = Qwen3Encoder_Checkpoint_Config.model_construct(path=str(checkpoint), variant=Qwen3VariantType.Qwen3_4B)
- with pytest.raises(ValueError, match="no weight_scale_2"):
+ with pytest.raises(ValueError, match="with a weight_scale but no weight_scale_2"):
loader._load_from_singlefile(config)
loader._ram_cache.make_room.assert_not_called()
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.py
index 192ced86c6..1f82b299a6 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
@@ -49,6 +49,19 @@ def _marker(fmt: str) -> torch.Tensor:
return comfy_quant_marker({"format": fmt})
+#: Both single-file encoder cells drive the same entry, so the driver is declared once.
+ENCODER_SEAM = Seam(
+ loader=QwenVLEncoderCheckpointLoader,
+ module=qwen_image,
+ entry="_load_text_encoder_from_singlefile",
+ # The loader imports `load_file` inside the method, so the name it resolves is the package's.
+ load_file_host=safetensors.torch,
+ patches_device=True,
+ sets_torch_dtype=False,
+ casts_fp8_storage=False,
+)
+
+
def _patch_common(monkeypatch: pytest.MonkeyPatch, state_dict: dict, metadata: dict) -> list[bool]:
"""Patch file access and devices; return a log for `_record_fold`."""
import safetensors.torch
@@ -292,17 +305,7 @@ def test_an_int8_convrot_checkpoint_is_refused_before_the_cache_is_evicted(monke
}
checkpoint = tmp_path / "qwen_2.5_vl_7b_int8_convrot.safetensors"
checkpoint.touch()
- seam = Seam(
- loader=QwenVLEncoderCheckpointLoader,
- module=qwen_image,
- entry="_load_text_encoder_from_singlefile",
- # The loader imports `load_file` inside the method, so the name it resolves is the package's.
- 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)
+ run = prepare(ENCODER_SEAM, monkeypatch, state_dict=state_dict, metadata=None)
with pytest.raises(ValueError, match="quantized with convrot"):
run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))
@@ -316,8 +319,8 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
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.
+ still reaches the detector *before* it asks the cache for room, which nothing but the order of
+ those two statements secures.
"""
state_dict = {
"model.layers.0.self_attn.q_proj.weight": torch.zeros(64, 128, dtype=torch.uint8),
@@ -325,18 +328,9 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
}
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)
+ run = prepare(ENCODER_SEAM, monkeypatch, state_dict=state_dict, metadata=None)
- with pytest.raises(ValueError, match="no weight_scale_2"):
+ with pytest.raises(ValueError, match="with a weight_scale but no weight_scale_2"):
run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))
assert run.reserved == []
@@ -347,8 +341,8 @@ def test_the_transformer_refuses_an_nvfp4_layer_missing_its_global_scale_before_
) -> None:
"""The same degraded half-state at the transformer seam, which had no `Seam` of its own.
- The encoder cell above covers the other Qwen-Image seam; this one is the transformer, where the
- pop sits 25 lines above the reservation. Declared through the shared driver rather than the
+ The encoder cell above covers the other Qwen-Image seam; this one is the transformer. Declared
+ through the shared driver rather than the
hand-rolled loader the cells above use, because `run.reserved` is the assertion -- the recorded
reservations are what say "before", and a `MagicMock` would only say "not called at all".
"""
@@ -357,6 +351,7 @@ def test_the_transformer_refuses_an_nvfp4_layer_missing_its_global_scale_before_
state_dict = {
"img_in.weight": torch.randn(128, 64),
"img_in.bias": torch.randn(128),
+ # 128 rows and 4 blocks: a whole number of cuBLAS tiles, i.e. a layer a real build could hold.
"transformer_blocks.0.attn.to_q.weight": torch.zeros(128, 32, dtype=torch.uint8),
"transformer_blocks.0.attn.to_q.weight_scale": torch.zeros(128, 4).to(torch.float8_e4m3fn),
}
@@ -369,6 +364,10 @@ def test_the_transformer_refuses_an_nvfp4_layer_missing_its_global_scale_before_
load_file_host=safetensors.torch,
compute_dtype=COMPUTE_DTYPE,
patches_device=True,
+ # This entry reads neither: `_torch_dtype` is read nowhere in `qwen_image`, and the fp8
+ # storage cast is called from `_load_model`. Stubbing them would hide one that started.
+ sets_torch_dtype=False,
+ casts_fp8_storage=False,
)
run = prepare(
seam,
@@ -380,7 +379,7 @@ def test_the_transformer_refuses_an_nvfp4_layer_missing_its_global_scale_before_
),
)
- with pytest.raises(ValueError, match="no weight_scale_2"):
+ with pytest.raises(ValueError, match="with a weight_scale but no weight_scale_2"):
run.load(Main_Checkpoint_QwenImage_Config.model_construct(path=str(checkpoint), name="qwen_image_nvfp4_half"))
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.py
index 654b22c2da..b5122dfadb 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
@@ -418,8 +418,8 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
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.
+ reaches the detector before it asks the cache for room, which nothing but the order of those two
+ statements secures.
"""
state_dict = {
"x_embedder.weight": torch.randn(4, 4),
@@ -428,7 +428,7 @@ def test_an_nvfp4_layer_missing_its_global_scale_is_refused_before_the_cache_is_
}
run, config = _driver(monkeypatch, tmp_path, state_dict)
- with pytest.raises(ValueError, match="no weight_scale_2"):
+ with pytest.raises(ValueError, match="with a weight_scale but no weight_scale_2"):
run.load(config)
assert run.reserved == []