huggingface / huggingface/diffusers

[Bug] GlmImagePipeline silently corrupts weights on MPS accelerator

Open
#13,227 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

### 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

Contributor guide

Open the contributing guide

Research direction

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.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.