Safetensors checkpoint loading fails with a torch.device map_location
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
src/diffusers/models/model_loading_utils.pyから始めます。ここではload_state_dictがsafetensorsチェックポイントを処理しています。map_locationの扱いを.binの処理と比較してください。issueにある1テンソルの再現例を使って失敗を確認し、関連するモデル読み込みテストを確認してください。map_location=torch.device("cpu")を渡したときに有効なチェックポイントが読み込まれれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
I get an OSError when I pass torch.device("cpu") to load_state_dict for a valid safetensors checkpoint. The helper accepts torch.device in its type annotation, and the same argument works for .bin checkpoints. I have a small fix for the safetensors call and would like to submit it.
Reproduction
from pathlib import Path
from tempfile import TemporaryDirectory
import torch
from safetensors.torch import save_file
from diffusers.models.model_loading_utils import load_state_dict
with TemporaryDirectory() as directory:
path = Path(directory) / "model.safetensors"
save_file({"weight": torch.ones(1)}, path)
load_state_dict(path, map_location=torch.device("cpu"))
Context
I found this while reading checkpoint loading in model_loading_utils.py, then reproduced it with the one-tensor checkpoint above.
Logs
SafetensorError: device device(type='cpu') is invalid
OSError: Unable to load weights from checkpoint file
System Info
Diffusers 0.44.0.dev0 at 08d5de3, Linux x86_64, Python 3.14.5, PyTorch 2.15.0+cpu, safetensors 0.8.0. CPU only, single process.
- 主要言語
- Python
- スター
- 35k
- フォーク
- 7.5k
- 平均マージ
- 3日 2時間
- マージ済み PR(30日)
- 58
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
huggingface/diffusers のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
huggingface/diffusers#15463 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
huggingface/diffusers#15461 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
huggingface/diffusers#15460 ·
メンテナーはふだん 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 日以内に返信