{"record":{"id":"f63bcc3a3073764b","repo":"invoke-ai/InvokeAI","slug":"layer-layer-name-does-not-match-the-expected-p","errorCode":null,"errorMessage":"Layer '{layer_name}' does not match the expected pattern for FLUX LoRA weights.","messagePattern":"Layer '(.+?)' does not match the expected pattern for FLUX LoRA weights\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/patches/lora_conversions/flux_kohya_lora_conversion_utils.py","lineNumber":87,"sourceCode":"            grouped_state_dict[layer_name] = {}\n        grouped_state_dict[layer_name][param_name] = value\n\n    # Split the grouped state dict into transformer, CLIP, and T5 state dicts.\n    transformer_grouped_sd: dict[str, dict[str, torch.Tensor]] = {}\n    clip_grouped_sd: dict[str, dict[str, torch.Tensor]] = {}\n    t5_grouped_sd: dict[str, dict[str, torch.Tensor]] = {}\n    for layer_name, layer_state_dict in grouped_state_dict.items():\n        if layer_name.startswith(\"lora_unet\"):\n            # Skip the final layer. This is incompatible with current model definition.\n            if layer_name.startswith(\"lora_unet_final_layer\"):\n                continue\n            transformer_grouped_sd[layer_name] = layer_state_dict\n        elif layer_name.startswith(\"lora_te1\"):\n            clip_grouped_sd[layer_name] = layer_state_dict\n        elif layer_name.startswith(\"lora_te2\"):\n            t5_grouped_sd[layer_name] = layer_state_dict\n        else:\n            raise ValueError(f\"Layer '{layer_name}' does not match the expected pattern for FLUX LoRA weights.\")\n\n    # Convert the state dicts to the InvokeAI format.\n    transformer_grouped_sd = _convert_flux_transformer_kohya_state_dict_to_invoke_format(transformer_grouped_sd)\n    clip_grouped_sd = _convert_flux_clip_kohya_state_dict_to_invoke_format(clip_grouped_sd)\n    t5_grouped_sd = _convert_flux_t5_kohya_state_dict_to_invoke_format(t5_grouped_sd)\n\n    # Create LoRA layers.\n    layers: dict[str, BaseLayerPatch] = {}\n    for model_prefix, grouped_sd in [\n        (FLUX_LORA_TRANSFORMER_PREFIX, transformer_grouped_sd),\n        (FLUX_LORA_CLIP_PREFIX, clip_grouped_sd),\n        (FLUX_LORA_T5_PREFIX, t5_grouped_sd),\n    ]:\n        for layer_key, layer_state_dict in grouped_sd.items():\n            layers[model_prefix + layer_key] = any_lora_layer_from_state_dict(layer_state_dict)\n\n    # Create and return the LoRAModelRaw.\n    return ModelPatchRaw(layers=layers)","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/patches/lora_conversions/flux_kohya_lora_conversion_utils.py#L69-L105","documentation":"lora_model_from_flux_kohya_state_dict partitions a Kohya FLUX LoRA state dict into transformer, CLIP, and T5 groups by key prefix (lora_unet_, lora_te1_, lora_te2_). Any top-level layer name starting with none of these prefixes raises ValueError. The LoRA file contains keys outside the Kohya FLUX convention.","triggerScenarios":"Loading a Kohya-format file where a layer key has an unexpected prefix (e.g. 'lora_te' from a single-text-encoder SD-style LoRA, 'lora_unet' misspelled, or SDXL/SD1.5 LoRA keys) passed to lora_model_from_flux_kohya_state_dict.","commonSituations":"Trying to load a Stable Diffusion / SDXL Kohya LoRA as a FLUX LoRA; a trainer emitting a new prefix convention; corrupted key names from manual renaming.","solutions":["Check the failing layer_name's prefix; if it's not a FLUX LoRA, use the correct converter/loader for the base model family.","Rename or strip the unexpected key if it's an extraneous entry (e.g. preview/metadata tensors leaking into the state dict).","Regenerate the LoRA with a FLUX-capable trainer version that uses lora_unet_/lora_te1_/lora_te2_ prefixes."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"bad = [k for k in state_dict if not k.startswith((\"lora_unet_\", \"lora_te1_\", \"lora_te2_\"))]\nassert not bad, f\"non-FLUX-kohya keys present: {bad[:5]}\"","typeGuard":"def is_flux_kohya_key(k: str) -> bool:\n    return k.startswith((\"lora_unet_\", \"lora_te1_\", \"lora_te2_\"))","tryCatchPattern":"try:\n    lora = lora_model_from_flux_kohya_state_dict(sd, model)\nexcept ValueError as e:\n    logger.error(\"Kohya FLUX LoRA has unexpected layer: %s\", e)\n    lora = None","preventionTips":["Verify the LoRA was trained for FLUX before using the FLUX kohya loader.","Inspect top-level key prefixes after loading safetensors.","Filter out metadata/preview tensors before conversion."],"tags":["lora","flux","kohya","key-prefix"],"backgroundTag":"unsupported-lora-key-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}