Views
No views yet
16 (rank of the low-rank matrices)64 (scaling factor for the low-rank update){q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj}0.05"none" (bias terms are frozen)True (half-precision training)7e-55501import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5
6
7prompt = """Question: What is the total horses record for each farm, sorted ascending?
8CREATE TABLE competition_record (
9 Competition_ID number, -- example: [1, 2]
10 Farm_ID number, -- example: [2, 3]
11 Rank number, -- example: [1, 2]
12 PRIMARY KEY (Competition_ID),
13 CONSTRAINT fk_competition_record_competition_id FOREIGN KEY (Competition_ID) REFERENCES farm_competition (Competition_ID),
14 CONSTRAINT fk_competition_record_farm_id FOREIGN KEY (Farm_ID) REFERENCES farm (Farm_ID)
15);
16
17CREATE TABLE city (
18 City_ID number, -- example: [1, 2]
19 Status text, -- example: ['Town', 'Village']
20 PRIMARY KEY (City_ID)
21);
22
23CREATE TABLE farm_competition (
24 Competition_ID number, -- example: [1, 2]
25 Host_city_ID number, -- example: [1, 2]
26 PRIMARY KEY (Competition_ID),
27 CONSTRAINT fk_farm_competition_host_city_id FOREIGN KEY (Host_city_ID) REFERENCES city (City_ID)
28);
29
30CREATE TABLE farm (
31 Farm_ID number, -- example: [1, 2]
32 Total_Horses number, -- example: [5056.5, 5486.9]
33 Total_Cattle number, -- example: [8374.5, 8604.8]
34 PRIMARY KEY (Farm_ID)
35);
36What is the total horses record for each farm, sorted ascending?
37SQL: SELECT SUM(Total_Horses) AS Total_Horses, Farm_ID
38FROM farm
39GROUP BY Farm_ID
40ORDER BY SUM(Total_Horses) ASC;
41Is the SQL correct?"""
42
43base_model = AutoModelForCausalLM.from_pretrained("seeklhy/OmniSQL-7B", torch_dtype="auto", device_map="auto")
44peft_model = PeftModel.from_pretrained(base_model, "sisinflab-ai/GradeSQL-7B-ORM-Spider")
45orm_model = peft_model.merge_and_unload()
46orm_tokenizer = AutoTokenizer.from_pretrained("seeklhy/OmniSQL-7B", use_fast=True)
47
48del base_model
49del peft_model
50
51inputs = orm_tokenizer(prompt, return_tensors="pt").to(orm_model.device)
52
53with torch.no_grad():
54 outputs = orm_model.generate(**inputs, max_new_tokens=1, return_dict_in_generate=True, output_scores=True, use_cache=False)
55
56 generated_ids = outputs.sequences[0, len(inputs.input_ids[0]):]
57 yes_token_id = orm_tokenizer.convert_tokens_to_ids("ĠYes")
58 no_token_id = orm_tokenizer.convert_tokens_to_ids("ĠNo")
59
60 yes_no_pos = None
61 for i, token_id in enumerate(generated_ids):
62 if token_id in [yes_token_id, no_token_id]:
63 yes_no_pos = i
64 break
65
66 if yes_no_pos is None:
67 print("[Warning]: No 'Yes' or 'No' token found in the generated output.")
68 print("[Score]: 0.5")
69
70 logits = outputs.scores[yes_no_pos]
71 probs = torch.softmax(logits, dim=-1)
72 yes_prob = probs[0, yes_token_id].item()
73 generated_answer = "Yes" if generated_ids[yes_no_pos] == yes_token_id else "No"
74
75 if generated_answer == "Yes":
76 print("[Score]: ", yes_prob)
77 elif generated_answer == "No":
78 print("[Score]: ", 0)1@misc{gradesqloutcomerewardmodels2025,
2 title={GradeSQL: Outcome Reward Models for Ranking SQL Queries from Large Language Models},
3 author={Mattia Tritto and Giuseppe Farano and Dario Di Palma and Gaetano Rossiello and Fedelucio Narducci and Dharmashankar Subramanian and Tommaso Di Noia},
4 year={2025},
5 eprint={2509.01308},
6 archivePrefix={arXiv},
7 primaryClass={cs.AI},
8 url={https://arxiv.org/abs/2509.01308},
9}