forked from LykosAI/StabilityMatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDWebForge.cs
More file actions
208 lines (193 loc) · 7.68 KB
/
SDWebForge.cs
File metadata and controls
208 lines (193 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System.Text;
using Injectio.Attributes;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Cache;
using StabilityMatrix.Core.Helper.HardwareInfo;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.Packages.Extensions;
using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes;
using StabilityMatrix.Core.Python;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Core.Models.Packages;
[RegisterSingleton<BasePackage, SDWebForge>(Duplicate = DuplicateStrategy.Append)]
public class SDWebForge(
IGithubApiCache githubApi,
ISettingsManager settingsManager,
IDownloadService downloadService,
IPrerequisiteHelper prerequisiteHelper,
IPyInstallationManager pyInstallationManager
) : A3WebUI(githubApi, settingsManager, downloadService, prerequisiteHelper, pyInstallationManager)
{
public override string Name => "stable-diffusion-webui-forge";
public override string DisplayName { get; set; } = "Stable Diffusion WebUI Forge";
public override string Author => "lllyasviel";
public override string Blurb =>
"Stable Diffusion WebUI Forge is a platform on top of Stable Diffusion WebUI (based on Gradio) to make development easier, optimize resource management, and speed up inference.";
public override string LicenseUrl =>
"https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/LICENSE.txt";
public override Uri PreviewImageUri => new("https://cdn.lykos.ai/sm/packages/sdwebforge/preview.webp");
public override string MainBranch => "main";
public override bool ShouldIgnoreReleases => true;
public override IPackageExtensionManager ExtensionManager => null;
public override PackageDifficulty InstallerSortOrder => PackageDifficulty.ReallyRecommended;
public override List<LaunchOptionDefinition> LaunchOptions =>
[
new()
{
Name = "Host",
Type = LaunchOptionType.String,
DefaultValue = "localhost",
Options = ["--server-name"],
},
new()
{
Name = "Port",
Type = LaunchOptionType.String,
DefaultValue = "7860",
Options = ["--port"],
},
new()
{
Name = "Share",
Type = LaunchOptionType.Bool,
Description = "Set whether to share on Gradio",
Options = { "--share" },
},
new()
{
Name = "Pin Shared Memory",
Type = LaunchOptionType.Bool,
Options = { "--pin-shared-memory" },
InitialValue =
HardwareHelper.HasNvidiaGpu()
&& (
SettingsManager.Settings.PreferredGpu?.IsLegacyNvidiaGpu() is false
|| !HardwareHelper.HasLegacyNvidiaGpu()
),
},
new()
{
Name = "CUDA Malloc",
Type = LaunchOptionType.Bool,
Options = { "--cuda-malloc" },
InitialValue =
HardwareHelper.HasNvidiaGpu()
&& (
SettingsManager.Settings.PreferredGpu?.IsLegacyNvidiaGpu() is false
|| !HardwareHelper.HasLegacyNvidiaGpu()
),
},
new()
{
Name = "CUDA Stream",
Type = LaunchOptionType.Bool,
Options = { "--cuda-stream" },
InitialValue =
HardwareHelper.HasNvidiaGpu()
&& (
SettingsManager.Settings.PreferredGpu?.IsLegacyNvidiaGpu() is false
|| !HardwareHelper.HasLegacyNvidiaGpu()
),
},
new()
{
Name = "Skip Install",
Type = LaunchOptionType.Bool,
InitialValue = true,
Options = ["--skip-install"],
},
new()
{
Name = "Always Offload from VRAM",
Type = LaunchOptionType.Bool,
Options = ["--always-offload-from-vram"],
},
new()
{
Name = "Always GPU",
Type = LaunchOptionType.Bool,
Options = ["--always-gpu"],
},
new()
{
Name = "Always CPU",
Type = LaunchOptionType.Bool,
Options = ["--always-cpu"],
},
new()
{
Name = "Skip Torch CUDA Test",
Type = LaunchOptionType.Bool,
InitialValue = Compat.IsMacOS,
Options = ["--skip-torch-cuda-test"],
},
new()
{
Name = "No half-precision VAE",
Type = LaunchOptionType.Bool,
InitialValue = Compat.IsMacOS,
Options = ["--no-half-vae"],
},
LaunchOptionDefinition.Extras,
];
public override IEnumerable<TorchIndex> AvailableTorchIndices =>
[TorchIndex.Cpu, TorchIndex.Cuda, TorchIndex.Rocm, TorchIndex.Mps];
public override async Task InstallPackage(
string installLocation,
InstalledPackage installedPackage,
InstallPackageOptions options,
IProgress<ProgressReport>? progress = null,
Action<ProcessOutput>? onConsoleOutput = null,
CancellationToken cancellationToken = default
)
{
progress?.Report(new ProgressReport(-1f, "Setting up venv", isIndeterminate: true));
await using var venvRunner = await SetupVenvPure(
installLocation,
pythonVersion: options.PythonOptions.PythonVersion
)
.ConfigureAwait(false);
// Dynamically discover all requirements files
var requirementsPaths = new List<string> { "requirements_versions.txt" };
var extensionsBuiltinDir = new DirectoryPath(installLocation, "extensions-builtin");
if (extensionsBuiltinDir.Exists)
{
requirementsPaths.AddRange(
extensionsBuiltinDir
.EnumerateFiles("requirements.txt", EnumerationOptionConstants.AllDirectories)
.Select(f => Path.GetRelativePath(installLocation, f.ToString()))
);
}
var torchIndex = options.PythonOptions.TorchIndex ?? GetRecommendedTorchVersion();
var isBlackwell =
torchIndex is TorchIndex.Cuda
&& (SettingsManager.Settings.PreferredGpu?.IsBlackwellGpu() ?? HardwareHelper.HasBlackwellGpu());
var isAmd = torchIndex is TorchIndex.Rocm;
var config = new PipInstallConfig
{
PrePipInstallArgs = ["joblib"],
RequirementsFilePaths = requirementsPaths,
TorchVersion = "",
TorchvisionVersion = "",
CudaIndex = isBlackwell ? "cu128" : "cu126",
RocmIndex = "rocm6.4",
ExtraPipArgs =
[
"https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip",
],
PostInstallPipArgs = ["numpy==1.26.4"],
};
await StandardPipInstallProcessAsync(
venvRunner,
options,
installedPackage,
config,
onConsoleOutput,
progress,
cancellationToken
)
.ConfigureAwait(false);
progress?.Report(new ProgressReport(1f, "Install complete", isIndeterminate: false));
}
}