profile_decode.sh 1.3 KB

1234567891011121314151617
  1. #!/usr/bin/env bash
  2. # Profile N decode steps of the running server with torch.profiler and pull the
  3. # rank-0 trace out of the head container. Analyse it on a worker, never on the
  4. # head (the head has ~6 GB free while serving; json.load of a trace wants more).
  5. # ./scripts/profile/profile_decode.sh 45 /tmp/prof # start + wait
  6. # python3 scripts/profile/analyze_steps.py trace.json.gz [step] # per-step budget
  7. # python3 scripts/profile/analyze_trace.py trace.json.gz # kernel table, gaps
  8. # python3 scripts/profile/engram_wait.py trace.json.gz # Engram all-reduce wait
  9. set -euo pipefail
  10. STEPS="${1:-45}"; DIR="${2:-/tmp/prof}"; PORT="${PORT:-8888}"; CTN="${HEAD_CTN:-dsv41-head}"
  11. L0=$(docker logs "$CTN" 2>&1 | wc -l)
  12. curl -s -m 20 -X POST "localhost:$PORT/start_profile" -H 'Content-Type: application/json' \
  13. -d "{\"output_dir\":\"$DIR\",\"num_steps\":$STEPS,\"activities\":[\"CPU\",\"GPU\"],\"with_stack\":false,\"record_shapes\":false}"; echo
  14. echo "profiling armed: send ONE request now (e.g. 300 tokens from a worker); waiting for 'Profiling done'..."
  15. for _ in $(seq 1 120); do docker logs "$CTN" 2>&1 | tail -n +$((L0+1)) | grep -q "Profiling done" && break; sleep 3; done
  16. f=$(docker exec "$CTN" ls "$DIR" | head -1)
  17. docker cp "$CTN:$DIR/$f" "./${f}" && echo "trace: ./$f (rank 0; workers keep theirs in $DIR inside dsv41-worker)"