Skip to content

Commit 257fed3

Browse files
committed
refactor: Convert windows package ROCm profiles to instance-based polymorphic classes
- replace static *WindowsRocmProfile wrappers with concrete subclasses of RocmPackageProfile - introduce Default singleton instances for Comfy, InvokeAI, reForge, and Wan2GP profile classes - remove all remaining .Profile static call sites and switch package flows to profile instances - add virtual hooks to RocmPackageProfile for package-specific launch defaults and cross-attention selection - migrate reForge ROCm launch customization to profile overrides (ApplyWindowsRocmLaunchDefaults, GetPreferredCrossAttentionArgument) - keep install-time dynamic profile factories (CreateProfile, CreateInstallProfile) for per-package/per-python install config - preserve helper-centric ROCm orchestration by continuing to route env/install decisions through IRocmPackageHelper
1 parent 21b6732 commit 257fed3

10 files changed

Lines changed: 64 additions & 39 deletions

StabilityMatrix.Core/Models/Packages/ComfyUI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public override async Task InstallPackage(
422422

423423
if (Compat.IsWindows && torchIndex == TorchIndex.Rocm && HasWindowsRocmSupport())
424424
{
425-
var config = rocmPackageHelper.BuildWindowsNativeInstallConfig(ComfyWindowsRocmProfile.Profile);
425+
var config = rocmPackageHelper.BuildWindowsNativeInstallConfig(ComfyWindowsRocmProfile.Default);
426426

427427
await StandardPipInstallProcessAsync(
428428
venvRunner,
@@ -439,7 +439,7 @@ await rocmPackageHelper
439439
.InstallWindowsNativeTorchAsync(
440440
venvRunner,
441441
installedPackage,
442-
ComfyWindowsRocmProfile.Profile,
442+
ComfyWindowsRocmProfile.Default,
443443
progress,
444444
onConsoleOutput,
445445
cancellationToken
@@ -1189,7 +1189,7 @@ InstalledPackage installedPackage
11891189
if (!Compat.IsWindows || !hasRocmGpu || selectedTorchIndex != TorchIndex.Rocm)
11901190
return env;
11911191

1192-
var rocmEnvironment = rocmPackageHelper.BuildLaunchEnvironment(ComfyWindowsRocmProfile.Profile);
1192+
var rocmEnvironment = rocmPackageHelper.BuildLaunchEnvironment(ComfyWindowsRocmProfile.Default);
11931193

11941194
return env.SetItems(rocmEnvironment);
11951195
}

StabilityMatrix.Core/Models/Packages/InvokeAI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ InstalledPackage installedPackage
667667
return env;
668668
}
669669

670-
return env.SetItems(rocmPackageHelper.BuildLaunchEnvironment(InvokeAiWindowsRocmProfile.Profile));
670+
return env.SetItems(rocmPackageHelper.BuildLaunchEnvironment(InvokeAiWindowsRocmProfile.Default));
671671
}
672672

673673
private IReadOnlyList<string> GetLaunchNoticeLines(InstalledPackage installedPackage)

StabilityMatrix.Core/Models/Packages/Reforge.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,18 @@ public override List<LaunchOptionDefinition> LaunchOptions
5858
// Adjust inherited launch defaults for the Windows ROCm path before inserting reForge-specific options.
5959
// Makes the reForge-specific attention options visible in the UI and leaves them unset by default
6060
// for non-Windows-ROCm installs so reForge can keep using its normal internal attention selection.
61-
ReforgeWindowsRocmProfile.ApplyWindowsRocmLaunchDefaults(baseLaunchOptions, rocmPackageHelper);
61+
ReforgeWindowsRocmProfile.Default.ApplyWindowsRocmLaunchDefaults(
62+
baseLaunchOptions,
63+
rocmPackageHelper
64+
);
6265

6366
baseLaunchOptions.Insert(
6467
extrasIndex >= 0 ? extrasIndex : baseLaunchOptions.Count,
6568
new LaunchOptionDefinition
6669
{
6770
Name = "Cross Attention Method",
6871
Type = LaunchOptionType.Bool,
69-
InitialValue = ReforgeWindowsRocmProfile.GetPreferredCrossAttentionArgument(
72+
InitialValue = ReforgeWindowsRocmProfile.Default.GetPreferredCrossAttentionArgument(
7073
rocmPackageHelper
7174
),
7275
Options = ["--attention-split", "--attention-quad", "--attention-pytorch"],
@@ -167,7 +170,7 @@ InstalledPackage installedPackage
167170
return env;
168171
}
169172

170-
return env.SetItems(rocmPackageHelper.BuildLaunchEnvironment(ReforgeWindowsRocmProfile.Profile));
173+
return env.SetItems(rocmPackageHelper.BuildLaunchEnvironment(ReforgeWindowsRocmProfile.Default));
171174
}
172175

173176
protected override IReadOnlyList<string> GetLaunchNoticeLines(InstalledPackage installedPackage)

StabilityMatrix.Core/Models/Packages/StableSwarm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ x.PackageName is nameof(ComfyUI) or "ComfyUI-Zluda"
591591
return new Dictionary<string, string>();
592592
}
593593

594-
return rocmPackageHelper.BuildLaunchEnvironment(ComfyWindowsRocmProfile.Profile);
594+
return rocmPackageHelper.BuildLaunchEnvironment(ComfyWindowsRocmProfile.Default);
595595
}
596596

597597
/// <summary>

StabilityMatrix.Core/Models/Packages/Wan2GP.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ CancellationToken cancellationToken
383383
{
384384
if (Compat.IsWindows)
385385
{
386-
var config = rocmPackageHelper.BuildWindowsNativeInstallConfig(Wan2GpWindowsRocmProfile.Profile);
386+
var config = rocmPackageHelper.BuildWindowsNativeInstallConfig(Wan2GpWindowsRocmProfile.Default);
387387

388388
await StandardPipInstallProcessAsync(
389389
venvRunner,
@@ -400,7 +400,7 @@ await rocmPackageHelper
400400
.InstallWindowsNativeTorchAsync(
401401
venvRunner,
402402
installedPackage,
403-
Wan2GpWindowsRocmProfile.Profile,
403+
Wan2GpWindowsRocmProfile.Default,
404404
progress,
405405
onConsoleOutput,
406406
cancellationToken
@@ -446,7 +446,7 @@ await SetupVenv(installLocation, pythonVersion: PyVersion.Parse(installedPackage
446446

447447
if (Compat.IsWindows && selectedTorchIndex == TorchIndex.Rocm && HasWindowsRocmSupport())
448448
{
449-
var rocmEnvironment = rocmPackageHelper.BuildLaunchEnvironment(Wan2GpWindowsRocmProfile.Profile);
449+
var rocmEnvironment = rocmPackageHelper.BuildLaunchEnvironment(Wan2GpWindowsRocmProfile.Default);
450450
VenvRunner.UpdateEnvironmentVariables(env => env.SetItems(rocmEnvironment));
451451
}
452452

StabilityMatrix.Core/Models/Rocm/ComfyWindowsRocmProfile.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@ namespace StabilityMatrix.Core.Models.Rocm;
55
/// <summary>
66
/// Shared Windows ROCm profile for Comfy backends launched either directly by Stability Matrix or indirectly via SwarmUI.
77
/// </summary>
8-
public static class ComfyWindowsRocmProfile
8+
public class ComfyWindowsRocmProfile : RocmPackageProfile
99
{
10-
public static RocmPackageProfile Profile { get; } =
11-
new()
10+
public ComfyWindowsRocmProfile()
11+
{
12+
InstallConfig = new PipInstallConfig
1213
{
13-
InstallConfig = new PipInstallConfig
14-
{
15-
RequirementsFilePaths = ["requirements.txt"],
16-
ExtraPipArgs = ["numpy<2"],
17-
PostInstallPipArgs = ["typing-extensions>=4.15.0"],
18-
UpgradePackages = true,
19-
},
20-
ExtraEnvironmentFactory = BuildEnvironment,
14+
RequirementsFilePaths = ["requirements.txt"],
15+
ExtraPipArgs = ["numpy<2"],
16+
PostInstallPipArgs = ["typing-extensions>=4.15.0"],
17+
UpgradePackages = true,
2118
};
2219

23-
private static IReadOnlyDictionary<string, string> BuildEnvironment(RocmRuntimeContext runtimeContext)
20+
ExtraEnvironmentFactory = BuildEnvironment;
21+
}
22+
23+
private IReadOnlyDictionary<string, string> BuildEnvironment(RocmRuntimeContext runtimeContext)
2424
{
2525
return WindowsRocmSupport.IsModernArchitecture(runtimeContext.RuntimeGfxArch)
2626
? new Dictionary<string, string> { ["COMFYUI_ENABLE_MIOPEN"] = "1" }
2727
: new Dictionary<string, string>();
2828
}
29+
30+
public static RocmPackageProfile Default { get; } = new ComfyWindowsRocmProfile();
2931
}

StabilityMatrix.Core/Models/Rocm/InvokeAiWindowsRocmProfile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace StabilityMatrix.Core.Models.Rocm;
66
/// <summary>
77
/// Shared Windows ROCm profile for InvokeAI.
88
/// </summary>
9-
public static class InvokeAiWindowsRocmProfile
9+
public class InvokeAiWindowsRocmProfile : RocmPackageProfile
1010
{
11-
public static RocmPackageProfile Profile { get; } = new();
11+
public static RocmPackageProfile Default { get; } = new InvokeAiWindowsRocmProfile();
1212

1313
//Restores flop counter functionality requiring triton module
1414
private const string TritonWindowsPackage = "triton-windows";

StabilityMatrix.Core/Models/Rocm/ReforgeWindowsRocmProfile.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using StabilityMatrix.Core.Helper;
2-
using StabilityMatrix.Core.Models;
32
using StabilityMatrix.Core.Models.Packages;
43
using StabilityMatrix.Core.Services.Rocm;
54

@@ -8,14 +7,14 @@ namespace StabilityMatrix.Core.Models.Rocm;
87
/// <summary>
98
/// Shared Windows ROCm profile for reForge.
109
/// </summary>
11-
public static class ReforgeWindowsRocmProfile
10+
public class ReforgeWindowsRocmProfile : RocmPackageProfile
1211
{
1312
// reForge currently pins accelerate 0.21.0, but 0.22.0 avoids the early distributed.torch import that breaks on Windows ROCm torch builds
1413
// caused by the marigold depth controlnet preprocessor
1514
public const string WindowsRocmAccelerateVersion = "0.22.0";
1615
private static readonly string[] DisabledCudaLaunchOptionNames = ["CUDA Malloc", "CUDA Stream"];
1716

18-
public static RocmPackageProfile Profile { get; } = CreateProfile([]);
17+
public static ReforgeWindowsRocmProfile Default { get; } = new ReforgeWindowsRocmProfile();
1918

2019
public static RocmPackageProfile CreateProfile(IEnumerable<string> requirementsFilePaths)
2120
{
@@ -47,7 +46,7 @@ public static RocmPackageProfile CreateProfile(IEnumerable<string> requirementsF
4746
};
4847
}
4948

50-
public static void ApplyWindowsRocmLaunchDefaults(
49+
public override void ApplyWindowsRocmLaunchDefaults(
5150
List<LaunchOptionDefinition> launchOptions,
5251
IRocmPackageHelper rocmPackageHelper
5352
)
@@ -69,7 +68,7 @@ IRocmPackageHelper rocmPackageHelper
6968
}
7069
}
7170

72-
public static string? GetPreferredCrossAttentionArgument(IRocmPackageHelper rocmPackageHelper)
71+
public override string? GetPreferredCrossAttentionArgument(IRocmPackageHelper rocmPackageHelper)
7372
{
7473
var compatibility = rocmPackageHelper.GetCompatibility();
7574
if (!compatibility.IsCompatible)

StabilityMatrix.Core/Models/Rocm/RocmPackageProfile.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using StabilityMatrix.Core.Models.Packages;
22
using StabilityMatrix.Core.Models.Progress;
3+
using StabilityMatrix.Core.Services.Rocm;
34

45
namespace StabilityMatrix.Core.Models.Rocm;
56

@@ -26,4 +27,23 @@ public Func<
2627
/// Controls whether package-specific environment variables should be layered on top of helper defaults.
2728
/// </summary>
2829
public RocmEnvironmentOptions EnvironmentOptions { get; init; } = new();
30+
31+
/// <summary>
32+
/// Allows a package profile to adjust default launch options for Windows ROCm.
33+
/// Default implementation is a no-op; profiles that need package-specific adjustments
34+
/// should override this method.
35+
/// </summary>
36+
public virtual void ApplyWindowsRocmLaunchDefaults(
37+
List<LaunchOptionDefinition> launchOptions,
38+
IRocmPackageHelper rocmPackageHelper
39+
) { }
40+
41+
/// <summary>
42+
/// Returns a package-specific preferred cross-attention argument for Windows ROCm launches.
43+
/// Default implementation returns <c>null</c> indicating no preference.
44+
/// </summary>
45+
public virtual string? GetPreferredCrossAttentionArgument(IRocmPackageHelper rocmPackageHelper)
46+
{
47+
return null;
48+
}
2949
}

StabilityMatrix.Core/Models/Rocm/Wan2GpWindowsRocmProfile.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ namespace StabilityMatrix.Core.Models.Rocm;
55
/// <summary>
66
/// Shared Windows ROCm profile for Wan2GP.
77
/// </summary>
8-
public static class Wan2GpWindowsRocmProfile
8+
public class Wan2GpWindowsRocmProfile : RocmPackageProfile
99
{
10-
public static RocmPackageProfile Profile { get; } =
11-
new()
10+
public Wan2GpWindowsRocmProfile()
11+
{
12+
InstallConfig = new PipInstallConfig
1213
{
13-
InstallConfig = new PipInstallConfig
14-
{
15-
RequirementsFilePaths = ["requirements.txt"],
16-
UpgradePackages = true,
17-
PostTorchInstallPipArgs = ["hf-xet", "setuptools<70.0.0", "numpy==1.26.4"],
18-
},
14+
RequirementsFilePaths = ["requirements.txt"],
15+
UpgradePackages = true,
16+
PostTorchInstallPipArgs = ["hf-xet", "setuptools<70.0.0", "numpy==1.26.4"],
1917
};
18+
}
19+
20+
public static RocmPackageProfile Default { get; } = new Wan2GpWindowsRocmProfile();
2021
}

0 commit comments

Comments
 (0)