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

Commit 3530a63

Browse files
authored
Merge pull request #28 from riddlemd/master
Added Async suffix to any methods that returned a Task or Task<>
2 parents 6d6ea5a + 3755b1c commit 3530a63

32 files changed

+109
-109
lines changed

OnnxStack.Console/Examples/StableDebug.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public async Task RunAsync()
5252
foreach (var model in _stableDiffusionService.Models)
5353
{
5454
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
55-
await _stableDiffusionService.LoadModel(model);
55+
await _stableDiffusionService.LoadModelAsync(model);
5656

5757
foreach (var schedulerType in model.PipelineType.GetSchedulerTypes())
5858
{
@@ -62,7 +62,7 @@ public async Task RunAsync()
6262
}
6363

6464
OutputHelpers.WriteConsole($"Unloading Model `{model.Name}`...", ConsoleColor.Green);
65-
await _stableDiffusionService.UnloadModel(model);
65+
await _stableDiffusionService.UnloadModelAsync(model);
6666
}
6767
break;
6868
}

OnnxStack.Console/Examples/StableDiffusionBatch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task RunAsync()
5454
foreach (var model in _stableDiffusionService.Models)
5555
{
5656
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
57-
await _stableDiffusionService.LoadModel(model);
57+
await _stableDiffusionService.LoadModelAsync(model);
5858

5959
var batchIndex = 0;
6060
var callback = (int batch, int batchCount, int step, int steps) =>
@@ -72,7 +72,7 @@ public async Task RunAsync()
7272
}
7373

7474
OutputHelpers.WriteConsole($"Unloading Model `{model.Name}`...", ConsoleColor.Green);
75-
await _stableDiffusionService.UnloadModel(model);
75+
await _stableDiffusionService.UnloadModelAsync(model);
7676
}
7777
}
7878
}

OnnxStack.Console/Examples/StableDiffusionExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task RunAsync()
5050
foreach (var model in _stableDiffusionService.Models)
5151
{
5252
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
53-
await _stableDiffusionService.LoadModel(model);
53+
await _stableDiffusionService.LoadModelAsync(model);
5454

5555
foreach (var schedulerType in model.PipelineType.GetSchedulerTypes())
5656
{
@@ -60,7 +60,7 @@ public async Task RunAsync()
6060
}
6161

6262
OutputHelpers.WriteConsole($"Unloading Model `{model.Name}`...", ConsoleColor.Green);
63-
await _stableDiffusionService.UnloadModel(model);
63+
await _stableDiffusionService.UnloadModelAsync(model);
6464
}
6565
}
6666
}

OnnxStack.Console/Examples/StableDiffusionGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task RunAsync()
3434
foreach (var model in _stableDiffusionService.Models)
3535
{
3636
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
37-
await _stableDiffusionService.LoadModel(model);
37+
await _stableDiffusionService.LoadModelAsync(model);
3838

3939
foreach (var generationPrompt in _generationPrompts)
4040
{
@@ -56,7 +56,7 @@ public async Task RunAsync()
5656
}
5757

5858
OutputHelpers.WriteConsole($"Unloading Model `{model.Name}`...", ConsoleColor.Green);
59-
await _stableDiffusionService.UnloadModel(model);
59+
await _stableDiffusionService.UnloadModelAsync(model);
6060
}
6161
OutputHelpers.WriteConsole("Complete :)", ConsoleColor.DarkMagenta);
6262
OutputHelpers.ReadConsole(ConsoleColor.Gray);

OnnxStack.Core/Services/IOnnxModelService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public interface IOnnxModelService : IDisposable
1515
/// </summary>
1616
/// <param name="model">The model.</param>
1717
/// <returns></returns>
18-
Task<OnnxModelSet> LoadModel(IOnnxModel model);
18+
Task<OnnxModelSet> LoadModelAsync(IOnnxModel model);
1919

2020
/// <summary>
2121
/// Unloads the model.
2222
/// </summary>
2323
/// <param name="model">The model.</param>
2424
/// <returns></returns>
25-
Task<bool> UnloadModel(IOnnxModel model);
25+
Task<bool> UnloadModelAsync(IOnnxModel model);
2626

2727
/// <summary>
2828
/// Determines whether the specified model is loaded.

OnnxStack.Core/Services/OnnxModelService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public bool UpdateModelSet(IOnnxModelSetConfig modelSet)
4848
/// </summary>
4949
/// <param name="model">The model.</param>
5050
/// <returns></returns>
51-
public async Task<OnnxModelSet> LoadModel(IOnnxModel model)
51+
public async Task<OnnxModelSet> LoadModelAsync(IOnnxModel model)
5252
{
5353
return await Task.Run(() => LoadModelSet(model)).ConfigureAwait(false);
5454
}
@@ -58,7 +58,7 @@ public async Task<OnnxModelSet> LoadModel(IOnnxModel model)
5858
/// </summary>
5959
/// <param name="model">The model.</param>
6060
/// <returns></returns>
61-
public async Task<bool> UnloadModel(IOnnxModel model)
61+
public async Task<bool> UnloadModelAsync(IOnnxModel model)
6262
{
6363
return await Task.Run(() => UnloadModelSet(model)).ConfigureAwait(false);
6464
}

OnnxStack.StableDiffusion/Common/IStableDiffusionService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public interface IStableDiffusionService
2626
/// </summary>
2727
/// <param name="modelOptions">The model options.</param>
2828
/// <returns></returns>
29-
Task<bool> LoadModel(IModelOptions modelOptions);
29+
Task<bool> LoadModelAsync(IModelOptions modelOptions);
3030

3131

3232
/// <summary>
3333
/// Unloads the model.
3434
/// </summary>
3535
/// <param name="modelOptions">The model options.</param>
3636
/// <returns></returns>
37-
Task<bool> UnloadModel(IModelOptions modelOptions);
37+
Task<bool> UnloadModelAsync(IModelOptions modelOptions);
3838

3939
/// <summary>
4040
/// Determines whether the specified model is loaded

OnnxStack.StableDiffusion/Diffusers/DiffuserBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public DiffuserBase(IOnnxModelService onnxModelService, IPromptService promptSer
7373
/// <param name="scheduler">The scheduler.</param>
7474
/// <param name="timesteps">The timesteps.</param>
7575
/// <returns></returns>
76-
protected abstract Task<DenseTensor<float>> PrepareLatents(IModelOptions model, PromptOptions prompt, SchedulerOptions options, IScheduler scheduler, IReadOnlyList<int> timesteps);
76+
protected abstract Task<DenseTensor<float>> PrepareLatentsAsync(IModelOptions model, PromptOptions prompt, SchedulerOptions options, IScheduler scheduler, IReadOnlyList<int> timesteps);
7777

7878

7979
/// <summary>
@@ -87,7 +87,7 @@ public DiffuserBase(IOnnxModelService onnxModelService, IPromptService promptSer
8787
/// <param name="progressCallback">The progress callback.</param>
8888
/// <param name="cancellationToken">The cancellation token.</param>
8989
/// <returns></returns>
90-
protected abstract Task<DenseTensor<float>> SchedulerStep(IModelOptions modelOptions, PromptOptions promptOptions, SchedulerOptions schedulerOptions, DenseTensor<float> promptEmbeddings, bool performGuidance, Action<int, int> progressCallback = null, CancellationToken cancellationToken = default);
90+
protected abstract Task<DenseTensor<float>> SchedulerStepAsync(IModelOptions modelOptions, PromptOptions promptOptions, SchedulerOptions schedulerOptions, DenseTensor<float> promptEmbeddings, bool performGuidance, Action<int, int> progressCallback = null, CancellationToken cancellationToken = default);
9191

9292

9393
/// <summary>
@@ -113,7 +113,7 @@ public virtual async Task<DenseTensor<float>> DiffuseAsync(IModelOptions modelOp
113113
var promptEmbeddings = await _promptService.CreatePromptAsync(modelOptions, promptOptions, performGuidance);
114114

115115
// Run Scheduler steps
116-
var schedulerResult = await SchedulerStep(modelOptions, promptOptions, schedulerOptions, promptEmbeddings, performGuidance, progressCallback, cancellationToken);
116+
var schedulerResult = await SchedulerStepAsync(modelOptions, promptOptions, schedulerOptions, promptEmbeddings, performGuidance, progressCallback, cancellationToken);
117117

118118
_logger?.LogEnd($"End", diffuseTime);
119119

@@ -153,7 +153,7 @@ public virtual async IAsyncEnumerable<BatchResult> DiffuseBatchAsync(IModelOptio
153153
var schedulerCallback = (int step, int steps) => progressCallback?.Invoke(batchIndex, batchSchedulerOptions.Count, step, steps);
154154
foreach (var batchSchedulerOption in batchSchedulerOptions)
155155
{
156-
yield return new BatchResult(batchSchedulerOption, await SchedulerStep(modelOptions, promptOptions, batchSchedulerOption, promptEmbeddings, performGuidance, schedulerCallback, cancellationToken));
156+
yield return new BatchResult(batchSchedulerOption, await SchedulerStepAsync(modelOptions, promptOptions, batchSchedulerOption, promptEmbeddings, performGuidance, schedulerCallback, cancellationToken));
157157
batchIndex++;
158158
}
159159

@@ -203,7 +203,7 @@ protected virtual DenseTensor<float> PerformGuidance(DenseTensor<float> noisePre
203203
/// <param name="options">The options.</param>
204204
/// <param name="latents">The latents.</param>
205205
/// <returns></returns>
206-
protected virtual async Task<DenseTensor<float>> DecodeLatents(IModelOptions model, PromptOptions prompt, SchedulerOptions options, DenseTensor<float> latents)
206+
protected virtual async Task<DenseTensor<float>> DecodeLatentsAsync(IModelOptions model, PromptOptions prompt, SchedulerOptions options, DenseTensor<float> latents)
207207
{
208208
var timestamp = _logger?.LogBegin("Begin...");
209209

OnnxStack.StableDiffusion/Diffusers/LatentConsistency/ImageDiffuser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected override IReadOnlyList<int> GetTimesteps(SchedulerOptions options, ISc
5656
/// <param name="options">The options.</param>
5757
/// <param name="scheduler">The scheduler.</param>
5858
/// <returns></returns>
59-
protected override async Task<DenseTensor<float>> PrepareLatents(IModelOptions model, PromptOptions prompt, SchedulerOptions options, IScheduler scheduler, IReadOnlyList<int> timesteps)
59+
protected override async Task<DenseTensor<float>> PrepareLatentsAsync(IModelOptions model, PromptOptions prompt, SchedulerOptions options, IScheduler scheduler, IReadOnlyList<int> timesteps)
6060
{
6161
var imageTensor = prompt.InputImage.ToDenseTensor(new[] { 1, 3, options.Height, options.Width });
6262
var inputNames = _onnxModelService.GetInputNames(model, OnnxModelType.VaeEncoder);

OnnxStack.StableDiffusion/Diffusers/LatentConsistency/LatentConsistencyDiffuser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected override bool ShouldPerformGuidance(SchedulerOptions schedulerOptions)
8686
/// <param name="progressCallback">The progress callback.</param>
8787
/// <param name="cancellationToken">The cancellation token.</param>
8888
/// <returns></returns>
89-
protected override async Task<DenseTensor<float>> SchedulerStep(IModelOptions modelOptions, PromptOptions promptOptions, SchedulerOptions schedulerOptions, DenseTensor<float> promptEmbeddings, bool performGuidance, Action<int, int> progressCallback = null, CancellationToken cancellationToken = default)
89+
protected override async Task<DenseTensor<float>> SchedulerStepAsync(IModelOptions modelOptions, PromptOptions promptOptions, SchedulerOptions schedulerOptions, DenseTensor<float> promptEmbeddings, bool performGuidance, Action<int, int> progressCallback = null, CancellationToken cancellationToken = default)
9090
{
9191
// Get Scheduler
9292
using (var scheduler = GetScheduler(schedulerOptions))
@@ -95,7 +95,7 @@ protected override async Task<DenseTensor<float>> SchedulerStep(IModelOptions mo
9595
var timesteps = GetTimesteps(schedulerOptions, scheduler);
9696

9797
// Create latent sample
98-
var latents = await PrepareLatents(modelOptions, promptOptions, schedulerOptions, scheduler, timesteps);
98+
var latents = await PrepareLatentsAsync(modelOptions, promptOptions, schedulerOptions, scheduler, timesteps);
9999

100100
// Get Guidance Scale Embedding
101101
var guidanceEmbeddings = GetGuidanceScaleEmbedding(schedulerOptions.GuidanceScale);
@@ -154,7 +154,7 @@ protected override async Task<DenseTensor<float>> SchedulerStep(IModelOptions mo
154154
}
155155

156156
// Decode Latents
157-
return await DecodeLatents(modelOptions, promptOptions, schedulerOptions, denoised);
157+
return await DecodeLatentsAsync(modelOptions, promptOptions, schedulerOptions, denoised);
158158
}
159159
}
160160

0 commit comments

Comments
 (0)