Skip to content

Commit 8e164fb

Browse files
committed
refactor: Remove self-inflicted nullable guarding on IRocmPackageHelper
- Change IRocmPackageHelper parameter from nullable with default null to non-nullable in ComfyUI, InvokeAI, and Reforge constructors - Remove null-throw guard blocks in ComfyUI.InstallPackage, InvokeAI.InstallPackage, and Reforge.InstallPackage — PackageFactory always injects a non-null instance, making these unreachable - Remove dead null-return guards in ComfyUI.EmitWindowsRocmLaunchNotice and ComfyUI.GetEnvVars - Collapse InvokeAI null-throw pattern (?? throw) on torch install call to a direct rocmPackageHelper method call - Remove nullHelperMessage parameter and ?? throw expression from ComfyUI.RunWindowsRocmPackageCommandAsync and all four call sites - Update BaseGitPackage.HasWindowsRocmSupport and GetWindowsRocmCompatibility signatures to non-nullable; remove dead null branch from the compatibility check condition - Remove null guards, ?? new Dictionary<>(), and ?? [] fallbacks from InvokeAiWindowsRocmProfile and ReforgeWindowsRocmProfile static methods - Add IRocmPackageHelper parameter to ComfyZluda and forward to ComfyUI base constructor to satisfy the now-required parameter; ZLUDA does not use it
1 parent edd3675 commit 8e164fb

8 files changed

Lines changed: 36 additions & 75 deletions

File tree

StabilityMatrix.Core/Helper/Factory/PackageFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ public BasePackage GetNewBasePackage(InstalledPackage installedPackage)
234234
downloadService,
235235
prerequisiteHelper,
236236
pyInstallationManager,
237-
pipWheelService
237+
pipWheelService,
238+
rocmPackageHelper
238239
),
239240
"stable-diffusion-webui-amdgpu-forge" => new ForgeAmdGpu(
240241
githubApiCache,

StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ IPipWheelService pipWheelService
8383
PipWheelService = pipWheelService;
8484
}
8585

86-
protected bool HasWindowsRocmSupport(IRocmPackageHelper? rocmPackageHelper)
86+
protected bool HasWindowsRocmSupport(IRocmPackageHelper rocmPackageHelper)
8787
{
8888
return GetWindowsRocmCompatibility(rocmPackageHelper).IsCompatible;
8989
}
9090

91-
protected RocmCompatibilityResult GetWindowsRocmCompatibility(IRocmPackageHelper? rocmPackageHelper)
91+
protected RocmCompatibilityResult GetWindowsRocmCompatibility(IRocmPackageHelper rocmPackageHelper)
9292
{
93-
if (!Compat.IsWindows || rocmPackageHelper is null)
93+
if (!Compat.IsWindows)
9494
{
9595
return new RocmCompatibilityResult { IsCompatible = false };
9696
}

StabilityMatrix.Core/Models/Packages/ComfyUI.cs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ComfyUI(
2929
IPrerequisiteHelper prerequisiteHelper,
3030
IPyInstallationManager pyInstallationManager,
3131
IPipWheelService pipWheelService,
32-
IRocmPackageHelper? rocmPackageHelper = null
32+
IRocmPackageHelper rocmPackageHelper
3333
)
3434
: BaseGitPackage(
3535
githubApi,
@@ -422,16 +422,6 @@ public override async Task InstallPackage(
422422

423423
if (Compat.IsWindows && torchIndex == TorchIndex.Rocm && HasWindowsRocmSupport())
424424
{
425-
// This is an internal guard for a wiring/configuration failure.
426-
// It can only trigger when Windows ROCm support was detected, but this ComfyUI instance was created
427-
// without the shared ROCm helper (for example via a manual construction path that omitted the dependency).
428-
if (rocmPackageHelper is null)
429-
{
430-
throw new InvalidOperationException(
431-
"Windows ROCm installation encountered an internal configuration error [rocmPackageHelper is null]. Please restart Stability Matrix and try again. If the issue persists, please report it to Stability Matrix."
432-
);
433-
}
434-
435425
var config = rocmPackageHelper.BuildWindowsNativeInstallConfig(ComfyWindowsRocmProfile.Profile);
436426

437427
await StandardPipInstallProcessAsync(
@@ -664,9 +654,6 @@ private void EmitWindowsRocmLaunchNotice(
664654
Action<ProcessOutput>? onConsoleOutput
665655
)
666656
{
667-
if (rocmPackageHelper is null)
668-
return;
669-
670657
if (!ShouldShowWindowsRocmLaunchNotice(installedPackage))
671658
return;
672659

@@ -1033,8 +1020,7 @@ private async Task InstallWindowsRocmSageAttention(InstalledPackage? installedPa
10331020
installedPackage,
10341021
WindowsRocmPackageCommandType.SageAttention,
10351022
"Windows ROCm SageAttention installed successfully",
1036-
includeEnvironmentVariables: true,
1037-
nullHelperMessage: "Windows ROCm SageAttention installation encountered an internal configuration error [rocmPackageHelper is null]."
1023+
includeEnvironmentVariables: true
10381024
)
10391025
.ConfigureAwait(false);
10401026

@@ -1050,8 +1036,7 @@ await RunWindowsRocmPackageCommandAsync(
10501036
installedPackage,
10511037
WindowsRocmPackageCommandType.DevelopmentSdk,
10521038
"Windows ROCm Development SDK installed successfully",
1053-
includeEnvironmentVariables: false,
1054-
nullHelperMessage: "Windows ROCm SDK installation encountered an internal configuration error [rocmPackageHelper is null]."
1039+
includeEnvironmentVariables: false
10551040
)
10561041
.ConfigureAwait(false);
10571042
}
@@ -1062,8 +1047,7 @@ await RunWindowsRocmPackageCommandAsync(
10621047
installedPackage,
10631048
WindowsRocmPackageCommandType.BitsAndBytes,
10641049
"Windows ROCm bitsandbytes installed successfully",
1065-
includeEnvironmentVariables: true,
1066-
nullHelperMessage: "Windows ROCm bitsandbytes installation encountered an internal configuration error [rocmPackageHelper is null]."
1050+
includeEnvironmentVariables: true
10671051
)
10681052
.ConfigureAwait(false);
10691053
}
@@ -1074,8 +1058,7 @@ await RunWindowsRocmPackageCommandAsync(
10741058
installedPackage,
10751059
WindowsRocmPackageCommandType.FlashAttention,
10761060
"Windows ROCm Flash Attention installed successfully",
1077-
includeEnvironmentVariables: true,
1078-
nullHelperMessage: "Windows ROCm Flash Attention installation encountered an internal configuration error [rocmPackageHelper is null]."
1061+
includeEnvironmentVariables: true
10791062
)
10801063
.ConfigureAwait(false);
10811064
}
@@ -1084,8 +1067,7 @@ private async Task<bool> RunWindowsRocmPackageCommandAsync(
10841067
InstalledPackage? installedPackage,
10851068
WindowsRocmPackageCommandType commandType,
10861069
string completionMessage,
1087-
bool includeEnvironmentVariables,
1088-
string nullHelperMessage
1070+
bool includeEnvironmentVariables
10891071
)
10901072
{
10911073
if (installedPackage?.FullPath is null)
@@ -1114,7 +1096,7 @@ await runner
11141096
downloadService,
11151097
pyInstallationManager,
11161098
prerequisiteHelper,
1117-
rocmPackageHelper ?? throw new InvalidOperationException(nullHelperMessage)
1099+
rocmPackageHelper
11181100
)
11191101
{
11201102
CommandType = commandType,
@@ -1218,9 +1200,6 @@ InstalledPackage installedPackage
12181200
if (!Compat.IsWindows || !hasRocmGpu || selectedTorchIndex != TorchIndex.Rocm)
12191201
return env;
12201202

1221-
if (rocmPackageHelper is null)
1222-
return env;
1223-
12241203
var rocmEnvironment = rocmPackageHelper.BuildLaunchEnvironment(ComfyWindowsRocmProfile.Profile);
12251204

12261205
return env.SetItems(rocmEnvironment);

StabilityMatrix.Core/Models/Packages/ComfyZluda.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using StabilityMatrix.Core.Processes;
1313
using StabilityMatrix.Core.Python;
1414
using StabilityMatrix.Core.Services;
15+
using StabilityMatrix.Core.Services.Rocm;
1516

1617
namespace StabilityMatrix.Core.Models.Packages;
1718

@@ -22,15 +23,17 @@ public class ComfyZluda(
2223
IDownloadService downloadService,
2324
IPrerequisiteHelper prerequisiteHelper,
2425
IPyInstallationManager pyInstallationManager,
25-
IPipWheelService pipWheelService
26+
IPipWheelService pipWheelService,
27+
IRocmPackageHelper rocmPackageHelper
2628
)
2729
: ComfyUI(
2830
githubApi,
2931
settingsManager,
3032
downloadService,
3133
prerequisiteHelper,
3234
pyInstallationManager,
33-
pipWheelService
35+
pipWheelService,
36+
rocmPackageHelper
3437
)
3538
{
3639
private const string ZludaPatchDownloadUrl =

StabilityMatrix.Core/Models/Packages/InvokeAI.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class InvokeAI(
2929
IPrerequisiteHelper prerequisiteHelper,
3030
IPyInstallationManager pyInstallationManager,
3131
IPipWheelService pipWheelService,
32-
IRocmPackageHelper? rocmPackageHelper = null
32+
IRocmPackageHelper rocmPackageHelper
3333
)
3434
: BaseGitPackage(
3535
githubApi,
@@ -296,12 +296,7 @@ public override async Task InstallPackage(
296296
new ProgressReport(-1f, "Installing Windows ROCm torch...", isIndeterminate: true)
297297
);
298298

299-
await (
300-
rocmPackageHelper
301-
?? throw new InvalidOperationException(
302-
"Windows ROCm installation encountered an internal configuration error [rocmPackageHelper is null]. Please restart Stability Matrix and try again. If the issue persists, please report it to Stability Matrix."
303-
)
304-
)
299+
await rocmPackageHelper
305300
.InstallWindowsNativeTorchAsync(
306301
venvRunner,
307302
installedPackage,

StabilityMatrix.Core/Models/Packages/Reforge.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Reforge(
2020
IPrerequisiteHelper prerequisiteHelper,
2121
IPyInstallationManager pyInstallationManager,
2222
IPipWheelService pipWheelService,
23-
IRocmPackageHelper? rocmPackageHelper = null
23+
IRocmPackageHelper rocmPackageHelper
2424
)
2525
: SDWebForge(
2626
githubApi,
@@ -124,13 +124,6 @@ await base.InstallPackage(
124124
)
125125
.ConfigureAwait(false);
126126

127-
if (rocmPackageHelper is null)
128-
{
129-
throw new InvalidOperationException(
130-
"Windows ROCm installation encountered an internal configuration error [rocmPackageHelper is null]. Please restart Stability Matrix and try again. If the issue persists, please report it to Stability Matrix."
131-
);
132-
}
133-
134127
var profile = ReforgeWindowsRocmProfile.CreateProfile(GetRequirementsPaths(installLocation));
135128
var config = rocmPackageHelper.BuildWindowsNativeInstallConfig(profile);
136129

StabilityMatrix.Core/Models/Rocm/InvokeAiWindowsRocmProfile.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,18 @@ public static RocmPackageProfile CreateInstallProfile(PyVersion pyVersion)
3838
};
3939
}
4040

41-
public static RocmCompatibilityResult GetCompatibility(IRocmPackageHelper? rocmPackageHelper)
41+
public static RocmCompatibilityResult GetCompatibility(IRocmPackageHelper rocmPackageHelper)
4242
{
43-
if (rocmPackageHelper is null)
44-
{
45-
return new RocmCompatibilityResult { IsCompatible = false };
46-
}
47-
4843
return rocmPackageHelper.GetCompatibility();
4944
}
5045

51-
public static bool HasSupport(IRocmPackageHelper? rocmPackageHelper)
46+
public static bool HasSupport(IRocmPackageHelper rocmPackageHelper)
5247
{
5348
return GetCompatibility(rocmPackageHelper).IsCompatible;
5449
}
5550

5651
public static bool ShouldApplyLaunchEnvironment(
57-
IRocmPackageHelper? rocmPackageHelper,
52+
IRocmPackageHelper rocmPackageHelper,
5853
TorchIndex selectedTorchIndex
5954
)
6055
{
@@ -67,19 +62,19 @@ TorchIndex selectedTorchIndex
6762
}
6863

6964
public static IReadOnlyDictionary<string, string> BuildLaunchEnvironment(
70-
IRocmPackageHelper? rocmPackageHelper
65+
IRocmPackageHelper rocmPackageHelper
7166
)
7267
{
73-
return rocmPackageHelper?.BuildLaunchEnvironment(Profile) ?? new Dictionary<string, string>();
68+
return rocmPackageHelper.BuildLaunchEnvironment(Profile);
7469
}
7570

7671
public static IReadOnlyList<string> GetLaunchNoticeLines(
77-
IRocmPackageHelper? rocmPackageHelper,
72+
IRocmPackageHelper rocmPackageHelper,
7873
TorchIndex selectedTorchIndex
7974
)
8075
{
8176
return ShouldApplyLaunchEnvironment(rocmPackageHelper, selectedTorchIndex)
82-
? rocmPackageHelper?.GetWindowsLaunchNoticeLines() ?? []
77+
? rocmPackageHelper.GetWindowsLaunchNoticeLines()
8378
: [];
8479
}
8580
}

StabilityMatrix.Core/Models/Rocm/ReforgeWindowsRocmProfile.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,18 @@ public static RocmPackageProfile CreateProfile(IEnumerable<string> requirementsF
4747
};
4848
}
4949

50-
public static RocmCompatibilityResult GetCompatibility(IRocmPackageHelper? rocmPackageHelper)
50+
public static RocmCompatibilityResult GetCompatibility(IRocmPackageHelper rocmPackageHelper)
5151
{
52-
if (rocmPackageHelper is null)
53-
{
54-
return new RocmCompatibilityResult { IsCompatible = false };
55-
}
56-
5752
return rocmPackageHelper.GetCompatibility();
5853
}
5954

60-
public static bool HasSupport(IRocmPackageHelper? rocmPackageHelper)
55+
public static bool HasSupport(IRocmPackageHelper rocmPackageHelper)
6156
{
6257
return GetCompatibility(rocmPackageHelper).IsCompatible;
6358
}
6459

6560
public static bool ShouldUseWindowsNativeInstall(
66-
IRocmPackageHelper? rocmPackageHelper,
61+
IRocmPackageHelper rocmPackageHelper,
6762
TorchIndex selectedTorchIndex
6863
)
6964
{
@@ -72,7 +67,7 @@ TorchIndex selectedTorchIndex
7267

7368
public static void ApplyWindowsRocmLaunchDefaults(
7469
List<LaunchOptionDefinition> launchOptions,
75-
IRocmPackageHelper? rocmPackageHelper
70+
IRocmPackageHelper rocmPackageHelper
7671
)
7772
{
7873
if (!(Compat.IsWindows && HasSupport(rocmPackageHelper)))
@@ -92,7 +87,7 @@ public static void ApplyWindowsRocmLaunchDefaults(
9287
}
9388
}
9489

95-
public static string? GetPreferredCrossAttentionArgument(IRocmPackageHelper? rocmPackageHelper)
90+
public static string? GetPreferredCrossAttentionArgument(IRocmPackageHelper rocmPackageHelper)
9691
{
9792
var compatibility = GetCompatibility(rocmPackageHelper);
9893
if (!compatibility.IsCompatible)
@@ -106,19 +101,19 @@ public static void ApplyWindowsRocmLaunchDefaults(
106101
}
107102

108103
public static IReadOnlyDictionary<string, string> BuildLaunchEnvironment(
109-
IRocmPackageHelper? rocmPackageHelper
104+
IRocmPackageHelper rocmPackageHelper
110105
)
111106
{
112-
return rocmPackageHelper?.BuildLaunchEnvironment(Profile) ?? new Dictionary<string, string>();
107+
return rocmPackageHelper.BuildLaunchEnvironment(Profile);
113108
}
114109

115110
public static IReadOnlyList<string> GetLaunchNoticeLines(
116-
IRocmPackageHelper? rocmPackageHelper,
111+
IRocmPackageHelper rocmPackageHelper,
117112
TorchIndex selectedTorchIndex
118113
)
119114
{
120115
return ShouldUseWindowsNativeInstall(rocmPackageHelper, selectedTorchIndex)
121-
? rocmPackageHelper?.GetWindowsLaunchNoticeLines() ?? []
116+
? rocmPackageHelper.GetWindowsLaunchNoticeLines()
122117
: [];
123118
}
124119
}

0 commit comments

Comments
 (0)