关于SD webui 部署运行的一些坑

[Bug 1]: RuntimeError: Couldn't install gfpgan

可以先尝试:

pip install gfpgan

不过是在虚拟环境venv下的

E:\stable-diffusion-webui\venv\Scripts\python.exe -m pip install gfpgan

如果还是无法安装gfpgan的原因是网络问题,就算已经科学上网,并设置为全局,也无法从github上下载源代码,从而导致install失败。
解决方法是直接到github下载 GFPGAN 代码到本地,并进行本地安装。
因为stable diffusion会在其根目录创建虚拟python环境venv,因此安装方法与github有所不同。可参考以下方法:

  1. 从github将GFPGAN的源文件下载到本地,这一步可以使用git clone也可以直接下载zip文件。下载后,解压(如果用git clone就不需要)到d:\\stable-diffusion-webui\venv\Scripts目录下(stable-diffusion-webui是你stable diffusion webui的根目录,这个地址只是我电脑中的,请根据自己放的位置调整)。
  2. 打开cmd,cd到d:\\stable-diffusion-webui\venv\Scripts\GFPGAN-master下。
  3. 使用命令d:\\stable-diffusion-webui\venv\Scripts\python.exe -m pip install basicsr facexlib安装GFPGAN的依赖。
  4. 再使用d:\\stable-diffusion-webui\venv\Scripts\python.exe -m pip install -r requirements.txt安装GFPGAN的依赖。
  5. 使用E:\\stable-diffusion-webui\venv\Scripts\python.exe setup.py develop安装GFPGAN。

安装完毕后,再打开stable diffusion根目录的webui-user.bat会发现不再要求安装GFPGAN。如果遇到其他github上的模块无法安装也可以用同样的方法

[Bug 2]: AssertionError: Torch is not able to use GPU;

解决方法:修改launch.py代码:

关于SD webui 部署运行的一些坑_第1张图片

launch.py
问题分析:查了一下似乎是CUDA和torch版本不匹配的问题,但我的CUDA版本是每问题的。所以把相关的两行注释掉,绕过这个检测好了。建议先检查一下自己的版本,实在不行再用我的这个方法。

2.23更新 实际上这个问题很可能是因为.bat自动安装了CPU版本的torch,所以无法使用CUDA。

建议检查一下python环境里能不能用CUDA和torch的版本

关于SD webui 部署运行的一些坑_第2张图片

不能用CUDA

关于SD webui 部署运行的一些坑_第3张图片

检查torch版本:cpu
解决方法:

查看自己NVIDIA的版本,如果是11.1或者以下的,建议先升级一下

关于SD webui 部署运行的一些坑_第4张图片

升级地址:https://www.nvidia.cn/Download/index.aspx?lang=cn 

关于SD webui 部署运行的一些坑_第5张图片

选择自己的显卡配置,搜索,下载,下一步安装更新即可

然后用pip uninstall torch卸载cpu版本的torch

到torch官网https://pytorch.org/get-started/locally/ 选择自己匹配的版本,复制命令自行安装torch

关于SD webui 部署运行的一些坑_第6张图片

复制红框框里的命令安装torch,我是用pip比较快
安装完后检查是GPU版本能用CUDA就OK了

GPU版本,能用CUDA

参考:自力更生:Stable Diffusion webui本地部署遇到的坑及解决 - 哔哩哔哩

python查看torch版本、cuda版本

import torch
print(torch.cuda.is_available()) # 查看cuda是否可用
print(torch.cuda.device_count()) # 查看可用cuda数量
print(torch.__version__) # 查看pytorch版本
print(torch.version.cuda) # 查看cuda版本

具体可参考:深度学习中如何在本地安装符合自己版本的Torch - 哔哩哔哩

pytorch 中 GPU 索引与 nvidia-smi 中GPU 编号不一致,原因是nvidia-smi 下的 GPU 编号默认使用 PCI_BUS_ID,而 PyTorch 代码默认情况下设备排序是 FASTEST_FIRST。解决方法为,进入bashrc,添加:

CUDA_DEVICE_ORDER=“PCI_BUS_ID“

终端输入 source ~/.bashrc 使配置生效。

补充遇到的一个大坑:torch.cuda.is_available总是false,torch.version.cuda返回None

原因是pytorch官网默认安装的是最新的版本,点击 install previous versions of PyTorch 移步到历史版本

关于SD webui 部署运行的一些坑_第7张图片

,我这边用的是

# CUDA 11.7
pip install torch==2.0.0+cu117 torchvision==0.15.1+cu117 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu117

它自动删除本地已有的torch,再进行安装,然后你执行 

print(torch.version.cuda) #11.7

就能看到安装了11.7版本的cuda了,再执行生图脚本也使用的是GPU

[Bug 3]: RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'

[Bug]: RuntimeError: "LayerNormKernelImpl" not implemented for 'Half' · Issue #5232 · AUTOMATIC1111/stable-diffusion-webui · GitHub

一般都是在 COMMANDLINE_ARGS 里加 --no-half 参数

免部署直接体验AI绘图:GPT问答+AI绘图

你可能感兴趣的:(java,html,开源)