load_lora_adapter can't load a folder written by save_lora_adapter unless use_safetensors=True is passed
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 65/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
阅读 PeftAdapterMixin.load_lora_adapter 和 _fetch_state_dict,然后检查共用测试 test_save_load_lora_adapter。使用默认参数保存并加载一个适配器,以重现问题;更新加载器和测试,使通过 save_lora_adapter 保存的文件夹能够默认加载。无需设置 use_safetensors=True 即可通过回归测试时,任务便完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
save_lora_adapter on a model writes pytorch_lora_weights.safetensors by default. Calling load_lora_adapter on that same folder with default arguments fails because it only looks for pytorch_lora_weights.bin. Passing use_safetensors=True works.
The cause is that PeftAdapterMixin.load_lora_adapter passes use_safetensors=None to _fetch_state_dict, and the safetensors branch there only runs when the flag is truthy or weight_name ends in .safetensors. The pipeline loaders in lora_pipeline.py, load_attn_procs and textual inversion all turn None into use_safetensors=True with pickle fallback. load_lora_adapter is the only one that doesn't.
I found this while reading the loader code around _fetch_state_dict and then reproduced it with the script below. The shared test_save_load_lora_adapter test passes use_safetensors=True on load, so it doesn't catch it.
Reproduction
import tempfile
from torch import nn
from diffusers.configuration_utils import ConfigMixin
from diffusers.loaders.peft import PeftAdapterMixin
from diffusers.models.modeling_utils import ModelMixin
from peft import LoraConfig
class TinyModel(ModelMixin, ConfigMixin, PeftAdapterMixin):
config_name = "config.json"
def __init__(self):
super().__init__()
self.linear = nn.Linear(2, 2)
model = TinyModel()
model.add_adapter(LoraConfig(r=1, lora_alpha=1, target_modules=["linear"]))
with tempfile.TemporaryDirectory() as tmp:
model.save_lora_adapter(tmp)
model.unload_lora()
model.load_lora_adapter(tmp, prefix=None) # OSError
Real models such as FluxTransformer2DModel and UNet2DConditionModel go through the same PeftAdapterMixin.load_lora_adapter path.
Logs
OSError: Error no file named pytorch_lora_weights.bin found in directory /tmp/tmp07lmtgut.
System Info
diffusers main (facc812), peft 0.22.0, torch 2.15.0 (CPU), Python 3.12, Linux.
Who can help?
@sayakpaul @BenjaminBossan
I have a fix ready (four lines in load_lora_adapter plus the shared test change) and can open a PR once a maintainer is fine with the approach.
- 主要语言
- Python
- 星标
- 35k
- 派生
- 7.5k
- 平均合并
- 3 天 2 小时
- 30 天内合并 PR
- 58
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
huggingface/diffusers 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
huggingface/diffusers#15461 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
huggingface/diffusers#15460 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
huggingface/diffusers#15459 ·
维护者通常 1 天内回复
-
GlmImagePipeline: image-to-image fails with `enable_model_cpu_offload()` (device mismatch in `get_image_features`)可能已有人在做 @saeekailas 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
huggingface/diffusers#15449 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
huggingface/diffusers#15436 · 1 条评论 ·
维护者通常 1 天内回复
查看 huggingface/diffusers 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
daniel-ospina/tortoise#15014 ·
维护者通常 1 天内回复
-
area:api p2 product:business triage:active type:feat
难度 2/5 1-3 小时 新手友好度 68/100
cuadrao-ai/argus#2656 ·
维护者通常 1 天内回复
-
documentation good first issue help wanted
难度 2/5 1-3 小时 新手友好度 84/100
-
good first issue tests
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复