Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#13,789 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Om-singhaI ci sta già lavorando.

Dal 24/8/2026.

  • #13791 di @Anai-Guo — chiusa senza merge
  • #13963 di @adhavan18 — chiusa senza merge
  • #13990 di @Whning0513 — chiusa senza merge
  • #14579 di @Om-singhaI — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python, pytorch

Direzione di ricerca

Inizia in diffusers/models/modeling_utils.py da get_parameter_dtype e dalla relativa annotazione find_tensor_attributes, quindi segui l’accesso a self.dtype da diffusers/models/unets/unet_2d.py. Riproduci il malfunzionamento con l’esempio fornito di UNet2DModel e torch.nn.DataParallel, quindi aggiungi o esegui un controllo di regressione che mostri che il forward pass viene completato senza UnboundLocalError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
34.6k
Fork
7.4k
Merge medio
4g 17h
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di huggingface/diffusers

Tutte le issue di huggingface/diffusers

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.