Get 50% Discount Offer 26 Days

Recommended Services
Supported Scripts
WordPress
Hubspot
Joomla
Drupal
Wix
Shopify
Magento
Typeo3
How to Generate Images using Stable Diffusion from WSL in Windows

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).

Installing Windows Subsystem for Linux

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
WSL List Command Output to Verify Installation

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.

NVIDIA-SMI Output Showing GPU Information for WSL Compatibility

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.

Terminal Command to Install Dependencies for Stable Diffusion on WSL

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).

Terminal Command to Install Pyenv for Python Version Management

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 -)"
Terminal Command to Configure Pyenv for Python Version Management

Reload the configuration:

source ~/.bashrc
Terminal Command to Reload Shell Configuration for Pyenv

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
Terminal Command to Install Python 3.10.15 with Pyenv for Version Management

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.

Terminal Command to Set Global Python Version for Stable Diffusion

Setting Up Stable Diffusion

Step 1: Create a Directory

mkdir stablediff && cd stablediff
Terminal Command to Create Directory for Stable Diffusion Installation

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.

Terminal Command to Download Stable Diffusion WebUI Script for Installation

Run Startup Script

After downloading, make the script executable by running.

chmod +x webui.sh
Terminal Command to Make Stable Diffusion Script Executable

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.

Terminal Command to Run Stable Diffusion Installation Script

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.

Stable Diffusion Web UI Interface for Image Generation

Configuring Automatic1111

Step 1: Open the Admin Panel in OpenWebUI

  1. 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.
Admin Panel Button to Access OpenWebUI Settings
  1. 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.
Image Settings Tab to Configure Image Generation in OpenWebUI.

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.

Entering Stable Diffusion URL in OpenWebUI Settings for Integration

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.

Text Input Field for Stable Diffusion Prompts and Image Generation.

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.

Stable Diffusion Image Generation Progress Bar Showing Completion Percentage

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.

Generated Image Displayed in Stable Diffusion Output Section

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.

Model Selection Dropdown for Choosing Image Generation Models in OpenWebUI

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.

Text Input Field for Entering Prompts in Stable Diffusion

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.

Generated Image Displayed in Stable Diffusion Output Section

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 
NVIDIA SMI Output Showing GPU Usage and Temperature for WSL Tasks

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

  1. Optimize Sampling Steps: Use higher steps for better quality but balance with speed.
  2. Start with Lower Resolutions: Preview images at 256×256 before generating full-resolution outputs.
  3. 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 Article Author

Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.

Leave a Reply

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

Lifetime Solutions:

VPS SSD

Lifetime Hosting

Lifetime Dedicated Servers