由于工作站安裝的是 ubuntu,卡也在上面,就只能在 ubuntu 上部署安裝 stable diffusion 了。另外,Linux 上使用 stable diffusion 也會(huì)方便很多。
1 準(zhǔn)備工作
- NVIDIA 官網(wǎng)下載驅(qū)動(dòng),主要是為了規(guī)避多卡驅(qū)動(dòng)不同的問題。由于本機(jī)是兩張一樣的卡,就可以省去這一步。如果存在不同型號(hào)的多卡驅(qū)動(dòng)不兼容的問題,就需要去官網(wǎng)下載。
- 安裝 python 3.10
- 安裝 CUDA11.8(pytorch2.x,xformers),對(duì) stable diffusion 兼容比較好
- 支持 pytorch2.x
- 支持 xformers,可以加速圖片生成
2 deploy stable diffusion
-
github stable diffusion webUI
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
-
配置 venv python 虛擬環(huán)境,因?yàn)椴煌P偷?python 版本要求不同
# 創(chuàng)建虛擬環(huán)境 python3 -m venv venv # 進(jìn)入虛擬環(huán)境 source venv/bin/activate # 退出虛擬環(huán)境 deactivate
也可以使用 conda 來進(jìn)行虛擬環(huán)境的創(chuàng)建和管理。
-
Stable diffusion WebUI 啟動(dòng),自動(dòng)安裝依賴
# 啟動(dòng),會(huì)自動(dòng)下載依賴 ./webui.sh --xformers
3 報(bào)錯(cuò)解決
‘’’
這里可能會(huì)出現(xiàn)一些報(bào)錯(cuò)
-
Cannot locate TCMalloc(improves CPU memory usage),這個(gè)報(bào)錯(cuò)是因?yàn)槿鄙?libgoogle-perftools4 和 libtcmalloc-minimal4,直接安裝即可
sudo apt install libgoogle-perftools4 libtcmalloc-minimal4 -y -
This scripts must not be launched as root, aborting…
解決方法:
bash webui.sh -f
‘’’
- OSError: Can’t load tokenizer for ‘openai/clip-vit-large-patch14’. If you were trying to load it from ‘https://huggingface.co/models’, make sure you don’t have a local directory with the same name. Otherwise, make sure ‘openai/clip-vit-large-patch14’ is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.
解決方法:
運(yùn)行時(shí)它需要訪問huggingface.co去下載一些模型需要的文件,而大陸用戶連接不上huggingface.co,導(dǎo)致部署失敗。
下載文件并進(jìn)行配置, 讓 stable diffusion 訪問本地?cái)?shù)據(jù), 放置到你所需要的目錄, 開始進(jìn)行配置,這些文件(clip)是模型中encoder所需要的,我們可以從報(bào)錯(cuò)信息中去發(fā)現(xiàn)是哪里調(diào)用了這個(gè)openai/clip-vit-large-patch14,去修改這個(gè)路徑配置即可。
這里的配置會(huì)導(dǎo)致我們運(yùn)行時(shí)會(huì)去huggingface.co(外網(wǎng))找這個(gè)文件,只需要將這個(gè)改成我們之前下載所放置的路徑即可, 一共四處
- RuntimeError: GET was unable to find an engine to execute this computation
解決方法:
因?yàn)閠orch torchvision cuda以及python版本都是有兼容關(guān)系的, 這三者安裝兼容版本就可以了.
檢測torch和cuda是否能用:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
測試:
import torch
print(torch.cuda.is_available())
num_gpu =1
# Decide which device to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and num_gpu > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())
檢查cudnn是否可用:文章來源:http://www.zghlxwxcb.cn/news/detail-799865.html
print(torch.backends.cudnn.version())
文章來源地址http://www.zghlxwxcb.cn/news/detail-799865.html
到了這里,關(guān)于在 Linux 本地部署 stable diffusion的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!