Skip to content

Latest commit

 

History

History
478 lines (387 loc) · 15 KB

ROCm-5.7.md

File metadata and controls

478 lines (387 loc) · 15 KB

AMD / Radeon 7900XTX 6900XT GPU ROCm install / setup / config

Ubuntu 22.04 / 23.04 / 23.10

ROCm 5.7.3

Automatic1111 Stable Diffusion + ComfyUI ( venv )

Oobabooga - Text Generation WebUI ( conda, Exllamav2, BitsAndBytes )

Install notes / instructions

2023-07 - I have composed this collection of instructions as they are my notes. I use to setup my own Linux system with AMD parts. I've gone over these doing many re-installs to get them all right. This is what I had hoped to find when I was looking for install instructions - so I'm sharing them in the hopes that they save time for other people.

2023-09-09 - I had a report that this doesn't work in virtual machines (virtualbox) as the system there cannot see the hardware, it can't load drivers, etc. While this is not a guide about Windows, Windows users may find it more helpful to try DirectML - https://rocm.docs.amd.com/en/latest/deploy/windows/quick_start.html / https://github.com/lshqqytiger/stable-diffusion-webui-directml

[ ... updates abridged ... ]

2024-05-12 - PyTorch.org now refers to ROCm 6 as stable, thus there's no need to refer to 5.7 series drivers anymore. I'm archiving these instructions here for posterity.


Ubuntu 22.04 / 23.04 / 23.10 - Base system install

Ubuntu 22.04 works great on Radeon 6900 XT video cards, but does not support 7900XTX cards as they came out later Ubuntu 23.04 is newer but has issues with some of the tools. So the notes below should work on either system, unless commented.

At this point we assume you've done the system install and you know what that is, have a user, root, etc.

# update system packages 
sudo apt update -y && sudo apt upgrade -y 
#turn on devel and sources.
sudo apt-add-repository -y -s -s
sudo apt install -y "linux-headers-$(uname -r)" \
	"linux-modules-extra-$(uname -r)"

[ for Ubuntu 23.04 - lunar ]

Some things may require older versions of python, so we need to add jammy packages, so that they can be installed, on lunar systems.

sudo add-apt-repository -y -s deb http://security.ubuntu.com/ubuntu jammy main universe

Add AMD GPU package sources

Make the directory if it doesn't exist yet. This location is recommended by the distribution maintainers.

sudo mkdir --parents --mode=0755 /etc/apt/keyrings

Download the key, convert the signing-key to a full Keyring required by apt and store in the keyring directory

wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | \
    gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null

amdgpu repository for jammy edited here to refer to 5.7.3 specifically ( previously this was "latest" )

echo 'deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] #https://repo.radeon.com/amdgpu/latest/ubuntu jammy main' \
https://repo.radeon.com/amdgpu/5.7.3/ubuntu jammy main' \
    | sudo tee /etc/apt/sources.list.d/amdgpu.list
sudo apt update -y 

AMDGPU DKMS

sudo apt install -y amdgpu-dkms

Note : This commonly produces warning message about 'Possible missing firmware' these are just wanrings and things work anyway, they can be ignored.

ROCm repositories for jammy

https://rocmdocs.amd.com/en/latest/deploy/linux/os-native/install.html

#echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/5.7.3 jammy main" \
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/5.7.3 jammy main" \
    | sudo tee --append /etc/apt/sources.list.d/rocm.list
echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' \
    | sudo tee /etc/apt/preferences.d/rocm-pin-600
sudo apt update -y

More AMD ROCm related packages

This is lots of stuff, but comparatively small so worth including, as some stuff later may want as dependencies without much notice.

# ROCm...
sudo apt install -y rocm-dev rocm-libs rocm-hip-sdk rocm-dkms rocm-libs
# ld.so.conf update 
sudo tee --append /etc/ld.so.conf.d/rocm.conf <<EOF
/opt/rocm/lib
/opt/rocm/lib64
EOF
sudo ldconfig
# update path
echo "PATH=/opt/rocm/bin:/opt/rocm/opencl/bin:$PATH" >> ~/.profile

Find graphics device

sudo /opt/rocm/bin/rocminfo | grep gfx

Found : gfx1030 [ Radeon 6900 ] Found : gfx1100 [ Radeon 7900 ]

Add user to groups

Of course note to change the user name to match your user.

sudo adduser `whoami` video
sudo adduser `whoami` render
# git and git-lfs (large file support
sudo apt install -y git git-lfs
# development tool may be required later...
sudo apt install -y libstdc++-12-dev
# stable diffusion likes TCMalloc...
sudo apt install -y libtcmalloc-minimal4

Performance Tuning

This section is optional, and as such has been moved to performance-tuning

Top for video memory and usage

nvtop Note : I have had issues with the distro version crashes with 2 GPUs, installing new version from sources works fine. Instructions for that are included at the bottom, as they depend on things installed between here and there. Project website : https://github.com/Syllo/nvtop

sudo apt install -y nvtop 

Radeon specific tools...

sudo apt install -y radeontop rovclock

and now we reboot...

sudo reboot

End of OS / base setup


Stable Diffusion (Automatic1111)

This system is built to use its own venv ( rather than Conda )...

Download Stable Diffusion ( Automatic1111 webui )

https://github.com/AUTOMATIC1111/stable-diffusion-webui Get the files...

cd
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui

The 1.9.x+ release series breaks the API so that it won't work with Oobabooga's TGW - so the following resets to use the 1.8.0 relaase that does work with Oobabooga.

git checkout bef51ae
git reset --hard

Requisites :

sudo apt install -y wget git python3.11 python3.11-venv libgl1 libglib2.0-0
python3.11 -m venv venv
source venv/bin/activate
python3.11 -m pip install -U pip
deactivate

Edit environment settings...

tee --append webui-user.sh <<EOF
# specify compatible python version
python_cmd="python3.11"
 ## Torch for ROCm
# generic import...
# export TORCH_COMMAND="pip install torch torchvision --index-url https://download.pytorch.org/whl/nightly/rocm5.7"
# use specific versions to avoid downloading all the nightlies... ( update dates as needed ) 
 export TORCH_COMMAND="pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/rocm5.7"
 ## And if you want to call this from other programs...
 export COMMANDLINE_ARGS="--api"
 ## crashes with 2 cards, so to get it to run on the second card (only), unremark the following 
 # export CUDA_VISIBLE_DEVICES="1"
EOF

If you keep models for SD somewhere, this is where you'd like them up...

If you don't do this, it will install a default to get you going. Note that these start files do include things that it needs you'll want to copy into the folder where you have other models ( to avoid issues )

#mv models models.1
#ln -s /path/to/models models 

Run SD...

Note that the first time it starts it may take it a while to go and get things it's not always good about saying what it's up to.

./webui.sh 

end Stable Diffusion


ComfyUI install script

Same install of packages here as for Stable Diffusion ( included here in case you're not installed SD and just want ComfyUI... )

sudo apt install -y wget git python3 python3-venv libgl1 libglib2.0-0
cd 
git clone https://github.com/comfyanonymous/ComfyUI
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager
cd ..
python3 -m venv venv
source venv/bin/activate
# pre-install torch and torchvision from nightlies - note you may want to update versions...
python3 -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/rocm5.7
python3 -m pip install -r requirements.txt  --extra-index-url https://download.pytorch.org/whl/rocm5.7
python3 -m pip install -r custom_nodes/ComfyUI-Manager/requirements.txt --extra-index-url https://download.pytorch.org/whl/rocm5.7

# end vend if needed...
deactivate

Scripts for running the program...

# run_gpu.sh
tee --append run_gpu.sh <<EOF
#!/bin/bash
source venv/bin/activate
python3 main.py --preview-method auto
EOF
chmod +x run_gpu.sh

#run_cpu.sh
tee --append run_cpu.sh <<EOF
#!/bin/bash
source venv/bin/activate
python3 main.py --preview-method auto --cpu
EOF
chmod +x run_cpu.sh

Update the config file to point to Stable Diffusion (presuming it's installed...)

# config file - connecto stable-diffusion-webui 
cp extra_model_paths.yaml.example extra_model_paths.yaml
sed -i "s@path/to@`echo ~`@g" extra_model_paths.yaml
# edit config file to point to your checkpoints etc 
#vi extra_model_paths.yaml

End ComfyUI install


Oobabooga - Text Generation WebUI - ROCm

Project Website : https://github.com/oobabooga/text-generation-webui.git

Conda

First we'll need Conda ... Required for pytorch... Conda provides virtual environments for python, so that programs with different dependencies can have different environments. Here is more info on managing conda : https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html# Other notes : https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html Download info : https://www.anaconda.com/download/

Anaconda ( if you prefer this to miniconda below )

#cd ~/Downloads/
#wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
#bash Anaconda3-2023.09-0-Linux-x86_64.sh -b
#cd ~
#ln -s anaconda3 conda

Miniconda ( if you prefer this to Anaconda above... ) [ https://docs.conda.io/projects/miniconda/en/latest/ ]

cd ~/Downloads/
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b
cd ~
ln -s miniconda3 conda
echo "PATH=~/conda/bin:$PATH" >> ~/.profile
source ~/.profile
conda update -y -n base -c defaults conda
conda install -y cmake ninja
conda init
source ~/.profile

conda is now active...

install pip

sudo apt install -y pip
pip3 install --upgrade pip

useful pip stuff to know ...

## show outdated packages...
#pip list --outdated
## check dependencies 
#pip check
## install specified bersion 
#pip install <packagename>==<version>

End conda and pip setup.

Oobabooga / Textgen webui

conda create -n textgen python=3.11 -y
conda activate textgen

PyTorch install...

# pre-install 
pip install --pre cmake colorama filelock lit numpy Pillow Jinja2 \
	mpmath fsspec MarkupSafe certifi filelock networkx \
	sympy packaging requests \
         --index-url https://download.pytorch.org/whl/rocm5.7
pip install --pre torch torchvision torchtext torchaudio triton pytorch-triton-rocm \
  --index-url https://download.pytorch.org/whl/rocm5.7

bitsandbytes rocm

2024-04-24 - AMD's own ROCm version of bitsandbytes has been updated! - https://github.com/ROCm/bitsandbytes ( ver 0.44.0.dev0 at time of writing )

cd
git clone https://github.com/ROCm/bitsandbytes.git
cd bitsandbytes
pip install .

Oobabooga / Text-generation-webui - Install webui...

cd
git clone https://github.com/oobabooga/text-generation-webui
cd text-generation-webui

Oobabooga's 'requirements'

The default bitsandbytes for AMD is out of date and doesn't support GPU. So we installed one earlier ( may be unsupported... ) we'll run sed first to adjust that line of the requirements...

sed -i "s@bitsandbytes==@bitsandbytes>=@g" requirements_amd.txt 
pip install -r requirements_amd.txt 

Exllama and Exllamav2 loaders ... It appears ExLlama isn't being maintained and the emphasis is now on ExLlamav2... v2 has been updated to support Mixture of Experts (MoE such as Mixtral ). 2023-12-23 - After many tests, it appears that the exllamav2 that's installed above gives an error, so we're compiling and reinstalling exllama here as when we do that it does work.
2024-01-18 - Something has broken and exllamav2 won't compile so I've added a line to reset the checkout to the last known good / compiling version 0.0.11 2024-01-20 - Thanks to TurboDerp for resolving issue with exllamav2 so it plays nice with HIP. Remarked out workaround, in case such is useful in future.

# install exllama
#git clone https://github.com/turboderp/exllama repositories/exllama
# install exllamav2
git clone https://github.com/turboderp/exllamav2 repositories/exllamav2
cd repositories/exllamav2
# Force collection back to base 0.0.11 
# git reset --hard a4ecea6
pip install .   --index-url https://download.pytorch.org/whl/rocm5.7
cd ../..

Models

Models : If you're new to this - new models can be downloaded from the shell via a python script, or from a form in the interface. There are lots of them - http://huggingface.co Generally the GPTQ models by TheBloke are likely to load... https://huggingface.co/TheBloke The 30B/33B models will load on 24GB of VRAM, but may error, or run out of memory depending on usage and parameters. Worthy of mention, TurboDerp ( author of the exllama loaders ) has been posting exllamav2 ( exl2 ) processed versions of models - https://huggingface.co/turboderp ( for use with exllamav2 loader ) - when downloading, note the --branch option.

To get new models note the ~/text-generation-webui directory has a program " download-model.py " that is made for downloading models from HuggingFace's collection.

If you have old models, link pre-stored models into the models

# cd ~/text-generation-webui
# mv models models.1
# ln -s /path/to/models models

Running TGW

Let's create a script (run.sh) to run the program...

tee --append run.sh <<EOF
#!/bin/bash
## activate conda
conda activate textgen
## command to run server... 
python server.py --extensions sd_api_pictures send_pictures gallery
# if you want the server to listen on the local network so other machines can access it, add --listen.  
#python server.py --listen  --extensions sd_api_pictures send_pictures gallery 
conda deactivate
EOF
chmod u+x run.sh

Note that to run the script :

source run.sh

End - Oobabooga - Text-Generation-WebUI


nvtop from source

( As one from packages crashes on 2 GPUs, while this never version from sources works fine. ) project website : https://github.com/Syllo/nvtop optional - tool for displaying gpu / memory usage info The package for this crashes with 2 gpu's, here it is from source.

sudo apt install -y libdrm-dev libsystemd-dev libudev-dev
cd 
git clone https://github.com/Syllo/nvtop.git
mkdir -p nvtop/build && cd nvtop/build
cmake .. -DNVIDIA_SUPPORT=OFF -DAMDGPU_SUPPORT=ON -DINTEL_SUPPORT=OFF
make
sudo make install

end nvtop