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
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.
Source
Thrown at invokeai/app/invocations/z_image_text_encoder.py:205
# Z-Image expects a 2D tensor [seq_len, hidden_dim] with only valid tokens
# Based on diffusers ZImagePipeline implementation:
# embeddings_list.append(prompt_embeds[i][prompt_masks[i]])
# Since batch_size=1, we take the first item and filter by mask
prompt_embeds = prompt_embeds[0][prompt_mask[0]]
if not isinstance(prompt_embeds, torch.Tensor):
raise TypeError(
f"Expected torch.Tensor for prompt embeddings, got {type(prompt_embeds).__name__}. "
"Text encoder returned unexpected type."
)
return prompt_embeds
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
- 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
Defensive patterns
Strategy: type-guard
Validate before calling
lora_info = context.models.load(lora.lora) assert isinstance(lora_info.model, ModelPatchRaw), type(lora_info.model)
Type guard
from invokeai.backend.model_manager.load.model_util import ModelPatchRaw # adjust import to project
def is_valid_lora(obj) -> bool:
return isinstance(obj, ModelPatchRaw) Try / catch
try:
patches = list(self._lora_iterator(context))
except TypeError as e:
if 'ModelPatchRaw' in str(e):
logger.error(f"Skipping incompatible LoRA: {e}")
else:
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- Unsupported control_lllite type: {type(control_lllite)}
- Expected AutoencoderKLWan or FluxAutoEncoder for Anima VAE,
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- Unknown lora: {lora_key}!
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/58a878a30eb68ac7.
Report an issue: GitHub.