{"record":{"id":"0689b885a670d3d5","repo":"invoke-ai/InvokeAI","slug":"layer-layer-name-does-not-match-the-expected-p-0689b8","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_onetrainer_lora_conversion_utils.py","lineNumber":81,"sourceCode":"    for key, value in state_dict.items():\n        layer_name, param_name = key.split(\".\", 1)\n        if layer_name not in grouped_state_dict:\n            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_transformer\"):\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    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    # Handle the transformer.\n    transformer_layers = _convert_flux_transformer_onetrainer_state_dict_to_invoke_format(transformer_grouped_sd)\n    layers.update(transformer_layers)","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/patches/lora_conversions/flux_onetrainer_lora_conversion_utils.py#L63-L99","documentation":"lora_model_from_flux_onetrainer_state_dict groups OneTrainer FLUX LoRA keys into transformer/CLIP/T5 by prefix (lora_unet_/lora_te1_/lora_te2_). A layer name with none of those prefixes raises ValueError with the same message as the Kohya path, since both share the grouping convention.","triggerScenarios":"Loading a OneTrainer FLUX LoRA whose top-level layer key has an unexpected prefix (SD-style 'lora_te', 'lora_unet' misspelled, or non-FLUX architecture keys).","commonSituations":"Loading an SD1.5/SDXL LoRA through the FLUX OneTrainer loader; OneTrainer version changes introducing new prefixes; stray keys (e.g. 'lora_prior') in the file.","solutions":["Check the layer_name prefix; use the converter matching the model family the LoRA was trained for.","Filter out unexpected keys before calling the loader.","Update to an InvokeAI version that supports the new OneTrainer prefix, or strip/rename keys accordingly."],"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\"keys outside OneTrainer FLUX convention: {bad[:5]}\"","typeGuard":"def is_flux_onetrainer_key(k: str) -> bool:\n    return k.startswith((\"lora_unet_\", \"lora_te1_\", \"lora_te2_\"))","tryCatchPattern":"try:\n    lora = lora_model_from_flux_onetrainer_state_dict(sd, model)\nexcept ValueError as e:\n    logger.error(\"OneTrainer FLUX LoRA unexpected layer: %s\", e)\n    lora = None","preventionTips":["Confirm the LoRA targets FLUX before using the OneTrainer FLUX loader.","Inspect key prefixes after loading the file.","Filter stray/non-model keys before conversion."],"tags":["lora","flux","onetrainer","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"}