Views
No views yet
CREATE TABLE schema and a natural-language question, generate the corresponding SQL query.1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name="/workspace/outputs/granite_sql_train/checkpoint-6000",
5 load_in_4bit=False,
6 device_map="cuda:0",
7)
8FastLanguageModel.for_inference(model)
9
10instruction = """Generate ONLY the SQL query for the following database.
11
12Do not explain your answer.
13Do not include markdown.
14Do not include any additional text.
15
16Schema:
17{schema}
18
19Question:
20{question}
21
22SQL:"""
23
24messages = [{"role": "user", "content": [{"type": "text", "text": instruction.format(schema=schema, question=question)}]}]
25input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
26inputs = tokenizer(input_text, add_special_tokens=False, return_tensors="pt").to("cuda")
27output = model.generate(**inputs, max_new_tokens=256, use_cache=True, temperature=0.7, top_p=0.8, top_k=20)train_test_split(test_size=10000, seed=42, shuffle=True): remaining rows for train, 10,000 held out for eval.q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj, shared_mlp.input_linear, shared_mlp.output_linear,
trained with Unsloth + TRL SFTTrainer.adapter_model.safetensors).b-mc2/sql-create-context (see Training Data), evaluated by SFT eval loss (cross-entropy) every 200 steps.| Checkpoint | Step | Eval loss |
|---|---|---|
| checkpoint-4000 | 4000 | 0.02830 |
| checkpoint-5000 | 5000 | 0.02811 |
| checkpoint-6000 | 6000 | 0.02673 (best saved) |
| checkpoint-6432 (final) | 6432 | ~0.02746 (nearest eval at step 6400) |
load_best_model_at_end was not enabled, so this checkpoint
was selected manually by comparing eval_loss across saved checkpoints.