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

Commit afae65b

Browse files
committed
Lower default step count for LCM
1 parent 86d7195 commit afae65b

File tree

9 files changed

+89
-15
lines changed

9 files changed

+89
-15
lines changed

OnnxStack.StableDiffusion/Schedulers/LatentConsistency/LCMScheduler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected override void Initialize()
5454

5555
//The default number of inference steps used to generate a linearly - spaced timestep schedule, from which we
5656
//will ultimately take `num_inference_steps` evenly spaced timesteps to form the final timestep schedule.
57-
_originalInferenceSteps = 30;
57+
_originalInferenceSteps = 50;
5858

5959
SetInitNoiseSigma(1.0f);
6060
}

OnnxStack.UI/Models/ImageResult.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OnnxStack.StableDiffusion.Config;
1+
using Models;
2+
using OnnxStack.StableDiffusion.Config;
23
using OnnxStack.StableDiffusion.Enums;
34
using System;
45
using System.Text.Json.Serialization;
@@ -11,6 +12,9 @@ public class ImageResult
1112
[JsonIgnore]
1213
public BitmapSource Image { get; init; }
1314

15+
[JsonIgnore]
16+
public ModelOptionsModel Model { get; set; }
17+
1418
public DateTime Timestamp { get; } = DateTime.UtcNow;
1519
public DiffuserType DiffuserType { get; init; }
1620
public string Prompt { get; init; }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.ComponentModel;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace OnnxStack.UI.Models
5+
{
6+
public class SchedulerOptionsConfig : INotifyPropertyChanged
7+
{
8+
9+
private int _stepsMin = 4;
10+
private int _stepsMax = 100;
11+
12+
public int StepsMin
13+
{
14+
get { return _stepsMin; }
15+
set { _stepsMin = value; NotifyPropertyChanged(); }
16+
}
17+
18+
public int StepsMax
19+
{
20+
get { return _stepsMax; }
21+
set { _stepsMax = value; NotifyPropertyChanged(); }
22+
}
23+
24+
25+
#region INotifyPropertyChanged
26+
public event PropertyChangedEventHandler PropertyChanged;
27+
public void NotifyPropertyChanged([CallerMemberName] string property = "")
28+
{
29+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
30+
}
31+
#endregion
32+
}
33+
}

OnnxStack.UI/UserControls/PromptControl.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public ObservableCollection<SchedulerType> SchedulerTypes
7676
private void OnModelChanged(ModelOptionsModel model)
7777
{
7878
SchedulerTypes.Clear();
79+
if (model is null)
80+
return;
81+
7982
if (model.ModelOptions.PipelineType == DiffuserPipelineType.StableDiffusion)
8083
{
8184
foreach (SchedulerType type in Enum.GetValues<SchedulerType>().Where(x => x != SchedulerType.LCM))

OnnxStack.UI/UserControls/SchedulerControl.xaml

Lines changed: 1 addition & 1 deletion
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="4" Maximum="100" TickFrequency="1" IsSnapToTickEnabled="True" SmallChange="0.1" LargeChange="0.1" >
56+
<Slider Name="SliderInferenceSteps" Value="{Binding SchedulerOptions.InferenceSteps}" Minimum="{Binding OptionsConfig.StepsMin}" Maximum="{Binding OptionsConfig.StepsMax}" TickFrequency="1" IsSnapToTickEnabled="True" SmallChange="1" LargeChange="1" >
5757
<i:Interaction.Behaviors>
5858
<behaviors:SliderMouseWheelBehavior />
5959
</i:Interaction.Behaviors>

OnnxStack.UI/UserControls/SchedulerControl.xaml.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System;
77
using System.Collections.ObjectModel;
88
using System.ComponentModel;
9-
using System.Linq;
109
using System.Runtime.CompilerServices;
1110
using System.Windows;
1211
using System.Windows.Controls;
@@ -19,6 +18,7 @@ namespace OnnxStack.UI.UserControls
1918
/// </summary>
2019
public partial class SchedulerControl : UserControl, INotifyPropertyChanged
2120
{
21+
private SchedulerOptionsConfig _optionsConfig = new();
2222

2323
/// <summary>Initializes a new instance of the <see cref="SchedulerControl" /> class.</summary>
2424
public SchedulerControl()
@@ -29,19 +29,18 @@ public SchedulerControl()
2929
InitializeComponent();
3030
}
3131

32-
/// <summary>Gets the reset parameters command.</summary>
33-
/// <value>The reset parameters command.</value>
3432
public ICommand ResetParametersCommand { get; }
3533
public ICommand RandomSeedCommand { get; }
3634
public ObservableCollection<int> ValidSizes { get; }
3735

38-
36+
/// <summary>
37+
/// Gets or sets the selected model.
38+
/// </summary>
3939
public ModelOptionsModel SelectedModel
4040
{
4141
get { return (ModelOptionsModel)GetValue(SelectedModelProperty); }
4242
set { SetValue(SelectedModelProperty, value); }
4343
}
44-
4544
public static readonly DependencyProperty SelectedModelProperty =
4645
DependencyProperty.Register("SelectedModel", typeof(ModelOptionsModel), typeof(SchedulerControl), new PropertyMetadata((d, e) =>
4746
{
@@ -50,17 +49,18 @@ public ModelOptionsModel SelectedModel
5049
}));
5150

5251

52+
/// <summary>
53+
/// Gets or sets the type of the diffuser.
54+
/// </summary>
5355
public DiffuserType DiffuserType
5456
{
5557
get { return (DiffuserType)GetValue(DiffuserTypeProperty); }
5658
set { SetValue(DiffuserTypeProperty, value); }
5759
}
58-
5960
public static readonly DependencyProperty DiffuserTypeProperty =
6061
DependencyProperty.Register("DiffuserType", typeof(DiffuserType), typeof(SchedulerControl));
6162

6263

63-
6464
/// <summary>
6565
/// Gets or sets the SchedulerOptions.
6666
/// </summary>
@@ -69,14 +69,18 @@ public SchedulerOptionsModel SchedulerOptions
6969
get { return (SchedulerOptionsModel)GetValue(SchedulerOptionsProperty); }
7070
set { SetValue(SchedulerOptionsProperty, value); }
7171
}
72+
public static readonly DependencyProperty SchedulerOptionsProperty =
73+
DependencyProperty.Register("SchedulerOptions", typeof(SchedulerOptionsModel), typeof(SchedulerControl));
7274

7375

7476
/// <summary>
75-
/// The SchedulerOptions property
77+
/// Gets or sets the options configuration.
7678
/// </summary>
77-
public static readonly DependencyProperty SchedulerOptionsProperty =
78-
DependencyProperty.Register("SchedulerOptions", typeof(SchedulerOptionsModel), typeof(SchedulerControl));
79-
79+
public SchedulerOptionsConfig OptionsConfig
80+
{
81+
get { return _optionsConfig; }
82+
set { _optionsConfig = value; NotifyPropertyChanged(); }
83+
}
8084

8185

8286
/// <summary>
@@ -85,7 +89,21 @@ public SchedulerOptionsModel SchedulerOptions
8589
/// <param name="modelOptionsModel">The model options model.</param>
8690
private void OnModelChanged(ModelOptionsModel model)
8791
{
88-
92+
if (model is null)
93+
return;
94+
95+
if (model.ModelOptions.PipelineType == DiffuserPipelineType.StableDiffusion)
96+
{
97+
OptionsConfig.StepsMin = 4;
98+
OptionsConfig.StepsMax = 100;
99+
SchedulerOptions.InferenceSteps = 30;
100+
}
101+
else if (model.ModelOptions.PipelineType == DiffuserPipelineType.LatentConsistency)
102+
{
103+
OptionsConfig.StepsMin = 1;
104+
OptionsConfig.StepsMax = 50;
105+
SchedulerOptions.InferenceSteps = 6;
106+
}
89107
}
90108

91109

OnnxStack.UI/Views/ImageInpaint.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public Task NavigateAsync(ImageResult imageResult)
163163
HasInputResult = true;
164164
HasInputMaskResult = false;
165165
InputImageMask = null;
166+
if (imageResult.Model.ModelOptions.Diffusers.Contains(DiffuserType.ImageInpaint)
167+
|| imageResult.Model.ModelOptions.Diffusers.Contains(DiffuserType.ImageInpaintLegacy))
168+
{
169+
SelectedModel = imageResult.Model;
170+
}
166171
InputImage = new ImageInput
167172
{
168173
Image = imageResult.Image,
@@ -314,6 +319,7 @@ private async Task<ImageResult> ExecuteStableDiffusion(IModelOptions modelOption
314319
return new ImageResult
315320
{
316321
Image = image,
322+
Model = _selectedModel,
317323
Prompt = promptOptions.Prompt,
318324
NegativePrompt = promptOptions.NegativePrompt,
319325
DiffuserType = promptOptions.DiffuserType,

OnnxStack.UI/Views/ImageToImage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public Task NavigateAsync(ImageResult imageResult)
145145
HasResult = false;
146146
ResultImage = null;
147147
HasInputResult = true;
148+
if (imageResult.Model.ModelOptions.Diffusers.Contains(DiffuserType.ImageToImage))
149+
{
150+
SelectedModel = imageResult.Model;
151+
}
148152
InputImage = new ImageInput
149153
{
150154
Image = imageResult.Image,
@@ -288,6 +292,7 @@ private async Task<ImageResult> ExecuteStableDiffusion(IModelOptions modelOption
288292
return new ImageResult
289293
{
290294
Image = image,
295+
Model = _selectedModel,
291296
Prompt = promptOptions.Prompt,
292297
NegativePrompt = promptOptions.NegativePrompt,
293298
DiffuserType = promptOptions.DiffuserType,

OnnxStack.UI/Views/TextToImage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ public Task NavigateAsync(ImageResult imageResult)
131131
Reset();
132132
HasResult = false;
133133
ResultImage = null;
134+
if (imageResult.Model.ModelOptions.Diffusers.Contains(DiffuserType.TextToImage))
135+
{
136+
SelectedModel = imageResult.Model;
137+
}
134138
PromptOptions = new PromptOptionsModel
135139
{
136140
Prompt = imageResult.Prompt,
@@ -262,6 +266,7 @@ private async Task<ImageResult> ExecuteStableDiffusion(IModelOptions modelOption
262266
return new ImageResult
263267
{
264268
Image = image,
269+
Model = _selectedModel,
265270
Prompt = promptOptions.Prompt,
266271
NegativePrompt = promptOptions.NegativePrompt,
267272
DiffuserType = promptOptions.DiffuserType,

0 commit comments

Comments
 (0)