A card 2023 latest AI drawing tutorial: 3A host installs ROCm and runs Stable Diffusion drawing

Hardware platform: 3A host (memory 16G)

Graphics card: AMD RX6700 XT 12GB ASRock Phantom Gaming
Processor: AMD R5 3500X 6C6T
Motherboard: ASUS TUF B450M-PRO GAMING

  • Install Ubuntu22.04.2 LTS system

Replace the system source and install the basic environment

Install git, vim

1. First backup the source list file

cp /etc/apt/sources.list /etc/apt/sources.list.bak

2. Then edit and change it to Tsinghua Source

sudo gedit sources.list

------------------Delete all the original content, copy the following paragraph into it, and remember to save it at the end! ! ! ----------------------------------------

# 默认注释了源码镜像以提高 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

# 预发布软件源,不建议启用
# 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. Finally close the text editor and execute the following 3 commands:
sudo apt-get update

sudo apt-get upgrade

sudo apt-get install wget git vim python3-pip python3-venv
4. Ubuntu modifies the pypi source to Douban (it is strongly recommended to use Douban. If you use other sources - such as Tsinghua source, there have been cases where core dependencies such as gfpgan cannot be found), copy the following entire line of commands and execute it.
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

Install the A card driver corresponding to Ubuntu 22.04 version

wget http://repo.radeon.com/amdgpu-install/22.40.6/ubuntu/jammy/amdgpu-install_5.4.50406-1_all.deb
sudo apt-get install ./amdgpu-install_5.4.50406-1_all.deb

---------------Notice! ! ! If you have another Ubuntu system version, you need to find it according to the version number yourself: http://repo.radeon.com/amdgpu-install/

Install Rocm

1. Install Rocm and rocm-smi-lib [If you need to use other packages, you can use this command to find out which packages can be installed sudo amdgpu-install --list-usecase]
sudo amdgpu-install --no-dkms
sudo apt-get install rocm-smi-lib
2. Add calling permissions
sudo usermod -a -G video $LOGNAME 
sudo usermod -a -G render $LOGNAME
3. Use the following 3 commands to check whether the ROCm environment is installed successfully.
/opt/rocm/bin/rocm-smi

/opt/rocm/bin/rocminfo

/opt/rocm/opencl/bin/clinfo
4. Add the ROCm path to the system PATH environment variable and execute the following command
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. At this point, the installation of the ROCm basic environment is complete. You can use the following command to check the ROCm version:
apt show rocm-libs -a  #查看ROCm版本
watch -n 1 /opt/rocm/bin/rocm-smi   #实时显卡监控
6. Add calling permissions
sudo usermod -a -G video $LOGNAME 
sudo usermod -a -G render $LOGNAME
7. Use the following command to give all new users you add to the system access to the GPU:
echo 'ADD_EXTRA_GROUPS=1' | sudo tee -a /etc/adduser.conf echo 'EXTRA_GROUPS=video' | sudo tee -a /etc/adduser.conf

Turn on A card high performance mode (optional)

/opt/rocm/bin/rocm-smi --setperflevel high

----------Note: This will keep your card running at a high frequency. If you don't want to draw in the short term, you can set it to auto to save power.

/opt/rocm/bin/rocm-smi --setperflevel auto

Turn on CPU high performance mode (optional)

sudo apt install cpupower-gui

The protagonist appears and starts installing Stable Diffusion Webui

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
1. View the installation script (if you don’t understand the code, you can skip it and jump directly to step 4 below)
less webui.sh
2. The function of this script is to automatically help you import the HSA_OVERRIDE_GFX_VERSION variable (do not execute it, only analyze and explain)
# 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. Then it will automatically install torch==2.0.1+rocm5.4.2 for you (do not execute, only analyze and explain)
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. Enter the stable-diffusion-webui project folder
cd stable-diffusion-webui/
5. Create venv environment
python3 -m venv venv

Start it! stable-diffusion-webui

./webui.sh
6. If an error similar to the one below occurs, just retry executing ./webui.sh until it succeeds (students with scientific Internet access skills should not encounter this problem)
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: 连接超时`
7. When completed, you can see the output like this
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. The environment is OK at this time, but there is no model yet. You need to download the model:
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. In addition, plug-in related:
controlnet放在“/stable-diffusion-webui/extensions ”中
10. After placing your model, you can enter http://127.0.0.1:7860 to start your drawing journey ~

If you find that there are still environmental problems when using SD, you can manually verify the pytorh library first:

  1. In your stable-diffusion-webui\directory, enter the python3 env interpreter environment:
. ./venv/bin/python3
  1. Copy and execute the following torch code:
import torch
torch.cuda.is_available()

3. Install the SSH service to log in and manage Ubuntu on other devices:

安装SSH:
    sudo apt-get install openssh-server
启动SSH服务:
    sudo service ssh start
检查SSH服务已经启动
    sudo service ssh status
在其他电脑上登录该Ubuntu(用户名和IP需要根据实际情况修改)
    ssh 用户名@192.168.*.*

Complete text

Guess you like

Origin blog.csdn.net/qq_42183962/article/details/131217868