Skip to content

Add ROCm 5.4.2 Support for RVC WebUI on gfx803 (AMD RX580 / Polaris GPUs) #2577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions rocm_5.4/Dockerfile.base_rocm5.4_source_compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Docker Base Buildfile for ROCm 5.4.2 to Support Retrieval-based-Voice-Conversion-WebUI with RX580 / Polaris / gfx803 AMD GPU
# Created, Built, and Compiled by Levent Sunay (lsunay) - May-April 2025
#
# Description:
# This Dockerfile is designed to build a base image for ROCm 5.4.2, specifically targeting the gfx803 architecture
# (e.g., AMD RX580 / Polaris GPUs). It compiles PyTorch, TorchVision, and TorchAudio from source with ROCm support
# to enable machine learning workloads, such as Retrieval-based-Voice-Conversion-WebUI. This image includes necessary
# environment variables, build tools, and configurations for compatibility with older AMD GPUs.
#
# File Name: Dockerfile.base_rocm5.4_source_compile - Stage 1

FROM rocm/dev-ubuntu-22.04:5.4.2-complete

# === Environment Variables ===
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
ENV PIP_ROOT_USER_ACTION='ignore'
ENV MAX_JOBS=14
ENV HSA_OVERRIDE_GFX_VERSION=8.0.3
ENV PYTORCH_ROCM_ARCH=gfx803
ENV ROCM_ARCH=gfx803
ENV TORCH_BLAS_PREFER_HIPBLASLT=0
ENV ROC_ENABLE_PRE_VEGA=1
ENV USE_NINJA=1
# Ninja is used for builds if enabled, so ninja-build must be installed
ENV REQS_FILE='requirements.txt'
# CMAKE_POLICY_VERSION_MINIMUM may be required if the installed cmake version via pip is too new.
# For instance, cmake 3.20+ might cause issues with Protobuf in PyTorch 2.0.1.
ENV CMAKE_POLICY_VERSION_MINIMUM="3.18"
# Alternatively, versions like 3.13 or 3.5 can be used

# Write critical environment variables to /etc/environment for persistence
RUN echo "MAX_JOBS=${MAX_JOBS}" >> /etc/environment && \
echo "HSA_OVERRIDE_GFX_VERSION=${HSA_OVERRIDE_GFX_VERSION}" >> /etc/environment && \
echo "PYTORCH_ROCM_ARCH=${PYTORCH_ROCM_ARCH}" >> /etc/environment && \
echo "ROCM_ARCH=${ROCM_ARCH}" >> /etc/environment && \
echo "TORCH_BLAS_PREFER_HIPBLASLT=${TORCH_BLAS_PREFER_HIPBLASLT}" >> /etc/environment && \
echo "ROC_ENABLE_PRE_VEGA=${ROC_ENABLE_PRE_VEGA}" >> /etc/environment && \
echo "PIP_ROOT_USER_ACTION=${PIP_ROOT_USER_ACTION}" >> /etc/environment && \
echo "CMAKE_POLICY_VERSION_MINIMUM=${CMAKE_POLICY_VERSION_MINIMUM}" >> /etc/environment && \
true

# === System Updates and Build Tools ===
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
git wget curl \
ffmpeg \
python3.10 python3-pip python3.10-dev python3.10-venv \
cmake ninja-build \
libopenblas-dev libomp-dev pkg-config \
# Confirm/install ROCm development libraries
# rocm-dev meta-package may pull in all dev packages
# OR specifically install rocrand-dev
rocm-dev \
# This should include rocrand-dev, hiprand-dev, etc.
# OR use: apt-get install -y rocrand librocrand-dev # Verify package names
&& \
python3 -m pip install --upgrade pip wheel setuptools && \
python3 -m pip install "cmake==3.20.2" && \
# This line is still here for pip-installed cmake
apt-get clean && rm -rf /var/lib/apt/lists/* && \
true

# Verify Python and CMake versions
RUN python3 --version && pip3 --version && cmake --version

# ... (rocBLAS installation can remain commented or be added as needed) ...

# === PyTorch v2.0.1 Source Compilation for ROCm 5.4.2 / gfx803 ===
WORKDIR /
ENV PYTORCH_GIT_TAG="v2.0.1"
RUN echo "Checkout PyTorch Version: ${PYTORCH_GIT_TAG}" && \
git clone --depth 1 --recursive --branch ${PYTORCH_GIT_TAG} https://github.com/pytorch/pytorch.git /pytorch && \
true

WORKDIR /pytorch
RUN echo "BUILDING PYTORCH ${PYTORCH_GIT_TAG} for ${PYTORCH_ROCM_ARCH} *** " && \
python3 --version && \
# dpkg -r --force-depends python3-yaml python3-filelock || true &&
mkdir -p /pytorch/dist && \
python3 setup.py clean && \
# Install PyTorch's own requirements.txt
echo "Installing PyTorch build requirements from ${REQS_FILE}..." && \
python3 -m pip install --break-system-packages -r ${REQS_FILE} && \
# ---- Re-pin NumPy version after requirements install ----
echo "Re-pinning NumPy to 1.23.5 after PyTorch requirements install..." && \
python3 -m pip install --break-system-packages "numpy==1.23.5" --force-reinstall && \
python3 -c "import numpy; print(f'NumPy version for PyTorch build: {numpy.__version__}')" && \
# ---- End of NumPy pinning ----
echo "Running amd_build.py..." && \
python3 tools/amd_build/build_amd.py && \
echo "Running setup.py bdist_wheel..." && \
python3 setup.py bdist_wheel && \
echo "Installing built PyTorch wheel..." && \
python3 -m pip install --break-system-packages dist/torch*.whl && \
ls /pytorch/dist/torch*.whl | head -n 1 > /opt/pytorch_wheel_name.txt && \
true

WORKDIR /
ENV TORCHVISION_GIT_TAG="v0.15.2"
RUN echo "Checkout Torchvision Version: ${TORCHVISION_GIT_TAG}" && \
git clone --depth 1 --branch ${TORCHVISION_GIT_TAG} https://github.com/pytorch/vision.git /vision && \
true

WORKDIR /vision
RUN echo "BUILDING TorchVision ${TORCHVISION_GIT_TAG} *** " && \
python3 setup.py bdist_wheel && \
python3 -m pip install --break-system-packages dist/torchvision-*.whl && \
ls /vision/dist/torchvision*.whl | head -n 1 > /opt/torchvision_wheel_name.txt && \
true

WORKDIR /
ENV TORCHAUDIO_GIT_TAG="v2.0.2"
RUN echo "Checkout Torchaudio Version: ${TORCHAUDIO_GIT_TAG}" && \
git clone --depth 1 --branch ${TORCHAUDIO_GIT_TAG} https://github.com/pytorch/audio.git /audio && \
true

WORKDIR /audio
RUN echo "BUILDING Torchaudio ${TORCHAUDIO_GIT_TAG}" && \
apt-get update && apt-get install -y --no-install-recommends libsndfile1-dev libsox-dev sox && \
# Try adding /opt/rocm to CMAKE_PREFIX_PATH
export CMAKE_PREFIX_PATH="/opt/rocm:${CMAKE_PREFIX_PATH}" && \
python3 setup.py bdist_wheel && \
python3 -m pip install --break-system-packages dist/torchaudio*.whl && \
ls /audio/dist/torchaudio*.whl | head -n 1 > /opt/torchaudio_wheel_name.txt && \
apt-get purge -y --auto-remove libsndfile1-dev libsox-dev sox && \
apt-get clean && rm -rf /var/lib/apt/lists/*

RUN echo "Configuring ROCm library paths" && \
echo "/opt/rocm/lib" > /etc/ld.so.conf.d/rocm.conf && \
(test -d /opt/rocm/lib64 && echo "/opt/rocm/lib64" >> /etc/ld.so.conf.d/rocm.conf || true) && \
ldconfig && \
true

RUN echo "** Verifying PyTorch, TorchVision, TorchAudio Installation **" && \
python3 -c "import sys; import platform; import torch; import torchvision; import torchaudio; \
print(f'System Python Version (sys.version): {sys.version.split()[0]}'); \
print(f'Platform Python Version (platform.python_version): {platform.python_version()}'); \
print(f'Torch Version: {torch.__version__}'); \
print(f'TorchVision Version: {torchvision.__version__}'); \
print(f'TorchAudio Version: {torchaudio.__version__}'); \
print(f'ROCm available: {torch.cuda.is_available()}'); \
print(f'PyTorch built with ROCm/HIP: {torch.version.hip if hasattr(torch.version, \"hip\") else \"HIP not available or not a ROCm build\"}')"
146 changes: 146 additions & 0 deletions rocm_5.4/Dockerfile.rvc_original
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Docker Buildfile for RVC WebUI Installation with ROCm 5.4.2 for RX580 / Polaris / gfx803 AMD GPU
# Created, Built, and Compiled by Levent Sunay (lsunay) - May-April 2025
#
# Description:
# This Dockerfile is the second stage of a multi-stage build for installing the Retrieval-based-Voice-Conversion-WebUI (RVC)
# on top of a base image with ROCm 5.4.2 and PyTorch compiled for gfx803 architecture (e.g., AMD RX580 / Polaris GPUs).
# It sets up the necessary environment, dependencies, and configurations to run the RVC WebUI application.
#
# File Name: Dockerfile.rvc_original - Stage 2: Original RVC WebUI Installation (Based on ROCm 5.4.2)

FROM rocm542_gfx803_base:5.4.2
# Base image tag from Stage 1

# === Environment Variables ===
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
ENV PIP_ROOT_USER_ACTION='ignore'
ENV HSA_OVERRIDE_GFX_VERSION=8.0.3
ENV PYTORCH_ROCM_ARCH=gfx803
ENV ROCM_ARCH=gfx803
ENV RVC_PORT=7865
ENV NODE_VERSION=22.9.0
ENV NVM_DIR="/root/.nvm"
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin:${PATH}"

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
aria2 \
git wget curl ffmpeg \
&& \
apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# === RVC WebUI Installation ===
# Clone the RVC project repository into the /app directory.
RUN echo "Cloning RVC repository..." && \
git clone https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git . && \
echo "RVC repository cloned into /app."

# Create a Python 3.10 virtual environment (.venv)
RUN python3 -m venv .venv # .venv will be created under /app

# Create constraints.txt to use PyTorch wheels and other pinned versions from Stage 1
RUN echo "** Creating constraints.txt **" && \
export PATH="/opt/rocm/bin:/opt/rocm/hip/bin:${PATH}" && \
PYTORCH_WHEEL_FILE_PATH=$(cat /opt/pytorch_wheel_name.txt) && \
TORCHVISION_WHEEL_FILE_PATH=$(cat /opt/torchvision_wheel_name.txt) && \
TORCHAUDIO_WHEEL_FILE_PATH=$(cat /opt/torchaudio_wheel_name.txt) && \
echo "torch @ file://${PYTORCH_WHEEL_FILE_PATH}" > .venv/constraints.txt && \
echo "torchvision @ file://${TORCHVISION_WHEEL_FILE_PATH}" >> .venv/constraints.txt && \
echo "torchaudio @ file://${TORCHAUDIO_WHEEL_FILE_PATH}" >> .venv/constraints.txt && \
echo "numpy==1.23.5" >> .venv/constraints.txt && \
echo "protobuf==4.25.3" >> .venv/constraints.txt && \
echo "matplotlib==3.7.2" >> .venv/constraints.txt && \
echo "joblib==1.1.0" >> .venv/constraints.txt && \
echo "numba==0.56.4" >> .venv/constraints.txt && \
echo "llvmlite==0.39.0" >> .venv/constraints.txt && \
echo "fairseq==0.12.2" >> .venv/constraints.txt && \
echo "faiss-cpu==1.7.3" >> .venv/constraints.txt && \
echo "gradio==3.34.0" >> .venv/constraints.txt && \
echo "pyworld==0.3.2" >> .venv/constraints.txt && \
echo "torchcrepe==0.0.23" >> .venv/constraints.txt && \
echo "torchfcpe" >> .venv/constraints.txt && \
echo "Contents of constraints.txt:" && cat .venv/constraints.txt

# Process RVC's main requirements.txt and requirements-amd.txt files
RUN echo "Processing RVC requirements files" && \
# ---- Debugging: Check files for troubleshooting ----
echo "Current directory: $(pwd)" && ls -la && \
# ---- End of debugging ----
if [ ! -f "requirements.txt" ]; then echo "ERROR: requirements.txt NOT FOUND in $(pwd)" >&2; exit 1; fi && \
if [ ! -f "requirements-amd.txt" ]; then echo "ERROR: requirements-amd.txt NOT FOUND in $(pwd)" >&2; exit 1; fi && \
echo "--- Original requirements.txt ---" && cat requirements.txt && echo "--- End ---" && \
echo "--- Original requirements-amd.txt ---" && cat requirements-amd.txt && echo "--- End ---" && \
\
# Remove torch*, fairseq, and extension_* lines from requirements.txt
sed -i -E '/^torch(vision|audio)?\s*(==|>=)?/d' requirements.txt && \
sed -i '/^fairseq @ /d' requirements.txt && \
sed -i '/^extension_/d' requirements.txt && \
sed -i "/; sys_platform 'win32'/d" requirements.txt && \
sed -i "/; sys_platform 'darwin'/d" requirements.txt && \
echo "--- Cleaned main requirements.txt ---" && cat requirements.txt && echo "--- End ---" && \
\
# Remove torch*, numpy, numba, llvmlite, fairseq, faiss-cpu, gradio, pyworld, torchcrepe,
# torchfcpe, and onnxruntime* packages from requirements-amd.txt
sed -i -E '/^torch(vision|audio)?\\s*(==|>=)?/d' requirements-amd.txt && \
sed -i '/^tensorflow-rocm/d' requirements-amd.txt && \
sed -i '/^joblib/d' requirements-amd.txt && \
sed -i '/^numba/d' requirements-amd.txt && \
sed -i '/^numpy/d' requirements-amd.txt && \
sed -i '/^scipy/d' requirements-amd.txt && \
sed -i '/^librosa/d' requirements-amd.txt && \
sed -i '/^llvmlite/d' requirements-amd.txt && \
sed -i '/^fairseq/d' requirements-amd.txt && \
sed -i '/^faiss-cpu/d' requirements-amd.txt && \
sed -i '/^gradio/d' requirements-amd.txt && \
sed -i '/^Cython/d' requirements-amd.txt && \
sed -i '/^pyworld/d' requirements-amd.txt && \
sed -i '/^torchcrepe/d' requirements-amd.txt && \
sed -i '/^torchfcpe/d' requirements-amd.txt && \
sed -i '/^onnxruntime/d' requirements-amd.txt && \
sed -i "/; sys_platform 'darwin'/d" requirements-amd.txt && \
echo "--- Cleaned requirements-amd.txt ---" && cat requirements-amd.txt && echo "--- End ---"
# You can end this RUN block here to debug sed errors if needed.

# === Installation (Separate RUN blocks) ===
# Install remaining dependencies from the cleaned main requirements.txt
RUN echo "** Installing RVC dependencies from main requirements.txt (cleaned) **" && \
./.venv/bin/python -m pip install --no-cache-dir -r requirements.txt -c .venv/constraints.txt

# Install remaining dependencies from the cleaned requirements-amd.txt
RUN echo "** Installing RVC specific dependencies from requirements-amd.txt (cleaned) **" && \
./.venv/bin/python -m pip install --no-cache-dir -r requirements-amd.txt -c .venv/constraints.txt

# Install additional dependencies manually or with constraints, which are not in requirements files or have different pins
RUN echo "** Installing other essential dependencies into venv **" && \
./.venv/bin/python -m pip install --no-cache-dir \
-c .venv/constraints.txt \
Cython scipy librosa==0.10.2 pydub>=0.25.1 soundfile>=0.12.1 ffmpeg-python>=0.2.0 \
tensorboardX Jinja2>=3.1.2 json5 Markdown matplotlib>=3.7.2 matplotlib-inline>=0.1.3 \
praat-parselmouth>=0.4.2 Pillow>=9.1.1 resampy>=0.4.2 scikit-learn tensorboard \
tqdm>=4.63.1 tornado>=6.1 Werkzeug>=2.2.3 uc-micro-py>=1.0.1 sympy>=1.11.1 \
tabulate>=0.8.10 PyYAML>=6.0 pyasn1>=0.4.8 pyasn1-modules>=0.2.8 fsspec>=2022.11.0 \
absl-py>=1.2.0 audioread uvicorn>=0.21.1 colorama>=0.4.5 httpx fastapi==0.88 \
ffmpy==0.3.1 python-dotenv>=1.0.0 av torchcrepe==0.0.23 torchfcpe joblib==1.1.0 \
numba==0.56.4 llvmlite==0.39.0 fairseq==0.12.2 faiss-cpu==1.7.3 gradio==3.34.0 \
pyworld==0.3.2 \
# onnxruntime-rocm \ # <-- Comment or remove this line
# Try installing standard onnxruntime instead (if RVC supports it)
onnxruntime \
&& \
echo "Essential dependencies installed into venv."

# Set executable permissions for RVC scripts
RUN chmod +x *.sh

# RVC Application Launch
EXPOSE ${RVC_PORT}
# Default port for RVC (typically 7865, verify as needed)

# Copy and set up the entrypoint script for RVC
COPY entrypoint_rvc.sh /entrypoint_rvc.sh
RUN chmod +x /entrypoint_rvc.sh
ENTRYPOINT ["/entrypoint_rvc.sh"]
Loading