From e3db2ec99e37b46b73a0eb038091a689b0cffa54 Mon Sep 17 00:00:00 2001 From: Pedro Cuenca Date: Wed, 28 Dec 2022 21:04:34 +0100 Subject: [PATCH] Fix timesteps of DPMSolverMultistepScheduler. (#88) There were minor differences in the timesteps because the linspace was computed slightly differently. This PR makes the Swift implementation identical to the current Python implementation in diffusers, which was originally contributed by the DPM-Solver++ author. See https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_dpmsolver_multistep.py#L199-L204 for reference. --- .../StableDiffusion/pipeline/DPMSolverMultistepScheduler.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swift/StableDiffusion/pipeline/DPMSolverMultistepScheduler.swift b/swift/StableDiffusion/pipeline/DPMSolverMultistepScheduler.swift index 704472a..1fbfff1 100644 --- a/swift/StableDiffusion/pipeline/DPMSolverMultistepScheduler.swift +++ b/swift/StableDiffusion/pipeline/DPMSolverMultistepScheduler.swift @@ -77,7 +77,7 @@ public final class DPMSolverMultistepScheduler: Scheduler { self.sigma_t = vForce.sqrt(vDSP.subtract([Float](repeating: 1, count: self.alphasCumProd.count), self.alphasCumProd)) self.lambda_t = zip(self.alpha_t, self.sigma_t).map { α, σ in log(α) - log(σ) } - self.timeSteps = linspace(0, Float(self.trainStepCount-1), stepCount).reversed().map { Int(round($0)) } + self.timeSteps = linspace(0, Float(self.trainStepCount-1), stepCount+1).dropFirst().reversed().map { Int(round($0)) } } /// Convert the model output to the corresponding type the algorithm needs.