XGenerationLab/XiYanSQL-QwenCoder-3B-2502
5201
1---2license: apache-2.03pipeline_tag: text-generation4tags:5- Text-to-SQL6- SQL7- NL2SQL8---9 10### Important Links11 12🤖[Github](https://github.com/XGenerationLab/XiYanSQL-QwenCoder) |13🤗[ModelScope](https://modelscope.cn/collections/XiYanSQL-Models-4483337b614241) |14📖[XiYan-SQL](https://github.com/XGenerationLab/XiYan-SQL) |15🌕[析言GBI](https://bailian.console.aliyun.com/xiyan) |16📄[Paper](https://arxiv.org/abs/2507.04701)17 18 19## Introduction20We are excited to open source the XiYanSQL-QwenCoder series model, dedicated to advancing the development of LLMs in the text-to-SQL domain. As of now, XiYanSQL-QwenCoder covers four mainstream model sizes: 3B, 7B, 14B, and 32B parameters, to meet the needs of different developers.21- The XiYanSQL-QwenCoder model demonstrates strong performance in SQL generation, with the XiYanSQL-QwenCoder-32B achieving a 69.03% EX score on the BIRD TEST set, setting a new SOTA with a single fine-tuned model. Other models in the series also maintain a leading position at their respective sizes.22- The XiYanSQL-QwenCoder model supports multiple SQL dialects, such as SQLite, PostgreSQL, and MySQL.23- The XiYanSQL-QwenCoder model can be used directly for text-to-SQL tasks or serve as a better starting point for fine-tuning SQL models.24 25 26## Model Downloads27 28 29| **Model** | **Download Latest** |30|-----------|------------------|31|XiYanSQL-QwenCoder-3B |💻[HuggingFace](https://huggingface.co/XGenerationLab/XiYanSQL-QwenCoder-3B-2502) 🤗[Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-3B-2502)|32|XiYanSQL-QwenCoder-7B |💻[HuggingFace](https://huggingface.co/XGenerationLab/XiYanSQL-QwenCoder-7B-2502) 🤗[Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-7B-2502)|33|XiYanSQL-QwenCoder-14B |💻[HuggingFace](https://huggingface.co/XGenerationLab/XiYanSQL-QwenCoder-14B-2502) 🤗[Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-14B-2502)|34|XiYanSQL-QwenCoder-32B |💻[HuggingFace](https://huggingface.co/XGenerationLab/XiYanSQL-QwenCoder-32B-2412) 🤗[Modelscope](https://www.modelscope.cn/models/XGenerationLab/XiYanSQL-QwenCoder-32B-2412)|35 36 37 38## Performance39The XiYanSQL-QwenCoder models, as multi-dialect SQL base models, demonstrating robust SQL generation capabilities. The following presents the evaluation results at the time of release. We conducted a comprehensive evaluation of the model's performance under two schema formats, M-Schema, and original DDL, using the BIRD and Spider benchmarks in the Text-to-SQL domain.40 41| Model name|BIRD Dev@M-Schema |BIRD Dev@DDL|Spider Test@M-Schema|Spider Test@DDL|42|-----------|:------------------:|:---------------:|:-------------------:|:---------------:|43|Codellama-34b | 33.05% | - | 67.74% | - |44|Deepseek-coder-33b | 47.52% | 44.72% | 72.39% | - |45|TableGPT2 | 46.35% | 47.07% | 74.76% | 77.28% |46|Codestral 22b | 50.52% | 47.00% | 78.45% | 75.47% |47|GLM-4-plus | 54.37% | - | 79.40% | - |48|Claude35_sonnet-1022 | 53.32% | 50.46% | 76.27% | 73.04% |49|Deepseek(v2.5-1210) | 55.74% | 55.61% | 82.08% | 80.57% |50|Gemini-1.5-pro | 61.34% | 57.89% | 85.11% | 84.00% |51|GPT-4o-0806 | 58.47% | 54.82% | 82.89% | 78.45% |52|XiYanSQL-QwenCoder-3B | 54.11% | 53.19% | 82.69% | 78.85% |53|XiYanSQL-QwenCoder-7B | 59.78% | 56.58% | 84.86% | 80.31% |54|XiYanSQL-QwenCoder-14B | 63.10% | 60.37% | 85.76% | 82.79% |55|XiYanSQL-QwenCoder-32B | 67.01% | 63.04% | 88.39% | 85.46% |56 57 58## Requirements59 60transformers >= 4.37.061 62## Quickstart63 64Here is a simple code snippet for quickly using **XiYanSQL-QwenCoder** model. We provide a Chinese version of the prompt, and you just need to replace the placeholders for "question," "db_schema," and "evidence" to get started. We recommend using our [M-Schema](https://github.com/XGenerationLab/M-Schema) format for the schema; other formats such as DDL are also acceptable, but they may affect performance.65Currently, we mainly support mainstream dialects like SQLite, PostgreSQL, and MySQL.66 67```python68 69nl2sqlite_template_cn = """你是一名{dialect}专家,现在需要阅读并理解下面的【数据库schema】描述,以及可能用到的【参考信息】,并运用{dialect}知识生成sql语句回答【用户问题】。70【用户问题】71{question}72 73【数据库schema】74{db_schema}75 76【参考信息】77{evidence}78 79【用户问题】80{question}81 82```sql"""83 84import torch85from transformers import AutoModelForCausalLM, AutoTokenizer86 87model_name = "XGenerationLab/XiYanSQL-QwenCoder-3B-2502"88model = AutoModelForCausalLM.from_pretrained(89 model_name,90 torch_dtype=torch.bfloat16,91 device_map="auto"92)93 94tokenizer = AutoTokenizer.from_pretrained(model_name)95 96## dialects -> ['SQLite', 'PostgreSQL', 'MySQL']97prompt = nl2sqlite_template_cn.format(dialect="", db_schema="", question="", evidence="")98message = [{'role': 'user', 'content': prompt}]99 100text = tokenizer.apply_chat_template(101 message,102 tokenize=False,103 add_generation_prompt=True104)105model_inputs = tokenizer([text], return_tensors="pt").to(model.device)106 107generated_ids = model.generate(108 **model_inputs,109 pad_token_id=tokenizer.pad_token_id,110 eos_token_id=tokenizer.eos_token_id,111 max_new_tokens=1024,112 temperature=0.1,113 top_p=0.8,114 do_sample=True,115)116generated_ids = [117 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)118]119response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]120 121```122 123### Inference with vLLM124```python125from vllm import LLM, SamplingParams126from transformers import AutoTokenizer127model_path = "XGenerationLab/XiYanSQL-QwenCoder-3B-2502"128llm = LLM(model=model_path, tensor_parallel_size=8)129tokenizer = AutoTokenizer.from_pretrained(model_path)130sampling_params = SamplingParams(131 n=1,132 temperature=0.1,133 max_tokens=1024134)135## dialects -> ['SQLite', 'PostgreSQL', 'MySQL']136prompt = nl2sqlite_template_cn.format(dialect="", db_schema="", question="", evidence="")137message = [{'role': 'user', 'content': prompt}]138text = tokenizer.apply_chat_template(139 message,140 tokenize=False,141 add_generation_prompt=True142)143outputs = llm.generate([text], sampling_params=sampling_params)144response = outputs[0].outputs[0].text145```146 147 148## Acknowledgments149If you find our work useful, please give us a citation or a like, so we can make a greater contribution to the open-source community!150```bibtex151@article{XiYanSQL,152 title={XiYan-SQL: A Novel Multi-Generator Framework For Text-to-SQL}, 153 author={Yifu Liu and Yin Zhu and Yingqi Gao and Zhiling Luo and Xiaoxia Li and Xiaorong Shi and Yuntao Hong and Jinyang Gao and Yu Li and Bolin Ding and Jingren Zhou},154 year={2025},155 eprint={2507.04701},156 archivePrefix={arXiv},157 primaryClass={cs.CL},158 url={https://arxiv.org/abs/2507.04701}, 159}160```