mats-sql-bundle / code /CANONICAL.md
thanhdath's picture
Push code: scripts, slurm sbatch, recipes, utils (v3 + selector series)
778d47d verified
|
Raw
History Blame Contribute Delete
2.45 kB
# 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
```