KeenSQL1.0 / README.md
Keendata's picture
KeenSQL1.0
a0122bb verified
|
Raw History Blame Contribute Delete
7 kB
metadata
library_name: transformers
license: apache-2.0
base_model: Qwen/Qwen3.5-9B
tags:
  - text-to-sql
  - agent
  - tool-use
  - sqlite
  - reinforcement-learning
  - qwen3_5
language:
  - en
pipeline_tag: text-generation

KeenSQL1.0

A 9B tool-using Text-to-SQL agent for SQLite databases. Given a natural-language question, a database, and optional evidence, the model runs a multi-turn agent loop — inspecting the schema, executing probe queries, then emitting a final SQL answer — and returns a single SQL statement.

KeenSQL1.0 is the final checkpoint (global step 240) of a reinforcement fine-tuning run started from a full-parameter SFT of Qwen3.5-9B, trained with GRPO plus a KL-to-reference penalty on execution-based rewards.

Model details

Base architecture Qwen3.5 (hybrid linear/full attention, Qwen3_5ForConditionalGeneration)
Parameters ~9B
Precision bfloat16
Hidden / layers 4096 / 32
Attention 16 Q heads, 4 KV heads, head_dim 256, mRoPE (partial 0.25)
Vocabulary 248,320
Context 262,144
Training start point SFT checkpoint at global step 286 (full-parameter SFT of Qwen3.5-9B)
Training steps 240 optimizer steps (1 update per step)
Batch 8 question groups × 3 candidates × 8 rollouts per step
Optimizer AdamW, lr 1e-6 with 7-step warmup, cosine decay to 0.3×
KL controller target 0.03 nats/token, adaptive coefficient in [0.02, 0.5]

The checkpoint also carries an (unused) vision tower from the Qwen3.5 multimodal architecture; this model is text-only in practice.

⚠️ Use this model's own chat template

chat_template.jinja (also embedded in tokenizer_config.json) is a modified variant, not the stock Qwen3.5 template. It emits a plain assistant header on every turn and adds no think block.

The stock template gives the assistant message that follows the last non-tool user turn a closed empty think block, which acts as a perfect "this is the final turn" flag — a signal that a rollout cannot reproduce, because whether a turn ends the episode is decided by tokens sampled after the header is already fixed in the context.

Training, rollout and evaluation all use the plain-header shape. Loading this model with the default Qwen template produces a train/inference format mismatch and will degrade accuracy substantially.

from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained("<this-repo>", trust_remote_code=True)
# chat_template is already set from tokenizer_config.json — do not override it
assert "plain-header" in tok.chat_template

Agent protocol

The model expects to be driven by an agent loop with these properties:

Item Value
Max turns 8 tool calls + 1 final answer
Max tokens per turn 2048
Max observation size 2048 tokens per tool return
Tool sqlite_query (single SQL statement; returns rows or an error)
Final answer a turn containing a sql block instead of a tool call

Turns must alternate: one tool call per turn, observation fed back as a user message wrapped in <observation>. The model was trained with this exact wrapper and turn budget.

Sampling used for evaluation: temperature 0.7, top_p 0.95, top_k -1.

Evaluation

BIRD dev (1,534 questions, self-consistency)

sc_ex = execution accuracy after majority vote over k samples. pass@k = fraction of questions with at least one correct sample out of k.

Checkpoint sc_ex (k=8) pass@8 all-attempt protocol rate
SFT start point (step 286) 0.6851 0.7992 0.8801
RFT step 120 0.6930 0.7621 0.9720
KeenSQL1.0 (RFT step 240) 0.7053 0.7901 0.8911

At higher sampling budgets (step 240): sc_ex@16 = 0.7112, sc_ex@32 = 0.7125, pass@32 = 0.8305.

By difficulty (BIRD dev, sc@8)

Difficulty Questions SFT start KeenSQL1.0 Δ
simple 925 0.7351 0.7514 +1.63
moderate 464 0.6207 0.6466 +2.59
challenging 145 0.5724 0.6000 +2.76

The gain grows with difficulty, which is what one wants from execution-reward training.

Internal held-out split (323 questions, n=2, temp 0.7)

Weighted execution accuracy: 0.6502 at the SFT start point → 0.7167 at its peak (step 120) → 0.6796 at step 240.

This internal split disagreed with the full BIRD dev set: it made step 120 look like the best checkpoint (0.7167) while on BIRD dev step 240 scored higher (0.7053 vs 0.6930). The internal split is only 323 questions from a narrow set of databases, so its step-to-step swings (roughly ±1.5 points) are dominated by sampling noise.

How to read these numbers

  • The gain over the SFT start point is modest but consistent: +2.0 points sc_ex on BIRD dev, concentrated on the harder questions.
  • pass@8 is slightly lower than the SFT start point (0.7901 vs 0.7992), while sc_ex@8 is higher. In other words RFT improved per-sample reliability under majority voting rather than the capability ceiling — expected, since the SFT start point already solved 80% of questions at least once in 8 tries.
  • Output diversity increased during training (mean entropy 0.23 nats/token, up from 0.19), so self-consistency needs k≥8 to pay off. At k=2 expect considerably lower numbers.

Limitations

  • SQLite only. Trained and evaluated on SQLite databases. Other dialects untested.
  • Schema must be provided in the prompt; the model does not connect to a database.
  • Needs the agent loop. Loaded as a plain chat model without the tool protocol and turn budget, quality drops sharply.
  • Late-training drift. From roughly step 120 onward the KL-to-reference penalty was pushed to its operating point, output diversity rose, and self-consistency consensus fell. If you need maximum stability rather than maximum accuracy, evaluate step 120 as well.
  • Small validation set. The internal split used to monitor training was too small to distinguish nearby checkpoints reliably; the BIRD dev numbers above are the trustworthy ones.
  • Not safety-tuned beyond whatever the base SFT model carried. No guarantee against generating destructive SQL — never run its output against a production database without review.

Files

File Notes
model.safetensors single-file bf16 weights, 760 tensors, ~17.5 GB
config.json Qwen3.5 text config (+ unused vision_config)
tokenizer.json, tokenizer_config.json fast tokenizer, custom chat template embedded
chat_template.jinja same template as a standalone file
generation_config.json default generation parameters
processor_config.json Qwen3VLProcessor (multimodal; unused for text-only SQL)

Requires a transformers release that supports the qwen3_5 architecture (the checkpoint was exported with transformers 5.9.0).