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.

fix(model-manager): refuse unsupported FLUX NVFP4 checkpoints (#10409)

Nianze Wuf97d7470bfb2
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 1e53b56db0..bf7a5d588c 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
@@ -49,7 +49,7 @@ InvokeAI recognizes the format from the file's contents, so you install them lik
- **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, Qwen-Image-2.1, Ideogram 4, MiniMax H3, LTX-2, Wan 2.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.
+- **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. InvokeAI refuses FLUX.1, FLUX.2, Ideogram 4 and Qwen-Image-2.1 nvfp4 transformer checkpoints at install.
- **fp8** (plain or `fp8_scaled`): a transformer keeps its weights in fp8 when [FP8 Storage](/configuration/optimization/fp8-storage/) is on, which installation does for you, or when `fp8_compute` is enabled. The single-file T5, Qwen3, Qwen3-VL, Qwen2.5-VL and FLUX.2 Mistral text encoders have neither setting: they keep their fp8 layers on their own on a GPU that can store fp8, and are widened elsewhere.
- **MXFP8** (fp8 with one scale per block of 32 weights): loaded by unpacking to BF16. Turn FP8 Storage off for these, except on Wan 2.2; see the [FP8 Storage caution](/configuration/optimization/fp8-storage/).
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 1d722ab3c3..cb785dfcff 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
@@ -36,8 +36,8 @@ reader's error; if the file is incomplete or corrupt, download it again.
|---|---|---|---|---|---|---|---|---|---|---|
| [SD 1.x / 2.x](/users-guide/models/local-models/stable-diffusion-1-2/), [SDXL](/users-guide/models/local-models/sdxl/) | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | R | ✗ | ✗ |
| [SD 3](/users-guide/models/local-models/sd-3/) | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ (transformer only: T5, CLIP-L, CLIP-G and VAE installed separately) | ✗ | ✗ |
-| [FLUX.1](/users-guide/models/local-models/flux-1/) | ✓ | ✓ | ✓ | ✓ | L | ✗ | ✓ | ✓ | ✓ | ✓ |
-| [FLUX.2](/users-guide/models/local-models/flux-2/) | ✓ | ✓ | ✓ | ✓ | L | ✗ | ✓ | ✓ | ✓ | inside the Diffusers folder (FLUX.2 [dev]) |
+| [FLUX.1](/users-guide/models/local-models/flux-1/) | ✓ | ✓ | ✓ | ✓ | L | R | ✓ | ✓ | ✓ | ✓ |
+| [FLUX.2](/users-guide/models/local-models/flux-2/) | ✓ | ✓ | ✓ | ✓ | L | R | ✓ | ✓ | ✓ | inside the Diffusers folder (FLUX.2 [dev]) |
| [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 | ✓ | ✓ | ✓ | ✓ | ✗ |
diff --git a/invokeai/backend/model_manager/configs/main.py b/invokeai/backend/model_manager/configs/main.py
index a66f8d0aa7..3d65175b9a 100644
--- a/invokeai/backend/model_manager/configs/main.py
+++ b/invokeai/backend/model_manager/configs/main.py
@@ -93,6 +93,7 @@ from invokeai.backend.quantization.int8_convrot import (
int8_weights_without_a_decodable_marker,
read_comfy_quant_markers,
)
+from invokeai.backend.quantization.nvfp4 import WEIGHT_SCALE_2_SUFFIX
from invokeai.backend.quantization.sdnq.detection import is_sdnq_folder
from invokeai.backend.quantization.sdnq.sdnq_tensor import SDNQTensor
from invokeai.backend.sd3.checkpoint_layout import is_sd3_mmdit, sd3_transformer_config
@@ -639,6 +640,30 @@ def _get_flux_variant(state_dict: dict[str | int, Any]) -> FluxVariantType | Non
return FluxVariantType.Schnell
+def _raise_for_flux_nvfp4_transformer(state_dict: dict[str | int, Any]) -> None:
+ prefix = CheckpointPrefix.detect(state_dict).prefix
+ # Bundled encoders and VAEs sit outside the wrapped transformer or have their own namespaces.
+ sidecar_prefixes = (
+ "text_encoders.",
+ "text_encoder.",
+ "text_encoder_2.",
+ "cond_stage_model.",
+ "first_stage_model.",
+ "vae.",
+ )
+ if any(
+ isinstance(key, str)
+ and key.endswith(WEIGHT_SCALE_2_SUFFIX)
+ and key.startswith(prefix)
+ and not key.startswith(sidecar_prefixes)
+ for key in state_dict
+ ):
+ raise InvalidMatchError(
+ "FLUX transformer checkpoints with NVFP4 are not supported. "
+ "Choose a supported FLUX.1 or FLUX.2 checkpoint from the Model Manager."
+ )
+
+
class Main_Checkpoint_FLUX_Config(Checkpoint_Config_Base, Main_Config_Base, Config_Base):
"""Model config for main checkpoint models."""
@@ -661,6 +686,8 @@ class Main_Checkpoint_FLUX_Config(Checkpoint_Config_Base, Main_Config_Base, Conf
cls._validate_does_not_look_like_gguf_quantized(mod)
+ _raise_for_flux_nvfp4_transformer(mod.load_state_dict())
+
variant = override_fields.pop("variant", None) or cls._get_variant_or_raise(mod)
return cls(**override_fields, variant=variant)
@@ -739,6 +766,8 @@ class Main_Checkpoint_Flux2_Config(Checkpoint_Config_Base, Main_Config_Base, Con
cls._validate_does_not_look_like_gguf_quantized(mod)
+ _raise_for_flux_nvfp4_transformer(mod.load_state_dict())
+
variant = override_fields.pop("variant", None) or cls._get_variant_or_raise(mod)
return cls(**override_fields, variant=variant)
diff --git a/tests/backend/model_manager/configs/test_flux_nvfp4_identification.py b/tests/backend/model_manager/configs/test_flux_nvfp4_identification.py
new file mode 100644
index 0000000000..46667b4e9b
--- /dev/null
+++ b/tests/backend/model_manager/configs/test_flux_nvfp4_identification.py
@@ -0,0 +1,145 @@
+"""Probe FLUX checkpoints through the real safetensors and config factory paths."""
+
+import json
+from pathlib import Path
+
+import pytest
+import torch
+from safetensors.torch import save_file
+
+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_Flux2_Config, Main_Checkpoint_FLUX_Config
+from invokeai.backend.model_manager.taxonomy import Flux2VariantType, FluxVariantType
+
+_FAMILIES = [
+ pytest.param(Main_Checkpoint_FLUX_Config, FluxVariantType.Dev, "FLUX.1", id="flux1-dev"),
+ pytest.param(Main_Checkpoint_Flux2_Config, Flux2VariantType.Klein4B, "FLUX.2", id="flux2-klein-4b"),
+]
+_BLOCK = "double_blocks.0.img_attn.qkv"
+_PREFIX = "model.diffusion_model."
+_REFUSAL = (
+ "FLUX transformer checkpoints with NVFP4 are not supported. "
+ "Choose a supported FLUX.1 or FLUX.2 checkpoint from the Model Manager."
+)
+
+
+def _layer(name: str, quantization: str, *, out_features: int = 768, in_features: int = 256) -> dict[str, torch.Tensor]:
+ match quantization:
+ case "nvfp4":
+ tensors = {
+ "weight": torch.zeros(out_features, in_features // 2, dtype=torch.uint8),
+ "weight_scale": torch.ones(out_features, in_features // 16).to(torch.float8_e4m3fn),
+ "weight_scale_2": torch.ones(()),
+ }
+ case "int8_tensorwise":
+ tensors = {
+ "weight": torch.zeros(out_features, in_features, dtype=torch.int8),
+ "weight_scale": torch.ones(out_features, 1),
+ }
+ case "float8_e4m3fn":
+ tensors = {
+ "weight": torch.zeros(out_features, in_features).to(torch.float8_e4m3fn),
+ "weight_scale": torch.ones(()),
+ }
+ case _:
+ return {f"{name}.weight": torch.zeros(out_features, in_features, dtype=torch.bfloat16)}
+
+ marker = {"format": quantization}
+ if quantization == "int8_tensorwise":
+ marker.update(convrot=True, convrot_groupsize=256)
+ tensors["comfy_quant"] = torch.tensor(list(json.dumps(marker).encode()), dtype=torch.uint8)
+ return {f"{name}.{suffix}": tensor for suffix, tensor in tensors.items()}
+
+
+def _write_checkpoint(
+ path: Path,
+ family: str,
+ quantization: str,
+ *,
+ prefix: str = "",
+ bundle: bool = False,
+ depth: bool = False,
+ packed_context: bool = False,
+) -> None:
+ # Keep the BFL input dimensions used for identification and shrink the hidden width.
+ in_channels = 64 if family == "FLUX.1" and not depth else 128
+ context_dim = 4096 if family == "FLUX.1" else 7680
+ tensors = {
+ "img_in.weight": torch.zeros(256, in_channels, dtype=torch.bfloat16),
+ **_layer("txt_in", "nvfp4" if packed_context else "bf16", out_features=256, in_features=context_dim),
+ "double_blocks.0.img_attn.norm.key_norm.scale": torch.ones(128, dtype=torch.bfloat16),
+ **_layer(_BLOCK, quantization),
+ }
+ if family == "FLUX.1":
+ tensors["guidance_in.out_layer.weight"] = torch.zeros(256, 256, dtype=torch.bfloat16)
+ tensors = {f"{prefix}{key}": value for key, value in tensors.items()}
+ if bundle:
+ encoder = (
+ "t5xxl.transformer.encoder.block.0.layer.0.SelfAttention.q"
+ if family == "FLUX.1"
+ else "qwen3_4b.transformer.model.layers.0.self_attn.q_proj"
+ )
+ tensors.update(_layer(f"text_encoders.{encoder}", "nvfp4"))
+ save_file(tensors, path)
+
+
[email protected](("config_type", "_variant", "family"), _FAMILIES)
[email protected]("prefix", ["", _PREFIX], ids=["bare", "wrapped"])
+def test_nvfp4_transformer_is_refused_by_name(tmp_path: Path, config_type, _variant, family: str, prefix: str) -> None:
+ path = tmp_path / "transformer.safetensors"
+ _write_checkpoint(path, family, "nvfp4", prefix=prefix)
+
+ result = ModelConfigFactory.from_model_on_disk(path, allow_unknown=True)
+
+ assert result.config is None, type(result.config).__name__
+ refusal = result.details[config_type.__name__]
+ assert isinstance(refusal, InvalidMatchError)
+ assert result.invalid_matches == [refusal]
+ assert str(refusal) == _REFUSAL
+
+
+def test_nvfp4_depth_checkpoint_refusal_does_not_guess_a_flux_family(tmp_path: Path) -> None:
+ path = tmp_path / "transformer.safetensors"
+ # Comfy-Org's FLUX.1 Depth header has 128 image channels and a 4096-wide text input.
+ _write_checkpoint(path, "FLUX.1", "nvfp4", depth=True)
+
+ result = ModelConfigFactory.from_model_on_disk(path, allow_unknown=True)
+
+ assert result.config is None
+ assert [str(refusal) for refusal in result.invalid_matches] == [_REFUSAL]
+
+
+def test_flux2_refuses_nvfp4_in_the_packed_text_projection(tmp_path: Path) -> None:
+ path = tmp_path / "transformer.safetensors"
+ # Packing halves the physical text width to 3840. The dense image projection still identifies FLUX.2.
+ _write_checkpoint(path, "FLUX.2", "bf16", packed_context=True)
+
+ result = ModelConfigFactory.from_model_on_disk(path, allow_unknown=True)
+
+ assert result.config is None
+ assert [str(refusal) for refusal in result.invalid_matches] == [_REFUSAL]
+
+
[email protected](("config_type", "variant", "family"), _FAMILIES)
+ ("quantization", "prefix", "bundle"),
+ [
+ pytest.param("bf16", "", False, id="bf16"),
+ pytest.param("int8_tensorwise", "", False, id="int8-convrot"),
+ pytest.param("float8_e4m3fn", "", False, id="scaled-fp8"),
+ pytest.param("bf16", _PREFIX, True, id="wrapped-nvfp4-encoder-sidecar"),
+ pytest.param("bf16", "", True, id="bare-nvfp4-encoder-sidecar"),
+ ],
+)
+def test_supported_transformer_installs(
+ tmp_path: Path, config_type, variant, family: str, quantization: str, prefix: str, bundle: bool
+) -> None:
+ path = tmp_path / "transformer.safetensors"
+ _write_checkpoint(path, family, quantization, prefix=prefix, bundle=bundle)
+
+ result = ModelConfigFactory.from_model_on_disk(path, allow_unknown=True)
+
+ assert isinstance(result.config, config_type)
+ assert result.config.variant is variant
+ assert not result.invalid_matches