You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EulerDiscreteScheduler returns incorrect v-prediction targets for discrete timesteps #15461
I found this while reading EulerDiscreteScheduler.get_velocity. It looks up each timestep's position in the descending schedule and uses that position to index alphas_cumprod. At timestep 999 the default schedule reads alphas_cumprod[0]. I plan to fix the lookup to use the discrete training timestep value.
I get 1.4713691473007202. Both schedulers have the same betas, so the velocity targets should agree.
Context
The SDXL T2I-Adapter training script uses this result as its loss target when the scheduler is configured for v_prediction. I reproduced the mismatch at the scheduler call on CPU with synthetic inputs.
System Info
Diffusers 0.44.0.dev0 at 08d5de3, Python 3.14.5, PyTorch 2.15.0+cpu, Linux x86_64. Single process on CPU.
I checked EulerDiscreteScheduler in scheduling_euler_discrete.py against DDIMScheduler.get_velocity. In __init__, EulerDiscreteScheduler initializes self.timesteps in descending order (num_train_timesteps - 1 down to 0), so index_for_timestep(999.0) returns index 0 and flips the lookup against self.alphas_cumprod (which runs 0 to num_train_timesteps - 1). Passing timesteps directly as train_t2i_adapter_sdxl.py does hits that inverted lookup.
When you switch the lookup in get_velocity, there are two non-integer timestep paths in EulerDiscreteScheduler worth checking:
With use_karras_sigmas=True, use_exponential_sigmas=True, or use_beta_sigmas=True, _sigma_to_t produces fractional timesteps (and set_timesteps may have fewer than num_train_timesteps entries). Calling alphas_cumprod[timesteps.long()] directly would truncate fractional timesteps, whereas interpolating alphas_cumprod or deriving alpha_cumprod from sigmas[step_indices] after set_timesteps stays exact.
With timestep_type == "continuous" and prediction_type == "v_prediction", self.timesteps holds 0.25 * sigma.log(), which goes negative when sigma < 1. Casting those values with .long() would index from the end of alphas_cumprod or go out of bounds instead of recovering sigma = exp(4 * t) and alpha_cumprod = 1 / (sigma**2 + 1).
Guarding timestep_type == "discrete" (or routing continuous and interpolated timesteps separately) will keep discrete training scripts like SDXL T2I-Adapter working without silently mis-indexing continuous schedules.
Thanks, good points. My fix only uses the timestep value when it is an integer inside the training range. Fractional timesteps from the Karras, exponential and beta sigma schedules keep the current schedule-position lookup, and the continuous v-prediction case is skipped entirely, so nothing gets truncated or indexed from the end. The tests cover a fractional timestep (2.5) and a continuous log-sigma of 0.0. I'll open the PR once a maintainer confirms the approach.
Activity
varien199x commentedon Dec 3, 2026
Hey Mert, how's it going.
I checked
EulerDiscreteSchedulerin scheduling_euler_discrete.py against DDIMScheduler.get_velocity. In__init__,EulerDiscreteSchedulerinitializesself.timestepsin descending order (num_train_timesteps - 1down to0), soindex_for_timestep(999.0)returns index0and flips the lookup againstself.alphas_cumprod(which runs0tonum_train_timesteps - 1). Passingtimestepsdirectly as train_t2i_adapter_sdxl.py does hits that inverted lookup.When you switch the lookup in
get_velocity, there are two non-integer timestep paths inEulerDiscreteSchedulerworth checking:use_karras_sigmas=True,use_exponential_sigmas=True, oruse_beta_sigmas=True,_sigma_to_tproduces fractionaltimesteps(andset_timestepsmay have fewer thannum_train_timestepsentries). Callingalphas_cumprod[timesteps.long()]directly would truncate fractional timesteps, whereas interpolatingalphas_cumprodor derivingalpha_cumprodfromsigmas[step_indices]afterset_timestepsstays exact.timestep_type == "continuous"andprediction_type == "v_prediction",self.timestepsholds0.25 * sigma.log(), which goes negative whensigma < 1. Casting those values with.long()would index from the end ofalphas_cumprodor go out of bounds instead of recoveringsigma = exp(4 * t)andalpha_cumprod = 1 / (sigma**2 + 1).Guarding
timestep_type == "discrete"(or routing continuous and interpolated timesteps separately) will keep discrete training scripts like SDXL T2I-Adapter working without silently mis-indexing continuous schedules.mertkayacs commentedon Dec 3, 2026
Thanks, good points. My fix only uses the timestep value when it is an integer inside the training range. Fractional timesteps from the Karras, exponential and beta sigma schedules keep the current schedule-position lookup, and the continuous v-prediction case is skipped entirely, so nothing gets truncated or indexed from the end. The tests cover a fractional timestep (
2.5) and a continuous log-sigma of0.0. I'll open the PR once a maintainer confirms the approach.mertkayacs commentedon Dec 4, 2026
I opened #15491 for this. It only changes the integer timesteps inside the training range, as discussed above.