20240203在Ubuntu20.04.6下配置stable-diffusion-webui.git

20240203在Ubuntu20.04.6下配置stable-diffusion-webui.git
2024/2/3 11:55

【结论:在Ubuntu20.04.6下,生成512x512分辨率的图像,大概需要11秒钟!】
前提条件,可以通过技术手段上外网!^_
首先你要有一张NVIDIA的显卡,比如我用的PDD拼多多的二手GTX1080显卡。【并且极其可能是矿卡!】800¥
2、请正确安装好NVIDIA最新的545版本的驱动程序和CUDA、cuDNN。
2、安装Torch
3、配置whisper


【本文以这个教程为主】
https://www.bilibili.com/read/cv24784581/
Stable Diffusion云服务器部署完整版教程


【这个没有走通】
https://www.toutiao.com/article/7222852915286016544/
从零开始,手把手教本地部署Stable Diffusion AI绘画 V3版 (Win最新)


(二)配置运行环境
利用anaconda是它集成了很多我们需要的安装包,只要安装它一个,python下载、环境配置那些都不用我们再去设置,使用起来比较方便。

1、配置Anaconda
1、下载anaconda【深圳联通下载不了】
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2023.03-0-Linux-x86_64.sh

若遇到这种不能下载的,前面加上 -U NoSuchBrowser/1.0
wget -U NoSuchBrowser/1.0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2023.03-0-Linux-x86_64.sh


2.安装anaconda,提示enter按回车,提示yes or no的地方全部输入yes即可。vscode不安装
bash Anaconda3-2023.03-0-Linux-x86_64.sh

【不需要修改】
3.找到.bashrc这个文件并修改,修改文件有两种方式:
①通过vim修改。
#用vim打开.bashrc文件
vim ~/.bashrc
#再按i开始insert,将以下内容添加到文件最后一行
export PATH=$PATH:/home/ubuntu/anaconda3/bin
#按Esc并输入:wq即为保存退出文件再保存退出
:wq
②也可以通过编辑器修改,找到.bashrc文件直接输入内容即算保存


4.如果输入conda,提示找不到命令的话执行下source,(执行一次即可,以后都不用再 source 了,启动 Ubuntu会自动source)
source ~/.bashrc
然后验证下
conda info

至此anaconda已经安装完毕


2、安装pytorch
1.去pytorch官网配置自己服务器所需要的pytorch
pytorch官网
https://pytorch.org/
https://pytorch.org/get-started/locally/

Pytorch build选择stable稳定版,操作系统是linux,由于上面我安装了anaconda所以package选择conda,语言python,我的CUDA是12.0所以选择了CUDA11.8,最后获取comand
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia


2、pytorch需要安装到anaconda的虚拟环境中,所以使用conda时需要先有一个虚拟环境并进入

#若还没有虚拟环境需要创建一个,<env_name>是环境名称,python选择指定的版本,sd需要的python>3.10 #conda create -n <env_name> python=x.xx.x
conda create -n sd python=3.10.11

#启动虚拟环境,activate就是启动,sd是环境名称
conda activate sd

然后再执行pytorch的安装
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

如果出现提示需要升级conda版本的就输入,没有的话就跳过这步。我这里没截到图,会有个wanning的,注意看

conda update -n base -c defaults conda
验证安装结果

#首先要启动我们的sd虚拟环境,因为我们所有与stable diffusion有关的配置环境都是建立在这个虚拟环境之下的python,pytorch等都是如此
#进入虚拟环境
conda activate sd

#进入python环境
python

#导入torch
import torch

#查看torch的版本
torch.__version__  #各有两条下划线

#查看cuda版本
torch.version.cuda

#查看GPU是否运行
torch.cuda.is_available()

#退出
exit()


(三)安装sd-webui
1、启动sd
1.将sd webui clone到服务器上,此处我用了镜像。【下载异常了】
git clone https://github.moeyy.xyz/https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

(sd) rootroot@rootroot-X99-Turbo:~$ 
(sd) rootroot@rootroot-X99-Turbo:~$ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Cloning into 'stable-diffusion-webui'...
remote: Enumerating objects: 31156, done.
remote: Counting objects: 100% (159/159), done.
remote: Compressing objects: 100% (100/100), done.
remote: Total 31156 (delta 81), reused 110 (delta 48), pack-reused 30997
Receiving objects: 100% (31156/31156), 33.66 MiB | 7.55 MiB/s, done.
Resolving deltas: 100% (21819/21819), done.
(sd) rootroot@rootroot-X99-Turbo:~$ du -sh stable-diffusion-webui/
39M    stable-diffusion-webui/
(sd) rootroot@rootroot-X99-Turbo:~$ 

(sd) rootroot@rootroot-X99-Turbo:~$ tar zcvf stable-diffusion-webui99.tar.gz stable-diffusion-webui/

【不处理】
2.链接换源。打开stable-diffusion-webui/modules/launch.until.py文件,替换以下内容
torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1 torchvision==0.15.2")

【不处理】
3.每个https://github.com/  (就在上一步的下面几行,每一个网址都要改)链接前面添加https://ghproxy.com/,替换为以下内容

gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "https://ghproxy.com/https://github.com/TencentARC/GFPGAN/archive/8d2447a2d918f8eba5a4a01463fd48e45126a379.zip")
clip_package = os.environ.get('CLIP_PACKAGE', "https://ghproxy.com/https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip")
openclip_package = os.environ.get('OPENCLIP_PACKAGE', "https://ghproxy.com/https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip")
stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://ghproxy.com/https://github.com/Stability-AI/stablediffusion.git")
taming_transformers_repo = os.environ.get('TAMING_TRANSFORMERS_REPO', "https://ghproxy.com/https://github.com/CompVis/taming-transformers.git")
k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://ghproxy.com/https://github.com/crowsonkb/k-diffusion.git')
codeformer_repo = os.environ.get('CODEFORMER_REPO', 'https://ghproxy.com/https://github.com/sczhou/CodeFormer.git')
blip_repo = os.environ.get('BLIP_REPO', 'https://ghproxy.com/https://github.com/salesforce/BLIP.git')


4.先进入虚拟环境

#启动虚拟环境,因为刚刚上面我们已经创建过虚拟环境了
conda activate sd
5.先定位到的stable-diffusion-webui项目下

cd stable-diffusion-webui
6.第一次启动sd,sd会安装基础的配置,这里等待一段时间,网速慢的个把小时,所需要的内容才会下载完毕。

#以下两者都是启动公网环境,二选一执行即可。
./webui.sh --listen #(推荐)

#或者加--share也可以
./webui.sh --share

#listen与share的区别在于listen启动的地址是0.0.0.0:7860,而share启动后是一个随机的地址。
7.第一次执行会自动下载“v1-5-pruned-emaonly.safetensors”这个模型,如果下载速度还行就耐心等待,如果网络慢的同学,可以先“ctrl+C”断开下载步骤,然后到C站随便下个大模型上传上去。

2、打开webui
后续我们启动stable diffusion时分为3个步骤:

#启动虚拟环境 conda activate sd #定位到sd根目录 cd stable-diffusion-webui #加listen是启动公网环境 ./webui.sh --listen

#启动虚拟环境
conda activate sd

#定位到sd根目录
cd stable-diffusion-webui

#加listen是启动公网环境
./webui.sh --listen
然后等待有出现http:/0.0.0.0:7860就说明已启动成功
。浏览器访问http://x.x.x.x(云主机公网ip):7860,出现stable diffusion内容即为成功。

webui界面

模型下载之后直接放到目录:Z:\stable-diffusion-webui\openai\clip-vit-large-patch14

https://huggingface.co/openai/clip-vit-large-patch14/tree/main
openai/clip-vit-large-patch14

(base) rootroot@rootroot-X99-Turbo:~$ cd stable-diffusion-webui/openai/clip-vit-large-patch14/
(base) rootroot@rootroot-X99-Turbo:~/stable-diffusion-webui/openai/clip-vit-large-patch14$ ll
total 6686128
drwx------ 2 rootroot rootroot       4096 2月   3 11:25 ./
drwxrwxr-x 3 rootroot rootroot       4096 2月   3 11:23 ../
-rwx------ 1 rootroot rootroot       4519 2月   3 11:11 config.json*
-rwx------ 1 rootroot rootroot 1710486359 2月   3 11:17 flax_model.msgpack*
-rwx------ 1 rootroot rootroot       1229 2月   3 11:11 .gitattributes*
-rwx------ 1 rootroot rootroot     524619 2月   3 11:11 merges.txt*
-rwx------ 1 rootroot rootroot 1710540580 2月   3 11:17 model.safetensors*
-rwx------ 1 rootroot rootroot        316 2月   3 11:12 preprocessor_config.json*
-rwx------ 1 rootroot rootroot 1710671599 2月   3 11:17 pytorch_model.bin*
-rwx------ 1 rootroot rootroot       7947 2月   3 11:11 README.md*
-rwx------ 1 rootroot rootroot        389 2月   3 11:12 special_tokens_map.json*
-rwx------ 1 rootroot rootroot 1711114176 2月   3 11:17 tf_model.h5*
-rwx------ 1 rootroot rootroot        905 2月   3 11:13 tokenizer_config.json*
-rwx------ 1 rootroot rootroot    2224003 2月   3 11:12 tokenizer.json*
-rwx------ 1 rootroot rootroot     961143 2月   3 11:13 vocab.json*

(base) rootroot@rootroot-X99-Turbo:~/stable-diffusion-webui/openai/clip-vit-large-patch14$ 
(base) rootroot@rootroot-X99-Turbo:~/stable-diffusion-webui/openai/clip-vit-large-patch14$ 
 


【时间的关系,未完待续!】
(四)小结
虽然webui已经启动,但是我们可以看到页面下边的配置
version:当前webui的版本,我在写这份文档时最新版本就是1.4,当你们看到这份文档的时候注意使用最新版本的。
python:版本是3.10.11,这个版本会比较合适,既能用xformers,刚刚安装又不会报错,我试过3.10.12、3.11这些版本,会出现安装不上,至于原因我没去深入研究,你们想要用最新版本的话就研究下怎么配置。
torch:2.0.1+cu117,sd会用到的神经网络和cuda版本,这里我cuda只有117,但是上面我安装的cuda是11.8。我不知道为什么会降一个版本,有大佬懂得话可以评论区解答下。
xformers:N/A,等会会安装这个,能提升出图速度。
gradio:这个是AI的界面,可以不用管。
checkpoint:这个是大模型,我们还没下载,后面步骤会下载。

二、webui-user.sh文件配置
三、extensions换源
四、CheckPoint的下载
五、LoRA的下载与安装
六、VAE的下载与安装
七、ControlNet的下载与安装
八、Clip skip的配置
九、hypernetworks的下载与安装(选装)
去模型网站上下载hypernetworks的模型,然后上传到sd/models/hypernetworks文件夹中,然后在webui界面点击刷新就可以看到了
十、插件的使用
十一、其他
(一)可下载模型的网站
https://civitai.com/
https://huggingface.co/
https://www.liblibai.com/
https://www.liandange.com/
https://i-desai.com/#/
https://aigccafe.com/
(二)如何让服务器不断开连接
(三)其他
#定位到models中的Stable-diffusion
cd stable-diffusion-webui/models/Stable-diffusion

#用wget命令来下载sd-v1-4模型
wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt

#如果出现SSL无法连接,那么加上–-no-check-certificate
wget –-no-check-certificate https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt

#如果文件太大,一次性没办法下载完,可以加上断点续传
wget –-no-check-certificate --continue https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt

十二、总结


百度:PyTorch官网
https://blog.csdn.net/K_Kelly_/article/details/131926980
安装pytorch纯小白教程||重点是要注意版本!
nvidia-smi
https://pytorch.org/
https://pytorch.org/get-started/locally/


https://blog.csdn.net/qq_40641338/article/details/128307575
ubuntu配置cuda环境三:安装PyTorch

https://blog.csdn.net/orinhshdh/article/details/134806663?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-3-134806663-blog-128307575.235%5Ev43%5Epc_blog_bottom_relevance_base1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-3-134806663-blog-128307575.235%5Ev43%5Epc_blog_bottom_relevance_base1&utm_relevant_index=6
https://blog.csdn.net/orinhshdh/article/details/134806663
Ubuntu22.04.3安装pytorch12.1和tensor flow2.15.0


https://blog.csdn.net/UCB001/article/details/130039154
2023-05-06 16:25:18 最详细的Ubuntu服务器搭建Stable-Diffusion教程(无显卡,仅用CPU)

报错gnutls_handshake() failed: The TLS connection was non-properly terminated
解决办法:在执行时使用http而不是https,替换
git clone https://github.com/Stability-AI/stablediffusion.git

为:
git clone http://github.com/Stability-AI/stablediffusion.git

百度:Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly
出问题请看这里的解决方法:
https://zhuanlan.zhihu.com/p/666288849
2023-11-11 23:50_Stable Diffusion webui 服务器搭建环境&避坑指南

模型库下载:
https://huggingface.co/openai/clip-vit-large-patch14/tree/main
openai/clip-vit-large-patch14


百度:no module 'xformers'. Processing without...
https://blog.csdn.net/qq_27144923/article/details/130787220
【Stable-Diffusion-webui】No module ‘xformers‘. Proceeding without it. 问题解决方法(Windows)
打开项目目录下launch.py文件,找到:
commandline_args = os.environ.get('COMMANDLINE_ARGS', "")

修改为:
commandline_args = os.environ.get('COMMANDLINE_ARGS', "--xformers")


https://blog.csdn.net/GranteZhou/article/details/131808110
安装stable-diffusion的错误 xformers 安装解决
pip install xformer


https://www.fujieace.com/ai/no-module-xformers.html
No module ‘xformers’ 原因与解决方法

百度:Running on local URL:  http://0.0.0.0:7860
在浏览器中输入:http://0.0.0.0:7860
即可开工了!


参考资料:
http://www.ai2news.com/blog/3071169/
超易用的国产文档问答项目: langchain-ChatGLM
准备环境
按项目说明,需要安装 python 3.8,又因为使用GPU推理,所以需要手工安装torch 2.0.1 + cuda
torch 需要请自行下载cuda对应的版本 https://mirror.sjtu.edu.cn/pytorch- wheels/cu117/?mirror_intel_list
Running on local URL:  http://0.0.0.0:7860  

百度:ubuntu stable-diffusion
https://www.bilibili.com/read/cv19811242/
【AI绘画】A卡RX580用户在Ubuntu下配置Stable-Diffusion实战(小白纯享版)


百度:git clonne repositories/generative-models
https://www.zhihu.com/question/577067020/answer/3190606301
Stable Diffusion 本地部署方法是什么?

(一)去github上下载stable-diffusion-webui-master.zip
我当时的下载链接如下:
https://codeload.github.com/ThranduilELFKING/stable-diffusion-webui/zip/refs/heads/master
(二)我解压在了本地D盘解压后路径是D:\stable-diffusion-webui-master


https://www.bilibili.com/read/cv24574966/
截止至2023-06-25 最新免魔法stable-diffusion-webui的本地安装部署方法。
一.确认本地部署硬件达到条件。(要求win10,win11等等,具体网上搜一下一大堆)


百度:stable_diffusion_xl_repo = os.environ.get('STABLE_DIFFUSION_XL_REPO', "https://github.com/Stability-
Cloning Stable Diffusion XL into /home/rootroot/stable-diffusion-webui/repositories/generative-model
Cloning into '/home/rootroot/stable-diffusion-webui/repositories/generative-models'...

https://www.bilibili.com/read/cv23306752/
Stable Diffusion WebUI下载repositories超时的问题


https://www.iotword.com/10657.html
stable-diffusion-webui手动安装详细步骤(以及报错解决、踩坑)

https://blog.csdn.net/weixin_40660408/article/details/130139799
stable-diffusion-webui手动安装详细步骤(AMD显卡)


https://www.bilibili.com/read/cv18936264/
在本地部署stable-diffusion-webui
https://www.bilibili.com/video/BV1vN4y1P7nW/?vd_source=4a6b675fa22dfa306da59f67b1f22616
AI猫雷教你快速在本地部署全功能版Stable Diffusion和Waifu Diffusion


百度:sd git clone /stable-diffusion-webui.git 
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia 网络
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata 


https://www.bilibili.com/read/cv29388784/?jump_opus=1
【教程】利用whisper模型自动生成英文粗字幕


https://blog.csdn.net/qq_43223007/article/details/130194585
本地部署Stable Diffusion Webui AI 记录


百度:ubuntu miniconda安装教程
https://blog.csdn.net/Baby_of_breath/article/details/124041687
ubuntu安装Miniconda

效果图:

  • 12
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值