invoke-ai/InvokeAI · error · ValueError

LoRA "{lora_key}" already applied to Qwen3 encoder.

Error message

LoRA "{lora_key}" already applied to Qwen3 encoder.

What it means

The Flux2Klein LoRA loader raised ValueError because the LoRA key already exists in the Qwen3 text encoder's attached LoRA list. The library throws it to avoid applying the same text-encoder LoRA twice to the Qwen3 encoder. Like its transformer counterpart, it is a fail-fast duplicate guard in invoke().

Source

Thrown at invokeai/app/invocations/flux2_klein_lora_loader.py:106

        # Reject cross-family (dev) LoRAs regardless of which input they're wired to.
        _assert_not_dev_lora(context, lora_config)

        # Warn if LoRA variant doesn't match transformer variant (intra-Klein 4B/9B).
        lora_variant = getattr(lora_config, "variant", None)
        if lora_variant and self.transformer is not None:
            transformer_config = context.models.get_config(self.transformer.transformer.key)
            transformer_variant = getattr(transformer_config, "variant", None)
            if transformer_variant and lora_variant != transformer_variant:
                context.logger.warning(
                    f"LoRA variant mismatch: LoRA '{lora_config.name}' is for {lora_variant.value} "
                    f"but transformer is {transformer_variant.value}. This may cause shape errors."
                )

        # Check for existing LoRAs with the same key.
        if self.transformer and any(lora.lora.key == lora_key for lora in self.transformer.loras):
            raise ValueError(f'LoRA "{lora_key}" already applied to transformer.')
        if self.qwen3_encoder and any(lora.lora.key == lora_key for lora in self.qwen3_encoder.loras):
            raise ValueError(f'LoRA "{lora_key}" already applied to Qwen3 encoder.')

        output = Flux2KleinLoRALoaderOutput()

        # Attach LoRA layers to the models.
        if self.transformer is not None:
            output.transformer = self.transformer.model_copy(deep=True)
            output.transformer.loras.append(
                LoRAField(
                    lora=self.lora,
                    weight=self.weight,
                )
            )
        if self.qwen3_encoder is not None:
            output.qwen3_encoder = self.qwen3_encoder.model_copy(deep=True)
            output.qwen3_encoder.loras.append(
                LoRAField(
                    lora=self.lora,
                    weight=self.weight,

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Deduplicate the LoRA list supplied to the loader node before invoking
  2. Reset or deep-copy the qwen3_encoder before each invocation so its loras list starts empty
  3. Only wire one loader node per LoRA into the encoder
  4. Catch ValueError and filter out the already-applied key, then retry

Example fix

// before
output = loader.invoke(context)  # second run, qwen3_encoder.loras still has lora_x
// after
loader.qwen3_encoder = loader.qwen3_encoder.model_copy(deep=True)
loader.qwen3_encoder.loras = [l for l in loader.qwen3_encoder.loras if l.lora.key != lora_x]
output = loader.invoke(context)
Defensive patterns

Strategy: validation

Validate before calling

keys = [l.lora.key for l in loader_input_loras]
if any(l.lora.key in keys for l in qwen3_encoder.loras):
    raise ValueError("duplicate LoRA for Qwen3 encoder")

Type guard

def encoder_accepts(key: str, qwen3_encoder) -> bool:
    return not any(l.lora.key == key for l in qwen3_encoder.loras)

Try / catch

try:
    output = loader.invoke(context)
except ValueError as e:
    if 'already applied to Qwen3 encoder' in str(e):
        loader.qwen3_encoder.loras = []
        output = loader.invoke(context)
    else:
        raise

Prevention

When it happens

Trigger: Calling invoke() when self.qwen3_encoder is set and any(lora.lora.key == lora_key for lora in self.qwen3_encoder.loras) is true — the same LoRA key was already attached to the Qwen3 encoder's loras list.

Common situations: Duplicate LoRA entries in the node's input collection; re-invoking a loader whose qwen3_encoder still carries LoRAs from a previous run; two loader nodes applying the same text-encoder LoRA to one encoder.

Related errors


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