File size: 14,161 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# Handoff: Make COLLAB > INDEP at end-to-end EX (target ≥1pp, stretch ≥2pp)

## The problem in one line

Our paper-format ORPO **validator-internal reward-accuracy** strongly favors COLLAB over INDEP
(+10pp on val-sel, +17.7pp on val-cond), but **end-to-end selector EX is identical** (COLLAB 59.97% vs INDEP 60.31% — INDEP is actually 0.34pp ahead). The collab training signal isn't translating to pipeline gains.

**Your goal**: lift the COLLAB pipeline's selector EX so that it **beats INDEP by ≥1pp** (stretch goal: ≥2pp gap) on full BIRD-dev (1524 questions).

This must show in the **pipeline metric the paper cares about** (`compute_bestofn_with_selector.py` trained selector EX), not just the validator-internal `eval_rewards/accuracies`.

---

## 1. Current ground truth (full BIRD-dev, 1524 questions)

| Config | planner@1 (T=0) | pipeline@1 (T=0) | oracle pass@8 | **trained selector EX** |
|---|---|---|---|---|
| PLANNER-only | **51.54%** | 51.54% | 70.80% | — |
| SFT-VF (paper validators, no ORPO) | 51.48% | 52.20% | 71.65% | **59.91%** |
| **ORPO iter1 COLLAB** | 51.08% | 51.81% | 71.19% | **59.97%** |
| **ORPO iter1 INDEP** | 51.74% | 52.59% | 71.95% | **60.31%** |

Validator-internal reward accuracies (test_dpo split, what ORPO optimizes):

| Validator | eval_loss | eval_rewards/accuracies |
|---|---|---|
| **val-sel COLLAB** | 0.174 | **69.7%** |
| val-sel INDEP | 0.210 | 59.7% |
| **val-cond COLLAB** | 0.148 | **89.7%** |
| val-cond INDEP | 0.163 | 72.0% |

**Reading the gap**: COLLAB's chosen/rejected discrimination training succeeded, but at inference the chosen "correct" critiques don't lead to materially different fixer outputs (or different pipeline EX) than INDEP's.

---

## 2. Why collab SHOULD be better than indep (paper Alg. 2 intuition)

| Mode | What "chosen" means | What signal it carries |
|---|---|---|
| **INDEP** | critique whose `Conclude:` matches a HEURISTIC over planner-vs-gold correctness | Local: was the critique text consistent with whether planner was correct? Surface-level. |
| **COLLAB** | critique that, when fed to the fixer, produces a correct final SQL | End-to-end: did this critique HELP the downstream fixer produce correct SQL? |

If the fixer **actually uses critique content**, COLLAB's signal carries downstream-aware information INDEP doesn't have. If the fixer **ignores critique**, COLLAB signal collapses to noise + the fixer's intrinsic correctness, and INDEP wins on cleaner labels.

---

## 3. Diagnosis: why our collab signal is currently weak

Three structural issues identified in this session — partially mitigated, not fixed:

### 3.1 The fixer was trained on a FIXED critique template

[`build_orpo_data.py:245`](https://huggingface.co/datasets/thanhdath/mats-sql-bundle/blob/main/scripts/build_orpo_data.py) (in the snapshot uploaded to `thanhdath/mats-sql-bundle/scripts/`):

```python
val_critique = "<select>\nSELECT.\nINCORRECT\n</select>\n\n<condition>\nCONDITION.\nINCORRECT\n</condition>"
```

Every fixer SFT example uses this **identical** critique. The fixer never learned to condition its output on critique content. At collab data-gen time we feed K=4 *diverse* critiques per question, but the fixer's output is largely invariant to the critique — so chosen vs rejected critiques produce near-identical fixer SQLs → ORPO sees a low-information signal.

**Evidence**: collab pair-formation rate is 0.33 pairs/question (650 pairs from 2000 q) vs independent's 1.78 pairs/question (3565 pairs from 2000 q). The fixer judging step is collapsing — most critiques bucket identically.

### 3.2 Data-gen flow ≠ inference flow

At collab data-gen, the fixer runs for EVERY critique regardless of what the critique says. At inference, the fixer is gated by `planner_exec_ok=False`. This mismatch means the collab training distribution doesn't reflect how the validator actually contributes at inference (where it primarily votes "this candidate is good / bad" rather than steering a per-call fixer rewrite).

We added a `collab_v2` mode in `build_orpo_data.py` (`--mode collab_v2`) that simulates inference: critique-says-`Conclude:correct` → keep planner SQL; else → run fixer; chosen/rejected by end-to-end correctness. **It hasn't been used to retrain validators yet** — that's the obvious next experiment.

### 3.3 Small K + small dataset

`build_orpo_data.py` uses K=4 critiques per question in our runs. With paper-format validators that are already fairly calibrated, 4 critiques often land in the same bucket → 0 pairs for that question. Net pair yield is low for COLLAB.

---

## 4. Concrete experiments to flip the gap (ranked by ROI)

### E1. **Train a CRITIQUE-AWARE fixer** ⭐ highest ROI

The biggest single thing keeping COLLAB ≈ INDEP. Rebuild the fixer SFT data so each example has a DIFFERENT critique:

```
For each BIRD-train question with planner_exec_ok=False:
  Generate K=4 validator critiques (val-sel + val-cond, paper-format)
  For each critique:
    Run fixer at T=1.0, get fix_sql
    Score correctness
  Form (critique, fix) pairs:
    chosen   = (good_critique, correct_fix)
    rejected = (bad_critique, wrong_fix)
  Save with critique embedded in the prompt.
```

Then ORPO-train the fixer on this data. Now the fixer LEARNS to use critique content.

When the fixer becomes critique-aware, **collab's "fixer-judged chosen/rejected" signal becomes informative** (different critiques → different fix outputs → different correctness labels), so retraining COLLAB validators on iter2 data will discriminate better than INDEP.

Builder skeleton lives in [`scripts/build_orpo_data.py:build_fixer_data`](models/fixer-1B-orpo-iter1) — currently uses the fixed critique. Replace `val_critique = "<select>...INCORRECT..."` with per-row diverse critiques sampled from the SFT validators.

### E2. **Train iter2 COLLAB validators with the new fixer + `collab_v2` mode** ⭐ high ROI

Once E1 produces a critique-aware fixer (call it `fixer-1B-orpo-iter2`):

```bash
python scripts/build_orpo_data.py --agent validator_sel --mode collab_v2 \
    --planner_host ... --validator_host <SFT-paper> --fixer_host <fixer-iter2> \
    --K 8 --temperature 1.0 --max_questions 2000 \
    --out data/hf_orpo_val_sel_paper_iter2_collab
```

Note: **K=8 instead of K=4** for more pair-yield diversity. **`collab_v2`** for inference-aligned chosen/rejected.

Then ORPO iter2 on top of iter1 COLLAB. Expected gain: each ORPO iter typically lifts 0.3-0.8pp at pipeline level; with a working collab signal, iter2 should move COLLAB above INDEP.

### E3. **Joint K-rollout training (paper Alg. 2 in true form)**

The paper's joint training uses ONE rollout pool for ALL agents. We currently:

- Generate per-agent ORPO datasets independently (planner pool, val-sel pool, val-cond pool, fixer pool)
- Train each agent on its own pool

True Alg. 2: for each BIRD-train question, do K=8 FULL pipeline rollouts (planner→val-sel→val-cond→fixer→final SQL). Each rollout produces decisions at each agent. Then:

- planner chosen/rejected = the rollouts whose FINAL SQL was correct (vs not)
- val-sel chosen/rejected = the critiques that came from rollouts whose final was correct
- val-cond chosen/rejected = same
- fixer chosen/rejected = same

This couples the agents — each one is rewarded for decisions that helped the END-TO-END outcome. This is what COLLAB is supposed to be in the paper but our current `--mode collab` only does step-2 (fixer judges critique) not step-1 (final-outcome judges everything).

Build script doesn't exist; would need writing.

### E4. **Verify the fixer is gated correctly at inference**

[`scripts/run_pipeline_rollouts.py`](models/) wraps paper-format critique inside `<select>/<condition>` tags before sending to the fixer (since fixer was trained with wrapper tags). Inspect 5-10 fixer prompts in a `paper_COLLAB_par_passAt8_bird_dev.jsonl` row to confirm:
1. Critique content is reaching the fixer
2. Fixer's output actually responds to critique content (i.e., `fixed_sql != planner_sql` when critique says "INCORRECT")

If the fixer is ignoring critique content, E1 (critique-aware retraining) is mandatory.

### E5. **Tighten the comparison statistic**

Selector EX over n=1524 has ~1.2pp standard error at 60% — our COLLAB-INDEP gap of 0.34pp is well within noise. To call a ≥1pp gap "real":
- Report bootstrap CI over rollouts (resample questions with replacement, 1000 iters)
- Or report the gap on a fixed selector + fixed K=8 rollouts so the only variable is which validator was used

If the next iter shows COLLAB +1.2pp over INDEP, bootstrap will say whether it's statistically real or sampling.

---

## 5. Resources (all on `thanhdath/mats-sql-bundle` HF dataset + local)

### Pre-trained ckpts (already on HF, can re-download or use directly)

```
hf:thanhdath/mats-sql-bundle:models/planner-3B-sft/
hf:thanhdath/mats-sql-bundle:models/planner-3B-orpo-iter1/
hf:thanhdath/mats-sql-bundle:models/validator-sel-1B-sft-paper/
hf:thanhdath/mats-sql-bundle:models/validator-sel-1B-orpo-iter1-collab-paper/
hf:thanhdath/mats-sql-bundle:models/validator-sel-1B-orpo-iter1-indep-paper/
hf:thanhdath/mats-sql-bundle:models/validator-cond-1B-sft-paper/
hf:thanhdath/mats-sql-bundle:models/validator-cond-1B-orpo-iter1-collab-paper/
hf:thanhdath/mats-sql-bundle:models/validator-cond-1B-orpo-iter1-indep-paper/
hf:thanhdath/mats-sql-bundle:models/fixer-1B-sft/                          ← E1 retrains THIS
hf:thanhdath/mats-sql-bundle:models/fixer-1B-orpo-iter1/                   ← E1's alt input
hf:thanhdath/mats-sql-bundle:models/selector-3B-sft/                       ← keep frozen for fair compare
```

Local copies on weka (if you have the same compute):

```
/weka/s225250685/mats-tist/alignment-handbook/output/<same names>
```

### Pre-built ORPO iter1 paper datasets

```
data/hf_orpo_val_sel_paper_iter1_collab    617 train + 33 test pairs
data/hf_orpo_val_sel_paper_iter1_indep    3386 train + 179 test pairs
data/hf_orpo_val_cond_paper_iter1_collab   545 train + 29 test pairs
data/hf_orpo_val_cond_paper_iter1_indep   1553 train + 82 test pairs
```

### Scripts

```
scripts/build_orpo_data.py                  # has --mode {collab, collab_v2, independent}
scripts/run_pipeline_rollouts.py            # K=8 pipeline eval; emits *_passAt8_bird_dev.jsonl
scripts/compute_bestofn_with_selector.py    # runs trained selector, reports EX
scripts/gen_validator_sft_qwen72b.py        # Qwen-72B teacher for paper-format SFT (already ran)
scripts/train_sft_completion_only.py        # SFT trainer
```

### ORPO recipes

```
recipes/iter1-paper/orpo-val-sel-collab-paper.yaml
recipes/iter1-paper/orpo-val-sel-indep-paper.yaml
recipes/iter1-paper/orpo-val-cond-collab-paper.yaml
recipes/iter1-paper/orpo-val-cond-indep-paper.yaml
```

For an iter2, copy + change `model_name_or_path` to the iter1 ORPO ckpt, point `dataset_mixer` at the new iter2 dataset, output to `orpo-val-*-iter2-paper`.

### Reference rollouts (use these to eval without re-running the GPU pipeline)

```
eval_results/paper_SFT_VF_passAt8_bird_dev.jsonl       # K=8 SFT validators
eval_results/paper_COLLAB_par_passAt8_bird_dev.jsonl   # K=8 ORPO COLLAB
eval_results/paper_INDEP_par_passAt8_bird_dev.jsonl    # K=8 ORPO INDEP
eval_results/paper_greedy_*_passAt1_bird_dev.jsonl     # 4 greedy configs
```

---

## 6. Definition of done

A single command must produce a **passing** run:

```bash
python scripts/compute_bestofn_with_selector.py \
    eval_results/paper_COLLAB_iter2_passAt8_bird_dev.jsonl \
    paper_COLLAB_iter2_selectorEX \
    --selector_host http://localhost:8103 --row_preview
# Print: trained selector ≥ INDEP_iter2 + 1.0pp
```

Required to ship:

1. **K=8 BIRD-dev rollouts** for both new configs:
   - `paper_COLLAB_iter2_passAt8_bird_dev.jsonl` (new agents)
   - `paper_INDEP_iter2_passAt8_bird_dev.jsonl` (matched control)
2. **Selector EX from `compute_bestofn_with_selector.py`** on both.
3. **A bootstrap 95% CI** showing the COLLAB − INDEP gap is positive with lower bound ≥ 1pp.
4. **Updated `thanhdath/mats-sql-bundle` README** with the new numbers.
5. **The new iter2 ckpts pushed to HF** under `models/*-iter2-*-paper`.

---

## 7. Constraints (don't violate)

- **K = 8 is fixed** at inference rollout. Don't compare with K=16 etc.
- **Temperature = 1.0** for the K=8 rollouts.
- **Same selector for both configs** — use `selector-3B-sft` from the bundle, do NOT retrain the selector while making this comparison (otherwise you're conflating two changes).
- **Same planner and same fixer family across COLLAB vs INDEP at eval** — only the validators change (this is what isolates the COLLAB vs INDEP effect). If E1 retrains the fixer, evaluate COLLAB and INDEP both with the NEW fixer.
- **β = 0.1** for ORPO unless you have a specific reason to vary; β ≥ 0.5 collapsed val-sel in our runs.
- SLURM job name must be `vl` (lowercase). HF_TOKEN at `/weka/s225250685/mats-tist/.env`.
- `PYTHONNOUSERSITE=1` to avoid user-site contamination.

---

## 8. Suggested execution order

```
Day 0   E4: spot-check 10 fixer prompts on disk → confirm if fixer uses critique
Day 1   E1: build critique-aware fixer SFT data (~3h) → train fixer-1B-orpo-iter2 (~1h)
Day 2   E2: build iter2 COLLAB + INDEP datasets with new fixer + collab_v2 + K=8 (~6h each)
Day 2   E2: train iter2 COLLAB + INDEP validators (4 jobs in parallel, ~1h each)
Day 3   K=8 BIRD-dev rollouts × 2 configs (~3h each parallel) → selector EX
Day 3   Bootstrap CI, write up, push to HF
```

If E1 + E2 don't produce ≥1pp gap, drop to **E3 (joint Alg. 2)** which is the more aggressive rewrite.

## 9. What "good" looks like at the end

```
Selector EX
  paper_SFT_VF        : 59.91%   (baseline, unchanged)
  paper_INDEP_iter2   : 60.5±0.4%  (matched control)
  paper_COLLAB_iter2  : 62.0±0.4%  (target — gap ≥ 1pp, bootstrap-significant)
```

Then update the bundle README to show COLLAB ≠ INDEP, write a short summary of *why*
(critique-aware fixer + inference-aligned collab signal), and the paper claim "COLLAB > INDEP"
will be empirically supported on our reproduction.