PortPilot
Benchmark · pre-generated, always available← back to leaderboard
Migration Readiness Report

pytorch/examples

https://github.com/pytorch/examples
Ready to run on ROCm

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.

37Works as-is
0Mechanical change
0Manual blocker
Findings
37
Python files
93
Files scanned
238
Custom CUDA kernels
none

Detected but out of scope (not analyzed): C++, C/C++ header

Findings by file

37 findings · 12 files
distributed/ddp-tutorial-series/multigpu_torchrun.py· 1
A
torch.cuda API usage
torch.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).

distributed/ddp-tutorial-series/multigpu.py· 2
A
torch.cuda API usage
torch.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).

A
torch.cuda API usage
world_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).

distributed/ddp-tutorial-series/multinode.py· 1
A
torch.cuda API usage
torch.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).

distributed/FSDP/T5_training.py· 4
A
torch.cuda API usage
torch.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).

A
torch.cuda API usage
device_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).

A
torch.cuda API usage
format_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).

A
torch.cuda API usage
format_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).

distributed/FSDP/utils/environment.py· 1
A
torch.cuda API usage
and 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).

distributed/rpc/batch/parameter_server.py· 3
A
.cuda() tensor/module move
yield 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 move
m = 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 move
m = 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.

distributed/rpc/batch/reinforce.py· 4
A
.cuda() tensor/module move
self.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 move
probs = 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 move
probs = 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 move
rewards = 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.

distributed/rpc/pipeline/main.py· 2
A
Device 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.

A
Device 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.

imagenet/main.py· 11
A
Device 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.

A
Device 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.

A
torch.cuda API usage
torch.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 move
model.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 move
model.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.

A
Device 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 move
model.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 move
model = 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.

A
Device 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 move
images = 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 move
target = 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.

language_translation/main.py· 4
A
Device 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.

A
torch.cuda API usage
DEVICE = 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).

A
Device 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.

A
torch.cuda API usage
DEVICE = 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).

legacy/snli/train.py· 2
A
torch.cuda API usage
if 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).

A
torch.cuda API usage
torch.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).

mnist_hogwild/main.py· 2
A
torch.cuda API usage
use_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).

A
Device 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.