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

Commit a14bdf0

Browse files
committed
Add OriginalInferenceSteps scheduler parameter
1 parent 3d9cd5a commit a14bdf0

File tree

8 files changed

+60
-16
lines changed

8 files changed

+60
-16
lines changed

OnnxStack.StableDiffusion/Config/SchedulerOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ public class SchedulerOptions
8080
public AlphaTransformType AlphaTransformType { get; set; } = AlphaTransformType.Cosine;
8181
public float MaximumBeta { get; set; } = 0.999f;
8282

83-
83+
public int OriginalInferenceSteps { get; set; } = 30;
8484
}
8585
}

OnnxStack.StableDiffusion/Schedulers/LatentConsistency/LCMScheduler.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ internal class LCMScheduler : SchedulerBase
1212
{
1313
private float[] _alphasCumProd;
1414
private float _finalAlphaCumprod;
15-
private int _originalInferenceSteps;
1615

1716
/// <summary>
1817
/// Initializes a new instance of the <see cref="LCMScheduler"/> class.
@@ -52,10 +51,6 @@ protected override void Initialize()
5251
? 1.0f
5352
: _alphasCumProd.First();
5453

55-
//The default number of inference steps used to generate a linearly - spaced timestep schedule, from which we
56-
//will ultimately take `num_inference_steps` evenly spaced timesteps to form the final timestep schedule.
57-
_originalInferenceSteps = 50;
58-
5954
SetInitNoiseSigma(1.0f);
6055
}
6156

@@ -68,10 +63,10 @@ protected override int[] SetTimesteps()
6863
{
6964
// LCM Timesteps Setting
7065
// Currently, only linear spacing is supported.
71-
var timeIncrement = Options.TrainTimesteps / _originalInferenceSteps;
66+
var timeIncrement = Options.TrainTimesteps / Options.OriginalInferenceSteps;
7267

7368
//# LCM Training Steps Schedule
74-
var lcmOriginTimesteps = Enumerable.Range(1, _originalInferenceSteps)
69+
var lcmOriginTimesteps = Enumerable.Range(1, Options.OriginalInferenceSteps)
7570
.Select(x => x * timeIncrement - 1f)
7671
.ToArray();
7772

OnnxStack.UI/App.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
3232
<converters:InverseNullVisibilityConverter x:Key="InverseNullVisibilityConverter" />
3333
<converters:DiffuserVisibilityConverter x:Key="DiffuserVisibilityConverter" />
34+
<converters:PipelineVisibilityConverter x:Key="PipelineVisibilityConverter" />
3435

3536
<ObjectDataProvider x:Key="SchedulerType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
3637
<ObjectDataProvider.MethodParameters>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using OnnxStack.StableDiffusion.Enums;
2+
using System;
3+
using System.Globalization;
4+
using System.Windows;
5+
using System.Windows.Data;
6+
7+
namespace OnnxStack.UI.Converters
8+
{
9+
public class PipelineVisibilityConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
if (value is DiffuserPipelineType pipeLineValue)
14+
{
15+
Enum.TryParse<DiffuserPipelineType>(parameter.ToString(), true, out var parameterEnum);
16+
return pipeLineValue == parameterEnum ? Visibility.Visible : Visibility.Collapsed;
17+
}
18+
return Visibility.Visible;
19+
}
20+
21+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
}
26+
}

OnnxStack.UI/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Width="1200"
1212
Height="700"
1313
MinWidth="820"
14-
MinHeight="720"
14+
MinHeight="780"
1515
Icon="/Images/Icon.png" Name="UI"
1616
RenderOptions.BitmapScalingMode="HighQuality"
1717
RenderOptions.ClearTypeHint="Enabled"

OnnxStack.UI/Models/SchedulerOptionsModel.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class SchedulerOptionsModel : INotifyPropertyChanged
3131
private PredictionType _predictionType = PredictionType.Epsilon;
3232
private AlphaTransformType _alphaTransformType = AlphaTransformType.Cosine;
3333
private float _maximumBeta = 0.999f;
34+
private int _originalInferenceSteps = 100;
3435

3536
/// <summary>
3637
/// Gets or sets the height.
@@ -184,14 +185,23 @@ public PredictionType PredictionType
184185
get { return _predictionType; }
185186
set { _predictionType = value; NotifyPropertyChanged(); }
186187
}
187-
public AlphaTransformType AlphaTransformType { get { return _alphaTransformType; } set { _alphaTransformType = value; NotifyPropertyChanged(); } }
188+
public AlphaTransformType AlphaTransformType
189+
{
190+
get { return _alphaTransformType; }
191+
set { _alphaTransformType = value; NotifyPropertyChanged(); }
192+
}
193+
188194
public float MaximumBeta
189195
{
190196
get { return _maximumBeta; }
191197
set { _maximumBeta = value; NotifyPropertyChanged(); }
192198
}
193199

194-
200+
public int OriginalInferenceSteps
201+
{
202+
get { return _originalInferenceSteps; }
203+
set { _originalInferenceSteps = value; NotifyPropertyChanged(); }
204+
}
195205

196206
#region INotifyPropertyChanged
197207
public event PropertyChangedEventHandler PropertyChanged;

OnnxStack.UI/UserControls/SchedulerControl.xaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<Label>Inference Steps</Label>
5454
<TextBlock Text="{Binding ElementName=SliderInferenceSteps, Path=Value, StringFormat={}{0}}" VerticalAlignment="Bottom" HorizontalAlignment="Right" FontSize="10" Margin="0,0,6,0" FontWeight="Medium" />
5555
</DockPanel>
56-
<Slider Name="SliderInferenceSteps" Value="{Binding SchedulerOptions.InferenceSteps}" Minimum="{Binding OptionsConfig.StepsMin}" Maximum="{Binding OptionsConfig.StepsMax}" TickFrequency="1" IsSnapToTickEnabled="True" SmallChange="1" LargeChange="1" >
56+
<Slider Name="SliderInferenceSteps" Value="{Binding SchedulerOptions.InferenceSteps}" Minimum="2" Maximum="{Binding SchedulerOptions.OriginalInferenceSteps}" TickFrequency="1" IsSnapToTickEnabled="True" SmallChange="1" LargeChange="1" >
5757
<i:Interaction.Behaviors>
5858
<behaviors:SliderMouseWheelBehavior />
5959
</i:Interaction.Behaviors>
@@ -207,6 +207,19 @@
207207
</StackPanel>
208208
</UniformGrid>
209209

210+
<UniformGrid Columns="3">
211+
<StackPanel Visibility="{Binding SelectedModel.ModelOptions.PipelineType, Converter={StaticResource PipelineVisibilityConverter}, ConverterParameter=LatentConsistency}">
212+
<Label>LCM Original Steps</Label>
213+
<TextBox Text="{Binding SchedulerOptions.OriginalInferenceSteps}"/>
214+
</StackPanel>
215+
<StackPanel Margin="1,0,1,0">
216+
217+
</StackPanel>
218+
<StackPanel VerticalAlignment="Bottom">
219+
220+
</StackPanel>
221+
</UniformGrid>
222+
210223
<StackPanel HorizontalAlignment="Right">
211224
<Button Command="{Binding ResetParametersCommand}" Margin="0,5,0,0">
212225
<userControls:FontAwesome Icon="&#xf2ea;" IconStyle="Light" Size="14" Margin="2"/>

OnnxStack.UI/UserControls/SchedulerControl.xaml.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Models;
22
using OnnxStack.Core;
3+
using OnnxStack.StableDiffusion.Config;
34
using OnnxStack.StableDiffusion.Enums;
45
using OnnxStack.UI.Commands;
56
using OnnxStack.UI.Models;
@@ -94,14 +95,12 @@ private void OnModelChanged(ModelOptionsModel model)
9495

9596
if (model.ModelOptions.PipelineType == DiffuserPipelineType.StableDiffusion)
9697
{
97-
OptionsConfig.StepsMin = 4;
98-
OptionsConfig.StepsMax = 100;
98+
SchedulerOptions.OriginalInferenceSteps = 100;
9999
SchedulerOptions.InferenceSteps = 30;
100100
}
101101
else if (model.ModelOptions.PipelineType == DiffuserPipelineType.LatentConsistency)
102102
{
103-
OptionsConfig.StepsMin = 1;
104-
OptionsConfig.StepsMax = 50;
103+
SchedulerOptions.OriginalInferenceSteps = 50;
105104
SchedulerOptions.InferenceSteps = 6;
106105
}
107106
}

0 commit comments

Comments
 (0)