Skip to content

Commit 0d6d519

Browse files
authored
Merge pull request LykosAI#929 from ionite34/backport/main/pr-924
[dev to main] backport: Comfy zluda (924)
2 parents b1a236f + 894d69b commit 0d6d519

File tree

15 files changed

+293
-14
lines changed

15 files changed

+293
-14
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<PackageVersion Include="Dock.Model.Avalonia" Version="11.2.0" />
104104
<PackageVersion Include="Dock.Serializer" Version="11.2.0" />
105105
<PackageVersion Include="FluentAvalonia.BreadcrumbBar" Version="2.0.2" />
106-
<PackageVersion Include="FluentAvaloniaUI" Version="2.1.0" />
106+
<PackageVersion Include="FluentAvaloniaUI" Version="2.2.0" />
107107
<PackageVersion Include="FluentIcons.Avalonia" Version="1.1.249" />
108108
<PackageVersion Include="FluentIcons.Avalonia.Fluent" Version="1.1.249" />
109109
<PackageVersion Include="Markdown.Avalonia" Version="11.0.3-a1" />

StabilityMatrix.Avalonia/App.axaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ internal static IServiceCollection ConfigureServices()
450450
// if (string.IsNullOrWhiteSpace(githubApiKey))
451451
// return client;
452452
//
453-
// client.Credentials =
454-
// new Credentials("");
453+
// client.Credentials = new Credentials(
454+
// ""
455+
// );
455456
return client;
456457
});
457458

StabilityMatrix.Avalonia/Helpers/WindowsPrerequisiteHelper.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ IPyRunner pyRunner
4545

4646
private const string CppBuildToolsUrl = "https://aka.ms/vs/17/release/vs_BuildTools.exe";
4747

48+
private const string HipSdkDownloadUrl = "https://cdn.lykos.ai/AMD-HIP-SDK.exe";
49+
4850
private string HomeDir => settingsManager.LibraryDir;
4951

5052
private string VcRedistDownloadPath => Path.Combine(HomeDir, "vcredist.x64.exe");
@@ -83,6 +85,11 @@ IPyRunner pyRunner
8385
"BuildTools"
8486
);
8587

88+
private string HipSdkDownloadPath => Path.Combine(AssetsDir, "AMD-HIP-SDK.exe");
89+
90+
private string HipInstalledPath =>
91+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "AMD", "ROCm", "5.7");
92+
8693
public string GitBinPath => Path.Combine(PortableGitInstallDir, "bin");
8794
public bool IsPythonInstalled => File.Exists(PythonDllPath);
8895

@@ -192,6 +199,11 @@ public async Task InstallPackageRequirements(
192199
{
193200
await InstallVcBuildToolsIfNecessary(progress);
194201
}
202+
203+
if (prerequisites.Contains(PackagePrerequisite.HipSdk))
204+
{
205+
await InstallHipSdkIfNecessary(progress);
206+
}
195207
}
196208

197209
public async Task InstallAllIfNecessary(IProgress<ProgressReport>? progress = null)
@@ -202,6 +214,7 @@ public async Task InstallAllIfNecessary(IProgress<ProgressReport>? progress = nu
202214
await InstallGitIfNecessary(progress);
203215
await InstallNodeIfNecessary(progress);
204216
await InstallVcBuildToolsIfNecessary(progress);
217+
await InstallHipSdkIfNecessary(progress);
205218
}
206219

207220
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null)
@@ -553,6 +566,39 @@ await downloadService.DownloadToFileAsync(
553566
await process.WaitForExitAsync();
554567
}
555568

569+
[SupportedOSPlatform("windows")]
570+
public async Task InstallHipSdkIfNecessary(IProgress<ProgressReport>? progress = null)
571+
{
572+
if (Directory.Exists(HipInstalledPath))
573+
return;
574+
575+
await downloadService.DownloadToFileAsync(HipSdkDownloadUrl, HipSdkDownloadPath, progress: progress);
576+
Logger.Info("Downloaded & installing HIP SDK");
577+
578+
progress?.Report(
579+
new ProgressReport(
580+
progress: 0.5f,
581+
isIndeterminate: true,
582+
type: ProgressType.Generic,
583+
message: "Installing HIP SDK, this may take a few minutes..."
584+
)
585+
);
586+
587+
var info = new ProcessStartInfo
588+
{
589+
FileName = HipSdkDownloadPath,
590+
Arguments = "-install -log hip_install.log",
591+
UseShellExecute = true,
592+
CreateNoWindow = true,
593+
Verb = "runas"
594+
};
595+
596+
if (Process.Start(info) is { } process)
597+
{
598+
await process.WaitForExitAsync();
599+
}
600+
}
601+
556602
public async Task<Process> RunDotnet(
557603
ProcessArgs args,
558604
string? workingDirectory = null,

StabilityMatrix.Core/Helper/Factory/PackageFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public BasePackage GetNewBasePackage(InstalledPackage installedPackage)
9494
=> new SimpleSDXL(githubApiCache, settingsManager, downloadService, prerequisiteHelper),
9595
"Cogstudio"
9696
=> new Cogstudio(githubApiCache, settingsManager, downloadService, prerequisiteHelper),
97+
"ComfyUI-Zluda"
98+
=> new ComfyZluda(githubApiCache, settingsManager, downloadService, prerequisiteHelper),
9799
_ => throw new ArgumentOutOfRangeException(nameof(installedPackage))
98100
};
99101
}

StabilityMatrix.Core/Helper/HardwareInfo/HardwareHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public static bool HasAmdGpu()
264264
public static bool PreferRocm() => !HasNvidiaGpu() && HasAmdGpu() && Compat.IsLinux;
265265

266266
// Set DirectML for default if AMD and Windows
267-
public static bool PreferDirectML() => !HasNvidiaGpu() && HasAmdGpu() && Compat.IsWindows;
267+
public static bool PreferDirectMLOrZluda() => !HasNvidiaGpu() && HasAmdGpu() && Compat.IsWindows;
268268

269269
private static readonly Lazy<bool> IsMemoryInfoAvailableLazy = new(() => TryGetMemoryInfo(out _));
270270
public static bool IsMemoryInfoAvailable => IsMemoryInfoAvailableLazy.Value;

StabilityMatrix.Core/Models/PackagePrerequisite.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum PackagePrerequisite
55
Python310,
66
VcRedist,
77
Git,
8+
HipSdk,
89
Node,
910
Dotnet,
1011
Tkinter,

StabilityMatrix.Core/Models/Packages/A3WebUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ IPrerequisiteHelper prerequisiteHelper
162162
Type = LaunchOptionType.Bool,
163163
Description = "Do not switch the model to 16-bit floats",
164164
InitialValue =
165-
HardwareHelper.PreferRocm() || HardwareHelper.PreferDirectML() || Compat.IsMacOS,
165+
HardwareHelper.PreferRocm() || HardwareHelper.PreferDirectMLOrZluda() || Compat.IsMacOS,
166166
Options = ["--no-half"]
167167
},
168168
new()

StabilityMatrix.Core/Models/Packages/BasePackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public virtual TorchIndex GetRecommendedTorchVersion()
147147

148148
var preferDirectMl =
149149
Compat.IsWindows
150-
&& (SettingsManager.Settings.PreferredGpu?.IsAmd ?? HardwareHelper.PreferDirectML());
150+
&& (SettingsManager.Settings.PreferredGpu?.IsAmd ?? HardwareHelper.PreferDirectMLOrZluda());
151151
if (AvailableTorchIndices.Contains(TorchIndex.DirectMl) && preferDirectMl)
152152
{
153153
return TorchIndex.DirectMl;

StabilityMatrix.Core/Models/Packages/ComfyUI.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ IPrerequisiteHelper prerequisiteHelper
103103
Options = ["--highvram", "--normalvram", "--lowvram", "--novram"]
104104
},
105105
new LaunchOptionDefinition
106+
{
107+
Name = "Reserve VRAM",
108+
Type = LaunchOptionType.String,
109+
InitialValue = Compat.IsWindows && HardwareHelper.HasAmdGpu() ? "0.9" : null,
110+
Description =
111+
"Sets the amount of VRAM (in GB) you want to reserve for use by your OS/other software",
112+
Options = ["--reserve-vram"]
113+
},
114+
new LaunchOptionDefinition
106115
{
107116
Name = "Preview Method",
108117
Type = LaunchOptionType.Bool,
@@ -113,7 +122,7 @@ IPrerequisiteHelper prerequisiteHelper
113122
{
114123
Name = "Enable DirectML",
115124
Type = LaunchOptionType.Bool,
116-
InitialValue = HardwareHelper.PreferDirectML(),
125+
InitialValue = HardwareHelper.PreferDirectMLOrZluda() && this is not ComfyZluda,
117126
Options = ["--directml"]
118127
},
119128
new LaunchOptionDefinition
@@ -128,7 +137,11 @@ IPrerequisiteHelper prerequisiteHelper
128137
{
129138
Name = "Cross Attention Method",
130139
Type = LaunchOptionType.Bool,
131-
InitialValue = Compat.IsMacOS ? "--use-pytorch-cross-attention" : null,
140+
InitialValue = Compat.IsMacOS
141+
? "--use-pytorch-cross-attention"
142+
: (Compat.IsWindows && HardwareHelper.HasAmdGpu())
143+
? "--use-quad-cross-attention"
144+
: null,
132145
Options =
133146
[
134147
"--use-split-cross-attention",

0 commit comments

Comments
 (0)