Instructions to use aayush0325/llama-3.2-1b-text2sql-lora-r32 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use aayush0325/llama-3.2-1b-text2sql-lora-r32 with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Llama-3.2-1B-Instruct") model = PeftModel.from_pretrained(base_model, "aayush0325/llama-3.2-1b-text2sql-lora-r32") - Notebooks
- Google Colab
- Kaggle
Llama-3.2-1B-Instruct Text-to-SQL LoRA (r=32, MLP)
A LoRA adapter fine-tuned on gretelai/synthetic_text_to_sql to turn a natural
language question plus a SQLite schema into a single SQL query. This is the best
of five LoRA configurations trained in a sweep; it is an adapter only β load
it on top of the base model below.
This repository contains only the PEFT adapter weights. The base model remains
unsloth/Llama-3.2-1B-Instruct (a public mirror of meta-llama/Llama-3.2-1B-Instruct).
Model details
| Base model | unsloth/Llama-3.2-1B-Instruct |
| Adapter type | LoRA (r=32, alpha=64, dropout=0.1) |
| Target modules | gate_proj, up_proj, down_proj |
| Trainable parameters | 15,728,640 |
| Training data | gretelai/synthetic_text_to_sql (train split, 100k rows) |
| Eval data | test split (500 rows for loss) + 32 hand-curated rows for SQLite execution |
| Hardware | Modal L4 (24 GB), ~3h for this config |
| Precision | BF16 with SDPA/FlashAttention kernels, padding-free batches |
| Optimizer | Fused AdamW, lr 2e-4, weight decay 0.01, Ξ²=(0.9, 0.95) |
| Schedule | 3% linear warmup β cosine decay, 1 epoch, effective batch 16 |
| Max sequence length | 1024 tokens |
The prompt the model was trained on is exactly:
System: You are a SQL expert. Given a database schema and a question, respond with a single valid SQL query and nothing else.
User: ### Schema (SQLite)
{sql_context}
### Question
{sql_prompt}
Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE = "unsloth/Llama-3.2-1B-Instruct"
ADAPTER = "aayush0325/llama-3.2-1b-text2sql-lora-r32"
tokenizer = AutoTokenizer.from_pretrained(BASE)
model = AutoModelForCausalLM.from_pretrained(
BASE, dtype=torch.bfloat16, device_map="auto"
)
model = PeftModel.from_pretrained(model, ADAPTER).eval()
messages = [
{"role": "system", "content": "You are a SQL expert. Given a database schema and a question, respond with a single valid SQL query and nothing else."},
{"role": "user", "content": "### Schema (SQLite)\nCREATE TABLE staff (id INT, name TEXT, salary FLOAT);\n\n### Question\nWhat are the names of staff earning more than 50000?"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Generated text may include a markdown SQL fence; strip it and any trailing text before executing.
Evaluation
Predictions and reference SQL were both executed against an in-memory SQLite
database built from each row's sql_context. A prediction counts as correct only
if it executes and returns exactly the same rows as the reference query.
Rigorous comparison on a deterministic 2,000-row test subset (1,998 rows
usable after the executable-SQL filter), with the same rows used for every
model. Wilson 95% confidence intervals and paired McNemar tests are from
scripts/compare_eval.py in the training repo.
| model | exec accuracy (95% CI) | valid SQL rate | McNemar p vs this adapter |
|---|---|---|---|
| base (no adapter) | 0.5390 [0.5171, 0.5608] | 0.8669 | 2.8e-98 |
| attn_r8 | 0.7497 [0.7303, 0.7683] | 0.9294 | 5.2e-07 |
| attn_mlp_r16 | 0.7768 [0.7580, 0.7945] | 0.9464 | 0.228 |
| this adapter (mlp_r32) | 0.7833 [0.7647, 0.8008] | 0.9565 | β |
| attn_r64_rslora | 0.7758 [0.7570, 0.7935] | 0.9510 | 0.214 |
| all_linear_r16_dora | 0.7808 [0.7621, 0.7984] | 0.9525 | 0.682 |
For reference, on the earlier 32-row eval this adapter scored 0.8438 accuracy
versus 0.5000 for the base, with eval loss 0.1890 (500 held-out rows) β the
lowest of the five configs. The 2,000-row eval supersedes that small test:
this adapter is still nominally best, but the ~1-point gaps to attn_mlp_r16,
attn_r64_rslora and all_linear_r16_dora are not statistically significant
(all bootstrap CIs for the paired difference cross zero). Only the base model
and the small attn_r8 adapter are significantly worse.
Execution accuracy, not loss, is the metric that matters for text-to-SQL: lower next-token loss does not guarantee correct SQL, and a syntactically valid query can still return the wrong rows.
Limitations and license
- Trained on synthetic SQL from a single dataset; expect degraded performance on
schemas or SQL dialects unlike those in
gretelai/synthetic_text_to_sql. - SQLite evaluation uses exact row equality; semantically equivalent queries with different column order are counted as incorrect.
- Not evaluated on other text-to-SQL benchmarks.
- The adapter is derived from Llama 3.2 and is subject to the Llama 3.2 license.
- The training dataset is licensed Apache-2.0 (Gretel AI).
- Downloads last month
- 34
Model tree for aayush0325/llama-3.2-1b-text2sql-lora-r32
Base model
meta-llama/Llama-3.2-1B-Instruct