Warn and skip transformer LoRA loading when the transformer is absent (#13487)#13945
Open
archievi wants to merge 1 commit into
Open
Warn and skip transformer LoRA loading when the transformer is absent (#13487)#13945archievi wants to merge 1 commit into
archievi wants to merge 1 commit into
Conversation
…huggingface#13487) Loading a transformer-only LoRA onto a modular sub-pipeline that does not contain the transformer (for example a text-encoder-only sub-pipeline) raised "AttributeError: ... object has no attribute 'transformer'". Following the maintainer suggestion on the issue, load_lora_weights now resolves the transformer with a default of None and, when it is missing, logs a warning and skips loading the transformer LoRA layers instead of raising. The change is made at the copied-from source (CogVideoXLoraLoaderMixin.load_lora_weights) and propagated to the copies with make fix-copies. Adds a regression test.
sayakpaul
reviewed
Jun 15, 2026
sayakpaul
left a comment
Member
There was a problem hiding this comment.
Thanks! I left some comments.
Comment on lines
+1384
to
+1390
| transformer = self.transformer if hasattr(self, "transformer") else getattr(self, self.transformer_name, None) | ||
| if transformer is None: | ||
| logger.warning( | ||
| f"No `{self.transformer_name}` module was found in {self.__class__.__name__}, so no LoRA weights will be " | ||
| "loaded into the transformer. This can happen when loading LoRA weights into a modular pipeline that " | ||
| "does not contain the transformer (for example, a text-encoder-only sub-pipeline)." | ||
| ) |
Member
There was a problem hiding this comment.
This is not specific to a modular pipeline, though.
|
|
||
|
|
||
| @require_peft_backend | ||
| class Flux2LoRAModularPipelineTests(unittest.TestCase): |
Member
There was a problem hiding this comment.
It should be added to
Line 123 in 9b249df
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Loading a transformer-only LoRA onto a Modular sub-pipeline that does not contain the transformer (for example a text-encoder-only
text_pipe) currently crashes:This happens because
load_lora_weightsresolves the transformer withgetattr(self, self.transformer_name), which raises when the (sub-)pipeline has no transformer component.Following @yiyixuxu's suggestion on the issue ("maybe warn and skip is better"),
load_lora_weightsnow resolves the transformer with aNonedefault and, when no transformer is present, logs a warning and skips loading the transformer LoRA layers instead of raising.The change is made at the copied-from source (
CogVideoXLoraLoaderMixin.load_lora_weights) and propagated to its 14 copies withmake fix-copies, so the behavior is consistent across the transformer LoRA loaders (Flux2, Flux, SD3, CogView4, etc.). Normal pipelines that do have a transformer are unaffected.Fixes #13487
Before submitting
.ai/? I read and applied.ai/AGENTS.md(copied-code convention) and.ai/modular.md; the fix is made at the copied-from source and propagated withmake fix-copiesrather than editing individual copies..ai/review-rules.md? No ephemeral context, correctness-focused, no dead code.Flux2LoRAModularPipelineTestsintests/lora/test_lora_layers_flux2.py.Verification (run locally)
AttributeErrorwhen the fix is reverted (regression-proven).python utils/check_copies.pypasses (copies consistent aftermake fix-copies).ruff checkandruff format --checkare clean on the changed files.Who can review?
@yiyixuxu @sayakpaul @DN6