一、材料準(zhǔn)備
- 一臺(tái)帶GPU的電腦,系統(tǒng)Ubuntu20.2
- Xshell和Xftp,用于連接云主機(jī),傳輸文件
我用的是阿里云ECS,型號(hào)ecs.gn6i-c4g1.xlarge(4 vCPU 15 GiB 1 * NVIDIA T4)。推薦掛一個(gè)NAS盤方便保存文件。
二、安裝步驟
- (可選)安裝顯卡驅(qū)動(dòng)
# T4顯卡的驅(qū)動(dòng)是460,在這找https://www.nvidia.com/Download/index.aspx
apt-get install nvidia-driver-460
# 試試可不可以nvidia-smi檢測(cè)顯卡狀態(tài),如果可以顯示則成功了
nvidia-smi
- 安裝Python虛擬環(huán)境
# 安裝python環(huán)境
sudo apt install wget git python3 python3-venv
如果git報(bào)錯(cuò)443,可以多試幾次,或者在/etc/hosts文件最后加一行:
140.82.113.4 github.com
↑這個(gè)IP可以從這里找到
- 創(chuàng)建個(gè)非root用戶
# --home 用戶目錄,我的NAS掛載在/mnt,所以用戶目錄就建在mnt下了
adduser --home /mnt/sd2 sd2
su sd2
cd /mnt/sd2
- 正式安裝webui,主要遵循官方[1]的方法
# 這里運(yùn)行官方的自動(dòng)化安裝腳本webui.sh
wget https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh
bash webui.sh
到這里其實(shí)已經(jīng)結(jié)束了,但是如果主機(jī)是在國(guó)內(nèi),那么一般來(lái)說(shuō)都會(huì)報(bào)錯(cuò)的,下面總結(jié)幾種我遇到的錯(cuò)誤解決方法:
ERROR: Can’t cd to /mnt/sd2/stable-diffusion-webui/, aborting…
原因:沒(méi)有成功git clone
解決方式:重試幾次一般就可以了,或者手動(dòng)下載 https://github.com/AUTOMATIC1111/stable-diffusion-webui,然后放在stable-diffusion-webui文件夾下
重試的時(shí)候要運(yùn)行
bash webui.sh
,切勿python3 launch.py
,因?yàn)槭鞘褂锰摂M環(huán)境的,比如我的python3路徑是/mnt/sd2/stable-diffusion-webui/venv/bin/python3
Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check
原因:可能是驅(qū)動(dòng)版本不對(duì),也可能是你在docker里
解決:檢查一下GPU驅(qū)動(dòng)的版本對(duì)不對(duì),在這里查找https://www.nvidia.com/Download/index.aspx
如果是docker,搜一下csdn一大片解決方式
RuntimeError: Couldn’t install torch. (或者無(wú)法install其他的pip庫(kù))
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out.
原因:網(wǎng)絡(luò)問(wèn)題,pip安裝torch超時(shí)失敗
解決:使用清華pip源
1.編輯/stable-diffusion-webui/launch.py文件,找到這段代碼:run(f'"{python}" -m {torch_command}
整行改成:run(f'"{python}" -m {torch_command} -i https://pypi.tuna.tsinghua.edu.cn/simple', "Installing torch and torchvision", "Couldn't install torch")
2.然后再找到這段代碼:return run(f'"{python}" -m pip {args}
整行改成:return run(f'"{python}" -m pip {args} -i https://pypi.tuna.tsinghua.edu.cn/simple --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
3.然后重試,一般就好了。原理就是加了清華的pip鏡像-i https://pypi.tuna.tsinghua.edu.cn/simple
fatal: unable to access ‘https://github.com/sczhou/CodeFormer.git/’ (或者其他的庫(kù)): GnuTLS recv error (-110): The TLS connection was non-properly terminated.
原因:還是github網(wǎng)絡(luò)問(wèn)題
解決:這個(gè)和git clone失敗的解決方式一樣,重試幾次,或者改hosts
三、下載模型
- 下載模型的checkpoint:https://huggingface.co/stabilityai/stable-diffusion-2
官方給的示例有:
768-v-ema.ckpt 模型下載+yaml下載
512-base-ema.ckpt 模型下載+yaml下載
- 把.ckpt放到
models/Stable-Diffusion/
目錄下(如果你下載的模型帶有.yaml文件,那么也一起放進(jìn)去,.yaml的文件命名需要和你的.ckpt前面一樣) - 啟動(dòng)后在右上角選擇你的模型就可以了
四、啟動(dòng)
把參數(shù)帶上,讓遠(yuǎn)端可以訪問(wèn)。參數(shù)列表可以在/modules/shared.py
里面找到
# 進(jìn)到文件夾內(nèi),用虛擬環(huán)境的python運(yùn)行
cd /stable-diffusion-webui
venv/bin/python3 launch.py --port 9965 --listen --no-half --enable-insecure-extension-access
第一次運(yùn)行會(huì)下載一些模型,成功后會(huì)提示:
Launching Web UI with arguments: --port 9965 --listen --no-half --enable-insecure-extension-access
No module 'xformers'. Proceeding without it.
...
LatentDiffusion: Running in v-prediction mode
DiffusionWrapper has 865.91 M params
Loading weights [0b0d9f28] from ...
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Embeddings:
Running on local URL: http://0.0.0.0:9965 # 這里是監(jiān)聽(tīng)地址
電腦訪問(wèn)http://云主機(jī)ip:9965
就可以玩了~
五、其他
- 如果你像我一樣是用云主機(jī),為方便下一次運(yùn)行,可以生成一個(gè)鏡像,以后直接加載鏡像就不需要重新安裝了
- 以后重新進(jìn)入記得切用戶
su 你的用戶名
- 啟動(dòng)的完整參數(shù)看這里
usage: launch.py [-h] [--config CONFIG] [--ckpt CKPT] [--ckpt-dir CKPT_DIR] [--gfpgan-dir GFPGAN_DIR] [--gfpgan-model GFPGAN_MODEL] [--no-half] [--no-half-vae] [--no-progressbar-hiding]
[--max-batch-count MAX_BATCH_COUNT] [--embeddings-dir EMBEDDINGS_DIR] [--hypernetwork-dir HYPERNETWORK_DIR] [--localizations-dir LOCALIZATIONS_DIR] [--allow-code]
[--medvram] [--lowvram] [--lowram] [--always-batch-cond-uncond] [--unload-gfpgan] [--precision {full,autocast}] [--share] [--ngrok NGROK] [--ngrok-region NGROK_REGION]
[--enable-insecure-extension-access] [--codeformer-models-path CODEFORMER_MODELS_PATH] [--gfpgan-models-path GFPGAN_MODELS_PATH]
[--esrgan-models-path ESRGAN_MODELS_PATH] [--bsrgan-models-path BSRGAN_MODELS_PATH] [--realesrgan-models-path REALESRGAN_MODELS_PATH]
[--clip-models-path CLIP_MODELS_PATH] [--xformers] [--force-enable-xformers] [--deepdanbooru] [--opt-split-attention] [--opt-split-attention-invokeai]
[--opt-split-attention-v1] [--disable-opt-split-attention] [--use-cpu USE_CPU [USE_CPU ...]] [--listen] [--port PORT] [--show-negative-prompt]
[--ui-config-file UI_CONFIG_FILE] [--hide-ui-dir-config] [--freeze-settings] [--ui-settings-file UI_SETTINGS_FILE] [--gradio-debug] [--gradio-auth GRADIO_AUTH]
[--gradio-img2img-tool {color-sketch,editor}] [--gradio-inpaint-tool {sketch,color-sketch}] [--opt-channelslast] [--styles-file STYLES_FILE] [--autolaunch]
[--theme THEME] [--use-textbox-seed] [--disable-console-progressbars] [--enable-console-prompts] [--vae-path VAE_PATH] [--disable-safe-unpickle] [--api]
[--api-auth API_AUTH] [--nowebui] [--ui-debug-mode] [--device-id DEVICE_ID] [--administrator] [--cors-allow-origins CORS_ALLOW_ORIGINS]
[--cors-allow-origins-regex CORS_ALLOW_ORIGINS_REGEX] [--tls-keyfile TLS_KEYFILE] [--tls-certfile TLS_CERTFILE] [--server-name SERVER_NAME]
[--ldsr-models-path LDSR_MODELS_PATH] [--scunet-models-path SCUNET_MODELS_PATH] [--swinir-models-path SWINIR_MODELS_PATH]
5.1 XFormer
如果不想用–no-half,可以安裝XFormer
# 先進(jìn)入stable-diffusion-webui目錄下
source ./venv/bin/activate
cd repositories
git clone https://github.com/facebookresearch/xformers.git
cd xformers
git submodule update --init --recursive
../../venv/bin/python3 -m pip install -r requirements.txt
../../venv/bin/python3 -m pip install -e .
我經(jīng)??ㄔ?code>git submodule update --init --recursiv這一步,國(guó)內(nèi)還是老老實(shí)實(shí)用–no-half吧。。
成功后,把啟動(dòng)參數(shù)改成–xformers文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-782448.html
venv/bin/python3 launch.py --port 9965 --listen --enable-insecure-extension-access --xformers
5.2 自定義腳本
可以安裝一些實(shí)用的自定義腳本文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-782448.html
# Tag輸入智能提示,能在輸入Tag時(shí)提供booru風(fēng)格(如Danbooru)的TAG自動(dòng)補(bǔ)全
git clone "https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git" extensions/tag-autocomplete
# Prompt測(cè)試,這個(gè)插件可以根據(jù)用戶輸入的提示語(yǔ)句,自動(dòng)生成相應(yīng)數(shù)量的圖像,以測(cè)試提示語(yǔ)句中每個(gè)單詞的影響。
git clone "https://github.com/Extraltodeus/test_my_prompt.git" extensions/test-my-prompt
到了這里,關(guān)于【踩坑筆記】從零開(kāi)始部署安裝Stable Diffusion 2 WebUI的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!