Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/diffusers/loaders/peft.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def load_lora_adapter(
metadata = kwargs.pop("metadata", None)
allow_pickle = False

if use_safetensors is None:
use_safetensors = True
allow_pickle = True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it have to do with allow_pickle?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once use_safetensors defaults to True, _fetch_state_dict tries the .safetensors file first, and on an IOError it only falls back to the .bin file when allow_pickle is set. Without it, adapters that only ship pytorch_lora_weights.bin would stop loading through load_lora_adapter, while they load today. This mirrors what load_lora_weights already does in lora_pipeline.py (allow_pickle = True when use_safetensors is not passed). An explicit use_safetensors=True still keeps the strict behaviour.


user_agent = {"file_type": "attn_procs_weights", "framework": "pytorch"}
state_dict = _fetch_state_dict(
pretrained_model_name_or_path_or_dict=pretrained_model_name_or_path_or_dict,
Expand Down
2 changes: 1 addition & 1 deletion tests/models/testing_utils/lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_save_load_lora_adapter(
model.unload_lora()
assert not check_if_lora_correctly_set(model), "LoRA should be unloaded"

model.load_lora_adapter(tmp_path, prefix=None, use_safetensors=True)
model.load_lora_adapter(tmp_path, prefix=None)
state_dict_retrieved = get_peft_model_state_dict(model, adapter_name="default_0")

for k in state_dict_loaded:
Expand Down
Loading