Boost Performance: Install and Update XFormers for 1.5x Faster Stable Diffusion

installing and upgrading xformers

XFormers is the python library developed by Facebook AI Researchers. Installing Xformers provides an alternative way to decrease the inference time for NVIDIA GPUs which result in faster image generation with less VRAM memory allocation.

It is widely used by researchers for Computer Vision, NLP(Natural Language Processing), etc. Well, Stable Diffusion WebUI uses high end GPUs that run with CUDA and xformers. Lets see how we can install and upgrade the Xformers.

Steps to install Xformers for Automatic1111/Forge:

If haven’t installed the Xformers yet, then this section will help you to install the required version for Stable Diffusion WebUIs.

1. Make sure you have installed the Automatic1111 or Forge WebUI.

2. Now, its recommended to download and install CUDA 11.3 version (Latest versions sometime support) from the official NVIDIA page.

Download NVIDIA CUDA driver

3. Select the appropriate configuration setup for your machine. Like in our case we have the Windows OS 10, x64 base architecture. You can check yours by moving to the system properties on “This PC” from home section. Here, the file size which we need to download is 2.7 GB approx. In your case, it can be different.

Install NVIDIA CUDA driver

4. After downloading, install it by following the installation instructions.

5. Now, make sure you have enable the xformers args inside “webui-user.bat” file otherwise WebUI will not use it.

Confirmation for Xformers running

6. For confirmation that WebUI is using the Xformers or not, as usual click on webui.bat to start Automatic1111/Forge and move to command prompt, you will see “Launching webui with args = –xformers” message.

At the first attempt of image generation it will take some time (10-20 minutes) but after that your image generation will be faster.

Steps to Upgrade Xformers for Automatic1111/Forge:

While using different Stable Diffusion models, we sometime noticed a warning message that “you are using xformers…. version This program is tested to work with xformers…“.

warning message for Xformers

If you are getting the same issue, so in this case you should upgrade the required Xformers version. Lets see how we can upgrade it.

Download xformers from Pypi

1. First go to the Xformers python library official release on Pypi website.

2. Copy the download link from there and move to your stable diffusion directory. 

pip install xformers

Move to address path directory

3. Move and click to the address bar and type “cmd” to open command prompt on the respective directory.

Paste copied link to command prompt

4. Then paste the copied link by right clicking on the command prompt and press enter. It will start the processing for updates for Xformers.

If you face error that its unsupported then you should try lower version for getting it compatible. 

add arguments

5. After getting installed, go to the Stable Diffusion directory and right click on “webui-user.bat” file and open your file with notepad or editor(we use notepad++). Add the required arguments:

–reinstall-xformers

Now save the file and restart Automatic1111 / Forge to get install all the necessary files and packages.

6. Now reedit and remove the args from the “webui-user.bat” file which you have added earlier and save the file, otherwise the files will get installed again.

Xformers Upgraded

For confirmation that Stable diffusion WebUI is really using Xformers and its updated or not , you can check the version on the bottom of the WebUI.

After installation, at the initial stage of image generation, it will take some time (10-20 minutes) for processing. After first attempt it will be faster.

Conclusion:

Xformers makes the image generation faster for Stable Diffusion WebUIs. Its is mostly used for NLP, Computer Vision, etc. which directs to consume less VRAM.