{"record":{"id":"36d551bb67164471","repo":"invoke-ai/InvokeAI","slug":"expected-modelpatchraw-for-lora-lora-lora-key-36d551","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/flux2_dev_text_encoder.py","lineNumber":248,"sourceCode":"                f\"layers {DEV_EXTRACTION_LAYERS} and requires at least {max(DEV_EXTRACTION_LAYERS)}. \"\n                \"This is not a supported FLUX.2 [dev] text encoder.\"\n            )\n        extraction_layers = DEV_EXTRACTION_LAYERS\n\n        # Concatenate the selected layers along the hidden dim: (B, seq, 3 * hidden_size).\n        # This is byte-identical to stack(dim=1).permute(0,2,1,3).reshape(...) but avoids\n        # the two intermediate full copies that stack + permute-reshape would allocate.\n        prompt_embeds = torch.cat([outputs.hidden_states[i] for i in extraction_layers], dim=-1)\n        prompt_embeds = prompt_embeds.to(dtype=text_encoder.dtype, device=device)\n\n        return prompt_embeds\n\n    def _lora_iterator(self, context: InvocationContext) -> Iterator[Tuple[ModelPatchRaw, float]]:\n        \"\"\"Iterate over LoRAs to apply to the Mistral encoder.\"\"\"\n        for lora in self.mistral_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)\n            del lora_info\n","sourceCodeStart":230,"sourceCodeEnd":254,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux2_dev_text_encoder.py#L230-L254","documentation":"_lora_iterator throws this TypeError when a LoRA listed on the Mistral encoder input loads as something other than a ModelPatchRaw. ModelPatchRaw is the internal representation LoRA application expects; any other object means the model file is corrupted or incompatible with LoRA patching. The message identifies the offending LoRA key and the actual loaded type.","triggerScenarios":"invoke() -> _encode_prompt -> _lora_iterator iterates mistral_encoder.loras, and context.models.load(lora.lora).model is not an instance of ModelPatchRaw.","commonSituations":"A corrupted or wrong-format LoRA file is attached to the FLUX.2 [dev] text encoder's LoRA list, or a non-LoRA model was mistakenly wired into the LoRA input.","solutions":["Re-download the LoRA file referenced by the reported key and re-import it into the model manager.","Confirm the wired model is actually a LoRA compatible with the Mistral encoder, not another model type.","Remove the problematic LoRA from the encoder's LoRA list and retry."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"lora_info = context.models.load(lora.lora)\nif not isinstance(lora_info.model, ModelPatchRaw):\n    raise TypeError(f\"LoRA {lora.lora.key} loaded as {type(lora_info.model).__name__}, expected ModelPatchRaw\")","typeGuard":"def is_lora_patch(model) -> bool:\n    return isinstance(model, ModelPatchRaw)","tryCatchPattern":"try:\n    output = text_encoder_invocation.invoke(context)\nexcept TypeError as e:\n    if \"Expected ModelPatchRaw for LoRA\" in str(e):\n        remove_bad_loras(context)\n        output = text_encoder_invocation.invoke(context)\n    else:\n        raise","preventionTips":["Validate LoRA files import correctly in the Model Manager before use.","Only wire LoRA models into LoRA inputs.","Re-download LoRAs that fail to load as ModelPatchRaw."],"tags":["invokeai","lora","type-mismatch","corrupted-model","flux2"],"backgroundTag":"unexpected-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}