Skip to content

Instantly share code, notes, and snippets.

@jurgonaut
Last active July 16, 2024 02:52
Show Gist options
  • Save jurgonaut/462a6bd9b87ed085fa0fe6c893536993 to your computer and use it in GitHub Desktop.
Save jurgonaut/462a6bd9b87ed085fa0fe6c893536993 to your computer and use it in GitHub Desktop.
Install AMD GPU ROCm and PyTorch on Ubuntu

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.

Prerequisites

  • Python 3.10 or newer
  • Ubuntu
  • Make sure you have the appropriate kernel version, see prerequesites.

Amdgpu

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

ROCm repository

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

Install ROCm

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

Install PyTorch

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment