| # MATS-TIST Workflow on gf-henry |
|
|
| ## Machine Info |
| - GPUs: RTX 2080 Ti (11GB) + TITAN RTX (24GB) |
| - Home: `/home/datht/` |
| - Conda env: `mats` |
|
|
| ## Code Policy |
| > **Never edit code on gf-henry.** Always edit on the dev machine, then sync: |
| > ```bash |
| > # On dev machine (not gf-henry): |
| > bash /home/datht/mats-sql-tist/scripts/sync_code.sh |
| > ``` |
| |
| --- |
| |
| ## Directory Layout on gf-henry |
| |
| ``` |
| /home/datht/ |
| ├── mats-sql-tist/ ← synced code (never edit directly) |
| │ ├── data -> /home/datht/mats/data (symlink) |
| │ ├── alignment-handbook/ |
| │ ├── utils/ |
| │ ├── db_content_retrieval/ |
| │ ├── scripts/ |
| │ │ ├── setup_env_gf_henry.sh |
| │ │ ├── sync_code.sh |
| │ │ ├── build_all_bm25_indexes.py |
| │ │ ├── train_bird.sh ← alignment-handbook train commands |
| │ │ └── evaluate_bird.sh |
| │ ├── prepare_sft_datasets.py |
| │ └── evaluate_end2end.py |
| │ |
| ├── mats/ |
| │ ├── alignment-handbook/output/ ← Qwen SQL-writer trained models |
| │ │ ├── Qwen-2.5-Coder-1.5B-SQL-Writer/ |
| │ │ ├── Qwen-2.5-Coder-3B-SQL-Writer/ |
| │ │ └── ... |
| │ ├── schema_insight/output/ |
| │ │ └── grpo_schema_bird-Qwen-Coder-0.5B-phase2/checkpoint-6200/ ← schema agent ckpt |
| │ └── data/ ← all datasets + BM25 indexes |
| │ ├── bird/dev/ (11 dbs + BM25 indexes) |
| │ ├── bird/train/ (69 dbs + BM25 indexes) |
| │ ├── spider/ (169 dbs + BM25 indexes) |
| │ └── sft_data_collections/ (Spider-DK, Dr.Spider, domain, ...) |
| │ |
| └── huggingface/ ← trained MATS agent models |
| ├── llama-3b-bird-planner-fft/ (6G) Planner SFT |
| ├── llama-3b-bird-validator-fft/ (6G) Validator SFT |
| ├── llama-3b-bird-fixed-fft/ (6G) Fixer SFT |
| ├── orpo-llama-3b-iter-3-bird-planner-no-filter-seed107/ (6.1G) Planner ORPO |
| └── Meta-Llama-3.1-8B-Instruct/ (30G) (available if needed) |
| ``` |
| |
| --- |
|
|
| ## Setup (one-time) |
|
|
| ```bash |
| # 1. Setup conda env (installs torch, transformers, trl, vllm, pyserini, etc.) |
| cd /home/datht/mats-sql-tist |
| bash scripts/setup_env_gf_henry.sh |
| |
| # 2. Install alignment-handbook (custom ORPO) |
| source /home/datht/anaconda3/etc/profile.d/conda.sh |
| conda activate mats |
| cd /home/datht/mats-sql-tist/alignment-handbook |
| pip install -e . |
| ``` |
|
|
| --- |
|
|
| ## Base LLaMA Models (for retraining) |
|
|
| The recipe YAMLs reference `/home/datht/huggingface/meta-llama/Llama-3.2-{1B,3B}-Instruct`. |
| Download them from HuggingFace if not already present: |
|
|
| ```bash |
| conda activate mats |
| python -c " |
| from huggingface_hub import snapshot_download |
| # LLaMA 3.2 3B (Planner, Selector) |
| snapshot_download('meta-llama/Llama-3.2-3B-Instruct', |
| local_dir='/home/datht/huggingface/meta-llama/Llama-3.2-3B-Instruct') |
| # LLaMA 3.2 1B (Validator, Fixer) |
| snapshot_download('meta-llama/Llama-3.2-1B-Instruct', |
| local_dir='/home/datht/huggingface/meta-llama/Llama-3.2-1B-Instruct') |
| " |
| ``` |
|
|
| --- |
|
|
| ## Running Experiments |
|
|
| ### Step 1: Start BM25 API (for schema retrieval during SFT data build) |
| ```bash |
| conda activate mats |
| cd /home/datht/mats-sql-tist |
| python db_content_retrieval/lsh_api.py --port 8005 & |
| ``` |
|
|
| ### Step 2: Build SFT training data (with CHESS-style DDL + BIRD CSV descriptions) |
| ```bash |
| conda activate mats |
| cd /home/datht/mats-sql-tist |
| # BIRD dev |
| python prepare_sft_datasets.py |
| ``` |
|
|
| ### Step 3: SFT Training (alignment-handbook) |
| ```bash |
| conda activate mats |
| cd /home/datht/mats-sql-tist/alignment-handbook |
| export PYTHONPATH=src/ |
| # BIRD - planner (LLaMA 3.2 3B) |
| ACCELERATE_LOG_LEVEL=info accelerate launch \ |
| --config_file recipes/accelerate_configs/multi_gpu.yaml \ |
| --num_processes 1 \ |
| scripts/run_sft.py recipes/llama-3b-bird/planner-fft.yaml |
| |
| # BIRD - validator + fixer (LLaMA 3.2 1B) |
| ACCELERATE_LOG_LEVEL=info accelerate launch \ |
| --config_file recipes/accelerate_configs/multi_gpu.yaml \ |
| --num_processes 1 \ |
| scripts/run_sft.py recipes/llama-3b-bird/validator-fixer-fft.yaml |
| ``` |
|
|
| ### Step 4: ORPO Training (after SFT) |
| ```bash |
| conda activate mats |
| cd /home/datht/mats-sql-tist/alignment-handbook |
| export PYTHONPATH=src/ |
| # See alignment-handbook/scripts/train_bird.sh for full commands |
| bash scripts/train_bird.sh |
| ``` |
|
|
| ### Step 5: Evaluation (BIRD dev) |
| ```bash |
| conda activate mats |
| cd /home/datht/mats-sql-tist |
| |
| # Serve agents via vLLM (on TITAN RTX, 24GB) |
| CUDA_VISIBLE_DEVICES=1 vllm serve /home/datht/huggingface/orpo-llama-3b-iter-3-bird-planner-no-filter-seed107 \ |
| --host 0.0.0.0 --port 8003 --served-model-name planner \ |
| --dtype bfloat16 --max-model-len 4096 --gpu-memory-utilization 0.9 & |
| |
| CUDA_VISIBLE_DEVICES=0 vllm serve /home/datht/huggingface/llama-3b-bird-validator-fft \ |
| --host 0.0.0.0 --port 8004 --served-model-name validator \ |
| --dtype bfloat16 --max-model-len 4096 --gpu-memory-utilization 0.8 & |
| |
| CUDA_VISIBLE_DEVICES=0 vllm serve /home/datht/huggingface/llama-3b-bird-fixed-fft \ |
| --host 0.0.0.0 --port 8005 --served-model-name fixed \ |
| --dtype bfloat16 --max-model-len 4096 --gpu-memory-utilization 0.8 & |
| |
| # Run evaluation |
| python evaluate_end2end.py \ |
| --input_file data/full_value_matching_sft_bird_062024_with_evidence_dev_text2sql.json \ |
| --output_file output/bird_dev_results.jsonl \ |
| --model-name llama \ |
| --api_host http://localhost:8003 \ |
| --n_processes 8 |
| ``` |
|
|
| --- |
|
|
| ## Syncing Code Updates from Dev Machine |
|
|
| After editing code on the dev machine: |
|
|
| ```bash |
| # On DEV machine: |
| bash /home/datht/mats-sql-tist/scripts/sync_code.sh gf-henry |
| |
| # On gf-henry (if alignment-handbook changed): |
| cd /home/datht/mats-sql-tist/alignment-handbook && pip install -e . |
| ``` |
|
|
| --- |
|
|
| ## Notes |
|
|
| - **vLLM**: TITAN RTX (24GB, GPU 1) is preferred for planner/selection, RTX 2080 Ti (11GB, GPU 0) for smaller validator/fixer models |
| - **BM25 indexes**: already built, stored in `data/*/db_contents_index/` |
| - **BIRD CSV descriptions**: automatically loaded during `prepare_sft_datasets.py` via `utils/bird_csv_utils.py` |
| - **Schema format**: CHESS-style DDL with inline `-- Column Description | Value Description` (see `utils/db_utils.py`) |
|
|