You are not logged in.

#1 2022-09-07 20:38:37

kendew
Member
Registered: 2016-11-09
Posts: 41

Stable Diffusion with AMD GPU and ROCm

Installed Stable Diffusion only to be disappointed I needed an Nvidia GPU.  Mine is AMD:

inxi -G -a
Graphics:
  Device-1: AMD Cezanne driver: amdgpu v: kernel
    arch: GCN-5.1 code: Vega-2 process: TSMC n7 (7nm)
    built: 2018-21 pcie: gen: 3 speed: 8 GT/s lanes: 16
    link-max: gen: 4 speed: 16 GT/s ports:
    active: HDMI-A-2 empty: DP-1,DP-2,HDMI-A-1
    bus-ID: 04:00.0 chip-ID: 1002:1638 class-ID: 0300
 ......
  OpenGL: renderer: AMD RENOIR (LLVM 14.0.6 DRM 3.47
    5.19.7-zen2-1-zen) v: 4.6 Mesa 22.1.7
    direct render: Yes 

The AUR has a version of Stable Diffusion for Intel but I see nothing for amdgpu at the moment.  A YouTube video offers instructions especially for Arch.  A stable-diffusion-radeon package exists on github with a pretty detailed installation guide in Japanese
All in all it looks like a pretty involved install that is going to bring loads of new packages to my SSD that make a minimalist like me cringe.   I'm trying to wrap my head around it because I'm fairly new to AMD hardware and the install involves docker and ROCm which I am not familiar with. 
I'll list my issues in the three categories below and anyone is more than welcome to comment on any of them.  It would really help me out.
1. ROCm.  From what I gather ROCm helps coordinate  AMD CPU with GPU.  So I wonder, irrespective of Stable Diffusion, is ROCm something I would want to set up anyway?  What would be the downside?  If so, is there a ROCm capable kernel already available I could just install and use when I needed Stable Diffusion, which likely wouldn't be too often.
2.  Has anyone had any success in getting Stable Diffusion up and running on AMD architecture?
3.  Anyone know whether an AUR package might be in the works that I could just wait for, like stable-diffusion-intel but for AMD GPU?

Looking forward to anyone's insights.

Offline

#2 2022-09-12 18:34:52

ketsapiwiq
Member
Registered: 2022-09-12
Posts: 1

Re: Stable Diffusion with AMD GPU and ROCm

Edit: after I wrote this I just checked your GPU model and I think it may not be recent enough.
---

Hi!
So I managed to make the text2image version working roughly following the method from this youtube video.

My way of making it work on an AMD RX 6700XT was as followed:
0. Because of that GPU I needed:

export HSA_OVERRIDE_GFX_VERSION=10.3.0

1. built the pip version of ROCm (in a venv) since conda cannot be used according to the official docs:

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/rocm5.1.1

2. Used this repo: https://github.com/lstein/stable-diffusion
3. Downloaded and copied the weights from Hugging Face:

ln -s ~/Downloads/sd-v1-4-full-ema.ckpt models/ldm/stable-diffusion-v1/model.ckpt

4. Run it with or without `--web`:

 export HSA_OVERRIDE_GFX_VERSION=10.3.0; python3 scripts/dream.py --model stable-diffusion-1.4 --web     

What I don't know about is this message:

MIOpen(HIP): Warning [SQLiteBase] Missing system database file: gfx1030_20.kdb Performance may degrade. Please follow instructions to install: https://github.com/ROCmSoftwarePlatform/MIOpen#installing-miopen-kernels-package

On Arch, I found these packages were probably related:
- miopen-hip
- rocm-hip-sdk and rocm-opencl-sdk, see instructions at: https://github.com/rocm-arch/rocm-arch
- hsa-amd-aqlprofile-bin
- rocm-opencl-runtime
Edit:
- python-pytorch-rocm seems cool

Links:
- https://www.youtube.com/watch?v=d_CgaHyA_n4
- https://rocmdocs.amd.com/en/latest/Deep … rning.html
- https://www.reddit.com/r/StableDiffusio … t/imp7bx2/
- https://github.com/RadeonOpenCompute/RO … 1160386571
- https://github.com/RadeonOpenCompute/RO … k-start.md
- https://github.com/lstein/stable-diffusion
- https://github.com/AshleyYakeley/stable-diffusion-rocm
- https://huggingface.co/CompVis/stable-d … 4-original
- https://community.amd.com/t5/knowledge- … a-p/489937
- https://github.com/rocm-arch/rocm-arch

Last edited by ketsapiwiq (2022-09-13 01:48:44)

Offline

#3 2022-11-20 21:19:27

dmfay
Member
Registered: 2018-11-30
Posts: 7

Re: Stable Diffusion with AMD GPU and ROCm

ketsapiwiq wrote:

1. built the pip version of ROCm (in a venv) since conda cannot be used according to the official docs:

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/rocm5.1.1

...

What I don't know about is this message:

MIOpen(HIP): Warning [SQLiteBase] Missing system database file: gfx1030_20.kdb Performance may degrade. Please follow instructions to install: https://github.com/ROCmSoftwarePlatform/MIOpen#installing-miopen-kernels-package

The performance databases (kdbs) aren't included in the pytorch wheel, cf https://github.com/ROCmSoftwarePlatform … ssues/1391

I'm not sure how much of a drag on performance it actually is. I tried figuring out CMake parameters to rebuild the wheel myself but haven't gotten anywhere with it.

Offline

Board footer

Powered by FluxBB