The ultralytics/yolov5 repo is nearly ROCm-ready at 94/100, with 43 findings passing as-is and zero mechanical edits required — meaning the bulk of the codebase is already compatible with AMD Instinct GPUs. The remaining gap is concentrated in 3 manual blockers (Bucket C) that must be resolved before the code will run end-to-end on ROCm. Your first action should be to triage those three blockers — likely involving CUDA-specific kernel paths, custom autograd functions, or build/compile assumptions — and assess whether each can be replaced with a PyTorch-native or HIP equivalent. Until those are addressed, the repo will not produce correct results on ROCm despite its high readiness score.
Findings by file
46 findings · 13 filesAtorch.cuda API usagecuda = torch.cuda.is_available():366
On ROCm, PyTorch exposes the HIP backend through the torch.cuda namespace, so torch.cuda.is_available() returns True when HIP is active and generally works without changes. For explicit ROCm awareness, you can additionally check torch.version.hip to distinguish AMD GPU availability from NVIDIA CUDA.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
CTensorRT dependencyimport tensorrt as trt:619
TensorRT is an NVIDIA-only inference optimization library with no ROCm equivalent; on AMD Instinct GPUs the closest alternative is MIGraphX or ONNX Runtime with the ROCm execution provider. This import will fail on ROCm systems and must be replaced or conditionally guarded depending on the target platform.
RecommendRe-implement the inference path on AMD MIGraphX or ORT-ROCm.
--- export.py+++ export.py@@ -616,7 +616,11 @@ # NVIDIA TensorRT import — not available on ROCm-import tensorrt as trt+try:+ import tensorrt as trt+ HAS_TRT = True+except ImportError:+ trt = None+ HAS_TRT = False+ # On ROCm, consider migraphx or onnxruntime with ROCm EP as alternativesCTensorRT dependencyimport tensorrt as trt:623
TensorRT is NVIDIA-specific and has no ROCm equivalent at the same API level; on AMD Instinct GPUs the closest alternative is MIGraphX or ONNX Runtime with the ROCm execution provider. This import will fail on ROCm systems and the surrounding export/inference path must be ported or conditionally guarded.
RecommendRe-implement the inference path on AMD MIGraphX or ORT-ROCm.
--- export.py+++ export.py@@ -623,1 +623,8 @@-import tensorrt as trt+try:+ import tensorrt as trt+ _HAS_TENSORRT = True+except ImportError:+ trt = None+ _HAS_TENSORRT = False+ # Advisory: on ROCm, consider migraphx or onnxruntime with ROCm EP+ # as a replacement for TensorRT inference optimization.Atorch.cuda API usagecheck_requirements(f"tensorflow{'' if torch.cuda.is_available() else '-macos' if MACOS else '-cpu'}<=2.15.1"):740
On ROCm, torch.cuda.is_available() returns True for AMD Instinct GPUs via PyTorch's CUDA-compatibility layer, so the branch logic still executes; however, the resulting tensorflow (GPU) package targets NVIDIA CUDA and will not use ROCm. For AMD GPUs you should prefer tensorflow-cpu or a ROCm-enabled TensorFlow build rather than the CUDA default.
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 = torch.cuda.is_available() and device.type != "cpu" # use CUDA:480
On ROCm, PyTorch's HIP build aliases torch.cuda APIs so torch.cuda.is_available() returns true when a HIP device is present, but relying on the CUDA namespace reduces portability and clarity. Prefer a device-agnostic check or torch.version.hip to make ROCm intent explicit.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
CTensorRT dependencyimport tensorrt as trt # https://developer.nvidia.com/nvidia-tensorrt-download:534
TensorRT is an NVIDIA-only inference optimization library with no ROCm equivalent; importing it unconditionally will fail on AMD Instinct systems. This import should be guarded behind a try/except or a runtime backend check so the module remains importable on ROCm. For equivalent functionality on AMD, consider ONNX Runtime with the ROCm EP or MIGraphX.
RecommendRe-implement the inference path on AMD MIGraphX or ORT-ROCm.
--- models/common.py+++ models/common.py@@ -531,7 +531,11 @@ -import tensorrt as trt # https://developer.nvidia.com/nvidia-tensorrt-download+try:+ import tensorrt as trt # https://developer.nvidia.com/nvidia-tensorrt-download+except ImportError:+ trt = None # Not available on ROCm; consider MIGraphX or ONNX Runtime ROCm EPADevice string "cuda"device = torch.device("cuda:0"):538
Hardcoding "cuda:0" ties the code to CUDA-specific device naming. On ROCm PyTorch builds, "cuda" device strings often still work via the HIP compatibility layer, but for portability and clarity the device should be resolved dynamically (e.g., via torch.device("cuda" if torch.cuda.is_available() else "cpu"), or a configurable device string).
RecommendNo change required on ROCm PyTorch.
ADevice string "cuda"if "cuda" in device.type::106
Hardcoding a check for the substring "cuda" in device.type will fail to recognize AMD Instinct GPUs, whose device type is typically "hip" (or "cuda" only when using the CUDA-on-HIP shim). This control-flow branch may be silently skipped on ROCm, leading to wrong device selection or skipped GPU paths.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usagemem = "%.3gG" % (torch.cuda.memory_reserved() / 1e9 if torch.cuda.is_available() else 0) # (GB):242
On ROCm, PyTorch exposes the torch.cuda namespace via HIP compatibility, so torch.cuda.isavailable() and torch.cuda.memoryreserved() function without source changes. No migration action is required, though you could optionally use device-agnostic APIs for long-term portability.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageassert torch.cuda.device_count() > LOCAL_RANK, "insufficient CUDA devices for DDP command":357
torch.cuda.device_count() is supported on ROCm via PyTorch's CUDA-compatibility shim and will return the number of AMD Instinct GPUs, so no functional change is required. The only advisory change is cosmetic: the assertion message references 'CUDA devices', which could be made vendor-neutral for clarity in a mixed-environment codebase.
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):358
torch.cuda.setdevice() is transparently mapped by PyTorch's HIP layer on ROCm, so this call will function on AMD Instinct GPUs without modification. However, for cleaner portability and to avoid relying on the cuda namespace aliasing, consider using LOCALRANK with a device-agnostic pattern or setting HIPVISIBLEDEVICES/ROCRVISIBLEDEVICES before process launch.
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", LOCAL_RANK):359
PyTorch ROCm builds accept the "cuda" device string via HIP compatibility, so this line may work unchanged. However, for portability across NVIDIA and AMD backends, prefer a runtime-resolved device string so the same code runs on either platform without hardcoding.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usageif cuda and RANK == -1 and torch.cuda.device_count() > 1::237
torch.cuda.device_count() is supported on ROCm through PyTorch's HIP compatibility layer and will return the number of AMD Instinct GPUs. No code change is strictly required, though the torch.cuda namespace remains CUDA-specific in naming.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usagescaler = torch.cuda.amp.GradScaler(enabled=amp):325
torch.cuda.amp.GradScaler generally functions on ROCm because PyTorch maps the cuda namespace to HIP, but it is deprecated in newer PyTorch in favor of the device-agnostic torch.amp API. Migrating to torch.amp.GradScaler('cuda') improves portability and forward-compatibility across CUDA and ROCm backends.
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 = f"{torch.cuda.memory_reserved() / 1e9 if torch.cuda.is_available() else 0:.3g}G" # (GB):410
torch.cuda.memoryreserved() and torch.cuda.isavailable() are nominally functional on ROCm via PyTorch's HIP mapping, but hardcoding the CUDA namespace reduces portability across backends. For a device-agnostic memory report, prefer torch.cuda still works on ROCm, but wrap with a backend check or use a utility that abstracts the accelerator.
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():541
PyTorch's ROCm backend provides a compatibility layer that maps torch.cuda APIs to the underlying HIP runtime, so this call works natively without requiring code changes. It will correctly trigger the HIP caching allocator to release unused memory. No migration action is needed.
RecommendNo change required. Install the ROCm build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/rocm6.1).
Atorch.cuda API usageassert torch.cuda.device_count() > LOCAL_RANK, "insufficient CUDA devices for DDP command":639
torch.cuda.device_count() is functionally compatible on ROCm because PyTorch maps the torch.cuda namespace to HIP devices, so no code change is required for correctness. The only advisory change is to make the assertion message vendor-neutral, since it currently says 'CUDA devices' which is misleading 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 usagetorch.cuda.set_device(LOCAL_RANK):640
PyTorch's ROCm build exposes the torch.cuda namespace as a HIP compatibility shim, so torch.cuda.set_device works as-is on AMD Instinct GPUs with no functional change required. This is low-risk for migration; the only consideration is that the CUDA_VISIBLE_DEVICES env var (rather than ROCR_VISIBLE_DEVICES) still governs device visibility under this shim.
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", LOCAL_RANK):641
PyTorch on ROCm retains the "cuda" device-string for source compatibility, so this line will function as-is on AMD Instinct GPUs. However, hardcoding "cuda" obscures portability; making the backend configurable via an environment variable is the recommended advisory change.
RecommendNo change required on ROCm PyTorch.
Atorch.cuda API usageopt.half = torch.cuda.is_available() and opt.device != "cpu" # FP16 for fastest results:449
On ROCm, torch.cuda.is_available() typically returns True via the CUDA compatibility layer, so this line often works unchanged. For a more explicit/portable migration, you can gate on torch.version.hip or use a device-agnostic availability check to avoid implying NVIDIA-only CUDA.
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 cuda and RANK == -1 and torch.cuda.device_count() > 1::275
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 usagescaler = torch.cuda.amp.GradScaler(enabled=amp):358
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 = f"{torch.cuda.memory_reserved() / 1e9 if torch.cuda.is_available() else 0:.3g}G" # (GB):440
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.empty_cache():543
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 usageassert torch.cuda.device_count() > LOCAL_RANK, "insufficient CUDA devices for DDP command":680
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(LOCAL_RANK):681
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", LOCAL_RANK):682
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 usageproperties = torch.cuda.get_device_properties(device) # device properties:41
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 usager = torch.cuda.memory_reserved(device) / gb # GiB reserved: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 usagea = torch.cuda.memory_allocated(device) / gb # GiB allocated:44
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 usagend = torch.cuda.device_count() # number of CUDA devices:199
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 usagend = torch.cuda.device_count():1208
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"self.cuda = bool(device and str(device).startswith("cuda")):198
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 usagetorch.cuda.synchronize(self.device):213
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.manual_seed(seed):245
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.manual_seed_all(seed) # for Multi-GPU, exception safe:246
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 usagend = torch.cuda.device_count() # number of CUDA devices:66
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"return torch.amp.autocast("cuda", enabled=enabled):67
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 usagereturn torch.cuda.amp.autocast(enabled):69
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 usageassert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(",", "")), (:117
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 not cpu and not mps and torch.cuda.is_available(): # prefer GPU if available:121
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 usagep = torch.cuda.get_device_properties(i):128
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"arg = "cuda:0":130
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 usagemem = torch.cuda.memory_reserved() / 1e9 if torch.cuda.is_available() else 0 # (GB):186
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.empty_cache():194
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 usageopt.half = torch.cuda.is_available() and opt.device != "cpu" # FP16 for fastest results:502
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).