Stable Diffusion webUI 最全且简单配置指南

IRevers 2024-06-15 08:03:02 阅读 82

Stable Diffusion webUI 配置指南

本博客主要介绍部署Stable Diffusion到本地,生成想要的风格图片。

文章目录

Stable Diffusion webUI 配置指南1、配置环境(1)pip环境[可选](2)conda环境[可选] 2、配置Stable Diffusion webUI项目3、遇到的问题4、参考

1、配置环境

使用平台:Linux Ubuntu 18.04.5 LTS编程语言:Python 3.9CUDA环境:CUDA 11.7

Python环境配置可通过conda环境或者pip环境,如果不想用已有的环境或者使用python3.10及以上,可以直接跳过如下步骤。

(1)pip环境[可选]

requirements.txt文件内容如下:

accelerate==0.21.0aenum==3.1.15aiofiles==23.2.1aiohttp==3.9.5aiosignal==1.3.1altair==5.3.0antlr4-python3-runtime==4.9.3anyio==3.7.1async-timeout==4.0.3attrs==23.2.0blendmodes==2022certifi==2024.2.2chardet==5.2.0charset-normalizer==2.0.4clean-fid==0.1.35click==8.1.7clip==1.0cmake==3.29.2contourpy==1.2.1cycler==0.12.1deprecation==2.1.0diskcache==5.6.3einops==0.4.1exceptiongroup==1.2.1facexlib==0.3.0fastapi==0.94.0ffmpy==0.3.2filelock==3.14.0filterpy==1.4.5fonttools==4.51.0frozenlist==1.4.1fsspec==2024.3.1ftfy==6.2.0gitdb==4.0.11GitPython==3.1.32gradio==3.41.2gradio_client==0.5.0h11==0.12.0httpcore==0.15.0httpx==0.24.1huggingface-hub==0.23.0idna==3.7imageio==2.34.1importlib_resources==6.4.0inflection==0.5.1Jinja2==3.1.3jsonmerge==1.8.0jsonschema==4.22.0jsonschema-specifications==2023.12.1kiwisolver==1.4.5kornia==0.6.7lark==1.1.2lazy_loader==0.4lightning-utilities==0.11.2lit==18.1.4llvmlite==0.42.0MarkupSafe==2.1.5matplotlib==3.8.4mkl-fft==1.3.1mkl-random==1.2.2mkl-service==2.4.0mpmath==1.3.0multidict==6.0.5networkx==3.2.1numba==0.59.1numpy==1.26.2nvidia-cublas-cu11==11.10.3.66nvidia-cublas-cu12==12.1.3.1nvidia-cuda-cupti-cu11==11.7.101nvidia-cuda-cupti-cu12==12.1.105nvidia-cuda-nvrtc-cu11==11.7.99nvidia-cuda-nvrtc-cu12==12.1.105nvidia-cuda-runtime-cu11==11.7.99nvidia-cuda-runtime-cu12==12.1.105nvidia-cudnn-cu11==8.5.0.96nvidia-cudnn-cu12==8.9.2.26nvidia-cufft-cu11==10.9.0.58nvidia-cufft-cu12==11.0.2.54nvidia-curand-cu11==10.2.10.91nvidia-curand-cu12==10.3.2.106nvidia-cusolver-cu11==11.4.0.1nvidia-cusolver-cu12==11.4.5.107nvidia-cusparse-cu11==11.7.4.91nvidia-cusparse-cu12==12.1.0.106nvidia-nccl-cu11==2.14.3nvidia-nccl-cu12==2.20.5nvidia-nvjitlink-cu12==12.4.127nvidia-nvtx-cu11==11.7.91nvidia-nvtx-cu12==12.1.105omegaconf==2.2.3open-clip-torch==2.20.0opencv-python==4.9.0.80orjson==3.10.2packaging==24.0pandas==2.2.2piexif==1.1.3Pillow==9.5.0pillow-avif-plugin==1.4.3pip==23.3.1protobuf==3.20.0psutil==5.9.5pydantic==1.10.15pydub==0.25.1pyparsing==3.1.2python-dateutil==2.9.0.post0python-multipart==0.0.9pytorch-lightning==1.9.4pytz==2024.1PyWavelets==1.6.0PyYAML==6.0.1referencing==0.35.1regex==2024.4.28requests==2.31.0resize-right==0.0.2rpds-py==0.18.0safetensors==0.4.2scikit-image==0.21.0scipy==1.13.0semantic-version==2.10.0sentencepiece==0.2.0setuptools==68.2.2six==1.16.0smmap==5.0.1sniffio==1.3.1spandrel==0.1.6starlette==0.26.1sympy==1.12tifffile==2024.4.24timm==0.9.16tokenizers==0.13.3tomesd==0.1.3toolz==0.12.1torch==2.0.1torchaudio==2.0.2torchdiffeq==0.2.3torchmetrics==1.3.2torchsde==0.2.6torchvision==0.15.2tqdm==4.66.2trampoline==0.1.2transformers==4.30.2triton==2.0.0typing_extensions==4.11.0tzdata==2024.1urllib3==2.1.0uvicorn==0.29.0wcwidth==0.2.13websockets==11.0.3wheel==0.41.2yarl==1.9.4zipp==3.18.1

安装shell命令

pip install -r requirements.txt

(2)conda环境[可选]

requirements.txt文件内容如下:

# This file may be used to create an environment using:# $ conda create --name <env> --file <this file># platform: linux-64_libgcc_mutex=0.1=main_openmp_mutex=5.1=1_gnuaccelerate=0.21.0=pypi_0aenum=3.1.15=pypi_0aiofiles=23.2.1=pypi_0aiohttp=3.9.5=pypi_0aiosignal=1.3.1=pypi_0altair=5.3.0=pypi_0antlr4-python3-runtime=4.9.3=pypi_0anyio=3.7.1=pypi_0async-timeout=4.0.3=pypi_0attrs=23.2.0=pypi_0blas=1.0=mklblendmodes=2022=pypi_0bzip2=1.0.8=h5eee18b_6ca-certificates=2024.3.11=h06a4308_0certifi=2024.2.2=py39h06a4308_0chardet=5.2.0=pypi_0charset-normalizer=3.3.2=pypi_0clean-fid=0.1.35=pypi_0click=8.1.7=pypi_0clip=1.0=pypi_0cmake=3.29.2=pypi_0contourpy=1.2.1=pypi_0cuda-cudart=11.7.99=0cuda-cupti=11.7.101=0cuda-libraries=11.7.1=0cuda-nvrtc=11.7.99=0cuda-nvtx=11.7.91=0cuda-runtime=11.7.1=0cudatoolkit=11.1.1=ha002fc5_10cudnn=8.9.2.26=cuda11_0cycler=0.12.1=pypi_0deprecation=2.1.0=pypi_0diskcache=5.6.3=pypi_0einops=0.4.1=pypi_0exceptiongroup=1.2.1=pypi_0facexlib=0.3.0=pypi_0fastapi=0.94.0=pypi_0ffmpeg=4.3=hf484d3e_0ffmpy=0.3.2=pypi_0filelock=3.14.0=pypi_0filterpy=1.4.5=pypi_0fonttools=4.51.0=pypi_0freetype=2.12.1=h4a9f257_0frozenlist=1.4.1=pypi_0fsspec=2024.3.1=pypi_0ftfy=6.2.0=pypi_0gitdb=4.0.11=pypi_0gitpython=3.1.32=pypi_0gmp=6.2.1=h295c915_3gnutls=3.6.15=he1e5248_0gradio=3.41.2=pypi_0gradio-client=0.5.0=pypi_0h11=0.12.0=pypi_0httpcore=0.15.0=pypi_0httpx=0.24.1=pypi_0huggingface-hub=0.23.0=pypi_0idna=3.7=py39h06a4308_0imageio=2.34.1=pypi_0importlib-resources=6.4.0=pypi_0inflection=0.5.1=pypi_0intel-openmp=2021.4.0=h06a4308_3561jinja2=3.1.3=pypi_0jpeg=9e=h5eee18b_1jsonmerge=1.8.0=pypi_0jsonschema=4.22.0=pypi_0jsonschema-specifications=2023.12.1=pypi_0kiwisolver=1.4.5=pypi_0kornia=0.6.7=pypi_0lame=3.100=h7b6447c_0lark=1.1.2=pypi_0lazy-loader=0.4=pypi_0lcms2=2.12=h3be6417_0ld_impl_linux-64=2.38=h1181459_1lerc=3.0=h295c915_0libcublas=11.10.3.66=0libcufft=10.7.2.124=h4fbf590_0libcufile=1.9.1.3=0libcurand=10.3.5.147=0libcusolver=11.4.0.1=0libcusparse=11.7.4.91=0libdeflate=1.17=h5eee18b_1libffi=3.3=he6710b0_2libgcc-ng=11.2.0=h1234567_1libgomp=11.2.0=h1234567_1libiconv=1.16=h5eee18b_3libidn2=2.3.4=h5eee18b_0libnpp=11.7.4.75=0libnvjpeg=11.8.0.2=0libpng=1.6.39=h5eee18b_0libstdcxx-ng=11.2.0=h1234567_1libtasn1=4.19.0=h5eee18b_0libtiff=4.5.1=h6a678d5_0libunistring=0.9.10=h27cfd23_0libwebp-base=1.3.2=h5eee18b_0lightning-utilities=0.11.2=pypi_0lit=18.1.4=pypi_0llvmlite=0.42.0=pypi_0lz4-c=1.9.4=h6a678d5_1markupsafe=2.1.5=pypi_0matplotlib=3.8.4=pypi_0mkl=2021.4.0=h06a4308_640mkl-service=2.4.0=py39h7f8727e_0mkl_fft=1.3.1=py39hd3c417c_0mkl_random=1.2.2=py39h51133e4_0mpmath=1.3.0=pypi_0multidict=6.0.5=pypi_0ncurses=6.4=h6a678d5_0nettle=3.7.3=hbbd107a_1networkx=3.2.1=pypi_0numba=0.59.1=pypi_0numpy=1.26.2=pypi_0nvidia-cublas-cu11=11.10.3.66=pypi_0nvidia-cublas-cu12=12.1.3.1=pypi_0nvidia-cuda-cupti-cu11=11.7.101=pypi_0nvidia-cuda-cupti-cu12=12.1.105=pypi_0nvidia-cuda-nvrtc-cu11=11.7.99=pypi_0nvidia-cuda-nvrtc-cu12=12.1.105=pypi_0nvidia-cuda-runtime-cu11=11.7.99=pypi_0nvidia-cuda-runtime-cu12=12.1.105=pypi_0nvidia-cudnn-cu11=8.5.0.96=pypi_0nvidia-cudnn-cu12=8.9.2.26=pypi_0nvidia-cufft-cu11=10.9.0.58=pypi_0nvidia-cufft-cu12=11.0.2.54=pypi_0nvidia-curand-cu11=10.2.10.91=pypi_0nvidia-curand-cu12=10.3.2.106=pypi_0nvidia-cusolver-cu11=11.4.0.1=pypi_0nvidia-cusolver-cu12=11.4.5.107=pypi_0nvidia-cusparse-cu11=11.7.4.91=pypi_0nvidia-cusparse-cu12=12.1.0.106=pypi_0nvidia-nccl-cu11=2.14.3=pypi_0nvidia-nccl-cu12=2.20.5=pypi_0nvidia-nvjitlink-cu12=12.4.127=pypi_0nvidia-nvtx-cu11=11.7.91=pypi_0nvidia-nvtx-cu12=12.1.105=pypi_0omegaconf=2.2.3=pypi_0open-clip-torch=2.20.0=pypi_0opencv-python=4.9.0.80=pypi_0openh264=2.1.1=h4ff587b_0openjpeg=2.4.0=h3ad879b_0openssl=1.1.1w=h7f8727e_0orjson=3.10.2=pypi_0packaging=24.0=pypi_0pandas=2.2.2=pypi_0piexif=1.1.3=pypi_0pillow=9.5.0=pypi_0pillow-avif-plugin=1.4.3=pypi_0pip=23.3.1=py39h06a4308_0protobuf=3.20.0=pypi_0psutil=5.9.5=pypi_0pydantic=1.10.15=pypi_0pydub=0.25.1=pypi_0pyparsing=3.1.2=pypi_0python=3.9.0=hdb3f193_2python-dateutil=2.9.0.post0=pypi_0python-multipart=0.0.9=pypi_0pytorch-cuda=11.7=h778d358_5pytorch-lightning=1.9.4=pypi_0pytorch-mutex=1.0=cudapytz=2024.1=pypi_0pywavelets=1.6.0=pypi_0pyyaml=6.0.1=pypi_0readline=8.2=h5eee18b_0referencing=0.35.1=pypi_0regex=2024.4.28=pypi_0requests=2.31.0=py39h06a4308_1resize-right=0.0.2=pypi_0rpds-py=0.18.0=pypi_0safetensors=0.4.2=pypi_0scikit-image=0.21.0=pypi_0scipy=1.13.0=pypi_0semantic-version=2.10.0=pypi_0sentencepiece=0.2.0=pypi_0setuptools=68.2.2=py39h06a4308_0six=1.16.0=pyhd3eb1b0_1smmap=5.0.1=pypi_0sniffio=1.3.1=pypi_0spandrel=0.1.6=pypi_0sqlite=3.45.3=h5eee18b_0starlette=0.26.1=pypi_0sympy=1.12=pypi_0tifffile=2024.4.24=pypi_0timm=0.9.16=pypi_0tk=8.6.12=h1ccaba5_0tokenizers=0.13.3=pypi_0tomesd=0.1.3=pypi_0toolz=0.12.1=pypi_0torch=2.0.1=pypi_0torchaudio=2.0.2=pypi_0torchdiffeq=0.2.3=pypi_0torchmetrics=1.3.2=pypi_0torchsde=0.2.6=pypi_0torchvision=0.15.2=pypi_0tqdm=4.66.2=pypi_0trampoline=0.1.2=pypi_0transformers=4.30.2=pypi_0triton=2.0.0=pypi_0typing-extensions=4.11.0=pypi_0typing_extensions=4.9.0=py39h06a4308_1tzdata=2024.1=pypi_0urllib3=2.2.1=pypi_0uvicorn=0.29.0=pypi_0wcwidth=0.2.13=pypi_0websockets=11.0.3=pypi_0wheel=0.41.2=py39h06a4308_0xz=5.4.6=h5eee18b_1yarl=1.9.4=pypi_0zipp=3.18.1=pypi_0zlib=1.2.13=h5eee18b_1zstd=1.5.5=hc292b87_2

安装shell命令

conda install --yes --file requirements.txt

2、配置Stable Diffusion webUI项目

(1)克隆项目

目前克隆版本号为:v1.9.3。如果下载进度断了,建议下载后解压到目录下即可。

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

然后切换到项目根目录下,输入命令:cd stable-diffusion-webui

(2)提前配置【可选,推荐配置】

切换到第三方包文件夹下cd stable-diffusion-webui/repositories,提前安装open_clip(v2.24.0)和generative-models,离线安装open_clip具体命令如下:

git clone https://github.com/mlfoundations/open_clip.gitcd open_clippython setup.py build install

离线安装generative-models具体命令如下:

git clone https://github.com/Stability-AI/generative-models.gitcd generative-modelspython setup.py build install

如果在下面安装的过程中存在某些包拉取中断可以直接本地下载后再进行安装即可。笔者只遇到以上两个包安装存在中断的现象。

(3)运行脚本

方式一:bash start.sh配置环境到根目录下的文件,项目根目录下会生成一个venv文件用于存放python环境文件包。

如果使用该环境下的python的话,要找到文件夹里面的python执行脚本,比如:

一般在conda或者pip环境下执行python launch.py,那么如果要使用venv文件夹里的环境就需要执行/venv/bin/python launch.py

个人觉得比较麻烦,该环境复用性比较差,运行python不方便,所以后面都用第二种方式(如下面)

方式二:python launch.py,命令过程中如果发现某些包没有装,如进行安装,建议按照上述章节提前安装好,不然会出现网络问题而终止。

笔者运行命令行结果如下(推理了一次,红色字体是因为笔者没有设置外网映射,默认这个设置是不开的,“如果你想要的话需要去weibu.py中将shared.demo.launch()第一行,改为share=True”):

(4)下载预训练权重

项目中models目录下会有一个存放模型路径(model/Stable-diffusion/),从https://hf-mirror.com/LarryAIDraw/v1-5-pruned-emaonly/tree/main下载v1-5-pruned-emaonly.ckpt存放到该路径下。如果你想生成人像比较逼真的话需要从https://hf-mirror.com/92john/chilloutmix_NiPrunedFp32Fix.safetensors/tree/main下载一个chilloutmix_NiPrunedFp32Fix.safetensors模型文件,放到model/Stable-diffusion/目录下,然后再接下来的web界面上选择对应的模型就可以了。

打开本地7860端口,界面如下(选择好存放的模型):

在这里插入图片描述

测试图片示例展示如下:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

3、遇到的问题

问题1

version libcudnn_ops_infer.so.8 not defined in file libcudnn_ops_infer.so.8 with link time reference.

解决方法:命令行输入:conda install -c conda-forge cudnn安装cudnn和cudatoolkit。

问题2

OSError: Can’t load tokenizer for ‘openai/clip-vit-large-patch14’. If you were trying to load it from ‘https://huggingface.co/models’, make sure you don’t have a local directory with the same name. Otherwise, make sure ‘openai/clip-vit-large-patch14’ is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.

解决方法:下面https://huggingface.co/openai/clip-vit-large-patch14/tree/main的文件到stable-diffusion-webui/openai这个文件目录下(如果没有就创建)。参考【download files from https://huggingface.co/openai/clip-vit-large-patch14/tree/main and put them into the directory stable-diffusion-webui/openai (create it if doesn’t exist)】

国内专用安装命令:(不用加.git

git clone https://hf-mirror.com/openai/clip-vit-large-patch14 问题3

cannot import name ‘COMMON_SAFE_ASCII_CHARACTERS‘ from ‘charset_normalizer.constant’.

解决方法:安装chardet:pip install chardet

4、参考

[1] https://zhuanlan.zhihu.com/p/611519270

[2] https://blog.csdn.net/weixin_40735291/article/details/129333599

[3] https://github.com/pytorch/pytorch/issues/104591

[4] https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/11507

[5] https://blog.csdn.net/weixin_47037450/article/details/129616415



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。