You need to agree to share your contact information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

This checkpoint is an intermediate research artifact from an active TKDE extension of FINER-SQL (chained execution-feedback RL). Access is manual approval only while the paper is under development.

Log in or Sign Up to review the conditions and access this model content.

⚠️ Superseded by thanhdath/chained-sql-0.5b-sft-4teacher (correct 4-teacher dataset).

chained-sql-0.5b-sft-v2

Status: research checkpoint (gated, manual approval). This is the SFT-only baseline for a chained generate → execute → self-verify → regenerate Text-to-SQL policy, released as an intermediate artifact of the FINER-SQL TKDE extension (chained execution-feedback RL). It is the starting policy for a subsequent GRPO stage and is not the final model — do not compare its numbers to FINER-SQL-0.5B's published post-GRPO results.

Model details

  • Base model: Qwen/Qwen2.5-Coder-0.5B-Instruct
  • Architecture: Qwen2ForCausalLM, 0.5B params, bf16
  • Training paradigm: 2-epoch multi-turn chained supervised fine-tuning. Each training trajectory is a multi-turn conversation: the model generates a SQL query, the query is executed against the target database, the execution result (or error) is fed back as a user-turn observation, and the model self-verifies and regenerates if needed, for up to several turns.
  • Loss masking: assistant-only loss. Prompt tokens and execution-feedback (observation) tokens are masked out of the loss; only the assistant's generated content (including the <|im_end|> turn terminator) contributes to the gradient. This was implemented via the chat template's {%- generation %} markers and --assistant_only_loss, and cross-verified at 100.000% token-level agreement (1,532,708 / 1,532,708 tokens across 400 rows) against an independent offset-mapping oracle.
  • Dataset: chained_sft_merged_v1 — 32,881 chained multi-turn rows, distilled from two teacher models: qwen3-32b-awq and gpt-oss-120b.
  • Trainer: trl-llm-training fork's scripts/sft.py (this repo's vendored copy lives at trl_llm_training/ in the source repo), run with:
    • max_length = 24576 (covers 100% of training rows — the longest row is 22,855 tokens; length distribution and coverage were verified with a full histogram/statistics analysis before choosing this value)
    • effective batch size 64 (per-device batch × gradient accumulation × devices)
    • learning rate 1e-5, cosine schedule
    • precision bf16
    • hardware: single A100 (ICT Griffith cluster, gn061)
  • Final training metrics: train_loss = 0.9596, mean token accuracy = 0.773 (assistant tokens only), 144.5M trained tokens, 2 epochs / 1018 steps.

Evaluation — BIRD dev, chained protocol (SFT-only baseline)

Greedy decoding (temperature 0, n=1), up to 5 turns of generate→execute→self-verify per sample, full official BIRD dev set (1,534 samples).

Metric Value
EX overall 12.65%
EX — simple 16.76%
EX — moderate 6.47%
EX — challenging 6.21%
Convergence rate (same SQL twice, executable) 41.7%
Exec-ok rate 45.2%
Format violation rate 14.6%
Avg. turns used 3.29

This is a greedy, single-sample, SFT-only number and is not directly comparable to FINER-SQL-0.5B's reported 50.85 EX, which uses post-GRPO policy + n=30 majority voting. It is the pre-GRPO baseline this checkpoint is meant to establish. Error analysis: essentially all correct predictions converge within 2 turns; a large share of samples (43.7%) exhaust the 5-turn budget without producing a correct answer — the model has learned the generate/execute/ verify protocol but frequently emits invalid or incorrect SQL and fails to self-correct. This gap is exactly what the follow-on GRPO stage (execution + format + convergence rewards) targets.

Evaluation artifacts are included under eval/bird_dev_sft_v2/ in this repo: summary.json (metrics above) and results.jsonl (per-sample predictions/outcomes), plus the official BIRD submission file predict_dev.json. The full per-turn conversation trajectories (trajectories.jsonl, ~17MB) were not uploaded here for size; they are kept locally at campaigns/chained_05b_tkde/eval_results/sft_v2_ict_bird_dev/trajectories.jsonl in the source repo.

Usage

The model expects a multi-turn chained interaction: assistant emits SQL, the caller executes it and appends the result as a user-turn observation, and the loop repeats until the assistant's SQL converges (repeats) or a turn budget is hit.

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "thanhdath/chained-sql-0.5b-sft-v2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, dtype="bfloat16", device_map="auto")

messages = [
    {"role": "system", "content": SYSTEM_PROMPT},   # schema + task-specific system prompt
    {"role": "user", "content": QUESTION_WITH_SCHEMA},
]

MAX_TURNS = 5
prev_sql = None
final_sql = None

for turn in range(MAX_TURNS):
    prompt = tokenizer.apply_chat_template(
        messages, tokenize=False, add_generation_prompt=True
    )
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    out = model.generate(**inputs, max_new_tokens=2048, do_sample=False)
    reply = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
    messages.append({"role": "assistant", "content": reply})

    sql = extract_sql(reply)  # your own SQL-extraction helper

    if sql == prev_sql:  # convergence: model re-affirmed the same query
        final_sql = sql
        break
    prev_sql = sql

    exec_result_or_error = execute_sql(sql)      # run against the target DB
    observation = format_observation(exec_result_or_error)
    messages.append({"role": "user", "content": observation})
    final_sql = sql

print(final_sql)

The tokenizer's chat_template.jinja (included in this repo) contains {% generation %} markers used at training time to compute the assistant-only loss mask; they are inert for plain inference (apply_chat_template(..., tokenize=False, add_generation_prompt=True) works as shown above).

Intended use & limitations

  • Research artifact for the FINER-SQL TKDE extension studying chained execution-feedback RL for small (0.5B) Text-to-SQL policies. Not tuned for production use.
  • SFT-only: has not yet received the GRPO execution/format/convergence reward stage.
  • Repo is gated with manual approval — this is an intentional access-control choice for an in-progress research checkpoint, not a claim of restricted licensing (weights are Apache-2.0, inherited from the base model).
Downloads last month
-
Safetensors
Model size
0.5B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for thanhdath/chained-sql-0.5b-sft-v2

Finetuned
(97)
this model