最近先后在Windows和Linux设置成功stable-diffusion-webui的环境,现记录一下过程,希望对其他人有用

显卡:Nvidia Geforce RTX 3090

Windows 11

时间:2023/04/30

1. 主流程基本按照这篇知乎文章来的:喂饭级stable_diffusion_webUI使用教程 - 知乎 (zhihu.com),这其中安装git,安装python3,都比较简单

2. Windows装好,Nvidia驱动也就装好了。安装cuda组件,选了和我自己CUDA driver 版本号一致的,没有选最新版

 

 

3. 按知乎文章描述,直接启动webui-user.bat,为了下载包方便,开启了代理,但仍然会碰到一些错误。典型的有:

   3.1 “RuntimeError: Couldn't install gfpgan”,按使用stable diffusion webui时,安装gfpgan失败的解决方案(windows下的操作)_新时代原始人的博客-CSDN博客 解决

   3.2  Clip 安装不上,按打开stable diffusion webui时,提示缺少clip或clip安装不上的解决方案(windows下的操作)_新时代原始人的博客-CSDN博客 解决

   3.3  界面能启动成功,但控制台提示no module ‘xformer’,按How to fix the error No module 'xformers'. Proceeding without it. in Stable diffusion automatic 1111? : r/StableDiffusion (reddit.com) 解决

   3.4 启动后输入提示词,界面显示 'somethign went wrong', 按[Bug]: Something went wrong Expecting value: line 1 column 1 (char 0) · Issue #9150 · AUTOMATIC1111/stable-diffusion-webui · GitHub 描述,去掉代理即可

 

最终,

webui-user.bat 内容如下:

-------------------------------------------------------------------------------------------------------------------------

 @echo off

set PYTHON=C:\Users\kzhan\AppData\Local\Programs\Python\Python310\python.exe
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=--xformers

call webui.bat

-------------------------------------------------------------------------------------------------------------------------

启动成功的控制台提示信息长这样:

 启动成功的webui-stable-diffusion长这样:

 这个环境测试的第一张 AIGC图片,prompt:a blue dog sitting on a white paper

 

Ubuntu 20.04

时间:2023.05.20

如果全新安装,那么按照这一篇博客来是最好的:https://ivonblog.com/en-us/posts/linux-stable-diffusion-webui/

 

下面记录碰到过的问题以及解决方法:

1. 安装Nvidia驱动。我的方法是使用Ubuntu自带的“软件和更新”,勾选NVIDIA最新的驱动即可

 

 

2. 安装CUDA Toolkit.

基本上,按照官网步骤来就可以。安装完,一定要做官网这里的Post-installation Actions, 来设置好环境变量,否则 nvcc --version 会提示找不到命令。

提示找不到命令的错误信息里,有提示如何安装nvcc toolkit 的命令。此时如果按照提示的命令执行,会安装一个老版本的nvcc,其实这是不必要的。按照上面说的设置好环境变量即可。如果想卸载老版本nvcc,那么可以按这里的步骤来进行: https://medium.com/@lyl1617670866/how-to-update-cuda-and-cudnn-on-ubuntu-18-04-4bfb762cf0b8 。但其实不卸载应该也可以,我最后就没卸载

这篇StackOverflow 问答详细的解释了为什么有时候nvcc --version和nvidia-smi命令输出的版本号不同

 

3. 如果Nvidia驱动和CUDA Toolkit都装好,那么:

运行 nvcc --version,会显示:

 运行 nvidia-smi,会显示:

 

4. 下载好 stable-diffusion-webui 的git repo, 安装好 python 等之后,直接运行 ./webui.sh,在启动 log 里碰到了“Cannot locate TCMalloc (improves CPU memory usage)”的错误,按https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/10117 里提到的 "sudo apt-get install libgoogle-perftools4 libtcmalloc-minimal4 -y" 命令解决

5. 启动stable-diffusion-webui 界面后,输入prompt,生成图片报错:“RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! ”,按 https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/2373 解决,即在 .webui-user.sh里加上如下启动参数

export COMMANDLINE_ARGS="--precision full --no-half --lowvram --always-batch-cond-uncond --opt-split-attention"

 之后运行 ./webui.sh 即可正常运行

6. 运行过程中出现“RuntimeError: CUDA out of memory. Tried to allocate 8.00 GiB ... try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF”,按https://stackoverflow.com/questions/73747731/runtimeerror-cuda-out-of-memory-how-setting-max-split-size-mb 设置环境变量 “export 'PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512'” 解决

附上prompt: a robot talk to another robot  in a street side coffe shop 的图

posted on 2023-04-30 14:44  Kai.Zhang  阅读(2787)  评论(0编辑  收藏  举报