Instructions to use siruenyian/sqlgenerator-mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use siruenyian/sqlgenerator-mini with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("./granite-4.0-350b") model = PeftModel.from_pretrained(base_model, "siruenyian/sqlgenerator-mini") - Transformers
How to use siruenyian/sqlgenerator-mini with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="siruenyian/sqlgenerator-mini") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("siruenyian/sqlgenerator-mini", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use siruenyian/sqlgenerator-mini with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "siruenyian/sqlgenerator-mini" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "siruenyian/sqlgenerator-mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/siruenyian/sqlgenerator-mini
- SGLang
How to use siruenyian/sqlgenerator-mini 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 "siruenyian/sqlgenerator-mini" \ --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": "siruenyian/sqlgenerator-mini", "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 "siruenyian/sqlgenerator-mini" \ --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": "siruenyian/sqlgenerator-mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use siruenyian/sqlgenerator-mini 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 siruenyian/sqlgenerator-mini 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 siruenyian/sqlgenerator-mini to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for siruenyian/sqlgenerator-mini to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="siruenyian/sqlgenerator-mini", max_seq_length=2048, ) - Docker Model Runner
How to use siruenyian/sqlgenerator-mini with Docker Model Runner:
docker model run hf.co/siruenyian/sqlgenerator-mini
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,5 +1,133 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
- unsloth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: unsloth/granite-4.0-350m-unsloth-bnb-4bit
|
| 3 |
+
library_name: peft
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
tags:
|
| 6 |
+
- base_model:adapter:unsloth/granite-4.0-350m-unsloth-bnb-4bit
|
| 7 |
+
- lora
|
| 8 |
+
- sft
|
| 9 |
+
- transformers
|
| 10 |
+
- trl
|
| 11 |
- unsloth
|
| 12 |
+
- text-to-sql
|
| 13 |
+
license: apache-2.0
|
| 14 |
+
datasets:
|
| 15 |
+
- b-mc2/sql-create-context
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Model Card for granite_sql (checkpoint-6000)
|
| 19 |
+
|
| 20 |
+
LoRA adapter fine-tuning IBM Granite 4.0 350M for text-to-SQL generation: given a
|
| 21 |
+
`CREATE TABLE` schema and a natural-language question, generate the corresponding SQL query.
|
| 22 |
+
|
| 23 |
+
## Model Details
|
| 24 |
+
|
| 25 |
+
### Model Description
|
| 26 |
+
|
| 27 |
+
This checkpoint (step 6000 of 6432, epoch 2.80/3) is the best-performing checkpoint
|
| 28 |
+
of the run — lowest eval loss among all saved checkpoints (see Results).
|
| 29 |
+
|
| 30 |
+
- **Model type:** LoRA adapter (PEFT) on a causal LM
|
| 31 |
+
- **Language(s):** SQL (generation), English (instructions)
|
| 32 |
+
- **License:** Apache 2.0 (inherited from base model)
|
| 33 |
+
- **Finetuned from model:** [unsloth/granite-4.0-350m-unsloth-bnb-4bit](https://huggingface.co/unsloth/granite-4.0-350m-unsloth-bnb-4bit) (IBM Granite 4.0, 350M, GraniteMoeHybrid)
|
| 34 |
+
|
| 35 |
+
## How to Get Started with the Model
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
from unsloth import FastLanguageModel
|
| 39 |
+
|
| 40 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 41 |
+
model_name="/workspace/outputs/granite_sql_train/checkpoint-6000",
|
| 42 |
+
load_in_4bit=False,
|
| 43 |
+
device_map="cuda:0",
|
| 44 |
+
)
|
| 45 |
+
FastLanguageModel.for_inference(model)
|
| 46 |
+
|
| 47 |
+
instruction = """Generate ONLY the SQL query for the following database.
|
| 48 |
+
|
| 49 |
+
Do not explain your answer.
|
| 50 |
+
Do not include markdown.
|
| 51 |
+
Do not include any additional text.
|
| 52 |
+
|
| 53 |
+
Schema:
|
| 54 |
+
{schema}
|
| 55 |
+
|
| 56 |
+
Question:
|
| 57 |
+
{question}
|
| 58 |
+
|
| 59 |
+
SQL:"""
|
| 60 |
+
|
| 61 |
+
messages = [{"role": "user", "content": [{"type": "text", "text": instruction.format(schema=schema, question=question)}]}]
|
| 62 |
+
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
| 63 |
+
inputs = tokenizer(input_text, add_special_tokens=False, return_tensors="pt").to("cuda")
|
| 64 |
+
output = model.generate(**inputs, max_new_tokens=256, use_cache=True, temperature=0.7, top_p=0.8, top_k=20)
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## Training Details
|
| 68 |
+
|
| 69 |
+
### Training Data
|
| 70 |
+
|
| 71 |
+
[b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context) —
|
| 72 |
+
schema + natural-language-question + SQL-answer triples. Split via
|
| 73 |
+
`train_test_split(test_size=10000, seed=42, shuffle=True)`: remaining rows for train, 10,000 held out for eval.
|
| 74 |
+
|
| 75 |
+
### Training Procedure
|
| 76 |
+
|
| 77 |
+
LoRA (r=16, alpha=32, dropout=0, bias=none, no rslora) applied to
|
| 78 |
+
`q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj, shared_mlp.input_linear, shared_mlp.output_linear`,
|
| 79 |
+
trained with Unsloth + TRL SFTTrainer.
|
| 80 |
+
|
| 81 |
+
#### Training Hyperparameters
|
| 82 |
+
|
| 83 |
+
- **Training regime:** bf16 mixed precision
|
| 84 |
+
- Epochs: 3 | Per-device train batch size: 32 | Per-device eval batch size: 64 | Grad accumulation: 1
|
| 85 |
+
- Learning rate: 2e-4, linear schedule, 50 warmup steps
|
| 86 |
+
- Optimizer: adamw_8bit, weight decay 0.001, max grad norm 1.0
|
| 87 |
+
- Seed: 3407 | Eval every 200 steps | Save every 500 steps
|
| 88 |
+
|
| 89 |
+
#### Speeds, Sizes, Times
|
| 90 |
+
|
| 91 |
+
Full run: 6432 steps / 3 epochs, train_runtime ≈ 2567s. This adapter checkpoint: ~26.7MB (`adapter_model.safetensors`).
|
| 92 |
+
|
| 93 |
+
## Evaluation
|
| 94 |
+
|
| 95 |
+
### Testing Data & Metrics
|
| 96 |
+
|
| 97 |
+
10,000-row held-out split of `b-mc2/sql-create-context` (see Training Data), evaluated by SFT eval loss (cross-entropy) every 200 steps.
|
| 98 |
+
|
| 99 |
+
### Results
|
| 100 |
+
|
| 101 |
+
| Checkpoint | Step | Eval loss |
|
| 102 |
+
|---|---|---|
|
| 103 |
+
| checkpoint-4000 | 4000 | 0.02830 |
|
| 104 |
+
| checkpoint-5000 | 5000 | 0.02811 |
|
| 105 |
+
| **checkpoint-6000** | **6000** | **0.02673 (best saved)** |
|
| 106 |
+
| checkpoint-6432 (final) | 6432 | ~0.02746 (nearest eval at step 6400) |
|
| 107 |
+
|
| 108 |
+
Lowest eval_loss observed during training was 0.02630 at step 5200, but no checkpoint was
|
| 109 |
+
saved at that exact step (checkpoints every 500 steps, eval every 200), so checkpoint-6000
|
| 110 |
+
is the closest usable minimum. `load_best_model_at_end` was not enabled, so this checkpoint
|
| 111 |
+
was selected manually by comparing `eval_loss` across saved checkpoints.
|
| 112 |
+
|
| 113 |
+
## Compute Infrastructure
|
| 114 |
+
|
| 115 |
+
### Hardware
|
| 116 |
+
|
| 117 |
+
- 1× NVIDIA A100 40GB
|
| 118 |
+
|
| 119 |
+
### Software
|
| 120 |
+
|
| 121 |
+
- Unsloth
|
| 122 |
+
- Transformers
|
| 123 |
+
- PyTorch
|
| 124 |
+
|
| 125 |
---
|
| 126 |
+
|
| 127 |
+
## Model Card Authors
|
| 128 |
+
|
| 129 |
+
- Yian
|
| 130 |
+
|
| 131 |
+
## Contact
|
| 132 |
+
|
| 133 |
+
- https://github.com/Siruenyian
|