Browse Source

Merge branch 'dev' of https://github.com/ionite34/StabilityMatrix into show-package-install

pull/438/head
JT 10 months ago
parent
commit
72c8f264d7
  1. 4
      StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs
  2. 5
      StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs
  3. 3
      StabilityMatrix.Core/Helper/IPrerequisiteHelper.cs
  4. 3
      StabilityMatrix.Core/Helper/PrerequisiteHelper.cs
  5. 6
      StabilityMatrix.Core/Models/Packages/A3WebUI.cs
  6. 10
      StabilityMatrix.Core/Models/Packages/BasePackage.cs
  7. 8
      StabilityMatrix.Core/Models/Packages/InvokeAI.cs
  8. 16
      StabilityMatrix.Core/Models/Packages/StableDiffusionUx.cs
  9. 19
      StabilityMatrix.Core/Processes/ProcessRunner.cs

4
StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
@ -240,7 +241,8 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
public async Task RunNpm(
ProcessArgs args,
string? workingDirectory = null,
Action<ProcessOutput>? onProcessOutput = null
Action<ProcessOutput>? onProcessOutput = null,
IReadOnlyDictionary<string, string>? envVars = null
)
{
var command = args.Prepend([NpmPath]);

5
StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs

@ -115,11 +115,12 @@ public class WindowsPrerequisiteHelper : IPrerequisiteHelper
public async Task RunNpm(
ProcessArgs args,
string? workingDirectory = null,
Action<ProcessOutput>? onProcessOutput = null
Action<ProcessOutput>? onProcessOutput = null,
IReadOnlyDictionary<string, string>? envVars = null
)
{
var result = await ProcessRunner
.GetProcessResultAsync(NodeExistsPath, args, workingDirectory)
.GetProcessResultAsync(NodeExistsPath, args, workingDirectory, envVars)
.ConfigureAwait(false);
result.EnsureSuccessExitCode();

3
StabilityMatrix.Core/Helper/IPrerequisiteHelper.cs

@ -157,7 +157,8 @@ public interface IPrerequisiteHelper
Task RunNpm(
ProcessArgs args,
string? workingDirectory = null,
Action<ProcessOutput>? onProcessOutput = null
Action<ProcessOutput>? onProcessOutput = null,
IReadOnlyDictionary<string, string>? envVars = null
);
Task InstallNodeIfNecessary(IProgress<ProgressReport>? progress = null);
}

3
StabilityMatrix.Core/Helper/PrerequisiteHelper.cs

@ -112,7 +112,8 @@ public class PrerequisiteHelper : IPrerequisiteHelper
public Task RunNpm(
ProcessArgs args,
string? workingDirectory = null,
Action<ProcessOutput>? onProcessOutput = null
Action<ProcessOutput>? onProcessOutput = null,
IReadOnlyDictionary<string, string>? envVars = null
)
{
throw new NotImplementedException();

6
StabilityMatrix.Core/Models/Packages/A3WebUI.cs

@ -148,7 +148,8 @@ public class A3WebUI(
Name = "No Half",
Type = LaunchOptionType.Bool,
Description = "Do not switch the model to 16-bit floats",
InitialValue = HardwareHelper.PreferRocm() || HardwareHelper.PreferDirectML(),
InitialValue =
HardwareHelper.PreferRocm() || HardwareHelper.PreferDirectML() || Compat.IsMacOS,
Options = ["--no-half"]
},
new()
@ -171,7 +172,7 @@ public class A3WebUI(
new[] { SharedFolderMethod.Symlink, SharedFolderMethod.None };
public override IEnumerable<TorchVersion> AvailableTorchVersions =>
new[] { TorchVersion.Cpu, TorchVersion.Cuda, TorchVersion.Rocm };
new[] { TorchVersion.Cpu, TorchVersion.Cuda, TorchVersion.Rocm, TorchVersion.Mps };
public override string MainBranch => "master";
@ -208,6 +209,7 @@ public class A3WebUI(
TorchVersion.Cpu => "cpu",
TorchVersion.Cuda => "cu121",
TorchVersion.Rocm => "rocm5.6",
TorchVersion.Mps => "nightly/cpu",
_ => throw new ArgumentOutOfRangeException(nameof(torchVersion), torchVersion, null)
}
)

10
StabilityMatrix.Core/Models/Packages/BasePackage.cs

@ -201,10 +201,10 @@ public abstract class BasePackage
await venvRunner
.PipInstall(
new PipInstallArgs()
.WithTorch("==2.0.1")
.WithTorchVision("==0.15.2")
.WithXFormers("==0.0.20")
.WithTorchExtraIndex("cu118"),
.WithTorch("==2.1.2")
.WithTorchVision("==0.16.2")
.WithXFormers("==0.0.23post1")
.WithTorchExtraIndex("cu121"),
onConsoleOutput
)
.ConfigureAwait(false);
@ -230,7 +230,7 @@ public abstract class BasePackage
progress?.Report(new ProgressReport(-1f, "Installing PyTorch for CPU", isIndeterminate: true));
return venvRunner.PipInstall(
new PipInstallArgs().WithTorch("==2.0.1").WithTorchVision(),
new PipInstallArgs().WithTorch("==2.1.2").WithTorchVision(),
onConsoleOutput
);
}

8
StabilityMatrix.Core/Models/Packages/InvokeAI.cs

@ -283,11 +283,15 @@ public class InvokeAI : BaseGitPackage
)
{
await PrerequisiteHelper.InstallNodeIfNecessary(progress).ConfigureAwait(false);
await PrerequisiteHelper.RunNpm(["i", "pnpm"], installLocation).ConfigureAwait(false);
await PrerequisiteHelper
.RunNpm(["i", "pnpm"], installLocation, envVars: envVars)
.ConfigureAwait(false);
if (Compat.IsMacOS || Compat.IsLinux)
{
await PrerequisiteHelper.RunNpm(["i", "vite"], installLocation).ConfigureAwait(false);
await PrerequisiteHelper
.RunNpm(["i", "vite"], installLocation, envVars: envVars)
.ConfigureAwait(false);
}
var pnpmPath = Path.Combine(

16
StabilityMatrix.Core/Models/Packages/StableDiffusionUx.cs

@ -142,7 +142,8 @@ public class StableDiffusionUx(
Name = "No Half",
Type = LaunchOptionType.Bool,
Description = "Do not switch the model to 16-bit floats",
InitialValue = HardwareHelper.PreferRocm() || HardwareHelper.PreferDirectML(),
InitialValue =
HardwareHelper.PreferRocm() || HardwareHelper.PreferDirectML() || Compat.IsMacOS,
Options = ["--no-half"]
},
new()
@ -165,7 +166,7 @@ public class StableDiffusionUx(
new[] { SharedFolderMethod.Symlink, SharedFolderMethod.None };
public override IEnumerable<TorchVersion> AvailableTorchVersions =>
new[] { TorchVersion.Cpu, TorchVersion.Cuda, TorchVersion.Rocm };
new[] { TorchVersion.Cpu, TorchVersion.Cuda, TorchVersion.Rocm, TorchVersion.Mps };
public override string MainBranch => "master";
@ -199,6 +200,17 @@ public class StableDiffusionUx(
case TorchVersion.Rocm:
await InstallRocmTorch(venvRunner, progress, onConsoleOutput).ConfigureAwait(false);
break;
case TorchVersion.Mps:
await venvRunner
.PipInstall(
new PipInstallArgs()
.WithTorch("==2.1.2")
.WithTorchVision()
.WithTorchExtraIndex("nightly/cpu"),
onConsoleOutput
)
.ConfigureAwait(false);
break;
}
// Install requirements file

19
StabilityMatrix.Core/Processes/ProcessRunner.cs

@ -356,7 +356,11 @@ public static class ProcessRunner
return StartAnsiProcess(fileName, args, workingDirectory, outputDataReceived, environmentVariables);
}
public static async Task<ProcessResult> RunBashCommand(string command, string workingDirectory = "")
public static async Task<ProcessResult> RunBashCommand(
string command,
string workingDirectory = "",
IReadOnlyDictionary<string, string>? environmentVariables = null
)
{
// Escape any single quotes in the command
var escapedCommand = command.Replace("\"", "\\\"");
@ -372,6 +376,14 @@ public static class ProcessRunner
WorkingDirectory = workingDirectory,
};
if (environmentVariables != null)
{
foreach (var (key, value) in environmentVariables)
{
processInfo.EnvironmentVariables[key] = value;
}
}
using var process = new Process();
process.StartInfo = processInfo;
@ -396,12 +408,13 @@ public static class ProcessRunner
public static Task<ProcessResult> RunBashCommand(
IEnumerable<string> commands,
string workingDirectory = ""
string workingDirectory = "",
IReadOnlyDictionary<string, string>? environmentVariables = null
)
{
// Quote arguments containing spaces
var args = string.Join(" ", commands.Select(Quote));
return RunBashCommand(args, workingDirectory);
return RunBashCommand(args, workingDirectory, environmentVariables);
}
/// <summary>

Loading…
Cancel
Save