pytorch
pytorch copied to clipboard
No CPU fallback?
Issue description
In our software, we install the ROCm enabled pytorch if we detect an AMD GPU on Linux. Otherwise, we install the CUDA-enabled pytorch. If the AMD GPU is not supported by ROCm, the users get an error hipErrorNoBinaryForGpu: Unable to find code object for all current devices!
.
Is there a way to fallback to CPU mode in the ROCm enabled pytorch?
Code example
>>> import torch
>>> torch.cuda.is_available()
"hipErrorNoBinaryForGpu: Unable to find code object for all current devices!"
Aborted (core dumped)
Maybe something like this?
import torch
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
if device.type == 'cuda':
try:
# Try to use ROCm-enabled PyTorch
model.to(device)
except RuntimeError as error:
if 'Unable to find code object for all current devices' in str(error):
# Fallback to CPU mode
device = torch.device('cpu')
else:
# Re-raise the error if it's not the one we expect
raise error
else:
# Use CPU mode
model.to(device)
Maybe something like this?
The problem is that torch.cuda.is_available()
already core dumps.