TCDScheduler advances the generator on the final step of a strength-truncated custom schedule
维护者通常 1 天内回复
评估
- 难度
- 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 内容生成。
描述
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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
huggingface/diffusers 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
huggingface/diffusers#15363 ·
维护者通常 1 天内回复
-
`ZImageImg2ImgPipeline` / `ZImageInpaintPipeline`: explicit height/width different from the input image raises RuntimeError可能已有人在做 @chessing234 于 1 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 70/100
huggingface/diffusers#15337 · 2 条评论 ·
维护者通常 1 天内回复
-
Multi-vector textual inversion uses only the first vector when the token has uppercase letters (transformers v5)可能已有人在做 @sunhouy 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
huggingface/diffusers#15313 ·
维护者通常 1 天内回复
-
unload_textual_inversion(token) leaves the extra tokens of a multi-vector embedding behind, so it can't be loaded again可能已有人在做 @sohailshk 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
huggingface/diffusers#15211 · 3 条评论 ·
维护者通常 1 天内回复
-
set_ip_adapter_scale(float) raises "Cannot assign 1 scale_configs to 2 IP-Adapter" when several IP-Adapters are loaded可能已有人在做 @sohailshk 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
huggingface/diffusers#15210 · 1 条评论 ·
维护者通常 1 天内回复
查看 huggingface/diffusers 的全部 Issue
相似的 Issue
-
[dbt] exported dataset keys reference physical columns可能已有人在做 @WilliamKelley 今天认领。 未关闭needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
apache/ossie-converters#251 ·
维护者通常 2 天内回复
-
cli difficulty: easy enhancement
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
desec-io/desec-stack#1312 ·
维护者通常 14 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 82/100
aws/aws-durable-execution-sdk-python#977 ·
维护者通常 1 天内回复
-
needs-triage
难度 1/5 1 小时以内 新手友好度 88/100
flashinfer-ai/flashinfer#9803 ·
维护者通常 1 天内回复