Store timesteps in reverse order for consistency.

pull/73/head
Pedro Cuenca 1 year ago committed by Timothy Kautz
parent 3c30af52ee
commit d9563fb586

@ -178,10 +178,5 @@ public final class DPMSolverMultistepScheduler: Scheduler {
}
return prevSample
}
/// This scheduler does not support image2image strength value.
public func calculateTimesteps(strength: Float?) -> [Int] {
timeSteps
}
}
}

@ -92,12 +92,11 @@ public extension Scheduler {
@available(iOS 16.2, macOS 13.1, *)
public extension Scheduler {
func calculateTimesteps(strength: Float?) -> [Int] {
guard let strength else { return timeSteps.reversed() }
let startStep = Int(Float(inferenceStepCount) * strength)
let acutalTimesteps = Array(timeSteps[0..<startStep].reversed())
return acutalTimesteps
guard let strength else { return timeSteps }
let startStep = max(inferenceStepCount - Int(Float(inferenceStepCount) * strength), 0)
let actualTimesteps = Array(timeSteps[startStep...])
return actualTimesteps
}
}
@ -175,7 +174,7 @@ public final class PNDMScheduler: Scheduler {
timeSteps.append(contentsOf: forwardSteps.dropLast(1))
timeSteps.append(timeSteps.last!)
timeSteps.append(forwardSteps.last!)
// do no revers timeSteps, this is now done in `calculateTimesteps` function
timeSteps.reverse()
self.timeSteps = timeSteps
self.counter = 0

@ -23,7 +23,6 @@ public struct StableDiffusionPipeline: ResourceManaging {
public enum Error: String, Swift.Error {
case startingImageProvidedWithoutEncoder
case schedulerNotSupportedWithImage2Image
}
/// Model to generate embeddings for tokenized input text
@ -170,12 +169,6 @@ public struct StableDiffusionPipeline: ResourceManaging {
guard let encoder else {
throw Error.startingImageProvidedWithoutEncoder
}
switch schedulerType {
case .pndmScheduler:
break
case .dpmSolverMultistepScheduler:
throw Error.schedulerNotSupportedWithImage2Image
}
let noiseTuples = generateImage2ImageLatentSamples(imageCount, stdev: 1, seed: seed)
latents = try noiseTuples.map({

Loading…
Cancel
Save