Advisory Summary — pytorch/examples (ROCm Readiness)
This repository is fully ROCm-ready with a 100/100 score: all 37 findings fall into Bucket A (works as-is), with zero mechanical changes or manual blockers identified. Because PyTorch's ROCm backend maps CUDA APIs transparently, these example scripts should run on AMD Instinct GPUs out of the box when launched with a ROCm-enabled PyTorch build. First step: install PyTorch for ROCm (pip install torch --index-url https://download.pytorch.org/whl/rocm6.2), set HSA_OVERRIDE_GFX_VERSION if needed for your specific Instinct SKU, and run any example directly — no code edits required. Verify GPU visibility with rocminfo and torch.cuda.is_available() before launching larger training jobs.
Detected but out of scope (not analyzed): C++, C/C++ header
Findings by file
37 findings · 12 filesAtorch.cuda API usagetorch.cuda.set_device(int(os.environ["LOCAL_RANK"])):14
torch.cuda.set_device is compatible with ROCm through PyTorch's HIP compatibility layer — the cuda namespace is aliased to hip at runtime, so this call works as-is on AMD Instinct GPUs. No source change is strictly required for functional correctness. If full namespace portability is desired, a conditional or device-agnostic wrapper could be introduced, but it is not necessary for standard PyTorch ROCm stacks.
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_device(rank):21
PyTorch on ROCm provides a compatibility layer that maps torch.cuda APIs to HIP devices, so this code will typically run unmodified. No direct source change is strictly required for ROCm, though device visibility can also be managed via the HIP_VISIBLE_DEVICES or CUDA_VISIBLE_DEVICES environment variables.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageworld_size = torch.cuda.device_count():103
torch.cuda.device_count() works as-is on ROCm because PyTorch's HIP layer exposes the torch.cuda namespace as a compatibility shim, so no functional change is required. However, for cross-vendor portability you may prefer a device-agnostic guard so the code degrades gracefully on non-CUDA/HIP builds.
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_device(int(os.environ["LOCAL_RANK"])):14
torch.cuda.set_device is supported on ROCm via PyTorch's CUDA-compatibility namespace, which maps to hipSetDevice under the hood, so this line will function as-is. No source change is required for correctness, though the call remains semantically tied to the CUDA namespace rather than a device-agnostic alternative.
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_device(local_rank):112
PyTorch's ROCm build provides a drop-in compatibility layer for the torch.cuda namespace, so torch.cuda.set_device works natively on AMD Instinct GPUs without code changes. Device visibility should instead be managed via the HIP_VISIBLE_DEVICES or ROCR_VISIBLE_DEVICES environment variables.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagedevice_id=torch.cuda.current_device(),:122
PyTorch's ROCm backend transparently maps the torch.cuda namespace to HIP, so torch.cuda.current_device() functions correctly without modification. While strict device-agnostic code might use torch.device('cuda') directly for FSDP initialization, this specific API call does not block ROCm migration.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageformat_metrics_to_gb(torch.cuda.memory_allocated()):167
PyTorch's ROCm implementation aliases the torch.cuda module to HIP, meaning torch.cuda.memory_allocated() works out-of-the-box on AMD Instinct GPUs without requiring manual intervention. This allows existing CUDA-based memory tracking logic to remain intact during migration. No code changes are necessary for this specific API call.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageformat_metrics_to_gb(torch.cuda.memory_reserved()):170
torch.cuda.memoryreserved() is CUDA-specific; on ROCm, the equivalent is torch.amd.memoryreserved(). PyTorch ROCm builds do alias torch.cuda for compatibility, but switching to torch.amd makes the ROCm dependency explicit and avoids confusion in 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 usageand torch.cuda.is_bf16_supported():23
torch.cuda.isbf16supported() is generally functional under ROCm because PyTorch aliases torch.cuda to the HIP runtime, but it is not guaranteed to reflect AMD Instinct capabilities correctly in all versions. For portability and clarity, guard the check with torch.version.hip or use a device-agnostic capability check.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
A.cuda() tensor/module moveyield inputs.cuda(), labels.cuda():84
The .cuda() calls hardcode the CUDA backend and reduce portability across ROCm/HIP environments. While PyTorch+ROCm maps .cuda() to HIP at runtime, the recommended migration is to use a configurable device (e.g., torch.device from an env/config) so the code is backend-agnostic and testable on AMD Instinct GPUs.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module movem = self.ps_rref.rpc_sync().get_model().cuda():88
The .cuda() call hardcodes the CUDA backend and should be replaced with a configurable device reference so the same code path works on AMD Instinct GPUs under ROCm. In PyTorch ROCm builds, the literal string "cuda" still maps to HIP devices, but parameterizing the device avoids backend-specific assumptions and improves portability.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module movem = rpc.rpc_sync(:93
The .cuda() call hardcodes an NVIDIA-specific device and should be replaced with a device-agnostic pattern. On ROCm, PyTorch maps .cuda() to HIP internally, but best practice is to use a configurable device string so the code is portable across CUDA and ROCm backends.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module moveself.policy = Policy(batch).cuda():124
The .cuda() call hardcodes the device to CUDA and should be replaced with a device-agnostic pattern for ROCm portability. On AMD Instinct GPUs, PyTorch ROCm builds map .cuda() to HIP internally, but using .to(device) with a configurable device variable is the recommended migration approach.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module moveprobs = self.policy(self.states.cuda()):163
The .cuda() call hardcodes an NVIDIA device, preventing portability to AMD Instinct GPUs. Replace it with a device-agnostic pattern (e.g., a device variable or self.states.to(self.device)) so the same code path works on ROCm. This is a Bucket A item: low-risk, mechanical replacement.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module moveprobs = self.policy(state.cuda()):178
The .cuda() call hardcodes the CUDA backend and will fail or behave unexpectedly on AMD Instinct GPUs under ROCm. Migrate to a device-agnostic pattern using a configurable device variable so the same code path works on both CUDA and ROCm runtimes.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module moverewards = torch.stack([ret[0] for ret in rets]).cuda().t():197
The .cuda() call hardcodes the CUDA device and will break or behave unexpectedly on ROCm unless the HIP compatibility layer is active. Best practice is to use a device-agnostic pattern such as .to(device) where device is resolved at runtime, making the code portable across CUDA and ROCm backends.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"args = ("cuda:0",) + args,:154
PyTorch on ROCm maps "cuda:0" to the first AMD Instinct device, so this may work as-is, but hardcoding the string reduces portability across CUDA and ROCm environments. Advisory: replace with a configurable device string (e.g., derived from torch.cuda.is_available() or an env var) so the code is backend-agnostic.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"args = ("cuda:1",) + args,:162
The hardcoded device string "cuda:1" should be reviewed for ROCm migration. On PyTorch ROCm builds, "cuda" device strings are typically remapped to HIP internally, so this may work as-is, but for explicit clarity and portability it is advisable to use a ROCm-aware device string.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"if device.type =='cuda'::118
PyTorch on ROCm still reports device.type as 'cuda' because HIP reuses the CUDA namespace, so this check will functionally work on AMD Instinct GPUs without modification. However, for code clarity and future portability across CUDA and ROCm backends, an explicit comment or a portable helper is advisable.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"if device.type == 'cuda'::173
On ROCm, PyTorch's HIP backend typically still reports device.type as 'cuda' due to namespace compatibility, so this check may work as-is. However, for explicit ROCm portability and clarity, the check should also handle 'hip' device type or use a union check to avoid silent failures if the device string changes.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usagetorch.cuda.set_device(args.gpu):175
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).
A.cuda() tensor/module movemodel.cuda(device):176
.cuda() on tensors and modules is honoured by ROCm PyTorch and moves data to the AMD GPU. No change needed.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module movemodel.cuda():184
.cuda() on tensors and modules is honoured by ROCm PyTorch and moves data to the AMD GPU. No change needed.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"elif device.type == 'cuda'::188
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.
A.cuda() tensor/module movemodel.cuda():192
.cuda() on tensors and modules is honoured by ROCm PyTorch and moves data to the AMD GPU. No change needed.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module movemodel = torch.nn.DataParallel(model).cuda():194
.cuda() on tensors and modules is honoured by ROCm PyTorch and moves data to the AMD GPU. No change needed.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"if args.gpu is not None and device.type=='cuda'::374
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.
A.cuda() tensor/module moveimages = images.cuda(args.gpu, non_blocking=True):376
.cuda() on tensors and modules is honoured by ROCm PyTorch and moves data to the AMD GPU. No change needed.
RecommendNo change required on ROCm PyTorch.
A.cuda() tensor/module movetarget = target.cuda(args.gpu, non_blocking=True):377
.cuda() on tensors and modules is honoured by ROCm PyTorch and moves data to the AMD GPU. No change needed.
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu"):14
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 usageDEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu"):14
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"DEVICE = torch.device("cuda" if args.backend == "gpu" and torch.cuda.is_available() else "cpu"):301
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 usageDEVICE = torch.device("cuda" if args.backend == "gpu" and torch.cuda.is_available() else "cpu"):301
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()::17
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_device(args.gpu):18
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 usageuse_cuda = args.cuda and torch.cuda.is_available():61
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"device = torch.device("cuda"):64
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.