Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

UNet2DModel dtype property fails under nn.DataParallel with UnboundLocalError in get_parameter_dtype

オープン 初心者向け
#13,789 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Om-singhaI がすでに取り組んでいます。

2026年8月24日 から。

  • #13791 @Anai-Guo による — マージされずにクローズ
  • #13963 @adhavan18 による — マージされずにクローズ
  • #13990 @Whning0513 による — マージされずにクローズ
  • #14579 @Om-singhaI による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python, pytorch

調査の方向性

diffusers/models/modeling_utils.py の get_parameter_dtype とその find_tensor_attributes アノテーションから始め、次に diffusers/models/unets/unet_2d.py からの self.dtype へのアクセスを追ってください。提供されている UNet2DModel と torch.nn.DataParallel の例で失敗を再現し、UnboundLocalError を発生させずに forward pass が完了することを示す回帰チェックを追加するか実行してください。

索引モデルが issue の本文から書いたものです。

説明

bug models
Describe the bug

Description

UNet2DModel fails under torch.nn.DataParallel during the forward pass when it accesses self.dtype inside UNet2DModel.forward.

The error appears to come from diffusers.models.modeling_utils.get_parameter_dtype, where the nested function annotation uses tuple:

def find_tensor_attributes(module: nn.Module) -> list[tuple[str, Tensor]]:

### Reproduction

import torch
from diffusers import UNet2DModel

print("torch:", torch.__version__)

import diffusers
print("diffusers:", diffusers.__version__)

model = UNet2DModel(
    sample_size=128,
    in_channels=10,
    out_channels=5,
    layers_per_block=2,
    block_out_channels=(64, 128, 256, 256),
    down_block_types=(
        "DownBlock2D",
        "DownBlock2D",
        "AttnDownBlock2D",
        "DownBlock2D",
    ),
    up_block_types=(
        "UpBlock2D",
        "AttnUpBlock2D",
        "UpBlock2D",
        "UpBlock2D",
    ),
    norm_num_groups=8,
)

model = model.cuda()
model = torch.nn.DataParallel(model, device_ids=[0, 1])
model.eval()

x = torch.randn(8, 10, 128, 128, device="cuda")
t = torch.rand(8, device="cuda") * 1000

with torch.no_grad():
    y = model(x, t, return_dict=False)[0]

print(y.shape)

### Logs

```shell
File ".../diffusers/models/unets/unet_2d.py", line ..., in forward
    t_emb = t_emb.to(dtype=self.dtype)

File ".../diffusers/models/modeling_utils.py", line ..., in dtype
    return get_parameter_dtype(self)

File ".../diffusers/models/modeling_utils.py", line ..., in get_parameter_dtype
    def find_tensor_attributes(module: nn.Module) -> list[tuple[str, Tensor]]:

UnboundLocalError: cannot access local variable 'tuple' where it is not associated with a value
System Info

Python 3.11.13, torch 2.9.1+cu128, diffusers 0.38.0, CUDA Version: 12.9

Who can help?

No response

主要言語
Python
スター
34.7k
フォーク
7.4k
平均マージ
3日 14時間
マージ済み PR(30日)
51

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

huggingface/diffusers のほかの issue

huggingface/diffusers の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。