How To Use ROCm with FaceFusion on Linux (Ubuntu 22.04)

I've tried multiple cominbations of versions from pre-compiled wheels and by compiling the source code myself and this is what I've found worked for me. Also, the RX 7000 series might not be supported on ROCm 5.4.2 and I don't have a solution for that yet.

OVERVIEW:

  1. Installing ROCm Multi-Versioned 5.4.2 release
  2. Downloading FaceFusion and Installing
  3. Configuring environment variables on FaceFusion run

1. Installing ROCm Multi-Versioned 5.4.2 release

You can keep your latest installed version of ROCm by utilizing the multi-version feature in the AMDGPU installer tool.

A. ROCm Prerequisite configuration: (If you know you've already down this, you can skip this step)

Set up permissions for your User to access GPU resources:
https://rocm.docs.amd.com/projects/install-on-linux/en/docs-6.0.0/how-to/prerequisites.html#setting-permissions-for-groups

This section provides steps to add any current user to a video group to access GPU resources.
Use of the video group is recommended for all ROCm-supported operating systems.
To check the groups in your system, issue the following command:
groups

Add yourself to the render and video group using the command:
sudo usermod -a -G render,video $LOGNAME

To add all future users to the video and render groups by default, run the following commands:
echo 'ADD_EXTRA_GROUPS=1' | sudo tee -a /etc/adduser.conf
echo 'EXTRA_GROUPS=video' | sudo tee -a /etc/adduser.conf
echo 'EXTRA_GROUPS=render' | sudo tee -a /etc/adduser.conf

B. Adding ROCm and AMDGPU repositories for 5.4.2:

https://rocm.docs.amd.com/projects/install-on-linux/en/docs-6.0.0/how-to/native-install/ubuntu.html#package-signing-key
Add Package Signing Key:

sudo mkdir --parents --mode=0755 /etc/apt/keyrings
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null

Add repositories:
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/amdgpu/5.4.2/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/amdgpu.list
sudo apt update

echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/5.4.2 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

C. Download amdgpu-install for your latest installed version of ROCm if you don't already have it:

It might be in your software store under "amdgpu-install", if not, download it from AMD's site:

To download it from AMD, you'll need to visit this page for the version of ROCm you have installed. Select the right OS!:
(Note: the Version 5.5.1 page has an error in the name of the package, use the file name "amdgpu-install_5.5.50501-1_all.deb", not "amdgpu-install_5.6.50600-1_all.deb" when installing)
For ROCm version 6.0.0: https://rocm.docs.amd.com/projects/install-on-linux/en/docs-6.0.0/how-to/amdgpu-install.html
For ROCm version 5.7.1: https://rocm.docs.amd.com/en/docs-5.7.1/deploy/linux/installer/install.html
For ROCm version 5.7.0: https://rocm.docs.amd.com/en/docs-5.7.0/deploy/linux/installer/install.html
For ROCm version 5.6.1: https://rocm.docs.amd.com/en/docs-5.6.1/deploy/linux/installer/install.html
For ROCm version 5.6.0: https://rocm.docs.amd.com/en/docs-5.6.0/deploy/linux/installer/install.html
For ROCm version 5.5.1: https://rocm.docs.amd.com/en/docs-5.5.1/deploy/linux/installer/install.html

D. Install ROCm 5.4.2 with this command:

sudo amdgpu-install --rocmrelease=5.4.2 --usecase=rocm,hip,hiplibsdk,mllib,mlsdk --no-dkms

After it's installed, you should have the following folder: "/opt/rocm-5.4.2"


2. Downloading FaceFusion and Installing:

Note: FaceFusion requires Python version 3.10, check your default version using "python --version".
If you don't have that installed, add this package:
Python:
apt install python3.10

A. ###### Install The rest of the dependency packages:
PIP:
apt install python3-pip
GIT:
apt install git-all
cURL:
apt install curl
FFmpeg:
apt install ffmpeg

Note: for the remainder of the tutorial, if your python version when you type "python --version" does not start with 3.10, replace the word "python" in my following commands with "python3.10"

A. Download FaceFusion:

In the directory you want FaceFusion, issue the command:
git clone https://github.com/facefusion/facefusion

Go into the folder and create a python virtual environment then activate it:

1
2
3
cd facefusion
python -m venv venv
source venv/bin/activate
B. Download and install Torch and Torchvision:

In your virtual environment activated console, run:
pip install torch torchvision --index-url https://download.pytorch.org/whl/rocm5.4.2
That will download the torch version for ROCm 5.4.2

C. Download and install Onnxruntime-training for ROCm 5.4.2:

After installing torch, download onnxruntime for ROCm 5.4.2 from this link:
https://download.onnxruntime.ai/onnxruntime_training-1.16.3%2Brocm542-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Once that python wheel is downloaded, copy it's location and filename then return to your Terminal with the activated "venv" virtual environment and run:
pip install onnxruntime_training-1.16.3+rocm542-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
(add the file location if it's not in the facefusion folder)

D. Modify the requirements.txt file:

In the FaceFusion folder, open up the file requirements.txt in a text editor, comment out or remove these 2 lines:
onnxruntime==1.16.3
torch==2.1.2

E. Install the rest of the requirements:

In the venv activated terminal, run:
pip install -r requirements.txt

It will download and install the rest of the required packages for FaceFusion.


3. Configuring environment variables on FaceFusion run

Congrats on making it this far! The last step you'll need to do when running FaceFusion is to add this before your run command:
ROCM_PATH=/opt/rocm-5.4.2

Run FaceFusion:
ROCM_PATH=/opt/rocm-5.4.2 python run.py

That's it! Now in the WebUI, you can select ROCm and everything should work!
Keep the "threads" to 1 (2 can increase crash chance), and I've had most luck with "2" queue count.


Note: It CAN crash at times and will throw a bunch of "MIOpen Errors" when swapping a face, but everything should still work.
If you encounter a crash making the page say "Error", either restart the program or try moving a few settings around (like Face detection ratio or something). I've found that can help 'reset' the error.


Example FaceFusion launch commands:
WebUI, Full Size Model:
ROCM_PATH=/opt/rocm-5.4.2 python run.py --execution-thread-count 1 --execution-queue-count 2 --video-memory-strategy tolerant --execution-provider rocm --face-swapper-model inswapper_128

WebUI, 16bit model:
ROCM_PATH=/opt/rocm-5.4.2 python run.py --execution-thread-count 1 --execution-queue-count 2 --video-memory-strategy tolerant --execution-provider rocm

Benchmark:
ROCM_PATH=/opt/rocm-5.4.2 python run.py --ui-layouts benchmark --execution-thread-count 1 --execution-queue-count 2 --video-memory-strategy tolerant --execution-provider rocm


For ROCm-Enhanced AI Model Text Generation for Linux and Windows, check out KoboldCpp-ROCm: https://github.com/YellowRoseCx/koboldcpp-rocm

The End!

Edit

Pub: 25 Jan 2024 22:01 UTC

Edit: 25 Jan 2024 23:37 UTC

Views: 655