Skip to content

Commit dbaa4f7

Browse files
joaclaude
andcommitted
vastai: A deep prompt's time per flash shape and per kernel, against llama.cpp
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013RsvdtnrmKHFtgKKXaXTjJ
1 parent 98addff commit dbaa4f7

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎VASTAI.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ Each card's files go to `results/platforms/<card>/` beside a `card.json`, with
204204
150 W for two seconds after a process exits, which `bench.py`'s between-round
205205
check reads as another tenant; pass `--max-idle-power 200` after `REF` there.
206206

207+
A card can also run slow without a tenant. A rented RTX 4090 ran its whole
208+
platform run at 65% of its maximum clock, held there by heat. Phobos's 32k
209+
prompts lost twice as much there as llama.cpp's, so its row read 0.67x where
210+
a healthy 4090 reads 0.88x. `bench.py` reports the clock under load as a share
211+
of the card's maximum, with how often the driver slowed the card for heat or
212+
held it at its power limit, and warns below `--min-clock-share` (0.75). A
213+
warning means the host, not the card: rent another before publishing.
214+
215+
### Where a deep prompt's time goes
216+
217+
`scripts/vastai/deepprompt.sh REF [SHAPE...]` measures Qwen3.5-4B Q4_K_M at
218+
pp512 and pp32768 once per flash attention shape (`PHOBOS_ATTN_FLASH_SHAPE`,
219+
with `default` for the chip's own), then llama.cpp, then one 32k pass of each
220+
engine under nsys with its kernels summed. It wants `build.sh` beside it and
221+
the devel image; nsys comes from the image's NVIDIA apt repository. llama.cpp's
222+
profile includes its warmup pass, a whole prompt, so halve its sums.
223+
224+
```powershell
225+
scp -P PORT scripts/vastai/gate.sh scripts/vastai/deepprompt.sh scripts/vastai/build.sh root@HOST:/root/
226+
ssh -p PORT root@HOST "nohup bash /root/deepprompt.sh REF > /root/deep.out 2>&1 < /dev/null &"
227+
```
228+
207229
### Profiling without ncu
208230

209231
`ncu` fails on these hosts with `ERR_NVGPUCTRPERM`: the container gets no

‎scripts/vastai/deepprompt.sh‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)