StabilityMatrix icon indicating copy to clipboard operation
StabilityMatrix copied to clipboard

Comprehensive ROCm helper for centralized Windows package integration and installation support

Open NeuralFault opened this issue 7 months ago • 11 comments

Introduces significant improvements to AMD GPU (ROCm) support and consolidates Windows ROCm support behind a shared helper and expands AMD GPU coverage across the current Windows-native ROCm path. The result is a more consistent install and launch flow for ROCm-capable packages, less duplicated package-specific logic, and broader support from Vega/GCN5 through the entire RDNA lineup. It also establishes the shared ROCm helper foundation that ComfyUI and Wan2GP now use directly, with the same model intended to be reused by other AMD/ROCm-capable packages going forward.

ROCm Support Integration and Refactoring:

  • Introduced the IRocmPackageHelper dependency to PackageFactory, ComfyUI, and Wan2GP, so ROCm compatibility checks, runtime/install context resolution, Windows-native package installation, and launch environment construction all flow through the same shared service instead of being reimplemented per package. This centralizes the Windows ROCm path and makes it easier to extend the same behavior to additional packages later. [1] [2] [3] [4] [5] [6] [7] [8]

  • Refactored the Windows ROCm path in ComfyUI around the shared helper and a package-owned WindowsRocmProfile, replacing hardcoded install/index handling with shared compatibility, install, and environment policy. This keeps the package-specific behavior limited to the pieces that actually need to remain package-specific while letting the helper own the common ROCm workflow. [1] [2] [3]

  • Updated ROCm support detection and launch environment injection to use the centralized helper throughout the package startup. This makes ROCm eligibility checks, EnVar defaults, and runtime-specific overrides consistent across packages, while still allowing package-owned extras such as ComfyUI-specific COMFYUI_ENABLE_MIOPEN. [1] [2] [3] This also fixes user-set EnVars in SM settings/Environment Variables not overriding the package configured EnVars due to immutability coded in comfyui.cs's original Windows-ROCm package specific handling. Environment Variable injection flow is as follows: Helper Defaults > Package config > User-set. So the user-set variables are added as last step pulling them from SettingsManager, before finally being set into the package's launch flow. Prioritizing user variables over any previously injected variable of the same key if the user wishes to disable or modify a default variable.

GPU Architecture and Compatibility Improvements:

  • Extended the AMD GPU architecture detection matrix in GpuInfo to cover a wider set of Vega/GCN5, RDNA1, RDNA2, RDNA3/3.5, related handheld/mobile variants, and adding handling support for R9600 RDNA4 Pro GPU that was previously absent. Improving Windows ROCm coverage across the supported lineup instead of limiting support to a narrower subset of cards, as TheRock ROCm Technical Preview PyTorch builds exist now for Vega dGPUs, RDNA1 dGPUs, and practically the entire RDNA2 family. From Vega 56 all the way to RX 9070/R9700. This still excludes Radeon Instinct Vega/CDNA HPC/Datacenter GPUs due no official driver support and/or needing custom hacked drivers for Windows. [1] [2]

  • Refactored ROCm compatibility checks in GpuInfo and HardwareHelper to use shared WindowsRocmSupport logic, removing duplicated support tables and consolidating both support detection and architecture-based policy decisions in one place as a single source of truth in the domain of the ROCm helper. Keeping GpuInfo and HardwareHelper specifically handling just GPU-name > gfxarch translation, and extracting of hardware information from the OS for the GPU installed on the user's system respectively. Simplifying further addition of future released GPU gfxarch translation, along with installation indexes and special environmental handling, to 2 dedicated files which can be updated and automatically apply globally to packages wired into the ROCm helper's call paths. [1] [2]

Other Installation and Launch Improvements:

  • Adjusted ComfyUI launch defaults to account for Windows ROCm architecture differences, including defaulting to legacy Windows ROCm GPUs to Quad Cross-Attention where that remains the better default. This keeps package launch behavior aligned with the shared architecture policy without hardcoding that policy in multiple places. [1] [2]

  • Updated package launch environment injection to use ROCm helper-generated variables and shared defaults, so ROCm-enabled installs consistently receive the expected runtime configuration on Windows while still leaving room for package-specific additions where needed. [1] [2] [3]


In Progress / Considerations for further development while still Draft PR status
  • [SD WebUI Reforge Implemented] Expand the shared Windows ROCm helper wiring into additional packages, particularly A3 WebUI and SDForge variants (Forge / reForge), so they can reuse the same compatibility checks, package selection, install flow, and launch environment defaults now used by ComfyUI and Wan2GP. Adding the expansive support provided by the ROCm helper to these most popular additional packages.
  • [Implemented] Improve SwarmUI Windows ROCm integration so the default ROCm launch environment is passed through when SwarmUI starts its self-launched ComfyUI backend, while also layering in user-set variables in SM Settings. This never happened previously, only user set variables were passed from SettingsManager, So variables that were hardcoded in original Win/ROCm handling in ComfyUI never got passed to the SwarmUI Comfy Self-Start backend leading to degraded performance unless the user specifically set them in SM Settings.
  • [Implemented] Evaluate adding Flash Attention 2 support for legacy-architecture installs through AMD AITER using custom builds by 0xDELUXA, either as a default path where stable enough or as an optional Package Command action. With consideration for gating to RDNA2 and older. (RDNA3+ gets its own FA2 via AOTriton which is enabled by default if using modern arch's)
  • [Implemented] Evaluate adding Sage Attention 1.0 as an optional Package Command install, including any required ops patching (sourced from ComfyUI-Zluda installation scripting needed for the Windows ROCm environment along with triton-windows. With potiential gating to RDNA2 and older. (AOTriton Flash Attn 2 in RDNA3+ is preferrable for modern arch's)
  • [ROCm runtime implemented by default] Consider defaulting Windows ROCm installs to the runtime-only ROCm module set rather than the full ROCm + SDK module set, with fuller SDK components installable later through Package Commands if needed. The full SDK stack modules add considerable footprint to the overall size of the venv, installing just the ROCm core runtime modules can be preferrable but needs testing to verify. Potentially making installation of the SDK modules optional if the user intends to compile/build modules needing it at any point.
  • [Implemented] Consider offering an optimized ROCm-aware bitsandbytes install path through the Package Command menu for packages and workflows that benefit from it. These would be prebuilt optimized wheels by 0xDELUXA that cover the entire Win-ROCm supported GPU lineup. Improves low quantization performance for GPUs that support it (needs verification of support variance)
Other future considerations
  • Refactoring and package integration for future Linux install support for passing the same default environment variables for better user experience and performance when using AMD GPUs in a Linux environment with Stability Matrix.
  • Expanding package integration to include other WebUI packages such as InvokeAI, AI Toolkit, Trainers, etc.
  • [Implemented] Refactor build index decision and handling to use new multi-arch url format from TheRock. Consolidating the ROCm/PyTorch installation URLs to a single universal index and have the gfxarch applied in the pip command for the current GPU.

NeuralFault avatar May 02 '26 22:05 NeuralFault

@gemini-code-assist recheck

NeuralFault avatar May 08 '26 01:05 NeuralFault

Thank you for the recheck request. I have reviewed the changes in this pull request, which introduces a centralized IRocmPackageHelper to streamline Windows ROCm support across multiple packages like ComfyUI, Wan2GP, and future integrations. The refactoring effectively consolidates compatibility checks, installation logic, and environment variable management, reducing code duplication and improving maintainability. The extension of the GPU architecture detection matrix to include RDNA4 and additional Vega/RDNA variants is a significant improvement for broad hardware support. The implementation appears robust and follows the established architectural patterns of the project. No further issues identified.

gemini-code-assist avatar May 08 '26 01:05 gemini-code-assist

Refactored installation path to use the new multi-arch index, simplifying the torch install handling to a single command which the gfxarch for the user's GPU is pulled and integrated into the command used from resolved gfxarch, installing PyTorch modules and ROCm runtime in one go. "torch[device-gfx###]" "torchvision[device-gfx###]" torchaudio --index-url https://rocm.nightlies.amd.com/whl-staging-multi-arch/

Centralized most of ComfyUI’s Windows ROCm handling into the shared helper domain to make launch environment variable generation and reuse more consistent, and to support env-var passthrough for ComfyUI self-launch backends in SwarmUI. That Swarm-side integration is intentionally gated behind the expected operating environment and Windows ROCm compatibility checks, and is limited to launch-time passthrough rather than expanding Swarm’s install behavior. As part of that, a shared Windows ROCm Comfy profile was extracted so direct ComfyUI launches and Swarm-managed self-launches follow the same ROCm-specific behavior.

Added global notice message sent to console output of Comfy and future integrated packages notifying user of experimental state of the Windows ROCm configuration and on issue reporting for triage so unnecessary issue reports get submitted upstream for if the issue has nothing to do with the WebUI package itself. (Used package install disclaimer instead for Wan2GP due to not being able to successfully getting it to show in console)

Added a temporary exclusion for gfx1152 and gfx1153 from the AOTriton experimental EnVar passing since those architectures are not currently supported just yet from upstream, and added post-install torch verification so helper-managed installs confirm that the resulting torch build actually reports usable ROCm metadata after installation.

Integration with the helper for reForge (and A3WebUI since it inherits a lot from it) was worked on and got functional, but required rather large dedicated functions for override and fallbacks due to missing modules in the 103x-all index and incompatibility with certain extension that comes with reforge, and setuptools issue. So rolled all that back and gave up on it for the time being but can more easily revisit it due to switching to the multi-arch install handling as this should alleviate a lot of the bloating of the helper and package configs I had previously when they were part of the implementation.

Tested and verified compatibility and function with both R9700 (RDNA4) and 6900XT (RDNA2). Could not test older generation due to not having my Vega 64 anymore, but the special handling for legacy GPUs are already in place.

Last thing is to look over the consideration of the other attention mechanism builds and acceleration library (bnb), along with possible option for the user to install the ROCm SDK devel module for if they need or wish to compile modules or extensions against their installed ROCm, in the package command menu before marking ready for review.

NeuralFault avatar May 08 '26 02:05 NeuralFault

@gemini-code-assist recheck

NeuralFault avatar May 10 '26 02:05 NeuralFault

Thank you for the update and for providing such a comprehensive overview of the refactoring and improvements. The consolidation of the Windows ROCm logic into IRocmPackageHelper and the introduction of the multi-arch index handling are significant steps forward for maintainability and broad hardware support. The addition of the experimental notice and the post-install verification steps are also excellent additions for robustness. Since you have verified compatibility with RDNA2 and RDNA4 and addressed the environment variable passthrough for SwarmUI, this looks very solid. I have no further concerns at this time.

gemini-code-assist avatar May 10 '26 02:05 gemini-code-assist

Would also like to note, and possibly good for changelog if merged and hits release, that PyTorch TunableOp is intentionally disabled by default. Any user who has a cache database for it and wishes to continue using it and compile further optimized GEMM kernels will need to add PYTORCH_TUNABLEOP_ENABLED with a value of 1 to their environment variables in SM settings.

NeuralFault avatar May 10 '26 02:05 NeuralFault

The full ReadyToRun build exposed a latent runner bug that blocked installation of the ROCm development SDK module for the SageAttention and ROCm SDK package commands when it was not already installed in the ComfyUI venv, because pip show “not found” results were being raised as exceptions instead of being treated as a missing package state (null).

This change to pyrunner/uvrunner should be safe for other calls as the other call sites for it handle null intentionally and don't assume a non-null result without checking.

NeuralFault avatar May 10 '26 23:05 NeuralFault

RocmPackageHelper.InstallWindowsNativePackageAsync duplicates most of BaseGitPackage.StandardPipInstallProcessAsync

Comparing the two methods, almost every step is the same code with renamed properties:

Step StandardPipInstallProcessAsync InstallWindowsNativePackageAsync
Upgrade pip+wheel ✅ ✅ identical
Requirements walk + RequirementsExcludePattern + PipOverrides ✅ ✅ identical
if (SkipTorchInstall) return; ✅ (extension point) —
Torch install GetTorchPipArgs(... RocmIndex) multi-arch URL + torch[device-gfxNNNN]
--upgrade / --force-reinstall / PipOverrides on torch args ✅ ✅ identical
Post-install args with PipOverrides ✅ ✅ identical

The only step that genuinely needs to be ROCm-specific is the torch install itself (plus the new VerifyWindowsNativeTorchInstallAsync tail).

Worth noting: the pre-PR ComfyUI flow already used the right hook for this — SkipTorchInstall = true:

// pre-PR ComfyUI.cs
var config = new PipInstallConfig
{
    RequirementsFilePaths = ["requirements.txt"],
    ExtraPipArgs = ["numpy<2"],
    SkipTorchInstall = true,
    PostInstallPipArgs = ["typing-extensions>=4.15.0"],
};
await StandardPipInstallProcessAsync(venvRunner, options, installedPackage, config, ...);
// then the ROCm-specific torch install inline

It would be cleaner to keep that pattern and have the helper own just the ROCm-specific pieces — something like:

// in RocmPackageHelper
public PipInstallConfig BuildWindowsPipInstallConfig(RocmPackageProfile profile);
public Task InstallWindowsRocmTorchAsync(IPyVenvRunner venvRunner, RocmPackageProfile profile, InstalledPackage pkg, ...);

// in ComfyUI.InstallPackage
var config = rocmPackageHelper.BuildWindowsPipInstallConfig(ComfyWindowsRocmProfile.Profile);
await StandardPipInstallProcessAsync(venvRunner, options, installedPackage, config, ...);
await rocmPackageHelper.InstallWindowsRocmTorchAsync(venvRunner, ComfyWindowsRocmProfile.Profile, installedPackage, ...);

The concern with the duplicate-pipeline approach is drift: any future improvement to StandardPipInstallProcessAsync (better error reporting, smarter requirements parsing, changes to how PipOverrides are applied, etc.) will silently skip the ROCm path, and divergence only surfaces when something breaks for non-ROCm users but works for ROCm or vice versa.

This pairs naturally with the RocmPackageProfile / PipInstallConfig field overlap noted elsewhere — if RocmPackageProfile composes a PipInstallConfig rather than mirroring its fields, BuildWindowsPipInstallConfig is roughly a one-liner.

mohnjiles avatar May 24 '26 00:05 mohnjiles

@gemini-code-assist recheck

NeuralFault avatar May 28 '26 23:05 NeuralFault

Hi @mohnjiles, thank you for the detailed feedback. You've correctly identified that RocmPackageHelper.InstallWindowsNativePackageAsync and BaseGitPackage.StandardPipInstallProcessAsync share a significant amount of logic, which does introduce a risk of drift.

I agree that refactoring to keep the StandardPipInstallProcessAsync as the primary driver while allowing the RocmPackageHelper to own only the ROCm-specific installation steps (like the multi-arch torch install and verification) is a cleaner, more maintainable approach. This aligns with the existing SkipTorchInstall = true pattern and would definitely reduce the maintenance burden for future updates to the pip process.

I will look into refactoring the helper to provide a BuildWindowsPipInstallConfig method and a dedicated InstallWindowsRocmTorchAsync method, allowing packages to compose their installation flow as you suggested. This should resolve the duplication concern while keeping the ROCm-specific logic encapsulated.

gemini-code-assist avatar May 28 '26 23:05 gemini-code-assist

Implementation is complete with the initial WebUI package support for ComfyUI, SD WebUI Reforge, InvokeAI, SwarmUI, and Wan2GP. Tested various GPU install configurations at install and launch time ensuring expected behavior for AMD GPU and Nvidia environments.

It is now in an intended state of general use and for future package support expansion.

Unless something else stands out that can be changed, ready for merge.

NeuralFault avatar May 28 '26 23:05 NeuralFault

@ionite34 The requested changes have been addressed. Let me know if there is anything further needed.

NeuralFault avatar Jun 02 '26 03:06 NeuralFault