File size: 5,081 Bytes
778d47d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#SBATCH --job-name=vl
#SBATCH --partition=gpu-large
#SBATCH --qos=batch-long
#SBATCH --gres=gpu:1
#SBATCH --cpus-per-task=2
#SBATCH --mem=64G
#SBATCH --time=06:00:00
#SBATCH --output=/weka/s225250685/mats-tist/slurm_logs/fixer_v2_%j.out

set -u
cd /weka/s225250685/mats-tist

export HF_HOME=/weka/s225250685/Huggingface
export HF_HUB_CACHE=/weka/s225250685/Huggingface/hub
export DB_EXEC_API_DISABLE=1
export PYTHONNOUSERSITE=1
export NO_PROXY=localhost,127.0.0.1
export PYTHONPATH=/weka/s225250685/mats-tist
export TOKENIZERS_PARALLELISM=false

PY=/weka/s225250685/conda-envs/handbook/bin/python
VLLM=/weka/s225250685/conda-envs/handbook/bin/vllm
PLANNER=/weka/s225250685/mats-tist/alignment-handbook/output/planner-iter2-collab-3B
V_SEL=/weka/s225250685/mats-tist/alignment-handbook/output/validator-selection-0.5B-v3
V_COND=/weka/s225250685/mats-tist/alignment-handbook/output/validator-condition-0.6B-v3
FIXER_V2=/weka/s225250685/mats-tist/alignment-handbook/output/fixer-v2-1.5B-execerr-sft
SEL_V2=/weka/s225250685/mats-tist/alignment-handbook/output/selector-3B-v2-rows

LOG=/weka/s225250685/mats-tist/slurm_logs/fixer_v2_${SLURM_JOB_ID}.log
: > "$LOG"

nvidia-smi --query-gpu=name,memory.total --format=csv,noheader | tee -a "$LOG"

kill_vllm() {
    pkill -9 -f "vllm serve" 2>/dev/null || true
    pkill -9 -f "VLLM::EngineCore" 2>/dev/null || true
    sleep 5
}
trap kill_vllm EXIT

wait_url() {
    for i in {1..180}; do
        curl --noproxy '*' -fs "$1" >/dev/null 2>&1 && return 0
        sleep 5
    done
    return 1
}

##############################################
# STAGE A: train fixer v2 (1B, exec-err SFT)
##############################################
echo "==== [A] training fixer v2 (Qwen2.5-Coder-1B, exec-err targeted) ====" | tee -a "$LOG"
$PY scripts/train_fixer_v2.py 2>&1 | tee -a "$LOG"

if [ ! -f "$FIXER_V2/config.json" ]; then
    echo "FIXER V2 TRAIN FAILED" | tee -a "$LOG"; exit 1
fi
echo "==== [A] fixer v2 saved at $FIXER_V2 ====" | tee -a "$LOG"

##############################################
# STAGE B: 3-stage K=8 rollout with fixer v2 + gate
#   Planner 3B + v_s 0.5B + v_c 0.6B + FIXER_V2 1B (gated)
##############################################
kill_vllm
echo "==== [B] launching endpoints (planner+v_s+v_c+fixer_v2) ====" | tee -a "$LOG"

$VLLM serve "$PLANNER" --served-model-name planner --port 8100 --dtype bfloat16 \
    --gpu-memory-utilization 0.35 --enforce-eager --max-model-len 8192 > "${LOG}.p" 2>&1 &
wait_url http://localhost:8100/v1/models && echo "  planner READY" | tee -a "$LOG"

$VLLM serve "$V_SEL" --served-model-name validator_sel --port 8101 --dtype bfloat16 \
    --gpu-memory-utilization 0.10 --enforce-eager --max-model-len 5120 > "${LOG}.vs" 2>&1 &
wait_url http://localhost:8101/v1/models && echo "  v_s READY" | tee -a "$LOG"

$VLLM serve "$V_COND" --served-model-name validator_cond --port 8104 --dtype bfloat16 \
    --gpu-memory-utilization 0.10 --enforce-eager --max-model-len 5120 > "${LOG}.vc" 2>&1 &
wait_url http://localhost:8104/v1/models && echo "  v_c READY" | tee -a "$LOG"

$VLLM serve "$FIXER_V2" --served-model-name fixer --port 8102 --dtype bfloat16 \
    --gpu-memory-utilization 0.20 --enforce-eager --max-model-len 4096 > "${LOG}.f" 2>&1 &
wait_url http://localhost:8102/v1/models && echo "  fixer_v2 READY" | tee -a "$LOG"

OUT_GATED=eval_results/scaleup_BoN8_d_K8_3stage_planner_iter2_mixedtemp_vsel_vcond_fixerv2_gated_bird_dev.jsonl
rm -f "$OUT_GATED"

echo "==== [B] K=8 3-stage + fixer_v2 + gate (mixed-temp 0.5/0.7/0.9/1.1) ====" | tee -a "$LOG"
$PY scripts/run_pipeline_rollouts.py \
    --input_file data/sft_bird_with_evidence_dev_text2sql.json \
    --output_file "$OUT_GATED" \
    --planner_host http://localhost:8100 \
    --validator_host none \
    --validator_sel_host http://localhost:8101 \
    --validator_cond_host http://localhost:8104 \
    --fixer_host http://localhost:8102 \
    --fixer_gate_exec_ok \
    --K 8 --K_val 1 --K_fix 1 \
    --mixed_temp "0.5,0.7,0.9,1.1" --top_p 0.9 \
    --max_planner_tokens 1024 --max_validator_tokens 384 --max_fixer_tokens 512 \
    --max_questions -1 --n_threads 4 2>&1 | tee -a "$LOG"

echo "==== [B] metrics (oracle, greedy, majority) ====" | tee -a "$LOG"
$PY scripts/compute_bestofn_metrics.py "$OUT_GATED" K8_3stage_fixerv2_gated 2>&1 | tee -a "$LOG"

##############################################
# STAGE C: apply selector v2 to new rollout
##############################################
kill_vllm
echo "==== [C] launching selector v2 ====" | tee -a "$LOG"
$VLLM serve "$SEL_V2" --served-model-name selector --port 8103 --dtype bfloat16 \
    --gpu-memory-utilization 0.85 --enforce-eager --max-model-len 8192 > "${LOG}.sel" 2>&1 &
wait_url http://localhost:8103/v1/models && echo "  selector READY" | tee -a "$LOG"

label="$(basename $OUT_GATED .jsonl)_selectorV2rows"
echo "==== [C] $label ====" | tee -a "$LOG"
$PY scripts/compute_bestofn_with_selector.py \
    "$OUT_GATED" "$label" --selector_host http://localhost:8103 --row_preview 2>&1 | tee -a "$LOG"

echo "==== ALL_DONE ====" | tee -a "$LOG"