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
_lora_iterator throws this TypeError when a LoRA listed on the Mistral encoder input loads as something other than a ModelPatchRaw. ModelPatchRaw is the internal representation LoRA application expects; any other object means the model file is corrupted or incompatible with LoRA patching. The message identifies the offending LoRA key and the actual loaded type.
Source
Thrown at invokeai/app/invocations/flux2_dev_text_encoder.py:248
f"layers {DEV_EXTRACTION_LAYERS} and requires at least {max(DEV_EXTRACTION_LAYERS)}. "
"This is not a supported FLUX.2 [dev] text encoder."
)
extraction_layers = DEV_EXTRACTION_LAYERS
# Concatenate the selected layers along the hidden dim: (B, seq, 3 * hidden_size).
# This is byte-identical to stack(dim=1).permute(0,2,1,3).reshape(...) but avoids
# the two intermediate full copies that stack + permute-reshape would allocate.
prompt_embeds = torch.cat([outputs.hidden_states[i] for i in extraction_layers], dim=-1)
prompt_embeds = prompt_embeds.to(dtype=text_encoder.dtype, device=device)
return prompt_embeds
def _lora_iterator(self, context: InvocationContext) -> Iterator[Tuple[ModelPatchRaw, float]]:
"""Iterate over LoRAs to apply to the Mistral encoder."""
for lora in self.mistral_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)
del lora_info
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Re-download the LoRA file referenced by the reported key and re-import it into the model manager.
- Confirm the wired model is actually a LoRA compatible with the Mistral encoder, not another model type.
- Remove the problematic LoRA from the encoder's LoRA list and retry.
Defensive patterns
Strategy: type-guard
Validate before calling
lora_info = context.models.load(lora.lora)
if not isinstance(lora_info.model, ModelPatchRaw):
raise TypeError(f"LoRA {lora.lora.key} loaded as {type(lora_info.model).__name__}, expected ModelPatchRaw") Type guard
def is_lora_patch(model) -> bool:
return isinstance(model, ModelPatchRaw) Try / catch
try:
output = text_encoder_invocation.invoke(context)
except TypeError as e:
if "Expected ModelPatchRaw for LoRA" in str(e):
remove_bad_loras(context)
output = text_encoder_invocation.invoke(context)
else:
raise Prevention
- Validate LoRA files import correctly in the Model Manager before use.
- Only wire LoRA models into LoRA inputs.
- Re-download LoRAs that fail to load as ModelPatchRaw.
When it happens
Trigger: invoke() -> _encode_prompt -> _lora_iterator iterates mistral_encoder.loras, and context.models.load(lora.lora).model is not an instance of ModelPatchRaw.
Common situations: A corrupted or wrong-format LoRA file is attached to the FLUX.2 [dev] text encoder's LoRA list, or a non-LoRA model was mistakenly wired into the LoRA input.
Related errors
- Expected PreTrainedModel for text encoder, got {type(text_en
- Expected ModelPatchRaw for LoRA '{lora.lora.key}', got {type
- LoRA '{lora_config.name}' is a FLUX.2 [dev] LoRA and cannot
- Unknown lora: {lora_key}!
- LoRA "{lora_key}" already applied to transformer.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/36d551bb67164471.
Report an issue: GitHub.