invoke-ai/InvokeAI · error · ValueError
{layer_key} not expected
Error message
{layer_key} not expected What it means
lora_model_from_flux_control_state_dict maps each FLUX Control LoRA layer to an InvokeAI patch layer. After handling known layer kinds (lora A/B weights, bias, 'scale'), any layer whose state dict contains none of the expected entries triggers this ValueError. It's a strict-format guard for FLUX Control LoRA state dicts.
Source
Thrown at invokeai/backend/patches/lora_conversions/flux_control_lora_utils.py:84
layers[prefixed_key] = FluxControlLoRALayer(
layer_state_dict["lora_B.weight"],
None,
layer_state_dict["lora_A.weight"],
None,
layer_state_dict["lora_B.bias"],
)
elif all(k in layer_state_dict for k in ["lora_A.weight", "lora_B.bias", "lora_B.weight"]):
layers[prefixed_key] = LoRALayer(
layer_state_dict["lora_B.weight"],
None,
layer_state_dict["lora_A.weight"],
None,
layer_state_dict["lora_B.bias"],
)
elif "scale" in layer_state_dict:
layers[prefixed_key] = SetParameterLayer("scale", layer_state_dict["scale"])
else:
raise ValueError(f"{layer_key} not expected")
return ModelPatchRaw(layers=layers)
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Identify the offending layer_key and either remove it from the state dict (if it's a harmless extra tensor) before calling the converter.
- Add a branch in flux_control_lora_utils.py mapping the new key type to the appropriate layer, then upstream the fix.
- Confirm the LoRA is actually a FLUX Control LoRA and use the matching converter (kohya/diffusers/onetrainer/xlabs) otherwise.
Defensive patterns
Strategy: validation
Validate before calling
for key, lsd in state_dict.items():
if not ("lora_A" in lsd or "lora_B" in lsd or "scale" in lsd or "bias" in str(lsd.keys())):
print(f"unexpected control-lora layer {key}: {sorted(lsd.keys())}") Type guard
def is_expected_control_layer(lsd: dict) -> bool:
return any(k in lsd for k in ("lora_A.weight", "lora_B.weight", "scale")) Try / catch
try:
patch = lora_model_from_flux_control_state_dict(sd, model)
except ValueError as e:
logger.error("FLUX Control LoRA conversion failed: %s", e)
patch = None Prevention
- Only feed genuine FLUX Control LoRA checkpoints to this converter.
- Pre-scan state dicts for unknown key types when migrating to new trainer versions.
- Keep InvokeAI updated to cover new Control LoRA key types.
When it happens
Trigger: Calling lora_model_from_flux_control_state_dict with a state dict containing a layer key whose layer_state_dict lacks lora_A/lora_B weights, bias, and 'scale' entries - e.g. an unexpected extra tensor like a norm alpha or a new param type added by a newer exporter.
Common situations: Newer FLUX Control LoRA checkpoints that add key types the converter doesn't know; truncated or manually edited safetensors files; mixing keys from a non-Control FLUX LoRA into this converter.
Related errors
- LoRA model is in unsupported FLUX format
- Unknown lora: {lora_key}!
- LoRA "{lora_key}" already applied to transformer.
- LoRA "{lora_key}" already applied to CLIP encoder.
- LoRA "{lora_key}" already applied to T5 encoder.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/ea6e8228b9037b6b.
Report an issue: GitHub.