Skip to content

Instantly share code, notes, and snippets.

@harishanand95
Last active July 29, 2023 20:08
Show Gist options
  • Save harishanand95/04131b47aa5a6d37bb5849c89e786360 to your computer and use it in GitHub Desktop.
Save harishanand95/04131b47aa5a6d37bb5849c89e786360 to your computer and use it in GitHub Desktop.
Stable Diffusion optimized for AMD RDNA2 GPUs using IREE->Vulkan

Stable Diffusion optimized for AMD RDNA2 GPUs using IREE->Vulkan

This guide is meant for developers who want to experiment with the IREE/MLIR toolchain to compile Vulkan code. A more streamlined installation procedure (that uses precompiled .vmfb files optimized for various GPUs) would be possible, but in the interest of time, we’re sharing here instructions meant for developers.

Install the latest AMD Drivers

AMD Software: Adrenalin Edition 22.11.1 for MLIR/IREE Driver Version 22.20.29.09 for Windows® 10 and Windows® 11 (Windows Driver Store Version 31.0.12029.9003)

https://www.amd.com/en/support/kb/release-notes/rn-rad-win-22-11-1-mril-iree

Setup Powershell to do the installation

On a powershell with admin privileges, do the command below:

set-executionpolicy remotesigned

Install Python 3.10 & Git

You’ll need Python 3.10, here’s one possible way to install it on Windows:

Install SHARK from nod.ai

On a new powershell window, run the commands below:

PS C:\Users\harish> git clone https://github.com/nod-ai/SHARK
PS C:\Users\harish> cd SHARK
PS C:\Users\harish\SHARK> .\setup_venv.ps1

The last command will show the detected Python version as 3.10 in the beginning.

Run the AMD Nod.AI Stable Diffusion demo (sample code)

On the same powershell, or on a new powershell, run the commands below:

PS C:\Users\harish\SHARK> ./shark.venv/Scripts/activate
(shark.venv) PS C:\Users\harish\SHARK> cd web
(shark.venv) PS C:\Users\harish\SHARK\web> python index.py

Access Stable Diffusion on http://localhost:8080

Command-Line Interface

PS C:\Users\harish\SHARK> ./shark.venv/Scripts/activate
(shark.venv) PS C:\Users\harish\SHARK> cd .\shark\examples\shark_inference\stable_diffusion\
(shark.venv) PS C:\Users\harish\SHARK\shark\examples\shark_inference\stable_diffusion> python main.py --precision="fp16" --device="vulkan" --no-import_mlir --prompt "A film still of lalaland, artwork by studio ghibli, makoto shinkai, pixv" --steps=50 --seed=123456

Image will be saved in SHARK\shark\examples\shark_inference\stable_diffusion folder.

Tips

  1. In windows, you will need paths to be short, so clone the repo in your root folder of a drive.
@KangbingZhao
Copy link

does it support the older vega GPUs?

@agret
Copy link

agret commented Mar 7, 2023

does it support the older vega GPUs?

There is a list of supported GPUs for MLIR/IREE on the release notes for the driver:

https://www.amd.com/en/support/kb/release-notes/rn-rad-win-22-11-1-mlir-iree

@Jonglastra
Copy link

Hi, at the step to Run the AMD Nod.AI Stable Diffusion demo, with the first line ./shark.venv/Scripts/activate, I got an error , it is said that ./shark.venv/Scripts/activate is not recognised as a command for the applet (cf attached file). Do you have any idea from where the problem comes from ?

error script

@Jonglastra
Copy link

Jonglastra commented Apr 9, 2023

Hi, at the step to Run the AMD Nod.AI Stable Diffusion demo, with the first line ./shark.venv/Scripts/activate, I got an error , it is said that ./shark.venv/Scripts/activate is not recognised as a command for the applet (cf attached file). Do you have any idea from where the problem comes from ?

error script

Coming back to the full installation, isn't it enougt to follow the instructions presented here ? https://www.youtube.com/watch?v=hvYSt4AUeJg ? In my case, unfortunately I have an error message like " <eval_with_key>.13:146:12," following this automatic installaiton.

Another point, I've seen in the discord of nod.ai that for rnda 2, we are supposed to change some parameters in windows (see below), are we supposed to do that or the installaiton changes these parameters automatically ?
In powershell set env flag $Env:AMD_ENABLE_LLPC=0
This is applicable for RDNA1 and RDNA2 users (basically 6000-series and below). LLPC=1 is only applicable for RDNA3
For win10 Go to properties on 'this pc' -> advanced system settings -> advanced tab -> environment variables
under system variables add New -> variable name should be AMD_ENABLE_LLPC and set variable value to "0" (zero).

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