{"record":{"id":"b4bd4cb934926534","repo":"invoke-ai/InvokeAI","slug":"lora-lora-key-already-applied-to-qwen3-encoder-b4bd4c","errorCode":null,"errorMessage":"LoRA \"{lora_key}\" already applied to Qwen3 encoder.","messagePattern":"LoRA \"(.+?)\" already applied to Qwen3 encoder\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/flux2_klein_lora_loader.py","lineNumber":106,"sourceCode":"        # Reject cross-family (dev) LoRAs regardless of which input they're wired to.\n        _assert_not_dev_lora(context, lora_config)\n\n        # Warn if LoRA variant doesn't match transformer variant (intra-Klein 4B/9B).\n        lora_variant = getattr(lora_config, \"variant\", None)\n        if lora_variant and self.transformer is not None:\n            transformer_config = context.models.get_config(self.transformer.transformer.key)\n            transformer_variant = getattr(transformer_config, \"variant\", None)\n            if transformer_variant and lora_variant != transformer_variant:\n                context.logger.warning(\n                    f\"LoRA variant mismatch: LoRA '{lora_config.name}' is for {lora_variant.value} \"\n                    f\"but transformer is {transformer_variant.value}. This may cause shape errors.\"\n                )\n\n        # Check for existing LoRAs with the same key.\n        if self.transformer and any(lora.lora.key == lora_key for lora in self.transformer.loras):\n            raise ValueError(f'LoRA \"{lora_key}\" already applied to transformer.')\n        if self.qwen3_encoder and any(lora.lora.key == lora_key for lora in self.qwen3_encoder.loras):\n            raise ValueError(f'LoRA \"{lora_key}\" already applied to Qwen3 encoder.')\n\n        output = Flux2KleinLoRALoaderOutput()\n\n        # Attach LoRA layers to the models.\n        if self.transformer is not None:\n            output.transformer = self.transformer.model_copy(deep=True)\n            output.transformer.loras.append(\n                LoRAField(\n                    lora=self.lora,\n                    weight=self.weight,\n                )\n            )\n        if self.qwen3_encoder is not None:\n            output.qwen3_encoder = self.qwen3_encoder.model_copy(deep=True)\n            output.qwen3_encoder.loras.append(\n                LoRAField(\n                    lora=self.lora,\n                    weight=self.weight,","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux2_klein_lora_loader.py#L88-L124","documentation":"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().","triggerScenarios":"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.","commonSituations":"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.","solutions":["Deduplicate the LoRA list supplied to the loader node before invoking","Reset or deep-copy the qwen3_encoder before each invocation so its loras list starts empty","Only wire one loader node per LoRA into the encoder","Catch ValueError and filter out the already-applied key, then retry"],"exampleFix":"// before\noutput = loader.invoke(context)  # second run, qwen3_encoder.loras still has lora_x\n// after\nloader.qwen3_encoder = loader.qwen3_encoder.model_copy(deep=True)\nloader.qwen3_encoder.loras = [l for l in loader.qwen3_encoder.loras if l.lora.key != lora_x]\noutput = loader.invoke(context)","handlingStrategy":"validation","validationCode":"keys = [l.lora.key for l in loader_input_loras]\nif any(l.lora.key in keys for l in qwen3_encoder.loras):\n    raise ValueError(\"duplicate LoRA for Qwen3 encoder\")","typeGuard":"def encoder_accepts(key: str, qwen3_encoder) -> bool:\n    return not any(l.lora.key == key for l in qwen3_encoder.loras)","tryCatchPattern":"try:\n    output = loader.invoke(context)\nexcept ValueError as e:\n    if 'already applied to Qwen3 encoder' in str(e):\n        loader.qwen3_encoder.loras = []\n        output = loader.invoke(context)\n    else:\n        raise","preventionTips":["Reset or copy the qwen3_encoder before each loader run","Filter loader inputs against encoder.loras keys beforehand","Avoid feeding the same LoRA through multiple loader nodes into one encoder"],"tags":["lora","duplicate","qwen3-encoder","invokeai"],"backgroundTag":"duplicate-lora-applied","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}