win2003 网站服务器,统一企业信息管理系统网站,网站开发中界面,建设服装网站国内Ubuntu环境Docker部署Stable Diffusion入坑记录 本文旨在记录使用dockerpython进行部署 stable-diffusion-webui 项目时遇到的一些问题#xff0c;以及解决方案#xff0c;原项目地址: https://github.com/AUTOMATIC1111/stable-diffusion-webui
问题一览#xff1a;
…国内Ubuntu环境Docker部署Stable Diffusion入坑记录 本文旨在记录使用dockerpython进行部署 stable-diffusion-webui 项目时遇到的一些问题以及解决方案原项目地址: https://github.com/AUTOMATIC1111/stable-diffusion-webui
问题一览
国内如何下载大模型手写Docker运行时遇到的问题记录。
国内如何快速下载大模型
使用 modelscope 模块进行下载你可以在官网找到你需要的模型。 官网地址https://modelscope.cn/models
# SDK模型下载
from modelscope import snapshot_download
# 示例
snapshot_download(iic/CosyVoice2-0.5B, local_dirpretrained_models/CosyVoice2-0.5B)Docker运行时遇到的问题
1、安装带gpu版本的torch
在requirements_versions.txt 和 requirements.txt 的第一行加入以下文本
国外--extra-index-url https://download.pytorch.org/whl/cu121
国内--extra-index-url https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/wheel/cu121/一般我们安装带GPU的torch时通常会去 download.pytorch.org 找对应的torch版本。 加上上述文本后会自动从该网址查找并下载安装。
2、以下问题需要重新编译python
是因为手动编译python时系统依赖安装不足导致有些依赖库找不到指定的系统包。这种情况只能安装相关系统软件后重新编译python。
ModuleNotFoundError: No module named _ctypes使用 apt-get install libffi-dev 安装 libffi-dev。
ModuleNotFoundError: No module named _lzma使用 apt-get install liblzma-dev 安装 liblzma-dev。
重新编译方法
wget https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tgz
tar -xzf Python-3.10.13.tgz
cd Python-3.10.13
./configure --with-system-ffi --enable-shared --enable-optimizations make make install echo /usr/local/lib | tee /etc/ld.so.conf.d/python3.conf ldconfig3、以下问题安装需要安装git
root58befcdcc1d7:/workspace/automatic1111-stable-diffusion-webui# python3 webui.py
/usr/local/lib/python3.10/site-packages/torchvision/transforms/functional_tensor.py:5: UserWarning: The torchvision.transforms.functional_tensor module is deprecated in 0.15 and will be **removed in 0.17**. Please dont rely on it. You probably just need to use APIs in torchvision.transforms.functional or in torchvision.transforms.v2.functional.warnings.warn(
Traceback (most recent call last):File /usr/local/lib/python3.10/site-packages/git/__init__.py, line 87, in modulerefresh()File /usr/local/lib/python3.10/site-packages/git/__init__.py, line 76, in refreshif not Git.refresh(pathpath):File /usr/local/lib/python3.10/site-packages/git/cmd.py, line 341, in refreshraise ImportError(err)
ImportError: Bad git executable.
The git executable must be specified in one of the following ways:- be included in your $PATH- be set via $GIT_PYTHON_GIT_EXECUTABLE- explicitly set via git.refresh()All git commands will error until this is rectified.This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:- quiet|q|silence|s|none|n|0: for no warning or exception- warn|w|warning|1: for a printed warning- error|e|raise|r|2: for a raised exceptionExample:export GIT_PYTHON_REFRESHquietThe above exception was the direct cause of the following exception:Traceback (most recent call last):File /workspace/automatic1111-stable-diffusion-webui/webui.py, line 15, in modulefrom modules import import_hook, errors, extra_networks, ui_extra_networks_checkpointsFile /workspace/automatic1111-stable-diffusion-webui/modules/ui_extra_networks_checkpoints.py, line 6, in modulefrom modules import shared, ui_extra_networks, sd_modelsFile /workspace/automatic1111-stable-diffusion-webui/modules/shared.py, line 16, in modulefrom modules import localization, extensions, script_loading, errors, ui_components, shared_itemsFile /workspace/automatic1111-stable-diffusion-webui/modules/extensions.py, line 6, in moduleimport gitFile /usr/local/lib/python3.10/site-packages/git/__init__.py, line 89, in moduleraise ImportError(Failed to initialize: {0}.format(exc)) from exc
ImportError: Failed to initialize: Bad git executable.
The git executable must be specified in one of the following ways:- be included in your $PATH- be set via $GIT_PYTHON_GIT_EXECUTABLE- explicitly set via git.refresh()All git commands will error until this is rectified.This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:- quiet|q|silence|s|none|n|0: for no warning or exception- warn|w|warning|1: for a printed warning- error|e|raise|r|2: for a raised exceptionExample:export GIT_PYTHON_REFRESHquiet使用 apt install git 安装 git即可。
4、以下问题是因为缺少python依赖包或依赖包的版本问题
ModuleNotFoundError: No module named torchvision.transforms.functional_tensor这是因为高版本的torch有些包已经移动或者更改了导入方式可选择降torch版本到1.13以下或者更改高版本的源码的导入方式。 请参考这篇博客 https://blog.csdn.net/lanxing147/article/details/136625264
这篇博客讲到了有些版本是可以使用的比如笔者使用的 torch 2.12 torchvision0.16.2 torchaudio2.1.2。 可使用以下命令安装:
pip install torch2.1.2 torchvision0.16.2 torchaudio2.1.2 --index-url https://download.pytorch.org/whl/cu118但是国内比较慢可以选择使用国内镜像源进行提速。使用以下命令
pip install torch2.1.2 torchvision torchaudio -f https://mirrors.aliyun.com/pytorch-wheels/cu121/参考以下文章 https://docs.infini-ai.com/posts/download-pytorch-from-mirror.html
TypeError: AsyncConnectionPool.__init__() got an unexpected keyword argument socket_options这是由于 httpcore 版本太低导致的 使用 pip3 install -U httpcore 升级 httpcore 到最新版本即可。
ModuleNotFoundError: No module named clip使用 pip3 install clip 安装 clip 库即可。
No module named pytorch_lightning.utilities.distributedpytorch_lightning的版本较低安装高版本的 pytorch_lightning 即可。 笔者使用的是 pip3 pytorch_lightning1.9。
No module named gdown使用 pip3 install gdown 安装 gdown库即可。
No module named open_clip_torch使用 pip3 install open_clip_torch 安装 open_clip_torch库即可。
5、启动时遇到的问题
最终启动用命令
python3 webui.py --listen --port7860 --no-half --disable-nan-check写在最后
附上完整的Docker 镜像构筑的相关文件国内基本上也能够很顺畅的一键构筑好docker镜像总大小约28G。 请在项目根目录下创建一个 docker 目录然后将 Dockerfile、compose.yaml、requirements.txt 、 requirements_versions.txt、start.sh等文件放进去。 然后执行 cd docker docker compose -f compose.yaml up 命令。 如果访问浏览器的 7860 端口出现以下界面恭喜你成功了。 Dockerfile
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04ARG VENV_NAMEsd-webui
ENV VENV$VENV_NAME
ENV LANGC.UTF-8 LC_ALLC.UTF-8ENV DEBIAN_FRONTENnoninteractive
SHELL [/bin/bash, -c]RUN apt-get update -y
RUN apt-get install -y libgl1-mesa-glx libglib2.0-0
RUN apt-get install -y net-tools wget curl gitRUN apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev liblzma-dev# 从国内镜像源下载安装python
# wget https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tar.xz tar Jxf Python-3.10.13.tar.xz
RUN wget https://mirrors.huaweicloud.com/python/3.10.13/Python-3.10.13.tar.xz tar Jxf Python-3.10.13.tar.xz
RUN cd Python-3.10.13 ./configure --with-system-ffi --enable-shared --enable-optimizations make make install echo /usr/local/lib | tee /etc/ld.so.conf.d/python3.conf ldconfig
RUN python3 -V pip3 -V# 设置国内镜像源
RUN pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ pip3 config set install.trusted-host mirrors.aliyun.comWORKDIR /workspace
COPY ./requirements_versions.txt ./
COPY ./requirements.txt ./RUN pip3 install -r requirements_versions.txt
RUN pip3 install -r requirements.txtcompose.yaml
services:sd-webui:container_name: sd-webuiimage: sd-webui:1.0restart: alwaysports:- 7860:7860environment:- TZAsia/Tokyo- NVIDIA_VISIBLE_DEVICESallvolumes:- ../../automatic1111-stable-diffusion-webui:/workspace/automatic1111-stable-diffusion-webui# command: tail -f /dev/nullcommand: sh -c sh /workspace/automatic1111-stable-diffusion-webui/docker/start.shdeploy:resources:reservations:devices:- driver: nvidiacapabilities: [gpu]requirements.txt
--extra-index-url https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/wheel/cu121/
blendmodes
accelerate
basicsr
fonts
font-roboto
gfpgan
gradio
invisible-watermark
numpy
omegaconf
opencv-contrib-python
requests
piexif
Pillow
# pytorch_lightning1.7.7
pytorch_lightning1.9
realesrgan
scikit-image0.19
timm0.4.12
transformers4.25.1
# torch
torch2.1.2
torchaudio2.1.2
einops
jsonmerge
clean-fid
resize-right
torchdiffeq
kornia
lark
inflection
GitPython
torchsde
safetensors
psutil
open_clip_torch
gdown
cliprequirements_versions.txt
--extra-index-url https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/wheel/cu121/
blendmodes2022
transformers4.25.1
accelerate0.12.0
basicsr1.4.2
gfpgan1.3.8
gradio3.16.2
numpy1.23.3
Pillow9.4.0
realesrgan0.3.0
torch
omegaconf2.2.3
# pytorch_lightning1.7.6
pytorch_lightning
scikit-image0.19.2
fonts
font-roboto
timm0.6.7
piexif1.1.3
einops0.4.1
jsonmerge1.8.0
clean-fid0.1.29
resize-right0.0.2
torchdiffeq0.2.3
kornia0.6.7
lark1.1.2
inflection0.5.1
GitPython3.1.27
torchsde0.2.5
safetensors0.2.7
# httpcore0.15
httpcore
fastapi0.90.1
open_clip_torchstart.sh
#! /bin/bash
cd automatic1111-stable-diffusion-webui python3 webui.py --listen --port7860 --no-half --disable-nan-check以上就是本次踩坑的记录。愿看到的小伙伴不迷路。