Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 0ab31dd

Browse files
committed
LCM: Fix 2 & 3 step inference
1 parent 3753452 commit 0ab31dd

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

OnnxStack.StableDiffusion/Schedulers/LatentConsistency/LCMScheduler.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Microsoft.ML.OnnxRuntime.Tensors;
2+
using NumSharp;
23
using OnnxStack.Core;
34
using OnnxStack.StableDiffusion.Config;
45
using OnnxStack.StableDiffusion.Enums;
56
using OnnxStack.StableDiffusion.Helpers;
67
using System;
78
using System.Collections.Generic;
89
using System.Linq;
10+
using System.Net;
911

1012
namespace OnnxStack.StableDiffusion.Schedulers.LatentConsistency
1113
{
@@ -67,19 +69,16 @@ protected override int[] SetTimesteps()
6769
var timeIncrement = Options.TrainTimesteps / Options.OriginalInferenceSteps;
6870

6971
//# LCM Training Steps Schedule
70-
var lcmOriginTimesteps = Enumerable.Range(0, Options.OriginalInferenceSteps)
71-
.Select(x => x * (timeIncrement - 1))
72+
var lcmOriginTimesteps = Enumerable.Range(1, Options.OriginalInferenceSteps)
73+
.Select(x => x * timeIncrement - 1)
7274
.ToArray();
7375

74-
var skippingStep = lcmOriginTimesteps.Length / Options.InferenceSteps;
75-
76-
// LCM Inference Steps Schedule
77-
var steps = lcmOriginTimesteps
78-
.Where((t, index) => index % skippingStep == 0)
79-
.Take(Options.InferenceSteps)
80-
.OrderByDescending(x => x)
81-
.ToArray();
82-
return steps;
76+
var steps = ArrayHelpers.Linspace(0, lcmOriginTimesteps.Length - 1, Options.InferenceSteps)
77+
.Select(x => (int)Math.Floor(x))
78+
.Select(x => lcmOriginTimesteps[x])
79+
.OrderByDescending(x => x)
80+
.ToArray();
81+
return steps;
8382
}
8483

8584

0 commit comments

Comments
 (0)