Fix: ‘No module ‘xformers’ Stable Diffusion Automatic 1111

Stable Diffusion Automatic 1111 is a popular platform for image generation and manipulation tasks.

However, some users have reported encountering a message that reads “No module ‘xformers’. Proceeding without it.” while using the platform.

This article aims to address this issue and provide step-by-step solutions to resolve the error.


Fix: ‘No module ‘xformers’ Stable Diffusion Automatic 1111

1. Adding ‘–xformers’ to the Command Line Arguments

The first solution provided involves adding ‘–xformers’ to the command line arguments in the ‘webui-user.bat’ file.

To do this, follow these steps:

  • Step 1: Locate the ‘webui-user.bat’ file in your Stable Diffusion installation directory.
  • Step 2: Open the ‘webui-user.bat’ file using a text editor.
  • Step 3: Look for the line that contains the command line arguments.
  • Step 4: Add ‘–xformers’ to the command line arguments, separated by a space from other arguments if present.
  • Step 5: Save the changes and restart Stable Diffusion.

Note: While this solution has worked for some users, it might not be effective for everyone. If you’ve already tried this method and the error persists, proceed to the next solution.


2. Editing the ‘launch.py’ File

Next, to fix the ‘No module’ xformer error you can try editing the ‘launch.py’ file to include the ‘–xformers’ argument.

Follow these steps:

  • Step 1: Locate the ‘launch.py’ file within the Stable Diffusion installation directory.
  • Step 2: Open the ‘launch.py’ file with a text editor.
  • Step 3: Search for the ‘commandline_args’ variable assignment.
  • Step 4: Replace the existing assignment with the following line:

Python code: 
commandline_args = os.environ.get(‘COMMANDLINE_ARGS’, “–xformers”)

  • Step 5: Save the changes and restart Stable Diffusion.

3. Instead of using ‘–xformers,’ try to use’–opt-sdp-attention’ or ‘–opt-sdp-no-mem-attention’

Some users have questioned the need for ‘xformers’ and whether it is necessary to have it in the Stable Diffusion environment. ‘xformers’ is a library that allows users to create images with larger sizes than they could typically achieve. It enhances the image generation capabilities of the platform.

However, some users have reported that the latest version of Automatic 1111 includes ‘torch2,’ which performs better in many cases and obviates the need for ‘xformers.’ Instead of using ‘–xformers,’ users can try using ‘–opt-sdp-attention’ or ‘–opt-sdp-no-mem-attention’ as alternatives. More information on these options can be found in the Automatic 1111 documentation.


4. Installing ‘xformers’ using pip

To install ‘xformers’ into the environment, follow these steps:

  • Open a terminal or command prompt.
  • Change the current directory to the ‘stable-diffusion-webui’ folder.
  • Activate the virtual environment (venv) by running the following command:
venv\Scripts\activate
  • Install ‘xformers’ using pip by executing the command:
pip install –force-reinstall –no-deps –pre xformers
Note: The ‘–force-reinstall’ flag is used to force the reinstallation of the package, ‘–no-deps’ flag prevents installing dependencies, and ‘–pre’ flag installs pre-release versions if available.

5. Specifying the correct Torch version

To ensure compatibility with ‘xformers,’ the correct version of Torch should be installed.

Follow these steps:

  • Visit the PyTorch download page (https://download.pytorch.org/whl/torch/) and find the appropriate version for your system.
  • Download the correct Torch wheel file (e.g., torch-2.0.0+cu118-cp310-cp310-win_amd64.whl) matching your Python version, CUDA version, and OS architecture.
  • Place the downloaded file in the ‘venv\Scripts’ directory.
  • Install Torch using pip by running the following command:

pip install torch-2.0.0+cu118-cp310-cp310-win_amd64.whl

Replace the filename with the one you downloaded.


6. Checking the environment variables

If the ‘xformers’ module is still not recognized after installation, consider adding the ‘xformers’ path to the environment variables. This ensures that the module can be accessed from any directory.

However, be cautious while modifying environment variables to avoid conflicts with other packages.


7. Additional Troubleshooting Tips

If you encounter issues while implementing the solutions mentioned above, consider the following troubleshooting steps:

  • Ensure that you are editing the correct files in the correct installation directory.
  • Double-check the command line arguments in the ‘webui-user.bat’ file and the ‘launch.py’ file to ensure there are no syntax errors or typos.
  • Verify that you have the necessary permissions to modify the files in the installation directory.
  • If you are using a different operating system, like Linux, follow the corresponding instructions provided by users who succeeded on their system.

Conclusion:

So, that’s all for now folks. I hope after reading this post you were able to fix the issue.  As a recap, resolving the ‘No module ‘xformers’. Proceeding without it.’ error in Stable Diffusion Automatic 1111 can be achieved by adding ‘–xformers’ to the command line arguments or editing the ‘launch.py’ file. Additionally, understanding the purpose of ‘xformers’ and exploring alternative options can help enhance image generation capabilities.


Further Reading:

As a mechanical engineer I did not get much time to indulge into TV, but it had always been my love for technology, that allowed me to stay updated. My love for technology has helped me gather every required knowledge about SEO. I am still in the learning process and would continue to be so till I master it.

Leave a comment