From ed971ddd57c02bf1d4b09a7db1012e5ef49926ea Mon Sep 17 00:00:00 2001 From: Osamaali313 Date: Fri, 17 Jul 2026 22:51:37 +0300 Subject: [PATCH] Fix DDIMParallelScheduler batch path ignoring final_alpha_cumprod `DDIMParallelScheduler`'s parallel path must match its sequential path (the ParaDiGMS correctness guarantee is parallel == sequential). For the terminal step (`prev_timestep < 0`), the scalar methods use `self.final_alpha_cumprod`: # _get_variance (l.274) and step (l.448) alpha_prod_t_prev = self.alphas_cumprod[prev_timestep] if prev_timestep >= 0 else self.final_alpha_cumprod but the batched methods hardcode `1.0`: # _batch_get_variance and batch_step_no_noise alpha_prod_t_prev[prev_t < 0] = torch.tensor(1.0) `self.final_alpha_cumprod` equals `1.0` only when `set_alpha_to_one=True`; with `set_alpha_to_one=False` (the default in Stable Diffusion 1.x scheduler configs) it is `alphas_cumprod[0]` (~0.999). So on the final denoising step the parallel path diverges from the sequential one. Use `self.final_alpha_cumprod` in both batched methods, matching the scalar siblings (it is already moved to the correct device before use). --- src/diffusers/schedulers/scheduling_ddim_parallel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/schedulers/scheduling_ddim_parallel.py b/src/diffusers/schedulers/scheduling_ddim_parallel.py index a5bbac60275c..11fb9d471669 100644 --- a/src/diffusers/schedulers/scheduling_ddim_parallel.py +++ b/src/diffusers/schedulers/scheduling_ddim_parallel.py @@ -282,7 +282,7 @@ def _get_variance(self, timestep: int, prev_timestep: int | None = None) -> torc def _batch_get_variance(self, t: torch.Tensor, prev_t: torch.Tensor) -> torch.Tensor: alpha_prod_t = self.alphas_cumprod[t] alpha_prod_t_prev = self.alphas_cumprod[torch.clip(prev_t, min=0)] - alpha_prod_t_prev[prev_t < 0] = torch.tensor(1.0) + alpha_prod_t_prev[prev_t < 0] = self.final_alpha_cumprod beta_prod_t = 1 - alpha_prod_t beta_prod_t_prev = 1 - alpha_prod_t_prev @@ -577,7 +577,7 @@ def batch_step_no_noise( self.final_alpha_cumprod = self.final_alpha_cumprod.to(model_output.device) alpha_prod_t = self.alphas_cumprod[t] alpha_prod_t_prev = self.alphas_cumprod[torch.clip(prev_t, min=0)] - alpha_prod_t_prev[prev_t < 0] = torch.tensor(1.0) + alpha_prod_t_prev[prev_t < 0] = self.final_alpha_cumprod beta_prod_t = 1 - alpha_prod_t