siruenyian commited on
Commit
80469dc
·
verified ·
1 Parent(s): 75871d7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +129 -1
README.md CHANGED
@@ -1,5 +1,133 @@
1
  ---
2
- license: apache-2.0
 
 
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