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

Commit a68d7a9

Browse files
authored
Merge pull request #63 from saddam213/Init
Improve ModelSet runtime management
2 parents a4cd36f + ef91017 commit a68d7a9

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

+367
-218
lines changed

OnnxStack.Console/Examples/StableDebug.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task RunAsync()
4848
Strength = 0.6f
4949
};
5050

51-
foreach (var model in _stableDiffusionService.Models)
51+
foreach (var model in _stableDiffusionService.ModelSets)
5252
{
5353
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
5454
await _stableDiffusionService.LoadModelAsync(model);
@@ -71,7 +71,7 @@ public async Task RunAsync()
7171
}
7272

7373

74-
private async Task<bool> GenerateImage(ModelOptions model, PromptOptions prompt, SchedulerOptions options)
74+
private async Task<bool> GenerateImage(StableDiffusionModelSet model, PromptOptions prompt, SchedulerOptions options)
7575
{
7676
var timestamp = Stopwatch.GetTimestamp();
7777
var outputFilename = Path.Combine(_outputDirectory, $"{model.Name}_{options.Seed}_{options.SchedulerType}.png");

OnnxStack.Console/Examples/StableDiffusionBatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task RunAsync()
5151
BatchType = BatchOptionType.Scheduler
5252
};
5353

54-
foreach (var model in _stableDiffusionService.Models)
54+
foreach (var model in _stableDiffusionService.ModelSets)
5555
{
5656
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
5757
await _stableDiffusionService.LoadModelAsync(model);

OnnxStack.Console/Examples/StableDiffusionExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task RunAsync()
4747
Seed = Random.Shared.Next()
4848
};
4949

50-
foreach (var model in _stableDiffusionService.Models)
50+
foreach (var model in _stableDiffusionService.ModelSets)
5151
{
5252
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
5353
await _stableDiffusionService.LoadModelAsync(model);
@@ -65,7 +65,7 @@ public async Task RunAsync()
6565
}
6666
}
6767

68-
private async Task<bool> GenerateImage(ModelOptions model, PromptOptions prompt, SchedulerOptions options)
68+
private async Task<bool> GenerateImage(StableDiffusionModelSet model, PromptOptions prompt, SchedulerOptions options)
6969
{
7070
var outputFilename = Path.Combine(_outputDirectory, $"{options.Seed}_{options.SchedulerType}.png");
7171
var result = await _stableDiffusionService.GenerateAsImageAsync(model, prompt, options);

OnnxStack.Console/Examples/StableDiffusionGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task RunAsync()
3131
Directory.CreateDirectory(_outputDirectory);
3232

3333
var seed = Random.Shared.Next();
34-
foreach (var model in _stableDiffusionService.Models)
34+
foreach (var model in _stableDiffusionService.ModelSets)
3535
{
3636
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
3737
await _stableDiffusionService.LoadModelAsync(model);
@@ -62,7 +62,7 @@ public async Task RunAsync()
6262
OutputHelpers.ReadConsole(ConsoleColor.Gray);
6363
}
6464

65-
private async Task<bool> GenerateImage(ModelOptions model, PromptOptions prompt, SchedulerOptions options, string key)
65+
private async Task<bool> GenerateImage(StableDiffusionModelSet model, PromptOptions prompt, SchedulerOptions options, string key)
6666
{
6767
var outputFilename = Path.Combine(_outputDirectory, $"{options.Seed}_{options.SchedulerType}_{key}.png");
6868
var result = await _stableDiffusionService.GenerateAsImageAsync(model, prompt, options);

OnnxStack.Console/Examples/StableDiffusionGif.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task RunAsync()
5454
};
5555

5656
// Choose Model
57-
var model = _stableDiffusionService.Models.FirstOrDefault(x => x.Name == "LCM-Dreamshaper-V7");
57+
var model = _stableDiffusionService.ModelSets.FirstOrDefault(x => x.Name == "LCM-Dreamshaper-V7");
5858
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
5959
await _stableDiffusionService.LoadModelAsync(model);
6060

OnnxStack.Console/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
}
77
},
88
"AllowedHosts": "*",
9-
"OnnxStackConfig": {
10-
"OnnxModelSets": [
9+
"StableDiffusionConfig": {
10+
"ModelSets": [
1111
{
1212
"Name": "StableDiffusion 1.5",
1313
"IsEnabled": true,

OnnxStack.Core/Config/IOnnxModelSetConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public interface IOnnxModelSetConfig : IOnnxModel
1111
int IntraOpNumThreads { get; set; }
1212
ExecutionMode ExecutionMode { get; set; }
1313
ExecutionProvider ExecutionProvider { get; set; }
14-
List<OnnxModelSessionConfig> ModelConfigurations { get; set; }
14+
List<OnnxModelConfig> ModelConfigurations { get; set; }
1515
}
1616
}

OnnxStack.Core/Config/OnnxModelSessionConfig.cs renamed to OnnxStack.Core/Config/OnnxModelConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace OnnxStack.Core.Config
55
{
6-
public class OnnxModelSessionConfig
6+
public class OnnxModelConfig
77
{
88
public OnnxModelType Type { get; set; }
99
public string OnnxModelPath { get; set; }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
3+
namespace OnnxStack.Core.Config
4+
{
5+
public class OnnxModelEqualityComparer : IEqualityComparer<IOnnxModel>
6+
{
7+
public bool Equals(IOnnxModel x, IOnnxModel y)
8+
{
9+
return x != null && y != null && x.Name == y.Name;
10+
}
11+
12+
public int GetHashCode(IOnnxModel obj)
13+
{
14+
return obj?.Name?.GetHashCode() ?? 0;
15+
}
16+
}
17+
}

OnnxStack.Core/Config/OnnxModelSetConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public class OnnxModelSetConfig : IOnnxModelSetConfig
1313
public int IntraOpNumThreads { get; set; }
1414
public ExecutionMode ExecutionMode { get; set; }
1515
public ExecutionProvider ExecutionProvider { get; set; }
16-
public List<OnnxModelSessionConfig> ModelConfigurations { get; set; }
16+
public List<OnnxModelConfig> ModelConfigurations { get; set; }
1717
}
1818
}

0 commit comments

Comments
 (0)