Skip to content

Conversation

@leejet
Copy link
Owner

@leejet leejet commented Nov 16, 2025

In ComfyUI, when using samplers that include ancestral sampling steps (such as euler_a), an independent RNG is used to generate noise. Moreover, ComfyUI uses the RNG of the device where the current tensor resides. This means that if ComfyUI is running on CUDA, the initial noise is generated on the CPU, but the noise added during sampling is generated on CUDA. If ComfyUI is running on another device, such as the CPU, the results will be different.

The ComfyUI commit that introduced this issue: comfyanonymous/ComfyUI@916d1e1.

I don’t really understand why ComfyUI is designed this way, as it breaks cross-device consistency and causes different versions of ComfyUI to produce different outputs. However, for users who want to reproduce ComfyUI’s results in sd.cpp, this PR is necessary.

.\bin\Release\sd.exe -m ..\..\stable-diffusion-webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors -p "a lovely cat BREAK" -v --diffusion-fa --rng cpu --sampler-rng cuda

sd.cpp result
output

comfyui result
ComfyUI_00204_

@leejet leejet merged commit d5b05f7 into master Nov 16, 2025
10 checks passed
@leejet leejet deleted the sampler-rng branch November 16, 2025 09:37
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.

2 participants