invoke-ai/InvokeAI · error · TypeError
Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
Error message
Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type(lora_info.model).__name__}. The LoRA model may be corrupted or incompatible. What it means
When applying LoRAs to the Qwen3 text encoder, _lora_iterator loads each LoRA model and requires the loaded object to be a ModelPatchRaw (InvokeAI's raw patch representation). Any other loaded type means the file is not a usable Anima LoRA patch, so it raises a TypeError suggesting the model is corrupted or incompatible.
Source
Thrown at invokeai/app/invocations/anima_text_encoder.py:215
context.util.signal_progress("Tokenizing with T5-XXL")
t5_tokenizer = load_bundled_t5_tokenizer()
t5_tokens = t5_tokenizer(
prompt,
padding=False,
truncation=True,
max_length=T5_MAX_SEQ_LEN,
return_tensors="pt",
)
t5xxl_ids = t5_tokens.input_ids[0] # Shape: (seq_len,)
return qwen3_embeds, t5xxl_ids, None
def _lora_iterator(self, context: InvocationContext) -> Iterator[PatchSpec]:
"""Iterate over LoRA models to apply to the Qwen3 text encoder."""
for lora in self.qwen3_encoder.loras:
lora_info = context.models.load(lora.lora)
if not isinstance(lora_info.model, ModelPatchRaw):
raise TypeError(
f"Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type(lora_info.model).__name__}. "
"The LoRA model may be corrupted or incompatible."
)
yield (lora_info.model, lora.weight, lora_info.model_in_ram())
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Re-import the LoRA with the correct model type (LoRA patch) in the model manager.
- Replace the LoRA file with a fresh download and re-scan models.
- Remove the LoRA from the qwen3_encoder loras list if it is not a Qwen3/Anima-compatible patch.
Defensive patterns
Strategy: type-guard
Validate before calling
from invokeai.backend.model_manager.load import ModelPatchRaw
info = context.models.load(lora.lora)
if not isinstance(info.model, ModelPatchRaw):
print(f"{lora.lora.key} is {type(info.model).__name__}, not a LoRA patch") Type guard
from invokeai.backend.model_manager.load import ModelPatchRaw
def is_lora_patch(info) -> bool:
return isinstance(info.model, ModelPatchRaw) Try / catch
try:
result = invocation.invoke(context)
except TypeError as e:
if "Expected ModelPatchRaw for LoRA" in str(e):
reimport_lora_with_correct_model_type(e)
else:
raise Prevention
- Import LoRAs with the correct model type (LoRA patch), not as checkpoints.
- Re-download LoRA files that fail to parse; verify integrity after download.
- Check base-model compatibility before attaching a LoRA to a Qwen3 encoder.
When it happens
Trigger: During invoke → _encode_prompt → _lora_iterator, when context.models.load(lora.lora).model is not an instance of ModelPatchRaw — e.g. the model record was imported with the wrong model type or the file is not a valid LoRA patch.
Common situations: Importing a checkpoint or full-model file as a LoRA; a LoRA trained for another base leaking into the qwen3_encoder list with mismatched metadata; corrupted download that parses as a different object type.
Related errors
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- LoRA "{lora_key}" already applied to transformer.
- LoRA "{lora_key}" already applied to Qwen3 encoder.
- Unknown lora: {lora.lora.key}!
- LoRA '{lora.lora.key}' is for {lora.lora.base.value if lora.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/c07685fa69b95052.
Report an issue: GitHub.