Repeated image edits with one pipeline instance return all-NaN from the second call on, but only at output_resolution=1024. At 512 and 768 three consecutive edits are clean. gc.collect(), torch.mps.synchronize() and torch.mps.empty_cache() between calls do not help.
Setup: diffusers 0121a91 and current main 0377f0c (identical), torch 2.14.0, bf16, MPS, M5 Max 128 GB, macOS 26.6.
Minimal repro (script below, 20 steps, one pipeline, three edits of the same 1024² image):
| output_resolution |
edit 1 |
edit 2 |
edit 3 |
| 512 |
0 NaN |
0 NaN |
0 NaN |
| 768 |
0 NaN |
0 NaN |
0 NaN |
| 1024 |
0 NaN |
4,194,304 of 4,194,304 NaN |
all NaN |
Workaround: a fresh process per edit at 1024.
Minimal repro
"""Minimal repro: every edit after the first in the same process returns NaN on MPS at 1024.
Three edits of the same image with one pipeline instance, with gc and torch.mps.empty_cache()
in between. Expected: no NaN. Observed at output_resolution=1024: first clean, then all NaN.
"""
import gc, sys, time
import numpy as np, torch
from PIL import Image
from diffusers import QwenImage21Pipeline
import diffusers
image = Image.open(sys.argv[1]).convert("RGB")
res = int(sys.argv[2]) if len(sys.argv) > 2 else 512
pipe = QwenImage21Pipeline.from_pretrained("Qwen/Qwen-Image-2.1", dtype=torch.bfloat16).to("mps")
pipe.set_progress_bar_config(disable=True)
print("diffusers", diffusers.__version__, "| torch", torch.__version__, "| output_resolution", res, flush=True)
for i, prompt in enumerate(["Change the scene to a rainy evening.", "Make the sign read HELLO.", "Add a black cat on the bench."], 1):
t = time.time()
arr = pipe(image=image, prompt=prompt, num_inference_steps=20, generator=torch.Generator("mps").manual_seed(i),
output_resolution=res, output_type="np").images[0]
print(f"edit {i}: {time.time() - t:.0f} s, NaN values: {int(np.isnan(arr).sum())} of {arr.size}", flush=True)
del arr; gc.collect(); torch.mps.synchronize(); torch.mps.empty_cache()
Usage: python nan_repro.py <image> <output_resolution>
Repeated image edits with one pipeline instance return all-NaN from the second call on, but only at
output_resolution=1024. At 512 and 768 three consecutive edits are clean.gc.collect(),torch.mps.synchronize()andtorch.mps.empty_cache()between calls do not help.Setup: diffusers 0121a91 and current main 0377f0c (identical), torch 2.14.0, bf16, MPS, M5 Max 128 GB, macOS 26.6.
Minimal repro (script below, 20 steps, one pipeline, three edits of the same 1024² image):
Workaround: a fresh process per edit at 1024.
Minimal repro
Usage:
python nan_repro.py <image> <output_resolution>