huggingface / huggingface/diffusers

[Bug] GlmImagePipeline silently corrupts weights on MPS accelerator

Aperta
#13,227 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Python
Stelle
34.5k
Fork
7.3k
Merge medio
3g 3h
PR unite (30g)
91

Descrizione

### Describe the bug

When loading `zai-org/GLM-Image` with `device_map="mps"` in diffusers, some model parameters become silently corrupted during `GlmImagePipeline.from_pretrained` call.

The corruption:
```
Happens only when tensors are placed directly on MPS during loading
Is non-deterministic across dtypes
```
* float32 + MPS: weights corrupted, bias OK
* float16 + MPS: bias corrupted, weights OK

Does not occur when loading on CPU first and then moving to MPS

This results in extreme values (~1e37), LayerNorm overflow, and NaN / zero outputs (all-black images).

### Reproduction

# ❌ Corrupted
```python
from diffusers.pipelines.glm_image import GlmImagePipeline
import torch

pipe = GlmImagePipeline.from_pretrained(
"zai-org/GLM-Image",
torch_dtype=torch.float32,
device_map="mps",
)
```

# ✅ Correct workaround
```python
from diffusers.pipelines.glm_image import GlmImagePipeline
import torch

pipe = GlmImagePipeline.from_pretrained(
"zai-org/GLM-Image",
torch_dtype=torch.float32,
)
pipe.to("mps")
```

### Logs

```shell
Device: mps, dtype: torch.float32
Keyword arguments {'trust_remote_code': True} are not expected by GlmImagePipeline and will be ignored.

Loading pipeline components...: 0%| | 0/7 [00:00

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start in diffusers.pipelines.glm_image at GlmImagePipeline.from_pretrained and reproduce the difference between device_map="mps" loading and CPU loading followed by pipe.to("mps"). Compare parameter values across float32 and float16 cases, then verify that direct MPS loading no longer produces extreme weights, NaNs, or black-image outputs.

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

Valutazione

Stack tecnologico
python, pytorch
Ambito
machine-learning, performance
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.