初始化项目,由ModelHub XC社区提供模型

Model: jk200201/qwen2.5-coder-7b-bird-cot
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-07-17 18:07:11 +08:00
commit a5513eea96
9 changed files with 327 additions and 0 deletions

36
.gitattributes vendored Normal file
View File

@@ -0,0 +1,36 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text

126
README.md Normal file
View File

@@ -0,0 +1,126 @@
---
license: apache-2.0
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
pipeline_tag: text-generation
library_name: transformers
language:
- en
tags:
- text-to-sql
- sql
- bird
- chain-of-thought
- reasoning
- qwen2.5-coder
- gguf
- llama.cpp
datasets:
- jk200201/bird-cot-sft
model-index:
- name: qwen2.5-coder-7b-bird-cot
results:
- task:
type: text-generation
name: Text-to-SQL
dataset:
type: bird
name: BIRD (dev)
metrics:
- type: accuracy
name: Result accuracy (greedy)
value: 52.1
- type: accuracy
name: Result accuracy (self-consistency, K=8)
value: 58.5
---
# Qwen2.5-Coder-7B BIRD CoT (Text-to-SQL)
A 7B text-to-SQL model that reasons step by step over a database schema and then writes the SQL. It is fine-tuned from `Qwen/Qwen2.5-Coder-7B-Instruct` by distilling execution-verified chain-of-thought solutions.
On BIRD dev (realistic, messy schemas, the harder text-to-SQL benchmark) it reaches **52.1% greedy** result accuracy and **58.5% with self-consistency** (Best-of-N, K=8). With self-consistency it matches DeepSeek V4-Pro (1.6T parameters) at roughly 0.4% of the size, running locally.
![BIRD dev results](bird_results.png)
## Results: BIRD dev (execution result accuracy)
All models use a single chain-of-thought sample unless noted, so the comparison is like for like.
| Model | Params | Result accuracy |
|:--|--:|--:|
| Base Qwen2.5-Coder-7B-Instruct | 7B | 27.0% |
| **This model, greedy** | **7B** | **52.1%** |
| **This model, self-consistency (K=8)** | **7B** | **58.5%** |
| DeepSeek V4-Pro | 1.6T | 58.7% |
| GLM 5.2 | 744B | 63.0% |
Result accuracy is the fraction of queries whose SQL executes to the same rows as the gold query (BIRD's official execution metric). The larger frontier models score higher, as expected. The point is that a 7B reaches their accuracy band at a fraction of the size and cost. The 58.5% figure uses K=8 self-consistency (roughly 8x inference).
## Usage
Prompt the model to reason step by step. It returns the reasoning followed by a fenced SQL block. Take the last SQL block as the query.
```python
import re, torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "jk200201/qwen2.5-coder-7b-bird-cot"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
SYSTEM = ("You are an expert SQLite query writer. Reason step by step about the schema "
"and the question, then output the final query in a fenced sql code block.")
def build_prompt(schema, question):
return ("Given the database schema and question, work out the correct SQLite query step by step.\n\n"
f"Database Schema:\n{schema}\n\nQuestion: {question}\n\n"
"Think step by step, then give the final answer in a fenced sql block.")
messages = [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": build_prompt(
"CREATE TABLE singer (Singer_ID INT, Name TEXT, Age INT);",
"How many singers are older than 40?")},
]
text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tok(text, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
resp = tok.decode(out[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
sql = re.findall(r"```(?:sql)?\s*(.*?)```", resp, re.DOTALL)[-1].strip()
print(sql)
```
For best accuracy (58.5%), sample K=8 at temperature 0.8, execute each candidate, and take the majority result (self-consistency).
## Model family
| Artifact | Repo |
|:--|:--|
| Merged model (this repo) | `jk200201/qwen2.5-coder-7b-bird-cot` |
| LoRA adapter | `jk200201/qwen2.5-coder-7b-bird-cot-lora` |
| Training data | `jk200201/bird-cot-sft` |
## Training
Reasoning distillation (CoT-SFT). A strong teacher (Qwen3-Coder-480B) generated step-by-step CoT solutions on BIRD train. Only execution-verified-correct chains were kept (5,593 examples), then supervised fine-tuned into the 7B. Distilling the teacher's reasoning generalized across BIRD's cross-domain dev databases better than distilling SQL answers directly.
Config: QLoRA (4-bit NF4, LoRA rank 32, alpha 64), 2 epochs, learning rate 2e-4 cosine, max sequence length 8192.
## Limitations
- Tuned for BIRD-style analytic SQL over realistic schemas. Unusual dialects or domains may need adaptation. It emits SQLite dialect.
- Greedy (52.1%) is the deployable single-shot number. The 58.5% figure needs K=8 self-consistency (roughly 8x inference).
- This is a 7B model. Review generated SQL before running it on production data.
## Citation
```bibtex
@misc{qwen25coder7b_bird_cot_2026,
title = {Qwen2.5-Coder-7B BIRD CoT: reasoning distillation for text-to-SQL},
author = {Jenish Kothari},
year = {2026}
}
```
## Acknowledgements
Base model: Qwen2.5-Coder by Alibaba Qwen. Teacher: Qwen3-Coder-480B. Benchmark: BIRD (bird-bench.github.io).

BIN
bird_results.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

54
chat_template.jinja Normal file
View File

@@ -0,0 +1,54 @@
{%- if tools %}
{{- '<|im_start|>system\n' }}
{%- if messages[0]['role'] == 'system' %}
{{- messages[0]['content'] }}
{%- else %}
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
{%- endif %}
{{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
{%- for tool in tools %}
{{- "\n" }}
{{- tool | tojson }}
{%- endfor %}
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
{%- if messages[0]['role'] == 'system' %}
{{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
{%- else %}
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- for message in messages %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{{- '<|im_start|>' + message.role }}
{%- if message.content %}
{{- '\n' + message.content }}
{%- endif %}
{%- for tool_call in message.tool_calls %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '\n<tool_call>\n{"name": "' }}
{{- tool_call.name }}
{{- '", "arguments": ' }}
{{- tool_call.arguments | tojson }}
{{- '}\n</tool_call>' }}
{%- endfor %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
{{- '<|im_start|>user' }}
{%- endif %}
{{- '\n<tool_response>\n' }}
{{- message.content }}
{{- '\n</tool_response>' }}
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- endif %}

61
config.json Normal file
View File

@@ -0,0 +1,61 @@
{
"architectures": [
"Qwen2ForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 151643,
"dtype": "bfloat16",
"eos_token_id": 151645,
"hidden_act": "silu",
"hidden_size": 3584,
"initializer_range": 0.02,
"intermediate_size": 18944,
"layer_types": [
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention"
],
"max_position_embeddings": 32768,
"max_window_layers": 28,
"model_type": "qwen2",
"num_attention_heads": 28,
"num_hidden_layers": 28,
"num_key_value_heads": 4,
"pad_token_id": null,
"rms_norm_eps": 1e-06,
"rope_parameters": {
"rope_theta": 1000000.0,
"rope_type": "default"
},
"sliding_window": null,
"tie_word_embeddings": false,
"transformers_version": "5.13.1",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 152064
}

14
generation_config.json Normal file
View File

@@ -0,0 +1,14 @@
{
"bos_token_id": 151643,
"do_sample": true,
"eos_token_id": [
151645,
151643
],
"pad_token_id": 151643,
"repetition_penalty": 1.1,
"temperature": 0.7,
"top_k": 20,
"top_p": 0.8,
"transformers_version": "5.13.1"
}

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:432a36746704cd4f5bfb157a6e0884c74818de60bfe643cc606d847c246df57e
size 15231272152

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
size 11421892

30
tokenizer_config.json Normal file
View File

@@ -0,0 +1,30 @@
{
"add_prefix_space": false,
"backend": "tokenizers",
"bos_token": null,
"clean_up_tokenization_spaces": false,
"eos_token": "<|im_end|>",
"errors": "replace",
"extra_special_tokens": [
"<|im_start|>",
"<|im_end|>",
"<|object_ref_start|>",
"<|object_ref_end|>",
"<|box_start|>",
"<|box_end|>",
"<|quad_start|>",
"<|quad_end|>",
"<|vision_start|>",
"<|vision_end|>",
"<|vision_pad|>",
"<|image_pad|>",
"<|video_pad|>"
],
"is_local": false,
"local_files_only": false,
"model_max_length": 32768,
"pad_token": "<|endoftext|>",
"split_special_tokens": false,
"tokenizer_class": "Qwen2Tokenizer",
"unk_token": null
}