win 安装 Stable Diffusion

注:本人使用的是 RTX2060 - 6G版

特别提醒安装一定要 CUDA 和 PyTorch 版本能配套用,不然会有生成保存问题(我是这样的),装完用 python -m xformers.info 这个看对应的版本

建议:有些命令安装在venv 虚拟机中做,这样东西都在venv对应目录

在最后有些资源,我在对应官网下了放在百度网盘,有些下的慢的,可以去里面下

安装Git

https://registry.npmmirror.com/-/binary/git-for-windows/v2.38.1.windows.1/Git-2.38.1-64-bit.exe

安装python3.10.6

官方的
https://www.python.org/ftp/python/3.10.6/python-3.10.6-amd64.exe

华为代理的
https://mirrors.huaweicloud.com/python/3.10.9/python-3.10.9-amd64.exe

注意:

Windows下安装Python时,请务必勾选"Add Python to PATH",以后我们调度Python时会方便很多。

如果你选择的是自定义安装,请务必在安装组件选择中勾选PIP(Python的包管理工具,无论是在接下来的安装中还是后续的使用中,我们都需要用到它)。

Nvidia CUDA(按需)

注意:如果CUDA版本不对,卸载对应版本后,删除C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA目录下的版本文件

https://developer.download.nvidia.com/compute/cuda/12.1.1/local_installers/cuda_12.1.1_531.14_windows.exe

下载并安装Microsoft C++生成工具(默认安装即可)(按需)

https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/

安装cuDNN cuDNN Archive | NVIDIA Developer

https://developer.download.nvidia.cn/compute/cudnn/secure/8.9.2/local_installers/12.x/cudnn-windows-x86_64-8.9.2.26_cuda12-archive.zip

安装 PyTorch 查看对应和安装命令 Start Locally | PyTorch

就像不同的Nvidia驱动版本固定搭配不同的CUDA版本一样,不同的Torch版本也固定搭配不同的CUDA版本使用。

pip uninstall xformers(按y卸载旧版xformers0.17)

pip uninstall torch(按y卸载旧版torch 2.0.1+cu118)

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

安装报错一、

ERROR: Exception:
Traceback (most recent call last):
  File "E:\ai\stable-diffusion-webui\venv\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher
    yield
  File "E:\ai\stable-diffusion-webui\venv\lib\site-packages\pip\_vendor\urllib3\response.py", line 561, in read
    data = self._fp_read(amt) if not fp_closed else b""
  File "E:\ai\stable-diffusion-webui\venv\lib\site-packages\pip\_vendor\urllib3\response.py", line 527, in _fp_read
    return self._fp.read(amt) if amt is not None else self._fp.read()
  File "E:\ai\stable-diffusion-webui\venv\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 98, in read
    data: bytes = self.__fp.read(amt)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 465, in read
    s = self.fp.read(amt)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\socket.py", line 705, in readinto
    return self._sock.recv_into(b)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1274, in recv_into
    return self.read(nbytes, buffer)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1130, in read
    return self._sslobj.read(len, buffer)
TimeoutError: The read operation timed out

1)、在环镜变量中加python安装目录

2)、在python安装目录中复制文件名

pythonw.exe -> pythonw3.exe

python.exe -> python3.exe

安装xformers 先查看是否有装并查看支持的对应版本

python -m xformers.info

pip install xformers

创建并配置Venv虚拟环境和安装PIP包

python -m venv .\venv

cd .\venv\Scripts
activate.bat

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
cd ../..

pip install -r requirements_versions.txt # 执行此条命令前,请检查你的剩余磁盘空间

再次运行上面命令,就成功了

修改配置(根据自己情况修改)

修改配置1、我们下的cu121 所以我改成whl/cu121( 如果是,就不用改)

路径:stable-diffusion-webui\modules\launch_utils.py

    torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu121")
修改配置2、开放外网访问

set COMMANDLINE_ARGS=--listen (加入这个参数 --listen 后面也有空格)

局域网下启动SD的方法:

在浏览器里边输入启动SD的那台电脑的IP地址+端口,即可打开SD使用

例如本机IP为,192.168.31.22,根据SD返回的http://0.0.0.0:7860,就需要把http://0.0.0.0,替换为http://192.168.31.22,然后加上端口,http://192.168.31.22:7860,即可在同一WiFi直接使用SD

安装必要的库 在stable-diffusion-webui目录(用webui-user.bat 一直超时报错)

cd ./repositories
git clone https://github.com/salesforce/BLIP.git
git clone https://github.com/sczhou/CodeFormer.git
git clone https://github.com/crowsonkb/k-diffusion.git
git clone https://github.com/Stability-AI/generative-models.git
git clone https://github.com/Stability-AI/stablediffusion.git stable-diffusion-stability-ai

如果xformes安装有问题,可以下源码后再安装,在stable-diffusion-webui目录(备用)

git clone https://github.com/facebookresearch/xformers.git
cd xformers
git submodule update --init --recursive

如果不行,也可以用下源码,下下来放对应目录 

git clone https://github.com/NVIDIA/cutlass.git third_party/cutlass
git clone https://github.com/Dao-AILab/flash-attention.git third_party/flash-attention
git clone https://github.com/ROCm/composable_kernel.git third_party/composable_kernel_tiled

下载模型

模型 1、官方使用 https://huggingface.co这一超时,我使用他的镜像网站 https://hf-mirror.com

https://hf-mirror.com/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors

启动文件配置

#设置python路径

set PYTHON=C:\Users\admin\AppData\Local\Programs\Python\Python310\python.exe

#设置git的路径

set GIT=C:\Program Files\Git\bin\git.exe

#设置venv文件夹路径

set VENV_DIR=E:\ai\stable-diffusion-webui\venv

#设置启动参数 (注:此处的"--medvram"是针对6GB及以上显存的显卡优化的,根据显卡配置的不同,你还可以更改为"--lowvram"(4GB以上)、"--lowram"(16GB以上)或者删除此项(无优化))

set COMMANDLINE_ARGS=--medvram --deepdanbooru --xformers

优化:说是能图片生成解析更快

set COMMANDLINE_ARGS=--medvram --deepdanbooru --reinstall-xformers --xformers

汉化处理

接着,我们会发现WebUI显示的并不是中文。此时,我们需要将其调整为简体中文。这里,我用百度网盘分享了一些语言的补丁。

链接:https://pan.baidu.com/s/1X7R4nQfAxHKdoXRWyknSxg
提取码:annx

下载我分享的"localizations.zip"并解压到克隆文件夹的"localizations"目录中。之后在Settings -> User interface -> Localization (requires restart)设置语言(在下拉菜单中选择zh_CN)。然后重新启动WebUI之后,你就会发现语言变成了简体中文

生成时报错处理

错误1、 openai/clip-vit-large-patch14

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.

安装 openai/clip-vit-large-patch14

当前在 stable-diffusion-webui 目录

mkdir openai
cd openai
git clone https://www.modelscope.cn/AI-ModelScope/clip-vit-large-patch14.git

创建目录 openai 进入 opena

错误 2、xformers未安装 查看版本xformers信息

NotImplementedError: No operator found for `memory_efficient_attention_forward` with inputs:

python -m xformers.info

pip install -U xformers --index-url https://download.pytorch.org/whl/cu121

如果些文章对您有帮助或有解决您的问题,随手打赏一杯咖啡

有些资源不好下载的可以去我的百度网盘下,后续有需要再补充

(python3.6,Git-2.38.1-64-bit,cudnn-windows-x86_64-8.9.2.26_cuda12-archive,cuda_12.1.1_531.14_windows,DevSidecar-1.7.3)

链接:https://pan.baidu.com/s/1SZa-uSRDELl8r4SG97puWw

提取码:sdai

参数文档:

1)、最细Stable Diffusion2.1+WebUI的安装部署教程(非大佬整合包,Revirsion) - 哔哩哔哩

2)、【AI】Stable-Diffusion-WebUI使用指南_stable diffusion webui-CSDN博客

3)、Stable Diffusion升级torch2.1.0.dev+cuda12.1.1+cudnn8.9.2.26+xforme - 哔哩哔哩

相关推荐
笃励16 分钟前
Java面试题二
java·开发语言·python
一颗星星辰1 小时前
Python | 第九章 | 排序和查找
服务器·网络·python
打码人的日常分享1 小时前
企业人力资源管理,人事档案管理,绩效考核,五险一金,招聘培训,薪酬管理一体化管理系统(源码)
java·数据库·python·需求分析·规格说明书
27669582921 小时前
京东e卡滑块 分析
java·javascript·python·node.js·go·滑块·京东
unix2linux1 小时前
Parade Series - SHA256
linux·python·mysql·shell
巽星石2 小时前
【Blender Python】7.一些运算、三角函数以及随机
python·blender·三角函数·随机·环形阵列
CSXB992 小时前
一、Python(介绍、环境搭建)
开发语言·python·测试工具·集成测试
Mopes__2 小时前
Python | Leetcode Python题解之第461题汉明距离
python·leetcode·题解
EterNity_TiMe_2 小时前
【机器学习】智驭未来:探索机器学习在食品生产中的革新之路
人工智能·python·机器学习·性能优化·学习方法
Mopes__3 小时前
Python | Leetcode Python题解之第452题用最少数量的箭引爆气球
python·leetcode·题解