{"record":{"id":"581686994a6e8bdd","repo":"invoke-ai/InvokeAI","slug":"unable-to-determine-base-type-from-state-dict","errorCode":null,"errorMessage":"unable to determine base type from state dict","messagePattern":"unable to determine base type from state dict","errorType":"exception","errorClass":"NotAMatchError","httpStatus":null,"severity":"warning","filePath":"invokeai/backend/model_manager/configs/main.py","lineNumber":385,"sourceCode":"            raise NotAMatchError(f\"base is {recognized_base}, not {expected_base}\")\n\n    @classmethod\n    def _get_base_or_raise(cls, mod: ModelOnDisk) -> BaseModelType:\n        state_dict = mod.load_state_dict()\n\n        key_name = \"model.diffusion_model.input_blocks.2.1.transformer_blocks.0.attn2.to_k.weight\"\n        if key_name in state_dict and state_dict[key_name].shape[-1] == 768:\n            return BaseModelType.StableDiffusion1\n        if key_name in state_dict and state_dict[key_name].shape[-1] == 1024:\n            return BaseModelType.StableDiffusion2\n\n        key_name = \"model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight\"\n        if key_name in state_dict and state_dict[key_name].shape[-1] == 2048:\n            return BaseModelType.StableDiffusionXL\n        elif key_name in state_dict and state_dict[key_name].shape[-1] == 1280:\n            return BaseModelType.StableDiffusionXLRefiner\n\n        raise NotAMatchError(\"unable to determine base type from state dict\")\n\n    @classmethod\n    def _get_scheduler_prediction_type_or_raise(cls, mod: ModelOnDisk) -> SchedulerPredictionType:\n        base = cls.model_fields[\"base\"].default\n\n        if base is BaseModelType.StableDiffusion2:\n            state_dict = mod.load_state_dict()\n            key_name = \"model.diffusion_model.input_blocks.2.1.transformer_blocks.0.attn2.to_k.weight\"\n            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","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/main.py#L367-L403","documentation":"This base-detection routine distinguishes SDXL (to_k dim 2048) from SDXL-Refiner (dim 1280) via a specific UNet cross-attention key. If the key is absent or its shape matches neither, the state dict does not look like any recognized base and NotAMatchError is raised. The probe treats the checkpoint as unidentifiable as an SD-family main model.","triggerScenarios":"from_model_on_disk → _validate_base on a checkpoint where 'model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight' is missing or has an unexpected last dimension (not 2048 or 1280).","commonSituations":"Importing non-SD checkpoints (FLUX, SD3) into SD-family configs; models with non-standard/unet-only key layouts; corrupted weights missing keys; refiner variants with unexpected channel sizes.","solutions":["Confirm the checkpoint is an SDXL or SDXL-Refiner main model; if it is another architecture, import via the appropriate config (update InvokeAI if needed).","Load the safetensors/checkpoint and check the to_k key exists and its shape[-1].","Re-download the model if keys appear truncated or renamed.","If you know the base, use explicit model-type/base fields on import to bypass heuristic probing where supported."],"exampleFix":"// check before import\nsd = load_file('model.safetensors')\nk = 'model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight'\nprint(k in sd, sd[k].shape if k in sd else None)  # expect shape[-1] in (1280, 2048)","handlingStrategy":"validation","validationCode":"sd = mod.load_state_dict()\nk = 'model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight'\nif k not in sd or sd[k].shape[-1] not in (1280, 2048):\n    print('Not an SDXL/Refiner main checkpoint; pick the right config/model type')","typeGuard":"def is_sdxl_or_refiner(sd: dict) -> bool:\n    k = 'model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight'\n    return k in sd and sd[k].shape[-1] in (1280, 2048)","tryCatchPattern":"try:\n    cfg = probe_model(mod)\nexcept NotAMatchError as e:\n    if 'unable to determine base type' in str(e):\n        log.warning('Unrecognized checkpoint base: %s', e)","preventionTips":["Only import full SDXL-family checkpoints into SD configs","Verify checkpoint keys/shapes before import","Download models from trusted sources to avoid truncated files"],"tags":["checkpoint","state-dict","base-detection"],"backgroundTag":"unrecognized-model-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}