TCDScheduler advances the generator on the final step of a strength-truncated custom schedule

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

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

@SIDDARTHAREDDY8 がすでに取り組んでいます。

2026年11月15日 から。

  • #15301 @SIDDARTHAREDDY8 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

TCDScheduler の step メソッドから始めてください。ここでは最終ステップの判定が現在のインデックスを num_inference_steps と比較し、eta > 0 のときにノイズをサンプリングします。issue の再現スクリプトを実行してください。このスクリプトは set_timesteps(timesteps=[999, 499, 19], strength=0.5) を使っています。そのうえで、ジェネレーターの状態が変化することを確認してください。判定が self.timesteps の長さを使い、実際の最終ステップでジェネレーターの状態が変わらず、既存の TCD スケジューラーのテストがすべて通れば完了です。

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

説明

bug
Describe the bug

When TCDScheduler uses a non-empty custom timestep schedule truncated by
strength < 1, its actual final step advances the supplied random generator
when eta > 0.

For example, timesteps=[999, 499, 19] with strength=0.5 leaves only [19],
but num_inference_steps remains 3. The final-step check uses the original
step count and enters the noise-sampling branch.

In the tested case, the terminal output stays the same because the noise
coefficient is zero, but the generator state changes. Subsequent draws using
the same generator therefore differ.

I expected the actual final step to leave the generator state unchanged,
consistent with the scheduler's comment that noise is not used on the final
timestep.

A possible fix is to decide whether another step exists using the length of
self.timesteps. I have tested a candidate fix and can provide it for review.

Reproduction
import diffusers
import torch
from diffusers import TCDScheduler

print(f"torch={torch.__version__} diffusers={diffusers.__version__}")
print(f"source={diffusers.__file__}")

scheduler = TCDScheduler(prediction_type="sample")
scheduler.set_timesteps(timesteps=[999, 499, 19], strength=0.5, device="cpu")

generator = torch.Generator(device="cpu").manual_seed(0)
control = torch.Generator(device="cpu").manual_seed(0)
sample = torch.ones((1, 1), device="cpu")

before = generator.get_state().clone()
result = scheduler.step(
    torch.zeros_like(sample),
    scheduler.timesteps[0],
    sample,
    eta=0.3,
    generator=generator,
)
after = generator.get_state()

next_draw = torch.randn(4, generator=generator, device="cpu")
control_draw = torch.randn(4, generator=control, device="cpu")

print(f"actual timesteps={scheduler.timesteps.tolist()}")
print(f"num_inference_steps={scheduler.num_inference_steps}")
print(f"prev_sample={result.prev_sample.item()}")
print(f"pred_noised_sample={result.pred_noised_sample.item()}")
print(f"RNG state preserved: {torch.equal(before, after)}")
print(f"next draw: {next_draw.tolist()}")
print(f"control:   {control_draw.tolist()}")

assert torch.equal(before, after), "The terminal step advanced the generator"
Context

No response

Logs
Baseline: unmodified Diffusers source at commit
43e30028af5120d8b0868cb6975b9fad39cc4fab

torch=2.9.0+cu126
diffusers=0.44.0.dev0

actual timesteps=[19]
num_inference_steps=3
prev_sample=0.21879726648330688
pred_noised_sample=0.21879726648330688
RNG state preserved: False

next draw: [-0.293428897857666, -2.1787893772125244, 0.5684312582015991, -1.0845223665237427]
control:   [1.5409960746765137, -0.293428897857666, -2.1787893772125244, 0.5684312582015991]

AssertionError: The terminal step advanced the generator
System Info

Platform: Windows 11
Python: 3.12.8
PyTorch: 2.9.0+cu126
Diffusers: 0.44.0.dev0, source checkout at commit 43e30028af5120d8b0868cb6975b9fad39cc4fab
Device used for reproduction: CPU

Who can help?

No response

主要言語
Python
スター
34.9k
フォーク
7.5k
平均マージ
3日 16時間
マージ済み PR(30日)
65

環境構築

はじめの一歩

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

huggingface/diffusers のほかの issue

huggingface/diffusers の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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