Downloads · 30 days
7
15% of all-time downloads
mohamed-ahmed-58059/Llama-3.1-8B-text2sql-wikisql
Llama-3.1-8B-text2sql-wikisql is a text generation model from mohamed-ahmed-58059. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as llama3.1.
Built with Llama. A QLoRA fine-tune of meta-llama/Llama-3.1-8B for text-to-SQL on WikiSQL.
Downloads · 30 days
7
15% of all-time downloads
All-time downloads
46
Public
Repo size
185 MB
Likes
0
Public
Click a slice to open those files.
.safetensors168 MB · 91%
From the Hugging Face model README
Built with Llama. A QLoRA fine-tune of
meta-llama/Llama-3.1-8Bfor text-to-SQL on WikiSQL.
This LoRA adapter turns the Llama-3.1-8B base model into a text-to-SQL generator. On WikiSQL dev it reaches 0.915 execution accuracy — beating a frontier-cheap API model (GPT-5.4-nano, 0.721) at effectively zero per-query cost (runs locally).
Execution accuracy = run the predicted SQL against the real database and compare result sets to the gold query (not string match).
| Model | exact |
|---|---|
| Llama-3.1-8B (base, zero-shot) | 0.222 |
| Hermes-3-8B (instruct, zero-shot) | 0.668 |
| GPT-5.4-nano (frontier-cheap, zero-shot) | 0.721 |
| This model (Llama-3.1-8B + QLoRA) | 0.915 |
The model was trained on this exact prompt — match it or accuracy drops. The schema is
a CREATE TABLE block; generation begins after the final SQL: line.
Construct a SQL statement using the following schema and question:
Schema:
CREATE TABLE players (
"name" TEXT,
"school_club_team" TEXT,
"no" REAL
)
Question: What school did player number 21 play for?
SQL:
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = "meta-llama/Llama-3.1-8B"
tok = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, device_map="auto", load_in_4bit=True)
model = PeftModel.from_pretrained(model, "mohamed-ahmed-58059/Llama-3.1-8B-text2sql-wikisql")
prompt = '''Construct a SQL statement using the following schema and question:
Schema:
CREATE TABLE players (
"name" TEXT,
"school_club_team" TEXT,
"no" REAL
)
Question: What school did player number 21 play for?
SQL:
'''
ids = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**ids, max_new_tokens=128, do_sample=False)
print(tok.decode(out[0][ids.input_ids.shape[1]:], skip_special_tokens=True))
vllm serve meta-llama/Llama-3.1-8B --enable-lora \
--lora-modules text2sql=mohamed-ahmed-58059/Llama-3.1-8B-text2sql-wikisql \
--max-lora-rank 16
# then request model="text2sql"
SFTTrainer, completion-only loss.Full pipeline (data prep, training, execution-accuracy eval) is open source: github.com/mohamed-ahmed-58059/hf-ml-platform-text2sql.finetune
Governed by the Llama 3.1 Community License. Built with Llama.