invoke-ai/InvokeAI · error · ValueError

Key '{key}' does not match the expected pattern for xlabs FL

Error message

Key '{key}' does not match the expected pattern for xlabs FLUX LoRA weights.

What it means

lora_model_from_flux_xlabs_state_dict expects every key to match FLUX_XLABS_KEY_REGEX, which encodes block index, component (qkv/proj), lora stream (1/2), and direction (down/up). Any non-conforming key raises ValueError before grouping. The file is not a valid xlabs FLUX LoRA.

Source

Thrown at invokeai/backend/patches/lora_conversions/flux_xlabs_lora_conversion_utils.py:67

    The xlabs format uses:
    - lora1 for image attention stream (img_attn)
    - lora2 for text attention stream (txt_attn)
    - qkv for query/key/value projection
    - proj for output projection

    Key mapping:
    - double_blocks.X.processor.qkv_lora1 -> double_blocks.X.img_attn.qkv
    - double_blocks.X.processor.proj_lora1 -> double_blocks.X.img_attn.proj
    - double_blocks.X.processor.qkv_lora2 -> double_blocks.X.txt_attn.qkv
    - double_blocks.X.processor.proj_lora2 -> double_blocks.X.txt_attn.proj
    """
    # Group keys by layer (without the .down.weight/.up.weight suffix)
    grouped_state_dict: dict[str, dict[str, torch.Tensor]] = {}

    for key, value in state_dict.items():
        match = re.match(FLUX_XLABS_KEY_REGEX, key)
        if not match:
            raise ValueError(f"Key '{key}' does not match the expected pattern for xlabs FLUX LoRA weights.")

        block_idx = match.group(1)
        component = match.group(2)  # qkv or proj
        lora_stream = match.group(3)  # 1 or 2
        direction = match.group(4)  # down or up

        # Map lora1 -> img_attn, lora2 -> txt_attn
        attn_type = "img_attn" if lora_stream == "1" else "txt_attn"

        # Create the InvokeAI-style layer key
        layer_key = f"double_blocks.{block_idx}.{attn_type}.{component}"

        if layer_key not in grouped_state_dict:
            grouped_state_dict[layer_key] = {}

        # Map down/up to lora_down/lora_up
        param_name = f"lora_{direction}.weight"
        grouped_state_dict[layer_key][param_name] = value

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Confirm the LoRA really is the xlabs format; if it's Kohya/diffusers/OneTrainer, call the matching converter instead.
  2. Compare the failing key to FLUX_XLABS_KEY_REGEX and fix or filter non-conforming keys before conversion.
  3. Re-export the LoRA using xlabs tooling so keys follow the expected pattern.
Defensive patterns

Strategy: validation

Validate before calling

import re
from invokeai.backend.patches.lora_conversions.flux_xlabs_lora_conversion_utils import FLUX_XLABS_KEY_REGEX
bad = [k for k in state_dict if not re.match(FLUX_XLABS_KEY_REGEX, k)]
assert not bad, f"keys not matching xlabs pattern: {bad[:5]}"

Type guard

def is_xlabs_key(k: str) -> bool:
    return bool(re.match(FLUX_XLABS_KEY_REGEX, k))

Try / catch

try:
    lora = lora_model_from_flux_xlabs_state_dict(sd, model)
except ValueError as e:
    logger.error("not an xlabs FLUX LoRA: %s", e)
    lora = None

Prevention

When it happens

Trigger: Passing a state dict with keys not matching the xlabs pattern (e.g. Kohya 'lora_unet_...' keys, diffusers 'transformer...' keys, or truncated xlabs keys missing the .down.weight/.up.weight suffix) to lora_model_from_flux_xlabs_state_dict.

Common situations: Using the xlabs converter on a diffusers/kohya FLUX LoRA (wrong converter choice); xlabs tooling version differences renaming keys; manual key editing or partial extraction from a safetensors file.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/0ab6e603568c604a. Report an issue: GitHub.