【Stable-Diffusion/SD-WebUI】2023年AI画图SD-WebUI从零开始最全搭建教程Windows/Linux Stable-Diffusion

mowen 2023-03-02 1281

1、nvidia-smi查看CUDA版本

2、根据CUDA版本下载并安装CUDA编译工具链
https://developer.nvidia.com/cuda-toolkit-archive

Windows:
https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_531.14_windows.exe

Linux:
sudo apt install -y build-essential libgl1 kmod wget git nvidia-kernel-source-515-server
wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_530.30.02_linux.run &&
sh cuda_12.1.0_530.30.02_linux.run

3、设置环境变量RUSTUP_HOME、CARGO_HOME,安装Rust
https://www.rust-lang.org/learn/get-started

Windows:
https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe

Linux:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

source "$HOME/.cargo/env"

4、安装python3.10.10
# Windows:
https://www.python.org/ftp/python/3.10.10/python-3.10.10-amd64.exe

# Debian-based:
sudo apt install -y python3 python3-pip python3-venv
# Red Hat-based:
sudo dnf install python3
# Arch-based:
sudo pacman -S python3

pip镜像加速(可选)

# windows:
C:\Users\Admin\pip\pip.ini

# linux:
~/.pip/pip.conf

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn

# 查看
pip3 config list

5、拉取stable-diffusion-webui源码
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

6、下载扩展库到stable-diffusion-webui\extensions\
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-aesthetic-gradients "extensions/aesthetic-gradients"
git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser "extensions/images-browser"

7、下载模型到目录:stable-diffusion-webui\models\Stable-diffusion\
wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt

8、运行SD-WebUI程序
# Windows:
cd stable-diffusion-webui
webui-user.bat

# Linux:
cd stable-diffusion-webui
bash webui-user.sh && bash webui.sh -f


【常见问题】

Q:git无法拉取依赖库,运行SD-WebUI失败

stderr:   Running command git clone --filter=blob:none --quiet https://github.com/TencentARC/GFPGAN.git 'C:\Users\Admin\AppData\Local\Temp\pip-req-build-_8kleg3_'
  error: RPC failed; curl 56 Recv failure: Connection was reset
  error: 6663 bytes of body are still expected
  fetch-pack: unexpected disconnect while reading sideband packet
  fatal: early EOF
  fatal: index-pack failed
  fatal: could not fetch fa702eeacff13fe8475b0e102a8b8c37602f3963 from promisor remote
  warning: Clone succeeded, but checkout failed.
  You can inspect what was checked out with 'git status'
  and retry with 'git restore --source=HEAD :/'
  error: subprocess-exited-with-error
  git clone --filter=blob:none --quiet https://github.com/TencentARC/GFPGAN.git 'C:\Users\Admin\AppData\Local\Temp\pip-req-build-_8kleg3_' did not run successfully.
  exit code: 128
  See above for output.
  note: This error originates from a subprocess, and is likely not a problem with pip.
Command: "D:\git\stable-diffusion-webui\venv\Scripts\python.exe" -m pip install git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 --prefer-binary
Error code: 1
stdout: Collecting git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379
  Cloning https://github.com/TencentARC/GFPGAN.git (to revision 8d2447a2d918f8eba5a4a01463fd48e45126a379) to c:\users\admin\appdata\local\temp\pip-req-build-nkf8z71z
stderr:   Running command git clone --filter=blob:none --quiet https://github.com/TencentARC/GFPGAN.git 'C:\Users\Admin\AppData\Local\Temp\pip-req-build-nkf8z71z'
  Running command git rev-parse -q --verify 'sha^8d2447a2d918f8eba5a4a01463fd48e45126a379'
  Running command git fetch -q https://github.com/TencentARC/GFPGAN.git 8d2447a2d918f8eba5a4a01463fd48e45126a379
  fatal: unable to access 'https://github.com/TencentARC/GFPGAN.git/': Failed to connect to github.com port 443 after 21023 ms: Couldn't connect to server
  error: subprocess-exited-with-error
  git fetch -q https://github.com/TencentARC/GFPGAN.git 8d2447a2d918f8eba5a4a01463fd48e45126a379 did not run successfully.
  exit code: 128
  See above for output.


A:git仓库全量拉取太大导致拉取失败,采用以下方式即可:

CLIP/GFPGAN/k-diffusion/open_clip/stable-diffusion-stability-ai/taming-transformers

mkdir repositorie  && cd repositories

git clone https://github.com/openai/CLIP.git --depth 1 &&
git clone https://github.com/TencentARC/GFPGAN.git --depth 1 &&
git clone https://github.com/crowsonkb/k-diffusion.git --depth 1 &&
git clone https://github.com/mlfoundations/open_clip.git --depth 1 &&
git clone https://github.com/Stability-AI/stablediffusion.git ./stable-diffusion-stability-ai --depth 1 &&
git clone https://github.com/CompVis/taming-transformers.git --depth 1 &&

cd CLIP &&
git fetch --unshallow &&
git checkout d50d76d &&
git branch -av &&
..\..\venv\Scripts\pip install -r requirements.txt &&
..\..\venv\Scripts\pip install .

cd ../GFPGAN &&
git fetch --unshallow &&
git checkout 8d2447a &&
git branch -av &&
..\..\venv\Scripts\pip install -r requirements.txt &&
..\..\venv\Scripts\pip install .

cd ../k-diffusion &&
git fetch --unshallow &&
git checkout 5b3af03 &&
git branch -av &&
..\..\venv\Scripts\pip install -r requirements.txt &&
..\..\venv\Scripts\pip install .

cd ../open_clip &&
git fetch --unshallow &&
git checkout bb6e834 &&
git branch -av &&
..\..\venv\Scripts\pip install -r requirements.txt &&
..\..\venv\Scripts\pip install .

cd ../stable-diffusion-stability-ai &&
git fetch --unshallow &&
git checkout 47b6b60 &&
git branch -av &&
..\..\venv\Scripts\pip install -r requirements.txt &&
..\..\venv\Scripts\pip install .

cd ../taming-transformers &&
git fetch --unshallow &&
git checkout 2426893 &&
git branch -av &&
..\..\venv\Scripts\pip install .


CodeFormer

cd repositories
git clone https://github.com/sczhou/CodeFormer.git --depth 1 &&
cd CodeFormer &&
git fetch --unshallow &&
git checkout c5b4593 &&
git branch -av &&
..\..\venv\Scripts\pip install -r requirements.txt &&
..\..\venv\Scripts\python3 basicsr/setup.py develop


BLIP

cd repositories
git clone https://github.com/salesforce/BLIP.git --depth 1 &&
cd BLIP &&
git fetch --unshallow &&
git checkout 48211a1 &&
git branch -av &&
..\..\venv\Scripts\pip install -r requirements.txt


Q:安装BLIP失败

Building wheels for collected packages: tokenizers
  Building wheel for tokenizers (pyproject.toml) ... error
  error: subprocess-exited-with-error
  × Building wheel for tokenizers (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [47 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-310
      creating build\lib.win-amd64-cpython-310\tokenizers
      copying py_src\tokenizers\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers
      creating build\lib.win-amd64-cpython-310\tokenizers\models
      copying py_src\tokenizers\models\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers\models
      creating build\lib.win-amd64-cpython-310\tokenizers\decoders
      copying py_src\tokenizers\decoders\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers\decoders
      creating build\lib.win-amd64-cpython-310\tokenizers\normalizers
      copying py_src\tokenizers\normalizers\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers\normalizers
      creating build\lib.win-amd64-cpython-310\tokenizers\pre_tokenizers
      copying py_src\tokenizers\pre_tokenizers\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers\pre_tokenizers
      creating build\lib.win-amd64-cpython-310\tokenizers\processors
      copying py_src\tokenizers\processors\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers\processors
      creating build\lib.win-amd64-cpython-310\tokenizers\trainers
      copying py_src\tokenizers\trainers\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers\trainers
      creating build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\implementations\base_tokenizer.py -> build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\implementations\bert_wordpiece.py -> build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\implementations\byte_level_bpe.py -> build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\implementations\char_level_bpe.py -> build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\implementations\sentencepiece_bpe.py -> build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\implementations\sentencepiece_unigram.py -> build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\implementations\__init__.py -> build\lib.win-amd64-cpython-310\tokenizers\implementations
      copying py_src\tokenizers\__init__.pyi -> build\lib.win-amd64-cpython-310\tokenizers
      copying py_src\tokenizers\models\__init__.pyi -> build\lib.win-amd64-cpython-310\tokenizers\models
      copying py_src\tokenizers\decoders\__init__.pyi -> build\lib.win-amd64-cpython-310\tokenizers\decoders
      copying py_src\tokenizers\normalizers\__init__.pyi -> build\lib.win-amd64-cpython-310\tokenizers\normalizers
      copying py_src\tokenizers\pre_tokenizers\__init__.pyi -> build\lib.win-amd64-cpython-310\tokenizers\pre_tokenizers
      copying py_src\tokenizers\processors\__init__.pyi -> build\lib.win-amd64-cpython-310\tokenizers\processors
      copying py_src\tokenizers\trainers\__init__.pyi -> build\lib.win-amd64-cpython-310\tokenizers\trainers
      running build_ext
      running build_rust
      error: can't find Rust compiler
      If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
      To update pip, run:
          pip install --upgrade pip
      and then retry package installation.
      If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects


A:

BLIP依赖rust编译器,先安装rust


Q:

ERROR: This script must not be launched as root, aborting...


A:

bash webui.sh -f
最新回复 (0)
返回
发新帖
X