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

Aperta Adatta ai principianti
#15,288 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@SIDDARTHAREDDY8 ci sta già lavorando.

Dal 15/11/2026.

  • #15301 di @SIDDARTHAREDDY8 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia dal metodo step di TCDScheduler, dove il controllo dell'ultimo passo confronta l'indice corrente con num_inference_steps e poi campiona rumore quando eta > 0. Esegui lo script di riproduzione dell'issue, che usa set_timesteps(timesteps=[999, 499, 19], strength=0.5), e conferma che lo stato del generatore cambia. È completato quando il controllo usa la lunghezza di self.timesteps, lo stato del generatore non cambia all'ultimo passo effettivo e i test esistenti dello scheduler TCD continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
34.9k
Fork
7.5k
Merge medio
3g 16h
PR unite (30g)
65

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di huggingface/diffusers

Tutte le issue di huggingface/diffusers

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.