The reason why older AMD cards don't work out of the box with Stable Diffusion is that AMD dropped official support for Polaris architecture cards (aka gfx803) in ROCm (CUDA equivalent for AMD). Since official ROCm distribution ships without this support enabled, other software using ROCm in backend such as PyTorch disable it as well by default. This is why even if you install the official ROCm-enabled PyTorch package it still won't detect your GPU. However it is possible to enable that support back by compiling the necessary software yourself.
I'll be using ROCm 5.1.3, PyTorch 1.13.0 and Torchvision 0.14.0 with Python 3.10 in this guide.
Keep in mind that steps below may differ if you use different versions (especially ROCm, since most fixes deal with ROCm packaging on Gentoo).
Ubuntu users should look at https://github.com/xuhuisheng/rocm-gfx803
Arch users should look at https://rentry.org/sdamd
Read the Gentoo wiki for more info: https://wiki.gentoo.org/wiki/ROCm
First we need ROCm libraries compiled for
gfx803 target. On Gentoo it's as easy as enabling the right use flag.
Create a file in
/etc/portage/package.use with the following content:
This will enable Polaris architecture and disable all other architectures to save on compilation time.
Now install all the required ROCm-related packages:
rocminfo to confirm ROCm is working, your card should be listed as
cd into a directory where you want to store Stable Diffusion Webgui, then run:
Now we need to apply a couple of fixes to successfully build PyTorch:
Finally build and install PyTorch:
Pay attention to CMake summary, make double sure the following items are there:
USE_CUDA : OFF
USE_ROCM : ON
USE_NUMPY : ON
The above options are required for Stable Diffusion to work.
If you don't get the right output then you will need to make additional changes to CMake files, scroll above summary and look for related warnings and errors.
If ROCm is not detected, the likely culprit is
cmake/public/LoadHIP.cmake. When applying changes pass the
--cmake option to
setup.py build to force CMake rerun.
Next is Torchvision, the process is similar:
Hopefully the build finishes without any erros.
Above should be enough to make Stable Diffusion work with your Polaris card.
Lastly i would advice to remove lines containing
requirements_versions.txt to ensure that setup script won't overwrite our manually compiled libraries.
You can now continue with the main guide to download, setup and test the model.
To monitor your GPU (temps, fans, VRAM usage etc.) you can use radeontop or rocm-smi:
ROCm requires PCI 3.0, make sure your card is connected to PCI 3.0 slot and not PCI 2.0.