{"record":{"id":"4d55872c53fc9b2a","repo":"invoke-ai/InvokeAI","slug":"expected-modelpatchraw-for-lora-lora-lora-key","errorCode":null,"errorMessage":"Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type(lora_info.model).__name__}. The LoRA model may be corrupted or incompatible.","messagePattern":"Expected ModelPatchRaw for LoRA '(.+?)', got (.+?)\\. The LoRA model may be corrupted or incompatible\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/anima_denoise.py","lineNumber":940,"sourceCode":"\n    def _estimate_preview_latents(self, latents: torch.Tensor, sigma: float, noise_pred: torch.Tensor) -> torch.Tensor:\n        latents_dtype = latents.dtype\n        latents_fp32 = latents.to(dtype=torch.float32)\n        preview = latents_fp32 - sigma * noise_pred.to(dtype=torch.float32)\n        return preview.to(dtype=latents_dtype)\n\n    def _build_step_callback(self, context: InvocationContext) -> Callable[[PipelineIntermediateState], None]:\n        def step_callback(state: PipelineIntermediateState) -> None:\n            context.util.sd_step_callback(state, BaseModelType.Anima)\n\n        return step_callback\n\n    def _lora_iterator(self, context: InvocationContext) -> Iterator[PatchSpec]:\n        \"\"\"Iterate over LoRA models to apply to the transformer.\"\"\"\n        for lora in self.transformer.loras:\n            lora_info = context.models.load(lora.lora)\n            if not isinstance(lora_info.model, ModelPatchRaw):\n                raise TypeError(\n                    f\"Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type(lora_info.model).__name__}. \"\n                    \"The LoRA model may be corrupted or incompatible.\"\n                )\n            yield (lora_info.model, lora.weight, lora_info.model_in_ram())\n","sourceCodeStart":922,"sourceCodeEnd":945,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/anima_denoise.py#L922-L945","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: reusing an SDXL LoRA file for Anima\nloras=[LoRAModelField(lora=\"sdxl_char_lora\")]\n# after: convert/import an Anima-compatible LoRA and reference its key\nloras=[LoRAModelField(lora=\"anima_char_lora_converted\")]","handlingStrategy":"type-guard","validationCode":"from invokeai.backend.model_manager import ModelPatchRaw\nlora_info = context.models.load(lora.lora)\nif not isinstance(lora_info.model, ModelPatchRaw):\n    # reject/re-convert the LoRA before use","typeGuard":"def is_valid_lora(model) -> bool:\n    from invokeai.backend.model_manager import ModelPatchRaw\n    return isinstance(model, ModelPatchRaw)","tryCatchPattern":"try:\n    output = invoker.invoke(denoise_invocation)\nexcept TypeError as e:\n    if \"Expected ModelPatchRaw\" in str(e):\n        reimport_or_reconvert_lora(bad_lora_key)  # rescan/re-download via model manager\n    else:\n        raise","preventionTips":["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"],"tags":["lora","type-error","model-loading"],"backgroundTag":"incompatible-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}