invoke-ai/InvokeAI · error · TypeError

Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type

Error message

Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type(lora_info.model).__name__}. The LoRA model may be corrupted or incompatible.

What it means

LoRAs for the Anima transformer must be loaded as ModelPatchRaw patch objects. If the model manager returns a different model type (raw transformer weights instead of a LoRA patch), the model is corrupted, mis-typed, or incompatible, so _lora_iterator raises this TypeError before applying the patch.

Source

Thrown at invokeai/app/invocations/anima_denoise.py:940

    def _estimate_preview_latents(self, latents: torch.Tensor, sigma: float, noise_pred: torch.Tensor) -> torch.Tensor:
        latents_dtype = latents.dtype
        latents_fp32 = latents.to(dtype=torch.float32)
        preview = latents_fp32 - sigma * noise_pred.to(dtype=torch.float32)
        return preview.to(dtype=latents_dtype)

    def _build_step_callback(self, context: InvocationContext) -> Callable[[PipelineIntermediateState], None]:
        def step_callback(state: PipelineIntermediateState) -> None:
            context.util.sd_step_callback(state, BaseModelType.Anima)

        return step_callback

    def _lora_iterator(self, context: InvocationContext) -> Iterator[PatchSpec]:
        """Iterate over LoRA models to apply to the transformer."""
        for lora in self.transformer.loras:
            lora_info = context.models.load(lora.lora)
            if not isinstance(lora_info.model, ModelPatchRaw):
                raise TypeError(
                    f"Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type(lora_info.model).__name__}. "
                    "The LoRA model may be corrupted or incompatible."
                )
            yield (lora_info.model, lora.weight, lora_info.model_in_ram())

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Re-download or re-convert the LoRA file; verify it is a valid Anima-compatible LoRA.
  2. Rescan/re-import models in the model manager so the LoRA is converted with the current patch format.
  3. Clear stale model cache entries and retry; check the LoRA's base model matches the Anima transformer.

Example fix

# before: reusing an SDXL LoRA file for Anima
loras=[LoRAModelField(lora="sdxl_char_lora")]
# after: convert/import an Anima-compatible LoRA and reference its key
loras=[LoRAModelField(lora="anima_char_lora_converted")]
Defensive patterns

Strategy: type-guard

Validate before calling

from invokeai.backend.model_manager import ModelPatchRaw
lora_info = context.models.load(lora.lora)
if not isinstance(lora_info.model, ModelPatchRaw):
    # reject/re-convert the LoRA before use

Type guard

def is_valid_lora(model) -> bool:
    from invokeai.backend.model_manager import ModelPatchRaw
    return isinstance(model, ModelPatchRaw)

Try / catch

try:
    output = invoker.invoke(denoise_invocation)
except TypeError as e:
    if "Expected ModelPatchRaw" in str(e):
        reimport_or_reconvert_lora(bad_lora_key)  # rescan/re-download via model manager
    else:
        raise

Prevention

When it happens

Trigger: A LoRA file whose converted checkpoint deserialized to the wrong class (not ModelPatchRaw); a corrupted safetensors file; a LoRA saved for a different model architecture being loaded as an Anima LoRA.

Common situations: Downloading a LoRA from a mismatched base model (e.g. SDXL LoRA used with Anima); truncated/interrupted download; stale model-manager cache after a version upgrade changed the patch format.

Related errors


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