scripts/run_llm_single_model_matrix_host.sh
scripts/run_llm_single_model_matrix_host.shBrowse 18 files
3,097 tokens
9,647 bytes
Token encoding: o200k_base
Snapshot a9fb1c3
← Back to SKILL.md
1#!/usr/bin/env bash2set -euo pipefail3 4usage() {5 cat <<'EOF'6Usage:7 run_llm_single_model_matrix_host.sh \8 --model-id gpt_oss_20b \9 --model openai/gpt-oss-20b \10 --root /data/bbuf/validate/unified_llm_profiler_skill/runs/20260423_h100_large_model_matrix \11 --gpus 2,3,4,5 \12 --sglang-port 30098 \13 --vllm-formal-port 31098 \14 --vllm-mapping-port 31099 \15 --trt-formal-prefill-port 32098 \16 --trt-formal-decode-port 32099 \17 --trt-mapping-prefill-port 32198 \18 --trt-mapping-decode-port 3219919 20This script is intended to run on the H100 host. It:211. captures SGLang live profiling and writes `analysis_sglang.txt`222. captures vLLM formal + eager mapping traces and writes `analysis_vllm.txt`233. captures TensorRT-LLM formal + graph-off mapping traces and writes `analysis_trtllm.txt`244. stores one benchmark JSON per framework under the model run directory25 26Default profiler workloads are stage-separated:27 prefill: input 4090, output 128 decode: input 1, output 204829 30Environment:31 Export `HF_TOKEN` and `HUGGINGFACE_HUB_TOKEN` before running.32EOF33}34 35MODEL_ID=""36MODEL=""37ROOT=""38GPUS=""39TP_SIZE=""40SGLANG_PORT=""41VLLM_FORMAL_PORT=""42VLLM_MAPPING_PORT=""43TRT_FORMAL_PREFILL_PORT=""44TRT_FORMAL_DECODE_PORT=""45TRT_MAPPING_PREFILL_PORT=""46TRT_MAPPING_DECODE_PORT=""47SGLANG_MEM_FRACTION="0.85"48MAX_MODEL_LEN="4096"49KV_FRACTION="0.85"50SGLANG_SERVER_EXTRA=""51PROFILE_WORKLOAD="both"52PREFILL_INPUT_LEN=409053PREFILL_OUTPUT_LEN=154DECODE_INPUT_LEN=155DECODE_OUTPUT_LEN=204856SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"57TRT_IMAGE="nvcr.io/nvidia/tensorrt-llm/release:latest"58TRT_OVERRIDE_ROOT="/data/bbuf/validate/unified_llm_profiler_skill/overrides/trtllm"59TRT_OVERRIDE_SOURCE="$TRT_OVERRIDE_ROOT/py_executor.original.py"60TRT_OVERRIDE_PATH="$TRT_OVERRIDE_ROOT/py_executor_with_stack.py"61 62while [[ $# -gt 0 ]]; do63 case "$1" in64 --model-id) MODEL_ID="$2"; shift 2 ;;65 --model) MODEL="$2"; shift 2 ;;66 --root) ROOT="$2"; shift 2 ;;67 --gpus) GPUS="$2"; shift 2 ;;68 --tp-size) TP_SIZE="$2"; shift 2 ;;69 --sglang-port) SGLANG_PORT="$2"; shift 2 ;;70 --vllm-formal-port) VLLM_FORMAL_PORT="$2"; shift 2 ;;71 --vllm-mapping-port) VLLM_MAPPING_PORT="$2"; shift 2 ;;72 --trt-formal-prefill-port) TRT_FORMAL_PREFILL_PORT="$2"; shift 2 ;;73 --trt-formal-decode-port) TRT_FORMAL_DECODE_PORT="$2"; shift 2 ;;74 --trt-mapping-prefill-port) TRT_MAPPING_PREFILL_PORT="$2"; shift 2 ;;75 --trt-mapping-decode-port) TRT_MAPPING_DECODE_PORT="$2"; shift 2 ;;76 --sglang-mem-fraction) SGLANG_MEM_FRACTION="$2"; shift 2 ;;77 --sglang-server-extra) SGLANG_SERVER_EXTRA="$2"; shift 2 ;;78 --max-model-len) MAX_MODEL_LEN="$2"; shift 2 ;;79 --kv-fraction) KV_FRACTION="$2"; shift 2 ;;80 --profile-workload) PROFILE_WORKLOAD="$2"; shift 2 ;;81 --prefill-input-len) PREFILL_INPUT_LEN="$2"; shift 2 ;;82 --prefill-output-len) PREFILL_OUTPUT_LEN="$2"; shift 2 ;;83 --decode-input-len) DECODE_INPUT_LEN="$2"; shift 2 ;;84 --decode-output-len) DECODE_OUTPUT_LEN="$2"; shift 2 ;;85 --help|-h) usage; exit 0 ;;86 *)87 echo "Unknown argument: $1" >&288 usage >&289 exit 290 ;;91 esac92done93 94if [[ -z "${HF_TOKEN:-}" && -z "${HUGGINGFACE_HUB_TOKEN:-}" ]]; then95 echo "Set HF_TOKEN or HUGGINGFACE_HUB_TOKEN before running." >&296 exit 297fi98if [[ -z "${HF_TOKEN:-}" ]]; then99 HF_TOKEN="$HUGGINGFACE_HUB_TOKEN"100fi101if [[ -z "${HUGGINGFACE_HUB_TOKEN:-}" ]]; then102 HUGGINGFACE_HUB_TOKEN="$HF_TOKEN"103fi104 105for value in \106 MODEL_ID MODEL ROOT GPUS \107 SGLANG_PORT VLLM_FORMAL_PORT VLLM_MAPPING_PORT \108 TRT_FORMAL_PREFILL_PORT TRT_FORMAL_DECODE_PORT \109 TRT_MAPPING_PREFILL_PORT TRT_MAPPING_DECODE_PORT; do110 if [[ -z "${!value}" ]]; then111 echo "Missing required argument: $value" >&2112 usage >&2113 exit 2114 fi115done116 117IFS=',' read -r -a GPU_LIST <<< "$GPUS"118GPU_COUNT="${#GPU_LIST[@]}"119if [[ "$GPU_COUNT" -lt 1 ]]; then120 echo "Could not parse --gpus: $GPUS" >&2121 exit 2122fi123if [[ -z "$TP_SIZE" ]]; then124 TP_SIZE="$GPU_COUNT"125fi126if (( TP_SIZE < 1 || TP_SIZE > GPU_COUNT )); then127 echo "--tp-size must be between 1 and the visible GPU count ($GPU_COUNT)." >&2128 exit 2129fi130 131MODEL_ROOT="$ROOT/$MODEL_ID"132SGLANG_ANALYSIS="$MODEL_ROOT/analysis_sglang.txt"133VLLM_FORMAL_DIR="$MODEL_ROOT/vllm_formal"134VLLM_MAPPING_DIR="$MODEL_ROOT/vllm_mapping"135VLLM_ANALYSIS="$MODEL_ROOT/analysis_vllm.txt"136TRT_FORMAL_DIR="$MODEL_ROOT/trtllm_formal"137TRT_MAPPING_DIR="$MODEL_ROOT/trtllm_mapping"138TRT_ANALYSIS="$MODEL_ROOT/analysis_trtllm.txt"139 140docker exec sglang_bbuf bash -lc "mkdir -p '$MODEL_ROOT'"141 142if [[ ! -s "$TRT_OVERRIDE_SOURCE" ]]; then143 echo "[bootstrap] TensorRT-LLM py_executor source snapshot"144 docker exec sglang_bbuf bash -lc "mkdir -p '$TRT_OVERRIDE_ROOT'"145 docker run --rm --entrypoint cat "$TRT_IMAGE" \146 /usr/local/lib/python3.12/dist-packages/tensorrt_llm/_torch/pyexecutor/py_executor.py \147 | docker exec -i sglang_bbuf bash -lc "cat > '$TRT_OVERRIDE_SOURCE'"148fi149echo "[bootstrap] TensorRT-LLM py_executor override with with_stack=True and rank0-only trace export"150docker exec sglang_bbuf bash -lc "cd '$SCRIPT_DIR' && python3 make_trtllm_py_executor_override.py --source '$TRT_OVERRIDE_SOURCE' --output '$TRT_OVERRIDE_PATH'"151 152sglang_args=(153 --model "$MODEL"154 --run-dir "$MODEL_ROOT"155 --port "$SGLANG_PORT"156 --gpus "$GPUS"157 --tp-size "$TP_SIZE"158 --mem-fraction "$SGLANG_MEM_FRACTION"159 --profile-workload "$PROFILE_WORKLOAD"160 --prefill-input-len "$PREFILL_INPUT_LEN"161 --prefill-output-len "$PREFILL_OUTPUT_LEN"162 --decode-input-len "$DECODE_INPUT_LEN"163 --decode-output-len "$DECODE_OUTPUT_LEN"164 --trust-remote-code165)166if [[ -n "$SGLANG_SERVER_EXTRA" ]]; then167 sglang_args+=(--server-extra "$SGLANG_SERVER_EXTRA")168fi169 170echo "[1/6] SGLang server + live triage"171HF_TOKEN="$HF_TOKEN" HUGGINGFACE_HUB_TOKEN="$HUGGINGFACE_HUB_TOKEN" \172 "$SCRIPT_DIR/run_sglang_torch_profile_host.sh" \173 "${sglang_args[@]}"174 175echo "[2/6] vLLM formal"176HF_TOKEN="$HF_TOKEN" HUGGINGFACE_HUB_TOKEN="$HUGGINGFACE_HUB_TOKEN" \177 "$SCRIPT_DIR/run_vllm_torch_profile_host.sh" \178 --model "$MODEL" \179 --run-dir "$VLLM_FORMAL_DIR" \180 --port "$VLLM_FORMAL_PORT" \181 --gpus "$GPUS" \182 --tensor-parallel-size "$TP_SIZE" \183 --max-model-len "$MAX_MODEL_LEN" \184 --profile-workload "$PROFILE_WORKLOAD" \185 --prefill-input-len "$PREFILL_INPUT_LEN" \186 --prefill-output-len "$PREFILL_OUTPUT_LEN" \187 --decode-input-len "$DECODE_INPUT_LEN" \188 --decode-output-len "$DECODE_OUTPUT_LEN" \189 --trust-remote-code190 191echo "[3/6] vLLM mapping"192HF_TOKEN="$HF_TOKEN" HUGGINGFACE_HUB_TOKEN="$HUGGINGFACE_HUB_TOKEN" \193 "$SCRIPT_DIR/run_vllm_torch_profile_host.sh" \194 --model "$MODEL" \195 --run-dir "$VLLM_MAPPING_DIR" \196 --port "$VLLM_MAPPING_PORT" \197 --gpus "$GPUS" \198 --tensor-parallel-size "$TP_SIZE" \199 --profiler-active-iterations 2 \200 --max-model-len "$MAX_MODEL_LEN" \201 --profile-workload "$PROFILE_WORKLOAD" \202 --prefill-input-len "$PREFILL_INPUT_LEN" \203 --prefill-output-len "$PREFILL_OUTPUT_LEN" \204 --decode-input-len "$DECODE_INPUT_LEN" \205 --decode-output-len "$DECODE_OUTPUT_LEN" \206 --trust-remote-code \207 --enforce-eager208 209echo "[4/6] vLLM mapping-formal analysis"210docker exec sglang_bbuf bash -lc "cd '$SCRIPT_DIR' && python3 analyze_llm_torch_profile.py --framework vllm --mapping-input '$VLLM_MAPPING_DIR' --formal-input '$VLLM_FORMAL_DIR' > '$VLLM_ANALYSIS'"211 212echo "[5/6] TensorRT-LLM formal + mapping captures"213HF_TOKEN="$HF_TOKEN" HUGGINGFACE_HUB_TOKEN="$HUGGINGFACE_HUB_TOKEN" \214 "$SCRIPT_DIR/run_trtllm_pytorch_profile_host.sh" \215 --model "$MODEL" \216 --run-dir "$TRT_FORMAL_DIR" \217 --stage prefill \218 --port "$TRT_FORMAL_PREFILL_PORT" \219 --gpus "$GPUS" \220 --tp-size "$TP_SIZE" \221 --kv-fraction "$KV_FRACTION" \222 --input-len "$PREFILL_INPUT_LEN" \223 --output-len "$PREFILL_OUTPUT_LEN" \224 --override-py-executor "$TRT_OVERRIDE_PATH" \225 --trust-remote-code226HF_TOKEN="$HF_TOKEN" HUGGINGFACE_HUB_TOKEN="$HUGGINGFACE_HUB_TOKEN" \227 "$SCRIPT_DIR/run_trtllm_pytorch_profile_host.sh" \228 --model "$MODEL" \229 --run-dir "$TRT_FORMAL_DIR" \230 --stage decode \231 --port "$TRT_FORMAL_DECODE_PORT" \232 --gpus "$GPUS" \233 --tp-size "$TP_SIZE" \234 --kv-fraction "$KV_FRACTION" \235 --input-len "$DECODE_INPUT_LEN" \236 --output-len "$DECODE_OUTPUT_LEN" \237 --override-py-executor "$TRT_OVERRIDE_PATH" \238 --trust-remote-code239HF_TOKEN="$HF_TOKEN" HUGGINGFACE_HUB_TOKEN="$HUGGINGFACE_HUB_TOKEN" \240 "$SCRIPT_DIR/run_trtllm_pytorch_profile_host.sh" \241 --model "$MODEL" \242 --run-dir "$TRT_MAPPING_DIR" \243 --stage prefill \244 --port "$TRT_MAPPING_PREFILL_PORT" \245 --gpus "$GPUS" \246 --tp-size "$TP_SIZE" \247 --kv-fraction "$KV_FRACTION" \248 --input-len "$PREFILL_INPUT_LEN" \249 --output-len "$PREFILL_OUTPUT_LEN" \250 --override-py-executor "$TRT_OVERRIDE_PATH" \251 --disable-cudagraph \252 --trust-remote-code253HF_TOKEN="$HF_TOKEN" HUGGINGFACE_HUB_TOKEN="$HUGGINGFACE_HUB_TOKEN" \254 "$SCRIPT_DIR/run_trtllm_pytorch_profile_host.sh" \255 --model "$MODEL" \256 --run-dir "$TRT_MAPPING_DIR" \257 --stage decode \258 --port "$TRT_MAPPING_DECODE_PORT" \259 --gpus "$GPUS" \260 --tp-size "$TP_SIZE" \261 --kv-fraction "$KV_FRACTION" \262 --input-len "$DECODE_INPUT_LEN" \263 --output-len "$DECODE_OUTPUT_LEN" \264 --override-py-executor "$TRT_OVERRIDE_PATH" \265 --disable-cudagraph \266 --trust-remote-code267 268echo "[6/6] TensorRT-LLM mapping-formal analysis"269docker exec sglang_bbuf bash -lc "cd '$SCRIPT_DIR' && python3 analyze_llm_torch_profile.py --framework trtllm --mapping-input '$TRT_MAPPING_DIR' --formal-input '$TRT_FORMAL_DIR' > '$TRT_ANALYSIS'"270 271echo "MODEL_ROOT=$MODEL_ROOT"272echo "ANALYSIS_SGLANG=$SGLANG_ANALYSIS"273echo "ANALYSIS_VLLM=$VLLM_ANALYSIS"274echo "ANALYSIS_TRTLLM=$TRT_ANALYSIS"275