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).
-
You'll need a recent Python 3 version installed on your machine. In this guide I'm using Python version
3.10.2
. -
You'll also need a huggingface account as well as an API access key from the huggingface settings, to download the latest version of the Stable Diffusion model (1.4 as of writing this blog post).
-
Make sure
python
andpip
are defined in your PATH:
-
Open your Windows Terminal or cmd (as an administrator)
-
Go to Harish Anand's Diffusers repository, clone it into a folder you've created for this little project and pip install its contents. You'll also need ftfy and scipy, so pip install those as well:
- The trick that makes this work is to use the latest nightly build of Onnx. You can download it here. Make sure the downloaded version matches your python version. In my case I have to download the file
ort_nightly_directml-1.13.0.dev20220901005-cp310-cp310-win_amd64.whl
since I'm on python version 3.10.2. Once you've downloaded it to your project folder do a:
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.
- Now you have to generate a Onnx version of the Stable Diffusion model. To do so run
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
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
Enjoy, have fun, and subscribe to my YouTube channel if you've liked this guide and consider buying me a coffee.