{"record":{"id":"1273ba13410ecd01","repo":"invoke-ai/InvokeAI","slug":"state-dict-does-not-look-like-a-main-model","errorCode":null,"errorMessage":"state dict does not look like a main model","messagePattern":"state dict does not look like a main model","errorType":"exception","errorClass":"NotAMatchError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/main.py","lineNumber":432,"sourceCode":"        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())\n        if not has_main_model_keys:\n            raise NotAMatchError(\"state dict does not look like a main model\")\n\n\nclass Main_Checkpoint_SD1_Config(Main_SD_Checkpoint_Config_Base, Config_Base):\n    base: Literal[BaseModelType.StableDiffusion1] = Field(default=BaseModelType.StableDiffusion1)\n\n\nclass Main_Checkpoint_SD2_Config(Main_SD_Checkpoint_Config_Base, Config_Base):\n    base: Literal[BaseModelType.StableDiffusion2] = Field(default=BaseModelType.StableDiffusion2)\n\n\nclass Main_Checkpoint_SDXL_Config(Main_SD_Checkpoint_Config_Base, Config_Base):\n    base: Literal[BaseModelType.StableDiffusionXL] = Field(default=BaseModelType.StableDiffusionXL)\n\n\nclass Main_Checkpoint_SDXLRefiner_Config(Main_SD_Checkpoint_Config_Base, Config_Base):\n    base: Literal[BaseModelType.StableDiffusionXLRefiner] = Field(default=BaseModelType.StableDiffusionXLRefiner)\n\n","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/main.py#L414-L450","documentation":"Before accepting a main checkpoint config, InvokeAI checks the state dict against a heuristic set of keys expected in a main model (_has_main_keys). If none of the characteristic keys are present, the file is not treated as a main model and NotAMatchError is raised. Typically this means you scanned a VAE, LoRA, ControlNet, embedding, or an empty file rather than a full UNet checkpoint.","triggerScenarios":"from_model_on_disk → _validate_looks_like_main_model on a state dict failing the main-keys heuristic — VAE files, LoRA files, ControlNet state dicts, text-encoder dumps, or files with pruned/renamed keys.","commonSituations":"Batch-scanning a models directory and hitting non-checkpoint files; picking the wrong file in a multi-file repo; all-in-one downloads where UNet keys are nested under unexpected prefixes.","solutions":["Confirm the scanned file is the full checkpoint (contains model.diffusion_model.* UNet weights), not a VAE/LoRA/ControlNet.","Re-check directory structure and scan the intended file; fix path mixups.","Re-download if the file is truncated (very small file size).","Inspect keys: sd.keys() should include UNet entries before import."],"exampleFix":"// check first\nfrom safetensors.torch import load_file\nsd = load_file('model.safetensors')\nassert any(k.startswith('model.diffusion_model') for k in sd), 'not a main checkpoint'","handlingStrategy":"validation","validationCode":"sd = mod.load_state_dict()\nif not any(k.startswith(('model.diffusion_model', 'double_blocks', 'down_blocks')) for k in sd):\n    print('File does not look like a main model checkpoint')","typeGuard":"def looks_like_main_model(sd: dict) -> bool:\n    from invokeai.backend.model_manager.configs.main import _has_main_keys\n    return _has_main_keys(sd)","tryCatchPattern":"try:\n    cfg = probe_model(path)\nexcept NotAMatchError as e:\n    if 'main model' in str(e):\n        print('Not a main checkpoint — classify as VAE/LoRA/ControlNet as appropriate')","preventionTips":["Organize model folders by type so scanners hit the right files","Check file sizes and key names before import","Download complete checkpoints (watch for truncation)"],"tags":["checkpoint","state-dict","validation"],"backgroundTag":"unrecognized-model-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}