{"record":{"id":"c07685fa69b95052","repo":"invoke-ai/InvokeAI","slug":"expected-modelpatchraw-for-lora-lora-lora-key-c07685","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_text_encoder.py","lineNumber":215,"sourceCode":"        context.util.signal_progress(\"Tokenizing with T5-XXL\")\n        t5_tokenizer = load_bundled_t5_tokenizer()\n        t5_tokens = t5_tokenizer(\n            prompt,\n            padding=False,\n            truncation=True,\n            max_length=T5_MAX_SEQ_LEN,\n            return_tensors=\"pt\",\n        )\n        t5xxl_ids = t5_tokens.input_ids[0]  # Shape: (seq_len,)\n\n        return qwen3_embeds, t5xxl_ids, None\n\n    def _lora_iterator(self, context: InvocationContext) -> Iterator[PatchSpec]:\n        \"\"\"Iterate over LoRA models to apply to the Qwen3 text encoder.\"\"\"\n        for lora in self.qwen3_encoder.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":197,"sourceCodeEnd":220,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/anima_text_encoder.py#L197-L220","documentation":"When applying LoRAs to the Qwen3 text encoder, _lora_iterator loads each LoRA model and requires the loaded object to be a ModelPatchRaw (InvokeAI's raw patch representation). Any other loaded type means the file is not a usable Anima LoRA patch, so it raises a TypeError suggesting the model is corrupted or incompatible.","triggerScenarios":"During invoke → _encode_prompt → _lora_iterator, when context.models.load(lora.lora).model is not an instance of ModelPatchRaw — e.g. the model record was imported with the wrong model type or the file is not a valid LoRA patch.","commonSituations":"Importing a checkpoint or full-model file as a LoRA; a LoRA trained for another base leaking into the qwen3_encoder list with mismatched metadata; corrupted download that parses as a different object type.","solutions":["Re-import the LoRA with the correct model type (LoRA patch) in the model manager.","Replace the LoRA file with a fresh download and re-scan models.","Remove the LoRA from the qwen3_encoder loras list if it is not a Qwen3/Anima-compatible patch."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"from invokeai.backend.model_manager.load import ModelPatchRaw\ninfo = context.models.load(lora.lora)\nif not isinstance(info.model, ModelPatchRaw):\n    print(f\"{lora.lora.key} is {type(info.model).__name__}, not a LoRA patch\")","typeGuard":"from invokeai.backend.model_manager.load import ModelPatchRaw\ndef is_lora_patch(info) -> bool:\n    return isinstance(info.model, ModelPatchRaw)","tryCatchPattern":"try:\n    result = invocation.invoke(context)\nexcept TypeError as e:\n    if \"Expected ModelPatchRaw for LoRA\" in str(e):\n        reimport_lora_with_correct_model_type(e)\n    else:\n        raise","preventionTips":["Import LoRAs with the correct model type (LoRA patch), not as checkpoints.","Re-download LoRA files that fail to parse; verify integrity after download.","Check base-model compatibility before attaching a LoRA to a Qwen3 encoder."],"tags":["lora","model-patch","type-mismatch","invokeai"],"backgroundTag":"incompatible-model-architecture","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}