File size: 3,537 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
#!/bin/bash
# Phase F: Best-of-N + selector eval (production inference protocol).
# For each of (a)/(b)/(b')/(d) configs, run K=8 planner sampling + 1 validator + 1 fixer
# per planner candidate, then compute three metrics:
#   - greedy:  EX of the first (K=1) trajectory (matches earlier K=1 numbers)
#   - pass@8:  EX if ANY of the 8 candidates is correct (oracle upper bound)
#   - selector-majority: EX of the SQL whose execution result is the most common non-empty result
#                        among executable candidates (rule-based selector, no extra model needed)

set -e
cd /home/datht/mats-sql-tist

EVAL_INPUT=data/sft_bird_with_evidence_dev_text2sql.json
[ ! -f "$EVAL_INPUT" ] && EVAL_INPUT=data/sft_bird_dev_with_evidence_text2sql_new.json

P_SFT=alignment-handbook/output/qwen-coder0.5b-bird-planner-collab-sft
V_SFT=alignment-handbook/output/qwen-coder0.5b-bird-validator-sft
F_SFT=alignment-handbook/output/qwen-coder0.5b-bird-fixer-sft
P_INDEP=alignment-handbook/output/qwen-coder0.5b-bird-planner-INDEP-orpo
P_COLLAB=alignment-handbook/output/qwen-coder0.5b-bird-planner-COLLAB-orpo
F_ORPO=alignment-handbook/output/qwen-coder0.5b-bird-fixer-orpo

VLLM=/home/datht/anaconda3/envs/llm/bin/vllm

run_eval_bestof8() {
    local LABEL=$1 P_CKPT=$2 V_CKPT=$3 F_CKPT=$4
    echo ""
    echo "================================================="
    echo "=== EVAL $LABEL (best-of-8 + selector) ==="
    echo "  planner=$P_CKPT"
    echo "  validator=$V_CKPT"
    echo "  fixer=$F_CKPT"
    echo "================================================="

    pkill -f "vllm serve" 2>/dev/null || true
    sleep 6

    CUDA_VISIBLE_DEVICES=0 $VLLM serve "$P_CKPT" \
        --served-model-name planner --port 8100 --dtype bfloat16 \
        --gpu-memory-utilization 0.45 --max-model-len 8192 \
        > /tmp/collab_eval_p.log 2>&1 &
    CUDA_VISIBLE_DEVICES=1 $VLLM serve "$V_CKPT" \
        --served-model-name validator --port 8101 --dtype bfloat16 \
        --gpu-memory-utilization 0.42 --max-model-len 8192 \
        > /tmp/collab_eval_v.log 2>&1 &
    CUDA_VISIBLE_DEVICES=1 $VLLM serve "$F_CKPT" \
        --served-model-name fixer --port 8102 --dtype bfloat16 \
        --gpu-memory-utilization 0.42 --max-model-len 8192 \
        > /tmp/collab_eval_f.log 2>&1 &

    for url in http://localhost:8100/v1/models http://localhost:8101/v1/models http://localhost:8102/v1/models; do
        for i in {1..120}; do
            curl --noproxy localhost -fs $url >/dev/null 2>&1 && break
            sleep 5
        done
    done

    OUT=eval_results/collab_BoN8_${LABEL}_bird_dev.jsonl
    PYTHONPATH=. /home/datht/anaconda3/envs/mats/bin/python scripts/run_pipeline_rollouts.py \
        --input_file "$EVAL_INPUT" \
        --output_file "$OUT" \
        --planner_host http://localhost:8100 \
        --validator_host http://localhost:8101 \
        --fixer_host http://localhost:8102 \
        --K 8 --K_val 1 --K_fix 1 --temperature 0.7 --top_p 0.9 \
        --max_questions -1 --n_threads 8

    # Compute the three metrics from the rollout JSONL
    /home/datht/anaconda3/envs/mats/bin/python scripts/compute_bestofn_metrics.py "$OUT" "$LABEL"
}

run_eval_bestof8 a_sft_only      "$P_SFT"     "$V_SFT" "$F_SFT"
run_eval_bestof8 b_planner_indep "$P_INDEP"   "$V_SFT" "$F_SFT"
run_eval_bestof8 b_prime_planner_indep_with_fixer_orpo "$P_INDEP" "$V_SFT" "$F_ORPO"
run_eval_bestof8 d_planner_collab_with_fixer_orpo      "$P_COLLAB" "$V_SFT" "$F_ORPO"

pkill -f "vllm serve" 2>/dev/null || true
echo "DONE_COLLAB_BESTOFN_EVAL"