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

Commit cee0288

Browse files
committed
Merge branch 'master' into CUDA
# Conflicts: # OnnxStack.UI/OnnxStack.UI.csproj
2 parents e1a63bb + f29bfa4 commit cee0288

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5113
-5620
lines changed

OnnxStack.Console/appsettings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"IsEnabled": true,
1414
"PadTokenId": 49407,
1515
"BlankTokenId": 49407,
16-
"InputTokenLimit": 2048,
1716
"TokenizerLimit": 77,
1817
"EmbeddingsLength": 768,
1918
"ScaleFactor": 0.18215,

OnnxStack.Core/Config/OnnxModelType.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ public enum OnnxModelType
77
TextEncoder = 20,
88
VaeEncoder = 30,
99
VaeDecoder = 40,
10-
SafetyChecker = 100,
1110
}
1211
}

OnnxStack.StableDiffusion/Common/IModelOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public interface IModelOptions : IOnnxModel
1212
int BlankTokenId { get; set; }
1313
float ScaleFactor { get; set; }
1414
int TokenizerLimit { get; set; }
15-
int InputTokenLimit { get; set; }
1615
int EmbeddingsLength { get; set; }
1716
DiffuserPipelineType PipelineType { get; set; }
1817
List<DiffuserType> Diffusers { get; set; }

OnnxStack.StableDiffusion/Config/ModelOptions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class ModelOptions : IModelOptions, IOnnxModelSetConfig
1515
public bool IsEnabled { get; set; }
1616
public int PadTokenId { get; set; }
1717
public int BlankTokenId { get; set; }
18-
public int InputTokenLimit { get; set; } = 2048;
1918
public int TokenizerLimit { get; set; }
2019
public int EmbeddingsLength { get; set; }
2120
public float ScaleFactor { get; set; }
@@ -34,7 +33,7 @@ public class ModelOptions : IModelOptions, IOnnxModelSetConfig
3433

3534
public void InitBlankTokenArray()
3635
{
37-
BlankTokenValueArray = Enumerable.Repeat(BlankTokenId, InputTokenLimit).ToImmutableArray();
36+
BlankTokenValueArray = Enumerable.Repeat(BlankTokenId, 20480).ToImmutableArray();
3837
}
3938
}
4039
}

OnnxStack.StableDiffusion/Diffusers/LatentConsistency/LatentConsistencyDiffuser.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,18 @@ protected virtual async Task<DenseTensor<float>> DecodeLatents(IModelOptions mod
193193
protected virtual IReadOnlyList<NamedOnnxValue> CreateUnetInputParams(IModelOptions model, DenseTensor<float> inputTensor, DenseTensor<float> promptEmbeddings, DenseTensor<float> guidanceEmbeddings, int timestep)
194194
{
195195
var inputNames = _onnxModelService.GetInputNames(model, OnnxModelType.Unet);
196+
var inputMetaData = _onnxModelService.GetInputMetadata(model, OnnxModelType.Unet);
197+
198+
// Some models support Long or Float, could be more but fornow just support these 2
199+
var timesepMetaKey = inputNames[1];
200+
var timestepMetaData = inputMetaData[timesepMetaKey];
201+
var timestepNamedOnnxValue = timestepMetaData.ElementDataType == TensorElementType.Int64
202+
? NamedOnnxValue.CreateFromTensor(timesepMetaKey, new DenseTensor<long>(new long[] { timestep }, new int[] { 1 }))
203+
: NamedOnnxValue.CreateFromTensor(timesepMetaKey, new DenseTensor<float>(new float[] { timestep }, new int[] { 1 }));
204+
196205
return CreateInputParameters(
197206
NamedOnnxValue.CreateFromTensor(inputNames[0], inputTensor),
198-
NamedOnnxValue.CreateFromTensor(inputNames[1], new DenseTensor<long>(new long[] { timestep }, new int[] { 1 })),
207+
timestepNamedOnnxValue,
199208
NamedOnnxValue.CreateFromTensor(inputNames[2], promptEmbeddings),
200209
NamedOnnxValue.CreateFromTensor(inputNames[3], guidanceEmbeddings));
201210
}

OnnxStack.StableDiffusion/Diffusers/StableDiffusion/StableDiffusionDiffuser.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,18 @@ protected virtual DenseTensor<float> PerformGuidance(DenseTensor<float> noisePre
213213
protected virtual IReadOnlyList<NamedOnnxValue> CreateUnetInputParams(IModelOptions model, DenseTensor<float> inputTensor, DenseTensor<float> promptEmbeddings, int timestep)
214214
{
215215
var inputNames = _onnxModelService.GetInputNames(model, OnnxModelType.Unet);
216+
var inputMetaData = _onnxModelService.GetInputMetadata(model, OnnxModelType.Unet);
217+
218+
// Some models support Long or Float, could be more but fornow just support these 2
219+
var timesepMetaKey = inputNames[1];
220+
var timestepMetaData = inputMetaData[timesepMetaKey];
221+
var timestepNamedOnnxValue = timestepMetaData.ElementDataType == TensorElementType.Int64
222+
? NamedOnnxValue.CreateFromTensor(timesepMetaKey, new DenseTensor<long>(new long[] { timestep }, new int[] { 1 }))
223+
: NamedOnnxValue.CreateFromTensor(timesepMetaKey, new DenseTensor<float>(new float[] { timestep }, new int[] { 1 }));
224+
216225
return CreateInputParameters(
217226
NamedOnnxValue.CreateFromTensor(inputNames[0], inputTensor),
218-
NamedOnnxValue.CreateFromTensor(inputNames[1], new DenseTensor<long>(new long[] { timestep }, new int[] { 1 })),
227+
timestepNamedOnnxValue,
219228
NamedOnnxValue.CreateFromTensor(inputNames[2], promptEmbeddings));
220229
}
221230

OnnxStack.StableDiffusion/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ Each model can be assigned to its own device, which is handy if you have only a
153153
"Name": "StableDiffusion 1.5",
154154
"PadTokenId": 49407,
155155
"BlankTokenId": 49407,
156-
"InputTokenLimit": 512,
157156
"TokenizerLimit": 77,
158157
"EmbeddingsLength": 768,
159158
"ScaleFactor": 0.18215,

0 commit comments

Comments
 (0)