AUTOMATIC1111/stable-diffusion-webui
https://github.com/AUTOMATIC1111/stable-diffusion-webui ↗This repo is essentially ROCm-ready — 43 findings work as-is, zero manual blockers exist, and only 3 mechanical fixes remain, yielding a 97/100 readiness score. The path to running on AMD Instinct is short: address the 3 bucket-B items (likely CUDA API renames, device-string assumptions, or torch.cuda references that need PyTorch's device-agnostic equivalents), then launch with HSA_OVERRIDE_GFX_VERSION set appropriately for your Instinct variant. No architectural rework is required. Start by reviewing the three mechanical findings and applying the corresponding one-line or small-patch fixes before your first test run.
Detected but out of scope (not analyzed): JavaScript
Findings by file
46 findings · 12 filesBxFormers dependencyimport xformers:126
xFormers is a CUDA-centric attention library that may not build or run correctly on ROCm; its CUDA kernels and memory optimizations are NVIDIA-specific. On AMD Instinct GPUs, you should guard or replace this import with a ROCm-compatible alternative such as FlashAttention-ROCm or PyTorch's native scaleddotproduct_attention.
RecommendPrefer torch SDPA; use a ROCm xFormers build where required.
--- modules/errors.py+++ modules/errors.py@@ -126,1 +126,8 @@-import xformers+try:+ import xformers+except Exception:+ # Advisory: xFormers may be unavailable or non-functional on ROCm.+ # Consider using torch.nn.functional.scaled_dot_product_attention+ # or a ROCm-compatible FlashAttention build as an alternative.+ xformers = NoneAtorch.cuda API usagereturn shared.cmd_opts.force_enable_xformers or (shared.xformers_available and torch.cuda.is_available() and (6, 0) <= torch.cuda.get_device_capability(shared.device) <= (9, 0)):57
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagereturn 1000 if shared.device.type != 'mps' and not torch.cuda.is_available() else 10:127
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
BxFormers dependencyimport xformers.ops:160
xFormers is not supported on ROCm/AMD Instinct GPUs and will fail to import or run correctly. The import should be made conditional with a fallback to native PyTorch attention (e.g., F.scaled_dot_product_attention) so the code path remains functional on AMD hardware.
RecommendPrefer torch SDPA; use a ROCm xFormers build where required.
--- modules/sd_hijack_optimizations.py+++ modules/sd_hijack_optimizations.py@@ -160,1 +160,5 @@-import xformers.ops+try:+ import xformers.ops+except ImportError:+ xformers = None+ xformers.ops = NoneADevice string "cuda"if shared.device.type == 'cuda'::167
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usagestats = torch.cuda.memory_stats(shared.device):168
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagemem_free_cuda, _ = torch.cuda.mem_get_info(torch.cuda.current_device()):171
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagestats = torch.cuda.memory_stats(q.device):338
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagemem_free_cuda, _ = torch.cuda.mem_get_info(q.device):341
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
ADevice string "cuda"if q.device.type == 'cuda'::349
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
BxFormers dependencyimport xformers:1187
xFormers is heavily optimized for NVIDIA hardware and lacks official, stable support on AMD ROCm, which can cause import errors or crashes on Instinct GPUs. It is recommended to make this import optional or replace xFormers usage with PyTorch 2.0+ native scaled dot product attention (SDPA) for ROCm compatibility.
RecommendPrefer torch SDPA; use a ROCm xFormers build where required.
- import xformers+ try:+ import xformers+ except ImportError:+ xformers = NoneAtorch.cuda API usageif torch.cuda.is_available()::863
torch.cuda.is_available() works as-is on PyTorch ROCm builds because the torch.cuda namespace is retained for source compatibility, returning True when a HIP GPU is present. No change is strictly required, but an optional HIP-aware guard can make the ROCm path explicit and aid debugging on mixed environments.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usages = torch.cuda.mem_get_info():864
PyTorch on ROCm maintains the torch.cuda namespace as a compatibility alias, so torch.cuda.mem_get_info() works as-is on AMD Instinct GPUs and returns (free, total) bytes for the HIP device. No code change is required for functional equivalence, though you may optionally pass an explicit device index for clarity.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usages = dict(torch.cuda.memory_stats(shared.device)):866
torch.cuda.memory_stats is supported on ROCm through PyTorch's HIP compatibility layer, so this call will function as-is on AMD Instinct GPUs. No code change is strictly required, though if broader portability is desired you could guard the device type or use a conditional namespace alias. This is a low-risk, bucket-A advisory item.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetorch.cuda.get_device_capability(device_id) == (7, 5):30
torch.cuda.getdevicecapability is available under ROCm's CUDA-compat layer, but the hardcoded (7, 5) check targets NVIDIA Turing and will never match AMD Instinct GPUs (e.g., gfx90a/gfx942). This likely gates a code path (e.g., fp16/bf16 or attention variant selection) that should instead branch on ROCm/HIP architecture or torch.version.hip.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageand torch.cuda.get_device_name(device_id).startswith("NVIDIA GeForce GTX 16"):31
torch.cuda.getdevicename is accessible on ROCm via HIP compatibility, but the NVIDIA-specific string check will always return False on AMD Instinct GPUs, silently skipping whatever GTX 16xx workaround this gates. If that workaround has an AMD analog (e.g., a similar architecture-specific path), the predicate should be made vendor-aware; otherwise the dead branch is harmless but misleading.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usage) or torch.cuda.current_device():40
torch.cuda.current_device() is compatible with PyTorch's ROCm/HIP backend, which reuses the torch.cuda namespace, so this call works on AMD Instinct GPUs without modification. No code change is strictly required, but if device-agnostic portability is desired, consider routing through a helper that checks torch.version.hip. This is advisory only and not an auto-fix.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
ADevice string "cuda"return "cuda":47
Returning a hardcoded "cuda" device string will break on ROCm unless PyTorch was built with the CUDA-compatibility layer (most ROCm PyTorch builds still accept "cuda" as the device name). If this string is used for non-PyTorch logic or display, it should be made ROCm-aware to avoid confusion or misrouting.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usageif torch.cuda.is_available()::51
torch.cuda.is_available() is compatible with ROCm because PyTorch's HIP backend exposes the torch.cuda namespace, returning True when HIP devices are present. No source change is required for functional correctness on AMD Instinct GPUs. If explicit ROCm detection is desired, you could additionally check torch.version.hip, but it is not mandatory.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageif torch.cuda.is_available()::79
On ROCm, PyTorch maintains CUDA API compatibility via HIP, so torch.cuda.is_available() typically returns True on AMD Instinct GPUs and often works unchanged. For long-term portability, you may prefer a HIP-aware guard, but no change is strictly required for functional correctness.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagewith torch.cuda.device(get_cuda_device_string())::80
PyTorch on ROCm retains the torch.cuda namespace for source compatibility, so torch.cuda.device generally works as-is on AMD Instinct. No code change is strictly required, but verify the device string resolves correctly under HIP and that context manager semantics behave as expected.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetorch.cuda.empty_cache():81
torch.cuda.empty_cache() is supported on ROCm via PyTorch's CUDA-compatibility namespace, which maps to HIP under the hood, so no functional change is required. However, be aware that cache behavior and memory management semantics may differ slightly between NVIDIA and AMD GPUs, so verify memory usage patterns on Instinct hardware.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetorch.cuda.ipc_collect():82
torch.cuda.ipc_collect() is a CUDA IPC handle garbage-collection call with no direct ROCm/HIP equivalent exposed in PyTorch's public API. PyTorch's ROCm build maps the torch.cuda namespace to HIP internally, so this call may be a no-op or unsupported depending on the ROCm version; it should be guarded to avoid runtime errors on AMD Instinct GPUs.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageif torch.cuda.is_available()::102
torch.cuda.is_available() is compatible with ROCm because PyTorch for HIP exposes the torch.cuda namespace as a compatibility shim, so this check will correctly detect AMD Instinct GPUs. No functional change is strictly required, but the call remains semantically CUDA-specific and may confuse maintainers during migration.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
ADevice string "cuda"return torch.autocast("cuda"):231
On ROCm, PyTorch's HIP backend still accepts "cuda" as the device_type string for torch.autocast, so this line is functionally compatible. However, hardcoding the string reduces portability; using a shared device variable makes the codebase easier to maintain across CUDA and ROCm targets.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"return torch.autocast("cuda", enabled=False) if torch.is_autocast_enabled() and not disable else contextlib.nullcontext():235
torch.autocast("cuda", ...) is compatible with ROCm because PyTorch's HIP backend maps the "cuda" device type to AMD GPUs, so no functional change is strictly required. However, hardcoding "cuda" reduces portability across backends; using a device-type variable is a common defensive pattern in ROCm migrations.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usagescaler = torch.cuda.amp.GradScaler():568
torch.cuda.amp.GradScaler is deprecated in newer PyTorch and the recommended replacement is torch.amp.GradScaler('cuda'), which works on ROCm since PyTorch/HIP exposes the 'cuda' device type. On ROCm this generally functions as-is, but migrating to the new API avoids deprecation warnings and is forward-compatible.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageif torch.cuda.is_available()::685
torch.cuda.is_available() is compatible with ROCm because PyTorch's HIP build maps the torch.cuda namespace to HIP/ROCm at runtime, so this check will correctly return True on AMD Instinct GPUs. No source change is required for functional correctness, though a fully portable codebase could eventually use a device-agnostic availability check. This is advisory only and not an auto-fix.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagecuda_rng_state = torch.cuda.get_rng_state_all():686
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageif torch.cuda.is_available()::723
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetorch.cuda.set_rng_state_all(cuda_rng_state):724
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetorch.cuda.memory_stats(self.device):27
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageindex = self.device.index if self.device.index is not None else torch.cuda.current_device():33
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagereturn torch.cuda.mem_get_info(index):34
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetorch.cuda.reset_peak_memory_stats():43
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetm = torch.cuda.memory_stats(self.device):64
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageprint(torch.cuda.memory_summary()):70
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagetorch_stats = torch.cuda.memory_stats(self.device):81
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
ADevice string "cuda"@torch.autocast("cuda", dtype=torch.float16):151
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"@torch.autocast("cuda", dtype=torch.float16):364
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"@torch.autocast("cuda", dtype=torch.float16):368
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usageif version.parse(torch.__version__) <= version.parse("1.13.2") or torch.cuda.is_available()::130
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
ADevice string "cuda"loaded_model.load_state_dict(torch.load(model_path, map_location='cpu' if devices.device.type != 'cuda' else None)):62
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"torch.load(decoder_path, map_location='cpu' if devices.device.type != 'cuda' else None)):70
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"torch.load(encoder_path, map_location='cpu' if devices.device.type != 'cuda' else None)):86
The literal device string "cuda" resolves to the active AMD GPU on ROCm PyTorch. .to("cuda") / device="cuda" need no edits.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usagescaler = torch.cuda.amp.GradScaler():493
Calls under torch.cuda.* are aliased by ROCm builds of PyTorch. The same code runs on AMD Instinct GPUs unchanged — torch.cuda.is_available(), streams, events and AMP all map onto HIP.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).