Skip to content

Commit bec5103

Browse files
authored
Merge pull request #192 from ionite34/fixes
2 parents 88ec80c + 9ea7cbd commit bec5103

File tree

3 files changed

+69
-22
lines changed

3 files changed

+69
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to Stability Matrix will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).
77

8+
## v2.1.2
9+
10+
### Changed
11+
- SD.Next install now uses ROCm PyTorch backend on Linux AMD GPU machines for better performance over DirectML
12+
813
## v2.1.1
914

1015
### Added

StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,21 @@ public VladAutomatic(IGithubApiCache githubApi, ISettingsManager settingsManager
9898
{
9999
Name = "Use DirectML if no compatible GPU is detected",
100100
Type = LaunchOptionType.Bool,
101-
InitialValue = !HardwareHelper.HasNvidiaGpu() && HardwareHelper.HasAmdGpu(),
101+
InitialValue = PreferDirectML(),
102102
Options = new() { "--use-directml" }
103103
},
104104
new()
105105
{
106106
Name = "Force use of Nvidia CUDA backend",
107107
Type = LaunchOptionType.Bool,
108+
InitialValue = HardwareHelper.HasNvidiaGpu(),
108109
Options = new() { "--use-cuda" }
109110
},
110111
new()
111112
{
112113
Name = "Force use of AMD ROCm backend",
113114
Type = LaunchOptionType.Bool,
115+
InitialValue = PreferRocm(),
114116
Options = new() { "--use-rocm" }
115117
},
116118
new()
@@ -136,6 +138,16 @@ public VladAutomatic(IGithubApiCache githubApi, ISettingsManager settingsManager
136138

137139
public override string ExtraLaunchArguments => "";
138140

141+
// Set ROCm for default if AMD and Linux
142+
private static bool PreferRocm() => !HardwareHelper.HasNvidiaGpu()
143+
&& HardwareHelper.HasAmdGpu()
144+
&& Compat.IsLinux;
145+
146+
// Set DirectML for default if AMD and Windows
147+
private static bool PreferDirectML() => !HardwareHelper.HasNvidiaGpu()
148+
&& HardwareHelper.HasAmdGpu()
149+
&& Compat.IsWindows;
150+
139151
public override Task<string> GetLatestVersion() => Task.FromResult("master");
140152

141153
public override async Task<IEnumerable<PackageVersion>> GetAllVersions(bool isReleaseMode = true)
@@ -150,42 +162,38 @@ public override async Task<IEnumerable<PackageVersion>> GetAllVersions(bool isRe
150162

151163
public override async Task InstallPackage(IProgress<ProgressReport>? progress = null)
152164
{
153-
progress?.Report(new ProgressReport(-1f, "Installing dependencies...", isIndeterminate: true));
165+
progress?.Report(new ProgressReport(-1f, "Installing package...", isIndeterminate: true));
154166
// Setup venv
155167
var venvRunner = new PyVenvRunner(Path.Combine(InstallLocation, "venv"));
156168
venvRunner.WorkingDirectory = InstallLocation;
157-
if (!venvRunner.Exists())
169+
venvRunner.EnvironmentVariables = SettingsManager.Settings.EnvironmentVariables;
170+
171+
await venvRunner.Setup().ConfigureAwait(false);
172+
173+
// Run initial install
174+
if (HardwareHelper.HasNvidiaGpu())
158175
{
159-
await venvRunner.Setup().ConfigureAwait(false);
176+
// CUDA
177+
await venvRunner.CustomInstall("launch.py --use-cuda --debug --test", OnConsoleOutput)
178+
.ConfigureAwait(false);
160179
}
161-
162-
// Install torch / xformers based on gpu info
163-
var gpus = HardwareHelper.IterGpuInfo().ToList();
164-
if (gpus.Any(g => g.IsNvidia))
180+
else if (PreferRocm())
165181
{
166-
Logger.Info("Starting torch install (CUDA)...");
167-
await venvRunner.PipInstall(PyVenvRunner.TorchPipInstallArgsCuda, OnConsoleOutput)
182+
// ROCm
183+
await venvRunner.CustomInstall("launch.py --use-rocm --debug --test", OnConsoleOutput)
168184
.ConfigureAwait(false);
169-
170-
Logger.Info("Installing xformers...");
171-
await venvRunner.PipInstall("xformers", OnConsoleOutput).ConfigureAwait(false);
172185
}
173-
else if (gpus.Any(g => g.IsAmd))
186+
else if (PreferDirectML())
174187
{
175-
Logger.Info("Starting torch install (DirectML)...");
176-
await venvRunner.PipInstall(PyVenvRunner.TorchPipInstallArgsDirectML, OnConsoleOutput)
188+
// DirectML
189+
await venvRunner.CustomInstall("launch.py --use-directml --debug --test", OnConsoleOutput)
177190
.ConfigureAwait(false);
178191
}
179192
else
180193
{
181-
Logger.Info("Starting torch install (CPU)...");
182-
await venvRunner.PipInstall(PyVenvRunner.TorchPipInstallArgsCpu, OnConsoleOutput)
194+
await venvRunner.CustomInstall("launch.py --debug --test", OnConsoleOutput)
183195
.ConfigureAwait(false);
184196
}
185-
186-
// Install requirements file
187-
Logger.Info("Installing requirements.txt");
188-
await venvRunner.PipInstall($"-r requirements.txt", OnConsoleOutput).ConfigureAwait(false);
189197

190198
progress?.Report(new ProgressReport(1, isIndeterminate: false));
191199
}

StabilityMatrix.Core/Python/PyVenvRunner.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,40 @@ public async Task PipInstall(string args, Action<ProcessOutput>? outputDataRecei
218218
);
219219
}
220220
}
221+
222+
/// <summary>
223+
/// Run a custom install command. Waits for the process to exit.
224+
/// workingDirectory defaults to RootPath.
225+
/// </summary>
226+
public async Task CustomInstall(string args, Action<ProcessOutput>? outputDataReceived = null)
227+
{
228+
// Record output for errors
229+
var output = new StringBuilder();
230+
231+
var outputAction =
232+
outputDataReceived == null
233+
? null
234+
: new Action<ProcessOutput>(s =>
235+
{
236+
Logger.Debug($"Install output: {s.Text}");
237+
// Record to output
238+
output.Append(s.Text);
239+
// Forward to callback
240+
outputDataReceived(s);
241+
});
242+
243+
SetPyvenvCfg(PyRunner.PythonDir);
244+
RunDetached(args, outputAction);
245+
await Process.WaitForExitAsync().ConfigureAwait(false);
246+
247+
// Check return code
248+
if (Process.ExitCode != 0)
249+
{
250+
throw new ProcessException(
251+
$"install script failed with code {Process.ExitCode}: {output.ToString().ToRepr()}"
252+
);
253+
}
254+
}
221255

222256
/// <summary>
223257
/// Run a command using the venv Python executable and return the result.

0 commit comments

Comments
 (0)