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): record the krea2, mistral and wan key layouts
Alexander Eichhorn81299d8604ae
diff --git a/tests/backend/model_manager/load/state_dicts/krea2_turbo_int8_convrot_keys.py b/tests/backend/model_manager/load/state_dicts/krea2_turbo_int8_convrot_keys.pynew file mode 100644index 0000000000..04cd298cf6--- /dev/null+++ b/tests/backend/model_manager/load/state_dicts/krea2_turbo_int8_convrot_keys.py@@ -0,0 +1,132 @@+"""Representative key layout of Comfy-Org's `int8_tensorwise` Krea-2 Turbo build.++Captured on 2026-09-26 with `scripts/capture_state_dict_fixture.py`,+which reads the header only, from+`Comfy-Org/Krea-2/diffusion_models/krea2_turbo_int8_convrot.safetensors`.++Subsetting rule: `blocks` index 0, plus every key outside a stack. Values are `(shape, dtype)`.++These are the native Krea-2 names -- `blocks.0.attn.wq`, not the diffusers+`transformer_blocks.0.attn.to_q` the model is built with -- so this layout only reaches the module+tree through `_convert_krea2_native_to_diffusers`. That is what makes it worth capturing: the side+channel has to survive a rename, and two of these keys are exactly the ones a probe gets wrong.+`blocks.0.mod.lin` is a modulation table whose parameter is not called `weight`, and `txtmlp.0.scale`+is a norm that stores its parameter as `scale`; assuming `<module>.weight` for either costs the layer+its scale, with one INFO line to say so.++The build declares its scheme **only per tensor**: no `__metadata__` block at all, and a+`.comfy_quant` beside every quantized weight. `convrot` and its group size live in that marker and+can live nowhere else -- a header entry cannot carry them -- so a re-upload that dropped `convrot`+would load cleanly against a 256-wide Hadamard and generate noise. That is the one failure this+fixture exists to make loud.+"""++state_dict_keys: dict[str, tuple[list[int], str]] = {+ "blocks.0.attn.gate.comfy_quant": ([72], "U8"),+ "blocks.0.attn.gate.weight": ([6144, 6144], "I8"),+ "blocks.0.attn.gate.weight_scale": ([6144, 1], "F32"),+ "blocks.0.attn.qknorm.knorm.scale": ([128], "F32"),+ "blocks.0.attn.qknorm.qnorm.scale": ([128], "F32"),+ "blocks.0.attn.wk.comfy_quant": ([72], "U8"),+ "blocks.0.attn.wk.weight": ([1536, 6144], "I8"),+ "blocks.0.attn.wk.weight_scale": ([1536, 1], "F32"),+ "blocks.0.attn.wo.comfy_quant": ([72], "U8"),+ "blocks.0.attn.wo.weight": ([6144, 6144], "I8"),+ "blocks.0.attn.wo.weight_scale": ([6144, 1], "F32"),+ "blocks.0.attn.wq.comfy_quant": ([72], "U8"),+ "blocks.0.attn.wq.weight": ([6144, 6144], "I8"),+ "blocks.0.attn.wq.weight_scale": ([6144, 1], "F32"),+ "blocks.0.attn.wv.comfy_quant": ([72], "U8"),+ "blocks.0.attn.wv.weight": ([1536, 6144], "I8"),+ "blocks.0.attn.wv.weight_scale": ([1536, 1], "F32"),+ "blocks.0.mlp.down.comfy_quant": ([72], "U8"),+ "blocks.0.mlp.down.weight": ([6144, 16384], "I8"),+ "blocks.0.mlp.down.weight_scale": ([6144, 1], "F32"),+ "blocks.0.mlp.gate.comfy_quant": ([72], "U8"),+ "blocks.0.mlp.gate.weight": ([16384, 6144], "I8"),+ "blocks.0.mlp.gate.weight_scale": ([16384, 1], "F32"),+ "blocks.0.mlp.up.comfy_quant": ([72], "U8"),+ "blocks.0.mlp.up.weight": ([16384, 6144], "I8"),+ "blocks.0.mlp.up.weight_scale": ([16384, 1], "F32"),+ "blocks.0.mod.lin": ([36864], "BF16"),+ "blocks.0.postnorm.scale": ([6144], "F32"),+ "blocks.0.prenorm.scale": ([6144], "F32"),+ "first.bias": ([6144], "BF16"),+ "first.weight": ([6144, 64], "BF16"),+ "last.linear.bias": ([64], "BF16"),+ "last.linear.weight": ([64, 6144], "BF16"),+ "last.modulation.lin": ([2, 6144], "BF16"),+ "last.norm.scale": ([6144], "F32"),+ "tmlp.0.bias": ([6144], "BF16"),+ "tmlp.0.weight": ([6144, 256], "BF16"),+ "tmlp.2.bias": ([6144], "BF16"),+ "tmlp.2.weight": ([6144, 6144], "BF16"),+ "tproj.1.bias": ([36864], "BF16"),+ "tproj.1.weight": ([36864, 6144], "BF16"),+ "txtfusion.layerwise_blocks.0.attn.gate.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.0.attn.qknorm.knorm.scale": ([128], "F32"),+ "txtfusion.layerwise_blocks.0.attn.qknorm.qnorm.scale": ([128], "F32"),+ "txtfusion.layerwise_blocks.0.attn.wk.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.0.attn.wo.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.0.attn.wq.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.0.attn.wv.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.0.mlp.down.weight": ([2560, 6912], "BF16"),+ "txtfusion.layerwise_blocks.0.mlp.gate.weight": ([6912, 2560], "BF16"),+ "txtfusion.layerwise_blocks.0.mlp.up.weight": ([6912, 2560], "BF16"),+ "txtfusion.layerwise_blocks.0.postnorm.scale": ([2560], "F32"),+ "txtfusion.layerwise_blocks.0.prenorm.scale": ([2560], "F32"),+ "txtfusion.layerwise_blocks.1.attn.gate.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.1.attn.qknorm.knorm.scale": ([128], "F32"),+ "txtfusion.layerwise_blocks.1.attn.qknorm.qnorm.scale": ([128], "F32"),+ "txtfusion.layerwise_blocks.1.attn.wk.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.1.attn.wo.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.1.attn.wq.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.1.attn.wv.weight": ([2560, 2560], "BF16"),+ "txtfusion.layerwise_blocks.1.mlp.down.weight": ([2560, 6912], "BF16"),+ "txtfusion.layerwise_blocks.1.mlp.gate.weight": ([6912, 2560], "BF16"),+ "txtfusion.layerwise_blocks.1.mlp.up.weight": ([6912, 2560], "BF16"),+ "txtfusion.layerwise_blocks.1.postnorm.scale": ([2560], "F32"),+ "txtfusion.layerwise_blocks.1.prenorm.scale": ([2560], "F32"),+ "txtfusion.projector.weight": ([1, 12], "BF16"),+ "txtfusion.refiner_blocks.0.attn.gate.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.0.attn.qknorm.knorm.scale": ([128], "F32"),+ "txtfusion.refiner_blocks.0.attn.qknorm.qnorm.scale": ([128], "F32"),+ "txtfusion.refiner_blocks.0.attn.wk.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.0.attn.wo.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.0.attn.wq.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.0.attn.wv.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.0.mlp.down.weight": ([2560, 6912], "BF16"),+ "txtfusion.refiner_blocks.0.mlp.gate.weight": ([6912, 2560], "BF16"),+ "txtfusion.refiner_blocks.0.mlp.up.weight": ([6912, 2560], "BF16"),+ "txtfusion.refiner_blocks.0.postnorm.scale": ([2560], "F32"),+ "txtfusion.refiner_blocks.0.prenorm.scale": ([2560], "F32"),+ "txtfusion.refiner_blocks.1.attn.gate.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.1.attn.qknorm.knorm.scale": ([128], "F32"),+ "txtfusion.refiner_blocks.1.attn.qknorm.qnorm.scale": ([128], "F32"),+ "txtfusion.refiner_blocks.1.attn.wk.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.1.attn.wo.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.1.attn.wq.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.1.attn.wv.weight": ([2560, 2560], "BF16"),+ "txtfusion.refiner_blocks.1.mlp.down.weight": ([2560, 6912], "BF16"),+ "txtfusion.refiner_blocks.1.mlp.gate.weight": ([6912, 2560], "BF16"),+ "txtfusion.refiner_blocks.1.mlp.up.weight": ([6912, 2560], "BF16"),+ "txtfusion.refiner_blocks.1.postnorm.scale": ([2560], "F32"),+ "txtfusion.refiner_blocks.1.prenorm.scale": ([2560], "F32"),+ "txtmlp.0.scale": ([2560], "F32"),+ "txtmlp.1.bias": ([6144], "BF16"),+ "txtmlp.1.weight": ([6144, 2560], "BF16"),+ "txtmlp.3.bias": ([6144], "BF16"),+ "txtmlp.3.weight": ([6144, 6144], "BF16"),+}++# The per-layer `.comfy_quant` markers, decoded from the blobs themselves.+markers: dict[str, dict[str, object]] = {+ "blocks.0.attn.gate": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+ "blocks.0.attn.wk": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+ "blocks.0.attn.wo": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+ "blocks.0.attn.wq": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+ "blocks.0.attn.wv": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+ "blocks.0.mlp.down": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+ "blocks.0.mlp.gate": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+ "blocks.0.mlp.up": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},+}diff --git a/tests/backend/model_manager/load/state_dicts/mistral_3_small_scaled_fp8_keys.py b/tests/backend/model_manager/load/state_dicts/mistral_3_small_scaled_fp8_keys.pynew file mode 100644index 0000000000..390f2e108b--- /dev/null+++ b/tests/backend/model_manager/load/state_dicts/mistral_3_small_scaled_fp8_keys.py@@ -0,0 +1,61 @@+"""Representative key layout of the scaled-fp8 Mistral-3-Small encoder FLUX.2 ships.++Captured on 2026-09-26 with `scripts/capture_state_dict_fixture.py`,+which reads the header only, from+`Comfy-Org/flux2-dev/split_files/text_encoders/mistral_3_small_flux2_fp8.safetensors`.++Subsetting rule: `model.layers` index 0, plus every key outside a stack. Values are `(shape, dtype)`.++Two things make this the encoder cell rather than a second transformer one.++It arrives already normalised: no `text_encoder.`/`language_model.` wrapper, so every key is the+plain `model.*` form that `_strip_known_prefixes` exists to produce, and `model.` itself comes off+later in `_convert_for_bare_mistral_model` because bare `MistralModel` has no LM head and no `model.`+level. The header names its layers in that same namespace, which is the agreement the hint re-key+depends on -- `MISTRAL_KEY_PREFIXES` is a named constant precisely because the header is written+*before* the strip, so a second copy of the list could drift out of step with it.++And it is the one captured layout that ships the tokenizer: `tekken_model`, 19 MB of it, as a uint8+tensor sitting beside the weights, next to a zero-element `scaled_fp8` marker that names no layer.+Both have to be told apart from a scale key -- one is metadata to strip, the other is the tokenizer.+"""++state_dict_keys: dict[str, tuple[list[int], str]] = {+ "model.embed_tokens.weight": ([131072, 5120], "BF16"),+ "model.layers.0.input_layernorm.weight": ([5120], "BF16"),+ "model.layers.0.mlp.down_proj.input_scale": ([], "F32"),+ "model.layers.0.mlp.down_proj.weight": ([5120, 32768], "F8_E4M3"),+ "model.layers.0.mlp.down_proj.weight_scale": ([], "F32"),+ "model.layers.0.mlp.gate_proj.input_scale": ([], "F32"),+ "model.layers.0.mlp.gate_proj.weight": ([32768, 5120], "F8_E4M3"),+ "model.layers.0.mlp.gate_proj.weight_scale": ([], "F32"),+ "model.layers.0.mlp.up_proj.input_scale": ([], "F32"),+ "model.layers.0.mlp.up_proj.weight": ([32768, 5120], "F8_E4M3"),+ "model.layers.0.mlp.up_proj.weight_scale": ([], "F32"),+ "model.layers.0.post_attention_layernorm.weight": ([5120], "BF16"),+ "model.layers.0.self_attn.k_proj.input_scale": ([], "F32"),+ "model.layers.0.self_attn.k_proj.weight": ([1024, 5120], "F8_E4M3"),+ "model.layers.0.self_attn.k_proj.weight_scale": ([], "F32"),+ "model.layers.0.self_attn.o_proj.input_scale": ([], "F32"),+ "model.layers.0.self_attn.o_proj.weight": ([5120, 4096], "F8_E4M3"),+ "model.layers.0.self_attn.o_proj.weight_scale": ([], "F32"),+ "model.layers.0.self_attn.q_proj.input_scale": ([], "F32"),+ "model.layers.0.self_attn.q_proj.weight": ([4096, 5120], "F8_E4M3"),+ "model.layers.0.self_attn.q_proj.weight_scale": ([], "F32"),+ "model.layers.0.self_attn.v_proj.input_scale": ([], "F32"),+ "model.layers.0.self_attn.v_proj.weight": ([1024, 5120], "F8_E4M3"),+ "model.layers.0.self_attn.v_proj.weight_scale": ([], "F32"),+ "scaled_fp8": ([0], "F8_E4M3"),+ "tekken_model": ([19399895], "U8"),+}++# The `_quantization_metadata` header block, layer names exactly as the producer wrote them.+layer_hints: dict[str, dict[str, object]] = {+ "model.layers.0.mlp.down_proj": {"format": "float8_e4m3fn"},+ "model.layers.0.mlp.gate_proj": {"format": "float8_e4m3fn"},+ "model.layers.0.mlp.up_proj": {"format": "float8_e4m3fn"},+ "model.layers.0.self_attn.k_proj": {"format": "float8_e4m3fn"},+ "model.layers.0.self_attn.o_proj": {"format": "float8_e4m3fn"},+ "model.layers.0.self_attn.q_proj": {"format": "float8_e4m3fn"},+ "model.layers.0.self_attn.v_proj": {"format": "float8_e4m3fn"},+}diff --git a/tests/backend/model_manager/load/state_dicts/wan22_t2v_14b_scaled_fp8_keys.py b/tests/backend/model_manager/load/state_dicts/wan22_t2v_14b_scaled_fp8_keys.pynew file mode 100644index 0000000000..473649166e--- /dev/null+++ b/tests/backend/model_manager/load/state_dicts/wan22_t2v_14b_scaled_fp8_keys.py@@ -0,0 +1,109 @@+"""Representative key layout of Comfy-Org's repackaged scaled-fp8 Wan 2.2.++Captured on 2026-09-26 with `scripts/capture_state_dict_fixture.py`,+which reads the header only, from+`Comfy-Org/Wan_2.2_ComfyUI_Repackaged/split_files/diffusion_models/wan2.2_t2v_low_noise_14B_fp8_scaled.safetensors`.++Subsetting rule: `blocks` index 0, plus every key outside a stack. Values are `(shape, dtype)`.++Captured over an HTTP range read. The file is ~14 GB and no Wan fp8 build is on this machine, which+is the case the capture tool exists for.++**What makes it worth capturing is the native key names.** Three Wan probes read them --+`_is_native_wan_layout` decides whether the diffusers conversion runs, `_detect_wan_variant_from_state_dict`+reads `patch_embedding.weight`'s channel count and width to pick T2V-A14B over I2V-A14B over TI2V-5B,+and `_has_wan_transformer_block_weights` separates a main model from an I2V LoRA that ships its own+`patch_embedding`. Until this capture all three were exercised only against a synthetic dict written+from the same understanding as the probes themselves.++It also declares itself through **neither** hint transport: no `_quantization_metadata` header block+and no `.comfy_quant` markers, only the bare `scaled_fp8` marker tensor and the sibling scale keys.+`WanCheckpointModel` therefore enters the fold structurally, on the key names alone. (Neither+transport is the common case among these fixtures, not a peculiarity of this one.)++The scales are spelled `.scale_weight`/`.scale_input` rather than `.weight_scale`/`.input_scale`.+That is *not* new here -- `flux1_transformer_scaled_fp8_keys.py` records the same spelling and+`test_flux1_scaled_fp8_keys.py` already drives a reader over it -- so no cell in this file claims it.++Every scale is per-tensor (0-d), so this layout does *not* exercise the per-output-channel axis that+`expand_weight_scale` gets right and the copy it replaced got wrong -- the FLUX.1 int8 fixture beside+this one is where that lives.+"""++state_dict_keys: dict[str, tuple[list[int], str]] = {+ "blocks.0.cross_attn.k.bias": ([5120], "F16"),+ "blocks.0.cross_attn.k.scale_input": ([], "F32"),+ "blocks.0.cross_attn.k.scale_weight": ([], "F32"),+ "blocks.0.cross_attn.k.weight": ([5120, 5120], "F8_E4M3"),+ "blocks.0.cross_attn.norm_k.weight": ([5120], "F16"),+ "blocks.0.cross_attn.norm_q.weight": ([5120], "F16"),+ "blocks.0.cross_attn.o.bias": ([5120], "F16"),+ "blocks.0.cross_attn.o.scale_input": ([], "F32"),+ "blocks.0.cross_attn.o.scale_weight": ([], "F32"),+ "blocks.0.cross_attn.o.weight": ([5120, 5120], "F8_E4M3"),+ "blocks.0.cross_attn.q.bias": ([5120], "F16"),+ "blocks.0.cross_attn.q.scale_input": ([], "F32"),+ "blocks.0.cross_attn.q.scale_weight": ([], "F32"),+ "blocks.0.cross_attn.q.weight": ([5120, 5120], "F8_E4M3"),+ "blocks.0.cross_attn.v.bias": ([5120], "F16"),+ "blocks.0.cross_attn.v.scale_input": ([], "F32"),+ "blocks.0.cross_attn.v.scale_weight": ([], "F32"),+ "blocks.0.cross_attn.v.weight": ([5120, 5120], "F8_E4M3"),+ "blocks.0.ffn.0.bias": ([13824], "F16"),+ "blocks.0.ffn.0.scale_input": ([], "F32"),+ "blocks.0.ffn.0.scale_weight": ([], "F32"),+ "blocks.0.ffn.0.weight": ([13824, 5120], "F8_E4M3"),+ "blocks.0.ffn.2.bias": ([5120], "F16"),+ "blocks.0.ffn.2.scale_input": ([], "F32"),+ "blocks.0.ffn.2.scale_weight": ([], "F32"),+ "blocks.0.ffn.2.weight": ([5120, 13824], "F8_E4M3"),+ "blocks.0.modulation": ([1, 6, 5120], "F16"),+ "blocks.0.norm3.bias": ([5120], "F16"),+ "blocks.0.norm3.weight": ([5120], "F16"),+ "blocks.0.self_attn.k.bias": ([5120], "F16"),+ "blocks.0.self_attn.k.scale_input": ([], "F32"),+ "blocks.0.self_attn.k.scale_weight": ([], "F32"),+ "blocks.0.self_attn.k.weight": ([5120, 5120], "F8_E4M3"),+ "blocks.0.self_attn.norm_k.weight": ([5120], "F16"),+ "blocks.0.self_attn.norm_q.weight": ([5120], "F16"),+ "blocks.0.self_attn.o.bias": ([5120], "F16"),+ "blocks.0.self_attn.o.scale_input": ([], "F32"),+ "blocks.0.self_attn.o.scale_weight": ([], "F32"),+ "blocks.0.self_attn.o.weight": ([5120, 5120], "F8_E4M3"),+ "blocks.0.self_attn.q.bias": ([5120], "F16"),+ "blocks.0.self_attn.q.scale_input": ([], "F32"),+ "blocks.0.self_attn.q.scale_weight": ([], "F32"),+ "blocks.0.self_attn.q.weight": ([5120, 5120], "F8_E4M3"),+ "blocks.0.self_attn.v.bias": ([5120], "F16"),+ "blocks.0.self_attn.v.scale_input": ([], "F32"),+ "blocks.0.self_attn.v.scale_weight": ([], "F32"),+ "blocks.0.self_attn.v.weight": ([5120, 5120], "F8_E4M3"),+ "head.head.bias": ([64], "F16"),+ "head.head.scale_input": ([], "F32"),+ "head.head.scale_weight": ([], "F32"),+ "head.head.weight": ([64, 5120], "F8_E4M3"),+ "head.modulation": ([1, 2, 5120], "F16"),+ "patch_embedding.bias": ([5120], "F16"),+ "patch_embedding.weight": ([5120, 16, 1, 2, 2], "F16"),+ "scaled_fp8": ([0], "F8_E4M3"),+ "text_embedding.0.bias": ([5120], "F16"),+ "text_embedding.0.scale_input": ([], "F32"),+ "text_embedding.0.scale_weight": ([], "F32"),+ "text_embedding.0.weight": ([5120, 4096], "F8_E4M3"),+ "text_embedding.2.bias": ([5120], "F16"),+ "text_embedding.2.scale_input": ([], "F32"),+ "text_embedding.2.scale_weight": ([], "F32"),+ "text_embedding.2.weight": ([5120, 5120], "F8_E4M3"),+ "time_embedding.0.bias": ([5120], "F16"),+ "time_embedding.0.scale_input": ([], "F32"),+ "time_embedding.0.scale_weight": ([], "F32"),+ "time_embedding.0.weight": ([5120, 256], "F8_E4M3"),+ "time_embedding.2.bias": ([5120], "F16"),+ "time_embedding.2.scale_input": ([], "F32"),+ "time_embedding.2.scale_weight": ([], "F32"),+ "time_embedding.2.weight": ([5120, 5120], "F8_E4M3"),+ "time_projection.1.bias": ([30720], "F16"),+ "time_projection.1.scale_input": ([], "F32"),+ "time_projection.1.scale_weight": ([], "F32"),+ "time_projection.1.weight": ([30720, 5120], "F8_E4M3"),+}diff --git a/tests/backend/model_manager/load/test_krea2_int8_convrot_keys.py b/tests/backend/model_manager/load/test_krea2_int8_convrot_keys.pynew file mode 100644index 0000000000..2a9e569820--- /dev/null+++ b/tests/backend/model_manager/load/test_krea2_int8_convrot_keys.py@@ -0,0 +1,118 @@+"""What the released `int8_tensorwise` Krea-2 Turbo build actually contains.++The Krea-2 loader suite beside this one runs on synthetic tiny geometry, which can say whether the+loader handles the shape it was given and cannot say whether the released file still has that shape.+These cells read the captured layout and pin the properties the decode depends on -- each one a+thing a re-upload could change without a line of loader code moving.++Krea-2 is the richest of the captured layouts because its keys are native: nothing here reaches the+module tree without `_convert_krea2_native_to_diffusers` running first, so every property below has+to survive a rename as well as being true in the file.+"""++import json++import torch++from invokeai.backend.quantization.fp8_scaled import COMFY_QUANT_SUFFIX+from invokeai.backend.quantization.int8_convrot import (+ CONVROT_GROUP_SIZE,+ INT8_TENSORWISE_FORMAT,+ check_int8_scale_layout,+ parse_comfy_quant_bytes,+)+from tests.backend.model_manager.load.state_dicts import krea2_turbo_int8_convrot_keys as fixture++KEYS = fixture.state_dict_keys+QUANTIZED = sorted(+ # `.endswith`, because the bare `scaled_fp8` marker key carries the same dtype and is not a weight.+ key[: -len(".weight")]+ for key, (_shape, dtype) in KEYS.items()+ if dtype == "I8" and key.endswith(".weight")+)+++def test_the_recorded_marker_is_the_rotated_one() -> None:+ """`convrot` and its group size live in the marker and in nothing else.++ A header entry cannot carry them -- measured: the header spelling is `{"format":+ "int8_tensorwise"}` with no room for a rotation flag. So a build that dropped `convrot` would+ still declare `int8_tensorwise`, still load, and derotate nothing. This is the cell that notices.+ """+ assert QUANTIZED+ expected = {"format": INT8_TENSORWISE_FORMAT, "convrot": True, "convrot_groupsize": CONVROT_GROUP_SIZE}++ assert set(fixture.markers) == set(QUANTIZED)+ assert all(marker == expected for marker in fixture.markers.values())+++def test_the_recorded_marker_is_what_the_production_parser_reads() -> None:+ """The fixture records the decoded marker; the loader decodes the bytes itself. Pinning the two+ together is what keeps a capture from drifting into a hand-written expectation."""+ blob = json.dumps(next(iter(fixture.markers.values()))).encode("utf-8")++ assert parse_comfy_quant_bytes(blob)["convrot_groupsize"] == CONVROT_GROUP_SIZE+ assert [shape for key, (shape, _dtype) in KEYS.items() if key.endswith(COMFY_QUANT_SUFFIX)][0] == [len(blob)]+++def test_every_int8_weight_is_marked_and_scaled_and_nothing_else_is() -> None:+ """The two halves `reject_unmarked_int8_weights` and `reject_foreign_quantization_scales` exist+ to keep matched. An orphan either way is a file one of them would refuse."""+ marked = {key[: -len(COMFY_QUANT_SUFFIX)] for key in KEYS if key.endswith(COMFY_QUANT_SUFFIX)}+ scaled = {key[: -len(".weight_scale")] for key in KEYS if key.endswith(".weight_scale")}++ assert marked == set(QUANTIZED)+ assert scaled == set(QUANTIZED)+++def test_the_scales_are_per_output_channel_and_shaped_to_multiply_rows() -> None:+ """`[out, 1]`, not `[out]`. Broadcasting aligns trailing dimensions, so a `[out]` scale on an+ `[out, in]` weight scales the input axis -- a shape error on a rectangular weight and, on a+ square one like `attn.wo` here, a model that loads and generates subtly wrong images.++ Run through `check_int8_scale_layout` rather than compared to a literal, so the cell answers the+ question the loader asks. The input extent is a stand-in: the layout check reads the row axis+ and the real widths here reach 16384, which would cost 100 MB of zeros to say the same thing.+ """+ for path in QUANTIZED:+ weight_shape, _dtype = KEYS[f"{path}.weight"]+ scale_shape, scale_dtype = KEYS[f"{path}.weight_scale"]++ assert scale_shape == [weight_shape[0], 1], path+ assert scale_dtype == "F32", path++ rows = min(weight_shape[0], 8)+ # The scale's trailing axes come from the file, so a recorded block grid would reach the+ # helper rather than being stopped by the literal above.+ check_int8_scale_layout(path, torch.zeros(rows, 4), torch.zeros(rows, *scale_shape[1:]))+++def test_every_quantized_weight_is_a_whole_number_of_rotation_groups_wide() -> None:+ """`convrot` rotates along the input dim in groups of 256, and `build_regular_hadamard` refuses+ a width that is not a multiple of it. This is the property that decides loadability at all."""+ for path in QUANTIZED:+ weight_shape, _dtype = KEYS[f"{path}.weight"]++ assert len(weight_shape) == 2, path+ assert weight_shape[1] % CONVROT_GROUP_SIZE == 0, path+++def test_the_two_keys_that_defeat_a_probe_are_here_and_are_not_quantized() -> None:+ """Both are real keys in this file, and both break the assumption that a module's parameter is+ called `weight`: the modulation table is stored at `mod.lin`, and the text-MLP norm at+ `txtmlp.0.scale`. A probe that asked the converter about `<module>.weight` answered with the+ module's own renamed prefix instead of its destination, and the scale was dropped at INFO.++ Neither is quantized in this build, which is why the defect stayed latent -- and why the cell+ pins their presence rather than their marker.+ """+ assert KEYS["blocks.0.mod.lin"][1] == "BF16"+ assert "blocks.0.mod.lin.weight" not in KEYS+ assert KEYS["txtmlp.0.scale"][1] == "F32"+ assert "txtmlp.0.weight" not in KEYS+++def test_the_build_declares_its_scheme_only_per_tensor() -> None:+ """No `__metadata__` at all -- so for this file the per-tensor marker is not a second opinion,+ it is the only one. A loader reading the header alone finds nothing and folds the codes."""+ assert not hasattr(fixture, "layer_hints")diff --git a/tests/backend/model_manager/load/test_mistral_scaled_fp8_keys.py b/tests/backend/model_manager/load/test_mistral_scaled_fp8_keys.pynew file mode 100644index 0000000000..07555dc550--- /dev/null+++ b/tests/backend/model_manager/load/test_mistral_scaled_fp8_keys.py@@ -0,0 +1,67 @@+"""What the released scaled-fp8 Mistral-3-Small encoder actually contains.++Two properties of this build are not visible in any other captured layout, and both are ones the+loader depends on rather than merely observes: the header names its layers in the same namespace as+the tensors, which is what the hint re-key assumes, and the checkpoint carries the tokenizer as a+tensor, which is what a metadata sweep must not take with it.++Deliberately not asserted here: the scale spellings and the per-tensor scale shape. Both are already+pinned against `flux1_transformer_scaled_fp8_keys.py`, which carries a calibrated input scale too.+"""++from invokeai.backend.model_manager.load.model_loaders.mistral_encoder import (+ MISTRAL_KEY_PREFIXES,+ _bare_mistral_path,+)+from invokeai.backend.quantization.fp8_scaled import is_scale_metadata_key+from tests.backend.model_manager.load.state_dicts import mistral_3_small_scaled_fp8_keys as fixture++KEYS = fixture.state_dict_keys+QUANTIZED = sorted(+ # `.endswith`, because the bare `scaled_fp8` marker key carries the same dtype and is not a weight.+ key[: -len(".weight")]+ for key, (_shape, dtype) in KEYS.items()+ if dtype == "F8_E4M3" and key.endswith(".weight")+)+++def test_the_header_names_its_layers_in_the_tensors_own_namespace() -> None:+ """The hint re-key rests on this and cannot check it.++ `_quantization_metadata` is written before any prefix is stripped, so a header naming a+ namespace the tensors do not use matches nothing: the flags are dropped, `full_precision_matmul`+ comes out False where the producer asked for True, and the load still succeeds. Here the two+ agree exactly, which is why this file is usable as the reference for that path.+ """+ assert QUANTIZED+ assert set(fixture.layer_hints) == set(QUANTIZED)+ assert {hint["format"] for hint in fixture.layer_hints.values()} == {"float8_e4m3fn"}+++def test_a_header_name_and_its_weight_survive_the_rename_together() -> None:+ """Driven through `_bare_mistral_path`, the one function that performs the rename, rather than+ through a restatement of it -- the drift this fixture family exists to catch is a side channel+ re-keyed by a *second* statement of the rule.++ `model.` comes off for bare `MistralModel`; the wrapper prefixes this build does not carry come+ off earlier, which is why they are named as a constant rather than spelled at the call site.+ """+ for path in QUANTIZED:+ assert path.startswith("model."), path+ assert not _bare_mistral_path(path).startswith("model."), path++ assert not any(key.startswith(MISTRAL_KEY_PREFIXES) for key in KEYS)+++def test_the_tokenizer_rides_along_as_a_tensor_and_is_not_swept_up_as_metadata() -> None:+ """`tekken_model` is 19 MB of tokenizer sitting beside a zero-element `scaled_fp8` marker.++ One is metadata that has to go or `load_state_dict` sees an unexpected key; the other is a+ payload the encoder needs. A predicate loose enough to take the marker and the tokenizer both+ would fail much later and somewhere unrelated.+ """+ assert KEYS["tekken_model"][1] == "U8"+ assert not is_scale_metadata_key("tekken_model")++ assert KEYS["scaled_fp8"] == ([0], "F8_E4M3")+ assert is_scale_metadata_key("scaled_fp8")diff --git a/tests/backend/model_manager/load/test_wan_scaled_fp8_keys.py b/tests/backend/model_manager/load/test_wan_scaled_fp8_keys.pynew file mode 100644index 0000000000..94972fbedb--- /dev/null+++ b/tests/backend/model_manager/load/test_wan_scaled_fp8_keys.py@@ -0,0 +1,117 @@+"""What Comfy-Org's repackaged scaled-fp8 Wan 2.2 actually contains.++Wan's identification is *layout-sensitive* in a way the other architectures' is not. Five probes ask,+in order: is this a Wan transformer at all, is it Wan 2.1 rather than 2.2, is its layout native or+diffusers, which variant is it, and is it a main model rather than a LoRA. Every one of them reads+key names, and two read one tensor's extents. Until this capture all five were exercised only against+`_wan_a14b_native_state_dict()`, a synthetic dict written from the same understanding as the probes+themselves. A probe and its test agreeing about invented names is the circularity these captured+layouts exist to break.++So the cells here drive the real probes over the real released names. The scale spelling is *not*+what makes this fixture worth having: `flux1_transformer_scaled_fp8_keys.py` already records+`.scale_weight`/`.scale_input` and `test_flux1_scaled_fp8_keys.py` already drives a reader over it,+as does `test_scaled_fp8_fold_axis.py` for both spellings through the very fold Wan uses.++Captured over an HTTP range read: the build is ~14 GB and is not on this machine.+"""++import torch++from invokeai.backend.model_manager.configs.main import (+ _detect_wan_variant_from_state_dict,+ _find_wan_2_1_marker,+ _has_wan_keys,+ _has_wan_transformer_block_weights,+ _is_native_wan_layout,+)+from invokeai.backend.model_manager.taxonomy import WanVariantType+from invokeai.backend.quantization.fp8_scaled import COMFY_QUANT_SUFFIX, is_scale_metadata_key+from tests.backend.model_manager.load.state_dicts import wan22_t2v_14b_scaled_fp8_keys as fixture+from tests.backend.model_manager.load.state_dicts.utils import token_extents++KEYS = fixture.state_dict_keys++# `patch_embedding.weight` is the one tensor whose real extents a probe reads, so it keeps them;+# everything else is shrunk, because nothing under test looks at its size.+EXACT = ("patch_embedding.weight",)++DTYPES = {"F16": torch.float16, "F32": torch.float32, "F8_E4M3": torch.float8_e4m3fn, "BF16": torch.bfloat16}+++def _state_dict() -> dict[str, torch.Tensor]:+ return {+ key: torch.zeros(shape if key in EXACT else token_extents(shape), dtype=DTYPES[dtype])+ for key, (shape, dtype) in KEYS.items()+ }+++def test_the_released_names_are_recognised_as_a_wan_transformer_at_all() -> None:+ """The first question asked of the file, before layout or variant: is this a Wan transformer?++ It is answered by `patch_embedding.weight` plus a text-projection fingerprint, and the whole+ point of that pairing is not to collide with FLUX, Qwen-Image or Z-Image. Driven here over the+ released names rather than a dict written from the same understanding as the probe.+ """+ assert _has_wan_keys(_state_dict()) is True+++def test_the_build_carries_none_of_the_wan_2_1_markers() -> None:+ """Wan 2.1 and 2.2 share a key layout and are separated only by architecture, so a 2.2 build has+ to be *negative* here -- a false marker would reject a supported file by name.++ This is also the second consumer of the exact `patch_embedding.weight` extent, which is why that+ one tensor keeps its real shape in `_state_dict`.+ """+ assert _find_wan_2_1_marker(_state_dict()) is None+++def test_the_released_native_names_satisfy_the_layout_probe() -> None:+ """`_is_native_wan_layout` decides whether `_convert_wan_native_to_diffusers` runs at all.++ It keys on `text_embedding.0.weight`, and this file really does spell it that way -- under no+ prefix, as ComfyUI's repackaging ships it. A release that renamed that one key would send the+ file down the diffusers branch, where every key is then unexpected.+ """+ assert _is_native_wan_layout(_state_dict()) is True+++def test_the_patch_embedding_shape_identifies_the_variant() -> None:+ """The variant comes from `patch_embedding.weight`'s `[inner_dim, in_channels, T, H, W]`, and+ getting it wrong is expensive rather than loud: a mislabelled variant pins the wrong expert,+ picks the wrong default settings, and hides the low-noise partner picker.++ This is the T2V A14B build, so 16 channels at 5120 wide. The shape is recorded from the file,+ and the probe requires *both* numbers precisely because in_channels alone is ambiguous across+ the wider Wan family.+ """+ assert KEYS["patch_embedding.weight"][0] == [5120, 16, 1, 2, 2]++ assert _detect_wan_variant_from_state_dict(_state_dict()) is WanVariantType.T2V_A14B+++def test_a_real_block_weight_separates_the_build_from_a_wan_lora() -> None:+ """An I2V LoRA ships a full replacement `patch_embedding` and a `text_embedding`, so it matches+ the coarse Wan probes; an undecorated `blocks.0.self_attn.q.weight` is what says "main model".++ Pinned against the released names because a LoRA spells the same layer+ `...self_attn.q.lora_A.weight`, and the separation is an exact key match.+ """+ assert "blocks.0.self_attn.q.weight" in KEYS++ assert _has_wan_transformer_block_weights(_state_dict()) is True+++def test_the_only_thing_the_build_declares_about_itself_is_the_bare_marker() -> None:+ """No `_quantization_metadata`, no per-layer `.comfy_quant`: one zero-element `scaled_fp8` key.++ So the fp8 branch is entered on the key names alone, and that single key has to be recognised as+ metadata -- left in the dict it is an unexpected key at `load_state_dict`, and it names no layer+ for a hint to hang on.+ """+ assert not hasattr(fixture, "layer_hints")+ assert not hasattr(fixture, "markers")+ assert not any(key.endswith(COMFY_QUANT_SUFFIX) for key in KEYS)++ assert KEYS["scaled_fp8"] == ([0], "F8_E4M3")+ assert is_scale_metadata_key("scaled_fp8")