Text Generation
Transformers
Safetensors
qwen2
text-to-sql
reinforcement-learning
code-generation
conversational
text-generation-inference
Instructions to use cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct") model = AutoModelForCausalLM.from_pretrained("cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct
- SGLang
How to use cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct 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 "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct" \ --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": "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct", "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 "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct" \ --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": "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct with Docker Model Runner:
docker model run hf.co/cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct
Add comprehensive model card for CSC-SQL (#1)
Browse files- Add comprehensive model card for CSC-SQL (eed5f5a82f138d70bbe4693f91ec6fdf7080d660)
Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>
README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
+
library_name: transformers
|
| 5 |
+
tags:
|
| 6 |
+
- text-to-sql
|
| 7 |
+
- reinforcement-learning
|
| 8 |
+
- qwen2
|
| 9 |
+
- code-generation
|
| 10 |
+
datasets:
|
| 11 |
+
- cycloneboy/bird_train
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# CSC-SQL: Corrective Self-Consistency in Text-to-SQL via Reinforcement Learning
|
| 15 |
+
|
| 16 |
+
This repository contains the models and code for the paper [CSC-SQL: Corrective Self-Consistency in Text-to-SQL via Reinforcement Learning](https://arxiv.org/abs/2505.13271).
|
| 17 |
+
|
| 18 |
+
π [Paper on arXiv](https://arxiv.org/abs/2505.13271) | π» [GitHub Repository](https://github.com/CycloneBoy/csc_sql)
|
| 19 |
+
|
| 20 |
+
## Introduction
|
| 21 |
+
|
| 22 |
+
Large language models (LLMs) have demonstrated strong capabilities in translating natural language questions about relational databases into SQL queries. In particular, test-time scaling techniques such as Self-Consistency and Self-Correction can enhance SQL generation accuracy by increasing computational effort during inference. However, these methods have notable limitations: Self-Consistency may select suboptimal outputs despite majority votes, while Self-Correction typically addresses only syntactic errors. To leverage the strengths of both approaches, we propose **CSC-SQL**, a novel method that integrates Self-Consistency and Self-Correction. CSC-SQL selects the two most frequently occurring outputs from parallel sampling and feeds them into a merge revision model for correction. Additionally, we employ the Group Relative Policy Optimization (GRPO) algorithm to fine-tune both the SQL generation and revision models via reinforcement learning, significantly enhancing output quality. Experimental results confirm the effectiveness and generalizability of CSC-SQL. On the BIRD private test set, our 7B model achieves 71.72% execution accuracy, while the 32B model achieves 73.67%.
|
| 23 |
+
|
| 24 |
+

|
| 25 |
+
|
| 26 |
+
## Main Results
|
| 27 |
+
|
| 28 |
+
Performance Comparison of different Text-to-SQL methods on BIRD dev and test dataset. On the BIRD private test set, our 7B model achieves 71.72% execution accuracy, while the 32B model achieves 73.67%.
|
| 29 |
+
|
| 30 |
+
<img src="https://github.com/CycloneBoy/csc_sql/raw/main/data/image/csc_sql_result_main.png" height="500" alt="CSC-SQL Main Results">
|
| 31 |
+
|
| 32 |
+
## Model Checkpoints
|
| 33 |
+
|
| 34 |
+
The available models are fine-tuned on Qwen2.5-Coder and are accessible on Hugging Face:
|
| 35 |
+
|
| 36 |
+
| **Model and Dataset** | HuggingFace |
|
| 37 |
+
| :------------------------------------- | :------------------------------------------------------------------------------------------ |
|
| 38 |
+
| CscSQL-Merge-Qwen2.5-Coder-3B-Instruct | [π€ HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-3B-Instruct) |
|
| 39 |
+
| CscSQL-Merge-Qwen2.5-Coder-7B-Instruct | [π€ HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct) |
|
| 40 |
+
| CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct | [π€ HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct) |
|
| 41 |
+
| CscSQL-Grpo-XiYanSQL-QwenCoder-3B-2502 | [π€ HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-XiYanSQL-QwenCoder-3B-2502) |
|
| 42 |
+
| CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct | [π€ HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct) |
|
| 43 |
+
| CscSQL-Grpo-XiYanSQL-QwenCoder-7B-2502 | [π€ HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-XiYanSQL-QwenCoder-7B-2502) |
|
| 44 |
+
|
| 45 |
+
## Quickstart
|
| 46 |
+
|
| 47 |
+
You can use this model with the `transformers` library. The `config.json` indicates `Qwen2ForCausalLM` as its architecture.
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
import torch
|
| 51 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
| 52 |
+
|
| 53 |
+
model_name = "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct"
|
| 54 |
+
|
| 55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 56 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 57 |
+
model_name,
|
| 58 |
+
torch_dtype=torch.bfloat16,
|
| 59 |
+
device_map="auto"
|
| 60 |
+
)
|
| 61 |
+
model.eval()
|
| 62 |
+
|
| 63 |
+
# Example usage for text-to-SQL generation
|
| 64 |
+
question = "List the names of all employees."
|
| 65 |
+
db_schema = "CREATE TABLE employees (id INT, name TEXT, salary INT);"
|
| 66 |
+
prompt = f"Question: {question}
|
| 67 |
+
Schema: {db_schema}
|
| 68 |
+
SQL: "
|
| 69 |
+
|
| 70 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 71 |
+
|
| 72 |
+
generation_config = GenerationConfig(
|
| 73 |
+
max_new_tokens=128,
|
| 74 |
+
do_sample=True,
|
| 75 |
+
temperature=0.7,
|
| 76 |
+
top_k=20,
|
| 77 |
+
top_p=0.8,
|
| 78 |
+
repetition_penalty=1.05,
|
| 79 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 80 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
with torch.no_grad():
|
| 84 |
+
outputs = model.generate(
|
| 85 |
+
**inputs,
|
| 86 |
+
generation_config=generation_config
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 90 |
+
print(f"Generated SQL: {response}")
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
## Citation
|
| 94 |
+
|
| 95 |
+
If you find our work helpful or inspiring, please feel free to cite our paper:
|
| 96 |
+
|
| 97 |
+
```bibtex
|
| 98 |
+
@misc{sheng2025cscsqlcorrectiveselfconsistencytexttosql,
|
| 99 |
+
title={CSC-SQL: Corrective Self-Consistency in Text-to-SQL via Reinforcement Learning},
|
| 100 |
+
author={Lei Sheng and Shuai-Shuai Xu},
|
| 101 |
+
year={2025},
|
| 102 |
+
eprint={2505.13271},
|
| 103 |
+
archivePrefix={arXiv},
|
| 104 |
+
primaryClass={cs.CL},
|
| 105 |
+
url={https://arxiv.org/abs/2505.13271},
|
| 106 |
+
}
|
| 107 |
+
```
|