This guide offers a comprehensive walkthrough for setting up and using Stable Diffusion and Automatic1111 on Windows using WSL (Windows Subsystem for Linux) with GPU acceleration. With the provided step-by-step instructions and example screenshots, this guide will help you generate images and harness the full potential of your hardware.
Stable Diffusion is one of the most potent tools for text-to-image generation, and Automatic1111 helps us integrate it with a user-friendly interface and extensive customization options. Let’s dive into the setup process.
What is Stable Diffusion and Automatic1111?
Stable Diffusion is a cutting-edge AI model that generates high-quality images from Text prompts. Automatic1111 builds on this by providing:
- Prompt refinements, negative prompts, and plugins for advanced use cases as features.
- Features like prompt refinements, negative prompts, and plugins for advanced use cases.
Whether you’re an artist, researcher, or AI enthusiast, this combination offers flexibility and power for your creative and technical needs.
How to Set Up WSL with GPU Acceleration
Step 1: Install WSL in Windows
To enable WSL, open PowerShell and execute the following command:
wsl --install
This command installs WSL and a default Linux distribution (usually Ubuntu).
Step 2: How to Check if WSL is Installed Properly in Windows
Once you run the installation command, you must confirm if WSL was successfully installed and works fine. Then, in the command prompt, enter.
wsl --list --verbose
Step 3: Verify GPU Support for WSL
To verify GPU support in WSL, open your WSL terminal and run the command
nvidia-smi
It gives you all the details on your NVIDIA GPU — driver version, GPU name, and how much memory it is using now. Make sure that the GPU is recognized to ensure it’s compatible for running Stable Diffusion and other GPU intensive tasks.
How to Install Requirements For Stable Diffusion
To prepare your system, update the Linux environment and install the required packages.
Step 1: Update and Upgrade System
Run:
sudo apt update && sudo apt upgrade -y
Step 2: Install Dependencies
To set up your environment for Stable Diffusion in WSL, install the required libraries and tools by running the following command:
sudo apt install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev git
This checks if important components like compilers, libraries for encryption, compression, and development tools are available. These dependencies are crucial for building Python environments, installing packages, and managing the software required for image generation using Stable Diffusion.
Installing and Configuring Pyenv
Pyenv is a handy tool for managing Python versions required for stable diffusion. Here’s how to install and configure it:
Step 1: Install Pyenv
curl https://pyenv.run | bash
This script is used to download the components of pyenv and configure your shell. Yet, after installation, you must add Pyenv initialization commands to your shell configuration file (e.g., .bashrc or .zshrc).
Step 2: Configure Environment
To configure your environment for Pyenv, you need to add its initialization commands to your shell configuration file. This process makes sure that Pyenv works every time you open a terminal. Just run
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Reload the configuration:
source ~/.bashrc
Step 3: Install Python
With Pyenv configured, the next step is to install the specific Python version required for Stable Diffusion. Using Pyenv, you can easily manage and switch between Python versions. To install Python 3.10.15, execute the command
pyenv install 3.10.15
Once the installation is complete, run it globally using the default Python version.
pyenv global 3.10.15
This step confirms that all dependencies and tools for Stable Diffusion operate seamlessly with the correct Python version.
Setting Up Stable Diffusion
Step 1: Create a Directory
mkdir stablediff && cd stablediff
Step 2: Download and Install Stable Diffusion
To begin installing Stable Diffusion, download the installation script provided by AUTOMATIC1111. Use the command
wget -q https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh
This script contains everything needed to set up the Stable Diffusion web interface, streamlining the process for efficient installation.
Run Startup Script
After downloading, make the script executable by running.
chmod +x webui.sh
Execute the Bash Script for Starting Installation:
./webui.sh
The script automatically downloads the required components and sets up the environment. Once complete, the web UI will be ready to use, allowing you to generate stunning AI-driven images effortlessly.
Step 3: Launch Stable Diffusion
The server will start at a local address like http://127.0.0.1:7860. Access it via a web browser.
Configuring Automatic1111
Step 1: Open the Admin Panel in OpenWebUI
- To configure Automatic1111 within OpenWebUI, start by accessing the Admin Panel. Open your web browser and navigate to the OpenWebUI’s URL (typically http://localhost:8080 if running locally). The Admin Panel provides a centralized interface to manage settings, plugins, and other configuration options for Stable Diffusion.
- Go to Settings > Images. This section gives you a chance to make some visual customizations to control various image generation parameters, including resolution, file format, output destination, and image quality. Then, adjust these options depending on how you want Stable Diffusion to output your results.
Step 2: Set Automatic1111 as the Image Generation Engine
Select Automatic1111 from the dropdown menu. Enter the Stable Diffusion URL (http://127.0.0.1:7860) and save the settings.
Generating Images with Stable Diffusion
Step 1: Input Prompt
Go to the Automatic1111 interface and find its Text input field to start imaging. Here, type a descriptive prompt that outlines your desired image, such as:
“Generate an image with servers, Ethernet cables, and a man working on servers.”
This prompt enables the AI also to represent your request in the visual form. Be specific enough to achieve goals.
Step 2: Monitor Progress
When you trigger the beginning of the image generation, the progress bar in the interface will show you the progress of that in real-time. It shows the percentage complete and an estimated time to finish. With this feature, you can keep a tab on the generation status and know if there’s smooth workflow, while you are waiting for the image.
Step 3: View Output
After the image generation is complete, the final result will be displayed in the output section of the interface. You can view the generated image directly, download it, or adjust your prompt and settings to refine the output. This section also stores previous results for easy access.
Using OpenWebUI: Select a Model
To do that in OpenWebUI, go to the Model Selection area. Select a model with an image generation feature like Stable Diffusion, or use one you consider. Choosing the proper model ensures compliance with the input prompt and sound output for the specific image generation work.
Enter Prompt and Generate Image
In the OpenWebUI interface, input your desired prompt in the Text field, describing your desired image (e.g., “A futuristic city skyline at sunset”). After entering the prompt, please wait for the system to process it. Once the response initializes, click the Generate Image button to create your image.
View and Download Output Image
After the generation process is complete, the output image will appear in the results section of the OpenWebUI interface. You can view the image directly within the interface, download it for personal use, or save it to your specified output directory. If unsatisfied, tweak your prompt or settings and regenerate.
How to Monitor GPU Performance in WSL
If you are using Nvidia GPUs alongside WSL, then to monitor your GPU performance while performing tasks in WSL, use the Nvidia-smi command. This tool offers GPU mainly the details of memory consumption, GPU utilization, processes that are running, and temperature of the GPU used. Run the command in your WSL terminal:
nvidia-smi
This command helps you identify bottlenecks, optimize resource usage, and ensure that your GPU correctly handles tasks such as image generation with Stable Diffusion without any issues.
Tips and Best Practices
- Optimize Sampling Steps: Use higher steps for better quality but balance with speed.
- Start with Lower Resolutions: Preview images at 256×256 before generating full-resolution outputs.
- Refine Prompts: Experiment with creative prompts for diverse outputs.
Troubleshooting
- Problem: GPU not detected.
- Solution: Reinstall drivers and verify with nvidia-smi.
- Problem: Poor image quality.
- Solution: Increase the CFG scale or sampling steps.
- Problem: Stable Diffusion won’t start.
- Solution: Make sure all dependencies are installed correctly.
Conclusion
Following this guide, it is easy to set up Stable Diffusion and Automatic1111 in a WSL environment with a GPU. The installation process is well described and elaborated with steps allowing for unproblematic installation, setup, and all subsequent usages, making you accomplish the perfect images. Use prompts, discover new customization possibilities, and extend the possibilities of Stable Diffusion usage.
About the writer
Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.