Text Generation
Transformers
Safetensors
qwen2
text-to-sql
reinforcement-learning
qwen
conversational
text-generation-inference
Run this model with HF Jobs
Run cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct") model = AutoModelForCausalLM.from_pretrained("cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-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-Merge-Qwen2.5-Coder-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct
- SGLang
How to use cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-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-Merge-Qwen2.5-Coder-7B-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-Merge-Qwen2.5-Coder-7B-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-Merge-Qwen2.5-Coder-7B-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-Merge-Qwen2.5-Coder-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct with Docker Model Runner:
docker model run hf.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct
Add comprehensive model card for CSC-SQL model (#1)
Browse files- Add comprehensive model card for CSC-SQL model (393ebe94ea8dbf909c31df61f02a1ec69ce1bb08)
Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110---pipeline_tag: text-generationlibrary_name: transformerslicense: cc-by-nc-4.0tags:- text-to-sql- reinforcement-learning- qwen---
# CSC-SQL: Corrective Self-Consistency in Text-to-SQL via Reinforcement Learning
This repository contains the `CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct` model, a key component of the CSC-SQL framework, as presented in the paper [CSC-SQL: Corrective Self-Consistency in Text-to-SQL via Reinforcement Learning](https://huggingface.co/papers/2505.13271).
## AbstractLarge 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%.
For more details, refer to the [paper](https://huggingface.co/papers/2505.13271) and the [official GitHub repository](https://github.com/CycloneBoy/csc_sql).
## Framework Overview
## CodeThe official code repository for CSC-SQL is available on GitHub: [https://github.com/CycloneBoy/csc_sql](https://github.com/CycloneBoy/csc_sql)
## Main ResultsPerformance comparison of different Text-to-SQL methods on BIRD dev and test dataset:<img src="https://raw.githubusercontent.com/CycloneBoy/csc_sql/main/data/image/csc_sql_result_main.png" height="500" alt="csc_sql_result main">
## Model CheckpointsThis model is part of a collection of checkpoints related to CSC-SQL, also available on Hugging Face:
| **Model** | HuggingFace ||-------------------------------|--------------------------------------------------------------------------------------------|| CscSQL-Merge-Qwen2.5-Coder-3B-Instruct | [🤗 HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-3B-Instruct) || CscSQL-Merge-Qwen2.5-Coder-7B-Instruct | [🤗 HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Merge-Qwen2.5-Coder-7B-Instruct) || CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct | [🤗 HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-3B-Instruct) || CscSQL-Grpo-XiYanSQL-QwenCoder-3B-2502 | [🤗 HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-XiYanSQL-QwenCoder-3B-2502) || CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct | [🤗 HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct) || CscSQL-Grpo-XiYanSQL-QwenCoder-7B-2502 | [🤗 HuggingFace](https://huggingface.co/cycloneboy/CscSQL-Grpo-XiYanSQL-QwenCoder-7B-2502) |
## UsageYou can load this model using the `transformers` library. Here's a basic example for inference:
```pythonimport torchfrom transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
model_name = "cycloneboy/CscSQL-Grpo-Qwen2.5-Coder-7B-Instruct"
# Load model and tokenizertokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype=torch.bfloat16, # Or torch.float16 depending on your hardware device_map="auto")model.eval()
# Example prompt for text-to-SQL generation# Note: The prompt format might need to align with the model's specific training# and database schema format for optimal text-to-SQL performance.prompt = "Translate the following question to SQL: 'What are the names of all employees?'"
# Encode the promptinput_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
# Set generation configuration based on the model's generation_config.jsongeneration_config = GenerationConfig( bos_token_id=tokenizer.bos_token_id, eos_token_id=[tokenizer.eos_token_id, 151643], # Include <|endoftext|> as eos_token_id pad_token_id=tokenizer.bos_token_id, # Or use tokenizer.pad_token_id if different temperature=0.7, max_new_tokens=512, do_sample=True, top_p=0.8, repetition_penalty=1.1, top_k=20,)
# Generate SQL queryoutput_ids = model.generate( input_ids, generation_config=generation_config)
# Decode the generated SQLgenerated_sql = tokenizer.decode(output_ids[0], skip_special_tokens=True)print(generated_sql)
# For detailed usage, including how to integrate with the full CSC-SQL framework# for improved accuracy via reinforcement learning, please refer to the# official GitHub repository: https://github.com/CycloneBoy/csc_sql```
## CitationIf you find this work helpful or inspiring, please feel free to cite it:
```bibtex@misc{sheng2025cscsqlcorrectiveselfconsistencytexttosql, title={CSC-SQL: Corrective Self-Consistency in Text-to-SQL via Reinforcement Learning}, author={Lei Sheng and Shuai-Shuai Xu}, year={2025}, eprint={2505.13271}, archivePrefix={arXiv}, primaryClass={cs.CL}, url={https://arxiv.org/abs/2505.13271}, }```README.mdAdded+110