pytorch icon indicating copy to clipboard operation
pytorch copied to clipboard

No CPU fallback?

Open JeLuF opened this issue 1 year ago • 2 comments

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)

JeLuF avatar May 04 '23 18:05 JeLuF

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)

YellowRoseCx avatar May 06 '23 20:05 YellowRoseCx

Maybe something like this?

The problem is that torch.cuda.is_available() already core dumps.

JeLuF avatar May 07 '23 07:05 JeLuF