load_lora_adapter can't load a folder written by save_lora_adapter unless use_safetensors=True is passed
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Đọc PeftAdapterMixin.load_lora_adapter và _fetch_state_dict, sau đó kiểm tra bài kiểm thử dùng chung test_save_load_lora_adapter. Tái hiện lỗi bằng cách lưu và tải một adapter với các đối số mặc định; cập nhật loader và bài kiểm thử để thư mục được lưu bằng save_lora_adapter có thể được tải theo mặc định. Hoàn tất khi bài kiểm thử hồi quy chạy thành công mà không cần đặt use_safetensors=True.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 35k
- Fork
- 7.5k
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 58
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của huggingface/diffusers
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
huggingface/diffusers#15461 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
huggingface/diffusers#15460 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
huggingface/diffusers#15459 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
GlmImagePipeline: image-to-image fails with `enable_model_cpu_offload()` (device mismatch in `get_image_features`)Có thể đã có người làm @saeekailas đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
huggingface/diffusers#15449 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
huggingface/diffusers#15436 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của huggingface/diffusers
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
daniel-ospina/tortoise#15014 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:api p2 product:business triage:active type:feat
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
cuadrao-ai/argus#2656 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
good first issue tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
yeab7505/tenasig#20 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày