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.
Table of Contents:
Steps to install Xformers for Automatic1111/Forge
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.
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.
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(found inside WebUI installation folder) otherwise WebUI will not use it.
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...".
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.
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
3. Move and click to the address bar and type "cmd" to open command prompt on the respective directory.
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 to your machine.
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.
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.