File size: 4,611 Bytes
314ecfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# Closed-loop coasting-horizon ablation: 1 s and 4 s arms next to the 2 s arm of chain_tracker_finetune.sh.
#   1. once the main chain has written its banks (detections cached in simlingo_data/tracker_dets), re-run
#      the tracker on CPU with max_coast_s = 1 and 4 -> simlingo_data/tracker_bank_coast{1,4}
#   2. wait for the main chain's three evals to finish (kills a CARLA whose worker log is idle > 30 min so
#      the evaluator's watchdog retries the route)
#   3. fine-tune stage 3 on each bank set (4 GPUs each, grad accumulation 2 -> global batch 128)
#   4. four 220-route evals, 6 slots each: coast1 x2, coast4 x2, TRACKER_COAST_S matching the banks
set -u
cd /workspace/code/ConsDrive_v2_eval
PY=/venv/fastvlm/bin/python
B=eval_results/Bench2Drive
MAIN_LOG=/tmp/chain_tracker_ft.log
log() { echo "[$(date '+%F %T')] $*"; }

# ---------------------------------------------------------------- 1. banks from cached detections
until grep -q "fine-tune ->" $MAIN_LOG 2>/dev/null; do
  grep -qE "failed|incomplete" $MAIN_LOG 2>/dev/null && { log "main chain failed"; exit 1; }
  sleep 60
done
n_det=$(find simlingo_data/tracker_dets -name dets.npz | wc -l)
log "cached detections: $n_det"
for c in 1 4; do
  for s in $(seq 0 23); do
    CUDA_VISIBLE_DEVICES= OMP_NUM_THREADS=1 $PY scripts/eval_tracker_offline.py --detector none \
      --out eval_results/tracker_offline/banks_coast$c --split all --shard $s/24 --reuse-detections \
      --write-banks --bank-folder tracker_bank_coast$c --max-coast-s $c --skip-existing \
      > eval_results/tracker_offline/banks_coast${c}_shard$s.log 2>&1 &
  done
  wait
  n=$(find simlingo_data/tracker_bank_coast$c -name objects.npz | wc -l)
  log "coast $c banks: $n / $n_det"
  [ "$n" -eq "$n_det" ] || { log "coast $c bank coverage incomplete"; exit 1; }
done

# ---------------------------------------------------------------- 2. wait for the main chain's evals
until grep -q "evals launched" $MAIN_LOG 2>/dev/null; do
  grep -qE "failed|incomplete" $MAIN_LOG 2>/dev/null && { log "main chain failed"; exit 1; }
  sleep 120
done
MAIN_EVALS="tracker_ft_det4hz_mask15 tracker_ft_det4hz_mask15_repeat speeddrop_det4hz_mask15_zeroshot"
all_done() {
  for r in $MAIN_EVALS; do
    [ "$(grep -l WORKER_EXIT $B/$r/logs/w*.log 2>/dev/null | wc -l)" -ge 16 ] || return 1
  done
}
until all_done; do
  now=$(date +%s)
  for r in $MAIN_EVALS; do
    for f in $B/$r/logs/w*.log; do
      [ -f "$f" ] || continue
      grep -q WORKER_EXIT "$f" && continue
      if [ $((now - $(stat -c %Y "$f"))) -gt 1800 ]; then
        w=$(basename "$f" .log)
        port=$(grep -oE -- "--port [0-9]+" $B/$r/scripts/run_$w.sh | awk '{print $2}')
        log "worker $r/$w idle > 30 min, killing CARLA on port $port"
        pkill -9 -f "carla-rpc-port=$port( |$)"
        touch "$f"
      fi
    done
  done
  sleep 300
done
log "main chain evals finished"

# ---------------------------------------------------------------- 3. fine-tunes (4 GPUs each, in parallel)
STAMP=$(date +%Y-%m-%d_%H-%M-%S)
declare -A FT
pids=()
for c in 1 4; do
  FT[$c]=outputs/fastvlm_stage3_tracker_coast$c/$STAMP
  gpus=$([ $c = 1 ] && echo 0,1,2,3 || echo 4,5,6,7)
  CUDA_VISIBLE_DEVICES=$gpus TRACKER_BANK_FOLDER=tracker_bank_coast$c CONFIG_NAME=fastvlm_stage3_tracker \
    OUTPUT_DIR=${FT[$c]} bash scripts/run_train_fastvlm_stage3.sh \
    trainer.devices=4 +trainer.accumulate_grad_batches=2 > /dev/null 2>&1 &
  pids+=($!)
done
rc=0
for p in "${pids[@]}"; do wait $p || rc=1; done
for c in 1 4; do
  ls ${FT[$c]}/checkpoints/epoch=*.ckpt > /dev/null 2>&1 || rc=1
  echo "TRAIN_EXIT=$rc" >> ${FT[$c]}/train.log
done
[ $rc -eq 0 ] || { log "a coast fine-tune failed"; exit 1; }
log "fine-tunes done: ${FT[1]} ${FT[4]}"

# ---------------------------------------------------------------- 4. evals
DET=/workspace/code/ConsDrive_v2_eval/outputs/detector/det_v1/last.pt
slots() {  # eval index k, slot count n (two workers per slot)
  local k=$1 n=$2 s="" j
  for ((j = 0; j < n; j++)); do s+="$(( (j + 2 * k) % 8 )):$(( (j + k) % 7 )) "; done
  echo "${s% }"
}
launch() {  # k run_dir name n_slots extra_env
  RUN_DIR=$2 RESULT_ROOT=$B/$3 SLOTS="$(slots $1 $4)" TAG=$3 \
    PORT_BASE=$((20000 + 2000 * $1)) TM_PORT_BASE=$((30000 + 2000 * $1)) EXTRA_ENV="$5" \
    bash scripts/run_full220_fastvlm.sh
}
k=0
for c in 1 4; do
  for rep in "" _repeat; do
    launch $k ${FT[$c]} tracker_ft_coast${c}_det4hz_mask15$rep 6 \
      "OBJECT_SOURCE=detector DETECTOR_CKPT=$DET DETECTOR_UPDATE_EVERY=5 SPEED_MASK_STALL_S=15 TRACKER_COAST_S=$c"
    k=$((k + 1))
  done
done
log "coast evals launched"