Xformers - linwownil/stable-diffusion-webui GitHub Wiki
Xformers
Xformers library is an optional way to speedup your image generation.
This optimization is only available for nvidia gpus, it speeds up image generation and lowers vram usage at the cost of producing non-deterministic results.
Note: Both Windows and linux should no longer need to build. On 1/23/23 webui shifted from a user-built wheel to an official wheel along with other package upgrades, shown in this PR
If you use a Pascal, Turing, Ampere, Lovelace or Hopper card with Python 3.10, launch the repo with --xformers
and a compatible wheel will be installed.
@duckness
Building xformers on Windows by- Install VS Build Tools 2022, you only need
Desktop development with C++
- Install CUDA 11.3 (later versions are not tested), select custom, you only need the following (VS integration is probably unecessary):
- Clone the xFormers repo, create a
venv
and activate it
git clone https://github.com/facebookresearch/xformers.git
cd xformers
git submodule update --init --recursive
python -m venv venv
./venv/scripts/activate
- To avoid issues with getting the CPU version, install pyTorch seperately:
pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113
- Then install the rest of the dependencies:
pip install -r requirements.txt
pip install wheel
-
As CUDA 11.3 is rather old, you need to force enable it to be built on MS Build Tools 2022. Do
$env:NVCC_FLAGS = "-allow-unsupported-compiler"
if onpowershell
, orset NVCC_FLAGS=-allow-unsupported-compiler
if oncmd
-
You can finally build xFormers, note that the build will take a long time (probably 10-20minutes), it may initially complain of some errors but it should still compile correctly.
OPTIONAL tip: To further speed up on multi-core CPU Windows systems, install ninja https://github.com/ninja-build/ninja. Steps to install:
- download ninja-win.zip from https://github.com/ninja-build/ninja/releases and unzip
- place ninja.exe under C:\Windows OR add the full path to the extracted ninja.exe into system PATH
- Run ninja -h in cmd and verify if you see a help message printed
- Run the follow commands to start building. It should automatically use Ninja, no extra config is needed. You should see significantly higher CPU usage (40%+).
python setup.py build python setup.py bdist_wheel
This has reduced build time on a windows PC with a AMD 5800X CPU from 1.5hr to 10min. Ninja is also supported on Linux and MacOS but I do not have these OS to test thus can not provide step-by-step tutorial.
- Run the following:
python setup.py build
python setup.py bdist_wheel
-
In
xformers
directory, navigate to thedist
folder and copy the.whl
file to the base directory ofstable-diffusion-webui
-
In
stable-diffusion-webui
directory, install the.whl
, change the name of the file in the command below if the name is different:
./venv/scripts/activate
pip install xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl
- Ensure that
xformers
is activated by launchingstable-diffusion-webui
with--force-enable-xformers
Building xformers on Linux (from anonymous user)
- go to the webui directory
source ./venv/bin/activate
cd repositories
git clone https://github.com/facebookresearch/xformers.git
cd xformers
git submodule update --init --recursive
pip install -r requirements.txt
pip install -e .