Skip to content

Commit dae982d

Browse files
authored
Merge pull request LykosAI#1103 from ionite34/fix-invoke-and-kohya
Fix invoke and kohya
2 parents 3beeb09 + 0869745 commit dae982d

File tree

5 files changed

+112
-43
lines changed

5 files changed

+112
-43
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
1313
- Inference is now able to load image metadata from Civitai generated images via drag & drop
1414
- Updated process tracking for ComfyUI to help mitigate restart issues when using Comfy Manager
1515
- Updated pre-selected download locations for certain model types in the Civitai model browser
16+
- Updated nodejs to v20.19.3 to support newer InvokeAI versions
1617
### Fixed
1718
- Fixed missing .NET 8 dependency for SwarmUI installs in certain cases
1819
- Fixed ComfyUI-Zluda not being recognized as a valid Comfy install for the workflow browser
1920
- Fixed [#1291](https://github.com/LykosAI/StabilityMatrix/issues/1291) - Certain GPUs not being detected on Linux
2021
- Fixed [#1284](https://github.com/LykosAI/StabilityMatrix/issues/1284) - Output browser not ignoring InvokeAI thumbnails folders
22+
- Fixed [#1301](https://github.com/LykosAI/StabilityMatrix/issues/1301) - Error when installing kohya_ss
2123
- Fixed [#1305](https://github.com/LykosAI/StabilityMatrix/issues/1305) - FluxGym installing incorrect packages for Blackwell GPUs
2224
- Fixed [#1316](https://github.com/LykosAI/StabilityMatrix/issues/1316) - Errors when installing Triton & SageAttention
2325

StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public async Task InstallAllIfNecessary(IProgress<ProgressReport>? progress = nu
148148
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null)
149149
{
150150
// Array of (asset_uri, extract_to)
151-
var assets = new[] { (Assets.SevenZipExecutable, AssetsDir), (Assets.SevenZipLicense, AssetsDir), };
151+
var assets = new[] { (Assets.SevenZipExecutable, AssetsDir), (Assets.SevenZipLicense, AssetsDir) };
152152

153153
progress?.Report(new ProgressReport(0, message: "Unpacking resources", isIndeterminate: true));
154154

@@ -176,10 +176,10 @@ public async Task InstallGitIfNecessary(IProgress<ProgressReport>? progress = nu
176176
{
177177
new TextBlock
178178
{
179-
Text = "The current operation requires Git. Please install it to continue."
179+
Text = "The current operation requires Git. Please install it to continue.",
180180
},
181181
new SelectableTextBlock { Text = "$ sudo apt install git" },
182-
}
182+
},
183183
},
184184
PrimaryButtonText = Resources.Action_Retry,
185185
CloseButtonText = Resources.Action_Close,
@@ -351,6 +351,22 @@ public async Task RunNpm(
351351
);
352352
}
353353

354+
// NOTE TO FUTURE DEVS: if this is causing merge conflicts with dev, just nuke it we don't need anymore
355+
private async Task<string> RunNode(
356+
ProcessArgs args,
357+
string? workingDirectory = null,
358+
IReadOnlyDictionary<string, string>? envVars = null
359+
)
360+
{
361+
var nodePath = Path.Combine(NodeDir, "bin", "node");
362+
var result = await ProcessRunner
363+
.GetProcessResultAsync(nodePath, args, workingDirectory, envVars)
364+
.ConfigureAwait(false);
365+
366+
result.EnsureSuccessExitCode();
367+
return result.StandardOutput ?? result.StandardError ?? string.Empty;
368+
}
369+
354370
[SupportedOSPlatform("Linux")]
355371
[SupportedOSPlatform("macOS")]
356372
public async Task<Process> RunDotnet(
@@ -395,17 +411,32 @@ public async Task<Process> RunDotnet(
395411
[SupportedOSPlatform("macOS")]
396412
public async Task InstallNodeIfNecessary(IProgress<ProgressReport>? progress = null)
397413
{
398-
if (IsNodeInstalled)
414+
// NOTE TO FUTURE DEVS: if this is causing merge conflicts with dev, just nuke it we don't need anymore
415+
if (NodeDir.Exists)
399416
{
400-
Logger.Info("node already installed");
401-
return;
417+
try
418+
{
419+
var result = await RunNode("-v");
420+
if (result.Contains("20.19.3"))
421+
{
422+
Logger.Debug("Node.js already installed at {NodeExistsPath}", NodeDir);
423+
return;
424+
}
425+
}
426+
catch (Exception)
427+
{
428+
// ignored
429+
}
430+
431+
Logger.Warn("Node.js version mismatch, reinstalling...");
432+
await NodeDir.DeleteAsync(true);
402433
}
403434

404435
Logger.Info("Downloading node");
405436

406437
var downloadUrl = Compat.IsMacOS
407-
? "https://nodejs.org/dist/v20.11.0/node-v20.11.0-darwin-arm64.tar.gz"
408-
: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-linux-x64.tar.gz";
438+
? "https://nodejs.org/dist/v20.19.3/node-v20.19.3-darwin-arm64.tar.gz"
439+
: "https://nodejs.org/dist/v20.19.3/node-v20.19.3-linux-x64.tar.gz";
409440

410441
var nodeDownloadPath = AssetsDir.JoinFile(Path.GetFileName(downloadUrl));
411442

@@ -425,8 +456,8 @@ public async Task InstallNodeIfNecessary(IProgress<ProgressReport>? progress = n
425456
await ArchiveHelper.Extract7ZAuto(nodeDownloadPath, AssetsDir);
426457

427458
var nodeDir = Compat.IsMacOS
428-
? AssetsDir.JoinDir("node-v20.11.0-darwin-arm64")
429-
: AssetsDir.JoinDir("node-v20.11.0-linux-x64");
459+
? AssetsDir.JoinDir("node-v20.19.3-darwin-arm64")
460+
: AssetsDir.JoinDir("node-v20.19.3-linux-x64");
430461
Directory.Move(nodeDir, NodeDir);
431462

432463
progress?.Report(

StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ IPyRunner pyRunner
3232
private const string TkinterDownloadUrl =
3333
"https://cdn.lykos.ai/tkinter-cpython-embedded-3.10.11-win-x64.zip";
3434

35-
private const string NodeDownloadUrl = "https://nodejs.org/dist/v20.11.0/node-v20.11.0-win-x64.zip";
35+
private const string NodeDownloadUrl = "https://nodejs.org/dist/v20.19.3/node-v20.19.3-win-x64.zip";
3636

3737
private const string Dotnet7DownloadUrl =
3838
"https://download.visualstudio.microsoft.com/download/pr/2133b143-9c4f-4daa-99b0-34fa6035d67b/193ede446d922eb833f1bfe0239be3fc/dotnet-sdk-7.0.405-win-x64.zip";
@@ -69,6 +69,7 @@ IPyRunner pyRunner
6969
private string TkinterExtractPath => PythonDir;
7070
private string TkinterExistsPath => Path.Combine(PythonDir, "tkinter");
7171
private string NodeExistsPath => Path.Combine(AssetsDir, "nodejs", "npm.cmd");
72+
private string NodeExePath => Path.Combine(AssetsDir, "nodejs", "node.exe");
7273
private string NodeDownloadPath => Path.Combine(AssetsDir, "nodejs.zip");
7374
private string Dotnet7DownloadPath => Path.Combine(AssetsDir, "dotnet-sdk-7.0.405-win-x64.zip");
7475
private string Dotnet8DownloadPath => Path.Combine(AssetsDir, "dotnet-sdk-8.0.101-win-x64.zip");
@@ -109,7 +110,7 @@ public async Task RunGit(
109110
onProcessOutput,
110111
environmentVariables: new Dictionary<string, string>
111112
{
112-
{ "PATH", Compat.GetEnvPathWithExtensions(GitBinPath) }
113+
{ "PATH", Compat.GetEnvPathWithExtensions(GitBinPath) },
113114
}
114115
);
115116
await process.WaitForExitAsync().ConfigureAwait(false);
@@ -127,7 +128,7 @@ public Task<ProcessResult> GetGitOutput(ProcessArgs args, string? workingDirecto
127128
workingDirectory: workingDirectory,
128129
environmentVariables: new Dictionary<string, string>
129130
{
130-
{ "PATH", Compat.GetEnvPathWithExtensions(GitBinPath) }
131+
{ "PATH", Compat.GetEnvPathWithExtensions(GitBinPath) },
131132
}
132133
);
133134
}
@@ -148,6 +149,21 @@ public async Task RunNpm(
148149
onProcessOutput?.Invoke(ProcessOutput.FromStdErrLine(result.StandardError));
149150
}
150151

152+
// NOTE TO FUTURE DEVS: if this is causing merge conflicts with dev, just nuke it we don't need anymore
153+
private async Task<string> RunNode(
154+
ProcessArgs args,
155+
string? workingDirectory = null,
156+
IReadOnlyDictionary<string, string>? envVars = null
157+
)
158+
{
159+
var result = await ProcessRunner
160+
.GetProcessResultAsync(NodeExePath, args, workingDirectory, envVars)
161+
.ConfigureAwait(false);
162+
163+
result.EnsureSuccessExitCode();
164+
return result.StandardOutput ?? result.StandardError ?? string.Empty;
165+
}
166+
151167
public Task InstallPackageRequirements(BasePackage package, IProgress<ProgressReport>? progress = null) =>
152168
InstallPackageRequirements(package.Prerequisites.ToList(), progress);
153169

@@ -214,7 +230,7 @@ public async Task InstallAllIfNecessary(IProgress<ProgressReport>? progress = nu
214230
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null)
215231
{
216232
// Array of (asset_uri, extract_to)
217-
var assets = new[] { (Assets.SevenZipExecutable, AssetsDir), (Assets.SevenZipLicense, AssetsDir), };
233+
var assets = new[] { (Assets.SevenZipExecutable, AssetsDir), (Assets.SevenZipLicense, AssetsDir) };
218234

219235
progress?.Report(new ProgressReport(0, message: "Unpacking resources", isIndeterminate: true));
220236

@@ -487,12 +503,31 @@ await downloadService.DownloadToFileAsync(
487503
[SupportedOSPlatform("windows")]
488504
public async Task InstallNodeIfNecessary(IProgress<ProgressReport>? progress = null)
489505
{
490-
if (File.Exists(NodeExistsPath))
491-
return;
506+
// NOTE TO FUTURE DEVS: if this is causing merge conflicts with dev, just nuke it we don't need anymore
507+
var nodeFolder = new DirectoryPath(AssetsDir, "nodejs");
508+
if (nodeFolder.Exists)
509+
{
510+
try
511+
{
512+
var result = await RunNode("-v");
513+
if (result.Contains("20.19.3"))
514+
{
515+
Logger.Debug("Node.js already installed at {NodeExistsPath}", NodeExistsPath);
516+
return;
517+
}
518+
}
519+
catch (Exception)
520+
{
521+
// ignored
522+
}
523+
524+
Logger.Warn("Node.js version mismatch, reinstalling...");
525+
await nodeFolder.DeleteAsync(true);
526+
}
492527

493528
await DownloadAndExtractPrerequisite(progress, NodeDownloadUrl, NodeDownloadPath, AssetsDir);
494529

495-
var extractedNodeDir = Path.Combine(AssetsDir, "node-v20.11.0-win-x64");
530+
var extractedNodeDir = Path.Combine(AssetsDir, "node-v20.19.3-win-x64");
496531
if (Directory.Exists(extractedNodeDir))
497532
{
498533
Directory.Move(extractedNodeDir, Path.Combine(AssetsDir, "nodejs"));
@@ -591,7 +626,7 @@ public async Task InstallHipSdkIfNecessary(IProgress<ProgressReport>? progress =
591626
Arguments = "-install -log hip_install.log",
592627
UseShellExecute = true,
593628
CreateNoWindow = true,
594-
Verb = "runas"
629+
Verb = "runas",
595630
};
596631

597632
if (Process.Start(info) is { } process)
@@ -755,14 +790,14 @@ private async Task PatchHipSdkIfNecessary(IProgress<ProgressReport>? progress)
755790
{
756791
_ when downloadUrl.Contains("gfx1201") => null,
757792
_ when downloadUrl.Contains("gfx1150") => "rocm gfx1150 for hip skd 6.2.4",
758-
_ when downloadUrl.Contains("gfx1103.AMD")
759-
=> "rocm gfx1103 AMD 780M phoenix V5.0 for hip skd 6.2.4",
793+
_ when downloadUrl.Contains("gfx1103.AMD") =>
794+
"rocm gfx1103 AMD 780M phoenix V5.0 for hip skd 6.2.4",
760795
_ when downloadUrl.Contains("gfx1034") => "rocm gfx1034-gfx1035-gfx1036 for hip sdk 6.2.4",
761796
_ when downloadUrl.Contains("gfx1032") => "rocm gfx1032 for hip skd 6.2.4(navi21 logic)",
762797
_ when downloadUrl.Contains("gfx1031") => "rocm gfx1031 for hip skd 6.2.4 (littlewu's logic)",
763-
_ when downloadUrl.Contains("gfx1010")
764-
=> "rocm gfx1010-xnack-gfx1011-xnack-gfx1012-xnack- for hip sdk 6.2.4",
765-
_ => null
798+
_ when downloadUrl.Contains("gfx1010") =>
799+
"rocm gfx1010-xnack-gfx1011-xnack-gfx1012-xnack- for hip sdk 6.2.4",
800+
_ => null,
766801
};
767802

768803
var librarySourceDir = rocmLibsExtractPath;

StabilityMatrix.Core/Models/Packages/InvokeAI.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,21 @@ private async Task SetupAndBuildInvokeFrontend(
214214
string installLocation,
215215
IProgress<ProgressReport>? progress,
216216
Action<ProcessOutput>? onConsoleOutput,
217-
IReadOnlyDictionary<string, string>? envVars = null
217+
IReadOnlyDictionary<string, string>? envVars = null,
218+
InstallPackageOptions? installOptions = null
218219
)
219220
{
220221
await PrerequisiteHelper.InstallNodeIfNecessary(progress).ConfigureAwait(false);
222+
223+
var pnpmVersion = installOptions?.VersionOptions.VersionTag?.Contains("v5") == true ? "8" : "10";
224+
221225
await PrerequisiteHelper
222-
.RunNpm(["i", "pnpm@8"], installLocation, envVars: envVars)
226+
.RunNpm(["i", $"pnpm@{pnpmVersion}"], installLocation, envVars: envVars)
223227
.ConfigureAwait(false);
224228

225-
if (Compat.IsMacOS || Compat.IsLinux)
226-
{
227-
await PrerequisiteHelper
228-
.RunNpm(["i", "vite", "--ignore-scripts=true"], installLocation, envVars: envVars)
229-
.ConfigureAwait(false);
230-
}
229+
await PrerequisiteHelper
230+
.RunNpm(["i", "vite", "--ignore-scripts=true"], installLocation, envVars: envVars)
231+
.ConfigureAwait(false);
231232

232233
var pnpmPath = Path.Combine(
233234
installLocation,
@@ -257,7 +258,7 @@ await PrerequisiteHelper
257258

258259
process = ProcessRunner.StartAnsiProcess(
259260
Compat.IsWindows ? pnpmPath : vitePath,
260-
"build",
261+
Compat.IsWindows ? "vite build" : "build",
261262
invokeFrontendPath,
262263
onConsoleOutput,
263264
envVars

StabilityMatrix.Core/Models/Packages/KohyaSs.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,51 @@ IPyRunner runner
4949
Name = "Listen Address",
5050
Type = LaunchOptionType.String,
5151
DefaultValue = "127.0.0.1",
52-
Options = ["--listen"]
52+
Options = ["--listen"],
5353
},
5454
new LaunchOptionDefinition
5555
{
5656
Name = "Port",
5757
Type = LaunchOptionType.String,
58-
Options = ["--port"]
58+
Options = ["--port"],
5959
},
6060
new LaunchOptionDefinition
6161
{
6262
Name = "Username",
6363
Type = LaunchOptionType.String,
64-
Options = ["--username"]
64+
Options = ["--username"],
6565
},
6666
new LaunchOptionDefinition
6767
{
6868
Name = "Password",
6969
Type = LaunchOptionType.String,
70-
Options = ["--password"]
70+
Options = ["--password"],
7171
},
7272
new LaunchOptionDefinition
7373
{
7474
Name = "Auto-Launch Browser",
7575
Type = LaunchOptionType.Bool,
76-
Options = ["--inbrowser"]
76+
Options = ["--inbrowser"],
7777
},
7878
new LaunchOptionDefinition
7979
{
8080
Name = "Share",
8181
Type = LaunchOptionType.Bool,
82-
Options = ["--share"]
82+
Options = ["--share"],
8383
},
8484
new LaunchOptionDefinition
8585
{
8686
Name = "Headless",
8787
Type = LaunchOptionType.Bool,
88-
Options = ["--headless"]
88+
Options = ["--headless"],
8989
},
9090
new LaunchOptionDefinition
9191
{
9292
Name = "Language",
9393
Type = LaunchOptionType.String,
94-
Options = ["--language"]
94+
Options = ["--language"],
9595
},
96-
LaunchOptionDefinition.Extras
96+
LaunchOptionDefinition.Extras,
9797
];
9898

9999
public override async Task InstallPackage(
@@ -143,7 +143,7 @@ await PrerequisiteHelper
143143
.WithTorch()
144144
.WithTorchVision()
145145
.WithTorchAudio()
146-
.WithXFormers()
146+
.WithXFormers(">=0.0.30")
147147
.WithTorchExtraIndex(torchExtraIndex)
148148
.AddArg("--force-reinstall");
149149

@@ -215,7 +215,7 @@ void HandleConsoleOutput(ProcessOutput s)
215215
}
216216

217217
VenvRunner.RunDetached(
218-
[Path.Combine(installLocation, options.Command ?? LaunchCommand), ..options.Arguments],
218+
[Path.Combine(installLocation, options.Command ?? LaunchCommand), .. options.Arguments],
219219
HandleConsoleOutput,
220220
OnExit
221221
);

0 commit comments

Comments
 (0)