Text Generation
Transformers
Safetensors
English
qwen2
sql
text-to-sql
qlora
unsloth
qwen2.5
database
natural-language-to-sql
conversational
text-generation-inference
Instructions to use sriksven/SQLForge-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sriksven/SQLForge-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sriksven/SQLForge-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("sriksven/SQLForge-7B") model = AutoModelForCausalLM.from_pretrained("sriksven/SQLForge-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use sriksven/SQLForge-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sriksven/SQLForge-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sriksven/SQLForge-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/sriksven/SQLForge-7B
- SGLang
How to use sriksven/SQLForge-7B 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 "sriksven/SQLForge-7B" \ --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": "sriksven/SQLForge-7B", "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 "sriksven/SQLForge-7B" \ --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": "sriksven/SQLForge-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio new
How to use sriksven/SQLForge-7B with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for sriksven/SQLForge-7B to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for sriksven/SQLForge-7B to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for sriksven/SQLForge-7B to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="sriksven/SQLForge-7B", max_seq_length=2048, ) - Docker Model Runner
How to use sriksven/SQLForge-7B with Docker Model Runner:
docker model run hf.co/sriksven/SQLForge-7B
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-7B-Instruct
|
| 4 |
+
tags:
|
| 5 |
+
- sql
|
| 6 |
+
- text-to-sql
|
| 7 |
+
- qlora
|
| 8 |
+
- unsloth
|
| 9 |
+
- qwen2.5
|
| 10 |
+
- database
|
| 11 |
+
- natural-language-to-sql
|
| 12 |
+
datasets:
|
| 13 |
+
- gretelai/synthetic_text_to_sql
|
| 14 |
+
language:
|
| 15 |
+
- en
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
library_name: transformers
|
| 18 |
+
model-index:
|
| 19 |
+
- name: SQLForge-7B
|
| 20 |
+
results: []
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# SQLForge-7B
|
| 24 |
+
|
| 25 |
+
A fine-tuned **Qwen2.5-7B-Instruct** model specialized for **natural language to SQL generation**. Given a database schema and a question in plain English, it writes the correct SQL query and explains what it does.
|
| 26 |
+
|
| 27 |
+
## Key Details
|
| 28 |
+
|
| 29 |
+
| | |
|
| 30 |
+
|---|---|
|
| 31 |
+
| **Base model** | Qwen/Qwen2.5-7B-Instruct |
|
| 32 |
+
| **Method** | QLoRA (4-bit NF4, rank 16, alpha 16) |
|
| 33 |
+
| **Library** | Unsloth + TRL SFTTrainer |
|
| 34 |
+
| **Dataset** | gretelai/synthetic_text_to_sql (10K examples from 100K) |
|
| 35 |
+
| **Hardware** | NVIDIA RTX A5000 (24GB VRAM) on RunPod |
|
| 36 |
+
| **Training time** | ~2.75 hours (500 steps) |
|
| 37 |
+
| **Final loss** | 0.414 |
|
| 38 |
+
| **Parameters trained** | 40.4M of 7.66B (0.53%) |
|
| 39 |
+
| **Format** | ChatML |
|
| 40 |
+
| **Output** | Merged 16-bit safetensors |
|
| 41 |
+
|
| 42 |
+
## Dataset
|
| 43 |
+
|
| 44 |
+
Trained on 10,000 examples from the [gretelai/synthetic_text_to_sql](https://huggingface.co/datasets/gretelai/synthetic_text_to_sql) dataset, which covers 100 domains with a wide range of SQL complexity levels including subqueries, joins, aggregations, window functions, and set operations. Each example includes the database schema (CREATE TABLE statements), a natural language question, the correct SQL query, and an explanation.
|
| 45 |
+
|
| 46 |
+
## Usage
|
| 47 |
+
|
| 48 |
+
### Transformers
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 52 |
+
|
| 53 |
+
model = AutoModelForCausalLM.from_pretrained("sriksven/SQLForge-7B")
|
| 54 |
+
tokenizer = AutoTokenizer.from_pretrained("sriksven/SQLForge-7B")
|
| 55 |
+
|
| 56 |
+
messages = [
|
| 57 |
+
{
|
| 58 |
+
"role": "system",
|
| 59 |
+
"content": "You are an expert SQL assistant. Given a database schema and a natural language question, write the correct SQL query and explain what it does.",
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"role": "user",
|
| 63 |
+
"content": (
|
| 64 |
+
"Schema:\n"
|
| 65 |
+
"CREATE TABLE employees (id INT, name VARCHAR(100), department VARCHAR(50), salary DECIMAL(10,2));\n"
|
| 66 |
+
"CREATE TABLE departments (name VARCHAR(50), budget DECIMAL(12,2));\n\n"
|
| 67 |
+
"Question: What is the average salary by department, only showing departments with average salary above 75000?"
|
| 68 |
+
),
|
| 69 |
+
},
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
|
| 73 |
+
outputs = model.generate(inputs, max_new_tokens=512)
|
| 74 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Unsloth (faster inference)
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
from unsloth import FastLanguageModel
|
| 81 |
+
|
| 82 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 83 |
+
model_name="sriksven/SQLForge-7B",
|
| 84 |
+
max_seq_length=2048,
|
| 85 |
+
load_in_4bit=True,
|
| 86 |
+
)
|
| 87 |
+
FastLanguageModel.for_inference(model)
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## SQL Complexity Coverage
|
| 91 |
+
|
| 92 |
+
The training data includes queries across multiple complexity levels:
|
| 93 |
+
- Simple SELECT with WHERE clauses
|
| 94 |
+
- Aggregations with GROUP BY and HAVING
|
| 95 |
+
- Single and multiple JOINs
|
| 96 |
+
- Subqueries and correlated subqueries
|
| 97 |
+
- Window functions (ROW_NUMBER, RANK, LAG, LEAD)
|
| 98 |
+
- Set operations (UNION, INTERSECT, EXCEPT)
|
| 99 |
+
- Data definition (CREATE, ALTER, INSERT)
|
| 100 |
+
|
| 101 |
+
## Intended Use
|
| 102 |
+
|
| 103 |
+
- Natural language interfaces to databases
|
| 104 |
+
- SQL copilot tools for analysts and developers
|
| 105 |
+
- Educational tools for learning SQL
|
| 106 |
+
- Prototyping data query systems
|
| 107 |
+
|
| 108 |
+
## Limitations
|
| 109 |
+
|
| 110 |
+
- Trained on synthetic data, not real production database queries
|
| 111 |
+
- May not handle highly domain-specific or proprietary SQL dialects
|
| 112 |
+
- Best with standard SQL syntax (PostgreSQL/MySQL style)
|
| 113 |
+
- Does not validate against a live database — SQL correctness is not guaranteed
|
| 114 |
+
- Long or deeply nested schemas may exceed the 2048 token context
|
| 115 |
+
|
| 116 |
+
## Training Infrastructure
|
| 117 |
+
|
| 118 |
+
| | |
|
| 119 |
+
|---|---|
|
| 120 |
+
| **GPU** | NVIDIA RTX A5000 24GB |
|
| 121 |
+
| **Cloud** | RunPod ($0.27/hr) |
|
| 122 |
+
| **Framework** | Unsloth 2026.5.2 + TRL + Transformers 5.5.0 |
|
| 123 |
+
| **Precision** | BF16 training, 4-bit NF4 base quantization |
|
| 124 |
+
| **Optimizer** | AdamW 8-bit |
|
| 125 |
+
| **Learning rate** | 2e-4, linear decay |
|
| 126 |
+
| **Batch size** | 16 effective (4 per device × 4 accumulation) |
|
| 127 |
+
| **Packing** | Enabled |
|
| 128 |
+
|
| 129 |
+
## Source Code
|
| 130 |
+
|
| 131 |
+
Training scripts: [github.com/sriksven/LLM-FineTune-Suite](https://github.com/sriksven/LLM-FineTune-Suite)
|
| 132 |
+
|
| 133 |
+
## License
|
| 134 |
+
|
| 135 |
+
Apache 2.0
|