|
| 1 | +#!/usr/bin/env bash |
| 2 | +############################################################################### |
| 3 | +# Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | +# |
| 5 | +# See LICENSE for license information. |
| 6 | +############################################################################### |
| 7 | +# |
| 8 | +# Magpie Generic SGLang Benchmark Script for Radeon 8060S / gfx1151 |
| 9 | +# |
| 10 | +# Phases (via MAGPIE_RUN_PHASE): all | server | client (default all). |
| 11 | +# |
| 12 | +# Remote server (BENCHMARK_BASE_URL): when set, the client phase points |
| 13 | +# benchmark_serving at an external SGLang-compatible HTTP endpoint |
| 14 | +# instead of localhost:$PORT, and forces PHASE=client (no local server |
| 15 | +# launch). See sglang_mi300x.sh for the full contract. |
| 16 | + |
| 17 | +source "$(dirname "$0")/benchmark_lib.sh" |
| 18 | +source "$(dirname "$0")/server_cleanup.sh" |
| 19 | +# shellcheck source=magpie_bench_remote_compat.sh |
| 20 | +source "$(dirname "$0")/magpie_bench_remote_compat.sh" |
| 21 | + |
| 22 | +PHASE="${MAGPIE_RUN_PHASE:-all}" |
| 23 | +case "$PHASE" in |
| 24 | + all|server|client) ;; |
| 25 | + *) echo "ERROR: Invalid MAGPIE_RUN_PHASE='$PHASE'. Must be all|server|client." >&2; exit 2 ;; |
| 26 | +esac |
| 27 | + |
| 28 | +if [[ -n "${BENCHMARK_BASE_URL:-}" ]]; then |
| 29 | + if [[ "$PHASE" != "client" ]]; then |
| 30 | + echo "[sglang_radeon8060s] BENCHMARK_BASE_URL set; forcing PHASE=client (was $PHASE)" |
| 31 | + PHASE=client |
| 32 | + fi |
| 33 | +fi |
| 34 | + |
| 35 | +if [[ "$PHASE" == "server" || "$PHASE" == "all" ]]; then |
| 36 | + check_env_vars MODEL TP |
| 37 | +fi |
| 38 | +if [[ "$PHASE" == "client" || "$PHASE" == "all" ]]; then |
| 39 | + check_env_vars MODEL CONC ISL OSL RANDOM_RANGE_RATIO RESULT_FILENAME |
| 40 | +fi |
| 41 | + |
| 42 | +for numeric in TP CONC ISL OSL PORT; do |
| 43 | + value=${!numeric:-} |
| 44 | + if [[ -n "$value" && ! "$value" =~ ^[0-9]+$ ]]; then |
| 45 | + echo "ERROR: $numeric must be an unsigned integer, got '$value'." >&2 |
| 46 | + exit 2 |
| 47 | + fi |
| 48 | +done |
| 49 | + |
| 50 | +if [[ -n "$SLURM_JOB_ID" ]]; then |
| 51 | + echo "JOB $SLURM_JOB_ID running on $SLURMD_NODENAME" |
| 52 | +fi |
| 53 | + |
| 54 | +if [[ "$PHASE" != "client" ]]; then |
| 55 | + hf download "$MODEL" 2>/dev/null || true |
| 56 | +fi |
| 57 | + |
| 58 | +# PYTORCH_ROCM_ARCH is build metadata, not a runtime GPU selector. Published |
| 59 | +# ROCm images may list multiple targets; preserve a list containing gfx1151. |
| 60 | +if [[ -n "${PYTORCH_ROCM_ARCH:-}" && ";$PYTORCH_ROCM_ARCH;" != *";gfx1151;"* ]]; then |
| 61 | + echo "ERROR: sglang_radeon8060s requires PYTORCH_ROCM_ARCH=gfx1151 or a semicolon-separated list containing gfx1151." >&2 |
| 62 | + exit 2 |
| 63 | +fi |
| 64 | +# Retain the default build hint when absent; this does not change kernel dispatch. |
| 65 | +if [[ -z "${PYTORCH_ROCM_ARCH:-}" ]]; then |
| 66 | + export PYTORCH_ROCM_ARCH=gfx1151 |
| 67 | +fi |
| 68 | +export HSA_ENABLE_SDMA=${HSA_ENABLE_SDMA:-0} |
| 69 | +unset HSA_OVERRIDE_GFX_VERSION |
| 70 | + |
| 71 | +# The qualified gfx1151 route uses Triton attention. Current AITER CK prefill |
| 72 | +# does not compile for this geometry and AITER paged decode device-asserts. |
| 73 | +export SGLANG_USE_AITER=0 |
| 74 | +unset SGLANG_AITER_MLA_PERSIST |
| 75 | +export HYPERLOOM_GFX1151_LOWBIT_BRIDGE=0 |
| 76 | + |
| 77 | +WORKSPACE_DIR=${RESULT_DIR:-/workspace} |
| 78 | +SERVER_LOG=${SERVER_LOG:-$WORKSPACE_DIR/server.log} |
| 79 | +PORT=${PORT:-8888} |
| 80 | + |
| 81 | +if [[ "${PROFILE:-}" == "1" ]]; then |
| 82 | + TRACE_DIR="${SGLANG_TORCH_PROFILER_DIR:-$WORKSPACE_DIR/torch_trace}" |
| 83 | + mkdir -p "$TRACE_DIR" |
| 84 | + export SGLANG_TORCH_PROFILER_DIR="$TRACE_DIR" |
| 85 | +fi |
| 86 | + |
| 87 | +# Pin the physically qualified route. Reject rather than silently override it. |
| 88 | +DEFAULT_ARGS=("--mem-fraction-static=0.5" "--disable-radix-cache" "--attention-backend=triton" "--disable-cuda-graph") |
| 89 | +read -r -a EXTRA_SGLANG_ARGV <<< "${EXTRA_SGLANG_ARGS:-}" |
| 90 | +for arg in "${EXTRA_SGLANG_ARGV[@]}"; do |
| 91 | + case "$arg" in |
| 92 | + --attention-backend|--attention-backend=*|--prefill-attention-backend|--prefill-attention-backend=*|--decode-attention-backend|--decode-attention-backend=*|--disable-cuda-graph|--enable-cuda-graph*) |
| 93 | + echo "ERROR: sglang_radeon8060s pins Triton attention with CUDA graphs disabled; conflicting arg '$arg'." >&2 |
| 94 | + exit 2 |
| 95 | + ;; |
| 96 | + esac |
| 97 | +done |
| 98 | + |
| 99 | +set -x |
| 100 | +if [[ "$PHASE" == "server" || "$PHASE" == "all" ]]; then |
| 101 | + SERVER_CMD=( |
| 102 | + python3 -m sglang.launch_server |
| 103 | + --model-path "$MODEL" |
| 104 | + --host 0.0.0.0 |
| 105 | + --port "$PORT" |
| 106 | + --trust-remote-code |
| 107 | + --tensor-parallel-size "$TP" |
| 108 | + ) |
| 109 | + SERVER_CMD+=("${DEFAULT_ARGS[@]}") |
| 110 | + SERVER_CMD+=("${EXTRA_SGLANG_ARGV[@]}") |
| 111 | + setsid "${SERVER_CMD[@]}" > "$SERVER_LOG" 2>&1 & |
| 112 | + |
| 113 | + SERVER_PID=$! |
| 114 | + if [[ "$PHASE" == "all" ]]; then |
| 115 | + trap 'magpie_stop_benchmark_server_stack "$SERVER_PID"' EXIT INT TERM |
| 116 | + fi |
| 117 | + |
| 118 | + wait_for_server_ready --port "$PORT" --server-log "$SERVER_LOG" --server-pid "$SERVER_PID" |
| 119 | + |
| 120 | + if [[ "$PHASE" == "server" ]]; then |
| 121 | + if [[ -z "${MAGPIE_SERVER_PID_FILE:-}" ]]; then |
| 122 | + echo "ERROR: MAGPIE_SERVER_PID_FILE must be set for MAGPIE_RUN_PHASE=server" >&2 |
| 123 | + kill -TERM "-$SERVER_PID" 2>/dev/null || true |
| 124 | + exit 3 |
| 125 | + fi |
| 126 | + printf '%s\n' "$SERVER_PID" > "$MAGPIE_SERVER_PID_FILE" |
| 127 | + disown "$SERVER_PID" 2>/dev/null || true |
| 128 | + exit 0 |
| 129 | + fi |
| 130 | +fi |
| 131 | + |
| 132 | +SERVER_MONITOR_ARGS=() |
| 133 | +if [[ -n "${SERVER_PID:-}" ]]; then |
| 134 | + SERVER_MONITOR_ARGS+=(--server-pid "$SERVER_PID") |
| 135 | +fi |
| 136 | + |
| 137 | +if [[ "$PHASE" == "client" || "$PHASE" == "all" ]]; then |
| 138 | + if [[ -n "${BENCHMARK_BASE_URL:-}" ]]; then |
| 139 | + SERVER_MONITOR_ARGS=() |
| 140 | + magpie_run_benchmark_serving_remote_direct || exit $? |
| 141 | + else |
| 142 | + # InferenceX names its OpenAI-compatible completions client "vllm"; |
| 143 | + # SGLang serves that protocol, and this is the physically qualified path. |
| 144 | + run_benchmark_serving \ |
| 145 | + --model "$MODEL" \ |
| 146 | + --port "$PORT" \ |
| 147 | + --backend vllm \ |
| 148 | + --input-len "$ISL" \ |
| 149 | + --output-len "$OSL" \ |
| 150 | + --random-range-ratio "$RANDOM_RANGE_RATIO" \ |
| 151 | + --num-prompts ${NUM_PROMPTS:-$(( $CONC * 10 ))} \ |
| 152 | + --max-concurrency "$CONC" \ |
| 153 | + --result-filename "$RESULT_FILENAME" \ |
| 154 | + "${SERVER_MONITOR_ARGS[@]}" \ |
| 155 | + --result-dir ${RESULT_DIR:-/workspace/} \ |
| 156 | + --trust-remote-code || exit $? |
| 157 | + fi |
| 158 | +fi |
| 159 | + |
| 160 | +if [[ "$PHASE" != "server" && "${RUN_EVAL}" = "true" ]]; then |
| 161 | + if [[ -n "${BENCHMARK_BASE_URL:-}" ]]; then |
| 162 | + if declare -F magpie_run_eval_remote_direct &>/dev/null; then |
| 163 | + magpie_run_eval_remote_direct || exit $? |
| 164 | + else |
| 165 | + echo "[sglang_radeon8060s] RUN_EVAL=true with BENCHMARK_BASE_URL but magpie_run_eval_remote_direct shim not available; skipping eval (results gate will see accuracy=None)." |
| 166 | + fi |
| 167 | + else |
| 168 | + export EVAL_CONCURRENT_REQUESTS="${MAGPIE_EVAL_CONCURRENCY:-${EVAL_CONCURRENT_REQUESTS:-$CONC}}" |
| 169 | + magpie_run_eval_persisted --framework lm-eval --port "$PORT" || exit $? |
| 170 | + fi |
| 171 | +fi |
| 172 | +set +x |
0 commit comments