MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

在 WSL2 环境下一键部署 Stable Diffusion with AUTOMATIC1111 WebUI

项目背景与痛点

随着 Stable Diffusion 模型的火热,越来越多的开发者和艺术家希望能够简洁、快速地在自己的本地环境中部署并运行这类模型。Stability AI 的 Stable Diffusion 可以生成高质量的图像,而 AUTOMATIC1111 提供的 WebUI 则将方便性和易用性提升到了一个新的水平。然而,要直接在 Windows 环境下部署和运行这一堆栈并不容易,因为涉及到大量的依赖管理、环境配置等问题。

这款由 rgryta 维护的仓库 Stable-Diffusion-WSL2-Docker,则提供了一个终极解决方案。通过结合 WSL2 和 Docker,实现了一键安装的体验,大大降低了开发者的入门门槛。这个方案显然解决了 Windows 用户长期以来的一个痛点,使得他们可以专注于创意和开发,而非基础设施的搭建和调试。

技术核心揭秘

着眼于架构层面,此项目的设计思路十分清晰,并利用了当前较为流行的开源技术栈。WLS2 提供了原生支持 Linux 和 Windows 两套操作系统的平台,Docker 则让开发者可以轻松地在容器化环境中部署和运行应用程序。这一技术组合极大的降低了部署的复杂度,并提升了开发环境的一致性和复用性。

graph LR A[用户拉取 Docker 镜像] --> B[启动 WSL2 实例] B --> C[容器环境初始化] C --> D[环境检查] D -->|"通过"| E[运行 Stable Diffusion] D -->|"失败"| F[日志记录并提示错误] E --> G[WebUI 启动] G --> H[用户与 WebUI 交互]

利用 Docker 镜像进行环境初始化,项目通过配置文件简化了必要的依赖安装步骤,进一步避免了常见的配置错误。容器化部署使得环境可以快速复现,这也能帮助开发者在不同的机器上无缝迁移自己的开发环境。

功能亮点与差异

对比用在本地直接安装和运行 Stable Diffusion with AUTOMATIC1111 的方式,这个项目的关键制胜点在于简洁和高效。WLS2 加 Docker 的组合提供了跨平台的无缝支持,使得 Windows 用户也能享受到 Linux 的强劲性能,同时 Docker 容器化解决了包管理和依赖冲突的问题。项目还预先基于 Docker 配置了必要的系统依赖,并通过 docker-compose 简化了启动流程。

特性上,项目提供了详细的 Dockerfile 和 docker-compose 配置文件,便于开发人员更好的定制化自己的部署环境。同时支持定制化的模型和插件,此类灵活的配置给了用户更多的选择权,为不同的使用场景提供了灵活的支持。

应用场景与落地建议

此项目非常适合已经在 Windows 环境工作的开发者们,尤其适用于那些需要频繁切换开发环境,并希望保持环境一致的开发团队。在启动和使用的过程中,需注意在 Docker 镜像中正确配置映射路径和端口,确保数据读写和网络通信的正确性。此外,因为项目依赖 Docker,也应确保本地机器的资源分配足够,特别是 CPU 和 GPU 资源的匹配以及适当的内存大小。

综合评价

rgryta/Stable-Diffusion-WSL2-Docker 项目以一种简洁、高效率的方式解决了部分开发者部署 Stable Diffusion 的需求,其架构设计完美贴合 Windows 用户的需求。该方案降低了环境搭建的复杂度,提供了灵活且强大的视觉生成能力。缺点在于,作为一个相对小众但功能强大的工具,它可能对初级用户的学习成本有一定要求,并且对于资源调优未做太多说明。

总的来说,此项目依然可以说是一个非常有潜力的产品,特别适合具有一定技术基础和需求复杂控制的开发者环境中使用。

关于

GitHub 原始描述(英文)

One-click install for StabilityAI's Stable-Diffusion with AUTOMATIC1111's webui

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
153
价值分
73
活跃状态
活跃

语言占比

Batchfile
Dockerfile
PowerShell
Python
Shell

README

Stable Diffusion on Docker (WSL2)

About

This repository is meant to allow for easy installation of Stable Diffusion on Windows. One click to install. Second click to start.

This setup is completely dependant on current versions of AUTOMATIC1111’s webui repository and StabilityAI’s Stable-Diffusion models.

In it’s current configuration only Nvidia GPUs are supported. This script will also install all dependencies (including xformers) in order to speed up launching the webui.

Prerequisites

Before following through with these instructions. Please verify below.

  1. You have virtualization support - easiest way is to check if you can see “Virtualization” section in Windows Task Manager -> Performance -> CPU (it’s located under “More details” if you don’t see the Performance tab).
  2. You have virtualization enabled - you have to enable it in your BIOS if you don’t.
  3. You have Windows 11 Pro - you can also use Windows 11 Home (also Windows 10 above certain version), but I cannot guarantee that provided scripts will work their magic.
  4. You have Nvidia GPU - this is mandatory for current configuration. Support for AMD is presumably possible, but won’t be added until such request shows up. Make sure you also have the newest drivers! Whole repository is based on CUDA 12 - you will be limited to GTX 900-series or higher.
  5. You need admin access. These scripts use a PowerShell library that I’ve prepared, called WSLTools (handles automatic and interactive installation of WSL distributions from source), you need to have admin privileges to install this module.

How to use

After installation simply execute start.bat file to start the Stable-Diffusion app. You can open it under http://localhost:7860.

If you want to close the app - simply launch stop.bat, it will terminate the application and close the terminals.

Note! Keep in mind that stop.bat will terminate and remove all containers based on Stable-Diffusion webui image. If you have downloaded additional models while the application was running - e.g. GAN models - they will have to be redownloaded again.

Installation

Automatic

Run install.bat in order to install the Stable Diffusion. This will take a while - as long as you don’t see red errors - everything’s fine. I takes about 20min to install on my machine.

Manual

WSL
  1. Install Windows 11
  2. Install WSL from MS Store (https://www.microsoft.com/store/productId/9P9TQF7MRM4R)
  3. Search for “Turn Windows features on or off” and enable “Hyper-V”
  4. Set WSL to use v2: wsl --set-default-version 2
  5. Install Linux distro of your choice (Ubuntu given as example): wsl --install Ubuntu
    1. Set up your username and password
  6. (In distro command line) sudo sh -c 'echo "[boot]\nsystemd=true" > /etc/wsl.conf'
  7. Check your distro name using wsl --list
  8. Shutdown all distros wsl --shutdown and restart the one we’re using wsl --distribution Ubuntu
  9. Make sure you have nvidia drivers installed on Windows
  10. Now open WSL. From now on, everything is executed from there.
Docker
  1. Execute following scripts (installs cuda drivers):
    sudo apt-key del 7fa2af80
    wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
    sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
    sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/3bf863cc.pub
    sudo add-apt-repository 'deb https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/ /'
    sudo apt-get update
    sudo apt-get -y install cuda
    
  2. Check if you’re able to see your GPU in WSL: nvidia-smi
  3. Install docker:
    curl https://get.docker.com | sh \
    && sudo systemctl --now enable docker
    
  4. Prepare gpg keys to install nvidia-docker as per https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#installing-with-apt
	curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
	&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
	sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
	sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
  1. Now we can install it: sudo apt-get install -y nvidia-docker2
  2. Restart docker service: sudo systemctl restart docker
  3. Check if docker container also sees your GPU: sudo docker run --rm --gpus all nvidia/cuda:12.0.1-base-ubuntu22.04 nvidia-smi
New Docker Container
  1. docker compose up --force-recreate -d
  2. If everything started great and no errors you can run the instance in the background docker compose up -d
Old Docker Container Method (doesn’t work)
  1. Run sh docker/build.sh from repo directory to build the container. You can uncomment depth, upscaler, inpainting and gfpgan from Dockerfile (first generated image) but it will take much more space - default installation is ~25GB total.
  2. Run sh docker/run.sh to start container. Open http://localhost:7860 to access the webui - you can do so from Windows of course.

Development

If you wish to make changes to this repository and test your changes, the following steps will help.

  1. Fork this repository
  2. Create a branch called “dev”
  3. Created a file called “docker-compose.override.yml” with the following contents in the repository root.
services:
  sd:
    container_name: sd-dev
    build: https://github.com/rgryta/Stable-Diffusion-WSL2-Docker.git#dev:docker  # Set to your github repostiory fork
  1. Run docker compose up --force-recreate -d

Sources

  1. StabilityAI Stable-Diffusion GitHub
  2. StabilityAI Stable-Diffusion HuggingFace
  3. AUTOMATIC1111 webui
  4. Nvidia Container Runtime
  5. Ubuntu GPU acceleration on WSL2
  6. MS WSL systemd
  7. Nvidia WSL

评论

暂无评论