diff --git a/OnnxStack.Core/LogExtensions.cs b/OnnxStack.Core/LogExtensions.cs index a2375df8..b74d39f8 100644 --- a/OnnxStack.Core/LogExtensions.cs +++ b/OnnxStack.Core/LogExtensions.cs @@ -19,13 +19,13 @@ public static void Log(this ILogger logger, LogLevel logLevel, string message, [ } - public static long LogBegin(this ILogger logger, string message, [CallerMemberName] string caller = default) + public static long LogBegin(this ILogger logger, string message = default, [CallerMemberName] string caller = default) { return LogBeginInternal(logger, LogLevel.Information, message, caller); } - public static long LogBegin(this ILogger logger, LogLevel logLevel, string message, [CallerMemberName] string caller = default) + public static long LogBegin(this ILogger logger, LogLevel logLevel, string message = default, [CallerMemberName] string caller = default) { return LogBeginInternal(logger, logLevel, message, caller); @@ -46,7 +46,9 @@ public static void LogEnd(this ILogger logger, LogLevel logLevel, string message private static long LogBeginInternal(ILogger logger, LogLevel logLevel, string message, string caller) { - LogInternal(logger, logLevel, message, caller); + if (!string.IsNullOrEmpty(message)) + LogInternal(logger, logLevel, message, caller); + return Stopwatch.GetTimestamp(); } diff --git a/OnnxStack.StableDiffusion/Diffusers/DiffuserBase.cs b/OnnxStack.StableDiffusion/Diffusers/DiffuserBase.cs index 2565aad7..512d933a 100644 --- a/OnnxStack.StableDiffusion/Diffusers/DiffuserBase.cs +++ b/OnnxStack.StableDiffusion/Diffusers/DiffuserBase.cs @@ -103,7 +103,7 @@ public virtual async Task> DiffuseAsync(IModelOptions modelOp // Create random seed if none was set schedulerOptions.Seed = schedulerOptions.Seed > 0 ? schedulerOptions.Seed : Random.Shared.Next(); - var diffuseTime = _logger?.LogBegin("Begin..."); + var diffuseTime = _logger?.LogBegin("Diffuse starting..."); _logger?.Log($"Model: {modelOptions.Name}, Pipeline: {modelOptions.PipelineType}, Diffuser: {promptOptions.DiffuserType}, Scheduler: {schedulerOptions.SchedulerType}"); // Check guidance @@ -115,7 +115,7 @@ public virtual async Task> DiffuseAsync(IModelOptions modelOp // Run Scheduler steps var schedulerResult = await SchedulerStepAsync(modelOptions, promptOptions, schedulerOptions, promptEmbeddings, performGuidance, progressCallback, cancellationToken); - _logger?.LogEnd($"End", diffuseTime); + _logger?.LogEnd($"Diffuse complete", diffuseTime); return schedulerResult; } @@ -137,8 +137,9 @@ public virtual async IAsyncEnumerable DiffuseBatchAsync(IModelOptio // Create random seed if none was set schedulerOptions.Seed = schedulerOptions.Seed > 0 ? schedulerOptions.Seed : Random.Shared.Next(); - var diffuseBatchTime = _logger?.LogBegin("Begin..."); + var diffuseBatchTime = _logger?.LogBegin("Batch Diffuser starting..."); _logger?.Log($"Model: {modelOptions.Name}, Pipeline: {modelOptions.PipelineType}, Diffuser: {promptOptions.DiffuserType}, Scheduler: {schedulerOptions.SchedulerType}"); + _logger?.Log($"BatchType: {batchOptions.BatchType}, ValueFrom: {batchOptions.ValueFrom}, ValueTo: {batchOptions.ValueTo}, Increment: {batchOptions.Increment}"); // Check guidance var performGuidance = ShouldPerformGuidance(schedulerOptions); @@ -153,11 +154,13 @@ public virtual async IAsyncEnumerable DiffuseBatchAsync(IModelOptio var schedulerCallback = (int step, int steps) => progressCallback?.Invoke(batchIndex, batchSchedulerOptions.Count, step, steps); foreach (var batchSchedulerOption in batchSchedulerOptions) { + var diffuseTime = _logger?.LogBegin("Diffuse starting..."); yield return new BatchResult(batchSchedulerOption, await SchedulerStepAsync(modelOptions, promptOptions, batchSchedulerOption, promptEmbeddings, performGuidance, schedulerCallback, cancellationToken)); + _logger?.LogEnd($"Diffuse complete", diffuseTime); batchIndex++; } - _logger?.LogEnd($"End", diffuseBatchTime); + _logger?.LogEnd($"Diffuse batch complete", diffuseBatchTime); } @@ -205,7 +208,7 @@ protected virtual DenseTensor PerformGuidance(DenseTensor noisePre /// protected virtual async Task> DecodeLatentsAsync(IModelOptions model, PromptOptions prompt, SchedulerOptions options, DenseTensor latents) { - var timestamp = _logger?.LogBegin("Begin..."); + var timestamp = _logger.LogBegin(); // Scale and decode the image latents with vae. latents = latents.MultiplyBy(1.0f / model.ScaleFactor); @@ -224,7 +227,7 @@ protected virtual async Task> DecodeLatentsAsync(IModelOption var results = await _onnxModelService.RunInferenceAsync(model, OnnxModelType.VaeDecoder, inputs, outputs); using (var imageResult = results.First()) { - _logger?.LogEnd("End", timestamp); + _logger?.LogEnd("Latents decoded", timestamp); return imageResult.ToDenseTensor(); } } diff --git a/OnnxStack.StableDiffusion/Diffusers/LatentConsistency/LatentConsistencyDiffuser.cs b/OnnxStack.StableDiffusion/Diffusers/LatentConsistency/LatentConsistencyDiffuser.cs index 99c83f45..533e9302 100644 --- a/OnnxStack.StableDiffusion/Diffusers/LatentConsistency/LatentConsistencyDiffuser.cs +++ b/OnnxStack.StableDiffusion/Diffusers/LatentConsistency/LatentConsistencyDiffuser.cs @@ -153,7 +153,7 @@ protected override async Task> SchedulerStepAsync(IModelOptio } progressCallback?.Invoke(step, timesteps.Count); - _logger?.LogEnd(LogLevel.Debug, $"Step {step}/{timesteps.Count}", stepTime); + _logger?.LogEnd($"Step {step}/{timesteps.Count}", stepTime); } // Decode Latents diff --git a/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintDiffuser.cs b/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintDiffuser.cs index d67aa4a0..40388dc6 100644 --- a/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintDiffuser.cs +++ b/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintDiffuser.cs @@ -119,7 +119,7 @@ protected override async Task> SchedulerStepAsync(IModelOptio } progressCallback?.Invoke(step, timesteps.Count); - _logger?.LogEnd(LogLevel.Debug, $"Step {step}/{timesteps.Count}", stepTime); + _logger?.LogEnd($"Step {step}/{timesteps.Count}", stepTime); } // Decode Latents diff --git a/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintLegacyDiffuser.cs b/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintLegacyDiffuser.cs index 60aad028..eead7305 100644 --- a/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintLegacyDiffuser.cs +++ b/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/InpaintLegacyDiffuser.cs @@ -125,7 +125,7 @@ protected override async Task> SchedulerStepAsync(IModelOptio } progressCallback?.Invoke(step, timesteps.Count); - _logger?.LogEnd(LogLevel.Debug, $"Step {step}/{timesteps.Count}", stepTime); + _logger?.LogEnd($"Step {step}/{timesteps.Count}", stepTime); } // Decode Latents diff --git a/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/StableDiffusionDiffuser.cs b/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/StableDiffusionDiffuser.cs index 114369e9..06ec187c 100644 --- a/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/StableDiffusionDiffuser.cs +++ b/OnnxStack.StableDiffusion/Diffusers/StableDiffusion/StableDiffusionDiffuser.cs @@ -107,7 +107,7 @@ protected override async Task> SchedulerStepAsync(IModelOptio } progressCallback?.Invoke(step, timesteps.Count); - _logger?.LogEnd(LogLevel.Debug, $"Step {step}/{timesteps.Count}", stepTime); + _logger?.LogEnd($"Step {step}/{timesteps.Count}", stepTime); } // Decode Latents