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
- Re-download or re-convert the LoRA file; verify it is a valid Anima-compatible LoRA.
- Rescan/re-import models in the model manager so the LoRA is converted with the current patch format.
- 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
- Only use LoRAs converted for the Anima base model
- Verify file integrity (hash/size) after download
- Re-scan models after upgrading InvokeAI so patches are rebuilt
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
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- Expected AutoencoderKLWan or FluxAutoEncoder for Anima VAE,
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- LoRA '{lora.lora.key}' has conflicting weights on the transf
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/4d55872c53fc9b2a.
Report an issue: GitHub.