This is a short guide on how to setup ROCm on Ubuntu. The most important step is that when we install PyTorch we get the latest available ROCm version for it.
- Python 3.10 or newer
- Ubuntu
- Make sure you have the appropriate kernel version, see prerequesites.
Select the desired amdgpu version and download the correct Ubuntu version, replace <version>
and <codename>
. Check the available versions first https://repo.radeon.com/amdgpu-install/
.
sudo apt update
wget https://repo.radeon.com/amdgpu-install/<version>/ubuntu/<codename>/amdgpu-install_22.20.50201-1_all.deb
sudo apt-get install ./amdgpu-install_22.20.50201-1_all.deb
Add the ROCm repository to sources, replace <release>
, check available versions https://repo.radeon.com/rocm/apt/
echo 'deb [arch=amd64] https://repo.radeon.com/rocm/apt/<release> ubuntu main' | sudo tee /etc/apt/sources.list.d/rocm.list
sudo apt update
Install the package `
apt apt-get install rocm-llvm<release>
In the case that the above command fails, you should edit the package, check the first answer from stackoverflow
Install OpenMP
sudo apt install libomp-dev
sudo amdgpu-install --rocmrelease=<release> --usecase=rocm,hip --no-dkms
Create groups and add your user to it
sudo usermod -a -G render $LOGNAME
sudo usermod -a -G video $LOGNAME
Reboot and after that check that ROCm is installed properly with command rocminfo
When installing torch, first check the latest supported ROCm version for torch, by visiting this url https://download.pytorch.org/whl/torch/
and searching for rocm
. At the time of the writing the latest version was 5.7
When you find the latest version install the Python dependencies
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/rocm<version>
After the dependencies have been installed you should run this small script to verify that everything is OK.
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(torch.cuda.current_device()))
The script should output True
and your GPU name.