From 28716c10ef4b25d45062e5664cbcd0bf72c2fc6a Mon Sep 17 00:00:00 2001 From: JT Date: Sun, 19 Nov 2023 23:34:04 -0800 Subject: [PATCH 1/3] Delete failed installations if a new install is attempted in the same directory --- .../ViewModels/Dialogs/InstallerViewModel.cs | 13 ++++-- .../Dialogs/OneClickInstallViewModel.cs | 7 +++ .../Models/Packages/BaseGitPackage.cs | 44 ++++++------------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs index 55b40f305..df056b4d8 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs @@ -16,6 +16,7 @@ using FluentAvalonia.UI.Controls; using NLog; using StabilityMatrix.Avalonia.Controls; +using StabilityMatrix.Avalonia.Extensions; using StabilityMatrix.Avalonia.Languages; using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.ViewModels.Base; @@ -24,6 +25,7 @@ using StabilityMatrix.Core.Helper.Factory; using StabilityMatrix.Core.Models; using StabilityMatrix.Core.Models.Database; +using StabilityMatrix.Core.Models.FileInterfaces; using StabilityMatrix.Core.Models.PackageModification; using StabilityMatrix.Core.Models.Packages; using StabilityMatrix.Core.Processes; @@ -221,7 +223,7 @@ private async Task Install() } } - private Task ActuallyInstall() + private async Task ActuallyInstall() { if (string.IsNullOrWhiteSpace(InstallName)) { @@ -232,12 +234,18 @@ private Task ActuallyInstall() NotificationType.Error ) ); - return Task.CompletedTask; + return; } var setPackageInstallingStep = new SetPackageInstallingStep(settingsManager, InstallName); var installLocation = Path.Combine(settingsManager.LibraryDir, "Packages", InstallName); + if (Directory.Exists(installLocation)) + { + var installPath = new DirectoryPath(installLocation); + await installPath.DeleteVerboseAsync(); + } + var prereqStep = new SetupPrerequisitesStep(prerequisiteHelper, pyRunner); var downloadOptions = new DownloadPackageVersionOptions(); @@ -313,7 +321,6 @@ private Task ActuallyInstall() }; Steps = steps; - return Task.CompletedTask; } public void Cancel() diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs index 4c341aeb0..8d1c033c5 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs @@ -7,6 +7,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.Logging; +using StabilityMatrix.Avalonia.Extensions; using StabilityMatrix.Avalonia.Languages; using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.ViewModels.Base; @@ -14,6 +15,7 @@ using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Helper.Factory; using StabilityMatrix.Core.Models; +using StabilityMatrix.Core.Models.FileInterfaces; using StabilityMatrix.Core.Models.PackageModification; using StabilityMatrix.Core.Models.Packages; using StabilityMatrix.Core.Python; @@ -139,6 +141,11 @@ private async Task DoInstall() "Packages", SelectedPackage.Name ); + if (Directory.Exists(installLocation)) + { + var installPath = new DirectoryPath(installLocation); + await installPath.DeleteVerboseAsync(); + } var downloadVersion = await SelectedPackage.GetLatestVersion(); var installedVersion = new InstalledPackageVersion { IsPrerelease = false }; diff --git a/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs b/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs index 2d4be8129..e2686bb25 100644 --- a/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs +++ b/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs @@ -181,36 +181,20 @@ public override async Task DownloadPackage( IProgress? progress = null ) { - if (!string.IsNullOrWhiteSpace(versionOptions.VersionTag)) - { - await PrerequisiteHelper - .RunGit( - new[] - { - "clone", - "--branch", - versionOptions.VersionTag, - GithubUrl, - installLocation - } - ) - .ConfigureAwait(false); - } - else if (!string.IsNullOrWhiteSpace(versionOptions.BranchName)) - { - await PrerequisiteHelper - .RunGit( - new[] - { - "clone", - "--branch", - versionOptions.BranchName, - GithubUrl, - installLocation - } - ) - .ConfigureAwait(false); - } + await PrerequisiteHelper + .RunGit( + new[] + { + "clone", + "--branch", + !string.IsNullOrWhiteSpace(versionOptions.VersionTag) + ? versionOptions.VersionTag + : versionOptions.BranchName ?? MainBranch, + GithubUrl, + installLocation + } + ) + .ConfigureAwait(false); if (!versionOptions.IsLatest && !string.IsNullOrWhiteSpace(versionOptions.CommitHash)) { From dd0b17bf889ccfd89b6a8c982a74429e14c0c30a Mon Sep 17 00:00:00 2001 From: JT Date: Mon, 20 Nov 2023 15:21:24 -0800 Subject: [PATCH 2/3] fix bad crc on inference outputs --- CHANGELOG.md | 1 + StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57647ef25..eb02670ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2 - Better error reporting including outputs for git subprocess errors during package install / update - Fixed `'accelerate' is not recognized as an internal or external command` error when starting training in kohya_ss - Fixed some instances of `ModuleNotFoundError: No module named 'bitsandbytes.cuda_setup.paths'` error when using 8-bit optimizers in kohya_ss +- Fixed errors preventing Inference outputs from loading in the img2img tabs of other packages ## v2.6.1 ### Changed diff --git a/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs b/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs index 1d729cfed..f7d7e7c23 100644 --- a/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs +++ b/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs @@ -104,7 +104,7 @@ private static byte[] BuildTextChunk(string key, string value) var dataBytes = Encoding.UTF8.GetBytes(textData); var textDataLength = BitConverter.GetBytes(dataBytes.Length).Reverse(); var textDataBytes = Text.Concat(dataBytes).ToArray(); - var crc = BitConverter.GetBytes(Crc32Algorithm.Compute(textDataBytes)); + var crc = BitConverter.GetBytes(Crc32Algorithm.Compute(textDataBytes)).Reverse(); return textDataLength.Concat(textDataBytes).Concat(crc).ToArray(); } From 9df0687fa34b74f9d21e4e0839affbc317a11463 Mon Sep 17 00:00:00 2001 From: JT Date: Mon, 20 Nov 2023 15:27:05 -0800 Subject: [PATCH 3/3] pass logger to deleteVerbose --- .../ViewModels/Dialogs/InstallerViewModel.cs | 21 ++++++++++--------- .../Dialogs/OneClickInstallViewModel.cs | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs index df056b4d8..c98d41bf7 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs @@ -14,7 +14,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using FluentAvalonia.UI.Controls; -using NLog; +using Microsoft.Extensions.Logging; using StabilityMatrix.Avalonia.Controls; using StabilityMatrix.Avalonia.Extensions; using StabilityMatrix.Avalonia.Languages; @@ -38,14 +38,13 @@ namespace StabilityMatrix.Avalonia.ViewModels.Dialogs; [Transient] public partial class InstallerViewModel : ContentDialogViewModelBase { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly ISettingsManager settingsManager; private readonly IPackageFactory packageFactory; private readonly IPyRunner pyRunner; private readonly IDownloadService downloadService; private readonly INotificationService notificationService; private readonly IPrerequisiteHelper prerequisiteHelper; + private readonly ILogger logger; [ObservableProperty] private BasePackage selectedPackage; @@ -132,7 +131,8 @@ public InstallerViewModel( IPyRunner pyRunner, IDownloadService downloadService, INotificationService notificationService, - IPrerequisiteHelper prerequisiteHelper + IPrerequisiteHelper prerequisiteHelper, + ILogger logger ) { this.settingsManager = settingsManager; @@ -141,6 +141,7 @@ IPrerequisiteHelper prerequisiteHelper this.downloadService = downloadService; this.notificationService = notificationService; this.prerequisiteHelper = prerequisiteHelper; + this.logger = logger; var filtered = packageFactory.GetAllAvailablePackages().Where(p => p.IsCompatible).ToList(); @@ -189,7 +190,7 @@ public override async Task OnLoadedAsync() } catch (Exception e) { - Logger.Warn("Error getting versions: {Exception}", e.ToString()); + logger.LogWarning("Error getting versions: {Exception}", e.ToString()); } finally { @@ -211,7 +212,7 @@ private async Task Install() else { var ex = result.Exception!; - Logger.Error(ex, $"Error installing package: {ex}"); + logger.LogError(ex, $"Error installing package: {ex}"); var dialog = new BetterContentDialog { @@ -243,7 +244,7 @@ private async Task ActuallyInstall() if (Directory.Exists(installLocation)) { var installPath = new DirectoryPath(installLocation); - await installPath.DeleteVerboseAsync(); + await installPath.DeleteVerboseAsync(logger); } var prereqStep = new SetupPrerequisitesStep(prerequisiteHelper, pyRunner); @@ -408,7 +409,7 @@ partial void OnSelectedVersionTypeChanged(PackageVersionType value) Dispatcher.UIThread .InvokeAsync(async () => { - Logger.Debug($"Release mode: {IsReleaseMode}"); + logger.LogDebug($"Release mode: {IsReleaseMode}"); var versionOptions = await SelectedPackage.GetAllVersionOptions(); AvailableVersions = IsReleaseMode @@ -420,7 +421,7 @@ partial void OnSelectedVersionTypeChanged(PackageVersionType value) return; ReleaseNotes = SelectedVersion.ReleaseNotesMarkdown; - Logger.Debug($"Loaded release notes for {ReleaseNotes}"); + logger.LogDebug($"Loaded release notes for {ReleaseNotes}"); if (!IsReleaseMode) { @@ -499,7 +500,7 @@ partial void OnSelectedVersionChanged(PackageVersion? value) } catch (Exception e) { - Logger.Warn($"Error getting commits: {e.Message}"); + logger.LogWarning(e, $"Error getting commits: {e.Message}"); } }) .SafeFireAndForget(); diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs index 8d1c033c5..8da42dd48 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs @@ -144,7 +144,7 @@ private async Task DoInstall() if (Directory.Exists(installLocation)) { var installPath = new DirectoryPath(installLocation); - await installPath.DeleteVerboseAsync(); + await installPath.DeleteVerboseAsync(logger); } var downloadVersion = await SelectedPackage.GetLatestVersion();