Delete README_EN.md
Browse files- README_EN.md +0 -547
README_EN.md
DELETED
@@ -1,547 +0,0 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
language:
|
4 |
-
- zh
|
5 |
-
- en
|
6 |
-
library_name: transformers
|
7 |
-
tags:
|
8 |
-
- qihoo360
|
9 |
-
- 奇虎360
|
10 |
-
- zhinao
|
11 |
-
- 360Zhinao
|
12 |
-
- pretrain
|
13 |
-
---
|
14 |
-
|
15 |
-
<div align="center">
|
16 |
-
<h1>
|
17 |
-
360Zhinao (360智脑)
|
18 |
-
</h1>
|
19 |
-
</div>
|
20 |
-
<div align="center">
|
21 |
-
🤖 <a href="https://www.modelscope.cn/profile/qihoo360">ModelScope</a>   |   
|
22 |
-
🔥 <a href="https://github.com/Qihoo360/360zhinao/">GitHub</a>   |   
|
23 |
-
💬 <a href="https://github.com/Qihoo360/360zhinao/tree/main/assets/WeChat.png">WeChat (微信)</a>  
|
24 |
-
</div>
|
25 |
-
<br>
|
26 |
-
<p align="center">
|
27 |
-
Feel free to visit 360Zhinao's official website<a href="https://ai.360.com"> https://ai.360.com</a> for more experience.
|
28 |
-
</p>
|
29 |
-
|
30 |
-
<br>
|
31 |
-
|
32 |
-
# Models Introduction
|
33 |
-
🎉🎉🎉We open-source the 360Zhinao model series:
|
34 |
-
- **360Zhinao-7B-Base**
|
35 |
-
- **360Zhinao-7B-Chat-4K**
|
36 |
-
- **360Zhinao-7B-Chat-32K**
|
37 |
-
- **360Zhinao-7B-Chat-360K**
|
38 |
-
|
39 |
-
|
40 |
-
The characteristics of the 360Zhinao open-source models are:
|
41 |
-
- **Base Model:** Leveraging a high-quality corpus of 3.4 trillion Tokens which mainly consist of Chinese, English and code, we achieved competitive performance on relevant benchmark evaluations of the same model scale.
|
42 |
-
- **Chat Model:** Powerful chat capabilities and three different sequence lengths of 4K, 32K and 360K. 360K (about 500k Chinese characters) is the longest sequcence length among open-sourced Chinese models until now.
|
43 |
-
|
44 |
-
<br>
|
45 |
-
|
46 |
-
# News and Updates
|
47 |
-
- 2024.04.11 We release **360Zhinao-7B** 1.0 version, include the base model and three chat model with sequence lengths of 4K, 32K adn 360K.
|
48 |
-
|
49 |
-
<br>
|
50 |
-
|
51 |
-
# Table of contents
|
52 |
-
- [Download URL](#Download-URL)
|
53 |
-
- [Model Evaluation](#Model-Evaluation)
|
54 |
-
- [Quickstart](#Quickstart)
|
55 |
-
- [Model Inference](#Model-Inference)
|
56 |
-
- [Model Finetune](#Model-Finetune)
|
57 |
-
- [License](#License)
|
58 |
-
|
59 |
-
<br>
|
60 |
-
|
61 |
-
# Download URL
|
62 |
-
See the following table for this release and download links:
|
63 |
-
| Size | Model | BF16 | Int4|
|
64 |
-
|-|-|-|-|
|
65 |
-
| 7B | 360Zhinao-7B-Base | <a href="https://www.modelscope.cn/models/qihoo360/360Zhinao-7B-Base/summary">🤖</a> <a href="https://huggingface.co/qihoo360/360Zhinao-7B-Base">🤗</a> | |
|
66 |
-
| 7B | 360Zhinao-7B-Chat-4K | <a href="https://www.modelscope.cn/models/qihoo360/360Zhinao-7B-Chat-4K/summary">🤖</a> <a href="https://huggingface.co/qihoo360/360Zhinao-7B-Chat-4K">🤗</a> | <a href="https://www.modelscope.cn/models/qihoo360/360Zhinao-7B-Chat-4K-Int4/summary">🤖</a> <a href="https://huggingface.co/qihoo360/360Zhinao-7B-Chat-4K-Int4">🤗</a> |
|
67 |
-
| 7B | 360Zhinao-7B-Chat-32K | <a href="https://www.modelscope.cn/models/qihoo360/360Zhinao-7B-Chat-32K/summary">🤖</a> <a href="https://huggingface.co/qihoo360/360Zhinao-7B-Chat-32K">🤗</a> | <a href="https://www.modelscope.cn/models/qihoo360/360Zhinao-7B-Chat-32K-Int4/summary">🤖</a> <a href="https://huggingface.co/qihoo360/360Zhinao-7B-Chat-32K-Int4">🤗</a> |
|
68 |
-
| 7B | 360Zhinao-7B-Chat-360K | <a href="https://www.modelscope.cn/models/qihoo360/360Zhinao-7B-Chat-360K/summary">🤖</a> <a href="https://huggingface.co/qihoo360/360Zhinao-7B-Chat-360K">🤗</a> | <a href="https://www.modelscope.cn/models/qihoo360/360Zhinao-7B-Chat-360K-Int4/summary">🤖</a> <a href="https://huggingface.co/qihoo360/360Zhinao-7B-Chat-360K-Int4">🤗</a> |
|
69 |
-
|
70 |
-
<br>
|
71 |
-
|
72 |
-
# Model Evaluation
|
73 |
-
## Base Model
|
74 |
-
We evaluate the performance of our model on the OpenCompass evaluation datasets, including C-Eval, AGIEval, MMLU, CMMLU, HellaSwag, MATH, GSM8K, HumanEval, MBPP, BBH, LAMBADA. The ablity evaluated of model include natural language understanding, knowledge, mathematical computation and reasoning, code generation, logical reasoning, etc.
|
75 |
-
|
76 |
-
| <div style="width: 100pt">Model</div> | AVG | CEval | AGIEval | MMLU | CMMLU | HellaSwag | MATH | GSM8K | HumanEval | MBPP | BBH | LAMBADA |
|
77 |
-
|:----------------------|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|
|
78 |
-
| Baichuan2-7B | 41.49 | 56.3 | 34.6 | 54.7 | 57 | 67 | 5.4 | 24.6 | 17.7 | 24 | 41.8 | 73.3 |
|
79 |
-
| Baichuan-7B | 31.94 | 44.7 | 24.6 | 41.5 | 44.6 | 68.4 | 2.5 | 9.6 | 9.1 | 6.4 | 32.8 | 67.1 |
|
80 |
-
| ChatGLM3-6B | **58.67** | 67 | 47.4 | 62.8 | 66.5 | 76.5 | 19.2 | 61 | 44.5 | **57.2** | **66.2** | 77.1 |
|
81 |
-
| DeepSeek-7B | 39.8 | 45 | 24 | 49.3 | 46.8 | 73.4 | 4.2 | 18.3 | 25 | 36.4 | 42.8 | 72.6 |
|
82 |
-
| InternLM2-7B | 58.01 | 65.7 | 50.2 | 65.5 | 66.2 | 79.6 | 19.9 | **70.6** | 41.5 | 42.4 | 64.4 | 72.1 |
|
83 |
-
| InternLM-7B | 39.33 | 53.4 | 36.9 | 51 | 51.8 | 70.6 | 6.3 | 31.2 | 13.4 | 14 | 37 | 67 |
|
84 |
-
| LLaMA-2-7B | 33.27 | 32.5 | 21.8 | 46.8 | 31.8 | 74 | 3.3 | 16.7 | 12.8 | 14.8 | 38.2 | 73.3 |
|
85 |
-
| LLaMA-7B | 30.35 | 27.3 | 20.6 | 35.6 | 26.8 | 74.3 | 2.9 | 10 | 12.8 | 16.8 | 33.5 | 73.3 |
|
86 |
-
| Mistral-7B-v0.1 | 47.67 | 47.4 | 32.8 | 64.1 | 44.7 | 78.9 | 11.3 | 47.5 | 27.4 | 38.6 | 56.7 | 75 |
|
87 |
-
| MPT-7B | 30.06 | 23.5 | 21.3 | 27.5 | 25.9 | 75 | 2.9 | 9.1 | 17.1 | 22.8 | 35.6 | 70 |
|
88 |
-
| Qwen1.5-7B | 55.12 | 73.57 | **50.8** | 62.15 | 71.84 | 72.62 | **20.36** | 54.36 | **53.05** | 36.8 | 40.01 | 70.74 |
|
89 |
-
| Qwen-7B | 49.53 | 63.4 | 45.3 | 59.7 | 62.5 | 75 | 13.3 | 54.1 | 27.4 | 31.4 | 45.2 | 67.5 |
|
90 |
-
| XVERSE-7B | 34.27 | 61.1 | 39 | 58.4 | 60.8 | 73.7 | 2.2 | 11.7 | 4.9 | 10.2 | 31 | 24 |
|
91 |
-
| Yi-6B | 47.8 | 73 | 44.3 | 64 | **73.5** | 73.1 | 6.3 | 39.9 | 15.2 | 23.6 | 44.9 | 68 |
|
92 |
-
| **360Zhinao-7B** | 56.15 | **74.11** | 49.49 | **67.44** | 72.38 | **83.05** | 16.38 | 53.83 | 35.98 | 42.4 | 43.95 | **78.59** |
|
93 |
-
|
94 |
-
The above results could be viewed or reproduced on [Opencompass](https://rank.opencompass.org.cn/leaderboard-llm).
|
95 |
-
|
96 |
-
## Chat Models
|
97 |
-
|
98 |
-
We adopted a two-stage approach to train the long context models.
|
99 |
-
|
100 |
-
**First stage**: We increased RoPE base and extended the context length to 32K.
|
101 |
-
- Firstly, we performed Continual Pretraining on approximately 5B tokens with a 32K context window.
|
102 |
-
- Then during the SFT stage, we fine-tuned the model using long data from various sources, including high-quality human-labeled 32K data.
|
103 |
-
|
104 |
-
**Second stage**: We extended the context length to 360K, training with the following data:
|
105 |
-
- A small amount of high-quality human-labeled super-long data.
|
106 |
-
- Due to the scarcity of annotated super-long data, we constructed various forms of synthetic data.
|
107 |
-
- Multi-Doc QA: Similar to [Ziya-Reader](https://arxiv.org/abs/2311.09198), we generated multi-document QA pairs based on 360's database. Multiple QA pairs are constructed for one row of Multi-Doc QA data input, resulting in a multi-turn format and significantly improving the training efficiency.
|
108 |
-
- Single-Doc QA: Similar to [LLama2 Long](https://arxiv.org/abs/2309.16039), we constructed multi-turn QA data based on different segments within one row of long-text input.
|
109 |
-
|
110 |
-
We evaluated our models across various lengths and benchmarks.
|
111 |
-
|
112 |
-
- ### Long Context Benchmarks
|
113 |
-
|
114 |
-
|
115 |
-
We evaluated our 32K and 360K models on [LongBench](https://github.com/THUDM/LongBench), a multi-task bilingual benchmark for long contexts. We report results on Chinese tasks that are the most relevant to downstream applications: Single/Multi-Doc QA, Summarization, Few-Shot Learning and Code Completion.
|
116 |
-
|
117 |
-
| Model | Avg | 单文档QA | 多文档QA | 摘要 | Few-shot学习 | 代码补全 |
|
118 |
-
| :------------------------ |:---------:|:--------:|:---------:|:---------:|:------------:|:---------:|
|
119 |
-
| GPT-3.5-Turbo-16k | 37.84 | 61.2 | 28.7 | 16 | 29.2 | 54.1 |
|
120 |
-
| ChatGLM2-6B-32k | 37.16 | 51.6 | 37.6 | 16.2 | 27.7 | 52.7 |
|
121 |
-
| ChatGLM3-6B-32k | 44.62 | **62.3** | 44.8 | 17.8 | 42 | 56.2 |
|
122 |
-
| InternLM2-Chat-7B | 42.20 | 56.65 | 29.15 | **17.99** | 43.5 | **63.72** |
|
123 |
-
| Qwen1.5-Chat-7B | 36.75 | 52.85 | 30.08 | 14.28 | 32 | 54.55 |
|
124 |
-
| Qwen1.5-Chat-14B | 39.80 | 60.39 | 27.99 | 14.77 | 37 | 58.87 |
|
125 |
-
| 360Zhinao-7B-Chat-32K | **45.18** | 57.18 | **48.06** | 15.03 | **44** | 61.64 |
|
126 |
-
|
127 |
-
- ### 360Zhinao-7B-Chat-360K on "NeedleInAHaystack"
|
128 |
-
|
129 |
-
[NeedleInAHaystack](https://github.com/gkamradt/LLMTest_NeedleInAHaystack) places one small piece of information in different positions of long text and queries this information as a test of LLM's long-context capabilities.
|
130 |
-
|
131 |
-
360Zhinao-7B-Chat-360K could achieve over 98% accuracy on both English and Chinese NeedleInAHaystack tasks.
|
132 |
-
|
133 |
-
- English version(same as [NeedleInAHaystack](https://github.com/gkamradt/LLMTest_NeedleInAHaystack))
|
134 |
-
|
135 |
-
<p align="center">
|
136 |
-
<img src="assets/360Zhinao-7B-Chat-360K.en_score.png" width="600" />
|
137 |
-
<p>
|
138 |
-
|
139 |
-
**needle**:The best thing to do in San Francisco is eat a sandwich and sit in Dolores Park on a sunny day.
|
140 |
-
|
141 |
-
**query**:What is the best thing to do in San Francisco?
|
142 |
-
|
143 |
-
|
144 |
-
- Chinese version
|
145 |
-
|
146 |
-
<p align="center">
|
147 |
-
<img src="assets/360Zhinao-7B-Chat-360K.zh_score.png" width="600" />
|
148 |
-
<p>
|
149 |
-
|
150 |
-
We constructed the Chinese version following the [SuperCLUE-200K benchmark](https://mp.weixin.qq.com/s/QgoRf2LB-7vc3vTFOHJkpw):
|
151 |
-
|
152 |
-
**haystack**:Chinese novels.
|
153 |
-
|
154 |
-
**needle**:(in Chinese) 王莽是一名勤奋的店员,他每天凌晨就起床,赶在第一缕阳光照亮大地之前到达店铺,为即将开始的一天做准备。他清扫店铺,整理货架,为顾客提供方便。他对五金的种类和用途了如指掌,无论顾客需要什么,他总能准确地找到。\n然而,他的老板刘秀却总是对他吹毛求疵。刘秀是个挑剔的人,他总能在王莽的工作中找出一些小错误,然后以此为由扣他的工资。他对王莽的工作要求非常严格,甚至有些过分。即使王莽做得再好,刘秀也总能找出一些小问题,让王莽感到非常沮丧。\n王莽虽然对此感到不满,但他并没有放弃。他知道,只有通过自己的努力,才能获得更好的生活。他坚持每天早起,尽管他知道那天可能会再次被刘秀扣工资。他始终保持微笑,尽管他知道刘秀可能会再次对他挑剔。
|
155 |
-
|
156 |
-
**query**:(in Chinese) 王莽在谁的手下工作?
|
157 |
-
|
158 |
-
<br>
|
159 |
-
|
160 |
-
# Quickstart
|
161 |
-
Simple examples to illustrate how to use 360Zhinao-7B-Base and 360Zhinao-7B-Chat quickly using 🤖 ModelScope and 🤗 Transformers
|
162 |
-
|
163 |
-
## Dependency Installation
|
164 |
-
- python 3.8 and above
|
165 |
-
- pytorch 2.0 and above
|
166 |
-
- transformers 4.37.2 and above
|
167 |
-
- CUDA 11.4 and above are recommended.
|
168 |
-
|
169 |
-
```shell
|
170 |
-
pip install -r requirements.txt
|
171 |
-
```
|
172 |
-
We recommend installing Flash-Attention (which currently supports flash attention 2) to increase your performance and reduce your memory footprint. (flash-attention is optional and will work without installation)
|
173 |
-
|
174 |
-
>flash-attn >= 2.3.6
|
175 |
-
```shell
|
176 |
-
FLASH_ATTENTION_FORCE_BUILD=TRUE pip install flash-attn==2.3.6
|
177 |
-
```
|
178 |
-
|
179 |
-
## 🤗 Transformers
|
180 |
-
### Demonstration of Base Model Inference
|
181 |
-
|
182 |
-
This code demonstrates fast inference with 360Zhinao-7B-Base models using transformers.
|
183 |
-
```python
|
184 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
185 |
-
from transformers.generation import GenerationConfig
|
186 |
-
|
187 |
-
MODEL_NAME_OR_PATH = "qihoo360/360Zhinao-7B-Base"
|
188 |
-
|
189 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
190 |
-
MODEL_NAME_OR_PATH,
|
191 |
-
trust_remote_code=True)
|
192 |
-
|
193 |
-
model = AutoModelForCausalLM.from_pretrained(
|
194 |
-
MODEL_NAME_OR_PATH,
|
195 |
-
device_map="auto",
|
196 |
-
trust_remote_code=True)
|
197 |
-
|
198 |
-
generation_config = GenerationConfig.from_pretrained(
|
199 |
-
MODEL_NAME_OR_PATH,
|
200 |
-
trust_remote_code=True)
|
201 |
-
|
202 |
-
inputs = tokenizer('中国二十四节气\n1. 立春\n2. 雨水\n3. 惊蛰\n4. 春分\n5. 清明\n', return_tensors='pt')
|
203 |
-
inputs = inputs.to(model.device)
|
204 |
-
|
205 |
-
pred = model.generate(input_ids=inputs["input_ids"], generation_config=generation_config)
|
206 |
-
print("outputs:\n", tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
|
207 |
-
```
|
208 |
-
### Demonstration of Chat Model Inference
|
209 |
-
|
210 |
-
This code demo uses transformers to quickly use the 360Zhinao-7B-Chat-4K model for inference.
|
211 |
-
```python
|
212 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
213 |
-
from transformers.generation import GenerationConfig
|
214 |
-
|
215 |
-
MODEL_NAME_OR_PATH = "qihoo360/360Zhinao-7B-Chat-4K"
|
216 |
-
|
217 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
218 |
-
MODEL_NAME_OR_PATH,
|
219 |
-
trust_remote_code=True)
|
220 |
-
|
221 |
-
model = AutoModelForCausalLM.from_pretrained(
|
222 |
-
MODEL_NAME_OR_PATH,
|
223 |
-
device_map="auto",
|
224 |
-
trust_remote_code=True)
|
225 |
-
|
226 |
-
generation_config = GenerationConfig.from_pretrained(
|
227 |
-
MODEL_NAME_OR_PATH,
|
228 |
-
trust_remote_code=True)
|
229 |
-
|
230 |
-
messages = []
|
231 |
-
#round-1
|
232 |
-
messages.append({"role": "user", "content": "介绍一下刘德华"})
|
233 |
-
response = model.chat(tokenizer=tokenizer, messages=messages, generation_config=generation_config)
|
234 |
-
messages.append({"role": "assistant", "content": response})
|
235 |
-
print(messages)
|
236 |
-
|
237 |
-
#round-2
|
238 |
-
messages.append({"role": "user", "content": "他有什么代表作?"})
|
239 |
-
response = model.chat(tokenizer=tokenizer, messages=messages, generation_config=generation_config)
|
240 |
-
messages.append({"role": "assistant", "content": response})
|
241 |
-
print(messages)
|
242 |
-
```
|
243 |
-
|
244 |
-
## 🤖 ModelScope
|
245 |
-
### Demonstration of Base Model Inference
|
246 |
-
|
247 |
-
This code demonstrates using ModelScope to quickly use the 360Zhinao-7B-Base model for inference.
|
248 |
-
|
249 |
-
```python
|
250 |
-
from modelscope import AutoModelForCausalLM, AutoTokenizer
|
251 |
-
from modelscope import GenerationConfig
|
252 |
-
|
253 |
-
MODEL_NAME_OR_PATH = "qihoo360/360Zhinao-7B-Base"
|
254 |
-
|
255 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
256 |
-
MODEL_NAME_OR_PATH,
|
257 |
-
trust_remote_code=True)
|
258 |
-
|
259 |
-
model = AutoModelForCausalLM.from_pretrained(
|
260 |
-
MODEL_NAME_OR_PATH,
|
261 |
-
device_map="auto",
|
262 |
-
trust_remote_code=True)
|
263 |
-
|
264 |
-
generation_config = GenerationConfig.from_pretrained(
|
265 |
-
MODEL_NAME_OR_PATH,
|
266 |
-
trust_remote_code=True)
|
267 |
-
|
268 |
-
inputs = tokenizer('中国二十四节气\n1. 立春\n2. 雨水\n3. 惊蛰\n4. 春分\n5. 清明\n', return_tensors='pt')
|
269 |
-
inputs = inputs.to(model.device)
|
270 |
-
|
271 |
-
pred = model.generate(input_ids=inputs["input_ids"], generation_config=generation_config)
|
272 |
-
print("outputs:\n", tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
|
273 |
-
```
|
274 |
-
|
275 |
-
### Demonstration of Chat Model Inference
|
276 |
-
|
277 |
-
This code demonstrates using ModelScope to quickly use the 360Zhinao-7B-Chat-4K model for inference.
|
278 |
-
|
279 |
-
```python
|
280 |
-
from modelscope import AutoModelForCausalLM, AutoTokenizer
|
281 |
-
from modelscope import GenerationConfig
|
282 |
-
|
283 |
-
MODEL_NAME_OR_PATH = "qihoo360/360Zhinao-7B-Chat-4K"
|
284 |
-
|
285 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
286 |
-
MODEL_NAME_OR_PATH,
|
287 |
-
trust_remote_code=True)
|
288 |
-
|
289 |
-
model = AutoModelForCausalLM.from_pretrained(
|
290 |
-
MODEL_NAME_OR_PATH,
|
291 |
-
device_map="auto",
|
292 |
-
trust_remote_code=True)
|
293 |
-
|
294 |
-
generation_config = GenerationConfig.from_pretrained(
|
295 |
-
MODEL_NAME_OR_PATH,
|
296 |
-
trust_remote_code=True)
|
297 |
-
|
298 |
-
messages = []
|
299 |
-
#round-1
|
300 |
-
messages.append({"role": "user", "content": "介绍一下刘德华"})
|
301 |
-
response = model.chat(tokenizer=tokenizer, messages=messages, generation_config=generation_config)
|
302 |
-
messages.append({"role": "assistant", "content": response})
|
303 |
-
print(messages)
|
304 |
-
|
305 |
-
#round-2
|
306 |
-
messages.append({"role": "user", "content": "他有什么代表作?"})
|
307 |
-
response = model.chat(tokenizer=tokenizer, messages=messages, generation_config=generation_config)
|
308 |
-
messages.append({"role": "assistant", "content": response})
|
309 |
-
print(messages)
|
310 |
-
```
|
311 |
-
|
312 |
-
## CLI Demo
|
313 |
-
Use terminal interaction for a fast experience
|
314 |
-
```shell
|
315 |
-
python cli_demo.py
|
316 |
-
```
|
317 |
-
<p align="center">
|
318 |
-
<img src="assets/cli_demo.gif" width="600" />
|
319 |
-
<p>
|
320 |
-
|
321 |
-
## Web Demo
|
322 |
-
You can also use web interaction for a quick experience
|
323 |
-
```shell
|
324 |
-
streamlit run web_demo.py
|
325 |
-
```
|
326 |
-
<p align="center">
|
327 |
-
<img src="assets/web_demo.gif" width="600" />
|
328 |
-
<p>
|
329 |
-
|
330 |
-
## API Demo
|
331 |
-
Start command
|
332 |
-
```shell
|
333 |
-
python openai_api.py
|
334 |
-
```
|
335 |
-
|
336 |
-
Request parameter
|
337 |
-
```shell
|
338 |
-
curl --location --request POST 'http://localhost:8360/v1/chat/completions' \
|
339 |
-
--header 'Content-Type: application/json' \
|
340 |
-
--data-raw '{
|
341 |
-
"max_new_tokens": 200,
|
342 |
-
"do_sample": true,
|
343 |
-
"top_k": 0,
|
344 |
-
"top_p": 0.8,
|
345 |
-
"temperature": 1.0,
|
346 |
-
"repetition_penalty": 1.0,
|
347 |
-
"messages": [
|
348 |
-
{
|
349 |
-
"role": "user",
|
350 |
-
"content": "你叫什么名字?"
|
351 |
-
}
|
352 |
-
]
|
353 |
-
}'
|
354 |
-
```
|
355 |
-
|
356 |
-
<br>
|
357 |
-
|
358 |
-
# Model Inference
|
359 |
-
## Quantization
|
360 |
-
We provide quantization schemes based on AutoGPTQ and open source the Int4 quantization models.
|
361 |
-
|
362 |
-
## Deployment
|
363 |
-
### vLLM Installation
|
364 |
-
If you want to deploy and accelerate inference, we recommend using `vLLM==0.3.3`。
|
365 |
-
|
366 |
-
If you are using **CUDA 12.1 and PyTorch 2.1**, you can install vLLM directly with the following command.
|
367 |
-
```shell
|
368 |
-
pip install vllm==0.3.3
|
369 |
-
```
|
370 |
-
|
371 |
-
Otherwise, please refer to the official vLLM [Installation Instructions](https://docs.vllm.ai/en/latest/getting_started/installation.html)。
|
372 |
-
|
373 |
-
>Once the installation is complete, you will need to do the following
|
374 |
-
1. Copy the vllm/zhinao.py file to the vllm/model_executor/models directory corresponding to your env environment.
|
375 |
-
2. Copy the vllm/serving_chat.py file to the vllm/entrypoints/openai corresponding to your env environment.
|
376 |
-
3. Then add a line to vllm/model_executor/models/\_\_init\_\_.py
|
377 |
-
|
378 |
-
```shell
|
379 |
-
"ZhinaoForCausalLM": ("zhinao", "ZhinaoForCausalLM"),
|
380 |
-
```
|
381 |
-
|
382 |
-
### vLLM Service Start
|
383 |
-
|
384 |
-
Starting the service
|
385 |
-
```shell
|
386 |
-
python -m vllm.entrypoints.openai.api_server \
|
387 |
-
--served-model-name 360Zhinao-7B-Chat-4K \
|
388 |
-
--model qihoo360/360Zhinao-7B-Chat-4K \
|
389 |
-
--trust-remote-code \
|
390 |
-
--tensor-parallel-size 1 \
|
391 |
-
--max-model-len 4096 \
|
392 |
-
--host 0.0.0.0 \
|
393 |
-
--port 8360
|
394 |
-
```
|
395 |
-
|
396 |
-
Use curl to request the service
|
397 |
-
```shell
|
398 |
-
curl http://localhost:8360/v1/chat/completions \
|
399 |
-
-H "Content-Type: application/json" \
|
400 |
-
-d '{
|
401 |
-
"model": "360Zhinao-7B-Chat-4K",
|
402 |
-
"max_tokens": 200,
|
403 |
-
"top_k": -1,
|
404 |
-
"top_p": 0.8,
|
405 |
-
"temperature": 1.0,
|
406 |
-
"presence_penalty": 0.0,
|
407 |
-
"frequency_penalty": 0.0,
|
408 |
-
"messages": [
|
409 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
410 |
-
{"role": "user", "content": "你好"}
|
411 |
-
],
|
412 |
-
"stop": [
|
413 |
-
"<eod>",
|
414 |
-
"<|im_end|>",
|
415 |
-
"<|im_start|>"
|
416 |
-
]
|
417 |
-
}'
|
418 |
-
```
|
419 |
-
Use python to request the service
|
420 |
-
```python
|
421 |
-
from openai import OpenAI
|
422 |
-
openai_api_key = "EMPTY"
|
423 |
-
openai_api_base = "http://localhost:8360/v1"
|
424 |
-
|
425 |
-
client = OpenAI(
|
426 |
-
api_key=openai_api_key,
|
427 |
-
base_url=openai_api_base,
|
428 |
-
)
|
429 |
-
|
430 |
-
chat_response = client.chat.completions.create(
|
431 |
-
model="360Zhinao-7B-Chat-4K",
|
432 |
-
messages=[
|
433 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
434 |
-
{"role": "user", "content": "你好"},
|
435 |
-
],
|
436 |
-
stop=[
|
437 |
-
"<eod>",
|
438 |
-
"<|im_end|>",
|
439 |
-
"<|im_start|>"
|
440 |
-
],
|
441 |
-
presence_penalty=0.0,
|
442 |
-
frequency_penalty=0.0
|
443 |
-
)
|
444 |
-
print("Chat response:", chat_response)
|
445 |
-
```
|
446 |
-
|
447 |
-
> Notice: If you need to enable repetition penalty, recommended to use *presence_penalty* and *frequency_penalty* parameters.
|
448 |
-
|
449 |
-
>
|
450 |
-
|
451 |
-
<br>
|
452 |
-
|
453 |
-
# Model Finetune
|
454 |
-
## Training data
|
455 |
-
|
456 |
-
Training Data: data/training_data_sample.json. The sample data is 10,000 pieces sampled from [multiturn_chat_0.8M](https://huggingface.co/datasets/BelleGroup/multiturn_chat_0.8M) and format converted.
|
457 |
-
|
458 |
-
Data Format:
|
459 |
-
```json
|
460 |
-
[
|
461 |
-
{
|
462 |
-
"id": 1,
|
463 |
-
"conversations": [
|
464 |
-
{
|
465 |
-
"from": "system",
|
466 |
-
"value": "You are a helpful assistant."
|
467 |
-
},
|
468 |
-
{
|
469 |
-
"from": "user",
|
470 |
-
"value": "您好啊"
|
471 |
-
},
|
472 |
-
{
|
473 |
-
"from": "assistant",
|
474 |
-
"value": "你好!我今天能为您做些什么?有什么问题或需要帮助吗? 我在这里为您提供服务。"
|
475 |
-
}
|
476 |
-
]
|
477 |
-
}
|
478 |
-
]
|
479 |
-
```
|
480 |
-
## Fine-tuning scripts
|
481 |
-
```shell
|
482 |
-
set -x
|
483 |
-
|
484 |
-
HOSTFILE=hostfile
|
485 |
-
DS_CONFIG=./finetune/ds_config_zero2.json
|
486 |
-
|
487 |
-
# PARAMS
|
488 |
-
LR=5e-6
|
489 |
-
EPOCHS=3
|
490 |
-
MAX_LEN=4096
|
491 |
-
BATCH_SIZE=4
|
492 |
-
NUM_NODES=1
|
493 |
-
NUM_GPUS=8
|
494 |
-
MASTER_PORT=29500
|
495 |
-
|
496 |
-
IS_CONCAT=False # Whether to concatenate to maximum length (MAX_LEN)
|
497 |
-
|
498 |
-
DATA_PATH="./data/training_data_sample.json"
|
499 |
-
MODEL_PATH="qihoo360/360Zhinao-7B-Base"
|
500 |
-
OUTPUT_DIR="./outputs/"
|
501 |
-
|
502 |
-
deepspeed --hostfile ${HOSTFILE} \
|
503 |
-
--master_port ${MASTER_PORT} \
|
504 |
-
--num_nodes ${NUM_NODES} \
|
505 |
-
--num_gpus ${NUM_GPUS} \
|
506 |
-
finetune.py \
|
507 |
-
--report_to "tensorboard" \
|
508 |
-
--data_path ${DATA_PATH} \
|
509 |
-
--model_name_or_path ${MODEL_PATH} \
|
510 |
-
--output_dir ${OUTPUT_DIR} \
|
511 |
-
--model_max_length ${MAX_LEN} \
|
512 |
-
--num_train_epochs ${EPOCHS} \
|
513 |
-
--per_device_train_batch_size ${BATCH_SIZE} \
|
514 |
-
--gradient_accumulation_steps 1 \
|
515 |
-
--save_strategy steps \
|
516 |
-
--save_steps 200 \
|
517 |
-
--learning_rate ${LR} \
|
518 |
-
--lr_scheduler_type cosine \
|
519 |
-
--adam_beta1 0.9 \
|
520 |
-
--adam_beta2 0.95 \
|
521 |
-
--adam_epsilon 1e-8 \
|
522 |
-
--max_grad_norm 1.0 \
|
523 |
-
--weight_decay 0.1 \
|
524 |
-
--warmup_ratio 0.01 \
|
525 |
-
--gradient_checkpointing True \
|
526 |
-
--bf16 True \
|
527 |
-
--tf32 True \
|
528 |
-
--deepspeed ${DS_CONFIG} \
|
529 |
-
--is_concat ${IS_CONCAT} \
|
530 |
-
--logging_steps 1 \
|
531 |
-
--log_on_each_node False
|
532 |
-
```
|
533 |
-
```shell
|
534 |
-
bash finetune/ds_finetune.sh
|
535 |
-
```
|
536 |
-
- By configuring the **hostfile**, single-machine and multi-machine training can be realized.
|
537 |
-
- By configuring **ds_config**, realize zero2 and zero3 training
|
538 |
-
- By configuring the **fp16**、**bf16** realize mixed precision training, bf16 is recommended to be consistent with the pre-trained model.
|
539 |
-
- By configuring **is_concat**, Whether the training data is concatenated or not is controlled. When the magnitude of the training data is large, the training efficiency can be improved by concatenation.
|
540 |
-
|
541 |
-
<br>
|
542 |
-
|
543 |
-
# License
|
544 |
-
|
545 |
-
The source code of this warehouse follows the open source license Apache 2.0.
|
546 |
-
|
547 |
-
The 360 Zhinao open source model supports commercial use. If you need to use this model and its derivative models for commercial purposes, please contact us via email (g-zhinao-opensource@360.cn) to apply. For the specific license agreement, please see [《360 Zhinao Open Source Model License》](./360智脑开源模型许可证.txt).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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