Post

Installing Stable Diffusion web UI on AMD Radeon RX 5500M

This tutorial has been tested on AMD RX 5500M gpu and is working properly.

Prerequisites

  • Linux distro: Arch
  • Hardware
    • AMD Radeon RX 5500M or any Navi 14 based GPU
  • Lots of patience!
  • AUR package manager: yay, paru etc.

Installing Software

1. ROCm libraries and dependencies

NOTE: This installation is gonna take a lot of time

1
  yay -S rocm-hip-sdk rocm-opencl-sdk rocminfo rocm-smi-lib

Replace yay with your favorite AUR package manager

  • ROCm HIP: A Langauge similar to CUDA by Nvidia.
  • ROCm OpenCL: Useful for enchacing run time on cpu based models like (GGFU/GGML)
  • rocminfo: To verify if ROCm is working.
  • rocm-smi: An efficient way of looking at GPU statistics

Failed to install? run the following command below

1
  HSA_OVERRIDE_GFX_VERSION=10.3.0 yay -S rocm-hip-sdk rocm-opencl-sdk rocminfo rocm-smi-lib

This makes the installation compatible to gfx1030 which for some reason also works on our device1

1.1 Add few environment variables

Add these two in your .bashrc or .zshrc

1
2
export HSA_OVERRIDE_GFX_VERSION=10.3.0
PATH=$PATH:/opt/rocm/bin

2. Verify ROCm installation

1
  /opt/rocm/bin/rocminfo

This should output some long information like the below output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  ROCk module is loaded
  =====================
  HSA System Attributes
  =====================
  Runtime Version:         1.1
  System Timestamp Freq.:  1000.000000MHz
  Sig. Max Wait Duration:  18446744073709551615 (0xFFFFFFFFFFFFFFFF) (timestamp count)
  Machine Model:           LARGE
  System Endianness:       LITTLE

  ========== HSA Agents
  ==========

  ....


  *******
  Agent 2
  *******
    Name:                    gfx1012
    Uuid:                    GPU-XX
    Marketing Name:          AMD Radeon RX 5500M
    Vendor Name:             AMD
    Feature:                 KERNEL_DISPATCH
    Profile:                 BASE_PROFILE
    Float Round Mode:        NEAR

  ...

If you found something like this with your GPU name correctly displayed, then ROCm is installed!

3. Installing PyTorch

First, check if your cpu supports AVX22.

1
grep avx2 /proc/cpuinfo

If there is no output then your CPU doesn’t support AVX2, so skip the next step.

Install Optimized AVX2 Pytorch

1
pacman -S python-pytorch-opt-rocm

Install for normal PyTorch (For non AVX2 CPUs)

1
pacman -S python-pytorch-rocm

Install torch vision

1
yay -S python-torchvision-rocm

4. Verify PyTorch installation

1
python -c 'import torch; print(torch.__version__)'

If this command fails then you would need to reinstall PyTorch again (Follow the previous step).

5. Installing Stable Diffusion UI

Clone the repo

1
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

Setup venv

Copy-pasta’d from Stable diffusion webui wiki

1
2
3
python -m venv venv --system-site-packages
source venv/bin/activate
pip install -r requirements.txt

Run the UI

1
2
source venv/bin/activate
./webui.sh --precision full --no-half --upcast-sampling --opt-sub-quad-attention --lowvram --disable-nan-check

The above command is a result of me fixing multiple errors which I’ve faced on my Radeon RX 5500M, feel free to experiment it yourself.

Place your safetensors in models/Stable-diffusion/

Results!

img1 img2 img3

Model used: ZHMix-Dramatic

Note: All of these images are generated and I have no rights or licenses over these images

Hip out of memory error
GPU Specs
RX Series information
Software support list

References

This post is licensed under CC BY 4.0 by the author.