{"record":{"id":"ea6e8228b9037b6b","repo":"invoke-ai/InvokeAI","slug":"layer-key-not-expected","errorCode":null,"errorMessage":"{layer_key} not expected","messagePattern":"(.+?) not expected","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/patches/lora_conversions/flux_control_lora_utils.py","lineNumber":84,"sourceCode":"            layers[prefixed_key] = FluxControlLoRALayer(\n                layer_state_dict[\"lora_B.weight\"],\n                None,\n                layer_state_dict[\"lora_A.weight\"],\n                None,\n                layer_state_dict[\"lora_B.bias\"],\n            )\n        elif all(k in layer_state_dict for k in [\"lora_A.weight\", \"lora_B.bias\", \"lora_B.weight\"]):\n            layers[prefixed_key] = LoRALayer(\n                layer_state_dict[\"lora_B.weight\"],\n                None,\n                layer_state_dict[\"lora_A.weight\"],\n                None,\n                layer_state_dict[\"lora_B.bias\"],\n            )\n        elif \"scale\" in layer_state_dict:\n            layers[prefixed_key] = SetParameterLayer(\"scale\", layer_state_dict[\"scale\"])\n        else:\n            raise ValueError(f\"{layer_key} not expected\")\n\n    return ModelPatchRaw(layers=layers)\n","sourceCodeStart":66,"sourceCodeEnd":87,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/patches/lora_conversions/flux_control_lora_utils.py#L66-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for key, lsd in state_dict.items():\n    if not (\"lora_A\" in lsd or \"lora_B\" in lsd or \"scale\" in lsd or \"bias\" in str(lsd.keys())):\n        print(f\"unexpected control-lora layer {key}: {sorted(lsd.keys())}\")","typeGuard":"def is_expected_control_layer(lsd: dict) -> bool:\n    return any(k in lsd for k in (\"lora_A.weight\", \"lora_B.weight\", \"scale\"))","tryCatchPattern":"try:\n    patch = lora_model_from_flux_control_state_dict(sd, model)\nexcept ValueError as e:\n    logger.error(\"FLUX Control LoRA conversion failed: %s\", e)\n    patch = None","preventionTips":["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."],"tags":["lora","flux","state-dict","unexpected-key"],"backgroundTag":"unsupported-lora-key-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}