Update README.md
Browse files
README.md
CHANGED
@@ -3,20 +3,76 @@ base_model: XGenerationLab/XiYanSQL-QwenCoder-7B-2502
|
|
3 |
tags:
|
4 |
- text-generation-inference
|
5 |
- transformers
|
6 |
-
- unsloth
|
7 |
-
- qwen2
|
8 |
-
- trl
|
9 |
license: apache-2.0
|
10 |
-
language:
|
11 |
-
- en
|
12 |
---
|
13 |
|
14 |
-
# Uploaded model
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
-
|
|
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
tags:
|
4 |
- text-generation-inference
|
5 |
- transformers
|
|
|
|
|
|
|
6 |
license: apache-2.0
|
|
|
|
|
7 |
---
|
8 |
|
|
|
9 |
|
10 |
+
# Notes in "XGenerationLab/XiYanSQL-QwenCoder-7B-2502":
|
11 |
+
## Requirements
|
12 |
+
```
|
13 |
+
transformers >= 4.37.0
|
14 |
+
```
|
15 |
+
## Quickstart
|
16 |
|
17 |
+
Here 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.
|
18 |
+
Currently, we mainly support mainstream dialects like SQLite, PostgreSQL, and MySQL.
|
19 |
|
20 |
+
```
|
21 |
+
|
22 |
+
nl2sqlite_template_cn = """你是一名{dialect}专家,现在需要阅读并理解下面的【数据库schema】描述,以及可能用到的【参考信息】,并运用{dialect}知识生成sql语句回答【用户问题】。
|
23 |
+
【用户问题】
|
24 |
+
{question}
|
25 |
+
|
26 |
+
【数据库schema】
|
27 |
+
{db_schema}
|
28 |
+
|
29 |
+
【参考信息】
|
30 |
+
{evidence}
|
31 |
+
|
32 |
+
【用户问题】
|
33 |
+
{question}
|
34 |
+
|
35 |
+
```sql"""
|
36 |
+
|
37 |
+
import torch
|
38 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
39 |
+
|
40 |
+
model_name = "beyoru/QwenCoderSQL_bnb_4bit"
|
41 |
+
model = AutoModelForCausalLM.from_pretrained(
|
42 |
+
model_name,
|
43 |
+
torch_dtype=torch.bfloat16,
|
44 |
+
device_map="auto"
|
45 |
+
)
|
46 |
+
|
47 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
48 |
+
|
49 |
+
## dialects -> ['SQLite', 'PostgreSQL', 'MySQL']
|
50 |
+
prompt = nl2sqlite_template_cn.format(dialect="", db_schema="", question="", evidence="")
|
51 |
+
message = [{'role': 'user', 'content': prompt}]
|
52 |
+
|
53 |
+
text = tokenizer.apply_chat_template(
|
54 |
+
message,
|
55 |
+
tokenize=False,
|
56 |
+
add_generation_prompt=True
|
57 |
+
)
|
58 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
59 |
+
|
60 |
+
generated_ids = model.generate(
|
61 |
+
**model_inputs,
|
62 |
+
pad_token_id=tokenizer.pad_token_id,
|
63 |
+
eos_token_id=tokenizer.eos_token_id,
|
64 |
+
max_new_tokens=1024,
|
65 |
+
temperature=0.1,
|
66 |
+
top_p=0.8,
|
67 |
+
do_sample=True,
|
68 |
+
)
|
69 |
+
generated_ids = [
|
70 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
71 |
+
]
|
72 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
73 |
+
|
74 |
+
```
|
75 |
+
|
76 |
+
|
77 |
+
## Acknowledgments
|
78 |
+
If 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!
|