Repository navigation
Description
Describe the bug
The reproducibility guide recommends a CPU torch.Generator. The image pipelines support this because randn_tensor samples on the CPU and moves the result to the device. The discrete diffusion code instead passes the generator straight to torch.randint / torch.multinomial / torch.rand on the pipeline's device, and PyTorch rejects a CPU generator there.
DiffusionGemmaPipelinefails on every call, even with greedy decoding, because the initial canvas is drawn withtorch.randint(..., device=device, generator=generator).LLaDA2Pipelinefails whenevertemperature > 0.- The same pattern is in
BlockRefinementScheduler,DiscreteDDIMSchedulerandEntropyBoundScheduler(_sample_from_logits, the random-token renoising instep, andadd_noise).
I tested on MPS. I don't have a CUDA machine, but PyTorch does the same device check on CUDA (see #6501), so CUDA should fail the same way.
Proposed fix: draw on generator.device and move the result to the pipeline's device, the same approach as #13228 for Helios. I'd like to open a PR for this with tests. #14741 keeps the same calls.
Reproduction
This uses the tiny checkpoint from the DiffusionGemma tests. The full model (google/diffusiongemma-26B-A4B-it) doesn't fit on my machine.
import torch
from transformers import AutoProcessor, DiffusionGemmaForBlockDiffusion
from diffusers import BlockRefinementScheduler, DiffusionGemmaPipeline
model_id = "trl-internal-testing/tiny-DiffusionGemmaForBlockDiffusion"
pipe = DiffusionGemmaPipeline(
model=DiffusionGemmaForBlockDiffusion.from_pretrained(model_id, dtype=torch.float32),
scheduler=BlockRefinementScheduler(),
processor=AutoProcessor.from_pretrained(model_id),
).to("mps")
generator = torch.Generator("cpu").manual_seed(0)
out = pipe(prompt="Name a color.", gen_length=32, num_inference_steps=4, generator=generator)
print(out.texts)It runs with torch.Generator("mps"), or with both on CPU.
Context
No response
Logs
File "src/diffusers/pipelines/diffusion_gemma/pipeline_diffusion_gemma.py", line 347, in __call__
canvas = torch.randint(
RuntimeError: Expected a 'mps' device type for generator but found 'cpu'System Info
- 🤗 Diffusers version: 0.42.0.dev0 (main @ f598e6e)
- Platform: macOS-26.6.2-arm64-arm-64bit
- Python version: 3.11.14
- PyTorch version (GPU?): 2.15.0 (False)
- Transformers version: 5.22.0
- Accelerator: Apple M1 Pro
- Using GPU in script?: Yes (MPS)
- Using distributed or parallel set-up in script?: No
Activity