diff --git a/dockerfile/rocm10.1.x.dockerfile b/dockerfile/rocm10.1.x.dockerfile new file mode 100644 index 000000000..539125c96 --- /dev/null +++ b/dockerfile/rocm10.1.x.dockerfile @@ -0,0 +1,332 @@ +ARG BASE_IMAGE=rocm/pytorch:rocm10.1.0_ubuntu26.04_py3.14_pytorch_release_2.13.0@sha256:1d3ebef7da1df35f0c103ed038521933ebaeaf6f8c8d710168d8c294efdc59d9 +FROM ${BASE_IMAGE} + +LABEL maintainer="SuperBench" +SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"] + +# Experimental scaffold: preserve AMD's matched Python 3.14 / PyTorch 2.13 stack. +# SDK packages include all devices; this argument selects the targets of locally +# built kernels (SuperBench benchmarks, RCCL and TransformerEngine). +ARG AMDGPU_TARGETS="gfx942 gfx950 gfx1250" +ARG NUM_MAKE_JOBS=64 +ARG ROCM_VERSION=10.1.0 +# rocm-systems revision selected by TheRock's therock-10.1 release. +ARG ROCM_SYSTEMS_COMMIT=7da43026e4f2ef7600433c38c820732f7a205d22 +# Retain the source override for MI455X (gfx1250) RCCL fixes, including +# ROCm/rocm-systems#12051 (GPU->NIC distance and GDR on gfx1250 +# MLOPart partitions) and the gfx1250 symmetric-memory/VMM teardown fixes. +# RCCL and RCCL-tests are built from this revision into RCCL_SOURCE_PREFIX. +# Pass an empty value to keep the packaged RCCL with release-matched RCCL-tests. +ARG RCCL_SOURCE_COMMIT=2a0c58ec63ea22487ea65458b68b92426119eb11 + +ENV DEBIAN_FRONTEND=noninteractive \ + AMDGPU_TARGETS="${AMDGPU_TARGETS}" \ + CMAKE_BUILD_PARALLEL_LEVEL="${NUM_MAKE_JOBS}" \ + CMAKE_POLICY_VERSION_MINIMUM=3.5 \ + MPI_HOME=/usr/local/mpi \ + RCCL_SOURCE_PREFIX=/opt/rccl \ + EXTRAS_PATH=/opt/rocm/extras-10 \ + SB_HOME=/opt/superbench \ + SB_MICRO_PATH=/opt/superbench \ + ANSIBLE_DEPRECATION_WARNINGS=FALSE \ + ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections + +# The 10.1 base runs the system /usr/bin/python3 (the 10.0 base used /opt/venv). +# TE's AOTriton build creates a venv from that interpreter and needs liblzma. +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + autoconf automake bc build-essential ca-certificates cmake curl \ + dmidecode flex gfortran git gnupg iproute2 jq libaio-dev \ + libatomic1 libboost-program-options-dev libcap2 libcurl4-openssl-dev \ + libdrm-dev libibumad-dev libibverbs-dev liblzma-dev libnuma-dev libpci-dev libquadmath0 librdmacm-dev \ + libssl-dev libtinfo6 libtool lshw net-tools ninja-build numactl \ + openssh-client openssh-server pciutils pkg-config python3-dev python3-venv rsync sudo \ + util-linux wget && \ + pkg-config --exists liblzma && \ + /usr/bin/python3 -m venv /tmp/sb-aotriton-venv-check && \ + /tmp/sb-aotriton-venv-check/bin/python -m pip --version && \ + rm -rf /tmp/sb-aotriton-venv-check && \ + apt-get clean + +# Install the Docker CLI client only. +ARG DOCKER_VERSION=29.6.2 +RUN curl -fsSL "https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz" -o /tmp/docker.tgz && \ + tar --extract --file /tmp/docker.tgz --strip-components 1 --directory /usr/local/bin/ docker/docker && \ + rm /tmp/docker.tgz + +# Update system config. +RUN mkdir -p /root/.ssh /var/run/sshd && \ + touch /root/.ssh/authorized_keys && \ + sed -i 's/[# ]*PermitRootLogin prohibit-password/PermitRootLogin yes/; s/[# ]*PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config && \ + printf '%s\n' '* soft nofile 1048576' '* hard nofile 1048576' >> /etc/security/limits.conf + +# Match the Ubuntu 26.04 Azure HPC userspace stack; never install host drivers here. +# TODO: Add a selectable alternative networking stack after its qualification. +ARG DOCA_VERSION=3.4.0 +ARG DOCA_PACKAGE_VERSION=3.4.0-085000 +ARG DOCA_OPENMPI_VERSION=5.0.10rc2.2605121430-1.b99be7132e +ARG DOCA_BUNDLE_SHA256=60789bbbfc9b283a87a64589a0d4bd5d08d1b746494c24ce05e10bbd694de6bb +# Use NVIDIA's signed local repository bundle: the online repository's TLS EOF +# handling fails with Ubuntu 26.04 APT. Do not disable certificate/signature checks. +RUN curl -fsSL "https://content.mellanox.com/DOCA/DOCA_v${DOCA_VERSION}/host/doca-host_${DOCA_PACKAGE_VERSION}-26.04-ubuntu2604_amd64.deb" -o /tmp/doca-host.deb && \ + printf '%s %s\n' "${DOCA_BUNDLE_SHA256}" /tmp/doca-host.deb | sha256sum --check --strict && \ + dpkg -i /tmp/doca-host.deb && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + "doca-ofed-userspace=${DOCA_PACKAGE_VERSION}" "openmpi=${DOCA_OPENMPI_VERSION}" && \ + mpi_prefix=$(dpkg-query -L openmpi | sed -n 's#/bin/mpirun$##p') && \ + test -n "${mpi_prefix}" && \ + test -x "${mpi_prefix}/bin/mpicc" && \ + ln -s "${mpi_prefix}" "${MPI_HOME}" && \ + printf '%s\n' "${MPI_HOME}/lib" > /etc/ld.so.conf.d/superbench-mpi.conf && \ + ldconfig && \ + "${MPI_HOME}/bin/mpirun" --version && \ + apt-get purge -y doca-host && \ + rm /tmp/doca-host.deb && \ + apt-get update && apt-get clean + +# Add development files to the base's SDK and use AMD's path discovery directly. +# The SDK's prebuilt RCCL remains installed; RCCL_SOURCE_COMMIT may add an override. +RUN python3 -m pip install --index-url https://stable.repo.amd.com/rocm/whl-next/ \ + "rocm[devel,libraries,device-all]==${ROCM_VERSION}" && \ + rocm-sdk init && \ + ROCM_PATH="$(rocm-sdk path --root)" && \ + test -r "${ROCM_PATH}/.info/version" && \ + test -r "${ROCM_PATH}/lib/librccl.so" && \ + printf 'export ROCM_PATH=%q\n' "${ROCM_PATH}" > /etc/profile.d/rocm10-env.sh && \ + printf '%s\n' \ + 'export ROCM_HOME="${ROCM_PATH}" HIP_PATH="${ROCM_PATH}" RCCL_HOME="${ROCM_PATH}"' \ + 'export PATH="${EXTRAS_PATH}/bin:${MPI_HOME}/bin:${SB_MICRO_PATH}/bin:${ROCM_PATH}/bin:${PATH}"' \ + 'export LD_LIBRARY_PATH="${EXTRAS_PATH}/lib:${MPI_HOME}/lib:${ROCM_PATH}/lib:${ROCM_PATH}/lib/llvm/lib:${ROCM_PATH}/lib/host-math/lib:${ROCM_PATH}/lib/rocm_sysdeps/lib"' \ + >> /etc/profile.d/rocm10-env.sh + +# Resolve the SDK once at build time; shell startup must not reinitialize it. +ENV BASH_ENV=/etc/profile.d/rocm10-env.sh +ENTRYPOINT ["/bin/bash", "-e", "-c", "exec \"$@\"", "--"] +CMD ["/bin/bash"] + +# Register the bundled module until https://github.com/ROCm/TheRock/issues/3054 +# is fixed (upstream registration: https://github.com/ROCm/TheRock/pull/8424). +# A relative .pth entry preserves the wrapper's lookup of its matching library. +RUN python3 -c 'import sysconfig; from pathlib import Path; Path(sysconfig.get_path("purelib"), "amdsmi.pth").write_text("_rocm_sdk_core/share/amd_smi\n")' && \ + python3 -c 'import amdsmi' + +# Built-in MPI calls exchange host data; RCCL exchanges GPU buffers. The DOCA +# Open MPI package needs neither a ROCm-aware rebuild nor unused OpenSHMEM. +ENV SB_ROCM_MEM_BW_BACKEND=transferbench \ + USE_HIP_DATATYPE=1 \ + USE_HIPBLAS_COMPUTETYPE=1 + +# Install RVS through AMD's signed Ubuntu 26.04 repositories. Explicitly select +# matching ROCm 10.1 native dependencies instead of legacy distro packages. +ARG RVS_VERSION=1.6.122-708 +ARG ROCM_APT_VERSION=10.1.0-3 +RUN install -d -m 0755 /etc/apt/keyrings && \ + curl -fsSL https://stable.repo.amd.com/rocm/gpg/packages.gpg | \ + gpg --batch --yes --dearmor -o /etc/apt/keyrings/amdrocm.gpg && \ + printf '%s\n' 'Types: deb' \ + 'URIs: https://stable.repo.amd.com/rocm/core/packages/ubuntu2604/' \ + 'Suites: stable' 'Components: main' 'Architectures: amd64' \ + 'Signed-By: /etc/apt/keyrings/amdrocm.gpg' > /etc/apt/sources.list.d/amdrocm-core.sources && \ + printf '%s\n' 'Types: deb' \ + 'URIs: https://stable.repo.amd.com/rocm/extras/rvs/packages/ubuntu2604/' \ + 'Suites: stable' 'Components: main' 'Architectures: amd64' \ + 'Signed-By: /etc/apt/keyrings/amdrocm.gpg' > /etc/apt/sources.list.d/amdrocm-rvs.sources && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + "amdrocm-runtime=${ROCM_APT_VERSION}" "amdrocm-base=${ROCM_APT_VERSION}" \ + "amdrocm-amdsmi=${ROCM_APT_VERSION}" "amdrocm-blas=${ROCM_APT_VERSION}" \ + "amdrocm-rand=${ROCM_APT_VERSION}" "amdrocm-llvm=${ROCM_APT_VERSION}" \ + "amdrocm10-rvs=${RVS_VERSION}" && \ + apt-get clean && \ + test -x "${EXTRAS_PATH}/bin/rvs" && \ + test -x "${EXTRAS_PATH}/bin/TransferBench" + +WORKDIR ${SB_HOME} +COPY third_party third_party + +# Build RCCL-tests, and RCCL itself when RCCL_SOURCE_COMMIT is set, from one +# rocm-systems revision. The source-built library precedes the SDK library on +# LD_LIBRARY_PATH, which RUNPATH alone cannot override, so soname lookups +# (including SuperBench's mpirun -x LD_LIBRARY_PATH) resolve the fixed RCCL. +RUN rccl_architectures=$(printf '%s' "${AMDGPU_TARGETS}" | tr -s '[:space:]' ';' | sed 's/^;//; s/;$//') && \ + if [ -z "${rccl_architectures}" ]; then \ + echo 'AMDGPU_TARGETS must contain at least one GPU architecture.' >&2; exit 1; \ + fi && \ + if [ -n "${RCCL_SOURCE_COMMIT}" ]; then \ + rocm_systems_commit="${RCCL_SOURCE_COMMIT}"; rccl_prefix="${RCCL_SOURCE_PREFIX}"; \ + rccl_projects='projects/rccl projects/rccl-tests'; \ + else \ + rocm_systems_commit="${ROCM_SYSTEMS_COMMIT}"; rccl_prefix="${ROCM_PATH}"; \ + rccl_projects='projects/rccl-tests'; \ + fi && \ + git init /tmp/rocm-systems && \ + git -C /tmp/rocm-systems remote add origin https://github.com/ROCm/rocm-systems.git && \ + git -C /tmp/rocm-systems sparse-checkout set ${rccl_projects} && \ + git -C /tmp/rocm-systems fetch --depth 1 --filter=blob:none origin "${rocm_systems_commit}" && \ + git -C /tmp/rocm-systems checkout --detach FETCH_HEAD && \ + if [ -n "${RCCL_SOURCE_COMMIT}" ]; then \ + cmake -S /tmp/rocm-systems/projects/rccl -B /tmp/rccl-build -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_CXX_COMPILER="${ROCM_PATH}/bin/hipcc" \ + -DCMAKE_PREFIX_PATH="${ROCM_PATH}" \ + -DROCM_PATH="${ROCM_PATH}" \ + -DGPU_TARGETS="${rccl_architectures}" \ + -DBUILD_TESTS=OFF \ + -DCMAKE_INSTALL_PREFIX="${rccl_prefix}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_INSTALL_RPATH="${ROCM_PATH}/lib" && \ + cmake --build /tmp/rccl-build -j"${NUM_MAKE_JOBS}" && \ + cmake --install /tmp/rccl-build && \ + test -r "${rccl_prefix}/lib/librccl.so" && \ + printf 'export RCCL_HOME=%q\n' "${rccl_prefix}" >> /etc/profile.d/rocm10-env.sh && \ + printf 'export LD_LIBRARY_PATH=%q:"${LD_LIBRARY_PATH}"\n' "${rccl_prefix}/lib" >> /etc/profile.d/rocm10-env.sh; \ + fi && \ + cmake -S /tmp/rocm-systems/projects/rccl-tests -B /tmp/rccl-tests-build \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH="${rccl_prefix};${ROCM_PATH};${MPI_HOME}" \ + -DROCM_PATH="${ROCM_PATH}" \ + -DGPU_TARGETS="${rccl_architectures}" \ + -DUSE_MPI=ON \ + -DCMAKE_INSTALL_PREFIX="${SB_HOME}" \ + -DCMAKE_INSTALL_RPATH="${rccl_prefix}/lib;${ROCM_PATH}/lib;${MPI_HOME}/lib" \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON && \ + cmake --build /tmp/rccl-tests-build -j"${NUM_MAKE_JOBS}" && \ + cmake --install /tmp/rccl-tests-build && \ + rm -rf /tmp/rocm-systems /tmp/rccl-build /tmp/rccl-tests-build && \ + bash -c 'ldd "${SB_HOME}/bin/all_reduce_perf"' | grep -F "${rccl_prefix}/lib/librccl.so" + +# Do not invoke the legacy ROCm aggregate target: it clones HIP 5.5 samples, +# rebuilds math libraries, and installs unqualified Megatron/DeepSpeed dependencies. +RUN test -f third_party/fio/Makefile && \ + test -f third_party/perftest/autogen.sh && \ + make -C third_party fio rocm_perftest + +# Extract only matching prebuilt clients and their external GPU kernel packs. +# The ELFs alone cannot initialize matrices without the blas_test_*.kpack files. +ARG ROCM_TESTS_SHA256=c6d6afe27474badb88793330278616caf74c40d647ea2d26457352d7dfc0ace8 +RUN curl -fsSL "https://stable.repo.amd.com/rocm/core/tarball/therock-dist-linux-multiarch-tests-${ROCM_VERSION}.tar.gz" -o /tmp/rocm-tests.tar.gz && \ + printf '%s %s\n' "${ROCM_TESTS_SHA256}" /tmp/rocm-tests.tar.gz | sha256sum --check --strict && \ + tar -xzf /tmp/rocm-tests.tar.gz -C "${SB_HOME}" --wildcards --no-wildcards-match-slash \ + './bin/rocblas-bench' './bin/hipblaslt-bench' './.kpack/blas_test_*.kpack' && \ + rm /tmp/rocm-tests.tar.gz && \ + test -x "${SB_HOME}/bin/rocblas-bench" && \ + test -x "${SB_HOME}/bin/hipblaslt-bench" && \ + test -s "${SB_HOME}/.kpack/blas_test_gfx942.kpack" && \ + test -s "${SB_HOME}/.kpack/blas_test_gfx950.kpack" && \ + test -s "${SB_HOME}/.kpack/blas_test_gfx1250.kpack" + +COPY . . +# Keep AMD's framework and all-device SDK packages when resolving SuperBench deps. +# The same constraints protect them while building the frameworks below. +# The SDK supplies amdsmi via .pth, not a separate distribution; use the torch +# extra so amdworker does not install a PyPI wrapper that shadows the SDK module. +# Drop stale setuptools output from the build context before installing. +RUN rm -rf build *.egg-info && \ + python3 -m pip freeze | grep -Ei '^(torch|torchvision|torchaudio|triton|apex|rocm|rocm[-_][^=]+)==' > /tmp/rocm10-constraints.txt && \ + python3 -m pip install -c /tmp/rocm10-constraints.txt '.[torch]' && \ + python3 -m pip install pytest pytest-timeout vcrpy + +# This TE revision still includes the legacy ROCm SMI header, which the SDK omits. +# Build that library from the release's rocm-systems revision under /usr/local, +# separate from the SDK and its AMD SMI. +RUN git init -q /tmp/rocm-smi-source && \ + git -C /tmp/rocm-smi-source remote add origin https://github.com/ROCm/rocm-systems.git && \ + git -C /tmp/rocm-smi-source sparse-checkout set projects/rocm-smi-lib && \ + git -C /tmp/rocm-smi-source fetch -q --depth 1 --filter=blob:none origin "${ROCM_SYSTEMS_COMMIT}" && \ + git -C /tmp/rocm-smi-source checkout -q --detach FETCH_HEAD && \ + cmake -S /tmp/rocm-smi-source/projects/rocm-smi-lib -B /tmp/rocm-smi-build -G Ninja \ + -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DCMAKE_INSTALL_LIBDIR=lib -DROCM_SMI_DISABLE=OFF -DBUILD_TESTS=OFF && \ + cmake --build /tmp/rocm-smi-build -j"${NUM_MAKE_JOBS}" && \ + cmake --install /tmp/rocm-smi-build && \ + printf '%s\n' /usr/local/lib > /etc/ld.so.conf.d/superbench-rocm-smi.conf && \ + ldconfig && \ + test -r /usr/local/include/rocm_smi/rocm_smi.h && \ + printf '#include \n' | \ + "${ROCM_PATH}/lib/llvm/bin/clang++" -x c++ -fsyntax-only - && \ + python3 -c 'import ctypes; ctypes.CDLL("/usr/local/lib/librocm_smi64.so").rsmi_init' && \ + rm -rf /tmp/rocm-smi-source /tmp/rocm-smi-build + +# Build TransformerEngine, AITER and Megatron-LM from pinned sources against the +# base's PyTorch, Triton and SDK, without build isolation or dependency resolution. +# TE v2.15_rocm, AITER snapshot 2026-09-30, Megatron Core v0.19.2. The TE 2.18-dev +# alternative cannot compile its BF16 small-sequence attention for gfx1250. +# TE uses its own pinned AITER/CK. CK attention excludes gfx1250 and AOTriton ships +# only gfx942/gfx950 images, so gfx1250 gets TE's common kernels. +ARG TE_COMMIT=e7835ed1b134f56e58c575fba2455471064cab9b +ARG AITER_COMMIT=89a47b84ac4b576339a50047e290c383c2377389 +ARG MEGATRON_COMMIT=4b4acac9a1d28ea6829c8d4f566d75698a21249d +ENV SB_ROCM10_FRAMEWORK_ROOT=/opt/rocm10-frameworks \ + SB_MEGATRON_PATH=/opt/rocm10-frameworks/Megatron-LM \ + AITER_USE_SYSTEM_TRITON=1 \ + TRITON_F32_DEFAULT=ieee \ + MAX_JOBS=16 \ + CUDA_DEVICE_MAX_CONNECTIONS=1 \ + NVTE_FLASH_ATTN=0 \ + NVTE_FUSED_ATTN=1 \ + NVTE_FUSED_ATTN_CK=1 \ + NVTE_FUSED_ATTN_AOTRITON=0 +RUN framework_jobs="${NUM_MAKE_JOBS}" && \ + if [ "${framework_jobs}" -gt 16 ]; then framework_jobs=16; fi && \ + te_architectures=$(printf '%s' "${AMDGPU_TARGETS}" | tr -s '[:space:]' ';' | sed 's/^;//; s/;$//') && \ + export MAX_JOBS="${framework_jobs}" CMAKE_BUILD_PARALLEL_LEVEL="${framework_jobs}" \ + NVTE_BUILD_MAX_JOBS="${framework_jobs}" PIP_CONSTRAINT=/tmp/rocm10-constraints.txt \ + TMPDIR=/tmp/rocm10-frameworks-scratch NVTE_USE_ROCM=1 NVTE_FRAMEWORK=pytorch \ + NVTE_ROCM_ARCH="${te_architectures}" NVTE_NO_LOCAL_VERSION=1 NVTE_CK_JIT=1 \ + NVTE_FUSED_ATTN_AOTRITON=1 PREBUILD_KERNELS=0 BUILD_TARGET=rocm RCCL_HOME="${ROCM_PATH}" && \ + python3 -c 'import sys; from importlib.metadata import version; expected = {"torch": "2.13.0+rocm10.1.0", "triton": "3.8.0+git669b31ac.rocm10.1.0", "rocm-sdk-core": "10.1.0", "rocm-sdk-devel": "10.1.0"}; wrong = ["{}=={} (found {})".format(name, value, version(name)) for name, value in expected.items() if version(name) != value]; sys.exit("Unexpected base packages: " + ", ".join(wrong) if wrong else 0)' && \ + mkdir -p "${TMPDIR}" && \ + python3 -m pip install \ + pybind11==3.0.1 pydantic==2.13.5 einops==0.8.2 psutil==7.2.2 mpi4py==4.1.1 \ + flydsl==0.3.4.1 pandas==3.0.5 nvdlfw-inspect==0.2.2 \ + onnxscript==0.7.2 onnx-ir==1.0.0 onnx==1.23.1 ml_dtypes==0.6.0 && \ + for source in "TransformerEngine https://github.com/ROCm/TransformerEngine.git ${TE_COMMIT}" \ + "aiter https://github.com/ROCm/aiter.git ${AITER_COMMIT}" \ + "Megatron-LM https://github.com/NVIDIA/Megatron-LM.git ${MEGATRON_COMMIT}"; do \ + set -- ${source} && \ + git init -q "${SB_ROCM10_FRAMEWORK_ROOT}/$1" && \ + git -C "${SB_ROCM10_FRAMEWORK_ROOT}/$1" remote add origin "$2" && \ + git -C "${SB_ROCM10_FRAMEWORK_ROOT}/$1" fetch -q --depth 1 origin "$3" && \ + git -C "${SB_ROCM10_FRAMEWORK_ROOT}/$1" checkout -q --detach FETCH_HEAD && \ + git -C "${SB_ROCM10_FRAMEWORK_ROOT}/$1" submodule update --init --recursive --depth 1 || exit 1; \ + done && \ + git -C "${SB_MEGATRON_PATH}" apply "${SB_HOME}/third_party/Megatron/megatron_core_0.19.2_rocm10.patch" && \ + python3 -m pip wheel --no-build-isolation --no-deps -w /tmp/rocm10-wheels \ + "${SB_ROCM10_FRAMEWORK_ROOT}/TransformerEngine" "${SB_ROCM10_FRAMEWORK_ROOT}/aiter" "${SB_MEGATRON_PATH}" && \ + python3 -m pip install --no-deps /tmp/rocm10-wheels/*.whl && \ + python3 -m pip check && \ + python3 -m pip freeze | grep -Ei '^(torch|torchvision|torchaudio|triton|apex|rocm|rocm[-_][^=]+)==' | \ + diff -u /tmp/rocm10-constraints.txt - && \ + rm -rf /tmp/rocm10-wheels "${TMPDIR}" + +# Build-only framework settings above stay out of the runtime environment. +RUN printf '%s\n' \ + "PATH=${PATH}" \ + "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" \ + "SB_MICRO_PATH=${SB_MICRO_PATH}" \ + "SB_ROCM_MEM_BW_BACKEND=${SB_ROCM_MEM_BW_BACKEND}" \ + "ROCM_PATH=${ROCM_PATH}" \ + "ROCM_HOME=${ROCM_HOME}" \ + "HIP_PATH=${HIP_PATH}" \ + "RCCL_HOME=${RCCL_HOME}" \ + "SB_ROCM10_FRAMEWORK_ROOT=${SB_ROCM10_FRAMEWORK_ROOT}" \ + "SB_MEGATRON_PATH=${SB_MEGATRON_PATH}" \ + "AITER_USE_SYSTEM_TRITON=${AITER_USE_SYSTEM_TRITON}" \ + "TRITON_F32_DEFAULT=${TRITON_F32_DEFAULT}" \ + "MAX_JOBS=${MAX_JOBS}" \ + "CUDA_DEVICE_MAX_CONNECTIONS=${CUDA_DEVICE_MAX_CONNECTIONS}" \ + "NVTE_FLASH_ATTN=${NVTE_FLASH_ATTN}" \ + "NVTE_FUSED_ATTN=${NVTE_FUSED_ATTN}" \ + "NVTE_FUSED_ATTN_CK=${NVTE_FUSED_ATTN_CK}" \ + "NVTE_FUSED_ATTN_AOTRITON=${NVTE_FUSED_ATTN_AOTRITON}" \ + > /etc/environment + +# Build SuperBench and finish installation. +RUN CXX="${ROCM_PATH}/bin/hipcc" make cppbuild && \ + make postinstall + +RUN python3 -m pip check && \ + sb --help && \ + rm /tmp/rocm10-constraints.txt && \ + rm -rf .git diff --git a/docs/getting-started/installation.mdx b/docs/getting-started/installation.mdx index a3f2f7c47..d3e69b0e4 100644 --- a/docs/getting-started/installation.mdx +++ b/docs/getting-started/installation.mdx @@ -107,6 +107,175 @@ Here're the system requirements for all managed GPU nodes. * Compatible GPU drivers should be installed correctly, and group permission should be set to access GPU resources. You should be able to run `rocm-smi` and `rocminfo` directly to check GPU usage and information. * [Docker CE](https://docs.docker.com/engine/install/) version 20.10 or later (which can be checked by running `docker --version`). +* NUMA auto-balancing should be disabled on the host, as AMD + [recommends](https://instinct.docs.amd.com/projects/amdgpu-docs/en/docs-30.20.1/system-optimization/mi300x.html#disable-numa-auto-balancing) + for MI200 and MI300 series systems. Hangs and unexpected behavior have also been seen on MI455X with the ROCm 10 + image when it is enabled. This is a host kernel setting that the container cannot change. + `cat /proc/sys/kernel/numa_balancing` should print `0`. Disable it until the next reboot with + `sudo sysctl -w kernel.numa_balancing=0`, or persistently with + `echo 'kernel.numa_balancing = 0' | sudo tee /etc/sysctl.d/99-numa-balancing.conf && sudo sysctl --system`. + +### Experimental ROCm 10 image scaffold + +`dockerfile/rocm10.1.x.dockerfile` starts from AMD's digest-pinned +`rocm10.1.0_ubuntu26.04_py3.14_pytorch_release_2.13.0` image. +It is a scaffold, not a feature-equivalent replacement for the ROCm 7 images, +and is intentionally not yet in the release-image workflow matrix. Hosts need +the AMD GPU prerequisites above, including NUMA auto-balancing disabled. + +```bash +git submodule update --init --recursive +docker build --build-arg NUM_MAKE_JOBS=8 \ + -f dockerfile/rocm10.1.x.dockerfile -t superbench:rocm10-scaffold . +``` + +The base contains a wheel-distributed SDK. The scaffold installs +`rocm[devel,libraries,device-all]==10.1.0` and preserves the base's framework +and SDK versions with pip constraints. Unlike the ROCm 10.0 base, which used a +virtualenv under `/opt/venv`, the 10.1 base runs the system `/usr/bin/python3`, +so SuperBench and the frameworks install into its site-packages and +`python3-venv` is added for TransformerEngine's AOTriton build. **All-device GPU packages are the +default**; this is not a multi-platform CPU image (the base is Linux x86_64). +`rocm-sdk init` expands the development tree. `ROCM_PATH` (and `ROCM_HOME`, +`HIP_PATH`) is set to the discovered wheel SDK root in +`/etc/profile.d/rocm10-env.sh`; no `/opt/rocm` alias is created. The native +`amdrocm-*` 10.1.0 runtime, base, AMD SMI, BLAS, rand and LLVM packages from +AMD's APT repository are installed only as RVS dependencies; SuperBench builds +and `LD_LIBRARY_PATH` use the wheel SDK. The core wheel's bundled AMD SMI Python +bindings are registered in place with a `.pth` entry (until +[ROCm/TheRock#3054](https://github.com/ROCm/TheRock/issues/3054) is fixed), so +`import amdsmi` does not pick up a separate PyPI wrapper. + +* RCCL and RCCL-tests are built from one `rocm-systems` revision + (`RCCL_SOURCE_COMMIT`) and installed under `/opt/rccl` and + `/opt/superbench/bin`. The default revision contains the gfx1250 (MI455X) + fixes merged after TheRock's `therock-10.1` release branched, including + [ROCm/rocm-systems#12051](https://github.com/ROCm/rocm-systems/pull/12051). + `/opt/rccl/lib` precedes the SDK library on `LD_LIBRARY_PATH`, so RCCL-tests + and other soname lookups, including SuperBench MPI launches, resolve it. Build with + `--build-arg RCCL_SOURCE_COMMIT=` to keep AMD's prebuilt SDK RCCL and compile + only RCCL-tests from the `therock-10.1` revision. +* Open MPI 5.0.10 from the DOCA 3.4.0 userspace packages retains + `/usr/local/mpi`. Current built-in MPI calls exchange + host metadata, timing/error values, and NumPy arrays; GPU collectives use + RCCL. This scaffold does not claim ROCm-aware MPI support for applications + that pass device pointers directly to MPI. +* Locally compiled kernels (SuperBench benchmarks, RCCL and TransformerEngine) + default to `gfx942 gfx950 gfx1250`, independently of the all-device SDK + packages. Other kernel targets require an explicit `AMDGPU_TARGETS` build + argument and hardware qualification. +* RVS `1.6.122-708` and its bundled TransferBench come from AMD's signed + Ubuntu 26.04 APT repositories under `/opt/rocm/extras-10`. The image sets + `SB_ROCM_MEM_BW_BACKEND=transferbench` for ROCm `mem-bw`; the TransferBench + backend itself is added by a separate benchmark change, and `mem-bw` is not + runnable in this image without it. +* The image includes SuperBench, its native microbenchmarks, RCCL-tests, fio, + ROCm-enabled perftest, `rocblas-bench`/`hipblaslt-bench` from TheRock's test + archive, and TransformerEngine, AITER and Megatron-LM built in the Dockerfile + from pinned revisions (`TE_COMMIT`, `AITER_COMMIT`, `MEGATRON_COMMIT`) against + the base's PyTorch, Triton and SDK. No host driver is installed. +* The pinned TransformerEngine revision still includes the legacy ROCm SMI + header, which the SDK no longer ships, so `rocm-smi-lib` is built from the + release's `rocm-systems` revision into `/usr/local` as a build compatibility + library, separate from the SDK and its AMD SMI. + +The following remain absent: Intel MLC (`cpu-memory-bw-latency`), +Megatron-DeepSpeed, and the old HIP 5.5 `hipBusBandwidth` sample. Existing +`rocm-smi` system-info collection and `rocprofv2` tracing still need their +separate ROCm 10 migrations. + +The ROCm 10.1 image has been built and passed the current (26.10) SuperBench +benchmark configuration, together with the PyTorch DDP store fix in the +separate benchmark change. + +Earlier validation of the ROCm 10.0 variant on 2026-09-30 used AMD's packaged SDK RCCL +(equivalent to `--build-arg RCCL_SOURCE_COMMIT=`): the image built successfully and passed `pip check`, +34 targeted regression tests (three NVIDIA-only tests skipped), GEMM correctness +on all eight MI300X GPUs, FP16/BF16 PyTorch flash SDPA forward/backward, and the +SuperBench GPU-copy wrapper with data checking and 304 positive parsed metrics. +An eight-rank Open MPI / packaged-RCCL all-reduce passed data checking +(`NCCL_IB_DISABLE=1`, single node). RVS module/GPU discovery also worked. +That 10.0 validation did not build or run the default source-built RCCL path. These checks +do not qualify multi-node networking, additional GPU architectures, +the omitted benchmarks, or sustained RVS stress workloads. + +### ROCm 10 migration considerations + +The following is a scouting snapshot from **2026-09-29**, not a claim that the +ROCm 7 images support ROCm 10 or a new GPU. Keep the ROCm 7 baseline while +qualifying a separately pinned ROCm 10 image. + +#### Confirm the new GPU target first + +TheRock's public +[target definitions](https://github.com/ROCm/TheRock/blob/68ac349433a9a1f8434010c2751404d0f6192916/cmake/therock_amdgpu_targets.cmake) +identify **MI450/MI450X/MI455X as `gfx1250`**, not `gfx1251`. +Its [development support table](https://github.com/ROCm/TheRock/blob/68ac349433a9a1f8434010c2751404d0f6192916/SUPPORTED_GPUS.md) +marks `gfx1250` build-passing and sanity-tested but not release-ready. +The public [ROCm 10 compatibility matrix](https://rocm.docs.amd.com/en/latest/compatibility/compatibility-matrix.html) +lists MI300X and MI355X, but does not yet list MI455X. + +Treat `gfx1251` as a separate, unqualified target until the actual device's +`rocminfo` output and its vendor support matrix establish the mapping. +Compiler recognition is not proof of runtime, library kernel, or framework +support. Do not simply add either target to the ROCm 7 Dockerfiles or their +TransformerEngine AOTriton allowlists. + +#### Installation and dependency changes + +[ROCm 10 is a production Core SDK release built through TheRock](https://rocm.docs.amd.com/en/latest/about/transition-guide-TheRock.html). +It changes more than the base-image tag: + +| Area | ROCm 7 baseline | ROCm 10 work to qualify | +| --- | --- | --- | +| SDK packaging | Legacy packages such as `amd-smi-lib`, `rocm-cmake`, and `hipify-clang`; `/opt/rocm` paths | Core SDK under `/opt/rocm/core-10.0`; packages such as `amdrocm-amdsmi`, `amdrocm-base`, `amdrocm-hipify`, `amdrocm-blas`, and `amdrocm-rccl`. Package-manager installs provide compatibility symlinks; tarballs/wheels need explicit path discovery. | +| Source builds | Separate RCCL, rocBLAS, hipBLASLt and HIP clones | Pin a coherent TheRock release and its dependencies. Math libraries now live in [rocm-libraries](https://github.com/ROCm/rocm-libraries); runtime, HIP and management/profiling components in [rocm-systems](https://github.com/ROCm/rocm-systems). Do not assume old branches, `install.sh` options, or the 7.2 standalone hipBLASLt client shim remain applicable. | +| Device libraries | Prebuilt gfx942/gfx950 kernels plus locally compiled benchmarks | Install the matching device kernel packs as well as host libraries, compiler, headers and benchmark clients. Confirm each requested target is actually in the shipped artifacts. Keep MI300X as a regression target. | +| Frameworks | PyTorch 2.9.1; TE `v2.4_rocm` / `v2.10_rocm`; CK attention disabled | Select matched PyTorch, Triton, TE and attention-library releases. Current [TE development](https://github.com/ROCm/TransformerEngine/blob/03afd8f813300417ee1a41a4471d89be71c88f2d/README.rst) uses hipBLASLt for GEMM and AITER/CK JIT for attention; warm and record JIT caches before timing. AOTriton remains version/ABI-sensitive and its development builds add FlyDSL dependencies. | +| Monitoring | Python device manager already uses AMD SMI, but system-info collection invokes `rocm-smi` | ROCm SMI is removed from Core SDK. Port system-info commands and parsers to AMD SMI; retest enumeration, power units, ECC, topology and partition identifiers. | +| Profiling | Runner builds `rocprofv2` commands | Qualify ROCprofiler-SDK / `rocprofv3`, its CLI arguments and output formats; update runner tests and trace collection rather than only renaming the executable. | +| Host integration | Container uses the host's kernel driver and network devices | Qualify the OS, AMDGPU driver/firmware and user-space compatibility together. Preserve matched OFED/RDMA libraries and test single-node then multi-node RCCL; installing a newer SDK inside a container does not update the host driver. | + +For Python-distributed SDKs, TheRock now separates `rocm-sdk-core`, +`rocm-sdk-libraries`, `rocm-sdk-devel`, and `rocm-sdk-device-*`. +[TheRock's release instructions](https://github.com/ROCm/TheRock/blob/68ac349433a9a1f8434010c2751404d0f6192916/RELEASES.md) +describe `rocm[libraries,devel,device-gfx942,device-gfx950]`, `rocm-sdk init`, +`rocm-sdk test`, and `rocm-sdk path` for discovery. Pin the release/index; +nightly package availability does not establish hardware qualification. +Do not mix a wheel SDK with unrelated `/opt/rocm` libraries through +`LD_LIBRARY_PATH`. + +#### RVS and the validation matrix + +[RVS and TransferBench are ROCm Extras](https://rocm.docs.amd.com/en/latest/components/extras.html), +not part of the Core SDK install. The current +[RVS installation guide](https://rocm.docs.amd.com/projects/ROCmValidationSuite/en/latest/install/installation.html) +uses the separate Extras repository, package `amdrocm10-rvs`, and +`/opt/rocm/extras-10`. RVS includes TransferBench; source builds make its +standalone CLI optional. + +ROCm Bandwidth Test is end-of-life, with RVS/TransferBench the recommended +replacements. SuperBench's current `mem-bw` is a **different legacy path**: +it builds `hipBusBandwidth` from the HIP 5.5 samples. Replace that dependency +with an explicit RVS-backed benchmark/parser rather than assuming the old +command and metric format work unchanged. + +| Coverage | Candidate RVS module / retained test | +| --- | --- | +| Inventory, configuration and PCIe qualification | GPUP, RCQT, PEQT; AMD SMI inventory and telemetry | +| Host/device and peer transfers | PEBB and PBQT, now using TransferBench; retain SuperBench SM/DMA copy correctness checks | +| HBM bandwidth and integrity | BABEL (BabelStream) and MEM; qualify duration, allocation size and fault reporting | +| Sustained compute, power and thermal behavior | GST, IET and TST with per-SKU limits and opt-in durations | +| Communication and application regressions | Retain RCCL correctness/scaling, RDMA tests, rocBLAS/hipBLASLt precision checks, and PyTorch/TE forward/backward/attention tests | + +See the [RVS module descriptions](https://rocm.docs.amd.com/projects/ROCmValidationSuite/en/latest/features.html) +and [TransferBench integration notes](https://rocm.docs.amd.com/projects/ROCmValidationSuite/en/latest/transferbench.html). +The documented TransferBench default offload targets do not include gfx1250 +or gfx1251; verify actual package contents or build with explicitly supported +targets before claiming new-GPU coverage. RVS is not a replacement for all +SuperBench application/network tests. Keep stress tests opt-in on shared nodes, +preserve units and GPU identifiers in new parsers, and establish new per-SKU +thresholds rather than reusing MI300X baselines. diff --git a/tests/test_rocm10_dockerfile.py b/tests/test_rocm10_dockerfile.py new file mode 100644 index 000000000..91c425999 --- /dev/null +++ b/tests/test_rocm10_dockerfile.py @@ -0,0 +1,452 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +"""Tests for the experimental ROCm 10 image scaffold.""" + +import os +import subprocess +import tempfile +import unittest +import venv +from pathlib import Path + + +class Rocm10DockerfileTestCase(unittest.TestCase): + """Check package selection and executable architecture routing without Docker.""" + + @classmethod + def setUpClass(cls): + """Load the Dockerfile and extract RCCL test architecture handling.""" + root = Path(__file__).resolve().parents[1] + cls.dockerfile = (root / 'dockerfile' / 'rocm10.1.x.dockerfile').read_text(encoding='utf-8') + env_start = cls.dockerfile.index("printf 'export ROCM_PATH=%q") + env_end = cls.dockerfile.index('\n\n', env_start) + cls.environment_script = cls.dockerfile[env_start:env_end] + registration_start = cls.dockerfile.index("RUN python3 -c 'import sysconfig;") + registration_end = cls.dockerfile.index('\n\n', registration_start) + cls.registration_script = cls.dockerfile[registration_start + len('RUN '):registration_end] + start = cls.dockerfile.index('rccl_architectures=$(printf') + end = cls.dockerfile.index(' if [ -n "${RCCL_SOURCE_COMMIT}" ]; then', start) + cls.routing = cls.dockerfile[start:end] + 'printf \'%s\\n\' "$rccl_architectures"\n' + override_start = cls.dockerfile.index("printf 'export RCCL_HOME=%q") + override_end = cls.dockerfile.index('; \\\n fi', override_start) + cls.rccl_override_script = cls.dockerfile[override_start:override_end].replace('\\\n', '\n') + + def run_routing(self, targets): + """Execute the real Dockerfile routing block with a supplied target list.""" + env = os.environ.copy() + env['AMDGPU_TARGETS'] = targets + return subprocess.run( + ['/bin/bash', '-e', '-o', 'pipefail', '-c', self.routing], + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + check=False, + ) + + def test_architecture_routing(self): + """Normalize single, multiple, and whitespace-separated architectures.""" + for targets, expected in ( + ('gfx942 gfx950 gfx1250', 'gfx942;gfx950;gfx1250'), + ('gfx942', 'gfx942'), + ('gfx90a gfx942 gfx950 gfx1250', 'gfx90a;gfx942;gfx950;gfx1250'), + (' gfx942\t gfx950\n', 'gfx942;gfx950'), + ): + with self.subTest(targets=targets): + result = self.run_routing(targets) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.strip(), expected) + + def test_empty_architectures_fail_explicitly(self): + """Do not fall back to the build host's detected GPU architecture.""" + for targets in ('', ' \t\n'): + with self.subTest(targets=targets): + result = self.run_routing(targets) + self.assertNotEqual(result.returncode, 0) + self.assertIn('AMDGPU_TARGETS must contain at least one GPU architecture.', result.stderr) + + def test_default_build_parallelism(self): + """Default native builds to 64 jobs while retaining the framework build cap.""" + self.assertIn('ARG NUM_MAKE_JOBS=64', self.dockerfile) + self.assertIn('CMAKE_BUILD_PARALLEL_LEVEL="${NUM_MAKE_JOBS}"', self.dockerfile) + self.assertIn('if [ "${framework_jobs}" -gt 16 ]; then framework_jobs=16; fi', self.dockerfile) + + def test_all_device_sdk_uses_base_package_ecosystem(self): + """Discover the installed wheel SDK without an alias or global loader override.""" + self.assertIn('rocm10.1.0_ubuntu26.04_py3.14_pytorch_release_2.13.0@sha256:', self.dockerfile) + self.assertIn('"rocm[devel,libraries,device-all]==${ROCM_VERSION}"', self.dockerfile) + self.assertIn('rocm-sdk init', self.dockerfile) + self.assertIn('ROCM_PATH="$(rocm-sdk path --root)"', self.dockerfile) + self.assertNotIn('/opt/rocm/wheel', self.dockerfile) + self.assertNotIn('ln -s "$(rocm-sdk path --root)"', self.dockerfile) + self.assertNotIn('/etc/ld.so.conf.d/rocm.conf', self.dockerfile) + self.assertIn('ENV BASH_ENV=/etc/profile.d/rocm10-env.sh', self.dockerfile) + self.assertIn('ENTRYPOINT ["/bin/bash", "-e", "-c", "exec \\"$@\\"", "--"]', self.dockerfile) + self.assertIn('CMD ["/bin/bash"]', self.dockerfile) + + def test_sdk_environment_uses_discovered_paths(self): + """Activate the SDK for shell builds and arbitrary container commands.""" + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + sdk_root = str(root / 'sdk with spaces') + bin_dir = root / 'usr' / 'local' / 'bin' + bin_dir.mkdir(parents=True) + sdk = bin_dir / 'rocm-sdk' + sdk.write_text('#!/bin/sh\n[ "$1" = path ] && [ "$2" = --root ] || exit 2\n' + 'printf "%s\\n" "$TEST_SDK_ROOT"\n') + sdk.chmod(0o755) + env = os.environ.copy() + # The 10.1 base runs the system interpreter, so the SDK CLI is not in a virtualenv. + for name in ('BASH_ENV', 'VIRTUAL_ENV'): + env.pop(name, None) + env.update({ + 'TEST_SDK_ROOT': sdk_root, + 'MPI_HOME': '/vendor/mpi', + 'SB_MICRO_PATH': '/superbench', + 'EXTRAS_PATH': '/vendor/extras', + 'ROCM_PATH': '/stale/sdk', + 'ROCM_HOME': '/stale/sdk', + 'HIP_PATH': '/stale/sdk', + 'RCCL_HOME': '/stale/sdk', + 'LD_LIBRARY_PATH': '/stale/sdk/lib', + 'PATH': f'{bin_dir}:/usr/bin:/bin', + }) + activation = root / 'rocm10-env.sh' + script = 'ROCM_PATH="$(rocm-sdk path --root)" && ' + self.environment_script.replace( + '/etc/profile.d/rocm10-env.sh', str(activation) + ) + subprocess.run(['/bin/bash', '-e', '-c', script], env=env, check=True) + sdk.unlink() + env.update({'BASH_ENV': str(activation), 'PATH': '/usr/bin:/bin'}) + result = subprocess.run( + ['/bin/bash', '-e', '-c', 'exec "$@"', '--', '/usr/bin/env'], + env=env, check=True, capture_output=True, text=True, + ) + actual = dict(line.split('=', 1) for line in result.stdout.splitlines() if '=' in line) + for name in ('ROCM_PATH', 'ROCM_HOME', 'HIP_PATH', 'RCCL_HOME'): + self.assertEqual(actual[name], sdk_root) + self.assertEqual( + actual['PATH'], f'/vendor/extras/bin:/vendor/mpi/bin:/superbench/bin:{sdk_root}/bin:/usr/bin:/bin' + ) + self.assertEqual( + actual['LD_LIBRARY_PATH'], + f'/vendor/extras/lib:/vendor/mpi/lib:{sdk_root}/lib:{sdk_root}/lib/llvm/lib:' + f'{sdk_root}/lib/host-math/lib:{sdk_root}/lib/rocm_sysdeps/lib', + ) + + def test_sdk_discovery_failure_stops_environment_generation(self): + """Never publish stale SDK paths if build-time discovery fails.""" + with tempfile.TemporaryDirectory() as directory: + bin_dir = Path(directory) / 'bin' + bin_dir.mkdir() + sdk = bin_dir / 'rocm-sdk' + sdk.write_text('#!/bin/sh\necho "SDK unavailable" >&2\nexit 7\n') + sdk.chmod(0o755) + env = os.environ.copy() + env.update({'PATH': f'{bin_dir}:/usr/bin:/bin'}) + env.pop('BASH_ENV', None) + activation = Path(directory) / 'rocm10-env.sh' + script = 'ROCM_PATH="$(rocm-sdk path --root)" && ' + self.environment_script.replace( + '/etc/profile.d/rocm10-env.sh', str(activation) + ) + result = subprocess.run( + ['/bin/bash', '-e', '-c', script], + env=env, check=False, capture_output=True, text=True, + ) + self.assertEqual(result.returncode, 7) + self.assertIn('SDK unavailable', result.stderr) + self.assertEqual(result.stdout, '') + self.assertFalse(activation.exists()) + + def test_rccl_source_build_includes_gfx1250_fixes(self): + """Build RCCL and its tests from one revision that contains the MI455X fixes.""" + self.assertIn('ARG AMDGPU_TARGETS="gfx942 gfx950 gfx1250"', self.dockerfile) + self.assertIn('test -r "${ROCM_PATH}/lib/librccl.so"', self.dockerfile) + self.assertIn('ARG ROCM_SYSTEMS_COMMIT=7da43026e4f2ef7600433c38c820732f7a205d22', self.dockerfile) + # Merge commit of ROCm/rocm-systems#12051; therock-10.1 branched before it. + self.assertIn('ARG RCCL_SOURCE_COMMIT=2a0c58ec63ea22487ea65458b68b92426119eb11', self.dockerfile) + self.assertIn('RCCL_SOURCE_PREFIX=/opt/rccl', self.dockerfile) + self.assertIn("rccl_projects='projects/rccl projects/rccl-tests'", self.dockerfile) + self.assertIn("rccl_projects='projects/rccl-tests'", self.dockerfile) + self.assertIn('cmake -S /tmp/rocm-systems/projects/rccl -B /tmp/rccl-build', self.dockerfile) + self.assertEqual(self.dockerfile.count('-DGPU_TARGETS="${rccl_architectures}"'), 2) + self.assertIn('-DCMAKE_PREFIX_PATH="${rccl_prefix};${ROCM_PATH};${MPI_HOME}"', self.dockerfile) + self.assertIn('-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON', self.dockerfile) + self.assertIn('grep -F "${rccl_prefix}/lib/librccl.so"', self.dockerfile) + self.assertLess( + self.dockerfile.index('cmake --install /tmp/rccl-build'), + self.dockerfile.index('cmake -S /tmp/rocm-systems/projects/rccl-tests'), + ) + self.assertNotIn('https://github.com/ROCm/rccl.git', self.dockerfile) + self.assertNotIn('https://github.com/ROCmSoftwarePlatform/rccl.git', self.dockerfile) + self.assertNotIn('LD_PRELOAD=', self.dockerfile) + + def test_source_built_rccl_precedes_the_sdk_library(self): + """Prepend the source-built RCCL once, even when the activation is sourced again.""" + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + activation = root / 'rocm10-env.sh' + prefix = str(root / 'rccl with spaces') + activation.write_text('export ROCM_PATH=/sdk RCCL_HOME=/sdk\nexport LD_LIBRARY_PATH="/sdk/lib"\n') + env = os.environ.copy() + env.pop('BASH_ENV', None) + env['rccl_prefix'] = prefix + script = self.rccl_override_script.replace('/etc/profile.d/rocm10-env.sh', str(activation)) + subprocess.run(['/bin/bash', '-e', '-c', script], env=env, check=True) + env.update({'BASH_ENV': str(activation), 'LD_LIBRARY_PATH': '/stale'}) + result = subprocess.run( + ['/bin/bash', '-e', '-c', '. "$BASH_ENV"; printf "%s\\n%s\\n" "$RCCL_HOME" "$LD_LIBRARY_PATH"'], + env=env, + check=True, + capture_output=True, + text=True, + ) + self.assertEqual(result.stdout.splitlines(), [prefix, f'{prefix}/lib:/sdk/lib']) + + def test_doca_uses_only_the_userspace_profile(self): + """Use the matching Ubuntu release without installing host kernel drivers.""" + self.assertIn('ARG DOCA_VERSION=3.4.0', self.dockerfile) + self.assertIn('ARG DOCA_PACKAGE_VERSION=3.4.0-085000', self.dockerfile) + self.assertIn('-26.04-ubuntu2604_amd64.deb', self.dockerfile) + self.assertIn('"doca-ofed-userspace=${DOCA_PACKAGE_VERSION}"', self.dockerfile) + self.assertIn('"${DOCA_BUNDLE_SHA256}" /tmp/doca-host.deb | sha256sum --check --strict', self.dockerfile) + self.assertIn('apt-get purge -y doca-host', self.dockerfile) + self.assertNotIn('apt-get install -y doca-ofed ', self.dockerfile) + self.assertNotIn('amdgpu-dkms', self.dockerfile) + + def test_mpi_reuses_the_doca_package(self): + """Install vendor MPI before removing its repository, without a source build.""" + self.assertIn('ARG DOCA_OPENMPI_VERSION=5.0.10rc2.2605121430-1.b99be7132e', self.dockerfile) + self.assertIn('"openmpi=${DOCA_OPENMPI_VERSION}"', self.dockerfile) + self.assertIn("dpkg-query -L openmpi | sed -n 's#/bin/mpirun$##p'", self.dockerfile) + self.assertIn('test -x "${mpi_prefix}/bin/mpicc"', self.dockerfile) + self.assertIn('ln -s "${mpi_prefix}" "${MPI_HOME}"', self.dockerfile) + self.assertLess( + self.dockerfile.index('"openmpi=${DOCA_OPENMPI_VERSION}"'), + self.dockerfile.index('apt-get purge -y doca-host'), + ) + self.assertNotIn('ARG OPENMPI_VERSION=', self.dockerfile) + self.assertNotIn('https://github.com/open-mpi/ompi.git', self.dockerfile) + self.assertNotIn('--disable-oshmem', self.dockerfile) + + def test_prebuilt_blas_clients_keep_their_kernel_packs(self): + """Keep helper kernels and SDK dependency paths without extracting another runtime.""" + self.assertIn('therock-dist-linux-multiarch-tests-${ROCM_VERSION}.tar.gz', self.dockerfile) + self.assertIn("'./bin/rocblas-bench' './bin/hipblaslt-bench' './.kpack/blas_test_*.kpack'", self.dockerfile) + for arch in ('gfx942', 'gfx950', 'gfx1250'): + self.assertIn(f'test -s "${{SB_HOME}}/.kpack/blas_test_{arch}.kpack"', self.dockerfile) + self.assertIn( + '${ROCM_PATH}/lib/host-math/lib:${ROCM_PATH}/lib/rocm_sysdeps/lib', + self.environment_script, + ) + + def test_transferbench_backend_is_inherited_by_ssh(self): + """Preserve existing YAML while making the image's backend choice explicit.""" + self.assertIn('SB_ROCM_MEM_BW_BACKEND=transferbench', self.dockerfile) + self.assertEqual(self.dockerfile.count('> /etc/environment'), 1) + self.assertIn('"SB_ROCM_MEM_BW_BACKEND=${SB_ROCM_MEM_BW_BACKEND}"', self.dockerfile) + + def test_installation_order_and_prerequisites(self): + """Follow the older images' layout while retaining ROCm 10 prerequisites.""" + steps = ( + 'RUN apt-get update', + 'ARG DOCKER_VERSION=', + 'RUN mkdir -p /root/.ssh', + 'ARG DOCA_VERSION=', + '"rocm[devel,libraries,device-all]==${ROCM_VERSION}"', + "RUN python3 -c 'import sysconfig;", + '"amdrocm10-rvs=${RVS_VERSION}"', + 'WORKDIR ${SB_HOME}', + 'COPY third_party third_party', + 'RUN rccl_architectures=$(printf', + 'git init /tmp/rocm-systems', + 'make -C third_party fio rocm_perftest', + 'ARG ROCM_TESTS_SHA256=', + 'COPY . .', + "pip install -c /tmp/rocm10-constraints.txt '.[torch]'", + 'python3 -m pip install pytest pytest-timeout vcrpy', + 'ARG TE_COMMIT=', + 'python3 -m pip wheel --no-build-isolation --no-deps', + 'RUN printf \'%s\\n\' \\\n "PATH=${PATH}"', + '> /etc/environment', + 'CXX="${ROCM_PATH}/bin/hipcc" make cppbuild', + 'make postinstall', + 'RUN python3 -m pip check', + 'sb --help', + 'rm -rf .git', + ) + positions = [self.dockerfile.index(step) for step in steps] + self.assertEqual(positions, sorted(positions)) + + def test_framework_prerequisites_for_system_python(self): + """Provide TE's AOTriton and legacy ROCm SMI needs on the base's system interpreter.""" + apt_start = self.dockerfile.index('RUN apt-get update') + apt = self.dockerfile[apt_start:self.dockerfile.index('\n\n', apt_start)] + for package in ('libdrm-dev', 'liblzma-dev', 'python3-venv'): + self.assertRegex(apt, r'\s{}\s'.format(package)) + self.assertIn('pkg-config --exists liblzma', apt) + self.assertIn('/usr/bin/python3 -m venv /tmp/sb-aotriton-venv-check', apt) + self.assertEqual(self.dockerfile.count('apt-get install'), 3) + + smi_start = self.dockerfile.index('RUN git init -q /tmp/rocm-smi-source') + smi = self.dockerfile[smi_start:self.dockerfile.index('\n\n', smi_start)] + self.assertIn('origin "${ROCM_SYSTEMS_COMMIT}"', smi) + self.assertIn('sparse-checkout set projects/rocm-smi-lib', smi) + self.assertIn('-DCMAKE_INSTALL_PREFIX=/usr/local', smi) + self.assertIn('ctypes.CDLL("/usr/local/lib/librocm_smi64.so").rsmi_init', smi) + self.assertIn('rm -rf /tmp/rocm-smi-source /tmp/rocm-smi-build', smi) + self.assertLess(smi_start, self.dockerfile.index('RUN framework_jobs=')) + self.assertNotIn('pip wheel --verbose', self.dockerfile) + + def test_framework_runtime_configuration_survives_build_layers(self): + """Keep the selected Megatron path and precise Triton FP32 mode at runtime.""" + self.assertIn('SB_MEGATRON_PATH=/opt/rocm10-frameworks/Megatron-LM', self.dockerfile) + self.assertIn('AITER_USE_SYSTEM_TRITON=1', self.dockerfile) + self.assertIn('TRITON_F32_DEFAULT=ieee', self.dockerfile) + for name in ( + 'ROCM_PATH', 'ROCM_HOME', 'HIP_PATH', 'RCCL_HOME', + 'SB_MEGATRON_PATH', 'AITER_USE_SYSTEM_TRITON', 'TRITON_F32_DEFAULT', 'MAX_JOBS', + 'CUDA_DEVICE_MAX_CONNECTIONS', 'NVTE_FLASH_ATTN', 'NVTE_FUSED_ATTN', + 'NVTE_FUSED_ATTN_CK', 'NVTE_FUSED_ATTN_AOTRITON' + ): + self.assertIn(f'"{name}=${{{name}}}"', self.dockerfile) + self.assertIn('CUDA_DEVICE_MAX_CONNECTIONS=1', self.dockerfile) + self.assertIn('NVTE_FUSED_ATTN_CK=1', self.dockerfile) + self.assertIn('NVTE_FUSED_ATTN_AOTRITON=0', self.dockerfile) + self.assertLess( + self.dockerfile.index("RUN python3 -c 'import sysconfig;"), + self.dockerfile.index('python3 -m pip wheel --no-build-isolation --no-deps'), + ) + + def test_framework_build_settings_do_not_reach_runtime(self): + """Export build-only settings in a different layer from the runtime environment file.""" + start = self.dockerfile.index('RUN framework_jobs=') + end = self.dockerfile.index('\n\n', start) + build = self.dockerfile[start:end] + self.assertIn('NVTE_FUSED_ATTN_AOTRITON=1', build) + self.assertIn('RCCL_HOME="${ROCM_PATH}"', build) + self.assertNotIn('/etc/environment', build) + self.assertEqual(self.dockerfile.count('NVTE_FUSED_ATTN_AOTRITON=1'), 1) + + def test_framework_sources_are_pinned_and_built_without_resolution(self): + """Build immutable framework revisions without replacing the SDK, PyTorch or Triton.""" + for name in ('TE_COMMIT', 'AITER_COMMIT', 'MEGATRON_COMMIT'): + self.assertRegex(self.dockerfile, r'(?m)^ARG {}=[0-9a-f]{{40}}$'.format(name)) + for url in ( + 'https://github.com/ROCm/TransformerEngine.git ${TE_COMMIT}', + 'https://github.com/ROCm/aiter.git ${AITER_COMMIT}', + 'https://github.com/NVIDIA/Megatron-LM.git ${MEGATRON_COMMIT}', + ): + self.assertIn(url, self.dockerfile) + self.assertIn('third_party/Megatron/megatron_core_0.19.2_rocm10.patch', self.dockerfile) + self.assertIn('NVTE_ROCM_ARCH="${te_architectures}"', self.dockerfile) + normalize = "$(printf '%s' \"${AMDGPU_TARGETS}\" | tr -s '[:space:]' ';' | sed 's/^;//; s/;$//')" + self.assertIn('rccl_architectures=' + normalize, self.dockerfile) + self.assertIn('te_architectures=' + normalize, self.dockerfile) + self.assertIn('PIP_CONSTRAINT=/tmp/rocm10-constraints.txt', self.dockerfile) + self.assertIn('python3 -m pip install --no-deps /tmp/rocm10-wheels/*.whl', self.dockerfile) + self.assertIn('diff -u /tmp/rocm10-constraints.txt -', self.dockerfile) + self.assertNotIn('pip install transformer_engine', self.dockerfile) + self.assertNotIn('git clone --recursive https://github.com/ROCm/TransformerEngine.git', self.dockerfile) + self.assertFalse((Path(__file__).resolve().parents[1] / 'dockerfile/etc/install-rocm10-frameworks.sh').exists()) + + def test_framework_base_version_check(self): + """Stop before building frameworks unless the base provides the tested packages.""" + start = self.dockerfile.index("python3 -c 'import sys; from importlib.metadata import version;") + check = self.dockerfile[start:self.dockerfile.index(' && \\\n', start)] + versions = { + 'torch': '2.13.0+rocm10.1.0', + 'triton': '3.8.0+git669b31ac.rocm10.1.0', + 'rocm-sdk-core': '10.1.0', + 'rocm-sdk-devel': '10.1.0', + } + for changed in (None, 'torch'): + with self.subTest(changed=changed), tempfile.TemporaryDirectory() as directory: + for name, version in versions.items(): + version = '0.0.0' if name == changed else version + info = Path(directory) / '{}-{}.dist-info'.format(name.replace('-', '_'), version) + info.mkdir() + (info / 'METADATA').write_text(f'Metadata-Version: 2.1\nName: {name}\nVersion: {version}\n') + env = dict(os.environ, PYTHONPATH=directory) + result = subprocess.run(['/bin/bash', '-c', check], env=env, capture_output=True, text=True) + if changed: + self.assertNotEqual(result.returncode, 0) + self.assertIn('torch==2.13.0+rocm10.1.0 (found 0.0.0)', result.stderr) + else: + self.assertEqual(result.returncode, 0, result.stderr) + + def test_mpi_prefix_and_scaffold_boundaries(self): + """Keep the MPI prefix while avoiding unqualified legacy dependencies.""" + self.assertIn('MPI_HOME=/usr/local/mpi', self.dockerfile) + self.assertNotIn('--with-rocm=', self.dockerfile) + self.assertIn('make -C third_party fio rocm_perftest', self.dockerfile) + self.assertNotIn('ROCM_VER=rocm-5.5.0', self.dockerfile) + self.assertNotIn('make -C third_party rocm ', self.dockerfile) + self.assertIn("pip install -c /tmp/rocm10-constraints.txt '.[torch]'", self.dockerfile) + self.assertIn('python3 -m pip check', self.dockerfile) + + def test_rvs_uses_signed_apt_repositories(self): + """Install RVS and matching dependencies with APT, not a tarball or forced extraction.""" + self.assertIn('ARG RVS_VERSION=1.6.122-708', self.dockerfile) + self.assertIn('ARG ROCM_APT_VERSION=10.1.0-3', self.dockerfile) + self.assertIn('https://stable.repo.amd.com/rocm/extras/rvs/packages/ubuntu2604/', self.dockerfile) + self.assertIn('https://stable.repo.amd.com/rocm/core/packages/ubuntu2604/', self.dockerfile) + self.assertIn('Signed-By: /etc/apt/keyrings/amdrocm.gpg', self.dockerfile) + self.assertIn('"amdrocm10-rvs=${RVS_VERSION}"', self.dockerfile) + for component in ('runtime', 'base', 'amdsmi', 'blas', 'rand', 'llvm'): + self.assertIn(f'"amdrocm-{component}=${{ROCM_APT_VERSION}}"', self.dockerfile) + self.assertIn('EXTRAS_PATH=/opt/rocm/extras-10', self.dockerfile) + self.assertIn('test -x "${EXTRAS_PATH}/bin/TransferBench"', self.dockerfile) + self.assertIn('LD_LIBRARY_PATH="${EXTRAS_PATH}/lib:', self.environment_script) + self.assertNotIn('/rvs/tarball/', self.dockerfile) + self.assertNotIn('RVS_SHA256', self.dockerfile) + self.assertNotIn('/tmp/rvs.tar.gz', self.dockerfile) + + def test_perftest_uses_the_configured_sdk(self): + """Honor the wheel SDK prefix while preserving other images' /opt/rocm default.""" + root = Path(__file__).resolve().parents[1] + makefile = (root / 'third_party' / 'Makefile').read_text(encoding='utf-8') + self.assertIn('--enable-rocm --with-rocm="$(ROCM_PATH)"', makefile) + self.assertIn('ROCM_PATH ?= /opt/rocm', makefile) + + def test_amdsmi_uses_the_core_bindings_in_place(self): + """Preserve the SDK's binding/library layout without copying or patching either.""" + self.assertIn('https://github.com/ROCm/TheRock/issues/3054', self.dockerfile) + self.assertIn('https://github.com/ROCm/TheRock/pull/8424', self.dockerfile) + self.assertIn('Path(sysconfig.get_path("purelib"), "amdsmi.pth")', self.registration_script) + self.assertIn('.write_text("_rocm_sdk_core/share/amd_smi\\n")', self.registration_script) + self.assertNotIn('--editable', self.dockerfile) + self.assertNotIn("'.[amdworker]'", self.dockerfile) + self.assertNotIn('version("amdsmi")', self.dockerfile) + self.assertNotIn('pip install "${ROCM_PATH}/share/amd_smi"', self.dockerfile) + self.assertNotIn('smi_library=', self.dockerfile) + self.assertNotIn('ln -sf', self.dockerfile) + + def test_amdsmi_registration_makes_bundled_module_importable(self): + """Execute the real build step in an isolated interpreter with an SDK payload.""" + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + venv.EnvBuilder(with_pip=False).create(root) + python = root / 'bin' / 'python3' + env = os.environ.copy() + for name in ('PYTHONPATH', 'PYTHONHOME', 'BASH_ENV'): + env.pop(name, None) + env['PATH'] = f'{python.parent}:/usr/bin:/bin' + purelib = Path(subprocess.check_output( + [str(python), '-c', 'import sysconfig; print(sysconfig.get_path("purelib"))'], + env=env, text=True, + ).strip()) + module = purelib / '_rocm_sdk_core' / 'share' / 'amd_smi' / 'amdsmi' + module.mkdir(parents=True) + (module / '__init__.py').write_text('VERSION = "sdk-bundled"\n') + subprocess.run(['/bin/bash', '-e', '-c', self.registration_script], env=env, check=True) + self.assertEqual((purelib / 'amdsmi.pth').read_text(), '_rocm_sdk_core/share/amd_smi\n') + imported = subprocess.check_output( + [str(python), '-c', 'import amdsmi; print(amdsmi.__file__)'], env=env, text=True, + ).strip() + self.assertEqual(Path(imported), module / '__init__.py') + + +if __name__ == '__main__': + unittest.main() diff --git a/third_party/Makefile b/third_party/Makefile index 5dd73372c..d88feba8e 100755 --- a/third_party/Makefile +++ b/third_party/Makefile @@ -136,7 +136,7 @@ ifneq (,$(wildcard perftest/autogen.sh)) endif rocm_perftest: ifneq (,$(wildcard perftest/autogen.sh)) - cd perftest && ./autogen.sh && ./configure --enable-rocm --with-rocm=/opt/rocm --prefix=$(SB_MICRO_PATH) && make -j && make install + cd perftest && ./autogen.sh && ./configure --enable-rocm --with-rocm="$(ROCM_PATH)" --prefix=$(SB_MICRO_PATH) && make -j && make install endif cpu_perftest: ifneq (,$(wildcard perftest/autogen.sh)) diff --git a/third_party/Megatron/megatron_core_0.19.2_rocm10.patch b/third_party/Megatron/megatron_core_0.19.2_rocm10.patch new file mode 100644 index 000000000..10239576f --- /dev/null +++ b/third_party/Megatron/megatron_core_0.19.2_rocm10.patch @@ -0,0 +1,58 @@ +diff --git a/megatron/training/argument_utils.py b/megatron/training/argument_utils.py +index 70f26c6..6b35b88 100644 +--- a/megatron/training/argument_utils.py ++++ b/megatron/training/argument_utils.py +@@ -166,7 +166,7 @@ class ArgumentGroupFactory: + argparse_kwargs = {} + argparse_kwargs["arg_names"] = [self._format_arg_name(attribute.name)] + argparse_kwargs["dest"] = attribute.name +- argparse_kwargs["help"] = self.field_docstrings[attribute.name] if attribute.name in self.field_docstrings else "" ++ argparse_kwargs["help"] = self.field_docstrings.get(attribute.name, "").replace("%", "%%") + + # dataclasses specifies that both should not be set + if isinstance(attribute.default, type(dataclasses.MISSING)): +diff --git a/megatron/training/arguments.py b/megatron/training/arguments.py +index fd30984..a32caf8 100644 +--- a/megatron/training/arguments.py ++++ b/megatron/training/arguments.py +@@ -2625,7 +2625,7 @@ def _add_rl_args(parser): + 'persist: leave KV cache in GPU memory (default), ' + 'offload: offload KV cache to CPU during training, ' + 'recompute: deallocate KV cache and recompute from scratch each cycle') +- group.add_argument('--rl-persist-cuda-graphs', action=argparse.BooleanOptionalAction, type=bool, default=False, ++ group.add_argument('--rl-persist-cuda-graphs', action=argparse.BooleanOptionalAction, default=False, + help='Persist CUDA graphs when the inference engine is suspended. ' + 'If False, CUDA graphs are deleted on suspend and re-captured on resume.') + group.add_argument('--rl-partial-rollouts', action=argparse.BooleanOptionalAction, default=False, +@@ -2633,11 +2633,11 @@ def _add_rl_args(parser): + 'the policy weights. This enables off-policy training where rollouts may ' + 'be generated with a stale version of the policy. Use ' + '--rl-generation-lag to control the degree of staleness.') +- group.add_argument('--rl-inference-logprobs-is-correction', action=argparse.BooleanOptionalAction, type=bool, default=False, ++ group.add_argument('--rl-inference-logprobs-is-correction', action=argparse.BooleanOptionalAction, default=False, + help='If set, use inference logprobs in importance sampling correction of the loss.') + group.add_argument('--rl-importance-sampling-truncation-coef', type=float, default=None, + help="If --inference-logprobs-is-correction is on and this coefficient is set, apply truncation for the IS correction at GRPO loss.") +- group.add_argument('--rl-use-sequence-packing', action=argparse.BooleanOptionalAction, type=bool, default=False, ++ group.add_argument('--rl-use-sequence-packing', action=argparse.BooleanOptionalAction, default=False, + help='Enable sequence packing') + group.add_argument('--rl-sequence-packing-max-sequences-per-bin', type=int, default=50, + help='Maximum number of sequences that can be packed into a single bin. ') +@@ -2646,7 +2646,7 @@ def _add_rl_args(parser): + help='Algorithm for distributing packed bins across ranks. ' + 'fifo: first-in-first-out sequential distribution, ' + 'round-robin: distribute bins cyclically across ranks for better load balancing') +- group.add_argument('--rl-training-cuda-graphs', action=argparse.BooleanOptionalAction, type=bool, ++ group.add_argument('--rl-training-cuda-graphs', action=argparse.BooleanOptionalAction, + default=False, + help='If set, do not toggle CUDA graphs on/off between inference and training phases.') + group.add_argument('--rl-inference-tensor-model-parallel-size', type=int, default=None, +@@ -2705,7 +2705,7 @@ def _add_rl_args(parser): + help='If set, verify that the model weights were correctly transferred by comparing forward pass outputs on' + 'the first swap of model weights.') + +- group.add_argument('--rl-skip-bos-token', action=argparse.BooleanOptionalAction, type=bool, default=False, ++ group.add_argument('--rl-skip-bos-token', action=argparse.BooleanOptionalAction, default=False, + help='Skip BOS token at the beginning of the sequences. Default is False.') + group.add_argument('--rl-profile', action='store_true', default=False, + help='Enable RL profiling to collect detailed timer data (JSONL + CSV).')