{"record":{"id":"58a878a30eb68ac7","repo":"invoke-ai/InvokeAI","slug":"expected-modelpatchraw-for-lora-lora-lora-key-58a878","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/z_image_text_encoder.py","lineNumber":205,"sourceCode":"            # Z-Image expects a 2D tensor [seq_len, hidden_dim] with only valid tokens\n            # Based on diffusers ZImagePipeline implementation:\n            # embeddings_list.append(prompt_embeds[i][prompt_masks[i]])\n            # Since batch_size=1, we take the first item and filter by mask\n            prompt_embeds = prompt_embeds[0][prompt_mask[0]]\n\n        if not isinstance(prompt_embeds, torch.Tensor):\n            raise TypeError(\n                f\"Expected torch.Tensor for prompt embeddings, got {type(prompt_embeds).__name__}. \"\n                \"Text encoder returned unexpected type.\"\n            )\n        return prompt_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/z_image_text_encoder.py#L187-L210","documentation":"LoRAs applied to the Qwen3 text encoder must be loaded as a ModelPatchRaw object; context.models.load() returned something else. InvokeAI raises this TypeError because a non-patch object cannot be used as a LoRA patch spec, usually meaning the model file is corrupt, the wrong format, or incompatible with this loader.","triggerScenarios":"Adding a LoRA to self.qwen3_encoder.loras whose backing file is not a valid ModelPatchRaw (e.g. a full checkpoint instead of a LoRA delta, a truncated download, or a LoRA saved for a different architecture/loader that deserializes to another type).","commonSituations":"Manually copied LoRA files in the LoRA directory; LoRAs converted for a different base model (SD/FLUX) being applied to the Qwen3 encoder; partially downloaded or corrupted safetensors; stale model-manager records pointing at wrong files.","solutions":["Remove and re-import the LoRA through InvokeAI's model manager so it is scanned and converted to the expected raw-patch format","Verify the LoRA file targets the Qwen3/Z-Image text encoder architecture, not SD or FLUX weights","Re-download the LoRA file; check integrity (file size / safetensors header) to rule out truncation","Delete stale model-manager DB entries pointing at the old file and rescan the model directory"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"lora_info = context.models.load(lora.lora)\nassert isinstance(lora_info.model, ModelPatchRaw), type(lora_info.model)","typeGuard":"from invokeai.backend.model_manager.load.model_util import ModelPatchRaw  # adjust import to project\n\ndef is_valid_lora(obj) -> bool:\n    return isinstance(obj, ModelPatchRaw)","tryCatchPattern":"try:\n    patches = list(self._lora_iterator(context))\nexcept TypeError as e:\n    if 'ModelPatchRaw' in str(e):\n        logger.error(f\"Skipping incompatible LoRA: {e}\")\n    else:\n        raise","preventionTips":["Import LoRAs only through the model manager, never copy files manually","Use LoRAs trained for the matching base model (Z-Image/Qwen3 encoder)","Verify downloaded LoRA file checksums"],"tags":["python","type-error","lora","model-loading"],"backgroundTag":"incompatible-model-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}