Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
78 changes: 63 additions & 15 deletions .buildkite/scripts/ci-bake-rocm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,26 @@ prepare_ci_build_context() {
echo "Using canonical CI Docker context: ${ROCM_BUILD_CONTEXT_ROOT}"
}

configure_custom_rocm_stages() {
using_custom_rocm_dockerfiles || return 0
local context_root="${ROCM_BUILD_CONTEXT_ROOT:-.}"
local dockerfile="${context_root}/${CI_BASE_DOCKERFILE}"
local stages=""

(cd "${context_root}" && \
validate_rocm_dockerfile "${CI_BASE_DOCKERFILE}" \
ci_base test export_vllm export_test_smoke csrc-build rust-build) \
|| return $?
# Hash all stages for custom layouts, including additional helper stages.
stages=$(rocm_dockerfile_stages "${dockerfile}" | paste -sd ' ')
CI_BASE_DOCKERFILE_STAGES="${CI_BASE_DOCKERFILE_STAGES:-${stages}}"
ROCM_CSRC_DOCKERFILE_STAGES="${ROCM_CSRC_DOCKERFILE_STAGES:-${stages}}"
ROCM_RUST_DOCKERFILE_STAGES="${ROCM_RUST_DOCKERFILE_STAGES:-${stages}}"
if [[ " ${stages} " != *" build_rocshmem "* ]]; then
unset ROCSHMEM_BRANCH ROCSHMEM_CACHE_KEY DEEPEP_CACHE_KEY
fi
}

compose_dependency_cache_key() {
local prefix="$1"
local material="$2"
Expand Down Expand Up @@ -569,11 +589,11 @@ hash_dockerfile_stages() {
}
emit = 0
}
$1 == "FROM" {
toupper($1) == "FROM" {
stage = ""
for (idx = 1; idx <= NF; idx++) {
if (tolower($idx) == "as" && idx < NF) {
stage = $(idx + 1)
stage = tolower($(idx + 1))
}
}
emit = (stage in wanted)
Expand Down Expand Up @@ -613,11 +633,11 @@ discover_dockerfile_stage_args() {
}
{
line = $0
if ($1 == "FROM") {
if (toupper($1) == "FROM") {
stage = ""
for (idx = 1; idx <= NF; idx++) {
if (tolower($idx) == "as" && idx < NF) {
stage = $(idx + 1)
stage = tolower($(idx + 1))
}
}
emit = (stage in wanted)
Expand All @@ -630,7 +650,7 @@ discover_dockerfile_stage_args() {
for (idx = 1; idx <= line_count; idx++) {
line = lines[idx]
arg_name = line
sub(/^[[:space:]]*ARG[[:space:]]+/, "", arg_name)
sub(/^[[:space:]]*[Aa][Rr][Gg][[:space:]]+/, "", arg_name)
if (arg_name != line) {
sub(/[=[:space:]].*/, "", arg_name)
if (arg_name ~ /^[A-Za-z_][A-Za-z0-9_]*$/) {
Expand Down Expand Up @@ -716,7 +736,7 @@ extract_dockerfile_arg_default() {
if [[ -n "${ROCM_BUILD_CONTEXT_ROOT:-}" && "${dockerfile}" != /* ]]; then
physical_dockerfile="${ROCM_BUILD_CONTEXT_ROOT}/${dockerfile}"
fi
sed -n -E "s/^[[:space:]]*ARG[[:space:]]+${arg_name}=\"?([^\"[:space:]]+)\"?.*/\\1/p" \
sed -n -E "s/^[[:space:]]*[Aa][Rr][Gg][[:space:]]+${arg_name}=\"?([^\"[:space:]]+)\"?.*/\\1/p" \
"${physical_dockerfile}" | head -1
}

Expand Down Expand Up @@ -1000,7 +1020,21 @@ create_and_bootstrap_builder() {
}

init_config() {
# shellcheck source=.buildkite/scripts/rocm/build-config.sh
source "$(dirname "${BASH_SOURCE[0]}")/rocm/build-config.sh"
configure_rocm_build

TARGET="${1:-test-ci}"
if using_custom_rocm_dockerfiles; then
if [[ -z "${BASE_IMAGE:-}" ]]; then
echo "Custom ROCm builds require BASE_IMAGE from the selected base handoff" >&2
return 1
fi
if ! is_ci_base_target && [[ -z "${CI_BASE_IMAGE:-}" ]]; then
echo "Custom ROCm builds require CI_BASE_IMAGE from the selected ci_base handoff" >&2
return 1
fi
fi
BAKE_TARGETS=("${TARGET}")
DEPENDENCY_CACHE_TARGETS=()
CI_HCL_SOURCE="${CI_HCL_SOURCE:-${CI_HCL_FILE:-${DEFAULT_CI_HCL_SOURCE}}}"
Expand All @@ -1010,10 +1044,12 @@ init_config() {
PYTORCH_ROCM_ARCH="${PYTORCH_ROCM_ARCH:-gfx90a;gfx942;gfx950}"
CI_BASE_CONTENT_FILES="${CI_BASE_CONTENT_FILES:-${DEFAULT_CI_BASE_CONTENT_FILES}}"
CI_BASE_DOCKERFILE="${CI_BASE_DOCKERFILE:-${DEFAULT_CI_BASE_DOCKERFILE}}"
CI_BASE_DOCKERFILE_STAGES="${CI_BASE_DOCKERFILE_STAGES:-${DEFAULT_CI_BASE_DOCKERFILE_STAGES}}"
if ! using_custom_rocm_dockerfiles; then
CI_BASE_DOCKERFILE_STAGES="${CI_BASE_DOCKERFILE_STAGES:-${DEFAULT_CI_BASE_DOCKERFILE_STAGES}}"
fi
CI_BASE_METADATA_VERSION="${CI_BASE_METADATA_VERSION:-${DEFAULT_CI_BASE_METADATA_VERSION}}"
CI_BASE_IMAGE_TAG="${CI_BASE_IMAGE_TAG:-rocm/vllm-dev:ci_base}"
export PYTORCH_ROCM_ARCH
export PYTORCH_ROCM_ARCH CI_BASE_DOCKERFILE

SCRIPT_TMP_DIR=$(mktemp -d -t ci-bake-rocm.XXXXXX)
CI_HCL_PATH="${SCRIPT_TMP_DIR}/ci.hcl"
Expand Down Expand Up @@ -1042,6 +1078,11 @@ print_header() {
}

validate_inputs() {
if using_custom_rocm_dockerfiles; then
validate_rocm_dockerfile "${ROCM_BASE_DOCKERFILE}" || return $?
validate_rocm_dockerfile "${CI_BASE_DOCKERFILE}" \
ci_base test export_vllm export_test_smoke csrc-build rust-build || return $?
fi
if [[ ! -f "${VLLM_BAKE_FILE}" ]]; then
echo "Error: vLLM bake file not found at ${VLLM_BAKE_FILE}"
echo "Make sure you're running from the vLLM repository root"
Expand Down Expand Up @@ -1069,6 +1110,11 @@ load_ci_hcl() {

init_bake_files() {
BAKE_FILES=(-f "${VLLM_BAKE_FILE}" -f "${CI_HCL_PATH}")
if using_custom_rocm_dockerfiles; then
# Custom stacks reuse local cache without replacing the
# standard ROCm registry caches for the same commit or branch.
BAKE_FILES+=(--set '*.cache-to=')
fi
}

compute_ci_base_hash_if_needed() {
Expand Down Expand Up @@ -1804,7 +1850,7 @@ compute_rocm_csrc_content_hash() {
local -a content_args=()

bake_dir=$(dirname "${VLLM_BAKE_FILE}")
dockerfile_rocm="${bake_dir}/Dockerfile.rocm"
dockerfile_rocm="${CI_BASE_DOCKERFILE:-${bake_dir}/Dockerfile.rocm}"
read -r -a content_paths <<< "${content_files}"
mapfile -t content_args < <(
get_content_arg_names "${dockerfile_rocm}" "${stages}" "${ROCM_CSRC_CONTENT_ARGS:-}"
Expand Down Expand Up @@ -1853,7 +1899,7 @@ compute_rocm_rust_content_hash() {
local -a content_args=()

bake_dir=$(dirname "${VLLM_BAKE_FILE}")
dockerfile_rocm="${bake_dir}/Dockerfile.rocm"
dockerfile_rocm="${CI_BASE_DOCKERFILE:-${bake_dir}/Dockerfile.rocm}"
read -r -a content_paths <<< "${content_files}"
mapfile -t content_args < <(
get_content_arg_names \
Expand Down Expand Up @@ -1943,7 +1989,7 @@ write_rocm_build_arg_override() {
local arg_value=""

bake_dir=$(dirname "${VLLM_BAKE_FILE}")
dockerfile_rocm="${bake_dir}/Dockerfile.rocm"
dockerfile_rocm="${CI_BASE_DOCKERFILE:-${bake_dir}/Dockerfile.rocm}"
mapfile -t arg_names < <(
{
get_content_arg_names \
Expand Down Expand Up @@ -2259,7 +2305,7 @@ extract_dependency_pins() {
local val=""

bake_dir=$(dirname "${VLLM_BAKE_FILE}")
dockerfile_rocm="${bake_dir}/Dockerfile.rocm"
dockerfile_rocm="${CI_BASE_DOCKERFILE:-${bake_dir}/Dockerfile.rocm}"
physical_dockerfile="${dockerfile_rocm}"
if [[ -n "${ROCM_BUILD_CONTEXT_ROOT:-}" && "${dockerfile_rocm}" != /* ]]; then
physical_dockerfile="${ROCM_BUILD_CONTEXT_ROOT}/${dockerfile_rocm}"
Expand All @@ -2275,12 +2321,12 @@ extract_dependency_pins() {
fi

val=$(
sed -n -E "s/^[[:space:]]*ARG[[:space:]]+${var}=\"?([^\"[:space:]]+)\"?.*/\\1/p" \
sed -n -E "s/^[[:space:]]*[Aa][Rr][Gg][[:space:]]+${var}=\"?([^\"[:space:]]+)\"?.*/\\1/p" \
"${physical_dockerfile}" | head -1
)
if [[ -n "${val}" ]]; then
export "${var}=${val}"
echo "Extracted ${var}=${val} from Dockerfile.rocm"
echo "Extracted ${var}=${val} from ${dockerfile_rocm}"
fi
done
}
Expand All @@ -2297,7 +2343,7 @@ compute_dependency_cache_keys() {
local deepep_material=""

bake_dir=$(dirname "${VLLM_BAKE_FILE}")
dockerfile_rocm="${bake_dir}/Dockerfile.rocm"
dockerfile_rocm="${CI_BASE_DOCKERFILE:-${bake_dir}/Dockerfile.rocm}"
nixl_branch=$(resolve_dockerfile_arg_value "${dockerfile_rocm}" "NIXL_BRANCH")
ucx_branch=$(resolve_dockerfile_arg_value "${dockerfile_rocm}" "UCX_BRANCH")
rocshmem_branch=$(resolve_dockerfile_arg_value "${dockerfile_rocm}" "ROCSHMEM_BRANCH")
Expand Down Expand Up @@ -2687,6 +2733,7 @@ main() {
init_bake_files
if is_ci_base_target; then
prepare_ci_build_context
configure_custom_rocm_stages
fi
compute_ci_base_hash_if_needed
configure_ci_base_image_refs
Expand All @@ -2697,6 +2744,7 @@ main() {
# version metadata only after that lookup sees the available tag history.
if ! is_ci_base_target; then
prepare_ci_build_context
configure_custom_rocm_stages
fi
extract_dependency_pins
write_rocm_build_arg_override
Expand Down
11 changes: 11 additions & 0 deletions .buildkite/scripts/hardware_ci/run-amd-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
###############################################################################
set -o pipefail

# shellcheck source=.buildkite/scripts/rocm/build-config.sh
source "$(dirname "${BASH_SOURCE[0]}")/../rocm/build-config.sh" || exit $?

: "${BUILDKIT_PROGRESS:=plain}"
: "${TERM:=xterm-256color}"
: "${FORCE_COLOR:=1}"
Expand Down Expand Up @@ -106,6 +109,11 @@ clear_ci_orchestration_env() {
VLLM_CI_REQUIRE_WORKSPACE_MOUNT \
VLLM_TEST_COMMANDS \
VLLM_CI_BRANCH \
VLLM_USE_ROCK \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need VLLM_USE_ROCK, or can we make the behavior that we just set CI_ROCM_DOCKERFILE_BASE and CI_ROCM_DOCKERFILE to the ROCk dockerfiles to override Dockerfile.rocm and Dockerfile.rocm_base?

Basically, I am wondering if we can boil this PR down to just two additional env vars (CI_ROCM_DOCKERFILE_BASE and CI_ROCM_DOCKERFILE) to override the Dockerfiles. This would be nice in case we want to support multiple dockerfiles/ROCm versions in the future (e.g. then we could also use this PR directly when we want to start testing Dockerfile.rocm_base_gfx1250 and Dockerfile.rocm_gfx1250 in CI).

CI_ROCM_DOCKERFILE_BASE \
CI_ROCM_DOCKERFILE \
ROCM_BASE_DOCKERFILE \
CI_BASE_DOCKERFILE \
VLLM_CI_BASE_IMAGE \
VLLM_CI_FALLBACK_IMAGE \
VLLM_CI_DOCKER_DISABLED \
Expand Down Expand Up @@ -225,6 +233,9 @@ prepare_artifact_image() {
metadata_file=$(find "${artifact_work_dir}" -name "ci-base-image.txt" -type f | head -1)
if [[ -n "${metadata_file}" && -s "${metadata_file}" ]]; then
base_image=$(tr -d '[:space:]' < "${metadata_file}")
elif using_custom_rocm_dockerfiles; then
echo "Custom ROCm ci_base metadata is missing; using the full CI image"
return 1
fi

echo "--- Preparing local ROCm test image"
Expand Down
98 changes: 98 additions & 0 deletions .buildkite/scripts/rocm/build-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
# Shared Dockerfile selection for the normal AMD CI build chain.
# CI_ROCM_DOCKERFILE_BASE and CI_ROCM_DOCKERFILE accept repository-relative paths.
# VLLM_USE_ROCK=1 remains a shorthand; explicit Dockerfile settings take priority.
# Custom recipes must preserve the CI targets and artifact layout. Additional
# COPY inputs also need the corresponding *_CONTENT_FILES overrides.

rocm_base_dockerfile() {
local default="docker/Dockerfile.rocm_base"
if [[ "${VLLM_USE_ROCK:-0}" == "1" ]]; then
default="docker/Dockerfile.rock_base"
fi
printf '%s\n' "${CI_ROCM_DOCKERFILE_BASE:-${ROCM_BASE_DOCKERFILE:-${default}}}"
}

rocm_ci_dockerfile() {
local default="docker/Dockerfile.rocm"
if [[ "${VLLM_USE_ROCK:-0}" == "1" ]]; then
default="docker/Dockerfile.rock"
fi
printf '%s\n' "${CI_ROCM_DOCKERFILE:-${CI_BASE_DOCKERFILE:-${default}}}"
}

using_custom_rocm_dockerfiles() {
[[ "$(rocm_base_dockerfile)" != "docker/Dockerfile.rocm_base" \
|| "$(rocm_ci_dockerfile)" != "docker/Dockerfile.rocm" ]]
}

rocm_dockerfile_stages() {
awk '
toupper($1) == "FROM" {
for (idx = 2; idx < NF; idx++) {
if (tolower($idx) == "as") print tolower($(idx + 1))
}
}
' "$1"
}

validate_rocm_dockerfile() {
local dockerfile="$1"
local stage=""
local stages=""
shift

case "${dockerfile}" in
/*|../*|*/../*|*/..|*[[:space:]]*)
echo "ROCm Dockerfile must be a repository-relative path without '..' or whitespace: ${dockerfile}" >&2
return 2
;;
esac
if [[ ! -f "${dockerfile}" ]]; then
echo "ROCm Dockerfile not found: ${dockerfile}" >&2
return 2
fi
if (($#)) && ! awk '
toupper($1) == "FROM" {
named = 0
for (idx = 2; idx < NF; idx++) {
if (tolower($idx) == "as") named = 1
}
if (!named) exit 1
}
' "${dockerfile}"; then
echo "ROCm Dockerfile must name every build stage: ${dockerfile}" >&2
return 2
fi
stages=$(rocm_dockerfile_stages "${dockerfile}")
for stage in "$@"; do
if ! grep -Fxq -- "${stage}" <<< "${stages}"; then
echo "ROCm Dockerfile ${dockerfile} is missing required stage: ${stage}" >&2
return 2
fi
done
}

configure_rocm_build() {
case "${VLLM_USE_ROCK:-0}" in
0|1) ;;
*)
echo "VLLM_USE_ROCK must be 0 or 1" >&2
return 2
;;
esac

ROCM_BASE_DOCKERFILE=$(rocm_base_dockerfile)
CI_BASE_DOCKERFILE=$(rocm_ci_dockerfile)
export ROCM_BASE_DOCKERFILE CI_BASE_DOCKERFILE
using_custom_rocm_dockerfiles || return 0

# Custom stacks may supply dependencies without separate build stages.
export ROCM_DEP_CACHE_EXPORT_MODE=never

# Preserve the standard runtime tags, which are unique to each build,
# while preventing experimental builds from promoting stable images.
export ROCM_BASE_PUSH_STABLE_TAG=0
export CI_BASE_PUSH_STABLE_TAG=0
echo "Custom ROCm Dockerfiles: ${ROCM_BASE_DOCKERFILE} and ${CI_BASE_DOCKERFILE}"
}
Loading
Loading