Llama 3.2 3B Text-to-SQL — Q4_K_M GGUF
A Q4_K_M quantized GGUF version of my fine-tuned Llama 3.2 3B Text-to-SQL model, designed for efficient local inference with llama.cpp and other GGUF-compatible runtimes.
The model converts natural-language questions and database schemas into SQL queries.
Model Details
Parameter Value Base Model meta-llama/Llama-3.2-3BFine-tuned Model farehaheha/llama3.2-3B-text-to-sqlQuantization Q4_K_MFormat GGUF Model Size ~2 GB Task Text-to-SQL Model Type Completion model
Original Model
This GGUF model is a quantized version of:
farehaheha/llama3.2-3B-text-to-sql
The original model was fine-tuned using QLoRA on approximately 5,850 Text-to-SQL examples from the Gretel AI Synthetic Text-to-SQL dataset.
Important: This Is a Completion Model
This model was fine-tuned as a completion model, not as an instruction or chat model.
For best results, use the same prompt format used during fine-tuning:
1 ### Database Schema:
2 {your_database_schema}
3
4 ### Request:
5 {your_natural_language_request}
6
7 ### SQL Query:
The model should continue directly from ### SQL Query:.
Avoid wrapping the prompt in chat templates or system/user/assistant messages.
Run with llama.cpp
Start llama-server:
1 llama-server \
2 -m llama3.2-3b-text-to-sql-q4_k_m.gguf \
3 --port 8080 \
4 -ngl 99 \
5 -c 4096
On Windows:
.\llama-server.exe -m ".\llama3.2-3b-text-to-sql-q4_k_m.gguf" --port 8080 -ngl 99 -c 4096
Inference with Python
Once llama-server is running on port 8080, send the prompt directly to the completion endpoint:
1 import requests
2
3 schema = """
4 CREATE TABLE salesperson (
5 salesperson_id INT,
6 name TEXT,
7 region TEXT
8 );
9
10 CREATE TABLE timber_sales (
11 sales_id INT,
12 salesperson_id INT,
13 volume REAL,
14 sale_date DATE
15 );
16 """
17
18 request = """
19 What is the total volume of timber sold by each salesperson?
20 """
21
22 prompt = f"""### Database Schema:
23 { schema }
24
25 ### Request:
26 { request }
27
28 ### SQL Query:
29 """
30
31 response = requests . post (
32 "http://localhost:8080/completion" ,
33 json = {
34 "prompt" : prompt ,
35 "n_predict" : 256 ,
36 "temperature" : 0.0 ,
37 "stop" : [ "###" ]
38 } ,
39 timeout = 60
40 )
41
42 response . raise_for_status ( )
43
44 sql = response . json ( ) [ "content" ] . strip ( )
45 print ( sql )
Example output:
1 SELECT salesperson_id , SUM ( volume ) AS total_volume
2 FROM timber_sales
3 GROUP BY salesperson_id ;
Inference Settings
Recommended settings for deterministic Text-to-SQL generation:
Parameter Recommended Value Temperature 0.0Max Tokens 128–256Stop Sequence ###Endpoint /completion
For Text-to-SQL, greedy decoding is generally preferred over creative sampling.
Python Inference Script
A simple Python example using llama-server is available in the project repository:
llama_cpp_tryout.py
The script:
starts from the model's completion-style prompt format
sends requests to a local llama-server
uses the /completion endpoint
generates SQL directly from the provided schema and natural-language request
Why Q4_K_M?
Q4_K_M provides a practical balance between:
reduced model size
lower memory usage
faster local inference
preservation of model quality
At approximately 2 GB, this version is intended to make the model easier to run on consumer hardware.
Limitations
The model may generate syntactically valid but logically incorrect SQL.
Performance depends on schema complexity and how clearly the request is written.
Generated SQL should be validated before execution in production environments.
The model was fine-tuned using examples from the test split of the source dataset, so that split should not be used for unbiased evaluation.
Acknowledgements
Built using:
Meta Llama 3.2 3B
Unsloth
Gretel AI Synthetic Text-to-SQL dataset
llama.cpp
License
Apache 2.0