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.

feat(qwen-image): load ComfyUI int8 convrot checkpoints (#10186)

Alexander Eichhorn6aaef6136823
diff --git a/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdx b/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdx
index 44cc982c64..7c41f348f8 100644
--- a/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdx
@@ -47,7 +47,7 @@ InvokeAI recognizes the format from the file's contents, so you install them lik
- **GGUF** (`.gguf`, llama.cpp quantization such as Q4_K or Q8_0): weights stay packed in memory and are unpacked layer by layer during generation. Supported for the FLUX.1, FLUX.2, FLUX.3, Z-Image, Krea-2, Qwen-Image, Qwen-Image-2.1, Ideogram 4, ERNIE-Image and Wan transformers, and for the T5, Qwen3, Qwen3-VL, Qwen2.5-VL (text only), Mistral and Gemma 2 text encoders. ComfyUI-GGUF's `Q8_CR` and `Q4_CR` files, which store int8 or int4 convrot layers inside a `.gguf`, load for the Krea-2 transformer; for other models installation is refused with a message saying so.
- **NF4** (bitsandbytes): 4-bit. InvokeAI installs bitsandbytes on Windows and Linux, with ROCm binaries for AMD GPUs, so NF4 models load on NVIDIA and AMD GPUs; macOS installs have no bitsandbytes, and NF4 models don't load there.
- **SDNQ**: see [SDNQ Quantization](/configuration/optimization/sdnq-quantization/).
-- **int8** (`int8_convrot`, from ComfyUI repackages): the weights stay int8 in memory on every device, including Apple Silicon, and need no setting to turn on. Supported for FLUX.1, FLUX.2 Klein, FLUX.3, Z-Image, Anima, Krea-2, Qwen-Image-2.1, Ideogram 4, MiniMax H3, LTX-2 and the PiD decoders, and for the Qwen3 4B and 8B, Qwen3-VL and LTX-2 Gemma encoders.
+- **int8** (`int8_convrot`, from ComfyUI repackages): the weights stay int8 in memory on every device, including Apple Silicon, and need no setting to turn on. Supported for FLUX.1, FLUX.2 Klein, FLUX.3, Z-Image, Anima, Krea-2, Qwen-Image, Qwen-Image-2.1, Ideogram 4, MiniMax H3, LTX-2 and the PiD decoders, and for the Qwen3 4B and 8B, Qwen3-VL, Qwen2.5-VL and LTX-2 Gemma encoders.
- **int4** (`convrot_w4a4` or `int4_tensorwise`, ComfyUI repackages that usually keep some layers int8): the weights stay packed in memory at half a byte each and are unpacked per layer, on every device. This saves memory, not time: InvokeAI unpacks the weights for every step rather than running 4-bit matrix kernels, and 4-bit weights keep less detail than int8. Supported for the Krea-2 transformer.
- **nvfp4** (4-bit, in ComfyUI's checkpoint format, such as Comfy-Org's builds; other nvfp4 exports such as AWQ are refused): the weights stay packed in memory and are unpacked per layer, so no special GPU is needed. Supported for the FLUX.3, Z-Image, Krea-2, Qwen-Image and LTX-2 transformers and for the Qwen3, Qwen3-VL 4B/8B, Qwen2.5-VL and FLUX.2 Mistral encoders; for FLUX.3 also Black Forest Labs' own nvfp4 build, in NVIDIA ModelOpt's layout. The Ideogram 4 and Qwen-Image-2.1 nvfp4 transformer files are refused at install.
- **fp8** (plain or `fp8_scaled`): InvokeAI keeps the weights in fp8 when [FP8 Storage](/configuration/optimization/fp8-storage/) is on, which installation does for you, or when `fp8_compute` is enabled.
diff --git a/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx b/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx
index adf4b869a7..1d0e8a384a 100644
--- a/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/03.model-format-support.mdx
@@ -40,7 +40,7 @@ reader's error; if the file is incomplete or corrupt, download it again.
| [FLUX.3](/users-guide/models/local-models/flux-3/) | ✓ | ✓ | ✓ | ✓ | R | ✓ | – | ✓ | – | – |
| [CogView4](/users-guide/models/local-models/cogview4/) | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
| [Z-Image](/users-guide/models/local-models/z-image/) | ✓ | ✓ | ✓ | ✓ | L | ✓ | ✓ | ✓ | ✓ | ✗ |
-| [Qwen-Image](/users-guide/models/local-models/qwen-image/) | ✓ | ✓ | ✓ | ✗ | ✗ | ✓ | ✓ | ✓ | ✗ | ✗ |
+| [Qwen-Image](/users-guide/models/local-models/qwen-image/) | ✓ | ✓ | ✓ | ✓ | R | ✓ | ✓ | ✓ | ✗ | ✗ |
| [Qwen-Image-2.1](/users-guide/models/local-models/qwen-image-2-1/) | ✓ | ✓ | ✓ | ✓ | R | R | – | ✓ | ✗ | ✗ |
| [Anima](/users-guide/models/local-models/anima/) | – | ✓ | ✓ | ✓ | L | ✗ | ✓ | ✓ | ✗ | ✗ |
| [Krea-2](/users-guide/models/local-models/krea-2/) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ |
@@ -59,7 +59,8 @@ reader's error; if the file is incomplete or corrupt, download it again.
AWQ and other producers' nvfp4 at install. For Qwen-Image-2.1 and FLUX.3, torchao exports such as unsloth's FP8
builds are refused at install. MOSS-Image loads Comfy-Org's int8 build and GGUFs; its fp8, nvfp4 and w4a8
transformers, and unsloth's torchao builds, are refused at install, unscaled fp8 included. ComfyUI's other low-bit
- layouts (`w4a8`, `w6a8`, SVDQuant) are not supported; Krea-2 refuses them at install.
+ layouts (`w4a8`, `w6a8`, SVDQuant) are not supported; Krea-2 and
+ Qwen-Image refuse them at install.
- **GGUF** covers the llama.cpp types (Q4_0 through Q8_0, the K-quants, BF16). ComfyUI-GGUF's `Q8_CR` (int8) and
`Q4_CR` (int4) files load for Krea-2 only; for every other model with GGUF support the install fails, as it does
for `Q4_CR` files of ComfyUI-GGUF's retired W4A16 kind.
@@ -78,7 +79,7 @@ reader's error; if the file is incomplete or corrupt, download it again.
| Qwen3-VL 32B (truncated) | MiniMax H3 | in the Diffusers folder | ✓ | L | ✓ | L | ✗ | ✗ |
| Qwen3.5 4B | Anima 3.8B | ✗ | ✓ | R | – | R | ✗ | ✗ |
| Qwen3.5 9B | MOSS-Image | in the Diffusers folder | ✓ | R | ✓ | R | ✗ | ✗ |
-| Qwen2.5-VL | Qwen-Image | ✓ | ✓ | ✓ | L | ✓ | ✓ (text only) | ✗ |
+| Qwen2.5-VL | Qwen-Image | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ (text only) | ✗ |
| Mistral Small 3 | FLUX.2 dev | ✓ | ✓ | ✓ | L | ✓ | ✓ | ✗ |
| Ministral 3B | ERNIE-Image | ✓ | ✓ | ✓ | L | L | R | ✗ |
| Gemma-2 2B | PiD decoders | ✓ | ✗ | ✗ | ✗ | ✗ | ✓ | ✗ |
diff --git a/docs/src/content/docs/Users Guide/03.Models/Local Models/qwen-image.mdx b/docs/src/content/docs/Users Guide/03.Models/Local Models/qwen-image.mdx
index 8154e84908..9d7ab0a5e6 100644
--- a/docs/src/content/docs/Users Guide/03.Models/Local Models/qwen-image.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/Local Models/qwen-image.mdx
@@ -46,6 +46,14 @@ cannot hold both, enable [Low-VRAM mode](/configuration/optimization/low-vram-mo
checkpoints that ship fp8 weights are kept in fp8 with
[FP8 Storage](/configuration/optimization/fp8-storage/), which is switched on for them when they are installed.
+ComfyUI's `int8_tensorwise` builds, rotated (`int8_convrot`) or not, load for the transformer and for the Qwen2.5-VL
+encoder. Comfy-Org publishes `int8_convrot` transformers for Qwen Image Edit 2509 and 2511; the Qwen2.5-VL int8
+encoders are community uploads. The int8 layers stay int8 in memory (about half the bf16 size) and are dequantized
+layer by layer as they run, on every device. That is the default: on NVIDIA GPUs, [int8 Compute](/configuration/optimization/int8-compute/)
+can run them on the int8 tensor cores instead. The main benefit is memory; no speed-up is promised. DoRA LoRAs do not
+run on an int8 transformer. A file whose int8 layers carry only a `{"convrot": true}` marker, with no format, is
+refused at install for the transformer and when the encoder loads. Int4 builds are refused at install.
+
## Installing
The easiest path is the **Qwen Image** bundle in the Model Manager's Starter Models. It installs the
diff --git a/invokeai/app/invocations/qwen_image/qwen_image_denoise.py b/invokeai/app/invocations/qwen_image/qwen_image_denoise.py
index 7b29fddd49..93ac1d0c9e 100644
--- a/invokeai/app/invocations/qwen_image/qwen_image_denoise.py
+++ b/invokeai/app/invocations/qwen_image/qwen_image_denoise.py
@@ -481,7 +481,7 @@ class QwenImageDenoiseInvocation(BaseInvocation, WithMetadata, WithBoard):
transformer_config = context.models.get_config(self.transformer.transformer)
# The forward's activations, which the cache keeps free by offloading as much of the transformer as that
- # takes, plus the per-forward dequantization transient of an nvfp4 or GGUF build, alive alongside them and
+ # takes, plus the per-forward dequantization transient of an nvfp4, int8 or GGUF build, alive alongside them and
# invisible to the estimate. All read from the unlocked model, before the lock; the transient is zero for a
# dense build.
text_seq_len = max(
diff --git a/invokeai/app/invocations/text_encoder/qwen_image_text_encoder.py b/invokeai/app/invocations/text_encoder/qwen_image_text_encoder.py
index 736c2dcf10..06015324e8 100644
--- a/invokeai/app/invocations/text_encoder/qwen_image_text_encoder.py
+++ b/invokeai/app/invocations/text_encoder/qwen_image_text_encoder.py
@@ -408,7 +408,7 @@ class QwenImageTextEncoderInvocation(BaseInvocation):
from transformers import Qwen2_5_VLForConditionalGeneration
text_encoder_info = context.models.load(self.qwen_vl_encoder.text_encoder)
- # An nvfp4 or GGUF build dequantizes each packed Linear per forward, a transient its resident size does not
+ # An nvfp4, int8 or GGUF build dequantizes each packed Linear per forward, a transient its resident size does not
# cover. The cache holds back the larger of this and its default working memory, not their sum. Read from the
# unlocked model, before the lock; zero for every other build.
dequant_bytes = peak_dequant_transient_bytes(
@@ -491,8 +491,8 @@ class QwenImageTextEncoderInvocation(BaseInvocation):
encoder_config = context.models.get_config(self.qwen_vl_encoder.text_encoder)
model_root = context.models.get_absolute_path(encoder_config)
if model_root.is_file():
- # Single-file checkpoint (e.g. ComfyUI fp8_scaled or nvfp4): BnB can't load from a single file. Fall back
- # to the cached path, which folds fp8 layers to bf16 and keeps nvfp4 layers packed.
+ # Single-file checkpoint (e.g. ComfyUI fp8_scaled, nvfp4 or int8): BnB can't load from a single file. Fall
+ # back to the cached path, which folds fp8 layers to bf16 and keeps nvfp4 and int8 layers packed.
return self._load_cached_encoder(context)
encoder_path = model_root / "text_encoder"
diff --git a/invokeai/backend/model_manager/configs/main.py b/invokeai/backend/model_manager/configs/main.py
index a989b5145f..dae1585413 100644
--- a/invokeai/backend/model_manager/configs/main.py
+++ b/invokeai/backend/model_manager/configs/main.py
@@ -2616,10 +2616,11 @@ def _infer_qwen_image_variant(sd: dict[str | int, Any], path: Path) -> QwenImage
class Main_Checkpoint_QwenImage_Config(Checkpoint_Config_Base, Main_Config_Base, Config_Base):
"""Model config for Qwen Image single-file checkpoint models (safetensors, etc).
- Covers raw bf16/fp16 checkpoints and ComfyUI-style fp8_scaled and nvfp4 checkpoints.
- The loader keeps scaled fp8 weights when fp8 compute is available or the
+ Covers raw bf16/fp16 checkpoints and ComfyUI-style fp8_scaled, nvfp4 and int8_tensorwise(+convrot)
+ checkpoints. The loader keeps scaled fp8 weights when fp8 compute is available or the
`default_settings.fp8_storage` toggle is on (which also re-casts the rest to fp8),
- and dequantizes them to bf16 at load time otherwise.
+ and dequantizes them to bf16 at load time otherwise. An int8 weight whose marker is missing or
+ names another format is refused at install, as the loader would refuse it.
"""
base: Literal[BaseModelType.QwenImage] = Field(default=BaseModelType.QwenImage)
@@ -2640,6 +2641,17 @@ class Main_Checkpoint_QwenImage_Config(Checkpoint_Config_Base, Main_Config_Base,
if _has_ggml_tensors(sd):
raise NotAMatchError("state dict looks like GGUF quantized")
+ # Not `_raise_for_unsupported_comfy_quantization`: it refuses nvfp4, which this family loads. The loader reads
+ # both the per-tensor markers and the `_quantization_metadata` header.
+ _raise_for_undecodable_int8_weights(
+ mod,
+ sd,
+ accepted_convrot_formats(accept_int4=False),
+ read_header=True,
+ what="Qwen Image transformer",
+ supported="Only the int8_tensorwise build (rotated or not) is supported.",
+ )
+
explicit_variant = override_fields.pop("variant", None) or _infer_qwen_image_variant(sd, mod.path)
return cls(**override_fields, variant=explicit_variant)
diff --git a/invokeai/backend/model_manager/load/model_loaders/qwen_image.py b/invokeai/backend/model_manager/load/model_loaders/qwen_image.py
index 7545ad792a..927efb33e7 100644
--- a/invokeai/backend/model_manager/load/model_loaders/qwen_image.py
+++ b/invokeai/backend/model_manager/load/model_loaders/qwen_image.py
@@ -49,15 +49,24 @@ from invokeai.backend.quantization.fp8_scaled import (
)
from invokeai.backend.quantization.gguf.ggml_tensor import GGMLTensor
from invokeai.backend.quantization.gguf.loaders import gguf_sd_loader, unpack_ggml_at_load
-from invokeai.backend.quantization.int8_convrot import reject_int8_layers_a_plain_fold_cannot_decode
+from invokeai.backend.quantization.int8_convrot import (
+ drop_unconsumed_quantization_sidecars,
+ extract_int8_convrot_markers,
+ install_int8_convrot_layers,
+ reject_unmarked_int8_weights,
+)
from invokeai.backend.quantization.load_plan import reserve_for_load
-from invokeai.backend.quantization.nvfp4 import install_nvfp4_layers, pop_nvfp4_layers
+from invokeai.backend.quantization.nvfp4 import install_nvfp4_layers, pop_nvfp4_layers, predict_nvfp4_install_size
from invokeai.backend.qwen2_5_vl.qwen2_5_vl_assets import (
load_bundled_qwen2_5_vl_config_dict,
load_bundled_qwen2_5_vl_tokenizer,
)
from invokeai.backend.util.devices import TorchDevice
-from invokeai.backend.util.state_dict_loading import load_state_dict_ignoring_extras, log_unexpected_keys
+from invokeai.backend.util.state_dict_loading import (
+ load_state_dict_ignoring_extras,
+ log_unexpected_keys,
+ reject_incomplete_load,
+)
def _remap_qwen_vl_checkpoint_keys(sd: dict) -> dict:
@@ -248,10 +257,11 @@ class QwenImageGGUFCheckpointModel(ModelLoader):
@ModelLoaderRegistry.register(base=BaseModelType.QwenImage, type=ModelType.Main, format=ModelFormat.Checkpoint)
class QwenImageCheckpointModel(ModelLoader):
"""Loads Qwen Image transformer models from single-file safetensors checkpoints
- (e.g. ComfyUI fp8_scaled or nvfp4, plain bf16/fp16). nvfp4 layers stay packed. Scaled
+ (e.g. ComfyUI fp8_scaled, nvfp4 or int8_tensorwise, plain bf16/fp16). nvfp4 layers stay packed and
+ int8_tensorwise(+convrot) layers stay int8 (`Int8ConvrotLinear`), both dequantized per forward. Scaled
fp8 layers keep their fp8 weight and scale when fp8 compute is available or the model's
`default_settings.fp8_storage` is on (which then also casts the dense remainder to fp8);
- otherwise they are dequantized to bf16 at load time."""
+ otherwise they are dequantized to bf16 at load time. A file carries int8 or scaled fp8, not both."""
def _load_model(
self,
@@ -304,13 +314,28 @@ class QwenImageCheckpointModel(ModelLoader):
)
nvfp4_payloads = pop_nvfp4_layers(sd, header_layers=header_layers)
- # ComfyUI 'scaled fp8': an fp8 weight plus its `weight_scale`, named in the header or by a per-layer marker.
- fp8_layers = extract_fp8_scaled_layers(sd, layer_hints={**extract_comfy_quant_hints(sd), **header_layers})
- # Kept fp8 only when something uses them: the fp8 matmul, or fp8 storage the user asked of this model. For
- # storage the checkpoint's own scale is exact, where the layerwise cast of a folded weight has none. Without
- # either, a dequantize per forward would cost speed for memory nobody asked to save, so they are folded.
- use_fp8_storage = bool(fp8_layers) and self._should_use_fp8(config, SubModelType.Transformer)
- keep_fp8 = bool(fp8_layers) and (should_keep_fp8_weights(target_device) or use_fp8_storage)
+ # ComfyUI 'int8_tensorwise' (+convrot) shares the fp8 key layout (`.weight` beside `.weight_scale`), and the
+ # fp8 extraction below pops every `.weight_scale`, so the int8 layers are claimed first. Outside the branch
+ # on purpose: an int8 weight whose marker is missing would otherwise be cast as raw codes and generate noise.
+ int8_markers = extract_int8_convrot_markers(sd, header_layers=header_layers)
+ reject_unmarked_int8_weights(sd, int8_markers, "Qwen Image", header_layers=header_layers)
+
+ if int8_markers:
+ sd = drop_unconsumed_quantization_sidecars(sd)
+ fp8_layers = {}
+ # Nothing scaled to keep for fp8 storage; the outer `_apply_fp8_layerwise_casting` still casts the dense
+ # remainder when the model asks for fp8 storage.
+ use_fp8_storage = False
+ keep_fp8 = False
+ else:
+ # ComfyUI 'scaled fp8': an fp8 weight plus its `weight_scale`, named in the header or by a per-layer marker.
+ fp8_layers = extract_fp8_scaled_layers(sd, layer_hints={**extract_comfy_quant_hints(sd), **header_layers})
+ # Kept fp8 only when something uses them: the fp8 matmul, or fp8 storage the user asked of this model. For
+ # storage the checkpoint's own scale is exact, where the layerwise cast of a folded weight has none.
+ # Without either, a dequantize per forward would cost speed for memory nobody asked to save, so they are
+ # folded.
+ use_fp8_storage = bool(fp8_layers) and self._should_use_fp8(config, SubModelType.Transformer)
+ keep_fp8 = bool(fp8_layers) and (should_keep_fp8_weights(target_device) or use_fp8_storage)
is_edit = getattr(config, "variant", None) == QwenImageVariantType.Edit
model_config = _build_qwen_image_transformer_config(sd, is_edit=is_edit)
@@ -321,26 +346,44 @@ class QwenImageCheckpointModel(ModelLoader):
model = QwenImageTransformer2DModel(**model_config)
skip_patterns = _model_declared_skip_patterns(model)
- # One reservation, before the fold or the split widens a single weight: `make_room` makes that much room
- # rather than adding to an earlier one.
- reserve_for_load(
- self._ram_cache.make_room,
- sd,
- model_dtype,
- keep_fp8=keep_fp8,
- model=model,
- skip_patterns=skip_patterns,
- fp8_layers=fp8_layers,
- nvfp4_payloads=nvfp4_payloads,
- )
+ if int8_markers:
+ # The checkpoint's keys already match diffusers' module tree, so the markers need no renaming. The one
+ # reservation also covers the nvfp4 layers held beside the int8 ones.
+ quantized = install_int8_convrot_layers(
+ model,
+ sd,
+ int8_markers,
+ model_dtype,
+ architecture="Qwen Image",
+ reserve=self._ram_cache.make_room,
+ skip_patterns=skip_patterns,
+ extra_reserved_bytes=predict_nvfp4_install_size(model, nvfp4_payloads, model_dtype, skip_patterns),
+ )
+ logger.info(
+ f"Qwen Image: kept {len(quantized)} of {len(int8_markers)} layer(s) in int8 "
+ "(int8_tensorwise checkpoint, dequantized per forward)"
+ )
+ else:
+ # One reservation, before the fold or the split widens a single weight: `make_room` makes that much room
+ # rather than adding to an earlier one.
+ reserve_for_load(
+ self._ram_cache.make_room,
+ sd,
+ model_dtype,
+ keep_fp8=keep_fp8,
+ model=model,
+ skip_patterns=skip_patterns,
+ fp8_layers=fp8_layers,
+ nvfp4_payloads=nvfp4_payloads,
+ )
- if fp8_layers and not keep_fp8:
- dequantize_fp8_scaled(sd, fp8_layers, model_dtype)
- logger.info(f"Qwen Image: folded {len(fp8_layers)} scaled fp8 layer(s) into {model_dtype}.")
- fp8_layers = {}
- # Layers the cast would widen anyway are folded here with their scale applied, so the cast never drops one.
- fp8_layers = split_fp8_scaled_layers(sd, fp8_layers, model_dtype, model=model, skip_patterns=skip_patterns)
- cast_state_dict(sd, model_dtype, keep_fp8=keep_fp8, model=model, skip_patterns=skip_patterns)
+ if fp8_layers and not keep_fp8:
+ dequantize_fp8_scaled(sd, fp8_layers, model_dtype)
+ logger.info(f"Qwen Image: folded {len(fp8_layers)} scaled fp8 layer(s) into {model_dtype}.")
+ fp8_layers = {}
+ # Layers the cast would widen anyway are folded here with their scale applied, so the cast never drops one.
+ fp8_layers = split_fp8_scaled_layers(sd, fp8_layers, model_dtype, model=model, skip_patterns=skip_patterns)
+ cast_state_dict(sd, model_dtype, keep_fp8=keep_fp8, model=model, skip_patterns=skip_patterns)
if nvfp4_payloads:
packed = install_nvfp4_layers(model, sd, nvfp4_payloads, model_dtype, skip_patterns)
@@ -349,6 +392,10 @@ class QwenImageCheckpointModel(ModelLoader):
load_state_dict_ignoring_extras(
model, sd, source="Qwen-Image transformer checkpoint", assign=True, allow_missing=True
)
+ if int8_markers:
+ # `allow_missing` lets a partial file through; a quantized layer that lost a tensor would otherwise fail
+ # on the first forward with a meta-tensor error.
+ reject_incomplete_load(model, what="Qwen Image int8 transformer checkpoint")
# `assign=True` aliases every param to its `sd` tensor: without this, the fp8 storage cast below would hold
# each dense weight at bf16 and fp8 at once, past the reservation.
sd.clear()
@@ -460,14 +507,18 @@ class QwenVLEncoderCheckpointLoader(ModelLoader):
# Comfy's nvfp4 build keeps the language model's projections in nvfp4, beside scaled fp8 embeddings. Take those
# layers out before the fold: `_dequantize_comfyui_fp8` multiplies every `.weight_scale` into its weight,
# nvfp4's block scales included. `install_nvfp4_layers` puts them back, packed.
- nvfp4_payloads = pop_nvfp4_layers(
- sd, header_layers=parse_quantization_metadata(read_safetensors_metadata(model_path, logger))
- )
+ header_layers = parse_quantization_metadata(read_safetensors_metadata(model_path, logger))
+ nvfp4_payloads = pop_nvfp4_layers(sd, header_layers=header_layers)
- # Ahead of the config fetch and the reservation below, rather than where the fold reaches it:
- # a load that cannot finish should not go to the network first, nor evict the cache for room
- # it will never use.
- reject_int8_layers_a_plain_fold_cannot_decode(sd, "Qwen2.5-VL encoder checkpoint")
+ # ComfyUI 'int8_tensorwise' (+convrot) shares the fp8 key layout, and the fold below multiplies every
+ # `.weight_scale` into its weight, which for a rotated layer leaves a weight of the right shape and no
+ # relation to the one stored. The int8 layers are claimed first and stay int8. Ahead of the reservation, so a
+ # load that cannot finish does not evict the cache for room it will never use. The refusal is outside the
+ # branch on purpose: an int8 weight with no marker is refused in every case.
+ int8_markers = extract_int8_convrot_markers(sd, header_layers=header_layers)
+ reject_unmarked_int8_weights(sd, int8_markers, "Qwen2.5-VL encoder", header_layers=header_layers)
+ if int8_markers:
+ sd = drop_unconsumed_quantization_sidecars(sd)
# The architecture config is vendored rather than fetched: these constants decide the
# module tree that the weights below are folded into, and a re-upload changing one of them
@@ -479,39 +530,57 @@ class QwenVLEncoderCheckpointLoader(ModelLoader):
with accelerate.init_empty_weights():
model = Qwen2_5_VLForConditionalGeneration(qwen_config)
skip_patterns = _model_declared_skip_patterns(model)
- # The packed layers are named in the same legacy layout as the keys.
+ # The packed and int8 layers are named in the same legacy layout as the keys.
nvfp4_payloads = _remap_qwen_vl_checkpoint_keys(nvfp4_payloads)
-
- # One reservation, before the fold widens a single weight: `make_room` makes that much room rather than adding
- # to an earlier one. Every fp8 layer is folded to the compute dtype.
- reserve_for_load(
- self._ram_cache.make_room,
- sd,
- model_dtype,
- keep_fp8=False,
- model=model,
- skip_patterns=skip_patterns,
- fp8_layers={},
- nvfp4_payloads=nvfp4_payloads,
- )
-
- # Dequantize ComfyUI-style fp8 weights, then strip the now-unused quantization
- # metadata (`scale_input` is the activation scale ComfyUI's fp8 matmul kernels
- # use at runtime — we run the encoder in bf16 after dequantization).
- dequantized_count = _dequantize_comfyui_fp8(sd, model_dtype, "Qwen2.5-VL encoder checkpoint")
- if dequantized_count > 0:
- logger.info(f"Dequantized {dequantized_count} ComfyUI-quantized weights")
- _strip_quantization_metadata(sd)
+ int8_markers = _remap_qwen_vl_checkpoint_keys(int8_markers)
# ComfyUI single-file checkpoints use the legacy Qwen2.5-VL key layout
# (`visual.X`, `model.X`); remap to the `model.visual.X` / `model.language_model.X`
# layout transformers expects. See `_remap_qwen_vl_checkpoint_keys` for details.
sd = _remap_qwen_vl_checkpoint_keys(sd)
- # Cast to compute dtype (skip integer/index tensors)
- for k in list(sd.keys()):
- if sd[k].is_floating_point():
- sd[k] = sd[k].to(model_dtype)
+ if int8_markers:
+ # The dense tensors are cast inside, and the fp32 scales are left alone: a blanket cast would ruin them.
+ quantized = install_int8_convrot_layers(
+ model,
+ sd,
+ int8_markers,
+ model_dtype,
+ architecture="Qwen2.5-VL encoder",
+ reserve=self._ram_cache.make_room,
+ skip_patterns=skip_patterns,
+ extra_reserved_bytes=predict_nvfp4_install_size(model, nvfp4_payloads, model_dtype, skip_patterns),
+ )
+ logger.info(
+ f"Qwen VL encoder: kept {len(quantized)} of {len(int8_markers)} layer(s) in int8 "
+ "(int8_tensorwise checkpoint, dequantized per forward)"
+ )
+ else:
+ # One reservation, before the fold widens a single weight: `make_room` makes that much room rather than
+ # adding to an earlier one. Every fp8 layer is folded to the compute dtype.
+ reserve_for_load(
+ self._ram_cache.make_room,
+ sd,
+ model_dtype,
+ keep_fp8=False,
+ model=model,
+ skip_patterns=skip_patterns,
+ fp8_layers={},
+ nvfp4_payloads=nvfp4_payloads,
+ )
+
+ # Dequantize ComfyUI-style fp8 weights, then strip the now-unused quantization
+ # metadata (`scale_input` is the activation scale ComfyUI's fp8 matmul kernels
+ # use at runtime; we run the encoder in bf16 after dequantization).
+ dequantized_count = _dequantize_comfyui_fp8(sd, model_dtype, "Qwen2.5-VL encoder checkpoint")
+ if dequantized_count > 0:
+ logger.info(f"Dequantized {dequantized_count} ComfyUI-quantized weights")
+ _strip_quantization_metadata(sd)
+
+ # Cast to compute dtype (skip integer/index tensors)
+ for k in list(sd.keys()):
+ if sd[k].is_floating_point():
+ sd[k] = sd[k].to(model_dtype)
if nvfp4_payloads:
packed = install_nvfp4_layers(model, sd, nvfp4_payloads, model_dtype, skip_patterns)
diff --git a/invokeai/backend/quantization/int8_convrot.py b/invokeai/backend/quantization/int8_convrot.py
index 829ba012ba..83dda6a81b 100644
--- a/invokeai/backend/quantization/int8_convrot.py
+++ b/invokeai/backend/quantization/int8_convrot.py
@@ -805,8 +805,9 @@ def reject_unmarked_int8_weights(
else f" A build that names its quantization only in the safetensors header is not supported for {architecture}."
)
raise ValueError(
- f"{architecture} checkpoint has {len(orphans)} int8 weight(s) with no `comfy_quant` marker, "
- f"e.g. {orphans[:3]}. Loading them would produce a model that runs and generates noise.{unread_header}"
+ f"{architecture} checkpoint has {len(orphans)} int8 weight(s) with no readable int8_tensorwise marker, "
+ f"e.g. {orphans[:3]}. Loading them would produce a model that runs and generates noise.{unread_header} "
+ "Use another build of this model."
)
diff --git a/invokeai/frontend/api/openapi.json b/invokeai/frontend/api/openapi.json
index 96d5433d7a..2e5917d747 100644
--- a/invokeai/frontend/api/openapi.json
+++ b/invokeai/frontend/api/openapi.json
@@ -78888,7 +78888,7 @@
"variant"
],
"title": "Main_Checkpoint_QwenImage_Config",
- "description": "Model config for Qwen Image single-file checkpoint models (safetensors, etc).\n\nCovers raw bf16/fp16 checkpoints and ComfyUI-style fp8_scaled and nvfp4 checkpoints.\nThe loader keeps scaled fp8 weights when fp8 compute is available or the\n`default_settings.fp8_storage` toggle is on (which also re-casts the rest to fp8),\nand dequantizes them to bf16 at load time otherwise."
+ "description": "Model config for Qwen Image single-file checkpoint models (safetensors, etc).\n\nCovers raw bf16/fp16 checkpoints and ComfyUI-style fp8_scaled, nvfp4 and int8_tensorwise(+convrot)\ncheckpoints. The loader keeps scaled fp8 weights when fp8 compute is available or the\n`default_settings.fp8_storage` toggle is on (which also re-casts the rest to fp8),\nand dequantizes them to bf16 at load time otherwise. An int8 weight whose marker is missing or\nnames another format is refused at install, as the loader would refuse it."
},
"Main_Checkpoint_SD1_Config": {
"properties": {
diff --git a/invokeai/frontend/api/schema.ts b/invokeai/frontend/api/schema.ts
index d01631e621..cf8e6d7cf0 100644
--- a/invokeai/frontend/api/schema.ts
+++ b/invokeai/frontend/api/schema.ts
@@ -32729,10 +32729,11 @@ export type components = {
* Main_Checkpoint_QwenImage_Config
* @description Model config for Qwen Image single-file checkpoint models (safetensors, etc).
*
- * Covers raw bf16/fp16 checkpoints and ComfyUI-style fp8_scaled and nvfp4 checkpoints.
- * The loader keeps scaled fp8 weights when fp8 compute is available or the
+ * Covers raw bf16/fp16 checkpoints and ComfyUI-style fp8_scaled, nvfp4 and int8_tensorwise(+convrot)
+ * checkpoints. The loader keeps scaled fp8 weights when fp8 compute is available or the
* `default_settings.fp8_storage` toggle is on (which also re-casts the rest to fp8),
- * and dequantizes them to bf16 at load time otherwise.
+ * and dequantizes them to bf16 at load time otherwise. An int8 weight whose marker is missing or
+ * names another format is refused at install, as the loader would refuse it.
*/
Main_Checkpoint_QwenImage_Config: {
/**
diff --git a/tests/backend/flux3/test_quantized_loaders.py b/tests/backend/flux3/test_quantized_loaders.py
index 3c1f5121be..4eb823df7c 100644
--- a/tests/backend/flux3/test_quantized_loaders.py
+++ b/tests/backend/flux3/test_quantized_loaders.py
@@ -291,7 +291,7 @@ def test_int8_weights_without_a_marker_are_refused_before_room_is_reserved(monke
build = _build("int8_convrot")
unmarked = {key: value for key, value in build.state_dict.items() if not key.endswith(".comfy_quant")}
- run = _refused(monkeypatch, build._replace(state_dict=unmarked), "no `comfy_quant` marker")
+ run = _refused(monkeypatch, build._replace(state_dict=unmarked), "no readable int8_tensorwise marker")
assert run.reserved == []
diff --git a/tests/backend/model_manager/configs/test_flux3_main_config.py b/tests/backend/model_manager/configs/test_flux3_main_config.py
index 42923ce104..ea77a968f7 100644
--- a/tests/backend/model_manager/configs/test_flux3_main_config.py
+++ b/tests/backend/model_manager/configs/test_flux3_main_config.py
@@ -209,7 +209,7 @@ _REFUSED = {
{_Q: {"weight": ([3072, 3072], "I8"), "weight_scale": ([3072, 1], "F32")}},
{},
{},
- "no `comfy_quant` marker",
+ "no readable int8_tensorwise marker",
),
"int8-group-size": ({_Q: _INT8}, {_Q: {**_INT8_MARKER, "convrot_groupsize": 512}}, {}, "groups of 512"),
"int8-missing-scale": (
diff --git a/tests/backend/model_manager/configs/test_qwen_image_main_config.py b/tests/backend/model_manager/configs/test_qwen_image_main_config.py
index 932689eb86..8043915a8f 100644
--- a/tests/backend/model_manager/configs/test_qwen_image_main_config.py
+++ b/tests/backend/model_manager/configs/test_qwen_image_main_config.py
@@ -1,3 +1,4 @@
+import json
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import MagicMock
@@ -5,9 +6,16 @@ from unittest.mock import MagicMock
import gguf
import pytest
import torch
+from safetensors.torch import save_file
-from invokeai.backend.model_manager.configs.main import Main_GGUF_QwenImage_Config
+from invokeai.backend.model_manager.configs.factory import ModelConfigFactory
+from invokeai.backend.model_manager.configs.identification_utils import InvalidMatchError
+from invokeai.backend.model_manager.configs.main import Main_Checkpoint_QwenImage_Config, Main_GGUF_QwenImage_Config
+from invokeai.backend.model_manager.model_on_disk import ModelOnDisk
+from invokeai.backend.model_manager.taxonomy import QwenImageVariantType
from invokeai.backend.quantization.gguf.ggml_tensor import GGMLTensor
+from tests.backend.model_manager.load.state_dicts import qwen_image_int8_convrot_keys
+from tests.backend.model_manager.load.state_dicts.utils import write_header_only_safetensors
def _build_ggml_tensor() -> GGMLTensor:
@@ -50,3 +58,83 @@ def test_qwen_gguf_config_sets_a_variant_for_imported_models(is_edit_model: bool
assert config.variant == "edit"
else:
assert config.variant == "generate"
+
+
+def _identify(path: Path):
+ return ModelConfigFactory.from_model_on_disk(ModelOnDisk(path, "random"), {}, allow_unknown=True).config
+
+
+def _tiny_int8_checkpoint(
+ tmp_path: Path, marker: dict | None, header: dict[str, dict] | None = None, name: str = "qwen_image_int8"
+) -> Path:
+ """The three keys that identify a Qwen Image transformer, and one int8 layer with the given per-tensor marker."""
+ state_dict = {
+ "img_in.weight": torch.zeros(8, 4),
+ "txt_in.weight": torch.zeros(8, 4),
+ "txt_norm.weight": torch.zeros(4),
+ "transformer_blocks.0.attn.to_q.weight": torch.zeros(4, 64, dtype=torch.int8),
+ "transformer_blocks.0.attn.to_q.weight_scale": torch.ones(4, 1),
+ }
+ if marker is not None:
+ raw = json.dumps(marker).encode("utf-8")
+ state_dict["transformer_blocks.0.attn.to_q.comfy_quant"] = torch.frombuffer(bytearray(raw), dtype=torch.uint8)
+ metadata = {"_quantization_metadata": json.dumps({"layers": header})} if header else None
+ path = tmp_path / f"{name}.safetensors"
+ save_file({k: v.clone() for k, v in state_dict.items()}, path, metadata=metadata)
+ return path
+
+
+def test_the_released_edit_2511_int8_convrot_layout_installs_as_the_edit_variant(tmp_path: Path) -> None:
+ """Its markers are read from the file; the `__index_timestep_zero__` key makes it the Edit variant."""
+ path = write_header_only_safetensors(
+ tmp_path / "qwen_image_2511_int8_convrot.safetensors",
+ qwen_image_int8_convrot_keys.state_dict_keys,
+ qwen_image_int8_convrot_keys.markers,
+ )
+
+ config = _identify(path)
+
+ assert isinstance(config, Main_Checkpoint_QwenImage_Config)
+ assert config.variant is QwenImageVariantType.Edit
+
+
+ ("marker", "header"),
+ [
+ pytest.param({"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256}, None, id="rotated"),
+ pytest.param({"format": "int8_tensorwise"}, None, id="unrotated"),
+ pytest.param(
+ None,
+ {"transformer_blocks.0.attn.to_q": {"format": "int8_tensorwise", "convrot": False}},
+ id="header_only",
+ ),
+ ],
+)
+def test_the_int8_marker_shapes_the_loader_decodes_install(tmp_path: Path, marker, header) -> None:
+ config = _identify(_tiny_int8_checkpoint(tmp_path, marker, header))
+
+ assert isinstance(config, Main_Checkpoint_QwenImage_Config)
+ assert config.variant is QwenImageVariantType.Generate
+
+
+ ("marker", "message"),
+ [
+ pytest.param(None, "carry no readable marker", id="unmarked"),
+ pytest.param({"convrot": True}, "carry no readable marker", id="convrot_without_format"),
+ pytest.param({"format": "int4_tensorwise", "convrot": True}, "marked 'int4_tensorwise'", id="int4"),
+ pytest.param({"format": "asym_w4a8_int8"}, "marked 'asym_w4a8_int8'", id="other_scheme"),
+ ],
+)
+def test_an_int8_weight_the_loader_cannot_decode_is_refused_at_install(tmp_path: Path, marker, message) -> None:
+ path = _tiny_int8_checkpoint(tmp_path, marker)
+
+ with pytest.raises(InvalidMatchError, match=message):
+ Main_Checkpoint_QwenImage_Config.from_model_on_disk(ModelOnDisk(path, "random"), {})
+
+
+def test_a_header_entry_that_does_not_say_whether_the_weight_was_rotated_is_refused_at_install(tmp_path: Path) -> None:
+ path = _tiny_int8_checkpoint(tmp_path, None, {"transformer_blocks.0.attn.to_q": {"format": "int8_tensorwise"}})
+
+ with pytest.raises(InvalidMatchError, match="does not say whether the weight was rotated"):
+ Main_Checkpoint_QwenImage_Config.from_model_on_disk(ModelOnDisk(path, "random"), {})
diff --git a/tests/backend/model_manager/load/state_dicts/qwen_image_int8_convrot_keys.py b/tests/backend/model_manager/load/state_dicts/qwen_image_int8_convrot_keys.py
new file mode 100644
index 0000000000..2c2369b527
--- /dev/null
+++ b/tests/backend/model_manager/load/state_dicts/qwen_image_int8_convrot_keys.py
@@ -0,0 +1,107 @@
+"""Representative key layout of Comfy-Org's `int8_tensorwise` (+convrot) Qwen-Image-Edit 2511 transformer.
+
+Captured on 2026-11-06 with `scripts/capture_state_dict_fixture.py`,
+which reads the header only, from
+`https://huggingface.co/Comfy-Org/Qwen-Image-Edit/resolve/main/split_files/diffusion_models/qwen_image_edit_2511_int8_convrot.safetensors`.
+
+Subsetting rule: `transformer_blocks` index 0, plus every key outside a stack. Values are `(shape, dtype)`.
+
+The names are diffusers' already, so nothing renames them before the module tree. Every attention projection,
+both MLPs and both modulation linears of a block are int8 with a `[out, 1]` float32 scale and a rotated marker;
+`img_in`, `txt_in`, `proj_out`, `norm_out.linear` and the timestep embedder stay bf16. The dotless, zero-element
+`__index_timestep_zero__` belongs to no module (`is_edit` and `zero_cond_t` come from the config), so it has to ride through the load without a marker, a scale or a place to land."""
+
+state_dict_keys: dict[str, tuple[list[int], str]] = {
+ "__index_timestep_zero__": ([0], "F32"),
+ "img_in.bias": ([3072], "BF16"),
+ "img_in.weight": ([3072, 64], "BF16"),
+ "norm_out.linear.bias": ([6144], "BF16"),
+ "norm_out.linear.weight": ([6144, 3072], "BF16"),
+ "proj_out.bias": ([64], "BF16"),
+ "proj_out.weight": ([64, 3072], "BF16"),
+ "time_text_embed.timestep_embedder.linear_1.bias": ([3072], "BF16"),
+ "time_text_embed.timestep_embedder.linear_1.weight": ([3072, 256], "BF16"),
+ "time_text_embed.timestep_embedder.linear_2.bias": ([3072], "BF16"),
+ "time_text_embed.timestep_embedder.linear_2.weight": ([3072, 3072], "BF16"),
+ "transformer_blocks.0.attn.add_k_proj.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.add_k_proj.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.add_k_proj.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.add_k_proj.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.attn.add_q_proj.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.add_q_proj.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.add_q_proj.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.add_q_proj.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.attn.add_v_proj.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.add_v_proj.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.add_v_proj.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.add_v_proj.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.attn.norm_added_k.weight": ([128], "BF16"),
+ "transformer_blocks.0.attn.norm_added_q.weight": ([128], "BF16"),
+ "transformer_blocks.0.attn.norm_k.weight": ([128], "BF16"),
+ "transformer_blocks.0.attn.norm_q.weight": ([128], "BF16"),
+ "transformer_blocks.0.attn.to_add_out.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.to_add_out.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.to_add_out.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.to_add_out.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.attn.to_k.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.to_k.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.to_k.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.to_k.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.attn.to_out.0.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.to_out.0.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.to_out.0.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.to_out.0.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.attn.to_q.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.to_q.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.to_q.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.to_q.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.attn.to_v.bias": ([3072], "BF16"),
+ "transformer_blocks.0.attn.to_v.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.attn.to_v.weight": ([3072, 3072], "I8"),
+ "transformer_blocks.0.attn.to_v.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.img_mlp.net.0.proj.bias": ([12288], "BF16"),
+ "transformer_blocks.0.img_mlp.net.0.proj.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.img_mlp.net.0.proj.weight": ([12288, 3072], "I8"),
+ "transformer_blocks.0.img_mlp.net.0.proj.weight_scale": ([12288, 1], "F32"),
+ "transformer_blocks.0.img_mlp.net.2.bias": ([3072], "BF16"),
+ "transformer_blocks.0.img_mlp.net.2.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.img_mlp.net.2.weight": ([3072, 12288], "I8"),
+ "transformer_blocks.0.img_mlp.net.2.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.img_mod.1.bias": ([18432], "BF16"),
+ "transformer_blocks.0.img_mod.1.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.img_mod.1.weight": ([18432, 3072], "I8"),
+ "transformer_blocks.0.img_mod.1.weight_scale": ([18432, 1], "F32"),
+ "transformer_blocks.0.txt_mlp.net.0.proj.bias": ([12288], "BF16"),
+ "transformer_blocks.0.txt_mlp.net.0.proj.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.txt_mlp.net.0.proj.weight": ([12288, 3072], "I8"),
+ "transformer_blocks.0.txt_mlp.net.0.proj.weight_scale": ([12288, 1], "F32"),
+ "transformer_blocks.0.txt_mlp.net.2.bias": ([3072], "BF16"),
+ "transformer_blocks.0.txt_mlp.net.2.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.txt_mlp.net.2.weight": ([3072, 12288], "I8"),
+ "transformer_blocks.0.txt_mlp.net.2.weight_scale": ([3072, 1], "F32"),
+ "transformer_blocks.0.txt_mod.1.bias": ([18432], "BF16"),
+ "transformer_blocks.0.txt_mod.1.comfy_quant": ([72], "U8"),
+ "transformer_blocks.0.txt_mod.1.weight": ([18432, 3072], "I8"),
+ "transformer_blocks.0.txt_mod.1.weight_scale": ([18432, 1], "F32"),
+ "txt_in.bias": ([3072], "BF16"),
+ "txt_in.weight": ([3072, 3584], "BF16"),
+ "txt_norm.weight": ([3584], "BF16"),
+}
+
+# The per-layer `.comfy_quant` markers, decoded from the blobs themselves.
+markers: dict[str, dict[str, object]] = {
+ "transformer_blocks.0.attn.add_k_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.attn.add_q_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.attn.add_v_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.attn.to_add_out": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.attn.to_k": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.attn.to_out.0": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.attn.to_q": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.attn.to_v": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.img_mlp.net.0.proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.img_mlp.net.2": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.img_mod.1": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.txt_mlp.net.0.proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.txt_mlp.net.2": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "transformer_blocks.0.txt_mod.1": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+}
diff --git a/tests/backend/model_manager/load/state_dicts/qwen_vl_encoder_int8_convrot_keys.py b/tests/backend/model_manager/load/state_dicts/qwen_vl_encoder_int8_convrot_keys.py
new file mode 100644
index 0000000000..22f63ff8f6
--- /dev/null
+++ b/tests/backend/model_manager/load/state_dicts/qwen_vl_encoder_int8_convrot_keys.py
@@ -0,0 +1,85 @@
+"""Representative key layout of supermind's `int8_tensorwise` (+convrot) Qwen2.5-VL 7B encoder.
+
+Captured on 2026-11-06 with `scripts/capture_state_dict_fixture.py`,
+which reads the header only, from
+`https://huggingface.co/supermind/int8_convrot_models/resolve/main/text_encoders/qwen_2.5_vl_7b_int8_convrot.safetensors`.
+
+Subsetting rule: `model.layers` index 0, `visual.blocks` index 0, plus every key outside a stack. Values are `(shape, dtype)`.
+
+The legacy ComfyUI names (`model.layers.*`, `visual.*`), which only reach the module tree through
+`_remap_qwen_vl_checkpoint_keys`: the markers sit under the old names and have to follow it. The visual tower's
+`mlp.down_proj` is bf16 with no marker because its input width, 3420, is not a multiple of the 256-wide rotation
+group, so a rotated build has nothing to quantize there; the language model's projections are all int8."""
+
+state_dict_keys: dict[str, tuple[list[int], str]] = {
+ "lm_head.weight": ([152064, 3584], "BF16"),
+ "model.embed_tokens.weight": ([152064, 3584], "BF16"),
+ "model.layers.0.input_layernorm.weight": ([3584], "BF16"),
+ "model.layers.0.mlp.down_proj.comfy_quant": ([72], "U8"),
+ "model.layers.0.mlp.down_proj.weight": ([3584, 18944], "I8"),
+ "model.layers.0.mlp.down_proj.weight_scale": ([3584, 1], "F32"),
+ "model.layers.0.mlp.gate_proj.comfy_quant": ([72], "U8"),
+ "model.layers.0.mlp.gate_proj.weight": ([18944, 3584], "I8"),
+ "model.layers.0.mlp.gate_proj.weight_scale": ([18944, 1], "F32"),
+ "model.layers.0.mlp.up_proj.comfy_quant": ([72], "U8"),
+ "model.layers.0.mlp.up_proj.weight": ([18944, 3584], "I8"),
+ "model.layers.0.mlp.up_proj.weight_scale": ([18944, 1], "F32"),
+ "model.layers.0.post_attention_layernorm.weight": ([3584], "BF16"),
+ "model.layers.0.self_attn.k_proj.bias": ([512], "BF16"),
+ "model.layers.0.self_attn.k_proj.comfy_quant": ([72], "U8"),
+ "model.layers.0.self_attn.k_proj.weight": ([512, 3584], "I8"),
+ "model.layers.0.self_attn.k_proj.weight_scale": ([512, 1], "F32"),
+ "model.layers.0.self_attn.o_proj.comfy_quant": ([72], "U8"),
+ "model.layers.0.self_attn.o_proj.weight": ([3584, 3584], "I8"),
+ "model.layers.0.self_attn.o_proj.weight_scale": ([3584, 1], "F32"),
+ "model.layers.0.self_attn.q_proj.bias": ([3584], "BF16"),
+ "model.layers.0.self_attn.q_proj.comfy_quant": ([72], "U8"),
+ "model.layers.0.self_attn.q_proj.weight": ([3584, 3584], "I8"),
+ "model.layers.0.self_attn.q_proj.weight_scale": ([3584, 1], "F32"),
+ "model.layers.0.self_attn.v_proj.bias": ([512], "BF16"),
+ "model.layers.0.self_attn.v_proj.comfy_quant": ([72], "U8"),
+ "model.layers.0.self_attn.v_proj.weight": ([512, 3584], "I8"),
+ "model.layers.0.self_attn.v_proj.weight_scale": ([512, 1], "F32"),
+ "model.norm.weight": ([3584], "BF16"),
+ "visual.blocks.0.attn.proj.bias": ([1280], "BF16"),
+ "visual.blocks.0.attn.proj.comfy_quant": ([72], "U8"),
+ "visual.blocks.0.attn.proj.weight": ([1280, 1280], "I8"),
+ "visual.blocks.0.attn.proj.weight_scale": ([1280, 1], "F32"),
+ "visual.blocks.0.attn.qkv.bias": ([3840], "BF16"),
+ "visual.blocks.0.attn.qkv.comfy_quant": ([72], "U8"),
+ "visual.blocks.0.attn.qkv.weight": ([3840, 1280], "I8"),
+ "visual.blocks.0.attn.qkv.weight_scale": ([3840, 1], "F32"),
+ "visual.blocks.0.mlp.down_proj.bias": ([1280], "BF16"),
+ "visual.blocks.0.mlp.down_proj.weight": ([1280, 3420], "BF16"),
+ "visual.blocks.0.mlp.gate_proj.bias": ([3420], "BF16"),
+ "visual.blocks.0.mlp.gate_proj.comfy_quant": ([72], "U8"),
+ "visual.blocks.0.mlp.gate_proj.weight": ([3420, 1280], "I8"),
+ "visual.blocks.0.mlp.gate_proj.weight_scale": ([3420, 1], "F32"),
+ "visual.blocks.0.mlp.up_proj.bias": ([3420], "BF16"),
+ "visual.blocks.0.mlp.up_proj.comfy_quant": ([72], "U8"),
+ "visual.blocks.0.mlp.up_proj.weight": ([3420, 1280], "I8"),
+ "visual.blocks.0.mlp.up_proj.weight_scale": ([3420, 1], "F32"),
+ "visual.blocks.0.norm1.weight": ([1280], "BF16"),
+ "visual.blocks.0.norm2.weight": ([1280], "BF16"),
+ "visual.merger.ln_q.weight": ([1280], "BF16"),
+ "visual.merger.mlp.0.bias": ([5120], "BF16"),
+ "visual.merger.mlp.0.weight": ([5120, 5120], "BF16"),
+ "visual.merger.mlp.2.bias": ([3584], "BF16"),
+ "visual.merger.mlp.2.weight": ([3584, 5120], "BF16"),
+ "visual.patch_embed.proj.weight": ([1280, 3, 2, 14, 14], "BF16"),
+}
+
+# The per-layer `.comfy_quant` markers, decoded from the blobs themselves.
+markers: dict[str, dict[str, object]] = {
+ "model.layers.0.mlp.down_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "model.layers.0.mlp.gate_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "model.layers.0.mlp.up_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "model.layers.0.self_attn.k_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "model.layers.0.self_attn.o_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "model.layers.0.self_attn.q_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "model.layers.0.self_attn.v_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "visual.blocks.0.attn.proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "visual.blocks.0.attn.qkv": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "visual.blocks.0.mlp.gate_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+ "visual.blocks.0.mlp.up_proj": {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256},
+}
diff --git a/tests/backend/model_manager/load/test_moss_image_loader.py b/tests/backend/model_manager/load/test_moss_image_loader.py
index f7ebfced47..5c92986f1f 100644
--- a/tests/backend/model_manager/load/test_moss_image_loader.py
+++ b/tests/backend/model_manager/load/test_moss_image_loader.py
@@ -516,7 +516,9 @@ class TestFusedAndInt8Checkpoints:
path = tmp_path / "moss-int8-unmarked.safetensors"
save_file(stored, str(path))
- with pytest.raises(ValueError, match=r"no `comfy_quant` marker, e\.g\. \['layers\.0\.proj\.o\.weight'\]"):
+ with pytest.raises(
+ ValueError, match=r"no readable int8_tensorwise marker, e\.g\. \['layers\.0\.proj\.o\.weight'\]"
+ ):
self._load(monkeypatch, path)
def test_fp8_storage_leaves_the_int8_layers_alone_and_still_runs(
diff --git a/tests/backend/model_manager/load/test_qwen_image_int8_convrot_keys.py b/tests/backend/model_manager/load/test_qwen_image_int8_convrot_keys.py
new file mode 100644
index 0000000000..475df41087
--- /dev/null
+++ b/tests/backend/model_manager/load/test_qwen_image_int8_convrot_keys.py
@@ -0,0 +1,85 @@
+"""What the released `int8_tensorwise` Qwen-Image Edit 2511 transformer and Qwen2.5-VL encoder contain.
+
+The loader suites run on toy geometry, which says whether the loader handles the shape it was given and not whether
+the released file still has that shape. These cells read the captured layouts, hold them against the real module
+trees (built on the meta device, so no weights exist), and pin the properties the decode depends on.
+"""
+
+import accelerate
+import pytest
+import torch
+
+from invokeai.backend.model_manager.load.model_loaders.qwen_image import _remap_qwen_vl_checkpoint_keys
+from invokeai.backend.quantization.fp8_scaled import COMFY_QUANT_SUFFIX
+from invokeai.backend.quantization.int8_convrot import (
+ CONVROT_GROUP_SIZE,
+ INT8_TENSORWISE_FORMAT,
+)
+from invokeai.backend.qwen2_5_vl.qwen2_5_vl_assets import load_bundled_qwen2_5_vl_config_dict
+from tests.backend.model_manager.load.state_dicts import qwen_image_int8_convrot_keys as transformer_fixture
+from tests.backend.model_manager.load.state_dicts import qwen_vl_encoder_int8_convrot_keys as encoder_fixture
+
+ROTATED = {"format": INT8_TENSORWISE_FORMAT, "convrot": True, "convrot_groupsize": CONVROT_GROUP_SIZE}
+
+
+def _quantized(keys: dict) -> list[str]:
+ return sorted(key[: -len(".weight")] for key, (_shape, dtype) in keys.items() if dtype == "I8")
+
+
+def _transformer_module_shapes() -> dict[str, torch.Size]:
+ from diffusers import QwenImageTransformer2DModel
+
+ with accelerate.init_empty_weights():
+ model = QwenImageTransformer2DModel(num_layers=1)
+ return {name: module.weight.shape for name, module in model.named_modules() if isinstance(module, torch.nn.Linear)}
+
+
+def _encoder_module_shapes() -> dict[str, torch.Size]:
+ from transformers import Qwen2_5_VLConfig, Qwen2_5_VLForConditionalGeneration
+
+ with accelerate.init_empty_weights():
+ model = Qwen2_5_VLForConditionalGeneration(Qwen2_5_VLConfig.from_dict(load_bundled_qwen2_5_vl_config_dict()))
+ return {name: module.weight.shape for name, module in model.named_modules() if isinstance(module, torch.nn.Linear)}
+
+
+CASES = {
+ "transformer": (transformer_fixture, lambda path: path, _transformer_module_shapes),
+ # The encoder's layers are named in the legacy layout; the loader remaps them before the swap.
+ "encoder": (
+ encoder_fixture,
+ lambda path: next(iter(_remap_qwen_vl_checkpoint_keys({path: 0}))),
+ _encoder_module_shapes,
+ ),
+}
+
+
[email protected](params=sorted(CASES))
+def case(request):
+ fixture, rename, module_shapes = CASES[request.param]
+ return fixture, rename, module_shapes()
+
+
+def test_every_int8_layer_is_marked_rotated_and_scaled_per_output_channel(case) -> None:
+ fixture, _rename, _shapes = case
+ keys = fixture.state_dict_keys
+ quantized = _quantized(keys)
+
+ assert quantized
+ assert set(fixture.markers) == set(quantized)
+ assert all(marker == ROTATED for marker in fixture.markers.values())
+ assert {k[: -len(COMFY_QUANT_SUFFIX)] for k in keys if k.endswith(COMFY_QUANT_SUFFIX)} == set(quantized)
+ for path in quantized:
+ weight_shape, _ = keys[f"{path}.weight"]
+ scale_shape, scale_dtype = keys[f"{path}.weight_scale"]
+ # `[out, 1]` and not `[out]`: a flat scale would broadcast along the input axis of a square weight.
+ assert scale_shape == [weight_shape[0], 1] and scale_dtype == "F32", path
+ assert weight_shape[1] % CONVROT_GROUP_SIZE == 0, path
+
+
+def test_the_captured_layers_are_the_linears_the_real_model_has(case) -> None:
+ """A swap needs a `Linear` of the stored shape at the path the (remapped) checkpoint names."""
+ fixture, rename, linears = case
+ keys = fixture.state_dict_keys
+
+ for path in _quantized(keys):
+ assert linears[rename(path)] == torch.Size(keys[f"{path}.weight"][0]), path
diff --git a/tests/backend/model_manager/load/test_qwen_image_int8_convrot_loader.py b/tests/backend/model_manager/load/test_qwen_image_int8_convrot_loader.py
new file mode 100644
index 0000000000..ae7d41a9de
--- /dev/null
+++ b/tests/backend/model_manager/load/test_qwen_image_int8_convrot_loader.py
@@ -0,0 +1,332 @@
+"""`QwenImageCheckpointModel` keeps Comfy's `int8_tensorwise` builds int8, rotated or not.
+
+An int8 layer ships a `.weight_scale` exactly like a scaled fp8 layer, and the fp8 extraction pops every one of them,
+so the int8 layers have to be claimed first. What these tests pin is the decode (each layer reproduces the weight its
+codes and scale stand for, rotated and not), the single reservation before anything widens, and the refusals: a weight
+no marker explains, a file that also holds scaled fp8, and a layer the model needs dense.
+
+The geometry is the released module names at toy width, with a rotation group of 64 instead of 256.
+"""
+
+import json
+from types import SimpleNamespace
+
+import pytest
+import safetensors.torch
+import torch
+
+from invokeai.backend.model_manager.configs.main import Main_Checkpoint_QwenImage_Config
+from invokeai.backend.model_manager.load import load_default
+from invokeai.backend.model_manager.load.model_loaders import qwen_image
+from invokeai.backend.model_manager.load.model_loaders.qwen_image import QwenImageCheckpointModel
+from invokeai.backend.model_manager.taxonomy import SubModelType
+from invokeai.backend.quantization.int8_convrot import Int8ConvrotLinear
+from invokeai.backend.quantization.nvfp4 import NVFP4Linear
+from tests.fixtures.loader_seams import Seam, SeamRun, prepare
+from tests.fixtures.quantized_payloads import (
+ INT8_LEVELS,
+ comfy_quant_marker,
+ nvfp4_signed_tensors,
+ quantize_convrot,
+ quantize_scaled_fp8,
+)
+
+COMPUTE_DTYPE = torch.bfloat16
+GROUP = 64
+ROTATED = {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": GROUP}
+UNROTATED = {"format": "int8_tensorwise"}
+
+#: `<path>: (out, in)`. Every input width is a whole number of rotation groups.
+LAYERS = {
+ "transformer_blocks.0.attn.to_q": (128, 64),
+ "transformer_blocks.0.img_mlp.net.0.proj": (256, 64),
+ "transformer_blocks.0.txt_mlp.net.2": (128, 64),
+}
+
+
+class _TinyQwenImageTransformer(torch.nn.Module):
+ """The diffusers module names Comfy's Qwen-Image build uses, at toy width."""
+
+ _skip_layerwise_casting_patterns = ["pos_embed", "norm"]
+
+ def __init__(self, **_kwargs) -> None:
+ super().__init__()
+ block = torch.nn.Module()
+ block.attn = torch.nn.Module()
+ block.attn.to_q = torch.nn.Linear(64, 128)
+ block.img_mlp = torch.nn.Module()
+ block.img_mlp.net = torch.nn.ModuleList([torch.nn.Module()])
+ block.img_mlp.net[0].proj = torch.nn.Linear(64, 256)
+ block.txt_mlp = torch.nn.Module()
+ block.txt_mlp.net = torch.nn.ModuleList([torch.nn.Identity(), torch.nn.Identity(), torch.nn.Linear(64, 128)])
+ self.transformer_blocks = torch.nn.ModuleList([block])
+ self.img_in = torch.nn.Linear(64, 128)
+ self.norm_out = torch.nn.Module()
+ self.norm_out.linear = torch.nn.Linear(64, 128)
+
+
+def _unrotated(weight: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
+ """As the unrotated builds store it: one 0-dim scale for the whole tensor. Returns codes, scale, round trip."""
+ scale = (weight.abs().max() / INT8_LEVELS).to(torch.float32)
+ codes = torch.clamp(torch.round(weight / scale), -128, 127).to(torch.int8)
+ return codes, scale, codes.float() * scale
+
+
+def _state_dict(rotated: bool = True, marked: bool = True) -> tuple[dict[str, torch.Tensor], dict[str, torch.Tensor]]:
+ """A checkpoint with every `LAYERS` entry int8, and the weight each must decode to."""
+ torch.manual_seed(0)
+ state_dict: dict[str, torch.Tensor] = {}
+ expected: dict[str, torch.Tensor] = {}
+ for path, shape in LAYERS.items():
+ weight = torch.randn(shape)
+ if rotated:
+ payload = quantize_convrot(weight, group_size=GROUP)
+ codes, scale, expected[path] = payload.codes, payload.scale, payload.dequantized
+ else:
+ codes, scale, expected[path] = _unrotated(weight)
+ state_dict[f"{path}.weight"] = codes
+ state_dict[f"{path}.weight_scale"] = scale
+ state_dict[f"{path}.bias"] = torch.randn(shape[0])
+ if not rotated:
+ # The unrotated builds ship an activation scale beside each layer, which has nothing to attach to.
+ state_dict[f"{path}.input_scale"] = torch.tensor(1.0)
+ if marked:
+ state_dict[f"{path}.comfy_quant"] = comfy_quant_marker(ROTATED if rotated else UNROTATED)
+ state_dict["img_in.weight"] = torch.randn(128, 64)
+ state_dict["img_in.bias"] = torch.randn(128)
+ state_dict["norm_out.linear.weight"] = torch.randn(128, 64)
+ state_dict["norm_out.linear.bias"] = torch.randn(128)
+ # Edit 2511 carries this: dotless, no elements, and no module to land in.
+ state_dict["__index_timestep_zero__"] = torch.zeros(0)
+ return state_dict, expected
+
+
+SEAM = Seam(
+ loader=QwenImageCheckpointModel,
+ module=qwen_image,
+ entry="_load_from_singlefile",
+ load_file_host=safetensors.torch,
+ compute_dtype=COMPUTE_DTYPE,
+ patches_device=True,
+ # `_torch_dtype` is read nowhere in `qwen_image`; the storage cast is driven through `_load_model` below.
+ sets_torch_dtype=False,
+ casts_fp8_storage=False,
+)
+
+
+def _run(
+ monkeypatch: pytest.MonkeyPatch,
+ tmp_path,
+ state_dict: dict,
+ *,
+ header: dict | None = None,
+ fp8_storage: bool = False,
+) -> tuple[SeamRun, Main_Checkpoint_QwenImage_Config]:
+ import diffusers
+
+ checkpoint = tmp_path / "qwen_image_edit_2511_int8_convrot.safetensors"
+ checkpoint.touch()
+ config = Main_Checkpoint_QwenImage_Config.model_construct(
+ path=str(checkpoint), name="qwen_image_int8", default_settings=SimpleNamespace(fp8_storage=fp8_storage)
+ )
+ metadata = None if header is None else {"_quantization_metadata": json.dumps({"layers": header})}
+ run = prepare(
+ SEAM,
+ monkeypatch,
+ state_dict=state_dict,
+ metadata=metadata,
+ geometry=lambda patch: patch.setattr(
+ diffusers, "QwenImageTransformer2DModel", _TinyQwenImageTransformer, raising=False
+ ),
+ )
+ return run, config
+
+
+def _load(monkeypatch, tmp_path, state_dict, **kwargs):
+ run, config = _run(monkeypatch, tmp_path, state_dict, **kwargs)
+ return run.load(config), run
+
+
+def _assert_decodes(model: torch.nn.Module, expected: dict[str, torch.Tensor], source: dict) -> None:
+ """Each layer reproduces `expected`; its bias is the source tensor's, rounded to the compute dtype by the load."""
+ for path, weight in expected.items():
+ layer = model.get_submodule(path)
+ assert isinstance(layer, Int8ConvrotLinear), path
+ assert layer.weight.dtype is torch.int8, path
+ assert layer.weight_scale.dtype is torch.float32, path
+ # A float32 activation, not the compute dtype: torch's CPU bf16 GEMM faults on part of the windows runner fleet.
+ x = torch.randn(3, layer.in_features)
+ bias = source[f"{path}.bias"].to(COMPUTE_DTYPE).float()
+ torch.testing.assert_close(layer(x), torch.nn.functional.linear(x, weight, bias), rtol=1e-4, atol=1e-4)
+
+
[email protected]("rotated", [True, False], ids=["rotated_column_scale", "unrotated_scalar_scale"])
+def test_the_released_builds_decode_to_the_weights_their_codes_stand_for(monkeypatch, tmp_path, rotated) -> None:
+ """The scale is `[out, 1]` in a rotated build and 0-dim in an unrotated one, and the rotated one also has to be
+ un-rotated. The expected weights come from the payload builders, not from the loader's own decode."""
+ state_dict, expected = _state_dict(rotated=rotated)
+
+ model, _ = _load(monkeypatch, tmp_path, state_dict)
+
+ _assert_decodes(model, expected, state_dict)
+ assert all(model.get_submodule(path).convrot is rotated for path in expected)
+ assert not isinstance(model.img_in, Int8ConvrotLinear)
+ assert model.img_in.weight.dtype is COMPUTE_DTYPE
+
+
[email protected]("rotated", [True, False], ids=["rotated", "unrotated"])
+def test_a_build_that_names_its_layers_only_in_the_header_loads(monkeypatch, tmp_path, rotated) -> None:
+ """The header has to say whether the codes were rotated; an entry without `convrot` is refused as ambiguous."""
+ state_dict, expected = _state_dict(rotated=rotated, marked=False)
+ header = {path: dict(ROTATED if rotated else {**UNROTATED, "convrot": False}) for path in LAYERS}
+
+ model, _ = _load(monkeypatch, tmp_path, state_dict, header=header)
+
+ _assert_decodes(model, expected, state_dict)
+ assert all(model.get_submodule(path).convrot is rotated for path in expected)
+
+
+def test_a_header_entry_that_does_not_say_whether_the_weight_was_rotated_is_refused(monkeypatch, tmp_path) -> None:
+ state_dict, _ = _state_dict(marked=False)
+ run, config = _run(monkeypatch, tmp_path, state_dict, header={path: dict(UNROTATED) for path in LAYERS})
+
+ with pytest.raises(ValueError, match="does not say whether the weight was rotated"):
+ run.load(config)
+
+ assert run.reserved == []
+
+
[email protected]("rotated", [True, False], ids=["rotated", "unrotated"])
+def test_the_reservation_is_one_call_made_before_the_split_and_the_cast_widen_anything(
+ monkeypatch, tmp_path, rotated
+) -> None:
+ from invokeai.backend.quantization import int8_convrot
+
+ state_dict, _ = _state_dict(rotated=rotated)
+ run, config = _run(monkeypatch, tmp_path, state_dict)
+ widening_steps: list[tuple[str, int]] = []
+ for name in ("split_int8_convrot_layers", "cast_unquantized"):
+
+ def step(*args, _name=name, _original=getattr(int8_convrot, name), **kwargs):
+ widening_steps.append((_name, len(run.reserved)))
+ return _original(*args, **kwargs)
+
+ monkeypatch.setattr(int8_convrot, name, step)
+
+ run.load(config)
+
+ # Counted by hand: the int8 weights as stored (one byte); the fp32 scales, `[out, 1]` or one scalar per layer; and
+ # the dense remainder at the compute width (the biases, `img_in` and `norm_out.linear`). The markers, the
+ # activation scales and the zero-element key are dropped and cost nothing.
+ int8 = sum(out * inp for out, inp in LAYERS.values())
+ scales = (sum(out for out, _ in LAYERS.values()) if rotated else len(LAYERS)) * 4
+ biases = sum(out for out, _ in LAYERS.values())
+ dense = biases + (128 * 64 + 128) + (128 * 64 + 128)
+ assert run.reserved == [int8 + scales + dense * COMPUTE_DTYPE.itemsize]
+ assert widening_steps == [("split_int8_convrot_layers", 1), ("cast_unquantized", 1)]
+
+
+def test_fp8_storage_leaves_the_int8_layers_int8(monkeypatch, tmp_path) -> None:
+ """The model-level storage cast walks the dense remainder; the int8 buffers are not layers it casts."""
+ state_dict, expected = _state_dict()
+ run, config = _run(monkeypatch, tmp_path, state_dict, fp8_storage=True)
+ monkeypatch.setattr(load_default, "_device_supports_fp8_storage", lambda *_args: True)
+ run.loader._torch_dtype = COMPUTE_DTYPE
+
+ model = run.loader._load_model(config, SubModelType.Transformer)
+
+ for path in expected:
+ layer = model.get_submodule(path)
+ assert isinstance(layer, Int8ConvrotLinear), path
+ assert layer.weight.dtype is torch.int8, path
+ assert layer.weight_scale.dtype is torch.float32, path
+ assert model.img_in.weight.dtype is torch.float8_e4m3fn
+
+
+def test_a_marked_layer_the_model_needs_dense_is_widened_with_its_scale_applied(monkeypatch, tmp_path) -> None:
+ """`norm_out.linear` matches the model's own "norm" skip pattern. A repack that quantizes it must still come
+ back dense and correct, rather than as codes cast without their scale."""
+ state_dict, expected = _state_dict()
+ payload = quantize_convrot(torch.randn(128, 64), group_size=GROUP)
+ state_dict["norm_out.linear.weight"] = payload.codes
+ state_dict["norm_out.linear.weight_scale"] = payload.scale
+ state_dict["norm_out.linear.comfy_quant"] = comfy_quant_marker(ROTATED)
+
+ model, _ = _load(monkeypatch, tmp_path, state_dict)
+
+ widened = model.norm_out.linear
+ assert not isinstance(widened, Int8ConvrotLinear)
+ assert widened.weight.dtype is COMPUTE_DTYPE
+ torch.testing.assert_close(widened.weight.float(), payload.dequantized, rtol=0.02, atol=0.02)
+ _assert_decodes(model, expected, state_dict)
+
+
+def test_an_int8_weight_without_a_marker_is_refused_before_the_cache_is_evicted(monkeypatch, tmp_path) -> None:
+ state_dict, _ = _state_dict(marked=False)
+ run, config = _run(monkeypatch, tmp_path, state_dict)
+
+ with pytest.raises(ValueError, match="no readable int8_tensorwise marker"):
+ run.load(config)
+
+ assert run.reserved == []
+
+
+def test_a_marker_without_a_format_is_refused(monkeypatch, tmp_path) -> None:
+ """Files marked only `{"convrot": true}` say nothing about how their codes are scaled."""
+ state_dict, _ = _state_dict()
+ for path in LAYERS:
+ state_dict[f"{path}.comfy_quant"] = comfy_quant_marker({"convrot": True})
+ run, config = _run(monkeypatch, tmp_path, state_dict)
+
+ with pytest.raises(ValueError, match=r"int8 weight\(s\) with no readable int8_tensorwise marker"):
+ run.load(config)
+
+ assert run.reserved == []
+
+
+def test_a_file_mixing_int8_with_scaled_fp8_is_refused(monkeypatch, tmp_path) -> None:
+ """Inside the int8 branch the fp8 pipeline is skipped, so an fp8 layer would be cast without its scale."""
+ state_dict, _ = _state_dict()
+ payload = quantize_scaled_fp8(torch.randn(128, 64))
+ state_dict["img_in.weight"] = payload.codes
+ state_dict["img_in.weight_scale"] = payload.scale
+
+ with pytest.raises(ValueError, match="float8 weight scale"):
+ _load(monkeypatch, tmp_path, state_dict)
+
+
+def test_a_layer_whose_tensors_are_missing_is_refused(monkeypatch, tmp_path) -> None:
+ """The load tolerates missing keys; a dense layer lost from an int8 file must not survive as a meta tensor."""
+ state_dict, _ = _state_dict()
+ del state_dict["img_in.weight"]
+
+ with pytest.raises(RuntimeError, match="meta"):
+ _load(monkeypatch, tmp_path, state_dict)
+
+
+def test_int8_and_nvfp4_layers_in_one_file_both_load_and_one_reservation_covers_both(monkeypatch, tmp_path) -> None:
+ state_dict, expected = _state_dict()
+ nvfp4_path = "transformer_blocks.0.attn.to_q"
+ for suffix in ("weight", "weight_scale"):
+ del state_dict[f"{nvfp4_path}.{suffix}"]
+ del state_dict[f"{nvfp4_path}.comfy_quant"]
+ packed, weight = nvfp4_signed_tensors(nvfp4_path, torch.randint(0, 2, (128, 64), dtype=torch.bool))
+ state_dict.update(packed)
+ del expected[nvfp4_path]
+ run, config = _run(monkeypatch, tmp_path, state_dict, header={nvfp4_path: {"format": "nvfp4"}})
+
+ model = run.load(config)
+
+ _assert_decodes(model, expected, state_dict)
+ layer = model.get_submodule(nvfp4_path)
+ assert isinstance(layer, NVFP4Linear)
+ x = torch.randn(3, 64)
+ torch.testing.assert_close(
+ layer(x), torch.nn.functional.linear(x, weight, state_dict[f"{nvfp4_path}.bias"].to(COMPUTE_DTYPE).float())
+ )
+ # The packed layer as stored (codes, block-scale grid, global scale), beside what the int8 case counts without it.
+ packed_bytes = 128 * 64 // 2 + 128 * (64 // 16) + 4
+ int8 = sum(out * inp for path, (out, inp) in LAYERS.items() if path != nvfp4_path)
+ scales = sum(out for path, (out, _) in LAYERS.items() if path != nvfp4_path) * 4
+ dense = sum(out for out, _ in LAYERS.values()) + 2 * (128 * 64 + 128)
+ assert run.reserved == [packed_bytes + int8 + scales + dense * COMPUTE_DTYPE.itemsize]
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 4dde6e2f88..513f907039 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
@@ -8,6 +8,7 @@ are folded unless fp8 compute or the model's fp8 storage setting keeps them; the
dtype is bf16, as in production: the packed global scale must not be cast.
"""
+import dataclasses
import json
from types import SimpleNamespace
from unittest.mock import MagicMock
@@ -26,6 +27,7 @@ from invokeai.backend.model_manager.load.model_loaders.qwen_image import (
QwenImageCheckpointModel,
QwenVLEncoderCheckpointLoader,
)
+from invokeai.backend.quantization.int8_convrot import Int8ConvrotLinear
from invokeai.backend.quantization.nvfp4 import NVFP4Linear
from tests.fixtures.loader_seams import Seam, prepare
from tests.fixtures.quantized_payloads import comfy_quant_marker, nvfp4_signed_tensors, quantize_convrot
@@ -293,29 +295,191 @@ def test_the_encoder_keeps_marker_named_nvfp4_layers_packed_under_their_transfor
loader._ram_cache.make_room.assert_called_once_with(packed + widened * COMPUTE_DTYPE.itemsize + fp8_marker.numel())
-def test_an_int8_convrot_checkpoint_is_refused_before_the_cache_is_evicted(monkeypatch, tmp_path) -> None:
- """This encoder has no int8 branch, and `int8_tensorwise` shares the fp8 key layout, so the fold
- applied the scale and skipped the inverse rotation.
+#: The shared encoder seam computes in float32; the int8 cells need bf16, since a blanket cast to it is what would ruin
+#: the float32 scales.
+BF16_ENCODER_SEAM = dataclasses.replace(ENCODER_SEAM, compute_dtype=COMPUTE_DTYPE)
- The refusal has to come before `make_room`, thirty lines further down, and before the config
- fetch between them: reserving room for a load that cannot finish evicts whatever else the user
- had resident, and the fetch reaches for the network to do it. That
- ordering is the half that went missing once already -- the guard was reported as moved ahead of
- the reservation while the call was not in the tree at all, and nothing here would have noticed.
- """
- payload = quantize_convrot(torch.randn(64, 256), group_size=64)
- state_dict = {
- "model.layers.0.self_attn.q_proj.weight": payload.codes,
- "model.layers.0.self_attn.q_proj.weight_scale": payload.scale,
- "model.layers.0.self_attn.q_proj.comfy_quant": comfy_quant_marker(
- {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 64}
- ),
+
+def _expected_bias(source: dict[str, torch.Tensor], layer: Int8ConvrotLinear) -> torch.Tensor | None:
+ """The bias the source file holds, rounded to the compute dtype by the load. Only `q_proj` has one in the toy."""
+ bias = source.get("model.layers.0.self_attn.q_proj.bias")
+ return bias.to(COMPUTE_DTYPE).float() if layer.bias is not None else None
+
+
+def _tiny_encoder(monkeypatch: pytest.MonkeyPatch):
+ """Stand in for the 7B module tree: the vendored config is real, the model class is `_TinyQwenVL`."""
+ import transformers
+
+ monkeypatch.setattr(transformers, "Qwen2_5_VLForConditionalGeneration", _TinyQwenVL, raising=False)
+
+
+def _int8_encoder_state_dict(
+ rotated: bool, marked: bool = True
+) -> tuple[dict[str, torch.Tensor], dict[str, torch.Tensor]]:
+ """The two language-model projections int8, with the activation scale an unrotated build adds; and what each
+ must decode to, keyed by the path the module tree gives it."""
+ torch.manual_seed(2)
+ state_dict: dict[str, torch.Tensor] = {}
+ expected: dict[str, torch.Tensor] = {}
+ for legacy, shape in (("model.layers.0.self_attn.q_proj", (128, 64)), ("model.layers.0.mlp.down_proj", (128, 64))):
+ weight = torch.randn(shape)
+ if rotated:
+ payload = quantize_convrot(weight, group_size=64)
+ codes, scale, round_trip = payload.codes, payload.scale, payload.dequantized
+ marker = {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 64}
+ else:
+ scale = (weight.abs().max() / 127.0).to(torch.float32)
+ codes = torch.clamp(torch.round(weight / scale), -128, 127).to(torch.int8)
+ round_trip = codes.float() * scale
+ marker = {"format": "int8_tensorwise"}
+ state_dict[f"{legacy}.input_scale"] = torch.tensor(1.0)
+ state_dict[f"{legacy}.weight"] = codes
+ state_dict[f"{legacy}.weight_scale"] = scale
+ if marked:
+ state_dict[f"{legacy}.comfy_quant"] = comfy_quant_marker(marker)
+ expected[legacy.replace("model.", "model.language_model.", 1)] = round_trip
+ state_dict["model.layers.0.self_attn.q_proj.bias"] = torch.randn(128)
+ state_dict["lm_head.weight"] = torch.randn(32, 64)
+ state_dict["visual.proj.weight"] = torch.randn(4, 8)
+ state_dict["visual.proj.bias"] = torch.randn(4)
+ return state_dict, expected
+
+
[email protected]("rotated", [True, False], ids=["rotated_column_scale", "unrotated_scalar_scale"])
+def test_the_encoder_keeps_int8_layers_int8_under_their_transformers_paths(monkeypatch, tmp_path, rotated) -> None:
+ """The fold the encoder runs for fp8 would multiply the scale in and skip the inverse rotation, so the int8 layers
+ are claimed first. Their markers sit under the legacy names and follow the remap with their weights."""
+ state_dict, expected = _int8_encoder_state_dict(rotated)
+ checkpoint = tmp_path / "qwen_2.5_vl_7b_int8.safetensors"
+ checkpoint.touch()
+ run = prepare(BF16_ENCODER_SEAM, monkeypatch, state_dict=state_dict, metadata=None, geometry=_tiny_encoder)
+
+ model = run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))
+
+ for path, weight in expected.items():
+ layer = model.get_submodule(path)
+ assert isinstance(layer, Int8ConvrotLinear), path
+ assert layer.convrot is rotated, path
+ assert layer.weight.dtype is torch.int8, path
+ # The blanket cast to the compute dtype must not reach the scale.
+ assert layer.weight_scale.dtype is torch.float32, path
+ # A float32 activation: torch's CPU bf16 GEMM faults on part of the windows runner fleet.
+ x = torch.randn(3, 64)
+ bias = _expected_bias(state_dict, layer)
+ torch.testing.assert_close(layer(x), torch.nn.functional.linear(x, weight, bias), rtol=1e-4, atol=1e-4)
+ # The W8A8 activation scale has nothing to attach to.
+ assert not hasattr(layer, "input_scale")
+ assert model.lm_head.weight.dtype is COMPUTE_DTYPE
+ assert model.model.visual.proj.weight.dtype is COMPUTE_DTYPE
+ # Counted by hand: the int8 weights as stored, their fp32 scales, and the bias, `lm_head` and vision projection at
+ # bf16. Markers and activation scales are dropped and cost nothing.
+ int8 = 2 * 128 * 64
+ scales = (2 * 128 * 4) if rotated else 2 * 4
+ dense = 128 + 32 * 64 + (4 * 8 + 4)
+ assert run.reserved == [int8 + scales + dense * COMPUTE_DTYPE.itemsize]
+
+
[email protected]("rotated", [True, False], ids=["rotated", "unrotated"])
+def test_an_encoder_build_that_names_its_layers_only_in_the_header_loads_under_the_remapped_paths(
+ monkeypatch, tmp_path, rotated
+) -> None:
+ """The header names the layers in the legacy layout, like the keys; the markers made from it follow the remap."""
+ state_dict, expected = _int8_encoder_state_dict(rotated, marked=False)
+ legacy = ("model.layers.0.self_attn.q_proj", "model.layers.0.mlp.down_proj")
+ entry = {"format": "int8_tensorwise", "convrot": rotated, **({"convrot_groupsize": 64} if rotated else {})}
+ metadata = {"_quantization_metadata": json.dumps({"layers": dict.fromkeys(legacy, entry)})}
+ checkpoint = tmp_path / "qwen_2.5_vl_7b_int8_header.safetensors"
+ checkpoint.touch()
+ run = prepare(BF16_ENCODER_SEAM, monkeypatch, state_dict=state_dict, metadata=metadata, geometry=_tiny_encoder)
+
+ model = run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))
+
+ for path, weight in expected.items():
+ layer = model.get_submodule(path)
+ assert isinstance(layer, Int8ConvrotLinear), path
+ assert layer.convrot is rotated, path
+ x = torch.randn(3, 64)
+ torch.testing.assert_close(
+ layer(x), torch.nn.functional.linear(x, weight, _expected_bias(state_dict, layer)), rtol=1e-4, atol=1e-4
+ )
+
+
+def test_an_encoder_header_entry_that_does_not_say_whether_the_weight_was_rotated_is_refused(
+ monkeypatch, tmp_path
+) -> None:
+ state_dict, _ = _int8_encoder_state_dict(rotated=True, marked=False)
+ layers = {
+ path: {"format": "int8_tensorwise"}
+ for path in ("model.layers.0.self_attn.q_proj", "model.layers.0.mlp.down_proj")
}
+ checkpoint = tmp_path / "qwen_2.5_vl_7b_int8_ambiguous.safetensors"
+ checkpoint.touch()
+ run = prepare(
+ BF16_ENCODER_SEAM,
+ monkeypatch,
+ state_dict=state_dict,
+ metadata={"_quantization_metadata": json.dumps({"layers": layers})},
+ )
+
+ with pytest.raises(ValueError, match="does not say whether the weight was rotated"):
+ run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))
+
+ assert run.reserved == []
+
+
+def test_an_encoder_file_mixing_int8_and_nvfp4_layers_loads_both_under_one_reservation(monkeypatch, tmp_path) -> None:
+ state_dict, expected = _int8_encoder_state_dict(rotated=True)
+ nvfp4_legacy = "model.layers.0.mlp.down_proj"
+ for suffix in ("weight", "weight_scale", "comfy_quant"):
+ del state_dict[f"{nvfp4_legacy}.{suffix}"]
+ del expected["model.language_model.layers.0.mlp.down_proj"]
+ tensors, nvfp4_weight = _nvfp4_tensors(nvfp4_legacy, (128, 64))
+ state_dict.update(tensors)
+ state_dict[f"{nvfp4_legacy}.comfy_quant"] = _marker("nvfp4")
+ checkpoint = tmp_path / "qwen_2.5_vl_7b_int8_nvfp4.safetensors"
+ checkpoint.touch()
+ run = prepare(BF16_ENCODER_SEAM, monkeypatch, state_dict=state_dict, metadata=None, geometry=_tiny_encoder)
+
+ model = run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))
+
+ q_proj = model.get_submodule("model.language_model.layers.0.self_attn.q_proj")
+ assert isinstance(q_proj, Int8ConvrotLinear)
+ packed = model.get_submodule("model.language_model.layers.0.mlp.down_proj")
+ assert isinstance(packed, NVFP4Linear)
+ x = torch.randn(3, 64)
+ torch.testing.assert_close(packed(x), torch.nn.functional.linear(x, nvfp4_weight))
+ # The int8 q_proj with its fp32 scale, the packed layer as stored, and the dense bias, `lm_head` and vision
+ # projection at bf16: one call that covers both schemes.
+ dense = 128 + 32 * 64 + (4 * 8 + 4)
+ assert run.reserved == [128 * 64 + 128 * 4 + _packed_bytes(128, 64) + dense * COMPUTE_DTYPE.itemsize]
+
+
+def test_an_encoder_int8_weight_without_a_marker_is_refused_before_the_cache_is_evicted(monkeypatch, tmp_path) -> None:
+ """Nothing says whether the codes were rotated, and cast as raw integers they generate noise. The refusal has to
+ come before `make_room`, and before the config fetch between them: reserving room for a load that cannot finish
+ evicts whatever else the user had resident."""
+ state_dict, _ = _int8_encoder_state_dict(rotated=True)
+ del state_dict["model.layers.0.mlp.down_proj.comfy_quant"]
checkpoint = tmp_path / "qwen_2.5_vl_7b_int8_convrot.safetensors"
checkpoint.touch()
run = prepare(ENCODER_SEAM, monkeypatch, state_dict=state_dict, metadata=None)
- with pytest.raises(ValueError, match="quantized with convrot"):
+ with pytest.raises(ValueError, match="no readable int8_tensorwise marker"):
+ run.load(QwenVLEncoder_Checkpoint_Config.model_construct(path=str(checkpoint)))
+
+ assert run.reserved == []
+
+
+def test_an_encoder_marked_only_convrot_is_refused(monkeypatch, tmp_path) -> None:
+ """A marker without a format names no scheme; the folds that used to take it would have rotated nothing."""
+ state_dict, _ = _int8_encoder_state_dict(rotated=True)
+ for legacy in ("model.layers.0.self_attn.q_proj", "model.layers.0.mlp.down_proj"):
+ state_dict[f"{legacy}.comfy_quant"] = comfy_quant_marker({"convrot": True})
+ checkpoint = tmp_path / "qwen_2.5_vl_7b_convrot_only.safetensors"
+ checkpoint.touch()
+ run = prepare(ENCODER_SEAM, monkeypatch, state_dict=state_dict, metadata=None)
+
+ with pytest.raises(ValueError, match=r"int8 weight\(s\) with no readable int8_tensorwise marker"):
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.py
index 2de7454d84..89285dd303 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
@@ -170,7 +170,7 @@ def test_an_int8_weight_without_a_per_tensor_marker_is_refused(monkeypatch, tmp_
},
)
- with pytest.raises(ValueError, match=r"int8 weight\(s\) with no `comfy_quant` marker"):
+ with pytest.raises(ValueError, match=r"int8 weight\(s\) with no readable int8_tensorwise marker"):
run.load(config)
diff --git a/tests/backend/pid/test_pid_int8.py b/tests/backend/pid/test_pid_int8.py
index badfbb60b6..45d5098689 100644
--- a/tests/backend/pid/test_pid_int8.py
+++ b/tests/backend/pid/test_pid_int8.py
@@ -173,7 +173,7 @@ def test_an_int8_weight_no_marker_claims_is_refused(monkeypatch: pytest.MonkeyPa
state_dict = {k: v for k, v in state_dict.items() if not k.endswith((".comfy_quant", ".weight_scale"))}
monkeypatch.setattr(pid_decode_module, "build_pid_net", lambda backbone, version: _tiny_net())
- with pytest.raises(ValueError, match="no `comfy_quant` marker"):
+ with pytest.raises(ValueError, match="no readable int8_tensorwise marker"):
load_pid_decoder(state_dict, BaseModelType.Flux)
diff --git a/tests/backend/qwen3_5/test_qwen3_5_loading.py b/tests/backend/qwen3_5/test_qwen3_5_loading.py
index 2ae0901f01..86994c8a19 100644
--- a/tests/backend/qwen3_5/test_qwen3_5_loading.py
+++ b/tests/backend/qwen3_5/test_qwen3_5_loading.py
@@ -320,7 +320,7 @@ def test_an_int8_layer_without_an_int8_tensorwise_marker_is_refused(tmp_path: Pa
path = tmp_path / "qwen3.5_9b_int8_convrot.safetensors"
save_file(file, path)
- with pytest.raises(ValueError, match="no `comfy_quant` marker"):
+ with pytest.raises(ValueError, match="no readable int8_tensorwise marker"):
load_qwen3_5_text_encoder(loader, [path], _config(), final_norm=True, keep_fp8=False, what="test")
loader._ram_cache.make_room.assert_not_called()