invoke-ai/InvokeAI · warning · NotAMatchError

unable to determine base type from state dict

Error message

unable to determine base type from state dict

What it means

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.

Source

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

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

    @classmethod
    def _get_base_or_raise(cls, mod: ModelOnDisk) -> BaseModelType:
        state_dict = mod.load_state_dict()

        key_name = "model.diffusion_model.input_blocks.2.1.transformer_blocks.0.attn2.to_k.weight"
        if key_name in state_dict and state_dict[key_name].shape[-1] == 768:
            return BaseModelType.StableDiffusion1
        if key_name in state_dict and state_dict[key_name].shape[-1] == 1024:
            return BaseModelType.StableDiffusion2

        key_name = "model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight"
        if key_name in state_dict and state_dict[key_name].shape[-1] == 2048:
            return BaseModelType.StableDiffusionXL
        elif key_name in state_dict and state_dict[key_name].shape[-1] == 1280:
            return BaseModelType.StableDiffusionXLRefiner

        raise NotAMatchError("unable to determine base type from state dict")

    @classmethod
    def _get_scheduler_prediction_type_or_raise(cls, mod: ModelOnDisk) -> SchedulerPredictionType:
        base = cls.model_fields["base"].default

        if base is BaseModelType.StableDiffusion2:
            state_dict = mod.load_state_dict()
            key_name = "model.diffusion_model.input_blocks.2.1.transformer_blocks.0.attn2.to_k.weight"
            if key_name in state_dict and state_dict[key_name].shape[-1] == 1024:
                if "global_step" in state_dict:
                    if state_dict["global_step"] == 220000:
                        return SchedulerPredictionType.Epsilon
                    elif state_dict["global_step"] == 110000:
                        return SchedulerPredictionType.VPrediction
            return SchedulerPredictionType.VPrediction
        else:
            return SchedulerPredictionType.Epsilon

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. 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).
  2. Load the safetensors/checkpoint and check the to_k key exists and its shape[-1].
  3. Re-download the model if keys appear truncated or renamed.
  4. If you know the base, use explicit model-type/base fields on import to bypass heuristic probing where supported.

Example fix

// check before import
sd = load_file('model.safetensors')
k = 'model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight'
print(k in sd, sd[k].shape if k in sd else None)  # expect shape[-1] in (1280, 2048)
Defensive patterns

Strategy: validation

Validate before calling

sd = mod.load_state_dict()
k = 'model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight'
if k not in sd or sd[k].shape[-1] not in (1280, 2048):
    print('Not an SDXL/Refiner main checkpoint; pick the right config/model type')

Type guard

def is_sdxl_or_refiner(sd: dict) -> bool:
    k = 'model.diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_k.weight'
    return k in sd and sd[k].shape[-1] in (1280, 2048)

Try / catch

try:
    cfg = probe_model(mod)
except NotAMatchError as e:
    if 'unable to determine base type' in str(e):
        log.warning('Unrecognized checkpoint base: %s', e)

Prevention

When it happens

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

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

Related errors


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