Skip to content

Commit e3db2ec

Browse files
authored
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.
1 parent e07c4d0 commit e3db2ec

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

swift/StableDiffusion/pipeline/DPMSolverMultistepScheduler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public final class DPMSolverMultistepScheduler: Scheduler {
7777
self.sigma_t = vForce.sqrt(vDSP.subtract([Float](repeating: 1, count: self.alphasCumProd.count), self.alphasCumProd))
7878
self.lambda_t = zip(self.alpha_t, self.sigma_t).map { α, σ in log(α) - log(σ) }
7979

80-
self.timeSteps = linspace(0, Float(self.trainStepCount-1), stepCount).reversed().map { Int(round($0)) }
80+
self.timeSteps = linspace(0, Float(self.trainStepCount-1), stepCount+1).dropFirst().reversed().map { Int(round($0)) }
8181
}
8282

8383
/// Convert the model output to the corresponding type the algorithm needs.

0 commit comments

Comments
 (0)