File size: 2,451 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
# Canonical Planner Pipeline

ONE configuration. No variants.

## Schema sequence format (used in BOTH train and dev prompts)

```
table T , columns = [
  T.col | [primary key ;] type: {text|integer|real} ; [meaning: <column_description from BIRD CSV> ;] [value description: <value_description from BIRD CSV> ;] [has None ;] [values: <BM25-retrieved-top-k for question>]
  ...
]
foreign keys:
T1.c1 = T2.c2
...
```

All five fields used (when applicable):
1. **type / primary key** — from SQLite PRAGMA
2. **meaning**`column_description` from `bird/<split>/<db>/database_description/*.csv`
3. **value description**`value_description` from same CSV
4. **has None** — count of NULL values > 0 in column
5. **values** — top-2 BM25 hits for the question against `db_contents_index/<db>/<table>-**-<column>/`. Falls back to first indexed doc if BM25 returns no query-relevant hits.

## Files

| Asset | Path |
|---|---|
| Training data | `data/sft_planner_canonical/` |
| Dev prompts | `data/bird_dev_planner_prompts.json` |
| Training recipe | `alignment-handbook/recipes/llama-1b-bird/planner-fft-canonical.yaml` |
| Trained checkpoint | `alignment-handbook/output/planner-canonical/` |
| Builder for dev prompts | `scripts/build_canonical_prompts.py` |
| BM25 server | `db_content_retrieval/lsh_api.py` (start with `--lazy_load --db_content_index bird-dev`) |

## How to rebuild dev prompts from scratch

```bash
# 1) Start BM25 server (lazy_load avoids OOM)
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 JAVA_TOOL_OPTIONS=-Xmx12g \
python db_content_retrieval/lsh_api.py --port 8005 --db_content_index bird-dev --lazy_load &

# 2) Build canonical dev prompts
python scripts/build_canonical_prompts.py \
    --source bird-dev \
    --data data/sft_bird_with_evidence_dev_text2sql.json \
    --bird_dir data/bird/dev/dev_databases \
    --out data/bird_dev_planner_prompts.json
```

## How to retrain

```bash
cd alignment-handbook
PYTHONPATH=src/ accelerate launch \
  --config_file recipes/accelerate_configs/single_gpu0_local.yaml \
  scripts/run_sft.py \
  recipes/llama-1b-bird/planner-fft-canonical.yaml
```

## Eval

```bash
python scripts/run_eval_vllm.py \
  --model alignment-handbook/output/planner-canonical \
  --tokenizer_template qwen \
  --prompts_json data/bird_dev_planner_prompts.json \
  --output_dir eval_results/planner-canonical-bird-dev \
  --skip_pass_k --max_model_len 8192 --max_tokens 1024 --dtype bfloat16
```