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(minimax-h3): pin why the marker format is checked twice
Alexander Eichhorn7f3373894927
diff --git a/invokeai/backend/model_manager/load/model_loaders/minimax_h3.py b/invokeai/backend/model_manager/load/model_loaders/minimax_h3.pyindex 0c5cd3c7ae..ddd7b3eb77 100644--- a/invokeai/backend/model_manager/load/model_loaders/minimax_h3.py+++ b/invokeai/backend/model_manager/load/model_loaders/minimax_h3.py@@ -301,6 +301,14 @@ class MiniMaxH3CheckpointModel(ModelLoader):# is what applies the scale-layout check and reads each marker's own `convrot_groupsize`# instead of assuming 256 -- a 64-wide repack derotated with a 256-wide Hadamard runs and# generates noise.+ # Not redundant with `_reject_formats_declared_in_the_header`, though it looks it. The two+ # read the same blob by different routes: the header check decodes raw file bytes, while+ # `parse_comfy_quant_marker` goes through `tensor.numpy()`, which returns `{}` for a dtype+ # numpy has no equivalent for -- bfloat16 and the float8s; int8, float16 and float32 all+ # decode the same bytes fine. A marker stored as one of those therefore passes the gate and+ # arrives here empty -- and an empty marker is not refused downstream, it is *defaulted*:+ # `convrot` False and a 256-wide group, so a 64-wide repack is derotated with the wrong+ # Hadamard and renders noise. Measured at correlation 0.14 to the true weight.for module_name, marker in quant_markers.items():if marker.get("format") != INT8_TENSORWISE_FORMAT:raise ValueError(f"Unsupported comfy_quant format {marker!r} on {module_name}")@@ -423,6 +431,14 @@ class MiniMaxH3TextEncoderCheckpointModel(ModelLoader):# Shared helper, not a second copy: it applies the scale-layout check and reads each# marker's own `convrot_groupsize` rather than assuming 256.+ # Not redundant with `_reject_formats_declared_in_the_header`, though it looks it. The two+ # read the same blob by different routes: the header check decodes raw file bytes, while+ # `parse_comfy_quant_marker` goes through `tensor.numpy()`, which returns `{}` for a dtype+ # numpy has no equivalent for -- bfloat16 and the float8s; int8, float16 and float32 all+ # decode the same bytes fine. A marker stored as one of those therefore passes the gate and+ # arrives here empty -- and an empty marker is not refused downstream, it is *defaulted*:+ # `convrot` False and a 256-wide group, so a 64-wide repack is derotated with the wrong+ # Hadamard and renders noise. Measured at correlation 0.14 to the true weight.for module_name, marker in quant_markers.items():if marker.get("format") != INT8_TENSORWISE_FORMAT:raise ValueError(f"Unsupported comfy_quant format {marker!r} on {module_name}")diff --git a/tests/backend/model_manager/load/test_minimax_h3_int8_loading.py b/tests/backend/model_manager/load/test_minimax_h3_int8_loading.pyindex 02f2206540..03e407568d 100644--- a/tests/backend/model_manager/load/test_minimax_h3_int8_loading.py+++ b/tests/backend/model_manager/load/test_minimax_h3_int8_loading.py@@ -311,3 +311,45 @@ def test_an_int8_build_that_also_writes_the_header_still_loads(tmp_path) -> Nonemodel = _load(path)assert isinstance(_quantized_module(model), Int8ConvrotLinear)+++def test_a_per_tensor_marker_declaring_another_format_is_refused(tmp_path) -> None:+ """The header gate's other half. Every refusal cell above goes through `_quantization_metadata`+ or the float8 dtype check; nothing pinned the per-tensor route the gate was originally written+ for, so a change loosening it -- it already skips header entries without a `format` -- would+ reopen it unnoticed."""+ path, _ = _write_checkpoint(tmp_path, marker={"format": "float8_e4m3fn"})++ with pytest.raises(ValueError, match=r"float8_e4m3fn.*MiniMax H3 checkpoint"):+ _load(path)+++def test_a_marker_the_converter_cannot_parse_is_refused_rather_than_defaulted(tmp_path) -> None:+ """The two marker readers decode the same blob by different routes, and can disagree.++ `read_comfy_quant_markers` decodes raw file bytes; `parse_comfy_quant_marker` goes through+ `tensor.numpy()`, which returns `{}` for a dtype numpy has no equivalent for -- bfloat16 and the+ float8s, while int8, float16 and float32 decode the same bytes fine. A marker stored as one of+ those satisfies the header gate and reaches the swap empty -- and an empty marker is not refused+ there, it is *defaulted*: `convrot` off and a 256-wide group. A+ 64-wide repack derotated with a 256-wide Hadamard loads and renders noise, measured at+ correlation 0.14 to the true weight.++ ComfyUI writes uint8, so this is hardening rather than a live defect -- which is exactly why it+ needs a cell: the check reads as redundant with the header gate, and was briefly deleted as such.+ """+ torch.manual_seed(0)+ sd = _tiny_remote_code_state_dict()+ quantized, scale, _restored = quantize_convrot(sd[QUANTIZED_SOURCE_KEY], group_size=GROUP_SIZE)+ sd[QUANTIZED_SOURCE_KEY] = quantized+ sd["blocks.0.attn.out_proj.weight_scale"] = scale+ marker = comfy_quant_marker({"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": GROUP_SIZE}, pad=16)+ if marker.numel() % 2: # a byte view needs an even length to reinterpret as a 2-byte dtype+ marker = torch.cat([marker, torch.zeros(1, dtype=torch.uint8)])+ # Same bytes, a dtype `numpy()` refuses.+ sd["blocks.0.attn.out_proj.comfy_quant"] = marker.view(torch.bfloat16)+ path = tmp_path / "minimax_h3_int8_convrot_bf16_marker.safetensors"+ save_file(sd, str(path))++ with pytest.raises(ValueError, match="Unsupported comfy_quant format"):+ _load(path)