Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/gpu-head-to-head/blob/main/bench/run_arm.sh # gpu-head-to-head aien-dev/gpu-head-to-head Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `gpu-head-to-head / bench / run_arm.sh` 617 lines ยท 33239 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # One arm session of the head-to-head (PROTOCOL.md sections 6-8, amendments A1-A10). 3 # usage: bench/run_arm.sh OURS|VLLM|SGLANG|LLAMA|LLAMA16|VLLM4|SGLANG4|LLAMA4|VLLM_ ROUND 4 # VLLM_: any arm declared in bench/arms.conf (ARM_MODEL[...]), PROTOCOL A10. 5 # Holds the GB10 lock for the whole session (at most 60 min; less with H2H_DEADLINE_EPOCH), or runs 6 # inside the caller's exclusive spark-window (A10), writes BOARD lines, starts exactly one server, 7 # runs the declared cell sets (H2H_CELLS, comma list), stops the server and checks the unload. 8 # Ends with results/logs/-/DONE, or NOT_RUN (with the reason) if the arm cannot start. 9 # H2H_PRINT_LAUNCH=1 prints the server launch argv (one item per line) and exits with no side effect. 10 set -u 11 ARM=$1; ROUND=$2 12 REPO=${H2H_REPO:-$(cd "$(dirname "$0")/.." && pwd)} 13 source "$REPO/bench/session-lifecycle.sh" || exit 2 14 RUN_ID="${ARM,,}-${ROUND,,}-$(date +%s)-$$" 15 H2H=${H2H:-/home/drakestapleton/h2h} 16 MODEL=/home/drakestapleton/models/qwen3.6-35b-a3b-fp8-`95a723d0` 17 VLLM_IMG=nvcr.io/nvidia/vllm@sha256:`557747337846eecf34486866f3d992383c6f8af869fdb0e365b5093fcaee02c2` 18 LLAMA_DIR=$H2H/dl/llama-bin/llama-b11913 19 CUDART_DIR=$H2H/dl/llama-bin/cudart-llama-b11913-bin-ubuntu-cuda-13.4-arm64 20 GGUF=$H2H/gguf/q36-35b-a3b-q8_0.gguf 21 GGUF16=$H2H/gguf/q36-35b-a3b-bf16.gguf 22 # A3 arms: SGLANG_IMG (image@digest), MODEL4 (vLLM/SGLang 4-bit checkpoint dir), GGUF4 (llama.cpp 23 # 4-bit GGUF) are set in bench/arms.conf once verified; unset -> the arm is recorded NOT_RUN. 24 # A10: bench/arms.conf also declares the per-arm vLLM hooks (ARM_* arrays) and the OURS binary. 25 SGLANG_IMG=; MODEL4=; GGUF4= 26 declare -A ARM_MODEL=() ARM_IMG=() ARM_UTIL=() ARM_QUANT=() ARM_KV=() ARM_ATTN=() ARM_MOE=() \ 27 ARM_SPEC=() ARM_PREFIX=() ARM_PROFILE=() 28 OURS_BIN_DIR=${OURS_BIN_DIR:-/home/drakestapleton/.local/state/aien-q36/bin-`19173f9e`} 29 OURS_BIN_SHA256=${OURS_BIN_SHA256:-`19173f9ec3b609fe79af644f84741d8808b92ea8eb3ecec4bc945af6f22b3aeb`} 30 OURS_WAVE=${OURS_WAVE:-0} # A10: AIEN_OMEGA_FP8_GROUPED_WAVE recorded and passed explicitly to OURS 31 NSYS_DIR=/opt/nvidia/nsight-systems/2025.3.2 32 [ -f "$REPO/bench/arms.conf" ] && . "$REPO/bench/arms.conf" 33 BOARD=${H2H_BOARD:-/home/drakestapleton/handoffs/BOARD.md} 34 VLLM_UTIL=${VLLM_UTIL:-0.50} 35 SGLANG_MEM=${SGLANG_MEM:-0.50} 36 RESULTS=${H2H_RESULTS:-$REPO/results} 37 OUT=$RESULTS/raw/$ARM-$ROUND.jsonl 38 LOGD=$RESULTS/logs/$ARM-$ROUND 39 DEADLINE=${H2H_DEADLINE_EPOCH:-} # A10: absolute epoch by which the whole session must have stopped 40 CELLSET=${H2H_CELLS:-full} # A10: comma list of full (14 cells, A3) | dra74 (7) | nsys-c8 (1) 41 # | ttft-fresh (1 per H2H_TTFT_PROMPTS item) | ttft-turn2 (1) 42 TTFT_PROMPTS=${H2H_TTFT_PROMPTS:-t2k,t8k,t32k} # A10: ttft-fresh prompts, in order 43 TTFT_REPS=${H2H_TTFT_REPS:-3}; TTFT_REP_BASE=${H2H_TTFT_REP_BASE:-0} # A10: reps split across slices 44 PREFIX_OVERRIDE=${H2H_PREFIX:-} # A10: "on" enables vLLM prefix caching for a ttft-turn2-only session 45 [ "$PREFIX_OVERRIDE" = on ] && ARM_PREFIX[$ARM]=on # validated in arm_preconditions before any launch 46 if [ "${H2H_PRINT_LAUNCH:-0}" != 1 ]; then 47 if [ -e "$OUT" ] || [ -e "$LOGD" ]; then 48 echo "refusing to overwrite an existing session: $LOGD or $OUT" >&2 49 exit 2 50 fi 51 mkdir -p "$LOGD" "$(dirname "$OUT")" 52 touch "$RESULTS/cell-status.jsonl" || exit 2 53 fi 54 ts() { date -u +%Y-%m-%dT%H:%M:%SZ; } 55 board() { echo "$(ts) HeadToHead: $*" >> "$BOARD"; echo "$(ts) $*" >> "$LOGD/session.log"; } 56 notrun() { board "$ARM $ROUND NOT_RUN: $*"; echo "$*" > "$LOGD/NOT_RUN"; exit 4; } 57 memavail() { awk '/MemAvailable/{print $2}' /proc/meminfo; } 58 CTR= 59 case $ARM in 60 OURS) PORT=18190; PAT='aien-serve-http.*--port 18190'; MID=qwen3.6-35b-a3b-fp8 ;; 61 VLLM) PORT=18191; PAT='vllm serve|VLLM::|EngineCore'; MID=q36; CTR=stack-h2h-$RUN_ID; MDIR=$MODEL ;; 62 VLLM4) PORT=18191; PAT='vllm serve|VLLM::|EngineCore'; MID=q36; CTR=stack-h2h-$RUN_ID; MDIR=$MODEL4 ;; 63 SGLANG) PORT=18194; PAT='sglang'; MID=q36; CTR=stack-h2h-$RUN_ID; MDIR=$MODEL ;; 64 SGLANG4) PORT=18194; PAT='sglang'; MID=q36; CTR=stack-h2h-$RUN_ID; MDIR=$MODEL4 ;; 65 LLAMA) PORT=18192; PAT='llama-server.*--port 18192'; MID=q36; G=$GGUF; MMAP= ;; 66 LLAMA16) PORT=18193; PAT='llama-server.*--port 18193'; MID=q36; G=$GGUF16; MMAP=--no-mmap ;; 67 LLAMA4) PORT=18192; PAT='llama-server.*--port 18192'; MID=q36; G=$GGUF4; MMAP= ;; 68 VLLM_*) 69 [ -n "${ARM_MODEL[$ARM]:-}" ] || { echo "bad arm: $ARM is not declared in bench/arms.conf"; exit 2; } 70 PORT=18191; PAT='vllm serve|VLLM::|EngineCore'; MID=q36; CTR=stack-h2h-$RUN_ID; MDIR=${ARM_MODEL[$ARM]} 71 VLLM_IMG=${ARM_IMG[$ARM]:-$VLLM_IMG}; VLLM_UTIL=${ARM_UTIL[$ARM]:-$VLLM_UTIL} ;; 72 *) echo "bad arm"; exit 2 ;; 73 esac 74 75 # A2: cpus 5-9,15-19 are Cortex-X925 (CPU part 0xd85), 0-4,10-14 Cortex-A725 (0xd87). 76 # A10 (supersedes A4(e)): the server gets the X925 cores minus core 17, minus the client and monitor 77 # cores, minus the core the nvidia-modeset kthread is on when the session takes the GPU lock (core 18 78 # when that core is on an A725 core or already excluded, so the count is constant). Default client 79 # 0-1 and monitor 2 leave 8 server cores; the DRA-74 slices put the client on X925 core 5 at nice 19. 80 X925=" 5 6 7 8 9 15 16 17 18 19 " 81 cpus_expand() { # "0-1,5" -> " 0 1 5 " 82 local IFS=, p out=" " 83 for p in $1; do 84 if [[ "$p" =~ ^([0-9]+)-([0-9]+)$ ]]; then out="$out$(seq -s ' ' "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}") " 85 elif [[ "$p" =~ ^[0-9]+$ ]]; then out="$out$p " 86 else return 1; fi 87 done 88 echo "$out" 89 } 90 cpu_guard() { # A10: fail closed unless the client and monitor cores are valid and disjoint 91 local cli c 92 cli=$(cpus_expand "$CLI_CPUS") && [ "$cli" != " " ] || { echo "client cpu list '$CLI_CPUS' is invalid"; return 1; } 93 [[ "$MON_CPU" =~ ^[0-9]+$ ]] || { echo "MON_CPU '$MON_CPU' must be one core number"; return 1; } 94 for c in $cli $MON_CPU; do 95 [ "$c" -le 19 ] || { echo "core $c does not exist"; return 1; } 96 [ "$c" -lt 10 ] || [ "$c" -gt 14 ] || { echo "core $c is in the 10-14 build set other lanes use"; return 1; } 97 [ "$c" != 17 ] || { echo "core 17 is excluded from every session role"; return 1; } 98 done 99 case $cli in *" $MON_CPU "*) echo "MON_CPU $MON_CPU overlaps the client cores $CLI_CPUS"; return 1 ;; esac 100 [[ "$CLI_NICE" =~ ^[0-9]+$ ]] && [ "$CLI_NICE" -le 19 ] || { echo "client nice '$CLI_NICE' must be 0-19"; return 1; } 101 } 102 pick_srv() { 103 local k=$(ktpsr) c excl 104 cpu_guard >/dev/null || return 1 105 excl=" 17$(cpus_expand "$CLI_CPUS")$MON_CPU " 106 case $X925 in *" $k "*) ;; *) k=18 ;; esac 107 case $excl in *" $k "*) k=18 ;; esac 108 excl="$excl$k " 109 SRV_LIST=" "; for c in $X925; do case $excl in *" $c "*) ;; *) SRV_LIST="$SRV_LIST$c " ;; esac; done 110 case $SRV_LIST in *" 17 "*|*" $MON_CPU "*|" ") return 1 ;; esac 111 SRV_CPUS=$(echo $SRV_LIST | tr ' ' ',') 112 export H2H_SRV_CPUS=$SRV_CPUS 113 } 114 SRV_CPUS=5-9,15-16,18-19 115 SRV_LIST=" 5 6 7 8 9 15 16 18 19 " 116 CLI_CPUS=${H2H_CLIENT_CPUS:-0-1} # A5(d): A725 cores outside the 10-14 build set; A10: slices use 5 117 CLI_NICE=${H2H_CLIENT_NICE:-0} # A10: slices run the client at nice 19 118 MON_CPU=${H2H_MON_CPU:-2} # coremon.py (A4), outside the server and client sets (cpu_guard) 119 export H2H_SRV_CPUS=$SRV_CPUS H2H_CLI_CPUS=$CLI_CPUS 120 KT=1671 # nvidia-modeset kthread; never reniced or pinned during the study (A2) 121 ktpsr() { awk '{print $39}' /proc/$KT/stat 2>/dev/null || echo NA; } 122 123 mytree() { # pids whose process trees belong to this session 124 echo $$ $SPID 125 [ -n "$CTR" ] && docker inspect -f '{{.State.Pid}}' $CTR 2>/dev/null 126 } 127 128 wait_quiet() { # PROTOCOL A2: before each cell, no foreign process >20% CPU over 10 s 129 while :; do 130 if python3 "$REPO/bench/quiet.py" --window 10 --max-load 0 --exclude-tree $(mytree) >> "$LOGD/quiet.jsonl"; then 131 return 0 132 fi 133 if [ "$(date +%s)" -ge "$QUIET_AT" ]; then echo "$(ts) quiet gate timeout" >> "$LOGD/session.log"; return 1; fi 134 done 135 } 136 137 sampler() { # 1 Hz: epoch MemAvailable_kB summed_RSS_kB load1 kthread_psr 138 while :; do 139 rss=$(for p in $(server_pids); do awk '/VmRSS/{print $2}' /proc/$p/status 2>/dev/null; done | awk '{s+=$1}END{print s+0}') 140 echo "$(date +%s) $(memavail) $rss $(cut -d' ' -f1 /proc/loadavg) $(ktpsr)" 141 sleep 1 142 done 143 } 144 145 server_pids() { 146 if [ -n "$CTR" ]; then 147 [ "$(docker inspect -f '{{index .Config.Labels "aien.stack-comparison.run"}}' "$CTR" 2>/dev/null)" = "$RUN_ID" ] || return 1 148 local root 149 root=$(docker inspect -f '{{.State.Pid}}' "$CTR" 2>/dev/null) || return 1 150 h2h_descendant_pids "$root" 151 elif [ -s "$LOGD/server-identity.txt" ]; then 152 local root expected identity state birth parent 153 read -r root expected < "$LOGD/server-identity.txt" || return 1 154 identity=$(h2h_identity "$root") || return 1 155 read -r state birth parent <<< "$identity" 156 [ "$birth" = "$expected" ] || return 1 157 h2h_descendant_pids "$root" 158 fi 159 } 160 161 start_server() { 162 case $ARM in 163 OURS) 164 ( cd "$OURS_BIN_DIR" && \ 165 exec env AIEN_Q36_STROKE=1 Q36_BATCH_BIN="$(basename "$OURS_BIN_DIR")" AIEN_SERVE_GPU_LOCK=/tmp/aien-serve-18190.lock \ 166 AIEN_GB10_LOCK_HELD=1 AIEN_OMEGA_FP8_GROUPED_WAVE="$OURS_WAVE" \ 167 taskset -c $SRV_CPUS ./aien-serve-http --engine omega --model-dir "$MODEL" --bind 127.0.0.1 --port 18190 --max-context 49152 \ 168 --max-tokens-cap 16384 --thinking off --batch-slots 8 ) < /dev/null > "$LOGD/server.log" 2>&1 & 169 SPID=$! ;; 170 VLLM|VLLM4|VLLM_*) 171 vllm_argv || return 1 172 [ "${#DARGV[@]}" -eq 0 ] || mkdir -p "$LOGD/nsys" || return 1 # only the nsys arm mounts docker extras 173 printf '%s\n' "${DARGV[@]}" -v "$MDIR:/model:ro" "$VLLM_IMG" "${VARGV[@]}" > "$LOGD/launch.txt" 174 timeout 30 docker create --pull never --rm --name "$CTR" --label "aien.stack-comparison.run=$RUN_ID" --runtime nvidia --gpus all --ipc host --network host \ 175 --cpuset-cpus $SRV_CPUS "${DARGV[@]}" -v "$MDIR":/model:ro "$VLLM_IMG" "${VARGV[@]}" \ 176 < /dev/null > "$LOGD/container-id.txt" 2> "$LOGD/server.log" || return 1 177 docker start --attach "$CTR" < /dev/null >> "$LOGD/server.log" 2>&1 & 178 SPID=$! ;; 179 SGLANG|SGLANG4) 180 timeout 30 docker create --pull never --rm --name "$CTR" --label "aien.stack-comparison.run=$RUN_ID" --runtime nvidia --gpus all --ipc host --network host \ 181 --cpuset-cpus $SRV_CPUS -v "$MDIR":/model:ro "$SGLANG_IMG" python3 -m sglang.launch_server \ 182 --model-path /model --served-model-name q36 --host 127.0.0.1 --port 18194 \ 183 --context-length 49152 --max-running-requests 32 --mem-fraction-static "$SGLANG_MEM" \ 184 < /dev/null > "$LOGD/container-id.txt" 2> "$LOGD/server.log" || return 1 185 docker start --attach "$CTR" < /dev/null >> "$LOGD/server.log" 2>&1 & 186 SPID=$! ;; 187 LLAMA*) 188 LD_LIBRARY_PATH=$CUDART_DIR:$LLAMA_DIR taskset -c $SRV_CPUS "$LLAMA_DIR/llama-server" -m "$G" --host 127.0.0.1 \ 189 --port $PORT -ngl 999 -fa on -c 393216 -np 32 --jinja $MMAP < /dev/null > "$LOGD/server.log" 2>&1 & 190 SPID=$! ;; 191 esac 192 h2h_track "$SPID" || return 1 193 printf '%s %s\n' "$SPID" "${H2H_PID_START[$SPID]}" > "$LOGD/server-identity.txt" 194 } 195 196 vllm_argv() { # A10: VARGV = argv inside the container, DARGV = extra docker create options 197 VARGV=(vllm serve /model --served-model-name q36 --host 127.0.0.1 --port 18191 --max-model-len 49152 198 --max-num-seqs 32 --gpu-memory-utilization "$VLLM_UTIL" --language-model-only) 199 DARGV=() 200 case $ARM in VLLM|VLLM4) return 0 ;; esac # A1/A3 arms: argv unchanged 201 [ -z "${ARM_QUANT[$ARM]:-}" ] || VARGV+=(--quantization "${ARM_QUANT[$ARM]}") 202 [ -z "${ARM_KV[$ARM]:-}" ] || VARGV+=(--kv-cache-dtype "${ARM_KV[$ARM]}") 203 [ -z "${ARM_ATTN[$ARM]:-}" ] || VARGV+=(--attention-backend "${ARM_ATTN[$ARM]}") 204 [ -z "${ARM_MOE[$ARM]:-}" ] || VARGV+=(--moe-backend "${ARM_MOE[$ARM]}") 205 [ -z "${ARM_SPEC[$ARM]:-}" ] || VARGV+=(--speculative-config "${ARM_SPEC[$ARM]}") 206 case ${ARM_PREFIX[$ARM]:-} in 207 off) VARGV+=(--no-enable-prefix-caching) ;; 208 on) VARGV+=(--enable-prefix-caching) ;; 209 '') ;; 210 *) echo "ARM_PREFIX[$ARM]='${ARM_PREFIX[$ARM]}' must be on, off or empty" >&2; return 1 ;; 211 esac 212 case ${ARM_PROFILE[$ARM]:-} in 213 '') ;; 214 nsys) # A10: kernel timeline of the cudaProfilerApi range opened by POST /start_profile 215 DARGV=(-v "$NSYS_DIR:/nsys:ro" -v "$LOGD/nsys:/nsys-out") 216 VARGV=(/nsys/bin/nsys profile -t cuda,nvtx --cuda-graph-trace=node --capture-range=cudaProfilerApi 217 --capture-range-end=repeat -f true -o "/nsys-out/$ARM-$ROUND" "${VARGV[@]}" 218 --profiler-config '{"profiler":"cuda"}') ;; 219 *) echo "ARM_PROFILE[$ARM]='${ARM_PROFILE[$ARM]}' must be nsys or empty" >&2; return 1 ;; 220 esac 221 } 222 223 stop_server() { 224 if [ -n "$CTR" ] && docker inspect "$CTR" >/dev/null 2>&1; then 225 local owner 226 owner=$(docker inspect -f '{{index .Config.Labels "aien.stack-comparison.run"}}' "$CTR" 2>/dev/null) 227 if [ "$owner" != "$RUN_ID" ]; then 228 echo "refusing to stop container owned by another session: $CTR" >&2 229 return 1 230 fi 231 timeout 15 docker stop -t 10 "$CTR" >/dev/null 2>&1 || { 232 docker inspect "$CTR" >/dev/null 2>&1 && return 1 233 } 234 fi 235 if [ -n "$SPID" ]; then h2h_stop "$SPID" || return 1; SPID=; fi 236 } 237 238 ready() { 239 for i in $(seq 1 1200); do 240 if ! kill -0 $SPID 2>/dev/null; then return 1; fi 241 if curl -sf "http://127.0.0.1:$PORT/v1/models" >/dev/null 2>&1; then return 0; fi 242 sleep 1 243 done 244 return 1 245 } 246 247 loopback_only() { # A5(f): every listener on the test port must be 127.0.0.1, else the arm FAILs 248 ss -ltnH "sport = :$PORT" > "$LOGD/listen.txt" 249 [ -s "$LOGD/listen.txt" ] && ! awk '{print $4}' "$LOGD/listen.txt" | grep -qv '^127\.0\.0\.1:' 250 } 251 252 window_held() { # A10: inside the runner's exclusive spark-window, the window holds the GB10 lock 253 local id 254 [ "${AIEN_GB10_LOCK_HELD:-}" = 1 ] && [ -n "${SPARK_WINDOW:-}" ] && [ -n "${SPARK_WINDOW_DIR:-}" ] \ 255 || { echo "AIEN_GB10_LOCK_HELD/SPARK_WINDOW/SPARK_WINDOW_DIR incomplete"; return 1; } 256 id=$(timeout 10 "${SPARK_WINDOW_BIN:-spark-window}" id 2>/dev/null) || { echo "spark-window id failed"; return 1; } 257 [ "$id" = "$SPARK_WINDOW" ] || { echo "held window '$id' is not SPARK_WINDOW '$SPARK_WINDOW'"; return 1; } 258 [ "$(cat "$SPARK_WINDOW_DIR/gb10" 2>/dev/null)" = exclusive ] || { echo "window $id does not hold the GB10 exclusively"; return 1; } 259 } 260 261 arm_preconditions() { # prints the NOT_RUN reason and returns 1; no side effects 262 case $ARM in 263 SGLANG*) [ -n "$SGLANG_IMG" ] || { echo "no SGLang image verified for aarch64/sm_121 (bench/arms.conf)"; return 1; } ;; 264 esac 265 case $ARM in 266 VLLM4|SGLANG4) [ -n "$MODEL4" ] && [ -f "$MODEL4/config.json" ] || { echo "no 4-bit checkpoint (bench/arms.conf MODEL4)"; return 1; } ;; 267 LLAMA4) [ -n "$GGUF4" ] && [ -f "$GGUF4" ] || { echo "no 4-bit GGUF (bench/arms.conf GGUF4)"; return 1; } ;; 268 VLLM_*) [ -f "$MDIR/config.json" ] || { echo "$ARM model dir $MDIR has no config.json"; return 1; } ;; 269 OURS) 270 local sha 271 sha=$(sha256sum "$OURS_BIN_DIR/aien-serve-http" 2>/dev/null | cut -d' ' -f1) 272 [ "$sha" = "$OURS_BIN_SHA256" ] || { echo "OURS binary $OURS_BIN_DIR/aien-serve-http sha256 '${sha:-missing}' is not $OURS_BIN_SHA256"; return 1; } 273 [[ "$OURS_WAVE" =~ ^[01]$ ]] || { echo "OURS_WAVE must be 0 or 1"; return 1; } ;; 274 esac 275 cpu_guard || return 1 276 if [ -n "$DEADLINE" ]; then 277 [[ "$DEADLINE" =~ ^[0-9]+$ ]] && [ "$DEADLINE" -gt $(( $(date +%s) + 600 )) ] \ 278 || { echo "H2H_DEADLINE_EPOCH '$DEADLINE' must be an epoch more than 600 s ahead"; return 1; } 279 fi 280 if [ -n "$PREFIX_OVERRIDE" ]; then 281 [ "$PREFIX_OVERRIDE" = on ] && [[ $ARM == VLLM_* ]] && [ "$CELLSET" = ttft-turn2 ] \ 282 || { echo "H2H_PREFIX=on applies only to a VLLM_* arm running H2H_CELLS=ttft-turn2 alone"; return 1; } 283 fi 284 [[ "$TTFT_REPS" =~ ^[1-9]$ && "$TTFT_REP_BASE" =~ ^[0-9]{1,2}$ ]] \ 285 || { echo "H2H_TTFT_REPS must be 1-9 and H2H_TTFT_REP_BASE 0-99"; return 1; } 286 local set seen=, 287 for set in ${CELLSET//,/ }; do 288 [[ $seen != *",$set,"* ]] || { echo "H2H_CELLS '$CELLSET' names $set twice"; return 1; } 289 seen=$seen$set, 290 case $set in 291 full|dra74) [ "${ARM_PROFILE[$ARM]:-}" = "" ] || { echo "$ARM is a profiling arm; it runs only cell set nsys-c8"; return 1; } ;; 292 nsys-c8) [ "${ARM_PROFILE[$ARM]:-}" = nsys ] && [ -x "$NSYS_DIR/bin/nsys" ] \ 293 || { echo "cell set nsys-c8 needs an ARM_PROFILE=nsys arm and $NSYS_DIR/bin/nsys"; return 1; } 294 [ "$CELLSET" = nsys-c8 ] || { echo "cell set nsys-c8 runs alone"; return 1; } ;; 295 ttft-fresh|ttft-turn2) 296 [[ $ARM == OURS || $ARM == VLLM_* ]] && [ "${ARM_PROFILE[$ARM]:-}" = "" ] \ 297 || { echo "TTFT cell sets run on OURS and unprofiled VLLM_* arms only"; return 1; } ;;& 298 ttft-fresh) 299 [ "${ARM_PREFIX[$ARM]:-}" != on ] || { echo "ttft-fresh needs prefix caching off"; return 1; } 300 local p pseen=, 301 for p in ${TTFT_PROMPTS//,/ }; do 302 [[ $p =~ ^t(2|8|32)k$ && $pseen != *",$p,"* ]] || { echo "H2H_TTFT_PROMPTS '$TTFT_PROMPTS' must list distinct t2k, t8k, t32k"; return 1; } 303 pseen=$pseen$p, 304 done 305 [ "$pseen" != , ] || { echo "H2H_TTFT_PROMPTS is empty"; return 1; } ;; 306 ttft-turn2) 307 [[ $ARM != VLLM_* ]] || [ "$PREFIX_OVERRIDE" = on ] \ 308 || { echo "ttft-turn2 on a vLLM arm needs H2H_PREFIX=on (the cached row)"; return 1; } ;; 309 *) echo "H2H_CELLS '$CELLSET': each item must be full, dra74, nsys-c8, ttft-fresh or ttft-turn2"; return 1 ;; 310 esac 311 done 312 [ "$seen" != , ] || { echo "H2H_CELLS is empty"; return 1; } 313 } 314 315 cell_status() { 316 python3 -c 'import json,sys; print(json.dumps({"cell_run":sys.argv[1],"status":sys.argv[2]}))' \ 317 "$1" "$2" >> "$RESULTS/cell-status.jsonl" 318 } 319 320 cell() { # metric concurrency max_tokens promptfile [extra] 321 # A2: a cell is VOID and re-run (<=3 tries) when the nvidia-modeset kthread was sampled on a server 322 # core, or a process outside HeadToHead used >20% of one server core (bench/coremon.py) 323 local metric=$1 c=$2 mt=$3 pf=$4; shift 4 324 local try t0 t1 hit cm cmrc why off clientrc 325 mkdir -p "$LOGD/coremon" 326 for try in 1 2 3; do 327 local id="$ARM-$ROUND-$metric-t$try" 328 [ -e "$LOGD/TIMEOUT" ] && { cell_status "$id" NOT_RUN; return 1; } 329 wait_quiet || { echo "$(ts) cell $metric NOT_RUN: no quiet window" >> "$LOGD/session.log"; cell_status "$id" NOT_RUN; return 1; } 330 taskset -c $MON_CPU python3 "$REPO/bench/coremon.py" --cpus $SRV_CPUS --exclude-tree $(mytree) \ 331 --out "$LOGD/coremon/$id.jsonl" & cm=$! 332 CMON_PID=$cm 333 h2h_track "$cm" || return 1 334 t0=$(date +%s) 335 taskset -c $CLI_CPUS nice -n "$CLI_NICE" python3 "$REPO/bench/bench.py" --port $PORT --model $MID --arm $ARM --round $ROUND --metric "$metric" \ 336 --prompts "$REPO/prompts/$pf" --concurrency $c --max-tokens $mt --out "$OUT" --cell-run "$id" "$@" 2>> "$LOGD/client.log" & CPID=$! 337 h2h_track "$CPID" || return 1 338 wait "$CPID"; clientrc=$? 339 unset 'H2H_PID_START[$CPID]'; CPID= 340 h2h_matches "$cm" && kill -TERM "$cm" 2>/dev/null || true 341 wait "$cm"; cmrc=$? 342 unset 'H2H_PID_START[$cm]'; CMON_PID= 343 if [ "$clientrc" -ne 0 ]; then 344 echo "$(ts) $id FAIL: client exit $clientrc; raw rows retained" >> "$LOGD/session.log" 345 cell_status "$id" FAIL 346 return 1 347 fi 348 if [ "$cmrc" -ne 0 ] && [ "$cmrc" -ne 1 ]; then 349 echo "$(ts) $id foreign-process check NOT_RUN: monitor exit $cmrc" >> "$LOGD/session.log" 350 cell_status "$id" NOT_RUN 351 return 1 352 fi 353 sleep 2; t1=$(date +%s) 354 if ! awk -v a=$t0 -v b=$t1 '$1>=a && $1<=b {n++; if ($5 !~ /^[0-9]+$/) bad=1} END{exit (!n || bad)}' "$LOGD/mem.tsv"; then 355 echo "$(ts) $id kthread check NOT_RUN: missing or invalid samples" >> "$LOGD/session.log" 356 cell_status "$id" NOT_RUN 357 return 1 358 fi 359 hit=$(awk -v a=$t0 -v b=$t1 -v s="$SRV_LIST" '$1>=a && $1<=b && index(s, " "$5" ") {print $5; exit}' "$LOGD/mem.tsv") 360 why= 361 [ -n "$hit" ] && why="nvidia-modeset kthread on server core $hit" 362 # A4: only a coremon summary that names offenders voids the cell; a monitor that wrote no 363 # summary is recorded as "foreign check NOT_RUN" for that cell, never as a void 364 off=$(python3 -c 'import json,sys 365 rows=[json.loads(l) for l in open(sys.argv[1])] 366 s=[r for r in rows if r.get("summary") is True] 367 if len(s)!=1 or not isinstance(s[0].get("elapsed_ticks"),int) or s[0]["elapsed_ticks"]<=0 or not isinstance(s[0].get("offenders"),list): 368 print("NOSUMMARY") 369 else: 370 print(json.dumps(s[0]["offenders"]))' "$LOGD/coremon/$id.jsonl" 2>/dev/null || echo NOSUMMARY) 371 case $off in 372 NOSUMMARY) echo "$(ts) $id foreign-process check NOT_RUN: coremon exit $cmrc, no summary" >> "$LOGD/session.log"; cell_status "$id" NOT_RUN; return 1 ;; 373 '[]') [ "$cmrc" -eq 0 ] || { echo "$(ts) $id FAIL: monitor exit disagrees with clean summary" >> "$LOGD/session.log"; cell_status "$id" FAIL; return 1; } ;; 374 *) why="${why:+$why; }foreign process >20% of a server core: $(echo "$off" | cut -c1-300)" ;; 375 esac 376 if [ -z "$why" ]; then 377 cell_status "$id" PASS || return 1 378 CELLS_COMPLETED=$((CELLS_COMPLETED + 1)) 379 return 0 380 fi 381 python3 -c 'import json,sys; print(json.dumps({"cell_run": sys.argv[1], "reason": sys.argv[2], "t0": int(sys.argv[3]), "t1": int(sys.argv[4])}))' \ 382 "$id" "$why" $t0 $t1 >> "$RESULTS/voids.jsonl" 383 cell_status "$id" VOID || return 1 384 echo "$(ts) VOID $id: $why" >> "$LOGD/session.log" 385 done 386 echo "$(ts) $metric NOT_RUN: all three attempts disturbed" >> "$LOGD/session.log" 387 return 1 388 } 389 390 mark_complete() { 391 if [ "$CELLS_COMPLETED" -ne "${EXPECTED_CELLS:-14}" ] || [ -e "$LOGD/TIMEOUT" ]; then 392 echo "incomplete: $CELLS_COMPLETED/${EXPECTED_CELLS:-14} accepted cells; see session.log" > "$LOGD/INCOMPLETE" 393 return 1 394 fi 395 touch "$LOGD/DONE" 396 } 397 398 start_watchdog() { 399 ( 400 if [ "$#" -ge 1 ]; then sleep "$1"; 401 else delay=$((WARN_AT - $(date +%s))); [ "$delay" -le 0 ] || sleep "$delay"; fi 402 board "T-$(( (${STOP_AT:-0} - ${WARN_AT:-0}) / 60 )) $ARM $ROUND: cleanup reserved before the session stop time" 403 if [ "$#" -ge 2 ]; then sleep "$2"; 404 else delay=$((STOP_AT - $(date +%s))); [ "$delay" -le 0 ] || sleep "$delay"; fi 405 touch "$LOGD/TIMEOUT" 406 board "$ARM $ROUND reached its stop time; stopping own session with cleanup time reserved" 407 kill -TERM $$ 408 ) & WD=$! 409 h2h_track "$WD" 410 } 411 412 cleanup_session() { 413 local rc=$? pid 414 trap - EXIT 415 trap '' INT TERM 416 H2H_STOP_DEADLINE=$((SECONDS + 30)) 417 for pid in "$WD" "$CPID" "$CMON_PID"; do 418 [ -z "$pid" ] || h2h_stop "$pid" || rc=1 419 done 420 stop_server || rc=1 421 for pid in "$SAMP" "$VMS"; do 422 [ -z "$pid" ] || h2h_stop "$pid" || rc=1 423 done 424 if [ "$GPU_LOCK_HELD" = 1 ]; then 425 timeout 5 nvidia-smi --query-compute-apps=pid,name,used_memory --format=csv > "$LOGD/gpu-after.csv" 2>&1 || rc=1 426 AFTER=$(memavail) 427 echo "after_memavail_kB $AFTER" >> "$LOGD/mem-baseline.txt" 428 # Recording the inventory alone does not prove that the model unloaded. 429 local remaining_gpu 430 if ! remaining_gpu=$(timeout 5 nvidia-smi --query-compute-apps=pid --format=csv,noheader,nounits); then 431 echo "FAIL GPU inventory unavailable after unload" >> "$LOGD/unload-status.txt" 432 rc=1 433 elif [ -n "$remaining_gpu" ]; then 434 echo "FAIL GPU processes remain after unload" >> "$LOGD/unload-status.txt" 435 rc=1 436 else 437 echo "PASS no GPU compute processes remain" >> "$LOGD/unload-status.txt" 438 fi 439 # /proc/meminfo reports KiB. Refuse missing/malformed/overflow-sized samples. 440 if [[ ! "$BASE" =~ ^[0-9]{1,12}$ || ! "$AFTER" =~ ^[0-9]{1,12}$ ]]; then 441 echo "FAIL unavailable or invalid memory baseline/sample" >> "$LOGD/unload-status.txt" 442 rc=1 443 elif (( 10#$BASE == 0 || 10#$AFTER == 0 || 10#$BASE - 10#$AFTER > 2 * 1024 * 1024 )); then 444 echo "FAIL memory did not recover within 2 GiB of baseline" >> "$LOGD/unload-status.txt" 445 rc=1 446 else 447 echo "PASS memory recovered within 2 GiB of baseline" >> "$LOGD/unload-status.txt" 448 fi 449 echo "kthread_psr_end $(ktpsr)" >> "$LOGD/session.log" 450 board "END $ARM $ROUND own session stopped at $SECONDS s; memavail base=${BASE}kB after=${AFTER}kB; exit=$rc" 451 if [ "$GPU_LOCK_RELEASE" = 1 ]; then flock -u 9 || rc=1; fi 452 fi 453 if [ "$rc" -ne 0 ]; then 454 rm -f "$LOGD/DONE" 455 echo "session exit $rc; see session.log" >> "$LOGD/INCOMPLETE" 456 fi 457 exit "$rc" 458 } 459 460 # ---- session ---- 461 # PROTOCOL A2 (Main's gate): start only when no foreign process used >20% CPU for 60 s and load1 < 6, 462 # before taking the lock, so the 60-min hold is not spent waiting 463 SPID= CPID= CMON_PID= WD= SAMP= VMS= BASE= GPU_LOCK_HELD=0 GPU_LOCK_RELEASE=1 464 if [ "${H2H_PRINT_LAUNCH:-0}" = 1 ]; then # A10: show the launch, touch nothing 465 why=$(arm_preconditions) || { echo "NOT_RUN: $why" >&2; exit 4; } 466 pick_srv || { echo "NOT_RUN: core guard" >&2; exit 4; } 467 echo "server_cpus $SRV_CPUS client_cpus $CLI_CPUS client_nice $CLI_NICE monitor_cpu $MON_CPU" >&2 468 case $ARM in 469 VLLM|VLLM4|VLLM_*) vllm_argv || exit 4; printf '%s\n' "${DARGV[@]}" -v "$MDIR:/model:ro" "$VLLM_IMG" "${VARGV[@]}" ;; 470 OURS) printf '%s\n' "AIEN_OMEGA_FP8_GROUPED_WAVE=$OURS_WAVE" "$OURS_BIN_DIR/aien-serve-http" ;; 471 *) echo "print mode covers the OURS and vLLM arms" >&2 ;; 472 esac 473 exit 0 474 fi 475 trap cleanup_session EXIT 476 trap 'exit 130' INT 477 trap 'exit 143' TERM 478 CELLS_COMPLETED=0 479 SESSION_RC=1 480 why=$(arm_preconditions) || notrun "$why" 481 until python3 "$REPO/bench/quiet.py" --window 60 --max-load 6 --exclude-tree $$ >> "$LOGD/quiet.jsonl"; do 482 [ -z "$DEADLINE" ] || [ "$(date +%s)" -lt $((DEADLINE - 600)) ] || notrun "no quiet 60 s window before deadline - 600 s" 483 done 484 for pair in LLAMA:convert.log LLAMA16:convert-bf16.log; do # the GGUF must be fully written 485 [ "$ARM" = "${pair%%:*}" ] || continue 486 CL=$H2H/gguf/${pair#*:} 487 until grep -q '^EXIT 0$' "$CL" 2>/dev/null; do 488 grep -q '^EXIT [1-9]' "$CL" 2>/dev/null && notrun "GGUF conversion failed ($CL)" 489 sleep 30 490 done 491 done 492 if [ "${AIEN_GB10_LOCK_HELD:-}" = 1 ] || [ -n "${SPARK_WINDOW:-}" ]; then 493 # A10: the runner's spark-window holds /tmp/aien-gb10.lock; waiting on it here would deadlock 494 why=$(window_held) || notrun "in-window lock check failed: $why" 495 GPU_LOCK_RELEASE=0 496 echo "$(ts) in spark-window $SPARK_WINDOW (gb10 exclusive); no flock taken" >> "$LOGD/session.log" 497 elif [ "${H2H_GPU_LOCK_FD:-}" = 9 ]; then 498 GPU_LOCK_RELEASE=0 499 [ "$(readlink /proc/$$/fd/9)" = /tmp/aien-gb10.lock ] || notrun "inherited GPU-lock descriptor names another file" 500 flock -n 9 || notrun "inherited GPU-lock descriptor cannot acquire the lock" 501 else 502 exec 9>/tmp/aien-gb10.lock 503 echo "$(ts) quiet: $(tail -1 "$LOGD/quiet.jsonl"); waiting for /tmp/aien-gb10.lock" >> "$LOGD/session.log" 504 flock -w 900 9 || { board "$ARM $ROUND NOT STARTED: /tmp/aien-gb10.lock busy 900 s"; exit 3; } 505 fi 506 GPU_LOCK_HELD=1 507 SECONDS=0 508 LOCK_EPOCH=$(date +%s); STOP_AT=$((LOCK_EPOCH + 3540)); WARN_AT=$((LOCK_EPOCH + 3300)); QUIET_AT=$((LOCK_EPOCH + 3000)) 509 if [ -n "$DEADLINE" ] && [ $((DEADLINE - 60)) -lt "$STOP_AT" ]; then # A10 deadline mode 510 STOP_AT=$((DEADLINE - 60)); WARN_AT=$((STOP_AT - 120)); QUIET_AT=$((STOP_AT - 120)) 511 fi 512 echo "lock_epoch $LOCK_EPOCH warn_at $WARN_AT stop_at $STOP_AT quiet_at $QUIET_AT cells $CELLSET" >> "$LOGD/session.log" 513 board "START $ARM $ROUND gpu lock held (<=60 min; test port $PORT; live 18091 untouched)" 514 echo "kthread_psr_start $(ktpsr)" >> "$LOGD/session.log" 515 pick_srv || notrun "core guard: $(cpu_guard || true)" 516 echo "server_cpus $SRV_CPUS client_cpus $CLI_CPUS monitor_cpu $MON_CPU" >> "$LOGD/session.log" 517 timeout 5 nvidia-smi --query-compute-apps=pid,name,used_memory --format=csv > "$LOGD/gpu-before.csv" 2>&1 || notrun "GPU process inventory failed" 518 GPU_ROWS=$(timeout 5 nvidia-smi --query-compute-apps=pid --format=csv,noheader,nounits) || notrun "GPU process inventory failed" 519 [ -z "$GPU_ROWS" ] || notrun "another model/process is resident; shared-service window must be coordinated before launch" 520 BASE=$(memavail); echo "baseline_memavail_kB $BASE" > "$LOGD/mem-baseline.txt" 521 sha256sum "$0" "$REPO/bench/bench.py" "$REPO/bench/arms.conf" "$REPO/bench/session-lifecycle.sh" \ 522 "$REPO/prompts/"*.jsonl > "$LOGD/driver-sha256.txt" 2>&1 523 case $ARM in 524 OURS) printf 'bin_dir %s\nsha256 %s\nAIEN_OMEGA_FP8_GROUPED_WAVE=%s\n' "$OURS_BIN_DIR" "$OURS_BIN_SHA256" "$OURS_WAVE" > "$LOGD/ours-bin.txt" ;; 525 VLLM*) docker image inspect -f '{{.Id}} {{json .RepoDigests}}' "$VLLM_IMG" > "$LOGD/image.txt" 2>&1 || notrun "vLLM image $VLLM_IMG not present locally" ;; 526 esac 527 sampler > "$LOGD/mem.tsv" & SAMP=$! 528 h2h_track "$SAMP" || exit 1 529 vmstat -t 1 > "$LOGD/vmstat.txt" & VMS=$! 530 h2h_track "$VMS" || exit 1 531 start_watchdog || exit 1 532 T0=$(date +%s.%N) 533 start_server || { board "$ARM $ROUND NOT_RUN: launch failed"; exit 4; } 534 if ready && loopback_only; then 535 echo "load_seconds $(echo "$(date +%s.%N) - $T0" | bc)" >> "$LOGD/session.log" 536 case $ARM in LLAMA*) LD_LIBRARY_PATH=$CUDART_DIR:$LLAMA_DIR "$LLAMA_DIR/llama-server" --version > "$LOGD/version.txt" 2>&1 ;; esac 537 [ -n "$CTR" ] && docker exec $CTR pip list 2>/dev/null | grep -i -E '^(vllm|sglang|torch|transformers|flashinfer)' > "$LOGD/version.txt" 538 EXPECTED_CELLS=0 539 for set in ${CELLSET//,/ }; do 540 [ -e "$LOGD/TIMEOUT" ] && break 541 SET0=$CELLS_COMPLETED 542 case $set in 543 full) 544 n=14 545 for c in 1 4 8 16; do 546 [ -e "$LOGD/TIMEOUT" ] && break 547 cell decode-c$c $c 256 decode.jsonl --warmup 2 --reps 3 || break 548 done 549 for p in p256 p2k p8k; do 550 [ $((CELLS_COMPLETED - SET0)) -ge 4 ] || break 551 [ -e "$LOGD/TIMEOUT" ] && break 552 cell prefill-$p 1 1 prefill.jsonl --select $p --warmup 2 --reps 3 --nonce || break 553 done 554 if [ $((CELLS_COMPLETED - SET0)) -eq 7 ] && [ ! -e "$LOGD/TIMEOUT" ]; then 555 cell agree 1 128 decode.jsonl --warmup 0 --reps 16 || true 556 fi 557 # A3 grid: N = 1, 8, 32 streams x prompt 512 / 8k tokens, 256 new tokens, 1 warmup + 3 runs 558 for p in p512 p8k; do 559 [ $((CELLS_COMPLETED - SET0)) -ge 8 ] || break 560 for n2 in 1 8 32; do 561 [ -e "$LOGD/TIMEOUT" ] && break 562 cell grid-$p-n$n2 $n2 256 prefill.jsonl --select $p --warmup 1 --reps 3 --nonce || break 2 563 done 564 done ;; 565 dra74) # A10: the DRA-74 decode ladder and prefill cells, one arm per chip slice 566 n=7 567 for c in 1 4 8 16; do 568 [ -e "$LOGD/TIMEOUT" ] && break 569 cell decode-c$c $c 256 decode.jsonl --warmup 2 --reps 3 || break 570 done 571 for p in p256 p2k p8k; do 572 [ $((CELLS_COMPLETED - SET0)) -ge 4 ] || break 573 [ -e "$LOGD/TIMEOUT" ] && break 574 cell prefill-$p 1 1 prefill.jsonl --select $p --warmup 2 --reps 3 --nonce || break 575 done ;; 576 nsys-c8) # A10: one profiled decode-c8 cell; its rows never enter timing results (extract.py) 577 n=1 578 if curl -sf -X POST "http://127.0.0.1:$PORT/start_profile" > /dev/null; then 579 cell decode-c8 8 256 decode.jsonl --warmup 1 --reps 1 || true 580 curl -sf -X POST "http://127.0.0.1:$PORT/stop_profile" > /dev/null || echo "$(ts) stop_profile failed" >> "$LOGD/session.log" 581 last=-1 582 for i in $(seq 1 36); do # the report is written after the range ends; wait for a stable size 583 sleep 5 584 size=$(cat "$LOGD"/nsys/*.nsys-rep 2>/dev/null | wc -c) 585 [ "$size" -gt 0 ] && [ "$size" = "$last" ] && break 586 last=$size 587 done 588 if [ "$size" -gt 0 ] && [ "$size" = "$last" ]; then echo "nsys_report_bytes $size" >> "$LOGD/session.log" 589 else echo "$(ts) nsys report missing or still growing after 180 s" >> "$LOGD/session.log"; CELLS_COMPLETED=$SET0; fi 590 else 591 echo "$(ts) start_profile failed; no profiled cell" >> "$LOGD/session.log" 592 fi ;; 593 ttft-fresh) # A10: fresh-prompt TTFT; per-rep nonce, byte-identical requests on every arm 594 n=$(echo ${TTFT_PROMPTS//,/ } | wc -w) 595 for p in ${TTFT_PROMPTS//,/ }; do 596 [ -e "$LOGD/TIMEOUT" ] && break 597 cell ttft-fresh-${p#t} 1 1 ttft.jsonl --select $p --ttft fresh --warmup 1 --warm-select t2k \ 598 --reps $TTFT_REPS --rep-base $TTFT_REP_BASE || break 599 done ;; 600 ttft-turn2) # A10: prime the 32k turn, then the conversation + ~1k new tokens; OURS re-reads it 601 n=1 602 case $ARM in OURS) t2=reread ;; *) t2=cached ;; esac 603 cell ttft-turn2-$t2 1 1 ttft.jsonl --select t32k --ttft turn2 --warmup 1 --warm-select t2k \ 604 --reps $TTFT_REPS --rep-base $TTFT_REP_BASE ;; 605 esac 606 EXPECTED_CELLS=$((EXPECTED_CELLS + n)) 607 [ $((CELLS_COMPLETED - SET0)) -eq "$n" ] || break # a short cell set ends the session INCOMPLETE 608 done 609 board "$ARM $ROUND cells done at $SECONDS s" 610 if mark_complete; then SESSION_RC=0; fi 611 else 612 if [ -s "$LOGD/listen.txt" ]; then why="FAIL: listener on port $PORT is not loopback-only (listen.txt); server stopped" 613 else why="server did not become ready (see results/logs/$ARM-$ROUND/server.log)"; fi 614 echo "$why" > "$LOGD/NOT_RUN" 615 board "$ARM $ROUND NOT_RUN: $why" 616 fi 617 exit "$SESSION_RC"