|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Where a deep prompt's time goes on one rented card: Phobos built from REF |
| 3 | +# and llama.cpp on Qwen3.5-4B Q4_K_M at pp512 and pp32768, Phobos once per |
| 4 | +# flash attention shape (PHOBOS_ATTN_FLASH_SHAPE), then one 32k pass of each |
| 5 | +# engine under nsys, its kernels summed. Wants /root/build.sh beside it and the |
| 6 | +# devel image. Run it under nohup; /root/results/STAGE says which stage runs. |
| 7 | +# |
| 8 | +# bash deepprompt.sh REF [SHAPE...] |
| 9 | +set -uo pipefail |
| 10 | +REF="${1:?usage: deepprompt.sh REF [SHAPE...]}" |
| 11 | +shift |
| 12 | +SHAPES=(default streamed16 resident16 resident32 resident16p resident32p) |
| 13 | +[ $# -gt 0 ] && SHAPES=("$@") |
| 14 | +OUT=/root/results; W=/root/bench; LLAMA="${LLAMA:-b11681}" |
| 15 | +mkdir -p "$OUT" "$W/models" |
| 16 | +stage() { echo "$1 $(date +%T)" | tee -a "$OUT/STAGE"; } |
| 17 | +fetch() { |
| 18 | + cd "$W" |
| 19 | + base=https://github.com/ggml-org/llama.cpp/releases/download/$LLAMA |
| 20 | + curl -sSfL "$base/llama-$LLAMA-bin-ubuntu-cuda-12.8-x64.tar.gz" | tar -xz && mv "llama-$LLAMA" llama |
| 21 | + curl -sSfL "$base/cudart-llama-$LLAMA-bin-ubuntu-cuda-12.8-x64.tar.gz" | tar -xz --strip-components=1 -C llama |
| 22 | + f=Qwen3.5-4B-Q4_K_M.gguf |
| 23 | + until curl -sSfL -C - -o "models/$f.part" "https://huggingface.co/unsloth/Qwen3.5-4B-GGUF/resolve/main/$f"; do sleep 2; done |
| 24 | + mv "models/$f.part" "models/$f"; sha256sum "models/$f" |
| 25 | +} |
| 26 | +stage apt |
| 27 | +apt-get update -qq && apt-get install -y -qq python3 curl ca-certificates libgomp1 build-essential git pkg-config libclang-dev libzstd-dev zlib1g-dev cuda-nsight-systems-12-8 > "$OUT/apt.log" 2>&1 || { stage APT-FAILED; exit 1; } |
| 28 | +stage fetch+build |
| 29 | +fetch > "$OUT/fetch.log" 2>&1 & |
| 30 | +FETCH=$! |
| 31 | +bash /root/build.sh "$REF" > "$OUT/build.log" 2>&1 || { stage BUILD-FAILED; exit 1; } |
| 32 | +wait $FETCH || { stage FETCH-FAILED; exit 1; } |
| 33 | +BIN=/root/src/target/release |
| 34 | +M="$W/models/Qwen3.5-4B-Q4_K_M.gguf" |
| 35 | +NSYS=$(ls /opt/nvidia/nsight-systems/*/bin/nsys /usr/local/cuda/bin/nsys 2>/dev/null | head -1) |
| 36 | +"$BIN/phobos-bench" --version > "$OUT/version.txt" |
| 37 | +nvidia-smi --query-gpu=name,driver_version,power.limit,clocks.max.sm --format=csv > "$OUT/card.txt" |
| 38 | +for shape in "${SHAPES[@]}"; do |
| 39 | + stage "shape-$shape" |
| 40 | + if [ "$shape" = default ]; then unset PHOBOS_ATTN_FLASH_SHAPE; else export PHOBOS_ATTN_FLASH_SHAPE=$shape; fi |
| 41 | + # A first pass compiles this shape's kernels outside the timed one. |
| 42 | + "$BIN/phobos-bench" -m "$M" -p 32768 -n 0 -r 1 > /dev/null 2>&1 |
| 43 | + "$BIN/phobos-bench" -m "$M" -p 512,32768 -n 0 -r 3 > "$OUT/phobos-$shape.log" 2>&1 || stage "SHAPE-$shape-FAILED" |
| 44 | +done |
| 45 | +unset PHOBOS_ATTN_FLASH_SHAPE |
| 46 | +stage llama |
| 47 | +"$W/llama/llama-bench" -m "$M" -p 512,32768 -n 0 -r 3 > "$OUT/llama.log" 2>&1 || stage LLAMA-FAILED |
| 48 | +stage nsys |
| 49 | +if [ -n "$NSYS" ]; then |
| 50 | + "$NSYS" profile -t cuda --cuda-graph-trace=node -o "$OUT/phobos-32k" -f true "$BIN/phobos-bench" -m "$M" -p 32768 -n 0 -r 1 > "$OUT/nsys-phobos.log" 2>&1 |
| 51 | + "$NSYS" stats -q --report cuda_gpu_kern_sum --format csv -o "$OUT/phobos-32k" "$OUT/phobos-32k.nsys-rep" >> "$OUT/nsys-phobos.log" 2>&1 |
| 52 | + "$NSYS" profile -t cuda --cuda-graph-trace=node -o "$OUT/llama-32k" -f true "$W/llama/llama-bench" -m "$M" -p 32768 -n 0 -r 1 > "$OUT/nsys-llama.log" 2>&1 |
| 53 | + "$NSYS" stats -q --report cuda_gpu_kern_sum --format csv -o "$OUT/llama-32k" "$OUT/llama-32k.nsys-rep" >> "$OUT/nsys-llama.log" 2>&1 |
| 54 | +else |
| 55 | + stage NO-NSYS |
| 56 | +fi |
| 57 | +stage DONE |
0 commit comments