Skip to content

Commit

Permalink
Merge pull request #720 from LykosAI/main
Browse files Browse the repository at this point in the history
v2.11.3
  • Loading branch information
mohnjiles authored Jun 25, 2024
2 parents b50e644 + 4286d39 commit debd131
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .backportrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"sourceBranch": "dev",
"targetBranch": "main",
"mainline": 1,
"fork": false,
"targetPRLabels": ["backport"],
"prTitle": "[{{sourceBranch}} to {{targetBranch}}] backport: {{sourcePullRequest.title}} ({{sourcePullRequest.number}})"
}
9 changes: 8 additions & 1 deletion .github/workflows/backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ jobs:
name: Backport PR
runs-on: ubuntu-latest
steps:
# Get the merge target branch to decide mainline number
# git cherry-pick mainline is 1 for merge to 'dev', else 2
- name: Get target branch
run: echo "CP_MAINLINE=$(if [ '${{ github.event.pull_request.base.ref }}' == 'dev' ]; then echo 1; else echo 2; fi)" >> $GITHUB_ENV

- name: Write json
id: create-json
uses: jsdaniell/[email protected]
with:
name: ".backportrc.json"
json: |
{
"targetPRLabels": "backport",
"targetPRLabels": ["backport"],
"mainline": ${{ env.CP_MAINLINE }},
"commitConflicts": "true",
"prTitle": "[{{sourceBranch}} to {{targetBranch}}] backport: {{sourcePullRequest.title}} ({{sourcePullRequest.number}})"
}
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to Stability Matrix will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).


## v2.11.3
### Changed
- Base Python install will now use `pip>=23.3.2,<24.1` for compatibility with `torchsde`.Individual Packages can upgrade as required.
- Added default `PIP_DISABLE_PIP_VERSION_CHECK=1` environment variable to suppress notices about pip version checks.
- As with other default environment variables, this can be overridden by setting your own value in `Settings > Environment Variables [Edit]`.
### Fixed
- Fooocus Package - Added `pip>=23.3.2,<24.1` specifier before install, fixes potential install errors due to deprecated requirement spec used by `torchsde`.
- Fixed error when launching SwarmUI when installed to a path with spaces
- Fixed issue where model folders were being created too late in certain cases
- Fixed [#683](https://github.com/LykosAI/StabilityMatrix/issues/683) - Model indexing causing LiteDB errors after upgrading from older versions due to updated enum values
### Supporters
#### Visionaries
- Huge thanks to our Visionary-tier supporters on Patreon, **Scopp Mcdee** and **Waterclouds**! Your support helps us continue to improve Stability Matrix!
#### Pioneers
- Thank you to our Pioneer-tier supporters on Patreon, **tankfox** and **tanangular**! Your support is greatly appreciated!

## v2.11.2
### Changed
- StableSwarmUI installs will be migrated to SwarmUI by mcmonkeyprojects the next time the package is updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,6 @@ or nameof(SortConnectedModelsFirst)
true
);

try
{
SharedFolders.SetupSharedModelFolders(settingsManager.ModelsDirectory);
}
catch (Exception e)
{
logger.LogError(e, @"Failed to setup shared model folders");
}

Refresh().SafeFireAndForget();

EventManager.Instance.ModelIndexChanged += (_, _) =>
Expand Down
7 changes: 7 additions & 0 deletions StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Threading;
Expand Down Expand Up @@ -115,6 +116,12 @@ protected override async Task OnInitialLoadedAsync()
return;
}

Task.Run(() => SharedFolders.SetupSharedModelFolders(settingsManager.ModelsDirectory))
.SafeFireAndForget(ex =>
{
Logger.Error(ex, "Error setting up shared model folders");
});

try
{
await modelDownloadLinkHandler.Value.StartListening();
Expand Down
5 changes: 5 additions & 0 deletions StabilityMatrix.Core/Database/ILiteDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public interface ILiteDbContext : IDisposable
Task<bool> UpsertCivitModelQueryCacheEntryAsync(CivitModelQueryCacheEntry entry);
Task<GithubCacheEntry?> GetGithubCacheEntry(string cacheKey);
Task<bool> UpsertGithubCacheEntry(GithubCacheEntry cacheEntry);

/// <summary>
/// Clear all Collections that store re-fetchable cache type data.
/// </summary>
Task ClearAllCacheCollectionsAsync();
}
24 changes: 24 additions & 0 deletions StabilityMatrix.Core/Database/LiteDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@ public async Task<bool> UpsertCivitModelQueryCacheEntryAsync(CivitModelQueryCach
public Task<bool> UpsertGithubCacheEntry(GithubCacheEntry cacheEntry) =>
GithubCache.UpsertAsync(cacheEntry);

/// <summary>
/// Clear all Collections that store re-fetchable cache type data.
/// </summary>
public async Task ClearAllCacheCollectionsAsync()
{
var collectionNames = new List<string>
{
nameof(CivitModels),
nameof(CivitModelVersions),
nameof(CivitModelQueryCache),
nameof(GithubCache),
nameof(LocalModelFiles),
nameof(LocalImageFiles)
};

logger.LogInformation("Clearing all cache collections: [{@Names}]", collectionNames);

foreach (var name in collectionNames)
{
var collection = Database.GetCollection(name);
await collection.DeleteAllAsync().ConfigureAwait(false);
}
}

public void Dispose()
{
if (lazyDatabase.IsValueCreated)
Expand Down
3 changes: 3 additions & 0 deletions StabilityMatrix.Core/Models/Packages/Fooocus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ public override async Task InstallPackage(

progress?.Report(new ProgressReport(-1f, "Installing requirements...", isIndeterminate: true));

// Pip version 24.1 deprecated numpy requirement spec used by torchsde 0.2.5
await venvRunner.PipInstall(["pip>=23.3.2,<24.1"], onConsoleOutput).ConfigureAwait(false);

var pipArgs = new PipInstallArgs();

if (torchVersion == TorchVersion.DirectMl)
Expand Down
2 changes: 1 addition & 1 deletion StabilityMatrix.Core/Models/Packages/StableSwarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void HandleConsoleOutput(ProcessOutput s)

dotnetProcess = await prerequisiteHelper
.RunDotnet(
args: $"{Path.Combine(releaseFolder, dllName)} {arguments.TrimEnd()}",
args: [Path.Combine(releaseFolder, dllName), arguments.TrimEnd()],
workingDirectory: installedPackagePath,
envVars: aspEnvVars,
onProcessOutput: HandleConsoleOutput,
Expand Down
8 changes: 7 additions & 1 deletion StabilityMatrix.Core/Models/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ public InstalledPackage? PreferredWorkflowPackage

[JsonIgnore]
public Dictionary<string, string> DefaultEnvironmentVariables { get; } =
new() { ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib" };
new()
{
// Fixes potential setuptools error on Portable Windows Python
["SETUPTOOLS_USE_DISTUTILS"] = "stdlib",
// Suppresses 'A new release of pip is available' messages
["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"
};

[JsonPropertyName("EnvironmentVariables")]
public Dictionary<string, string>? UserEnvironmentVariables { get; set; }
Expand Down
13 changes: 10 additions & 3 deletions StabilityMatrix.Core/Python/PyRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,17 @@ public async Task SetupPip()
throw new FileNotFoundException("get-pip not found", GetPipPath);
}

var result = await ProcessRunner
.GetProcessResultAsync(PythonExePath, "-m get-pip")
await ProcessRunner
.GetProcessResultAsync(PythonExePath, ["-m", "get-pip"])
.EnsureSuccessExitCode()
.ConfigureAwait(false);

// Pip version 24.1 deprecated numpy star requirement spec used by some packages
// So make the base pip less than that for compatibility, venvs can upgrade themselves if needed
await ProcessRunner
.GetProcessResultAsync(PythonExePath, ["-m", "pip", "install", "pip>=23.3.2,<24.1"])
.EnsureSuccessExitCode()
.ConfigureAwait(false);
result.EnsureSuccessExitCode();
}

/// <summary>
Expand Down
67 changes: 58 additions & 9 deletions StabilityMatrix.Core/Services/ModelIndexService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Text;
using System.Text.Json;
using AsyncAwaitBestPractices;
using AutoCtor;
using KGySoft.CoreLibraries;
using LiteDB;
using LiteDB.Async;
using Microsoft.Extensions.Logging;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Database;
Expand All @@ -15,6 +16,7 @@
using StabilityMatrix.Core.Models.Api;
using StabilityMatrix.Core.Models.Database;
using StabilityMatrix.Core.Models.FileInterfaces;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace StabilityMatrix.Core.Services;

Expand Down Expand Up @@ -103,9 +105,34 @@ private async Task LoadFromDbAsync()

logger.LogInformation("Loading models from database...");

var allModels = (
await liteDbContext.LocalModelFiles.IncludeAll().FindAllAsync().ConfigureAwait(false)
).ToImmutableArray();
ImmutableArray<LocalModelFile> allModels = [];
try
{
allModels =
[
..(
await liteDbContext.LocalModelFiles.IncludeAll().FindAllAsync().ConfigureAwait(false)
)
];
}
catch (Exception e)
{
// Handle enum deserialize exceptions from changes
if (e is LiteException or LiteAsyncException && e.InnerException is ArgumentException inner)
{
logger.LogWarning(
e,
"LiteDb Deserialize error while fetching LocalModelFiles '{Inner}', cache collections will be cleared",
inner.ToString()
);

await liteDbContext.ClearAllCacheCollectionsAsync().ConfigureAwait(false);
}
else
{
throw;
}
}

ModelIndex = allModels.GroupBy(m => m.SharedFolderType).ToDictionary(g => g.Key, g => g.ToList());

Expand Down Expand Up @@ -479,12 +506,34 @@ private async Task RefreshIndexParallelCore()

if (model.LatestModelInfo == null && model.HasConnectedModel)
{
var civitModel = await liteDbContext
.CivitModels.Include(m => m.ModelVersions)
.FindByIdAsync(model.ConnectedModelInfo.ModelId)
.ConfigureAwait(false);
try
{
model.LatestModelInfo = await liteDbContext
.CivitModels.Include(m => m.ModelVersions)
.FindByIdAsync(model.ConnectedModelInfo.ModelId)
.ConfigureAwait(false);
}
catch (Exception e)
{
// Handle enum deserialize exceptions from changes
if (
e is LiteException or LiteAsyncException
&& e.InnerException is ArgumentException inner
)
{
logger.LogWarning(
e,
"LiteDb Deserialize error while fetching CivitModels '{Inner}', cache collections will be cleared",
inner.ToString()
);

model.LatestModelInfo = civitModel;
await liteDbContext.ClearAllCacheCollectionsAsync().ConfigureAwait(false);
}
else
{
throw;
}
}
}
var list = newIndex.GetOrAdd(model.SharedFolderType);
list.Add(model);
Expand Down

0 comments on commit debd131

Please sign in to comment.