invoke-ai/InvokeAI · warning · NotAMatchError
state dict does not look like bnb quantized nf4
Error message
state dict does not look like bnb quantized nf4
What it means
Main_BnBNF4_FLUX_Config.from_model_on_disk calls _validate_model_looks_like_bnb_quantized, which checks the state dict for bitsandbytes NF4 quantization keys (e.g. "double_blocks.0.img_attn.proj.weight.quant_state.bitsandbytes__nf4" per _has_bnb_nf4_keys). If no such quant_state key exists, the file is not an NF4-quantized checkpoint, so NotAMatchError is raised. It is a probe rejection during model scan: the correct (non-quantized) FLUX config class will be attempted next.
Source
Thrown at invokeai/backend/model_manager/configs/main.py:808
if variant is None:
# TODO(psyche): Should we have a graceful fallback here? Previously we fell back to the "normal" variant,
# but this variant is no longer used for FLUX models. If we get here, but the model is definitely a FLUX
# model, we should figure out a good fallback value.
raise NotAMatchError("unable to determine model variant from state dict")
return variant
@classmethod
def _validate_looks_like_main_model(cls, mod: ModelOnDisk) -> None:
has_main_model_keys = _has_main_keys(mod.load_state_dict())
if not has_main_model_keys:
raise NotAMatchError("state dict does not look like a main model")
@classmethod
def _validate_model_looks_like_bnb_quantized(cls, mod: ModelOnDisk) -> None:
has_bnb_nf4_keys = _has_bnb_nf4_keys(mod.load_state_dict())
if not has_bnb_nf4_keys:
raise NotAMatchError("state dict does not look like bnb quantized nf4")
class Main_GGUF_FLUX_Config(Checkpoint_Config_Base, Main_Config_Base, Config_Base):
"""Model config for main checkpoint models."""
base: Literal[BaseModelType.Flux] = Field(default=BaseModelType.Flux)
format: Literal[ModelFormat.GGUFQuantized] = Field(default=ModelFormat.GGUFQuantized)
variant: FluxVariantType = Field()
@classmethod
def from_model_on_disk(cls, mod: ModelOnDisk, override_fields: dict[str, Any]) -> Self:
raise_if_not_file(mod)
raise_for_override_fields(cls, override_fields)
cls._validate_looks_like_main_model(mod)
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Import the model as a normal (non-NF4) FLUX main checkpoint; InvokeAI will fall through to Main_Checkpoint_FLUX_Config.
- If NF4 is required, re-quantize with bitsandbytes ensuring quant_state is stored under one of the recognized keys (double_blocks.0...quant_state.bitsandbytes__nf4).
- Check the download actually is the NF4 variant (file size ~half of fp16); re-download if not.
- Update InvokeAI if you have a newer bnb/NF4 layout not yet covered by _has_bnb_nf4_keys.
Defensive patterns
Strategy: validation
Validate before calling
from safetensors import safe_open
def is_bnb_nf4(path):
targets = ("double_blocks.0.img_attn.proj.weight.quant_state.bitsandbytes__nf4",
"model.diffusion_model.double_blocks.0.img_attn.proj.weight.quant_state.bitsandbytes__nf4")
with safe_open(path, framework="pt") as f:
keys = set(f.keys())
return any(t in keys for t in targets)
if not is_bnb_nf4(path):
print("not NF4-quantized - import as a regular checkpoint") Type guard
def is_bnb_nf4_state_dict(sd: dict) -> bool:
return any(k in sd for k in (
"double_blocks.0.img_attn.proj.weight.quant_state.bitsandbytes__nf4",
"model.diffusion_model.double_blocks.0.img_attn.proj.weight.quant_state.bitsandbytes__nf4",
)) Try / catch
try:
cfg = Main_BnBNF4_FLUX_Config.from_model_on_disk(mod)
except NotAMatchError:
cfg = Main_Checkpoint_FLUX_Config.from_model_on_disk(mod) # fall back to the unquantized config Prevention
- Download the NF4 build deliberately (it is roughly half the fp16 file size).
- Re-quantize with bitsandbytes keeping quant_state stored in the checkpoint.
- Don't rename files across quantization types; keep releases separate.
- Prefer letting InvokeAI auto-detect instead of forcing a quantized model type.
When it happens
Trigger: Scanning/importing a FLUX checkpoint file with this config class when the file is a plain fp16/fp8 safetensors (no bnb quant_state keys), or a GGUF quantization, or the quant_state key layout differs from the two known prefixes.
Common situations: Downloading the fp16 FLUX.1-dev checkpoint and expecting it to load as bnb-NF4; upgrading InvokeAI and an older NF4 export uses key names the current detector does not recognize; bitsandbytes re-quantized model saved without quant_state metadata.
Related errors
- state dict does not look like bnb quantized llm_int8
- missing keys after fp8 load: {missing[:10]}
- state dict does not look like GGUF quantized
- state dict looks like GGUF quantized
- state dict looks SDNQ-quantized; use Qwen3Encoder_SDNQ_Folde
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/fda456af65f5d53c.
Report an issue: GitHub.