{"record":{"id":"e76a7a6a946d7fac","repo":"invoke-ai/InvokeAI","slug":"unrecognized-cross-attention-dim-cross-attention","errorCode":null,"errorMessage":"unrecognized cross_attention_dim {cross_attention_dim}","messagePattern":"unrecognized cross_attention_dim (.+?)","errorType":"exception","errorClass":"NotAMatchError","httpStatus":null,"severity":"info","filePath":"invokeai/backend/model_manager/configs/main.py","lineNumber":1147,"sourceCode":"        if expected_base is not recognized_base:\n            raise NotAMatchError(f\"base is {recognized_base}, not {expected_base}\")\n\n    @classmethod\n    def _get_base_or_raise(cls, mod: ModelOnDisk) -> BaseModelType:\n        # Handle pipelines with a UNet (i.e SD 1.x, SD2.x, SDXL).\n        unet_conf = get_config_dict_or_raise(mod.path / \"unet\" / \"config.json\")\n        cross_attention_dim = unet_conf.get(\"cross_attention_dim\")\n        match cross_attention_dim:\n            case 768:\n                return BaseModelType.StableDiffusion1\n            case 1024:\n                return BaseModelType.StableDiffusion2\n            case 1280:\n                return BaseModelType.StableDiffusionXLRefiner\n            case 2048:\n                return BaseModelType.StableDiffusionXL\n            case _:\n                raise NotAMatchError(f\"unrecognized cross_attention_dim {cross_attention_dim}\")\n\n    @classmethod\n    def _get_scheduler_prediction_type_or_raise(cls, mod: ModelOnDisk) -> SchedulerPredictionType:\n        scheduler_conf = get_config_dict_or_raise(mod.path / \"scheduler\" / \"scheduler_config.json\")\n\n        # TODO(psyche): Is epsilon the right default or should we raise if it's not present?\n        prediction_type = scheduler_conf.get(\"prediction_type\", \"epsilon\")\n\n        match prediction_type:\n            case \"v_prediction\":\n                return SchedulerPredictionType.VPrediction\n            case \"epsilon\":\n                return SchedulerPredictionType.Epsilon\n            case _:\n                raise NotAMatchError(f\"unrecognized scheduler prediction_type {prediction_type}\")\n\n    @classmethod\n    def _get_variant_or_raise(cls, mod: ModelOnDisk) -> ModelVariantType:","sourceCodeStart":1129,"sourceCodeEnd":1165,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/main.py#L1129-L1165","documentation":"_get_base_or_raise maps the unet's `cross_attention_dim` from unet/config.json to a BaseModelType (768=>SD1/SD2, 1280=>SDXL Refiner, 2048=>SDXL). A value outside the known set raises NotAMatchError because the config family cannot classify the model. This lets identification fall through to other config classes (Flux, SD3, etc.) that don't rely on a UNet cross_attention_dim.","triggerScenarios":"from_model_on_disk -> _validate_base -> _get_base_or_raise on a folder whose `unet/config.json` exists but has a cross_attention_dim not in {768, 1280, 2048} (or a non-integer).","commonSituations":"Scanning a non-UNet model (Flux/SD3/Z-Image) that nevertheless has a `unet/` folder with unusual config, hand-edited or third-party unet configs, or experimental architectures.","solutions":["Let identification continue; ensure the correct config class for the actual architecture is available in your InvokeAI version.","If the folder truly is an SD-family model, restore the original unet/config.json from the upstream repo.","Remove or move non-SD components out of the folder if it mixes layouts."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\ndef check_cross_attention_dim(folder: Path):\n    conf = folder / \"unet\" / \"config.json\"\n    if conf.exists():\n        dim = json.loads(conf.read_text()).get(\"cross_attention_dim\")\n        if dim not in (768, 1280, 2048):\n            raise ValueError(f\"cross_attention_dim {dim} not SD-family\")","typeGuard":"def is_sd_family_unet(folder: Path) -> bool:\n    conf = folder / \"unet\" / \"config.json\"\n    if not conf.is_file():\n        return False\n    return json.loads(conf.read_text()).get(\"cross_attention_dim\") in (768, 1280, 2048)","tryCatchPattern":"try:\n    cfg = Main_SD_Diffusers_Config_Base_impl.from_model_on_disk(mod)\nexcept NotAMatchError:\n    cfg = None  # model is not SD-family; try other config classes","preventionTips":["Don't hand-edit unet/config.json values like cross_attention_dim.","Scan only models whose architecture InvokeAI supports.","Restore original configs from the upstream repo after any conversion."],"tags":["model-identification","unet-config","cross-attention"],"backgroundTag":"model-base-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}