AMD GPU installation runs stable diffusion

The operating environment of this article is Windows10/11+AMD

AI painting is a method of painting using artificial intelligence technology. It can learn the artist's style through machine learning algorithms and generate works similar to the artist. Recently, AI painting technology has been greatly developed, and many companies and research institutions are conducting related research and development. For example, OpenAI recently launched a project called DALL-E, which can generate images from textual descriptions provided by users. In addition, AI painting technology is also used in games, movies, advertisements and other fields, as well as in the creation of artists. Rather,Stable diffusion it is an algorithm for image generation that produces high-quality images.

1. Instructions before installation

Windows+AMD support is not officially done for webui yet,
but we can install lshqqytiger's fork of webui using Direct-ml.

The warehouse address is as follows:
https://github.com/lshqqytiger/stable-diffusion-webui-directml/issues

2. Install

1) Install Python3.10.6

 如果已经装了可以卸载原版本后下载3.10.6

The download address is as follows:
https://www.python.org/downloads/release/python-3106/ Choose to download tips
according to your own configuration : Remember to check "Add to environment variables" when installing
insert image description here

2) Copy the project to the local

git clone https://github.com/lshqqytiger/stable-diffusion-webui-directml
cd stable-diffusion-webui-directml
git submodule init
git submodule update

3) Download and add the model

Go to the link below, choose your favorite model, download it and put it in the Stable-diffusion folder under the models directory.
https://huggingface.co/models

4) Some amd cards will be incompatible, you can choose to add the following content in the webui-user.sh file

--precision full--no-halfCOMMANDLINE_ARGS=

5) Double-click to run webui.sh

After waiting for a while, the terminal displays 127.0.0.1:7860. You can directly access the web operation page of stable diffusion by visiting it in the browser.
insert image description here

Digression

local operation

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
cd stable-diffusion-webui
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip wheel

# It's possible that you don't need "--precision full", dropping "--no-half" however crashes my drivers
TORCH_COMMAND='pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.1.1' python launch.py --precision full --no-half


cd stable-diffusion-webui
# Optional: "git pull" to update the repository
source venv/bin/activate

# It's possible that you don't need "--precision full", dropping "--no-half" however crashes my drivers
TORCH_COMMAND='pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.1.1' python launch.py --precision full --no-half

It may take a long time to start the WebUI for the first time, and you may see a prompt similar to this:

MIOpen(HIP): Warning [SQLiteBase] Missing system database file: gfx1030_40.kdb Performance may degrade. Please follow instructions to install: https://github.com/ROCmSoftwarePlatform/MIOpen#installing-miopen-kernels-package

Run in Docker.
Pull the latest Docker image, start the image and attach to the container:

rocm/pytorchrocm/pytorchdocker run -it --network=host --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $HOME/dockerx:/dockerx rocm/pytorch

Execute the following command inside the container:

cd /dockerx
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
cd stable-diffusion-webui
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip wheel

# It's possible that you don't need "--precision full", dropping "--no-half" however crashes my drivers
TORCH_COMMAND='pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.1.1' REQS_FILE='requirements.txt' python launch.py --precision full --no-half

The folder inside the container should be accessible with the same name in the home directory.

Update the Python version in Docker
If the Web UI becomes incompatible with the pre-installed Python 3.7 version in the Docker image, you can do the following (provided that it has been successfully run in docker)

Execute the following command inside the container:

apt install python3.9-full # Confirm every prompt
update-alternatives --install /usr/local/bin/python python /usr/bin/python3.9 1
echo 'PATH=/usr/local/bin:$PATH' >> ~/.bashrc

Then follow the above steps to run in Docker again, and use the following modified startup command

rm -rf /dockerx/stable-diffusion-webui/venv
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui

Guess you like

Origin blog.csdn.net/qq_43774332/article/details/130213368