Categories
Machine Learning

Upgrade AUTOMATIC1111 StableDiffusion Torch 2.0 and Xformers Linux

The default installation of Stable Diffusion Automatic111 using the old version of Torch 1.13.1, Torchvision 0.14, and related Xformers, the webui.sh will receive “No module ‘xformers’. Proceeding without it.”.

Pytorch 2.0 and Xformers are offering a big upgrade. Here are quick step on how to upgrade the Automatic111 web UI and load with xformers.

If you are using Anaconda, go open its terminal then go to stable-diffusion-webui/venv/bin and source activate to enter “venv” environment with python 3.10 as default.

Then, we can start to upgrade the torchvision, torch and xformers with this command

pip install torchvision --upgrade
pip install torch==2.0
pip install -U xformers

If receive an error like this, you can upgrade the torchvision version.

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.14.1+cu117 requires torch==1.13.1, but you have torch 2.0.0 which is incompatible.
Successfully installed torch-2.0.0

After everything is done completely, you can fire-up your webui.sh along with xformers module loaded with command : “bash webui.sh –xformers”

bash webui.sh --xformers

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Python 3.10.9 (main, Mar  1 2023, 18:23:06) [GCC 11.2.0]
Commit hash: 22bcc7be428c94e9408f589966c2040187245d81
Installing requirements for Web UI
Launching Web UI with arguments: --xformers
UserWarning: The torchvision.transforms.functional_tensor module is deprecated in 0.15 and will be **removed in 0.17**. Please don't rely on it. You probably just need to use APIs in torchvision.transforms.functional or in torchvision.transforms.v2.functional.m
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying xformers cross attention optimization.
Textual inversion embeddings loaded(0): 
Model loaded in 1.4s (load weights from disk: 0.1s, create model: 0.4s, apply weights to model: 0.4s, apply half(): 0.3s, move model to device: 0.2s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 4.2s (import torch: 0.6s, import gradio: 0.5s, import ldm: 0.6s, other imports: 0.6s, load scripts: 0.2s, load SD checkpoint: 1.4s, create ui: 0.1s).

Check on the footer to see if any modules is loaded and upgraded properly

2 replies on “Upgrade AUTOMATIC1111 StableDiffusion Torch 2.0 and Xformers Linux”

Would you mind updating this with more detail with the most recent release of Automatic1111?

No matter what I try, I cannot resolve the dependencies. Your one of the few people talking about this.

Leave a Reply

Your email address will not be published. Required fields are marked *