Views
No views yet


| Model and Dataset | HuggingFace |
|---|---|
| CscSQL-Merge-Qwen2.5-Coder-3B-Instruct | 🤗 HuggingFace |
| CscSQL-Merge-Qwen2.5-Coder-7B-Instruct | 🤗 HuggingFace |
| CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct | 🤗 HuggingFace |
| CscSQL-Grpo-XiYanSQL-QwenCoder-3B-2502 | 🤗 HuggingFace |
| CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct | 🤗 HuggingFace |
| CscSQL-Grpo-XiYanSQL-QwenCoder-7B-2502 | 🤗 HuggingFace |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
3
4model_dir = "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct" # Or other released models
5
6def load_model_tokenizer(model_path):
7 tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
8 tokenizer.eos_token = "<|im_end|>"
9 tokenizer.pad_token = "<|endoftext|>"
10 tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids(tokenizer.eos_token)
11 tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids(tokenizer.pad_token)
12 tokenizer.padding_side = "left"
13
14 model = AutoModelForCausalLM.from_pretrained(model_path, device_map='auto',torch_dtype=torch.bfloat16, trust_remote_code=True)
15 return model, tokenizer
16
17# Example usage for a natural language question (Text-to-SQL)
18# Make sure your input string ends with "<|im_start|>assistant
19" for generation
20text_list = ["""
21<|im_start|>user
22Your task is to write a SQLite query given a natural language question and a database schema.
23You need to generate the SQL query that answers the question correctly.
24
25For example, to find out the names of all the songs, given:
26CREATE TABLE songs (
27 song_id INTEGER PRIMARY KEY,
28 song_name TEXT
29);
30Question: What are the names of all the songs?
31SQL: SELECT song_name FROM songs
32
33To find the artist of the song 'Yesterday', given:
34CREATE TABLE songs (
35 song_id INTEGER PRIMARY KEY,
36 song_name TEXT,
37 artist_id INTEGER
38);
39CREATE TABLE artists (
40 artist_id INTEGER PRIMARY KEY,
41 artist_name TEXT
42);
43Question: Who is the artist of the song 'Yesterday'?
44SQL: SELECT T2.artist_name FROM songs AS T1 JOIN artists AS T2 ON T1.artist_id = T2.artist_id WHERE T1.song_name = 'Yesterday'
45
46Now, answer the following question.
47Question: How many records are there in the table 'songs'?
48SQL:
49<|im_end|>
50<|im_start|>assistant
51"""]
52
53model, tokenizer = load_model_tokenizer(model_dir)
54inputs = tokenizer(text_list, return_tensors='pt', padding=True, add_special_tokens=False).to('cuda')
55input_ids = inputs["input_ids"]
56attention_mask = inputs["attention_mask"]
57generation_config = GenerationConfig(
58 eos_token_id=tokenizer.eos_token_id,
59 pad_token_id=tokenizer.pad_token_id,
60 temperature=0.1,
61 max_new_tokens=512,
62 num_return_sequences=1,
63 num_beams=1,
64 top_p=0.95,
65 do_sample=False
66)
67outputs = model.generate(
68 inputs= input_ids,
69 attention_mask=attention_mask,
70 **generation_config.to_dict()
71)
72gen_text = tokenizer.batch_decode(outputs[:, input_ids.shape[1]:], skip_special_tokens=True)
73print(gen_text[0])
74
75# Expected output: SELECT count(*) FROM songs1@misc{sheng2025cscsqlcorrectiveselfconsistencytexttosql,
2 title={CSC-SQL: Corrective Self-Consistency in Text-to-SQL via Reinforcement Learning},
3 author={Lei Sheng and Shuai-Shuai Xu},
4 year={2025},
5 eprint={2505.13271},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2505.13271},
9}