Skip to content

Add warning when using CUDA random generator (#13298)#13309

Open
r266-tech wants to merge 1 commit intohuggingface:mainfrom
r266-tech:warn-cuda-generator-device
Open

Add warning when using CUDA random generator (#13298)#13309
r266-tech wants to merge 1 commit intohuggingface:mainfrom
r266-tech:warn-cuda-generator-device

Conversation

@r266-tech
Copy link

What does this PR do?

Fixes #13298

When users pass a CUDA torch.Generator to diffusers pipelines, they may expect the same results as with a CPU generator given the same seed. However, PyTorch uses different random number generation algorithms on CPU and CUDA, so the generated images will differ.

This PR adds a warning in randn_tensor when a CUDA generator is used, informing users that:

  • CUDA generators produce different random numbers than CPU generators with the same seed
  • This is expected PyTorch behavior
  • Use a CPU generator if reproducibility across devices is needed

Before submitting

Who can review?

@yiyixuxu @DN6 @sayakpaul

Warn users that CUDA generators produce different random numbers than CPU
generators with the same seed, since PyTorch uses different RNG algorithms
on each device. This helps users understand why their images differ when
switching generator devices.

Fixes huggingface#13298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When generating images, if the generator device is on cuda, it break things

1 participant