{"record":{"id":"7f3b0a625cad0a64","repo":"invoke-ai/InvokeAI","slug":"lora-lora-key-already-applied-to-t5-encoder","errorCode":null,"errorMessage":"LoRA \"{lora_key}\" already applied to T5 encoder.","messagePattern":"LoRA \"(.+?)\" already applied to T5 encoder\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/flux_lora_loader.py","lineNumber":76,"sourceCode":"        default=None,\n        title=\"T5 Encoder\",\n        description=FieldDescriptions.t5_encoder,\n        input=Input.Connection,\n    )\n\n    def invoke(self, context: InvocationContext) -> FluxLoRALoaderOutput:\n        lora_key = self.lora.key\n\n        if not context.models.exists(lora_key):\n            raise ValueError(f\"Unknown lora: {lora_key}!\")\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.clip and any(lora.lora.key == lora_key for lora in self.clip.loras):\n            raise ValueError(f'LoRA \"{lora_key}\" already applied to CLIP encoder.')\n        if self.t5_encoder and any(lora.lora.key == lora_key for lora in self.t5_encoder.loras):\n            raise ValueError(f'LoRA \"{lora_key}\" already applied to T5 encoder.')\n\n        output = FluxLoRALoaderOutput()\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.clip is not None:\n            output.clip = self.clip.model_copy(deep=True)\n            output.clip.loras.append(\n                LoRAField(\n                    lora=self.lora,\n                    weight=self.weight,","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux_lora_loader.py#L58-L94","documentation":"Duplicate-guard for the T5 text encoder component: the loader raises ValueError when the requested LoRA key is already present on self.t5_encoder.loras. This prevents applying the same T5-side LoRA weights twice within one invocation.","triggerScenarios":"invoke() with self.t5_encoder set and an existing lora in self.t5_encoder.loras whose key equals lora_key — the same FLUX LoRA is being applied to the T5 encoder twice in the same graph run.","commonSituations":"Same LoRA connected to both T5 and another component plus repeated again; generated workflows that loop LoRA application without resetting state.","solutions":["Deduplicate the LoRA application nodes in the workflow","Verify each LoRA loader uses a unique model key","Re-run with a fresh transformer/encoder chain if state carried over from a prior invocation","Audit programmatic graph builders for repeated keys"],"exampleFix":"// before: same loader applied twice to T5 path\n// after: apply once and reuse the output invocation\nt5_out = FluxLoRALoader(lora=lora_key, weight=1.0)","handlingStrategy":"validation","validationCode":"t5_keys = [l.lora.key for l in t5_encoder.loras] if t5_encoder else []\nassert lora_key not in t5_keys, f\"LoRA {lora_key} already on T5\"","typeGuard":"def t5_lora_free(t5_encoder, lora_key: str) -> bool:\n    return not t5_encoder or not any(l.lora.key == lora_key for l in t5_encoder.loras)","tryCatchPattern":"try:\n    output = loader.invoke(context)\nexcept ValueError as e:\n    if 'already applied to T5' in str(e):\n        output = None  # skip, already loaded on T5\n    else:\n        raise","preventionTips":["Avoid looping LoRA application without resetting encoder state","Track applied keys in a set before building the graph","Use distinct LoRAs per component when stacking"],"tags":["lora","duplicate-model","t5","flux","invokeai"],"backgroundTag":"duplicate-lora-application","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}