diff --git a/CHANGELOG.md b/CHANGELOG.md index 714514b9..dd84bc14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,12 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2 ## v2.11.4 ### Changed - Base Python install will now use `setuptools==69.5.1` for compatibility with `torchsde`. Individual Packages can upgrade as required. +- Improved formatting of "Copy Details" action on the Unexpected Error dialog +- (Debug) Logging verbosity for classes can now be configured with environment variables (`Logging__LogLevel__`). ### Fixed +- Fixed ComfyUI slower generation speed with new torch versions not including flash attention for windows, pinned `torch==2.1.2` for ComfyUI on Windows CUDA - Fixed [#719](https://github.com/LykosAI/StabilityMatrix/issues/719) - Fix comments in Inference prompt not being ignored +- Fixed TaskCanceledException when Inference prompts finish before the delayed progress handler (250ms) ### Supporters #### Visionaries - Huge thanks to our Visionary-tier supporters on Patreon, **Scopp Mcdee** and **Waterclouds**! Your support helps us continue to improve Stability Matrix! diff --git a/StabilityMatrix.Avalonia/App.axaml.cs b/StabilityMatrix.Avalonia/App.axaml.cs index 54e65754..892535b8 100644 --- a/StabilityMatrix.Avalonia/App.axaml.cs +++ b/StabilityMatrix.Avalonia/App.axaml.cs @@ -504,6 +504,7 @@ internal static IServiceCollection ConfigureServices() Config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddEnvironmentVariables() .Build(); services.Configure(Config.GetSection(nameof(DebugOptions))); @@ -927,15 +928,22 @@ private static LoggingConfiguration ConfigureLogging() builder.ForLogger("Microsoft.*").WriteToNil(NLog.LogLevel.Warn); builder.ForLogger("Microsoft.Extensions.Http.*").WriteToNil(NLog.LogLevel.Warn); - // Disable console trace logging by default - builder - .ForLogger("StabilityMatrix.Avalonia.ViewModels.ConsoleViewModel") - .WriteToNil(NLog.LogLevel.Debug); + // Disable some trace logging by default, unless overriden by app settings + var typesToDisableTrace = new[] { typeof(ConsoleViewModel), typeof(LoadableViewModelBase) }; - // Disable LoadableViewModelBase trace logging by default - builder - .ForLogger("StabilityMatrix.Avalonia.ViewModels.Base.LoadableViewModelBase") - .WriteToNil(NLog.LogLevel.Debug); + foreach (var type in typesToDisableTrace) + { + // Skip if app settings already set a level for this type + if ( + Config[$"Logging:LogLevel:{type.FullName}"] is { } levelStr + && Enum.TryParse(levelStr, true, out _) + ) + { + continue; + } + + builder.ForLogger(type.FullName).FilterMinLevel(NLog.LogLevel.Debug); + } // Debug console logging /*if (Debugger.IsAttached) diff --git a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs index 17504e20..774e97a7 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs @@ -355,7 +355,13 @@ protected async Task RunGeneration(ImageGenerationEventArgs args, CancellationTo }, cancellationToken ) - .SafeFireAndForget(); + .SafeFireAndForget(ex => + { + if (ex is TaskCanceledException) + return; + + Logger.Error(ex, "Error while attaching running node change handler"); + }); // Wait for prompt to finish try diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/ExceptionViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/ExceptionViewModel.cs index 9531c864..f3accea4 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/ExceptionViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/ExceptionViewModel.cs @@ -1,4 +1,6 @@ using System; +using System.ComponentModel; +using System.Text; using Sentry; using StabilityMatrix.Avalonia.ViewModels.Base; using StabilityMatrix.Avalonia.Views.Dialogs; @@ -9,7 +11,7 @@ namespace StabilityMatrix.Avalonia.ViewModels.Dialogs; [View(typeof(ExceptionDialog))] [ManagedService] [Transient] -public partial class ExceptionViewModel : ViewModelBase +public class ExceptionViewModel : ViewModelBase { public Exception? Exception { get; set; } @@ -19,35 +21,53 @@ public partial class ExceptionViewModel : ViewModelBase public string? ExceptionType => Exception?.GetType().Name ?? ""; + [Localizable(false)] public string? FormatAsMarkdown() { - if (Exception is null) - { - return null; - } + var msgBuilder = new StringBuilder(); + msgBuilder.AppendLine(); - var message = $"## Exception\n{ExceptionType}: {Message}\n"; + if (Exception is not null) + { + msgBuilder.AppendLine("## Exception"); + msgBuilder.AppendLine($"```{ExceptionType}: {Message}```"); - if (SentryId is not null) + if (Exception.InnerException is not null) + { + msgBuilder.AppendLine( + $"```{Exception.InnerException.GetType().Name}: {Exception.InnerException.Message}```" + ); + } + } + else { - message += $"### Sentry ID\n```\n{SentryId}\n```\n"; + msgBuilder.AppendLine("## Exception"); + msgBuilder.AppendLine("```(None)```"); } - if (Exception.StackTrace != null) + if (SentryId is { } id) { - message += $"### Stack Trace\n```\n{Exception.StackTrace}\n```\n"; + msgBuilder.AppendLine("### Sentry ID"); + msgBuilder.AppendLine($"[`{id.ToString()[..8]}`]({GetIssueUrl(id)})"); } - if (Exception.InnerException is { } innerException) + if (Exception?.StackTrace is not null) { - message += $"## Inner Exception\n{innerException.GetType().Name}: {innerException.Message}\n"; + msgBuilder.AppendLine("### Stack Trace"); + msgBuilder.AppendLine($"```{Exception.StackTrace}```"); + } - if (innerException.StackTrace != null) - { - message += $"### Stack Trace\n```\n{innerException.StackTrace}\n```\n"; - } + if (Exception?.InnerException is { StackTrace: not null } innerException) + { + msgBuilder.AppendLine($"```{innerException.StackTrace}```"); } - return message; + return msgBuilder.ToString(); + } + + [Localizable(false)] + private static string GetIssueUrl(SentryId sentryId) + { + return $"https://stability-matrix.sentry.io/issues/?query=id%3A{sentryId.ToString()}&referrer=sm-app-ex&statsPeriod=90d"; } } diff --git a/StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs index 88595c29..ed67b95d 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using AsyncAwaitBestPractices; using Avalonia.Controls; using Avalonia.Threading; using FluentAvalonia.UI.Controls; @@ -86,7 +84,7 @@ private void PackageModificationRunnerOnProgressChanged(object? sender, Progress public async Task ShowProgressDialog() { - Progress.CloseWhenFinished = true; + Progress.CloseWhenFinished = packageModificationRunner.CloseWhenFinished; dialog = new BetterContentDialog { MaxDialogWidth = 900, diff --git a/StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs b/StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs index 4a4a0e0b..d3ddeb9e 100644 --- a/StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs +++ b/StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs @@ -30,6 +30,8 @@ public interface IPackageModificationRunner bool HideCloseButton { get; init; } + bool CloseWhenFinished { get; init; } + string? ModificationCompleteTitle { get; init; } string ModificationCompleteMessage { get; init; } diff --git a/StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs b/StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs index e82aa1a8..b7186656 100644 --- a/StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs +++ b/StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs @@ -76,6 +76,8 @@ public async Task ExecuteSteps(IReadOnlyList steps) public bool HideCloseButton { get; init; } + public bool CloseWhenFinished { get; init; } = true; + public bool ShowDialogOnStart { get; init; } public string? ModificationCompleteTitle { get; init; } = "Install Complete"; diff --git a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs index 6bdb0aed..31917327 100644 --- a/StabilityMatrix.Core/Models/Packages/ComfyUI.cs +++ b/StabilityMatrix.Core/Models/Packages/ComfyUI.cs @@ -192,21 +192,23 @@ public override async Task InstallPackage( ) { progress?.Report(new ProgressReport(-1, "Setting up venv", isIndeterminate: true)); - // Setup venv await using var venvRunner = await SetupVenvPure(installLocation).ConfigureAwait(false); await venvRunner.PipInstall("--upgrade pip wheel", onConsoleOutput).ConfigureAwait(false); - progress?.Report( - new ProgressReport(-1f, "Installing Package Requirements...", isIndeterminate: true) - ); - var pipArgs = new PipInstallArgs(); pipArgs = torchVersion switch { TorchVersion.DirectMl => pipArgs.WithTorchDirectML(), TorchVersion.Mps => pipArgs.WithTorch().WithTorchVision().WithTorchExtraIndex("cpu"), + TorchVersion.Cuda when Compat.IsWindows + => pipArgs + .AddArg("--upgrade") + .WithTorch("==2.1.2") + .WithTorchVision("==0.16.2") + .WithTorchAudio("==2.1.2") + .WithTorchExtraIndex("cu121"), _ => pipArgs .AddArg("--upgrade") @@ -237,6 +239,9 @@ await requirements.ReadAllTextAsync().ConfigureAwait(false), excludePattern: "torch" ); + progress?.Report( + new ProgressReport(-1f, "Installing Package Requirements...", isIndeterminate: true) + ); await venvRunner.PipInstall(pipArgs, onConsoleOutput).ConfigureAwait(false); progress?.Report(new ProgressReport(1, "Installed Package Requirements", isIndeterminate: false)); diff --git a/StabilityMatrix.Core/Python/PipInstallArgs.cs b/StabilityMatrix.Core/Python/PipInstallArgs.cs index 558a7db8..6f2d2215 100644 --- a/StabilityMatrix.Core/Python/PipInstallArgs.cs +++ b/StabilityMatrix.Core/Python/PipInstallArgs.cs @@ -5,6 +5,7 @@ namespace StabilityMatrix.Core.Python; +[SuppressMessage("ReSharper", "StringLiteralTypo")] public record PipInstallArgs : ProcessArgsBuilder { public PipInstallArgs(params Argument[] arguments) @@ -16,6 +17,8 @@ public PipInstallArgs(params Argument[] arguments) public PipInstallArgs WithTorchVision(string version = "") => this.AddArg($"torchvision{version}"); + public PipInstallArgs WithTorchAudio(string version = "") => this.AddArg($"torchaudio{version}"); + public PipInstallArgs WithXFormers(string version = "") => this.AddArg($"xformers{version}"); public PipInstallArgs WithExtraIndex(string indexUrl) => this.AddArg(("--extra-index-url", indexUrl));