File size: 5,082 Bytes
1e59964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
121
122
123
124
125
#!/usr/bin/env bash
###############################################################################
# StepProbe — 14B scale-up experiment.
#
# Adds a single (model × benchmark × method) cell at 14B scale without
# rerunning the whole matrix. Answers the Q1 reviewer's inevitable "does
# this generalise beyond 8B?" question by producing one diagnosed cell with
# full metrics/CIs. FP16 reference is not available at 14B on a 24 GB card,
# so we diagnose against the FP16 reference from the closest sibling model
# (r1-qwen-7b) as a partial proxy — noted explicitly in the paper's
# limitations if used for the main table.
#
# Expected runtime: ~60-90 min on 3090 Ti (14B GPTQ inference on 500 problems).
###############################################################################
set -euo pipefail

PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR"

export CUDA_VISIBLE_DEVICES="${CUDA_VISIBLE_DEVICES:-1}"
export HF_HUB_DOWNLOAD_TIMEOUT=300

MODEL_HF="${MODEL_HF:-deepseek-ai/DeepSeek-R1-Distill-Qwen-14B}"
MODEL_TAG="${MODEL_TAG:-r1-qwen-14b}"
QUANT_METHOD="${QUANT_METHOD:-gptq}"
BITS="${BITS:-4}"
QUANT_TAG="${QUANT_METHOD}_w${BITS}"
BENCHMARK="${BENCHMARK:-math500}"
PY="${PY:-python}"
GPU_MEM="${GPU_MEM:-0.55}"
QUANT_ENV_PY="${QUANT_ENV_PY:-/home/aiteam1/anaconda3/envs/sonthh-stepprobe-quant/bin/python}"

QUANT_MODEL_DIR="${PROJECT_DIR}/results/quantized_models/${MODEL_TAG}_${QUANT_TAG}"
INF_DIR="${PROJECT_DIR}/results/inference/${QUANT_TAG}/${MODEL_TAG}"
SEG_DIR="${PROJECT_DIR}/results/segmented/${QUANT_TAG}/${MODEL_TAG}"
DIAG_DIR="${PROJECT_DIR}/results/diagnosis/${QUANT_TAG}/${MODEL_TAG}"
METRICS_DIR="${PROJECT_DIR}/results/metrics"
# FP16 reference at 14B doesn't fit on a 24 GB card. Fall back to the 7B
# sibling's reference traces, which the 14B should follow closely in
# high-level reasoning structure.
REF_DIR="${PROJECT_DIR}/results/segmented/fp16/r1-qwen-7b"
LOG_DIR="${PROJECT_DIR}/logs"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
LOG_FILE="${LOG_DIR}/scale_up_${TIMESTAMP}.log"
mkdir -p "$METRICS_DIR" "$LOG_DIR"

log() { echo "[$(date '+%H:%M:%S')] $1" | tee -a "$LOG_FILE"; }

log "=============================================="
log "14B scale-up: $MODEL_TAG / $QUANT_TAG / $BENCHMARK"
log "=============================================="

# 1. Offline quantization (only needed for awq/gptq).
if [[ "$QUANT_METHOD" == "awq" || "$QUANT_METHOD" == "gptq" ]]; then
    if [[ ! -f "${QUANT_MODEL_DIR}/config.json" ]]; then
        log "RUN: offline quantization ($QUANT_METHOD w${BITS}) — ~30 min"
        "$QUANT_ENV_PY" ${PROJECT_DIR}/scripts/quantize_models.py \
            --model "$MODEL_HF" \
            --method "$QUANT_METHOD" \
            --bits "$BITS" \
            --group-size 128 \
            --output "$QUANT_MODEL_DIR" 2>&1 | tee -a "$LOG_FILE"
    else
        log "SKIP: quantized model exists at $QUANT_MODEL_DIR"
    fi
    VLLM_MODEL="$QUANT_MODEL_DIR"
else
    VLLM_MODEL="$MODEL_HF"
fi

# 2. Inference.
OUT_FILE="${INF_DIR}/${BENCHMARK}_run0.jsonl"
if [[ -f "$OUT_FILE" ]]; then
    log "SKIP: inference — $OUT_FILE exists"
else
    log "RUN: vLLM inference on $BENCHMARK"
    mkdir -p "$INF_DIR"
    $PY ${PROJECT_DIR}/scripts/run_inference.py \
        --model "$VLLM_MODEL" \
        --quant "$QUANT_METHOD" --bits "$BITS" \
        --benchmark "$BENCHMARK" \
        --output "$INF_DIR" \
        --max-tokens 4096 --num-runs 1 \
        --gpu-memory-utilization "$GPU_MEM" 2>&1 | tee -a "$LOG_FILE"
fi

# 3. Segment + diagnose + metrics.
if [[ ! -f "${SEG_DIR}/${BENCHMARK}_run0.jsonl" ]]; then
    mkdir -p "$SEG_DIR"
    log "RUN: segment"
    $PY -m stepprobe.segment --input "$INF_DIR" --output "$SEG_DIR" \
        --quant "$QUANT_TAG" 2>&1 | tee -a "$LOG_FILE"
fi

if [[ ! -f "${DIAG_DIR}/${BENCHMARK}_run0.jsonl" ]]; then
    if [[ ! -d "$REF_DIR" ]]; then
        log "ERROR: FP16 reference dir $REF_DIR missing — scale-up needs a"
        log "       reference; at 14B the own-model FP16 doesn't fit on a 24GB"
        log "       card. Either run 'bash run_all.sh --phase 4 --models small' to"
        log "       populate r1-qwen-7b references, or set REF_DIR=... via env."
        exit 1
    fi
    mkdir -p "$DIAG_DIR"
    log "RUN: diagnose (ref = r1-qwen-7b FP16)"
    $PY -m stepprobe.diagnose \
        --ref "$REF_DIR" --hyp "$SEG_DIR" --output "$DIAG_DIR" \
        --alignment dtw 2>&1 | tee -a "$LOG_FILE"
fi

log "RUN: metrics + bootstrap CIs"
$PY -m stepprobe.metrics \
    --diagnosis "$DIAG_DIR" --output "$METRICS_DIR" \
    --model "$MODEL_TAG" --quant "$QUANT_TAG" 2>&1 | tee -a "$LOG_FILE"
$PY ${PROJECT_DIR}/scripts/compute_ci.py \
    --diagnosis "${PROJECT_DIR}/results/diagnosis" \
    --output "$METRICS_DIR" --n-boot 5000 2>&1 | tee -a "$LOG_FILE"

log ""
log "DONE — 14B scale-up cell"
log "  Metrics:   ${METRICS_DIR}/${MODEL_TAG}_${QUANT_TAG}_${BENCHMARK}_run0_metrics.json"
log "  Log:       $LOG_FILE"
log ""
log "To include in the paper figures: rerun scripts/make_paper_figures.py"
log "  — the 14B cell will appear in fig_paper_3_forest.pdf and Table 1."