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

未關閉 適合新手
#15,288 2 則留言 0 個 reaction 已指派 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 小時
30 天內合併 PR
65

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

huggingface/diffusers 的其他 Issue

查看 huggingface/diffusers 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。