Flux and LTX pipelines do not forward the generator to stochastic scheduler steps

オープン 初心者向け
#15,163 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python, pytorch

調査の方向性

FluxPipeline と LTXPipeline クラスを読み、scheduler.step() が generator なしで呼び出されている場所を見つけます。パイプラインの generator をその呼び出しに渡し、PR #13678 を反映します。issue の再現スクリプトを実行します: stochastic_sampling=True では、最大差は 0.000000 になります。

索引モデルが issue の本文から書いたものです。

説明

bug
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.285045
System Info
  • Diffusers: 0.42.1; also reproduced on main revision 86ef420b17363c28e36ebad6b58555e9aa8feda2
  • Python: 3.12.14
  • PyTorch: 2.14.1
  • Transformers: 5.20.2
  • Platform: macOS arm64, CPU float32
Who can help?

No response

主要言語
Python
スター
34.8k
フォーク
7.4k
平均マージ
2日 12時間
マージ済み PR(30日)
57

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

huggingface/diffusers のほかの issue

huggingface/diffusers の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。