You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some pipelines encode a conditioning image or audio with vae.encode(x).latent_dist.sample() and do not pass the user's generator. So, with a fixed generator=, the output still depends on the global torch RNG state. Most pipelines already do this correctly: there are 129 latent_dist.sample(generator=...) / retrieve_latents(..., generator) call sites. These are the ones on current main that don't (excluding deprecated/):
OmniGen has the same problem and is already listed as Issue 3 in #13633, so it is not repeated here.
Every one of these pipelines takes generator in __call__. The fix is to pass it through, e.g. retrieve_latents(self.vae.encode(x), generator=generator), or to use .mode() where the original implementation is deterministic.
Reproduction
importtorchfromtypesimportSimpleNamespacefromdiffusersimportAutoencoderKL, StableDiffusion3ControlNetInpaintingPipelinetorch.manual_seed(0)
vae=AutoencoderKL(block_out_channels=[32], latent_channels=4, sample_size=32, norm_num_groups=32,
shift_factor=0.0, scaling_factor=1.0).eval()
pipe=SimpleNamespace(vae=vae, vae_scale_factor=1) # single-block tiny VAE does not downsampleimage, mask=torch.rand(1, 3, 32, 32) *2-1, (torch.rand(1, 1, 32, 32) >0.5).float()
defcontrol_latents(global_seed):
torch.manual_seed(global_seed) # the caller already passes `generator=`; global state should not matterwithtorch.no_grad():
returnStableDiffusion3ControlNetInpaintingPipeline.prepare_image_with_mask(
pipe, image, mask, 32, 32, 1, 1, "cpu", torch.float32)
print("max |seed 0 - seed 1| =", (control_latents(0) -control_latents(1)).abs().max().item())
Output:
max |seed 0 - seed 1| = 5.807077407836914
In the full tiny StableDiffusion3ControlNetInpaintingPipeline (the pipeline test's dummy components, fixed generator), changing only the global seed changes the output image by up to 0.0396. Passing the generator to this one sample() call makes the two outputs identical.
Context
I am working on a research project that checks diffusion pipelines for consistency between equivalent calls. One of the checks keeps generator fixed and changes the global RNG state. It flagged the SD3 ControlNet, HunyuanDiT ControlNet and JoyImage pipelines, and I found the others by searching for the same pattern. Happy to open a PR that threads generator through all of them if you agree on the approach.
Activity