{"record":{"id":"add3ff91a8dd3a47","repo":"invoke-ai/InvokeAI","slug":"unrecognized-unet-in-channels-in-channels-for-ba","errorCode":null,"errorMessage":"unrecognized unet in_channels {in_channels} for base '{base}'","messagePattern":"unrecognized unet in_channels (.+?) for base '(.+?)'","errorType":"exception","errorClass":"NotAMatchError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/main.py","lineNumber":426,"sourceCode":"        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())\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)","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/main.py#L408-L444","documentation":"After reading the UNet's first-conv in_channels, only 4 (Normal), 5 (Depth, SD2 only), and 9 (Inpaint) are recognized. Any other channel count — or 5 on a base other than SD2 — raises NotAMatchError because InvokeAI has no variant mapping for it.","triggerScenarios":"from_model_on_disk → _get_variant_or_raise with in_channels not in {4,5,9}, or in_channels==5 while the resolved base is not StableDiffusion2 (the assert fires first with a different message only if assertion checks pass differently; the match fallthrough raises this error otherwise).","commonSituations":"ControlNet or T2I-Adapter weights (extra conditioning channels) mistaken for main checkpoints; custom fine-tunes with modified input convs (e.g. grayscale or 8-channel editors); updated models adding channels (e.g. 8 for image-conditioned edit models).","solutions":["Verify the file is a main UNet checkpoint, not a ControlNet/adapter — import ControlNets via their own model type.","If it is a custom-channel fine-tune, InvokeAI cannot classify it; use the upstream repo tooling instead or patch the input conv back to 4 channels if it is a leftover.","Check the base resolution: in_channels==5 is only valid for SD2 Depth; ensure the correct base was detected.","Update InvokeAI in case support for newer channel layouts was added."],"exampleFix":"// sanity check before import\nsd = load_file('model.safetensors')\nch = sd['model.diffusion_model.input_blocks.0.0.weight'].shape[1]\nassert ch in (4, 5, 9), f'unsupported in_channels {ch}'","handlingStrategy":"validation","validationCode":"sd = load_file('model.safetensors')\nch = sd['model.diffusion_model.input_blocks.0.0.weight'].shape[1]\nif ch not in (4, 5, 9):\n    print(f'in_channels={ch}: likely a ControlNet/adapter or custom fine-tune, not a main model')","typeGuard":"def has_supported_variant(sd: dict) -> bool:\n    w = sd.get('model.diffusion_model.input_blocks.0.0.weight')\n    return w is not None and w.shape[1] in (4, 5, 9)","tryCatchPattern":"try:\n    cfg = probe_model(path)\nexcept NotAMatchError as e:\n    if 'in_channels' in str(e):\n        print('Import as its proper model type (e.g. ControlNet) instead')","preventionTips":["Import ControlNets/T2I adapters as their own model type","Avoid custom-channel fine-tunes unless you know how to serve them","Check in_channels early when triaging unknown checkpoints"],"tags":["checkpoint","variant-detection","in-channels"],"backgroundTag":"unrecognized-model-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}