{"record":{"id":"98573095593408a6","repo":"invoke-ai/InvokeAI","slug":"unrecognized-sdxl-lora-key-prefix-full-key","errorCode":null,"errorMessage":"Unrecognized SDXL LoRA key prefix: '{full_key}'.","messagePattern":"Unrecognized SDXL LoRA key prefix: '(.+?)'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/patches/lora_conversions/sdxl_lora_conversion_utils.py","lineNumber":54,"sourceCode":"        if full_key.startswith(\"lora_unet_\"):\n            search_key = full_key.replace(\"lora_unet_\", \"\")\n            # Use bisect to find the key in stability_unet_keys that *may* match the search_key's prefix.\n            position = bisect.bisect_right(stability_unet_keys, search_key)\n            map_key = stability_unet_keys[position - 1]\n            # Now, check if the map_key *actually* matches the search_key.\n            if search_key.startswith(map_key):\n                new_key = full_key.replace(map_key, SDXL_UNET_STABILITY_TO_DIFFUSERS_MAP[map_key])\n                new_state_dict[new_key] = value\n                converted_count += 1\n            else:\n                new_state_dict[full_key] = value\n                not_converted_count += 1\n        elif full_key.startswith(\"lora_te1_\") or full_key.startswith(\"lora_te2_\"):\n            # The CLIP text encoders have the same keys in both Stability AI and diffusers formats.\n            new_state_dict[full_key] = value\n            continue\n        else:\n            raise ValueError(f\"Unrecognized SDXL LoRA key prefix: '{full_key}'.\")\n\n    if converted_count > 0 and not_converted_count > 0:\n        raise ValueError(\n            f\"The SDXL LoRA could only be partially converted to diffusers format. converted={converted_count},\"\n            f\" not_converted={not_converted_count}\"\n        )\n\n    return new_state_dict\n\n\n# code from\n# https://github.com/bmaltais/kohya_ss/blob/2accb1305979ba62f5077a23aabac23b4c37e935/networks/lora_diffusers.py#L15C1-L97C32\ndef _make_sdxl_unet_conversion_map() -> List[Tuple[str, str]]:\n    \"\"\"Create a dict mapping state_dict keys from Stability AI SDXL format to diffusers SDXL format.\"\"\"\n    unet_conversion_map_layer: list[tuple[str, str]] = []\n\n    for i in range(3):  # num_blocks is 3 in sdxl\n        # loop over downblocks/upblocks","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/patches/lora_conversions/sdxl_lora_conversion_utils.py#L36-L72","documentation":"convert_sdxl_keys_to_diffusers_format recognizes SDXL LoRA keys only with known prefixes (lora_, lora_te1_, lora_te2_, etc.). Any key with an unrecognized prefix causes this ValueError, because the converter cannot know which model component the tensor targets.","triggerScenarios":"Calling convert_sdxl_keys_to_diffusers_format (via the SDXL LoRA _load_model path) with a state dict containing a key that starts with none of the supported prefixes, e.g. an unrelated model's key or a novel trainer's naming scheme.","commonSituations":"Loading an SD1/SD3/Flux LoRA with the SDXL converter; files with custom or vendor-specific prefixes; renamed/mangled keys from a state-dict preprocessing step; LyCORIS keys with unusual module names.","solutions":["Print the offending key and confirm the file is actually an SDXL LoRA; if not, load it with the converter for its real base model.","Rename the key to a supported prefix (e.g. 'lora_unet_...' or 'lora_te_...') matching the SDXL convention.","Update/patch the conversion utility to handle the new prefix if the trainer's format is legitimately new."],"exampleFix":"// before\n'my_custom_model.blocks.0.lora_down.weight': t\n// after (SDXL convention)\n'lora_unet_blocks_0_lora_down.weight': t","handlingStrategy":"validation","validationCode":"SUPPORTED = ('lora_', 'lora_te1_', 'lora_te2_')\nbad = [k for k in state_dict if not any(k.startswith(p) for p in SUPPORTED)]\nif bad:\n    raise ValueError(f'keys with unsupported prefixes: {bad[:5]}')","typeGuard":"def is_sdxl_lora_state_dict(state_dict: dict[str, object]) -> bool:\n    return all(isinstance(k, str) and k.startswith(('lora_', 'lora_te1_', 'lora_te2_')) for k in state_dict)","tryCatchPattern":"try:\n    sd = convert_sdxl_keys_to_diffusers_format(state_dict)\nexcept ValueError as e:\n    if str(e).startswith('Unrecognized SDXL LoRA key prefix'):\n        logger.error('Wrong model family or mangled key: %s', e)\n        # route to the correct converter for the file's base model\n    else:\n        raise","preventionTips":["Confirm the file's base model (SD1/SDXL/Flux) before choosing a converter.","Inspect a few keys of every downloaded LoRA before loading.","Do not rename keys ad hoc; follow the SDXL prefix conventions."],"tags":["lora","sdxl","key-format","unrecognized-prefix"],"backgroundTag":"unsupported-key-format","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}