Fix mutable default args in lora_base.py#14064
Conversation
sayakpaul
left a comment
There was a problem hiding this comment.
Thanks! Do we have an example reproducer reflecting the issue that this PR attempts to solve?
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Hi @sayakpaul! Although We can reproduce this directly on the live import inspect
from diffusers.loaders.lora_base import LoraBaseMixin
sig = inspect.signature(LoraBaseMixin.fuse_lora)
default_object = sig.parameters["components"].default
print(f"Initial default type: {type(default_object)}") # Expected: <class 'list'>
default_object.append("leaked_state_or_component")
new_sig = inspect.signature(LoraBaseMixin.fuse_lora)
print(f"Mutated default value: {new_sig.parameters['components'].default}") # Expected: ['leaked_state_or_component']
assert len(new_sig.parameters["components"].default) > 0, "Global signature state polluted!" |
|
Hi @PrakshaaleJain, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. |
What does this PR do?
Fixes #14052
This PR fixes a bug in
src/diffusers/loaders/lora_base.pywhere a mutable default argument (components: list[str] = []) was used in the signatures offuse_loraandunfuse_lora. It updates the default value toNoneand initializes it as a clean, empty list inside the method body if no explicit argument is passed.Why this change is important:
Before submitting
.ai/review-rules.md?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Core library / PEFT integrations: