{"record":{"id":"7eb567d65e9b3597","repo":"invoke-ai/InvokeAI","slug":"lora-lora-key-already-applied-to-transformer-7eb567","errorCode":null,"errorMessage":"LoRA \"{lora_key}\" already applied to transformer.","messagePattern":"LoRA \"(.+?)\" already applied to transformer\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/flux2_klein_lora_loader.py","lineNumber":104,"sourceCode":"\n        lora_config = context.models.get_config(lora_key)\n        # 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(","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux2_klein_lora_loader.py#L86-L122","documentation":"The Flux2Klein LoRA loader invocation raised a ValueError because the given LoRA key is already present in the transformer's attached LoRA list. This library throws it to prevent the same LoRA from being applied twice to the FLUX.2 Klein transformer, which would double its weight contribution. It is a fail-fast duplicate-application guard inside invoke().","triggerScenarios":"Calling invoke() on Flux2KleinLoRALoader when self.transformer is set and any(lora.lora.key == lora_key for lora in self.transformer.loras) is true — i.e. the same LoRA model-key was already attached to the transformer's loras list earlier in the same graph run.","commonSituations":"Reusing a LoRA loader node across multiple graph executions without clearing state; the same LoRA referenced by two loader nodes feeding one transformer; loops that re-invoke the loader with an already-populated transformer.","solutions":["Ensure each LoRA key appears only once in the LoRA collection fed to this loader node","Remove the duplicate LoRA entry from the loader input before re-running invoke()","Use a fresh transformer/loRA list for each invocation instead of reusing a mutated one","Catch ValueError around invoke() and skip already-applied keys"],"exampleFix":"// before: same LoRA listed twice\nloras = [lora_a, lora_a]\noutput = loader.invoke(context)\n// after: dedupe by key first\nseen = set()\nloras = [l for l in [lora_a, lora_a] if not (l.key in seen or seen.add(l.key))]\noutput = loader.invoke(context)","handlingStrategy":"validation","validationCode":"keys = [l.lora.key for l in loader_input_loras]\ndupes = {k for k in keys if keys.count(k) > 1\n          and any(l.lora.key == k for l in transformer.loras)}\nif dupes:\n    raise ValueError(f\"LoRAs already applied to transformer: {dupes}\")","typeGuard":"def not_already_applied(key: str, transformer) -> bool:\n    return not any(l.lora.key == key for l in transformer.loras)","tryCatchPattern":"try:\n    output = loader.invoke(context)\nexcept ValueError as e:\n    if 'already applied to transformer' in str(e):\n        key = str(e).split('\"')[1]\n        loader.transformer.loras = [l for l in loader.transformer.loras if l.lora.key != key]\n        output = loader.invoke(context)\n    else:\n        raise","preventionTips":["Deduplicate the LoRA list by key before building the loader node","Deep-copy the transformer for each invocation so loras state never carries over","Wire one loader node per unique LoRA key in the graph"],"tags":["lora","duplicate","flux2-klein","invokeai"],"backgroundTag":"duplicate-lora-applied","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}