{"record":{"id":"1102abe18274a6b5","repo":"invoke-ai/InvokeAI","slug":"expected-modelpatchraw-for-lora-lora-lora-key-1102ab","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_denoise.py","lineNumber":808,"sourceCode":"            height=self.height,\n            width=self.width,\n            dtype=inference_dtype,\n            device=device,\n            seed=self.seed,\n        )\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.ZImage)\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":790,"sourceCodeEnd":813,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/z_image_denoise.py#L790-L813","documentation":"Z-Image LoRAs must load as ModelPatchRaw — a raw patch applied to the transformer. If context.models.load returns some other model type for a LoRA entry, _lora_iterator raises TypeError, indicating the stored model is corrupted, misclassified, or incompatible with the Z-Image pipeline.","triggerScenarios":"A LoRA in self.transformer.loras whose loaded model is not ModelPatchRaw — e.g. the model manager registered the file under a wrong model type/format, so it loads as a different class.","commonSituations":"Using a LoRA trained for a different architecture (SD/Flux) with Z-Image; a model-manager scan misclassifying the LoRA file; a corrupted or partially downloaded LoRA file; quantized LoRA formats lacking a patch path.","solutions":["Verify the LoRA file is a valid Z-Image-compatible LoRA and re-download if corrupted","Re-scan/re-import the LoRA in the model manager so it is registered with the correct model type","Remove the incompatible LoRA from the transformer's loras list","Update InvokeAI in case LoRA format support was extended"],"exampleFix":"// before\nloras=[LoRAModelField(lora=sd_lora_key, weight=0.8)]  # SD LoRA\n// after\nloras=[LoRAModelField(lora=z_image_lora_key, weight=0.8)]  # compatible Z-Image LoRA","handlingStrategy":"type-guard","validationCode":"for lora in denoise.transformer.loras:\n    info = context.models.load(lora.lora)\n    if not isinstance(info.model, ModelPatchRaw):\n        raise TypeError(f\"LoRA {lora.lora.key} is not ModelPatchRaw ({type(info.model).__name__})\")","typeGuard":"def is_valid_lora(context, lora_field) -> bool:\n    from invokeai.backend.model_manager.load.model_cache.model_cache import ModelPatchRaw  # adjust import path\n    info = context.models.load(lora_field.lora)\n    return isinstance(info.model, ModelPatchRaw)","tryCatchPattern":"try:\n    output = denoise.invoke(context)\nexcept TypeError as e:\n    if \"Expected ModelPatchRaw for LoRA\" in str(e):\n        drop_incompatible_lora(extract_lora_key(str(e)))\n    else:\n        raise","preventionTips":["Use only LoRAs trained/tested for Z-Image","Re-scan misclassified LoRAs in the model manager","Hash-verify downloaded LoRA files"],"tags":["lora","type-error","model-compatibility"],"backgroundTag":"incompatible-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}