硬件平臺(tái):3A主機(jī)(內(nèi)存16G)
顯卡:AMD RX6700 XT 12GB 華擎幻影電競
處理器:AMD R5 3500X 6C6T
主板: 華碩TUF B450M-PRO GAMING
- 安裝Ubuntu22.04.2 LTS系統(tǒng)
更換系統(tǒng)源、安裝基本環(huán)境
安裝git、vim
1. 首先備份一下源列表文件
cp /etc/apt/sources.list /etc/apt/sources.list.bak
2.然后編輯修改為清華源
sudo gedit sources.list
-------------------刪掉原來全部內(nèi)容,把下面這段復(fù)制進(jìn)去,最后記得保存?。?!----------------------------------------
# 默認(rèn)注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse main universe restricted
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 預(yù)發(fā)布軟件源,不建議啟用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates multiverse main universe restricted
3.最后關(guān)閉文本編輯器,執(zhí)行以下3個(gè)命令:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install wget git vim python3-pip python3-venv
4.Ubuntu修改pypi源為豆瓣(強(qiáng)烈建議用豆瓣,如果你用其他源–例如清華源,曾出現(xiàn)過 找不到gfpgan等核心依賴的情況),復(fù)制以下整行命令,執(zhí)行即可
sudo mkdir ~/.pip&&sudo touch ~/.pip/pip.conf&&echo -e '[global]\nindex-url=https://pypi.douban.com/simple\ntimeout = 6000\n[install]\ntrusted-host=pypi.douban.com\n#disable-pip-version-check = true' > ~/.pip/pip.conf
安裝對應(yīng)Ubuntu 22.04版本的A卡驅(qū)動(dòng)(ROCm=5.6)
wget https://repo.radeon.com/amdgpu-install/5.6.1/ubuntu/jammy/amdgpu-install_5.6.50601-1_all.deb
sudo apt-get install ./amdgpu-install_5.6.50601-1_all.deb
---------------注意?。?!如果你是其他Ubuntu系統(tǒng)版本,需要自己根據(jù)版本號,去這個(gè)鏈接找:http://repo.radeon.com/amdgpu-install/
安裝Rocm
1.安裝Rocm和rocm-smi-lib【需要使用其他包的可以用這個(gè)命令查出來有哪些包可以裝sudo amdgpu-install --list-usecase】
sudo amdgpu-install --no-dkms
sudo apt-get install rocm-smi-lib
2.添加調(diào)用權(quán)限
sudo usermod -a -G video $LOGNAME
sudo usermod -a -G render $LOGNAME
3.使用以下3個(gè)命令檢查ROCm環(huán)境是否安裝成功
/opt/rocm/bin/rocm-smi
/opt/rocm/bin/rocminfo
/opt/rocm/opencl/bin/clinfo
4.將ROCm路徑加入系統(tǒng)PATH環(huán)境變量,執(zhí)行以下命令
echo 'export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin/x86_64' | sudo tee -a /etc/profile.d/rocm.sh
5.至此ROCm基礎(chǔ)環(huán)境就算安裝完成了。可以使用一下命令查看ROCm版本:
apt show rocm-libs -a #查看ROCm版本
watch -n 1 /opt/rocm/bin/rocm-smi #實(shí)時(shí)顯卡監(jiān)控
6.添加調(diào)用權(quán)限
sudo usermod -a -G video $LOGNAME
sudo usermod -a -G render $LOGNAME
7.使用以下命令可以讓你以后為系統(tǒng)新添加的用戶都有 GPU 訪問權(quán):
echo 'ADD_EXTRA_GROUPS=1' | sudo tee -a /etc/adduser.conf echo 'EXTRA_GROUPS=video' | sudo tee -a /etc/adduser.conf
開啟A卡高性能模式(可選)
/opt/rocm/bin/rocm-smi --setperflevel high
------------注意:這將會(huì)讓你的卡保持高頻率運(yùn)轉(zhuǎn),如果你短期不想畫圖了,可以設(shè)為auto,更省電文章來源:http://www.zghlxwxcb.cn/news/detail-504432.html
/opt/rocm/bin/rocm-smi --setperflevel auto
開啟CPU高性能模式(可選)
sudo apt install cpupower-gui
主角登場,開始安裝Stable Diffusion Webui
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
1.查看安裝腳本 (不懂代碼的可以跳過,直接跳到下面第4步)
less webui.sh
2.這段腳本的作用是自動(dòng)幫你導(dǎo)入HSA_OVERRIDE_GFX_VERSION變量(別執(zhí)行,僅分析和講解)
# Check prerequisites gpu_info=$(lspci 2>/dev/null | grep VGA) case "$gpu_info" in *"Navi 1"*|*"Navi 2"*) export HSA_OVERRIDE_GFX_VERSION=10.3.0 ;; *"Renoir"*) export HSA_OVERRIDE_GFX_VERSION=9.0.0 printf "\n%s\n" "${delimiter}"
3.然后它自動(dòng)幫你安裝torch==2.0.1+rocm5.4.2(別執(zhí)行,僅分析和講解)
if echo "$gpu_info" | grep -q "AMD" && [[ -z "${TORCH_COMMAND}" ]] then export TORCH_COMMAND="pip install torch==2.0.1+rocm5.4.2 torchvision==0.15.2+rocm5.4.2 --index-url https://download.pytorch.org/whl/rocm5.4.2" fi
4.進(jìn)入stable-diffusion-webui項(xiàng)目文件夾
cd stable-diffusion-webui/
5.創(chuàng)建venv環(huán)境
python3 -m venv venv
啟動(dòng)吧! stable-diffusion-webui
./webui.sh
6.如果出現(xiàn)類似下面的報(bào)錯(cuò),重試執(zhí)行./webui.sh即可,直到成功為止(有科學(xué)上網(wǎng)條件的同學(xué)應(yīng)該不會(huì)遇到此問題)
RuntimeError: Couldn't clone K-diffusion. Command: "git" clone "https://github.com/crowsonkb/k-diffusion.git" "/home/terryjay/SD/stable-diffusion-webui/repositories/k-diffusion" Error code: 128 stderr: 正克隆到 '/home/terryjay/SD/stable-diffusion-webui/repositories/k-diffusion'... fatal: 無法訪問 'https://github.com/crowsonkb/k-diffusion.git/':Failed to connect to github.com port 443 after 130035 ms: 連接超時(shí)`
7.完成了即可看到這樣的輸出
No checkpoints found. When searching for checkpoints, looked at: - file /home/terryjay/SD/stable-diffusion-webui/model.ckpt - directory /home/terryjay/SD/stable-diffusion-webui/models/Stable-diffusion Can't run without a checkpoint. Find and place a .ckpt or .safetensors file into any of those locations. The program will exit. Running on local URL: http://127.0.0.1:7860 To create a public link, set `share=True` in `launch()`. Startup time: 4.6s (import torch: 0.7s, import gradio: 1.3s, import ldm: 1.0s, other imports: 0.5s, list SD models: 0.2s, load scripts: 0.4s, create ui: 0.3s).
8.此時(shí)環(huán)境OK,但還沒有模型,你需要下載模型:
1. 下載的是checkpoint (縮寫ckpt) 或safetensors 類型的文件,都放入“stable-diffusion-webui\models\Stable-diffusion”中
2. LoRA類型放入“stable-diffusion-webui\models\Lora”中
3. hypernetwork類型放在“stable-diffusion-webui\models\hypernetworks”中
9.另外,插件相關(guān)的:
controlnet放在“/stable-diffusion-webui/extensions ”中
10.放好你的模型后即可進(jìn)入http://127.0.0.1:7860開始你的作圖之旅~
如果使用SD的過程中發(fā)現(xiàn)還是有環(huán)境問題,可先手動(dòng)驗(yàn)證pytorh庫:
- 在你的
stable-diffusion-webui\
目錄下,進(jìn)入python3 env解釋器環(huán)境:
. ./venv/bin/python3
- 復(fù)制執(zhí)行下面的torch代碼:
import torch
torch.cuda.is_available()
3.安裝SSH服務(wù),以便在其他設(shè)備上登錄管理Ubuntu:文章來源地址http://www.zghlxwxcb.cn/news/detail-504432.html
安裝SSH:
sudo apt-get install openssh-server
啟動(dòng)SSH服務(wù):
sudo service ssh start
檢查SSH服務(wù)已經(jīng)啟動(dòng)
sudo service ssh status
在其他電腦上登錄該Ubuntu(用戶名和IP需要根據(jù)實(shí)際情況修改)
ssh 用戶名@192.168.*.*
全文完
到了這里,關(guān)于A卡2023最新AI畫圖教程:3A主機(jī)安裝ROCm運(yùn)行Stable Diffusion畫圖的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!