invoke-ai/InvokeAI · warning · NotAMatchError
unable to determine model variant from state dict
Error message
unable to determine model variant from state dict
What it means
Variant detection reads the first conv layer 'model.diffusion_model.input_blocks.0.0.weight' and maps its in_channels to a variant (4=Normal, 5=Depth/SD2, 9=Inpaint). If that key is entirely absent from the state dict, the model cannot be classified as any variant and NotAMatchError is raised — the file likely is not a standard SD UNet checkpoint.
Source
Thrown at invokeai/backend/model_manager/configs/main.py:412
if key_name in state_dict and state_dict[key_name].shape[-1] == 1024:
if "global_step" in state_dict:
if state_dict["global_step"] == 220000:
return SchedulerPredictionType.Epsilon
elif state_dict["global_step"] == 110000:
return SchedulerPredictionType.VPrediction
return SchedulerPredictionType.VPrediction
else:
return SchedulerPredictionType.Epsilon
@classmethod
def _get_variant_or_raise(cls, mod: ModelOnDisk) -> ModelVariantType:
base = cls.model_fields["base"].default
state_dict = mod.load_state_dict()
key_name = "model.diffusion_model.input_blocks.0.0.weight"
if key_name not in state_dict:
raise NotAMatchError("unable to determine model variant from state dict")
in_channels = state_dict["model.diffusion_model.input_blocks.0.0.weight"].shape[1]
match in_channels:
case 4:
return ModelVariantType.Normal
case 5:
# Only SD2 has a depth variant
assert base is BaseModelType.StableDiffusion2, f"unexpected unet in_channels 5 for base '{base}'"
return ModelVariantType.Depth
case 9:
return ModelVariantType.Inpaint
case _:
raise NotAMatchError(f"unrecognized unet in_channels {in_channels} for base '{base}'")
@classmethod
def _validate_looks_like_main_model(cls, mod: ModelOnDisk) -> None:
has_main_model_keys = _has_main_keys(mod.load_state_dict())View on GitHub (pinned to 0b6a024f2f)
Solutions
- Point the scan at the actual full-checkpoint file containing the UNet keys, not a VAE/text-encoder file.
- If the model is diffusers-format (unet/ folders), ensure you are using the diffusers config class / directory scan, not the single-file checkpoint scan.
- Verify the file downloaded completely and contains model.diffusion_model.* keys.
- Re-export or convert the model to the legacy checkpoint layout if needed.
Example fix
// before
scan('model/vae/diffusion_pytorch_model.safetensors') # no UNet keys
// after
scan('model/sd_xl_base_1.0.safetensors') # full checkpoint Defensive patterns
Strategy: validation
Validate before calling
sd = load_file('model.safetensors')
if 'model.diffusion_model.input_blocks.0.0.weight' not in sd:
print('Missing UNet input conv key — not a legacy main checkpoint') Type guard
def has_unet_input_conv(sd: dict) -> bool:
return 'model.diffusion_model.input_blocks.0.0.weight' in sd Try / catch
try:
cfg = probe_model(path)
except NotAMatchError as e:
if 'unable to determine model variant' in str(e):
print('Scan the full checkpoint file, not a VAE/subcomponent') Prevention
- Scan the top-level checkpoint file, not VAE/text-encoder files
- Use diffusers-format scanning for diffusers-layout models
- Verify downloads complete
When it happens
Trigger: from_model_on_disk → _get_variant_or_raise on a state dict missing 'model.diffusion_model.input_blocks.0.0.weight' — e.g. a VAE, a text-encoder-only dump, a diffusers-unet-style checkpoint without the legacy key prefix, or an empty/partial state dict.
Common situations: Pointing the scanner at the wrong file inside a checkpoint repo (e.g. the VAE or CLIP files); diffusers-format checkpoints probed by legacy checkpoint configs; truncated downloads.
Related errors
- Unexpected key: {k}
- missing keys after fp8 load: {missing[:10]}
- unable to determine base type from state dict
- unrecognized unet in_channels {in_channels} for base '{base}
- state dict does not look like a main model
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/935baf17566f30ed.
Report an issue: GitHub.