{"record":{"id":"544db5ca74a9f741","repo":"invoke-ai/InvokeAI","slug":"expected-modelpatchraw-for-lora-lora-lora-key-544db5","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_klein_text_encoder.py","lineNumber":205,"sourceCode":"        out = out.to(dtype=text_encoder.dtype, device=device)\n\n        batch_size, num_channels, seq_len, hidden_dim = out.shape\n        prompt_embeds = out.permute(0, 2, 1, 3).reshape(batch_size, seq_len, num_channels * hidden_dim)\n\n        last_hidden_state = outputs.hidden_states[-1]\n        expanded_mask = attention_mask.unsqueeze(-1).expand_as(last_hidden_state).float()\n        sum_embeds = (last_hidden_state * expanded_mask).sum(dim=1)\n        num_tokens = expanded_mask.sum(dim=1).clamp(min=1)\n        pooled_embeds = sum_embeds / num_tokens\n\n        return prompt_embeds, pooled_embeds\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":187,"sourceCodeEnd":210,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux2_klein_text_encoder.py#L187-L210","documentation":"LoRAs applied to the Qwen3 text encoder must be loaded as ModelPatchRaw objects. If context.models.load returns a different model type for the LoRA, the file is not a FLUX.2-compatible LoRA patch or is corrupted, and it cannot be applied to the encoder.","triggerScenarios":"A LoRA listed in self.qwen3_encoder.loras resolves, via context.models.load(lora.lora), to a model that is not ModelPatchRaw in _lora_iterator; e.g. the record points at a checkpoint-format LoRA or an entirely different model file.","commonSituations":"Using SD/SDXL LoRA files with FLUX.2 Klein; LoRA converted to a format InvokeAI stores differently; stale model-manager records after conversion; corrupted LoRA downloads.","solutions":["Use a FLUX.2/Klein-compatible LoRA converted for InvokeAI","Re-convert/re-import the LoRA so the model manager stores it as ModelPatchRaw","Check the LoRA model record's type/hash points to the intended file","Re-download the LoRA if the file is corrupted"],"exampleFix":"// before: SDXL LoRA wired into qwen3_encoder.loras\nloras: [ModelIdentifierField(key='sdxl-lora-abc123')]\n// after: FLUX.2-compatible LoRA\nloras: [ModelIdentifierField(key='flux2-klein-lora-xyz789')]","handlingStrategy":"type-guard","validationCode":"info = context.models.load(lora_field)\nif not isinstance(info.model, ModelPatchRaw):\n    raise TypeError(f'{lora_field.key} is not a FLUX.2 LoRA patch')","typeGuard":"from invokeai.backend.model_patcher import ModelPatchRaw\n\ndef is_lora_patch(info) -> bool:\n    return isinstance(info.model, ModelPatchRaw)","tryCatchPattern":"try:\n    result = klein_encoder.invoke(context)\nexcept TypeError as e:\n    if 'ModelPatchRaw' in str(e):\n        convert_lora_to_flux2_format(e)\n    raise","preventionTips":["Only add LoRAs tagged for FLUX.2/Klein to encoder LoRA lists","Re-convert foreign-format LoRAs before use","Verify LoRA records after model-manager migrations"],"tags":["lora","model-loading","type-check"],"backgroundTag":"model-type-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}