|
8 | 8 | using OnnxStack.StableDiffusion.Common; |
9 | 9 | using OnnxStack.StableDiffusion.Config; |
10 | 10 | using OnnxStack.StableDiffusion.Enums; |
| 11 | +using OnnxStack.StableDiffusion.Helpers; |
11 | 12 | using OnnxStack.StableDiffusion.Models; |
12 | 13 | using OnnxStack.StableDiffusion.Schedulers.LatentConsistency; |
13 | 14 | using System; |
@@ -176,21 +177,16 @@ protected override IScheduler GetScheduler(SchedulerOptions options) |
176 | 177 | /// <returns></returns> |
177 | 178 | protected DenseTensor<float> GetGuidanceScaleEmbedding(float guidance, int embeddingDim = 256) |
178 | 179 | { |
179 | | - var scale = guidance - 1f; |
| 180 | + var scale = (guidance - 1f) * 1000.0f; |
180 | 181 | var halfDim = embeddingDim / 2; |
181 | 182 | float log = MathF.Log(10000.0f) / (halfDim - 1); |
182 | 183 | var emb = Enumerable.Range(0, halfDim) |
183 | | - .Select(x => MathF.Exp(x * -log)) |
| 184 | + .Select(x => scale * MathF.Exp(-log * x)) |
184 | 185 | .ToArray(); |
185 | | - var embSin = emb.Select(MathF.Sin).ToArray(); |
186 | | - var embCos = emb.Select(MathF.Cos).ToArray(); |
187 | | - var result = new DenseTensor<float>(new[] { 1, 2 * halfDim }); |
188 | | - for (int i = 0; i < halfDim; i++) |
189 | | - { |
190 | | - result[0, i] = embSin[i]; |
191 | | - result[0, i + halfDim] = embCos[i]; |
192 | | - } |
193 | | - return result; |
| 186 | + var embSin = emb.Select(MathF.Sin); |
| 187 | + var embCos = emb.Select(MathF.Cos); |
| 188 | + var guidanceEmbedding = embSin.Concat(embCos).ToArray(); |
| 189 | + return new DenseTensor<float>(guidanceEmbedding, new[] { 1, embeddingDim }); |
194 | 190 | } |
195 | 191 | } |
196 | 192 | } |
0 commit comments