Repository navigation
Description
Describe the bug
With FlowMatchEulerDiscreteScheduler(stochastic_sampling=True), FluxPipeline and LTXPipeline produce different outputs with the same supplied generator seed when unrelated global RNG state changes.
The pipelines use the supplied generator for initial latents but omit it from scheduler.step(). Subsequent noise therefore uses the global RNG.
PR #13678 fixed generator handling inside the scheduler; the pipeline callers still need to forward it.
I’d be happy to submit a PR to fix the issue.
Reproduction
This CPU example uses small real Flux components and precomputed prompt embeddings. Both calls use generator seed 17; only the global RNG state changes.
import torch
from diffusers import (
AutoencoderKL, FlowMatchEulerDiscreteScheduler,
FluxPipeline, FluxTransformer2DModel,
)
torch.set_num_threads(1)
torch.manual_seed(0)
transformer = FluxTransformer2DModel(
patch_size=1, in_channels=4, num_layers=1, num_single_layers=1,
attention_head_dim=16, num_attention_heads=2, joint_attention_dim=32,
pooled_projection_dim=32, axes_dims_rope=[4, 4, 8],
).eval()
vae = AutoencoderKL(
sample_size=32, in_channels=3, out_channels=3, block_out_channels=(4,),
layers_per_block=1, latent_channels=1, norm_num_groups=1,
use_quant_conv=False, use_post_quant_conv=False,
shift_factor=0.0609, scaling_factor=1.5035,
).eval()
pipe = FluxPipeline(
transformer=transformer, vae=vae,
scheduler=FlowMatchEulerDiscreteScheduler(),
text_encoder=None, tokenizer=None,
text_encoder_2=None, tokenizer_2=None,
)
pipe.set_progress_bar_config(disable=True)
prompt_embeds = torch.randn(1, 16, 32)
pooled_prompt_embeds = torch.randn(1, 32)
for stochastic in (False, True):
pipe.scheduler = FlowMatchEulerDiscreteScheduler(
stochastic_sampling=stochastic
)
outputs = []
for global_seed in (13, 99):
torch.manual_seed(global_seed)
outputs.append(pipe(
prompt_embeds=prompt_embeds,
pooled_prompt_embeds=pooled_prompt_embeds,
height=8, width=8, guidance_scale=1.0,
num_inference_steps=4,
generator=torch.Generator().manual_seed(17),
output_type="latent",
).images)
difference = (outputs[0] - outputs[1]).abs().max().item()
print(f"stochastic_sampling={stochastic}: max difference = {difference:.6f}")The two runs should produce identical outputs with the same supplied generator seed, but in this example, they differ by up to 2.285045 when only the global RNG state changes.
Logs
stochastic_sampling=False: max difference = 0.000000
stochastic_sampling=True: max difference = 2.285045System Info
- Diffusers:
0.42.1; also reproduced on main revision86ef420b17363c28e36ebad6b58555e9aa8feda2 - Python:
3.12.14 - PyTorch:
2.14.1 - Transformers:
5.20.2 - Platform: macOS arm64, CPU float32
Who can help?
No response
Activity
27-amu commentedon Nov 1, 2026
Hi @JohnLyu2, thanks for the clear repro.. I have put together a fix that forwards the generator in the Flux and LTX pipelines (only when the schedulers step accepts one, so swapping in e.g. UniPC still works), plus regression multiple tests. Happy to open the PR if youre not already working on it, otherwise no worries, I wll leave it to you.
JohnLyu2 commentedon Nov 2, 2026
@27-amu As mentioned in the PR, I'd love to contribute a PR. Thanks.
27-amu commentedon Nov 2, 2026
No worries, it’s your find, so go for it! While testing I noticed it seems to work best to only pass generator when scheduler.step accepts it, since UniPC doesn’t take one. Happy to take a look once the PR is up.