{"record":{"id":"935baf17566f30ed","repo":"invoke-ai/InvokeAI","slug":"unable-to-determine-model-variant-from-state-dict","errorCode":null,"errorMessage":"unable to determine model variant from state dict","messagePattern":"unable to determine model variant from state dict","errorType":"exception","errorClass":"NotAMatchError","httpStatus":null,"severity":"warning","filePath":"invokeai/backend/model_manager/configs/main.py","lineNumber":412,"sourceCode":"            if key_name in state_dict and state_dict[key_name].shape[-1] == 1024:\n                if \"global_step\" in state_dict:\n                    if state_dict[\"global_step\"] == 220000:\n                        return SchedulerPredictionType.Epsilon\n                    elif state_dict[\"global_step\"] == 110000:\n                        return SchedulerPredictionType.VPrediction\n            return SchedulerPredictionType.VPrediction\n        else:\n            return SchedulerPredictionType.Epsilon\n\n    @classmethod\n    def _get_variant_or_raise(cls, mod: ModelOnDisk) -> ModelVariantType:\n        base = cls.model_fields[\"base\"].default\n\n        state_dict = mod.load_state_dict()\n        key_name = \"model.diffusion_model.input_blocks.0.0.weight\"\n\n        if key_name not in state_dict:\n            raise NotAMatchError(\"unable to determine model variant from state dict\")\n\n        in_channels = state_dict[\"model.diffusion_model.input_blocks.0.0.weight\"].shape[1]\n\n        match in_channels:\n            case 4:\n                return ModelVariantType.Normal\n            case 5:\n                # Only SD2 has a depth variant\n                assert base is BaseModelType.StableDiffusion2, f\"unexpected unet in_channels 5 for base '{base}'\"\n                return ModelVariantType.Depth\n            case 9:\n                return ModelVariantType.Inpaint\n            case _:\n                raise NotAMatchError(f\"unrecognized unet in_channels {in_channels} for base '{base}'\")\n\n    @classmethod\n    def _validate_looks_like_main_model(cls, mod: ModelOnDisk) -> None:\n        has_main_model_keys = _has_main_keys(mod.load_state_dict())","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/main.py#L394-L430","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nscan('model/vae/diffusion_pytorch_model.safetensors')  # no UNet keys\n// after\nscan('model/sd_xl_base_1.0.safetensors')               # full checkpoint","handlingStrategy":"validation","validationCode":"sd = load_file('model.safetensors')\nif 'model.diffusion_model.input_blocks.0.0.weight' not in sd:\n    print('Missing UNet input conv key — not a legacy main checkpoint')","typeGuard":"def has_unet_input_conv(sd: dict) -> bool:\n    return 'model.diffusion_model.input_blocks.0.0.weight' in sd","tryCatchPattern":"try:\n    cfg = probe_model(path)\nexcept NotAMatchError as e:\n    if 'unable to determine model variant' in str(e):\n        print('Scan the full checkpoint file, not a VAE/subcomponent')","preventionTips":["Scan the top-level checkpoint file, not VAE/text-encoder files","Use diffusers-format scanning for diffusers-layout models","Verify downloads complete"],"tags":["checkpoint","variant-detection","state-dict"],"backgroundTag":"unrecognized-model-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}