Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/diffusers/schedulers/scheduling_dpmsolver_multistep.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,13 @@ def set_timesteps(
sigmas = np.flip(sigmas).copy()
sigmas = self._convert_to_karras(in_sigmas=sigmas, num_inference_steps=num_inference_steps)
timesteps = np.array([self._sigma_to_t(sigma, log_sigmas) for sigma in sigmas])
if self.config.beta_schedule != "squaredcos_cap_v2":
timesteps = timesteps.round()
timesteps = timesteps.round()
elif self.config.use_lu_lambdas:
lambdas = np.flip(log_sigmas.copy())
lambdas = self._convert_to_lu(in_lambdas=lambdas, num_inference_steps=num_inference_steps)
sigmas = np.exp(lambdas)
timesteps = np.array([self._sigma_to_t(sigma, log_sigmas) for sigma in sigmas])
if self.config.beta_schedule != "squaredcos_cap_v2":
timesteps = timesteps.round()
timesteps = timesteps.round()
elif self.config.use_exponential_sigmas:
sigmas = np.flip(sigmas).copy()
sigmas = self._convert_to_exponential(in_sigmas=sigmas, num_inference_steps=num_inference_steps)
Expand All @@ -467,6 +465,16 @@ def set_timesteps(
else:
sigmas = np.interp(timesteps, np.arange(0, len(sigmas)), sigmas)

# When using karras or lu sigmas with certain beta schedules (e.g. squaredcos_cap_v2),
# the sigma-to-timestep mapping can produce duplicate integer timesteps. Deduplicate
# them to prevent the step index from drifting out of bounds during multistep updates.
timesteps_int = np.round(timesteps).astype(np.int64)
_, unique_indices = np.unique(timesteps_int, return_index=True)
if len(unique_indices) < len(timesteps_int):
unique_indices = np.sort(unique_indices)
timesteps = timesteps[unique_indices]
sigmas = sigmas[unique_indices]

if self.config.final_sigmas_type == "sigma_min":
sigma_last = ((1 - self.alphas_cumprod[0]) / self.alphas_cumprod[0]) ** 0.5
elif self.config.final_sigmas_type == "zero":
Expand Down