{"record":{"id":"7715ee35435af27e","repo":"invoke-ai/InvokeAI","slug":"expected-modelpatchraw-for-lora-lora-lora-key-7715ee","errorCode":null,"errorMessage":"Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type(lora_info.model).__name__}.","messagePattern":"Expected ModelPatchRaw for LoRA '(.+?)', got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/krea2_text_encoder.py","lineNumber":167,"sourceCode":"            # Stack the selected layers along a new layer axis: (B, seq, 12, hidden).\n            stacked = torch.stack([hidden_states_tuple[i] for i in KREA2_SELECT_LAYERS], dim=2)\n\n            # Drop the system-prompt prefix tokens.\n            prompt_embeds = stacked[:, KREA2_START_IDX:]\n            prompt_mask = attention_mask[:, KREA2_START_IDX:].bool()\n\n            # Match the device-safe compute dtype used by the denoise loop (falls back from bf16 to\n            # fp16/fp32 on devices without bf16 support) rather than forcing bfloat16.\n            prompt_embeds = prompt_embeds.to(dtype=TorchDevice.choose_bfloat16_safe_dtype(device))\n\n        return prompt_embeds, prompt_mask\n\n    def _lora_iterator(self, context: InvocationContext) -> Iterator[PatchSpec]:\n        \"\"\"Iterate over the LoRA models to apply to the Qwen3-VL text encoder.\"\"\"\n        for lora in self.qwen3_vl_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                )\n            yield (lora_info.model, lora.weight, lora_info.model_in_ram())\n","sourceCodeStart":149,"sourceCodeEnd":171,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/krea2_text_encoder.py#L149-L171","documentation":"This TypeError is raised in _lora_iterator when a LoRA loaded via context.models.load for the Qwen3-VL text encoder resolves to a model object that is not a ModelPatchRaw. LayerPatcher.apply_smart_model_patches expects each patch spec to be a raw LoRA patch model; a different model type (e.g. a full main model or checkpoint) cannot be applied as a LoRA patch, so the code fails fast with a clear message naming the offending LoRA key.","triggerScenarios":"A LoRA model record referenced in qwen3_vl_encoder.loras whose key points at a non-patch model type in the model manager — e.g. the file was imported/detected as a full checkpoint instead of a LoRA, a converted-format mismatch (diffusers vs checkpoint LoRA config), or a main model was accidentally connected to the LoRA input field.","commonSituations":"A user downloads a LoRA whose folder layout or metadata makes InvokeAI classify it as a main model; model-manager scan misclassifies a renamed .safetensors file; a stale model record from an earlier InvokeAI version has the wrong model_type; wiring a checkpoint into a LoRA socket in the workflow editor.","solutions":["Open the Model Manager, find the LoRA with the reported key, and re-import/convert it so it is classified as a LoRA (ModelPatchRaw).","Fix the model record's type/config in the model manager database or remove and rescan the models directory so the file is detected as a LoRA.","Disconnect any non-LoRA model connected to the LoRA input of the Qwen3-VL encoder node and connect a valid LoRA.","Verify the LoRA file format is supported (correct LoRA key layout) rather than a merged checkpoint, and update InvokeAI if the file uses a newer format."],"exampleFix":"// before (model record classified as main model)\nconfig = {\"path\": \"my_lora.safetensors\", \"type\": \"main\", \"base\": \"krea-2\"}\n// after\nconfig = {\"path\": \"my_lora.safetensors\", \"type\": \"lora\", \"base\": \"krea-2\"}","handlingStrategy":"type-guard","validationCode":"# Before invoking, verify every attached LoRA loads as a patch model\nfor lora in self.qwen3_vl_encoder.loras:\n    info = context.models.load(lora.lora)\n    if not isinstance(info.model, ModelPatchRaw):\n        raise ValueError(f\"LoRA {lora.lora.key} is not classified as a LoRA in the model manager\")","typeGuard":"from invokeai.backend.patches.model_patch_raw import ModelPatchRaw\n\ndef is_lora_patch(model: object) -> bool:\n    return isinstance(model, ModelPatchRaw)","tryCatchPattern":"try:\n    output = krea2_text_encoder.invoke(context)\nexcept TypeError as e:\n    if \"Expected ModelPatchRaw\" in str(e):\n        bad_key = str(e).split(\"'\")[1]\n        logger.error(f\"Model {bad_key} is not a LoRA; re-import it as a LoRA in the Model Manager.\")\n        raise\n    raise","preventionTips":["Import LoRA files through the Model Manager so they are correctly classified as type 'lora'.","Never connect main-model/checkpoint entries to LoRA input sockets in workflows.","Rescan the models directory after manually moving or renaming LoRA files.","After InvokeAI upgrades, verify old model records still resolve to ModelPatchRaw."],"tags":["type-error","lora","model-manager","configuration"],"backgroundTag":"wrong-model-type-loaded","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}