add_error / verl_0720_main /verl /docker /rocm /Dockerfile.rocm
geminiDeveloper's picture
Upload 1194 files
dfbcd52 verified
Raw
History Blame Contribute Delete
7.92 kB
# Global build args shared across stages.
# Declared before the first FROM so the default value lives in ONE place.
ARG GPU_ARCH="gfx942;gfx950"
# Install basic packages from OS distro
FROM ubuntu:22.04 AS base
ENV DEBIAN_FRONTEND=noninteractive
ARG PYTHON_VERSION=3.12
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
apt update && \
apt install -y git software-properties-common curl rsync dialog gfortran wget sqlite3 ccache vim && \
if ! python3 --version | grep -q ${PYTHON_VERSION} ; then \
add-apt-repository -y ppa:deadsnakes/ppa && apt update && \
apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python${PYTHON_VERSION}-venv \
python${PYTHON_VERSION}-lib2to3 python-is-python3 ; fi
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 && \
update-alternatives --set python3 /usr/bin/python${PYTHON_VERSION} && \
ln -sf /usr/bin/python${PYTHON_VERSION}-config /usr/bin/python3-config && \
curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION}
RUN wget -nv -O /tmp/cmake-3.26.4-linux-x86_64.tar.gz https://cmake.org/files/v3.26/cmake-3.26.4-linux-x86_64.tar.gz && \
tar zfx /tmp/cmake-3.26.4-linux-x86_64.tar.gz -C /opt/ && \
mv /opt/cmake-3.26.4-linux-x86_64 /opt/cmake-3.26.4 && \
rm -f /tmp/cmake-3.26.4-linux-x86_64.tar.gz
ENV PATH=/opt/cmake-3.26.4/bin:$PATH
# ccache speeds up repeated source builds (FA / TE / vLLM / aiter).
# The actual cache lives in a BuildKit cache mount, so it persists across
# builds without being baked into the image.
ENV CCACHE_DIR=/root/.cache/ccache
ENV CCACHE_MAXSIZE=50G
ENV CMAKE_C_COMPILER_LAUNCHER=ccache
ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache
ENV CMAKE_HIP_COMPILER_LAUNCHER=ccache
# Install ROCm deb packages
FROM base AS rocm_deb
ARG ROCM_VERSION=7.0.2
ARG AMDGPU_VERSION=7.0.2
ARG GFX_ARCH=gfx942|gfx950
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
curl -sL https://repo.radeon.com/rocm/rocm.gpg.key | apt-key add - \
&& printf "deb [arch=amd64] https://repo.radeon.com/rocm/apt/$ROCM_VERSION/ jammy main\n" | tee /etc/apt/sources.list.d/rocm.list \
&& printf "deb [arch=amd64] https://repo.radeon.com/amdgpu/$AMDGPU_VERSION/ubuntu jammy main\n" | tee /etc/apt/sources.list.d/amdgpu.list \
&& printf "Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600\n" | tee /etc/apt/preferences.d/rocm-pin-600 \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y rocm && \
find /opt/rocm/lib -type f -name '*gfx*' | grep -Ev "${GFX_ARCH}" | xargs rm -f && \
find /opt/rocm/lib/hipblaslt/library -type f -name '*gfx*' | grep -Ev "${GFX_ARCH}" | xargs rm -f && \
find /opt/rocm/lib/rocblas/library -type f -name '*gfx*' | grep -Ev "${GFX_ARCH}" | xargs rm -f && \
find /opt/rocm/share/miopen/db -type f -name '*gfx*' | grep -Ev "${GFX_ARCH}" | xargs rm -f
ENV ROCM_HOME=/opt/rocm
ENV CPLUS_INCLUDE_PATH=/opt/rocm/include
ENV LD_LIBRARY_PATH=/opt/rocm/lib
ENV PATH=/opt/rocm/bin:/opt/rocm/llvm/bin:$PATH
# Install pytorch packages
FROM rocm_deb AS rocm_torch
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --upgrade pip "setuptools<80" wheel numpy einops packaging psutil ninja && \
pip install /opt/rocm/share/amd_smi
# Install the prebuilt ROCm wheels directly via pip.
# NOTE: these URLs are pinned to a specific ROCm release (rocm-rel-7.0.2),
# Python ABI (cp312) and nightly git hashes. Overriding ROCM_VERSION or
# PYTHON_VERSION alone will NOT change these wheels -- you must also update
# the URLs below to matching builds, otherwise install will 404 or mismatch.
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install \
https://repo.radeon.com/rocm/manylinux/rocm-rel-7.0.2/torch-2.9.1.dev20251204+rocm7.0.2.lw.git351ff442-cp312-cp312-linux_x86_64.whl \
https://repo.radeon.com/rocm/manylinux/rocm-rel-7.0.2/apex-1.9.0a0+rocm7.0.2.git07c3ee53-cp312-cp312-linux_x86_64.whl \
https://repo.radeon.com/rocm/manylinux/rocm-rel-7.0.2/torchaudio-2.9.0+rocm7.0.2.gite3c6ee2b-cp312-cp312-linux_x86_64.whl \
https://repo.radeon.com/rocm/manylinux/rocm-rel-7.0.2/torchvision-0.24.0+rocm7.0.2.gitb919bd0c-cp312-cp312-linux_x86_64.whl \
https://repo.radeon.com/rocm/manylinux/rocm-rel-7.0.2/triton-3.5.1+rocm7.0.2.gita272dfa8-cp312-cp312-linux_x86_64.whl
ARG GPU_ARCH
ENV PYTORCH_ROCM_ARCH=${GPU_ARCH}
WORKDIR /root
# Build Flash Attention wheel
FROM rocm_torch AS fa_build
ARG FA_REPO="https://github.com/ROCm/flash-attention"
ARG FA_TAG="83f9e450cd10e20701fb109db9c7703d376f282b"
RUN git clone ${FA_REPO} \
&& cd flash-attention \
&& git checkout ${FA_TAG} \
&& git submodule init \
&& git submodule update
ARG GPU_ARCH
ARG MAX_JOBS=
RUN --mount=type=cache,target=/root/.cache/ccache \
cd flash-attention \
&& GPU_ARCHS=${GPU_ARCH} BUILD_TARGET=rocm MAX_JOBS=${MAX_JOBS:-$(nproc)} python3 setup.py bdist_wheel \
&& mkdir /install && cp dist/*.whl /install \
&& ccache -s
# Install Flash Attention
FROM fa_build AS install_fa
RUN --mount=type=bind,from=fa_build,source=/install,target=/tmp/install \
--mount=type=cache,target=/root/.cache/pip \
pip install /tmp/install/*.whl
# Install TE
FROM install_fa AS te
ARG GPU_ARCH
ENV NVTE_USE_HIPBLASLT=1
ENV NVTE_USE_ROCM=1
ENV NVTE_FRAMEWORK=pytorch
ENV NVTE_ROCM_ARCH=${GPU_ARCH}
ENV NVTE_USE_CAST_TRANSPOSE_TRITON=0
ENV NVTE_CK_USES_BWD_V3=1
ENV NVTE_CK_V3_BF16_CVT=2
ARG TE_TAG="386bd316"
ARG MAX_JOBS=
RUN --mount=type=cache,target=/root/.cache/ccache \
pip install pybind11 && git clone https://github.com/ROCm/TransformerEngine.git && \
cd TransformerEngine && git checkout ${TE_TAG} && git submodule update --init --recursive && \
GPU_ARCHS=${GPU_ARCH} MAX_JOBS=${MAX_JOBS:-$(nproc)} python3 setup.py install && \
ccache -s && \
cd .. && rm -rf TransformerEngine
# TE patch
RUN FILE=$(find /usr/local/lib/python3.12/dist-packages/ -path "*transformer_engine*/transformer_engine/pytorch/attention/dot_product_attention/utils.py") && \
sed -i '121s/2\.8\.3/2.8.4/' "$FILE"
# Install vllm
FROM te AS install_vllm
ARG VLLM_TAG="1ff9d3353"
ARG MAX_JOBS=
RUN --mount=type=cache,target=/root/.cache/ccache \
pip install setuptools_scm && \
mkdir /workspace && cd /workspace && \
ln -sf /opt/rocm/lib/libamdhip64.so /usr/lib/libamdhip64.so && \
git clone https://github.com/vllm-project/vllm && \
cd vllm && git checkout ${VLLM_TAG} && pip install -r requirements/rocm.txt && \
MAX_JOBS=${MAX_JOBS:-$(nproc)} python3 setup.py develop --no-deps && \
ccache -s
RUN --mount=type=cache,target=/root/.cache/pip \
pip uninstall tilelang -y && pip install xgrammar==0.1.32
FROM install_vllm AS install_verl
RUN --mount=type=cache,target=/root/.cache/pip \
pip install cupy-rocm-7-0
ENV MIOPEN_DEBUG_CONV_DIRECT=0
ARG AITER_TAG="45c428e54"
ARG MAX_JOBS=
RUN --mount=type=cache,target=/root/.cache/ccache \
cd /workspace && git clone --recursive https://github.com/ROCm/aiter.git && \
cd aiter && git checkout ${AITER_TAG} && \
MAX_JOBS=${MAX_JOBS:-$(nproc)} python3 setup.py develop && \
ccache -s
# For qwen3.5
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -U git+https://github.com/ISEEKYAN/mbridge.git@v0.15.1 && \
pip install --no-deps megatron-bridge==0.5.0 && \
pip install transformers --upgrade && \
pip install megatron-core==0.18.0 && \
pip install mathruler && \
pip install qwen_vl_utils && \
pip install flash-linear-attention
RUN --mount=type=cache,target=/root/.cache/pip \
cd /workspace && git clone https://github.com/verl-project/verl.git && \
cd verl && pip install .
WORKDIR /workspace/verl
CMD ["/bin/bash"]