What you’ll need
Because xformers speeds things up a lot, you can get even better performance with the triton
addon… This is ONLY available on Linux.
Windows users, don’t fear, you can still get this. Just install Ubuntu, or another Linux distribution under WSL (Windows Subsystem for Linux). Once you have it up and running head back to this tutorial!
A lot of this article is based on, and improves upon @vladmandic’s discussion on the AUTOMATIC1111 Discussions page.
Preparing your system for Automatic1111’s Stable Diffusion WebUI
Windows
Before we even get to installing A1’s SDUI, we need to prepare Windows. This guide only focuses on Nvidia GPU users.
Make sure you have Nvidia CUDA 11.8 installed, as well as the latest cuDNN.
To install the latest cuDNN, download the zip
from Nvidia cuDNN (Note: you will need an Nvidia account to do so, as far as I can remember).
Open it with your favourite zip explorer, like 7-zip, and extract all the folders inside (Just open, don’t navigate around) into C:\Program FIles\NVIDIA GPU Computing Toolkit\CUDA\v11.8
. Your path may be different. You will be copying the bin
, include
and lib
folders. If told about duplicates, just click Replace.
I would also recommend using the latest Studio Drivers from Nvidia.
WSL (Ubuntu)
Setting up CUDA on WSL
CUDA is installed on Windows, but WSL needs a few steps as well. Following the Getting Started with CUDA on WSL from Nvidia, run the following commands.
This needs to match the CUDA installed on your computer. In my case, it’s 11.8.
To get updated commands assuming you’re running a different CUDA version, see Nvidia CUDA Toolkit Archive.
|
|
Now for cuDNN:
|
|
Preparing the environment
Following modified installation steps, based on the original, run the following commands.
Install Anaconda (conda)
|
|
Then download the Automatic1111 repo
|
|
If you have previously installed triton
, make sure to uninstall it with pip uninstall triton
. If you don’t have Python, don’t worry.
Now, instead of running conda env create -f environment-wsl2.yaml
as the guide suggests, instead edit that file. Either head across there in Windows, assuming you’ve used cd /mnt/c/users/tcno/desktop
, for example, to get to your desktop… Or just use nano: nano environment-wsl2.yaml
.
Remove the cudatoolkit
, pytorch
and torchvision
lines. We will install these later. We just need to create and activate the environment for now.
Mine appears as follows:
|
|
Now, install all the requirements using the command:
|
|
As suggested by the console, run:
|
|
Now that we’re in the right environment, we will install the latest version of Pytorch nightly (version 2.0+).
Run the command to install them. This will download roughly 2GB+:
|
|
Running pip show torch
should return something along the lines of Version: 2.0.0.dev20230125+cu118
. This is perfect.
Accelerate
Run:
|
|
You will need to edit requirements_versions.txt
as well to reflect accelerate==0.15.0
. Do note that you may need to delete this file to git pull
and update Automatic1111’s SDUI, otherwise just run git stash
and then git pull
. Just remember to change the accelerate version to match.
Xformers
This important package can do wonders to your image generation speeds. Make sure you install this, if you can and your computer is happy with it. You can always uninstall it later.
Because of how Facebook has this set up, you can download older versions, but you will get much better speed still by building and installing it yourself. As scary as that sounds, you’re already here and it’s just a few more simple commands.
There are 2 ways of doing this… Then, the official way uses Conda
, as suggested on the xformers GitHub page, and the second official way is building it yourself… here are both (Windows can only do the second, but WSL should be able to do the first as well).
Pick one:
|
|
or
|
|
Also, if you’re on Linux or WSL, install Triton:
|
|
This will take some time to put itself together, so be patient. We’re talking many minutes.
Running AUTOMATIC1111’s Stable Diffusion Web UI in WSL
You will need to edit the webui-user.sh
file to get the best results.
I have the following as the entire file (By default everything is commented out here).
|
|
I have further adjusted the COMMANDLINE_ARGS
option to get better performance on my PC (And my PC does some funky things when the VRAM fills up for some reason…)
|
|
Speaking of, I also need to add torch.backends.cudnn.enabled = False
just after import torch
in webui.py for it to work on my wonky Windows install…
Starting A1’s SDUI
To start A1’s SDUI, run:
|
|
And that’s it. All of your settings from webui-user.sh
will be brought in. I added the activate line just to make sure if you remember any commands, it should be these to restart A1’s SDUI after a WSL restart, or PC restart.
Fixing issues with Dreambooth
Dreambooth works, at least mostly… As mentioned previously I’m having strange things happen with my GPU under Windows and WSL, so I’m not able to test this fully. I assume a Windows reinstall is nessecary…
To fix the TypeError: '<' not supported between instances of 'str' and 'Version'
error for Dreambooth in A1’s SDUI, before it’s updated to work with Torch 2.0, open .
The full error is:
File "/root/anaconda3/envs/automatic/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 207, in <module>
if torch.__version__ < version.Version("1.12"):
TypeError: '<' not supported between instances of 'str' and 'Version'
So, sudo nano /root/anaconda3/envs/automatic/lib/python3.10/site-packages/diffusers/utils/import_utils.py
.
Skipping to line 207 (Hit Ctrl+/
and enter 207
), I’ll simply make it look as such:
I’ll simply comment out the lines, as such:
|
|
Ctrl+S
and Ctrl+X
to save and close.
Optimization
Now, let’s make it even better.
Head across to the discussion linked Here and continue your journey.
Why leave it here? Well, things will change from here. This is still experimental, and following the steps provided in this discussion should take you further.
At this point you’re up to the Optimize section.