invoke-ai/InvokeAI · info · NotAMatchError

unrecognized cross_attention_dim {cross_attention_dim}

Error message

unrecognized cross_attention_dim {cross_attention_dim}

What it means

_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.

Source

Thrown at invokeai/backend/model_manager/configs/main.py:1147

        if expected_base is not recognized_base:
            raise NotAMatchError(f"base is {recognized_base}, not {expected_base}")

    @classmethod
    def _get_base_or_raise(cls, mod: ModelOnDisk) -> BaseModelType:
        # Handle pipelines with a UNet (i.e SD 1.x, SD2.x, SDXL).
        unet_conf = get_config_dict_or_raise(mod.path / "unet" / "config.json")
        cross_attention_dim = unet_conf.get("cross_attention_dim")
        match cross_attention_dim:
            case 768:
                return BaseModelType.StableDiffusion1
            case 1024:
                return BaseModelType.StableDiffusion2
            case 1280:
                return BaseModelType.StableDiffusionXLRefiner
            case 2048:
                return BaseModelType.StableDiffusionXL
            case _:
                raise NotAMatchError(f"unrecognized cross_attention_dim {cross_attention_dim}")

    @classmethod
    def _get_scheduler_prediction_type_or_raise(cls, mod: ModelOnDisk) -> SchedulerPredictionType:
        scheduler_conf = get_config_dict_or_raise(mod.path / "scheduler" / "scheduler_config.json")

        # TODO(psyche): Is epsilon the right default or should we raise if it's not present?
        prediction_type = scheduler_conf.get("prediction_type", "epsilon")

        match prediction_type:
            case "v_prediction":
                return SchedulerPredictionType.VPrediction
            case "epsilon":
                return SchedulerPredictionType.Epsilon
            case _:
                raise NotAMatchError(f"unrecognized scheduler prediction_type {prediction_type}")

    @classmethod
    def _get_variant_or_raise(cls, mod: ModelOnDisk) -> ModelVariantType:

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Let identification continue; ensure the correct config class for the actual architecture is available in your InvokeAI version.
  2. If the folder truly is an SD-family model, restore the original unet/config.json from the upstream repo.
  3. Remove or move non-SD components out of the folder if it mixes layouts.
Defensive patterns

Strategy: validation

Validate before calling

import json
from pathlib import Path

def check_cross_attention_dim(folder: Path):
    conf = folder / "unet" / "config.json"
    if conf.exists():
        dim = json.loads(conf.read_text()).get("cross_attention_dim")
        if dim not in (768, 1280, 2048):
            raise ValueError(f"cross_attention_dim {dim} not SD-family")

Type guard

def is_sd_family_unet(folder: Path) -> bool:
    conf = folder / "unet" / "config.json"
    if not conf.is_file():
        return False
    return json.loads(conf.read_text()).get("cross_attention_dim") in (768, 1280, 2048)

Try / catch

try:
    cfg = Main_SD_Diffusers_Config_Base_impl.from_model_on_disk(mod)
except NotAMatchError:
    cfg = None  # model is not SD-family; try other config classes

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/e76a7a6a946d7fac. Report an issue: GitHub.