Stable Diffusion web UI 用CPU畫(huà)畫(huà)
????????之前用Stable Diffusion web UI項(xiàng)目搭建了一個(gè)用GPU畫(huà)畫(huà)的服務(wù),但是無(wú)奈電腦顯卡內(nèi)存只有2G,搭建成功沒(méi)過(guò)多久,也就畫(huà)了2到3張就不行了,一啟動(dòng)就OutOfMemory。好在它支持調(diào)用CPU進(jìn)行作畫(huà),現(xiàn)將搭建過(guò)程分享給大家。
????????如果朋友們實(shí)在用Linux系統(tǒng)搭建有難度,可以聯(lián)系我,我把VMware的系統(tǒng)包分享給你們,裝上就能用了;
一、配置清單
????設(shè)備配置: VMware虛擬機(jī)1臺(tái)
????操作系統(tǒng): CentOS7.9
????CPU: 4核心? #多多益善
????內(nèi)存: 12G? #至少需要這么多,如果內(nèi)存富裕,多多益善。
????磁盤(pán): 200G
????注意:關(guān)閉selinux、關(guān)閉防火墻、清空防火墻規(guī)則
二、安裝python環(huán)境
python環(huán)境版本為3.10.6,采用編譯安裝的方式
# 配置epel源
????yum install epel-release -y
????yum clean all
# 安裝源碼編譯需要的編譯環(huán)境
????yum?install gcc zlib zlib-devel libffi libffi-devel readline-devel -y
#安裝openssl11,后期的pip3安裝模塊需要用到ssl模塊
????yum install openssl-devel openssl11 openssl11-devel -y
#安裝UI項(xiàng)目所需模塊(報(bào)了數(shù)不清的錯(cuò)之后含淚整理的)
????yum install xz-devel?python-backports-lzma?bzip2-devel?mesa-libGL.x86_64
# 設(shè)置編譯FLAG,以便使用最新的openssl庫(kù)
vim /etc/profile,用vim編輯該文件,將其放在文件最后,并重新加載該文件
????export CFLAGS=$(pkg-config --cflags openssl11)
????export LDFLAGS=$(pkg-config --libs openssl11)
source /etc/profile? # 重新加載該文件
#安裝
????wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz
????tar xvf Python-3.10.6.tar.xz
????mkdir -pv /usr/local/python3
????cd Python-3.10.6
????./configure --prefix=/usr/local/python3 --with-ssl
????make
????make install
#替換原有openssl的鏈接
????ln -s /usr/python/bin/python3 /usr/bin/python3_11
????ln -s /usr/python/bin/pip3 /usr/bin/pip3_11
#定義環(huán)境變量
[root@localhost data]# cat /etc/profile.d/python3.sh
export PY3_HOME=/usr/local/python3
export PATH=$PATH:$PY3_HOME/bin
#加載環(huán)境變量
source?/etc/profile.d/python3.sh
#驗(yàn)證
[root@localhost data]# python3 -V
Python 3.10.6
三、給服務(wù)器配置能科學(xué)上網(wǎng)
因?yàn)榻酉聛?lái)的動(dòng)作,沒(méi)有這玩意根本玩不轉(zhuǎn)。
vim /etc/profile? # 編輯該文件,將下面的配置放在最后并用source重載該文件
export http_proxy='http://代理ip:代理端口'
export https_proxy='http://代理ip:代理端口'
四、安裝CUDA
官網(wǎng)地址:?https://pytorch.org/get-started/locally/

注意:如果提示需要升級(jí)pip,那就給它升級(jí)一下。
五、安裝git
請(qǐng)不要用yum install git安裝,這么安裝的git版本太低,不支持-C參數(shù),然后你執(zhí)行l(wèi)aunch.py腳本的時(shí)候會(huì)報(bào)錯(cuò)。如果已經(jīng)yum安裝的,請(qǐng)yum remove將其卸載。
git版本:2.22.0? 采用編譯安裝
git下載地址:https://mirrors.edge.kernel.org/pub/software/scm/git/
#安裝依賴(lài)
????yum install curl curl-config curl-devel expat-devel gettext-devel zlib-devel gcc perl-ExtUtils-MakelMaker -y
#安裝
????wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.22.0.tar.gz
????mkdir -pv /usr/local/git
????tar xvf?git-2.22.0.tar.gz
????cd?git-2.22.0
????./configure --prefix=/usr/local/git
????make
????make install
#配置環(huán)境變量
[root@localhost git-2.22.0]# cat /etc/profile.d/git.sh
export GIT_HOME=/usr/local/git
export PATH=$PATH:$GIT_HOME/bin
#加載配置
source /etc/profile.d/git.sh
#驗(yàn)證
[root@localhost git-2.22.0]# git version
git version 2.22.0
六、克隆項(xiàng)目
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git?
七、安裝項(xiàng)目所需依賴(lài)
cd?stable-diffusion-webui
python3 -m pip install -r requirements.txt
這步會(huì)花很長(zhǎng)時(shí)間:需要耐心等待?。。?!
八、運(yùn)行項(xiàng)目
# 將下載好的模型文件放置在該目錄下
/data/stable-diffusion-webui/models/Stable-diffusion

注意:data是我的路徑,這個(gè)需要朋友們自定義,其他路徑不變,需要模型文件的私信我,我用的模型文件可以畫(huà)二次元人物。
# 運(yùn)行
[root@localhost stable-diffusion-webui]# python3 launch.py --skip-torch-cuda-test --no-gradio-queue --precision full --no-half
這步也會(huì)花很長(zhǎng)時(shí)間,要下載一些依賴(lài),需要耐心等待?。?!

????????當(dāng)你們看到這個(gè)界面的時(shí)候,恭喜你們,搭建成功了;

九、配置反向代理,使其能被訪(fǎng)問(wèn)
????????因?yàn)閣eb UI監(jiān)聽(tīng)的是本地的7860端口,你的電腦是不能訪(fǎng)問(wèn)的,這時(shí)候就需要nginx來(lái)做反向代理,使其能訪(fǎng)問(wèn);
# 安裝nginx
yum install nginx -y
# 配置nginx

# 重載nginx服務(wù)
systemctl reload nginx
十、愉快的玩耍吧
將你的服務(wù)器IP地址輸入瀏覽器開(kāi)始愉快的玩耍吧

# 嘗試畫(huà)張畫(huà)



# 前臺(tái)已經(jīng)初見(jiàn)成效了,開(kāi)心?。?!
Prompt 輸入 :
(((masterpiece))),best quality, illustration,(beautiful detailed girl),beautiful detailed glow,detailed ice,beautiful detailed water,(beautiful detailed eyes),expressionless,(floating palaces),azure hair,disheveled hair,long bangs, hairs between eyes,(skyblue dress),black ribbon,white bowties,midriff,{{{half closed eyes}}},big forhead,blank stare,flower,large top sleeves
Negative prompt 輸入
owres,bad anatomy,bad hands,text,error,missing fingers,extra digit,fewer digits,cropped,worst quality,low quality,normal quality,jpeg artifacts,signature,watermark,username,blurry,missing fingers,bad hands,missing arms,large breasts

生成后的文件保存在這:/data/stable-diffusion-webui/outputs/txt2img-images

十一、報(bào)錯(cuò)總結(jié)

參考地址:https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/8334
這個(gè)報(bào)錯(cuò)是需要?jiǎng)h除/root/.cache/huggingface;因?yàn)榫彺娴奈募_突了。需要?jiǎng)h除緩存文件重新生成;
##############

參考地址:https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/9074
參考地址:https://github.com/facebookresearch/fairseq/issues/2413
#######################

解決辦法:yum install xdg-utils -y