September 1, 2022 • Josip Ledić • 0 min

How to use Stable Diffusion on Windows 10 with an AMD GPU

If you're on a unix-based system, this guide won't work for you, search for "SD AMD ROCm" guide instead. No ROCm does not work in combination with Windows Subsystem for Linux, at least I didn't get it to run with my AMD GPU.

Watch my guide on YouTube instead:

Dependencies & Preparation

Before starting make sure you have a decent AMD GPU, at least something like an RX480 with 8GB of VRAM or else you'll run out of memory pretty often or it may not even work at all (you'll just get gray pictures as outputs).

> python --version
Python 3.10.2
git clone https://github.com/harishanand95/diffusers.git
cd diffusers && git checkout dml && pip install -e .
pip install transformers ftfy scipy
pip install ort_nightly_directml-1.13.0.dev20220901005-cp310-cp310-win_amd64.whl

Make sure you're not using the "dot slash" (pip install ./ort_...) relative path syntax here as this is a common mistake that prevents the pip install command from finding the local file because Windows has issues with forward slashes.

cd ./diffusers/examples/inference
huggingface-cli login

and paste in your huggingface API token when prompted for it.

If this step fails, you probably didn't accept the terms and conditions of the Stable Diffusion model yet so head over to the model and do so before retrying the step above. Then run the ./save_onnx.py script

python ./save_onnx.py

Usage

There's the file called dml_onnx.py that can be used to generate your images. You can use as a reference or edit it according to your needs. At the bottom you can change the actual prompt, the seed, the output filename, the no. of steps, the guidance scale and so on.

If you want to change the default image resolution make sure that the widths and heights you choose can be divided by 8 and follow the instructions at the bottom of the dml_onnx.py file, such as re-generating a Onnx model for that new resolution.

Here's an example image that took roughly 2:30min to create on my AMD Vega 56

Created with Stable Diffusion on Win10 with an AMD GPU

Enjoy, have fun, and subscribe to my YouTube channel if you've liked this guide and consider buying me a coffee.