load_lora_adapter can't load a folder written by save_lora_adapter unless use_safetensors=True is passed
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 58
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
yeab7505/tenasig#20 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信