記錄Ubuntu下安裝Stable-Diffusion-webui,比較簡單,以供參考。
系統(tǒng):Ubuntu 18.04.4 LTS
內(nèi)存:40G
顯卡:32G
硬盤:500G
一、安裝cuda
支持安裝的cuda版本可以用nvidia-smi命令查看:
?
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.182.03 Driver Version: 470.182.03 CUDA Version: 11.4 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla V100-SXM2... Off | 00000000:00:08.0 Off | 0 |
| N/A 39C P0 55W / 300W | 0MiB / 32510MiB | 3% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
顯卡驅(qū)動支持的cuda版本最高是11.4,可以在這里下載對應的cuda版本:CUDA Toolkit Archive | NVIDIA Developer(https://developer.nvidia.com/cuda-toolkit-archive)。由于之前安裝別的環(huán)境,已經(jīng)裝了cuda11.4版本,可以用nvcc -V查看安裝的cuda版本。
二、搭建python虛擬環(huán)境(為了不影響原系統(tǒng)環(huán)境)
使用miniconda,我之前已經(jīng)安裝了。然后使用conda創(chuàng)建虛擬環(huán)境sdwebui,使用的python版本為3.10.9(stable-diffusion-webui用的python版本為3.10.6)。
conda create -n sdwebui python==3.10.9
激活環(huán)境
conda activate sdwebui
升級pip并更改默認庫包下載地址為清華鏡像(如果已經(jīng)有鏡像的可以忽略)
python -m pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
安裝torch
在pytorch官網(wǎng)Previous PyTorch Versions | PyTorch(https://pytorch.org/get-started/previous-versions/) 官網(wǎng)不能訪問的可以打開:Pytorch和CUDA版本對應關(guān)系_TURING.DT的博客-CSDN博客
查看對應的cuda支持的torch版本,并且直接拷貝安裝命令。
這里是我的cuda版本對應的安裝命令。
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch
三、下載并安裝stable-diffusion-webui
切換到當前用戶目錄下,使用git命令下載stable-diffusion-webui源碼
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
由于國內(nèi)github不能穩(wěn)定連接,所以可以從國內(nèi)的gitee(碼云)下載
git clone https://gitee.com/yiouyou/automatic1111-stable-diffusion-webui.git
打開v2-1_768-ema-pruned.ckpt · stabilityai/stable-diffusion-2-1 at main(https://huggingface.co/stabilityai/stable-diffusion-2-1/blob/main/v2-1_768-ema-pruned.ckpt),下載訓練模型(大小4.9G)。下載完成后,把v2-1_768-ema-pruned.ckpt這個訓練模型放入stable-diffusion-webui的models/Stable-diffusion目錄下,這個目錄專門存放用于生成AI繪圖的繪圖元素的基礎(chǔ)模型庫。后續(xù)如果在其他網(wǎng)站比如civitai之類的地方下載的ckpt或者safetensors文件也是放在這個文件夾里面。
然后切換到webui目錄下,安裝依賴
cd stable-diffusion-webui/
pip install -r requirements_versions.txt
pip install -r requirements.txt
安裝完成后,啟動stable-diffusion-webui
python launch.py
這里要安裝很多依賴,并且要git clone相關(guān)包和模型文件,需要科學上網(wǎng),否則會失敗。
最終啟動成功后如下圖所示,會出來一個url:
(sdwebui) ubuntu@VM-16-ubuntu:~/sdwebui/stable-diffusion-webui$ python launch.py
Python 3.10.9 (main, Mar 8 2023, 10:47:38) [GCC 11.2.0]
Version: v1.4.0
Commit hash: 394ffa7b0a7fff3ec484bcd084e673a8b301ccc8
Installing clip
Installing open_clip
Cloning Stable Diffusion into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/stable-diffusion-stability-ai...
Cloning K-diffusion into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/k-diffusion...
Cloning CodeFormer into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/CodeFormer...
Cloning BLIP into /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/BLIP...
Installing requirements for CodeFormer
Installing requirements
Launching Web UI with arguments:
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-9vmy3hxk because the default path (/home/ubuntu/.config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.12.1.
The program is tested to work with torch 2.0.0.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.
Use --skip-version-check commandline argument to disable this check.
==============================================================================
Calculating sha256 for /home/ubuntu/sdwebui/stable-diffusion-webui/models/Stable-diffusion/v2-1_768-ema-pruned.ckpt: preload_extensions_git_metadata for 7 extensions took 0.00s
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 7.8s (import torch: 1.6s, import gradio: 1.5s, import ldm: 0.4s, other imports: 3.2s, load scripts: 0.5s, create ui: 0.5s).
ad2a33c361c1f593c4a1fb32ea81afce2b5bb7d1983c6b94793a26a3b54b08a0
Loading weights [ad2a33c361] from /home/ubuntu/sdwebui/stable-diffusion-webui/models/Stable-diffusion/v2-1_768-ema-pruned.ckpt
Creating model from config: /home/ubuntu/sdwebui/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/configs/stable-diffusion/v2-inference-v.yaml
LatentDiffusion: Running in v-prediction mode
DiffusionWrapper has 865.91 M params.
Applying attention optimization: Doggettx... done.
在瀏覽器打開這個url,表示環(huán)境部署成功。
四、使用stable-diffusion-webui
注意:如果在prompt輸入后點擊generate無法生成圖片,看見黑色小框顯示“float 32“之類的關(guān)鍵字,則在webui 頁面的 Settings->StableDiffusion 最下面,勾選 float32 的選項框。接著點擊上方的Apply settings 應用,然后按F5刷新頁面后,即可正常使用。
在左上角的文本框prompt輸入提示詞,點擊Generate,等待數(shù)秒鐘(我的電腦大概等待15s左右),就會生成一張圖。
文章來源:http://www.zghlxwxcb.cn/news/detail-516384.html
默認端口是7860,如果想換端口 啟動時加參數(shù):python launch.py --port 7770文章來源地址http://www.zghlxwxcb.cn/news/detail-516384.html
到了這里,關(guān)于Ubuntu18.04本地部署Stable-Diffusion-webui繪畫的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!