{"record":{"id":"5f6b0eaaa2c12cbc","repo":"invoke-ai/InvokeAI","slug":"lora-lora-key-already-applied-to-mistral-encod","errorCode":null,"errorMessage":"LoRA \"{lora_key}\" already applied to Mistral encoder.","messagePattern":"LoRA \"(.+?)\" already applied to Mistral encoder\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/flux2_dev_lora_loader.py","lineNumber":104,"sourceCode":"        input=Input.Connection,\n    )\n\n    def invoke(self, context: InvocationContext) -> Flux2DevLoRALoaderOutput:\n        lora_key = self.lora.key\n        if not context.models.exists(lora_key):\n            raise ValueError(f\"Unknown lora: {lora_key}!\")\n\n        lora_config = context.models.get_config(lora_key)\n\n        # Reject variant-mismatched LoRAs regardless of which input they're wired to. A Klein\n        # LoRA on a dev transformer/encoder is guaranteed to shape-error during denoise.\n        _assert_dev_lora(context, lora_config)\n\n        # Check for duplicate keys.\n        if self.transformer and any(existing.lora.key == lora_key for existing in self.transformer.loras):\n            raise ValueError(f'LoRA \"{lora_key}\" already applied to transformer.')\n        if self.mistral_encoder and any(existing.lora.key == lora_key for existing in self.mistral_encoder.loras):\n            raise ValueError(f'LoRA \"{lora_key}\" already applied to Mistral encoder.')\n\n        output = Flux2DevLoRALoaderOutput()\n        if self.transformer is not None:\n            output.transformer = self.transformer.model_copy(deep=True)\n            output.transformer.loras.append(LoRAField(lora=self.lora, weight=self.weight))\n        if self.mistral_encoder is not None:\n            output.mistral_encoder = self.mistral_encoder.model_copy(deep=True)\n            output.mistral_encoder.loras.append(LoRAField(lora=self.lora, weight=self.weight))\n        return output\n\n\n@invocation(\n    \"flux2_dev_lora_collection_loader\",\n    title=\"Apply LoRA Collection - FLUX.2 [dev]\",\n    tags=[\"lora\", \"model\", \"flux\", \"flux2\", \"dev\"],\n    category=\"model\",\n    version=\"1.0.0\",\n    classification=Classification.Prototype,","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux2_dev_lora_loader.py#L86-L122","documentation":"Same duplicate-key guard as the transformer, but checked against self.mistral_encoder.loras. The dev loader can attach LoRAs to both the transformer and the Mistral text encoder; loading a LoRA with an already-present key into the encoder raises ValueError.","triggerScenarios":"Chaining Flux2DevLoRALoaderInvocations where a LoRA already applied to the Mistral encoder is applied to the encoder again; same key fed to the mistral_encoder input twice.","commonSituations":"Copying an encoder loader node and leaving the same LoRA selected; looped graphs re-applying encoder LoRAs.","solutions":["Remove the duplicate encoder LoRA loader node from the chain","Increase the weight on the existing single encoder LoRA instead of adding another","Deduplicate by key before building the chain: skip any lora whose key already exists in mistral_encoder.loras"],"exampleFix":"# before\nenc = Flux2DevLoRALoaderInvocation(lora=loraA, mistral_encoder=enc).mistral_encoder\nenc = Flux2DevLoRALoaderInvocation(lora=loraA, mistral_encoder=enc).mistral_encoder  # duplicate\n# after\nenc = Flux2DevLoRALoaderInvocation(lora=loraA, weight=1.2, mistral_encoder=enc).mistral_encoder","handlingStrategy":"validation","validationCode":"key = loader.lora.key\nif loader.mistral_encoder and any(e.lora.key == key for e in loader.mistral_encoder.loras):\n    raise ValueError(f'{key} already applied to Mistral encoder')","typeGuard":null,"tryCatchPattern":"try:\n    out = loader.invoke(context)\nexcept ValueError as e:\n    if 'already applied to Mistral encoder' in str(e):\n        encoder = skip_this_loader(loader.mistral_encoder)\n    else:\n        raise","preventionTips":["Track per-target (transformer vs encoder) applied keys separately","Deduplicate encoder chains the same way as transformer chains","Avoid duplicating encoder loader nodes when cloning graphs"],"tags":["lora","duplicate","mistral-encoder"],"backgroundTag":"duplicate-lora-application","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}