Skip to content

VAE posterior sampling ignores generator in 7 pipelines (SD3 ControlNet, HunyuanDiT ControlNet, JoyImage, QwenImage ControlNet inpaint, CogView4 Control, ACE-Step) #15464

Backlog

Description

@nyxbyb

Describe the bug

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

import torch
from types import SimpleNamespace
from diffusers import AutoencoderKL, StableDiffusion3ControlNetInpaintingPipeline

torch.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 downsample
image, mask = torch.rand(1, 3, 32, 32) * 2 - 1, (torch.rand(1, 1, 32, 32) > 0.5).float()

def control_latents(global_seed):
    torch.manual_seed(global_seed)  # the caller already passes `generator=`; global state should not matter
    with torch.no_grad():
        return StableDiffusion3ControlNetInpaintingPipeline.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.

Logs

System Info

diffusers main @ facc812, torch 2.13.0, Python 3.13.5, macOS arm64 (CPU).

Who can help?

@yiyixuxu @asomoza

Activity

  1. added
    bug
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions