AMD radeon not working with pytorch

I installed PyTorch for AMD ROCm™ using this
pip3 install torch torchvision torchaudio --extra-index-url

and ran a simple code
import os
import torch
os.environ[“CUDA_VISIBLE_DEVICES”]=“0,1” # ‘0’ is the NVIDIA GPU card, ‘1’ is AMD radeon GPU
t1 = torch.zeros(2,3, device=‘cuda:1’)

But got this error
RuntimeError: Unexpected error from hipGetDeviceCount(). Did you run some cuda functions before calling NumHipDevices() that might have already set an error? Error 101: hipErrorInvalidDevice

Could you help?

Here’s a guide I wrote: AMD, ROCM, PyTorch, and AI on Ubuntu: The Rules of the Jungle | by Jordan H (Principal, Damn Good Tech) #openforwork | Feb, 2023 | Medium

If you experience anything hip-related, then you usually need to set the HSA_OVERRIDE_GFX_VERSION flag.