Text Generation
Transformers
Safetensors
English
qwen3_5
image-text-to-text
text-to-sql
agent
tool-use
sqlite
reinforcement-learning
conversational
Instructions to use Keendata/KeenSQL1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Keendata/KeenSQL1.0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Keendata/KeenSQL1.0") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Keendata/KeenSQL1.0") model = AutoModelForMultimodalLM.from_pretrained("Keendata/KeenSQL1.0", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Keendata/KeenSQL1.0 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Keendata/KeenSQL1.0" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Keendata/KeenSQL1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Keendata/KeenSQL1.0
- SGLang
How to use Keendata/KeenSQL1.0 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Keendata/KeenSQL1.0" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Keendata/KeenSQL1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Keendata/KeenSQL1.0" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Keendata/KeenSQL1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Keendata/KeenSQL1.0 with Docker Model Runner:
docker model run hf.co/Keendata/KeenSQL1.0
File size: 7,000 Bytes
a0122bb | 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | ---
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.
```python
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).
|