🚀 析言SQL-QwenCoder-2504
析言SQL-QwenCoder-2504是最新的SQL生成模型,它在之前版本的基礎上持續優化,性能得到顯著提升。該模型結合了微調與GRPO訓練,支持多語言和多種SQL方言,開箱即用,泛化能力強。
重要鏈接
📖Github |
🤖ModelScope |
🌐析言SQL |
🌕析言GBI |
💻Modelscope Space
✨ 主要特性
- 訓練策略先進:結合了微調與GRPO訓練,在不依賴思考過程的情況下運用GRPO的後訓練策略,實現了SQL生成的高效與準確。
- 支持多語言:支持英文和中文。
- 多方言支持:支持SQLite、PostgreSQL和MySQL等主流方言,開箱即用。
- 泛化能力強:在不同方言和域外數據集上表現出色。
📦 安裝指南
依賴要求
- transformers >= 4.37.0
- vllm >= 0.7.2
💻 使用示例
基礎用法
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "XGenerationLab/XiYanSQL-QwenCoder-32B-2504"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = nl2sqlite_template_cn.format(dialect="", db_schema="", question="", evidence="")
message = [{'role': 'user', 'content': prompt}]
text = tokenizer.apply_chat_template(
message,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
max_new_tokens=1024,
temperature=0.1,
top_p=0.8,
do_sample=True,
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
高級用法
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_path = "XGenerationLab/XiYanSQL-QwenCoder-32B-2504"
llm = LLM(model=model_path, tensor_parallel_size=8)
tokenizer = AutoTokenizer.from_pretrained(model_path)
sampling_params = SamplingParams(
n=1,
temperature=0.1,
max_tokens=1024
)
prompt = nl2sqlite_template_cn.format(dialect="", db_schema="", question="", evidence="")
message = [{'role': 'user', 'content': prompt}]
text = tokenizer.apply_chat_template(
message,
tokenize=False,
add_generation_prompt=True
)
outputs = llm.generate([text], sampling_params=sampling_params)
response = outputs[0].outputs[0].text
📚 詳細文檔
模型下載
性能評估
析言SQL-QwenCoder系列模型作為多方言SQL基礎模型,展現出強大的SQL生成能力。以下是模型發佈時的評估結果。我們使用BIRD和Spider作為Text-to-SQL領域的SQLite基準,以及PostgreSQL和MySQL方言的DW基準,在M-Schema和原始DDL兩種模式格式下對模型性能進行了全面評估。
模型名稱 |
大小 |
BIRD Dev@M-Schema |
BIRD Dev@DDL |
Spider Test@M-Schema |
Spider Test@DDL |
DW PostgreSQL@M-Schema |
DW MySQL@M-Schema |
GPT-4o-0806 |
UNK |
58.47% |
54.82% |
82.89% |
78.45% |
46.79% |
57.77% |
GPT-4.1-0414 |
UNK |
59.39% |
54.11% |
84.45% |
79.86% |
54.29% |
63.18% |
Claude3.5-sonnet-1022 |
UNK |
53.32% |
50.46% |
76.27% |
73.04% |
55.22% |
52.84% |
Claude3.7-sonnet |
UNK |
54.82% |
49.22% |
78.04% |
74.66% |
53.23% |
54.61% |
Gemini-1.5-Pro |
UNK |
61.34% |
57.89% |
85.11% |
84.00% |
52.78% |
62.78% |
DeepSeek-V2.5-1210 |
236B |
55.74% |
55.61% |
82.08% |
80.57% |
45.74% |
52.18% |
DeepSeek-V3 |
685B |
59.58% |
56.71% |
81.52% |
79.91% |
52.56% |
55.95% |
DeepSeek-R1 |
685B |
58.15% |
55.61% |
80.72% |
78.85% |
60.56% |
62.00% |
DeepSeek-R1-Distill-Qwen-32B |
32B |
50.65% |
48.31% |
78.65% |
77.33% |
37.22% |
44.72% |
Deepseek-Coder-33B-Instruct |
33B |
47.52% |
44.72% |
72.39% |
62.0% |
31.48% |
36.17% |
OmniSQL-32B |
32B |
60.37% |
55.87% |
85.16% |
83.19% |
38.19% |
42.34% |
析言SQL-QwenCoder-3B-2502 |
3B |
53.52% |
52.54% |
83.34% |
79.10% |
34.75% |
35.62% |
析言SQL-QwenCoder-3B-2504 |
3B |
55.08% |
52.09% |
84.10% |
80.57% |
36.65% |
37.63% |
析言SQL-QwenCoder-7B-2502 |
7B |
59.65% |
56.32% |
84.15% |
80.01% |
39.38% |
42.10% |
析言SQL-QwenCoder-7B-2504 |
7B |
62.13% |
57.43% |
85.97% |
82.48% |
42.08% |
44.67% |
析言SQL-QwenCoder-14B-2502 |
14B |
63.23% |
60.10% |
85.31% |
82.84% |
38.51% |
41.62% |
析言SQL-QwenCoder-14B-2504 |
14B |
65.32% |
60.17% |
86.82% |
83.75% |
40.52% |
44.60% |
析言SQL-QwenCoder-32B-2412 |
32B |
67.07% |
63.04% |
88.39% |
85.46% |
45.07% |
52.84% |
析言SQL-QwenCoder-32B-2504 |
32B |
67.14% |
62.26% |
89.20% |
86.17% |
53.52% |
57.74% |
提示模板
nl2sqlite_template_cn = """你是一名{dialect}專家,現在需要閱讀並理解下面的【數據庫schema】描述,以及可能用到的【參考信息】,並運用{dialect}知識生成sql語句回答【用戶問題】。
【用戶問題】
{question}
【數據庫schema】
{db_schema}
【參考信息】
{evidence}
【用戶問題】
{question}
```sql"""
📄 許可證
本項目採用Apache-2.0許可證。
致謝
如果您覺得我們的工作有用,請引用或點贊,讓我們為開源社區做出更大的貢獻!