Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -14,53 +14,54 @@ tags:
|
|
14 |
|
15 |
<div align="center">
|
16 |
<h1>
|
17 |
-
360智脑
|
18 |
</h1>
|
19 |
</div>
|
20 |
<div align="center">
|
|
|
21 |
🤖 <a href="https://www.modelscope.cn/profile/qihoo360">ModelScope</a>   |   
|
22 |
-
|
23 |
-
💬 <a href="https://github.com/Qihoo360/360zhinao/blob/main/assets/WeChat.png">WeChat (微信)</a>  
|
24 |
</div>
|
25 |
<br>
|
26 |
<p align="center">
|
27 |
-
|
28 |
</p>
|
29 |
|
30 |
<br>
|
31 |
|
32 |
-
#
|
33 |
-
|
34 |
- **360Zhinao-7B-Base**
|
35 |
- **360Zhinao-7B-Chat-4K**
|
36 |
- **360Zhinao-7B-Chat-32K**
|
37 |
- **360Zhinao-7B-Chat-360K**
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
-
|
|
|
42 |
|
43 |
<br>
|
44 |
|
45 |
-
#
|
46 |
-
-
|
47 |
|
48 |
<br>
|
49 |
|
50 |
-
#
|
51 |
-
- [
|
52 |
-
- [
|
53 |
-
- [
|
54 |
-
- [
|
55 |
-
- [
|
56 |
-
- [
|
57 |
|
58 |
<br>
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
| Size | Model | BF16 | Int4|
|
63 |
-
|
64 |
| 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> | |
|
65 |
| 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> |
|
66 |
| 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,11 +69,9 @@ tags:
|
|
68 |
|
69 |
<br>
|
70 |
|
71 |
-
#
|
72 |
-
|
73 |
-
|
74 |
-
我们在OpenCompass的主流评测数据集上验证了我们的模型性能,包括C-Eval、AGIEval、MMLU、CMMLU、HellaSwag、MATH、GSM8K、HumanEval、MBPP、BBH、LAMBADA,考察的能力包括自然语言理解、知识、数学计算和推理、代码生成、逻辑推理等。
|
75 |
-
|
76 |
|
77 |
| <div style="width: 100pt">Model</div> | AVG | CEval | AGIEval | MMLU | CMMLU | HellaSwag | MATH | GSM8K | HumanEval | MBPP | BBH | LAMBADA |
|
78 |
|:----------------------|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|
|
@@ -92,30 +91,30 @@ tags:
|
|
92 |
| Yi-6B | 47.8 | 73 | 44.3 | 64 | **73.5** | 73.1 | 6.3 | 39.9 | 15.2 | 23.6 | 44.9 | 68 |
|
93 |
| **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** |
|
94 |
|
95 |
-
|
96 |
|
97 |
-
## Chat
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
-
|
103 |
-
-
|
104 |
|
105 |
-
|
106 |
-
-
|
107 |
-
-
|
108 |
-
|
109 |
-
|
110 |
|
111 |
-
|
112 |
|
113 |
-
- ###
|
114 |
|
115 |
|
116 |
-
|
117 |
|
118 |
-
| Model | Avg |
|
119 |
| :------------------------ |:---------:|:--------:|:---------:|:---------:|:------------:|:---------:|
|
120 |
| GPT-3.5-Turbo-16k | 37.84 | 61.2 | 28.7 | 16 | 29.2 | 54.1 |
|
121 |
| ChatGLM2-6B-32k | 37.16 | 51.6 | 37.6 | 16.2 | 27.7 | 52.7 |
|
@@ -125,43 +124,43 @@ tags:
|
|
125 |
| Qwen1.5-Chat-14B | 39.80 | 60.39 | 27.99 | 14.77 | 37 | 58.87 |
|
126 |
| 360Zhinao-7B-Chat-32K | **45.18** | 57.18 | **48.06** | 15.03 | **44** | 61.64 |
|
127 |
|
128 |
-
- ### 360Zhinao-7B-Chat-360K
|
129 |
|
130 |
-
|
131 |
|
132 |
-
360Zhinao-7B-Chat-360K
|
133 |
|
134 |
-
-
|
135 |
|
136 |
<p align="center">
|
137 |
<img src="assets/360Zhinao-7B-Chat-360K.en_score.png" width="600" />
|
138 |
<p>
|
139 |
|
140 |
-
|
141 |
|
142 |
-
|
143 |
|
144 |
|
145 |
-
-
|
146 |
|
147 |
<p align="center">
|
148 |
<img src="assets/360Zhinao-7B-Chat-360K.zh_score.png" width="600" />
|
149 |
<p>
|
150 |
|
151 |
-
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
|
157 |
-
|
158 |
|
159 |
<br>
|
160 |
|
161 |
-
#
|
162 |
-
|
163 |
|
164 |
-
##
|
165 |
- python 3.8 and above
|
166 |
- pytorch 2.0 and above
|
167 |
- transformers 4.37.2 and above
|
@@ -170,18 +169,17 @@ tags:
|
|
170 |
```shell
|
171 |
pip install -r requirements.txt
|
172 |
```
|
173 |
-
|
174 |
|
175 |
>flash-attn >= 2.3.6
|
176 |
```shell
|
177 |
FLASH_ATTENTION_FORCE_BUILD=TRUE pip install flash-attn==2.3.6
|
178 |
```
|
179 |
|
180 |
-
|
181 |
## 🤗 Transformers
|
182 |
-
### Base
|
183 |
|
184 |
-
|
185 |
```python
|
186 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
187 |
from transformers.generation import GenerationConfig
|
@@ -207,10 +205,9 @@ inputs = inputs.to(model.device)
|
|
207 |
pred = model.generate(input_ids=inputs["input_ids"], generation_config=generation_config)
|
208 |
print("outputs:\n", tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
|
209 |
```
|
|
|
210 |
|
211 |
-
|
212 |
-
|
213 |
-
此代���演示使用transformers快速使用360Zhinao-7B-Chat-4K模型进行推理
|
214 |
```python
|
215 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
216 |
from transformers.generation import GenerationConfig
|
@@ -245,10 +242,9 @@ print(messages)
|
|
245 |
```
|
246 |
|
247 |
## 🤖 ModelScope
|
248 |
-
### Base
|
249 |
-
|
250 |
-
此代码演示使用ModelScope快速使用360Zhinao-7B-Base模型进行推理
|
251 |
|
|
|
252 |
|
253 |
```python
|
254 |
from modelscope import AutoModelForCausalLM, AutoTokenizer
|
@@ -276,9 +272,10 @@ pred = model.generate(input_ids=inputs["input_ids"], generation_config=generatio
|
|
276 |
print("outputs:\n", tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
|
277 |
```
|
278 |
|
279 |
-
### Chat
|
|
|
|
|
280 |
|
281 |
-
此代码演示使用ModelScope快速使用360Zhinao-7B-Chat-4K模型进行推理
|
282 |
```python
|
283 |
from modelscope import AutoModelForCausalLM, AutoTokenizer
|
284 |
from modelscope import GenerationConfig
|
@@ -312,8 +309,8 @@ messages.append({"role": "assistant", "content": response})
|
|
312 |
print(messages)
|
313 |
```
|
314 |
|
315 |
-
##
|
316 |
-
|
317 |
```shell
|
318 |
python cli_demo.py
|
319 |
```
|
@@ -321,8 +318,8 @@ python cli_demo.py
|
|
321 |
<img src="assets/cli_demo.gif" width="600" />
|
322 |
<p>
|
323 |
|
324 |
-
##
|
325 |
-
|
326 |
```shell
|
327 |
streamlit run web_demo.py
|
328 |
```
|
@@ -331,16 +328,16 @@ streamlit run web_demo.py
|
|
331 |
<p>
|
332 |
|
333 |
## API Demo
|
334 |
-
|
335 |
```shell
|
336 |
python openai_api.py
|
337 |
```
|
338 |
|
339 |
-
|
340 |
```shell
|
341 |
-
curl
|
342 |
-
|
343 |
-
|
344 |
"max_new_tokens": 200,
|
345 |
"do_sample": true,
|
346 |
"top_k": 0,
|
@@ -348,43 +345,41 @@ curl --location --request POST 'http://localhost:8360/v1/chat/completions' \
|
|
348 |
"temperature": 1.0,
|
349 |
"repetition_penalty": 1.0,
|
350 |
"messages": [
|
351 |
-
{
|
352 |
-
|
353 |
-
"content": "你叫什么名字"
|
354 |
-
}
|
355 |
]
|
356 |
}'
|
357 |
```
|
358 |
|
359 |
<br>
|
360 |
|
361 |
-
#
|
362 |
-
##
|
363 |
-
|
364 |
|
365 |
-
##
|
366 |
-
### vLLM
|
367 |
-
|
368 |
|
369 |
-
|
370 |
```shell
|
371 |
pip install vllm==0.3.3
|
372 |
```
|
373 |
|
374 |
-
|
375 |
|
376 |
-
|
377 |
-
1.
|
378 |
-
2.
|
379 |
-
3.
|
380 |
|
381 |
```shell
|
382 |
"ZhinaoForCausalLM": ("zhinao", "ZhinaoForCausalLM"),
|
383 |
```
|
384 |
|
385 |
-
### vLLM
|
386 |
|
387 |
-
|
388 |
```shell
|
389 |
python -m vllm.entrypoints.openai.api_server \
|
390 |
--served-model-name 360Zhinao-7B-Chat-4K \
|
@@ -396,7 +391,7 @@ python -m vllm.entrypoints.openai.api_server \
|
|
396 |
--port 8360
|
397 |
```
|
398 |
|
399 |
-
|
400 |
```shell
|
401 |
curl http://localhost:8360/v1/chat/completions \
|
402 |
-H "Content-Type: application/json" \
|
@@ -419,10 +414,9 @@ curl http://localhost:8360/v1/chat/completions \
|
|
419 |
]
|
420 |
}'
|
421 |
```
|
422 |
-
|
423 |
```python
|
424 |
from openai import OpenAI
|
425 |
-
# Set OpenAI's API key and API base to use vLLM's API server.
|
426 |
openai_api_key = "EMPTY"
|
427 |
openai_api_base = "http://localhost:8360/v1"
|
428 |
|
@@ -448,16 +442,18 @@ chat_response = client.chat.completions.create(
|
|
448 |
print("Chat response:", chat_response)
|
449 |
```
|
450 |
|
451 |
-
>
|
|
|
|
|
452 |
|
453 |
<br>
|
454 |
|
455 |
-
#
|
456 |
-
##
|
457 |
|
458 |
-
|
459 |
|
460 |
-
|
461 |
```json
|
462 |
[
|
463 |
{
|
@@ -479,9 +475,7 @@ print("Chat response:", chat_response)
|
|
479 |
}
|
480 |
]
|
481 |
```
|
482 |
-
|
483 |
-
## 微调训练
|
484 |
-
训练脚本如下:
|
485 |
```shell
|
486 |
set -x
|
487 |
|
@@ -497,7 +491,7 @@ NUM_NODES=1
|
|
497 |
NUM_GPUS=8
|
498 |
MASTER_PORT=29500
|
499 |
|
500 |
-
IS_CONCAT=False #
|
501 |
|
502 |
DATA_PATH="./data/training_data_sample.json"
|
503 |
MODEL_PATH="qihoo360/360Zhinao-7B-Base"
|
@@ -537,15 +531,15 @@ deepspeed --hostfile ${HOSTFILE} \
|
|
537 |
```shell
|
538 |
bash finetune/ds_finetune.sh
|
539 |
```
|
540 |
-
-
|
541 |
-
-
|
542 |
-
-
|
543 |
-
-
|
544 |
|
545 |
<br>
|
546 |
|
547 |
-
#
|
548 |
|
549 |
-
|
550 |
|
551 |
-
360
|
|
|
14 |
|
15 |
<div align="center">
|
16 |
<h1>
|
17 |
+
360Zhinao (360智脑)
|
18 |
</h1>
|
19 |
</div>
|
20 |
<div align="center">
|
21 |
+
🤗 <a href="https://huggingface.co/qihoo360">Hugging Face</a>   |   
|
22 |
🤖 <a href="https://www.modelscope.cn/profile/qihoo360">ModelScope</a>   |   
|
23 |
+
💬 <a href="./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> |
|
|
|
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 |
|:----------------------|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|
|
|
|
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 | Single-Doc QA | Multi-Doc QA | Summarization | Few-Shot Learning | Code Completion |
|
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 |
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
309 |
print(messages)
|
310 |
```
|
311 |
|
312 |
+
## CLI Demo
|
313 |
+
Use terminal interaction for a fast experience
|
314 |
```shell
|
315 |
python cli_demo.py
|
316 |
```
|
|
|
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 |
```
|
|
|
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 'http://localhost:8360/v1/chat/completions' \
|
339 |
+
-H 'Content-Type: application/json' \
|
340 |
+
-d '{
|
341 |
"max_new_tokens": 200,
|
342 |
"do_sample": true,
|
343 |
"top_k": 0,
|
|
|
345 |
"temperature": 1.0,
|
346 |
"repetition_penalty": 1.0,
|
347 |
"messages": [
|
348 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
349 |
+
{"role": "user", "content": "你好"}
|
|
|
|
|
350 |
]
|
351 |
}'
|
352 |
```
|
353 |
|
354 |
<br>
|
355 |
|
356 |
+
# Model Inference
|
357 |
+
## Quantization
|
358 |
+
We provide quantization schemes based on AutoGPTQ and open source the Int4 quantization models.
|
359 |
|
360 |
+
## Deployment
|
361 |
+
### vLLM Installation
|
362 |
+
If you want to deploy and accelerate inference, we recommend using `vLLM==0.3.3`。
|
363 |
|
364 |
+
If you are using **CUDA 12.1 and PyTorch 2.1**, you can install vLLM directly with the following command.
|
365 |
```shell
|
366 |
pip install vllm==0.3.3
|
367 |
```
|
368 |
|
369 |
+
Otherwise, please refer to the official vLLM [Installation Instructions](https://docs.vllm.ai/en/latest/getting_started/installation.html)。
|
370 |
|
371 |
+
>Once the installation is complete, you will need to do the following
|
372 |
+
1. Copy the vllm/zhinao.py file to the vllm/model_executor/models directory corresponding to your env environment.
|
373 |
+
2. Copy the vllm/serving_chat.py file to the vllm/entrypoints/openai corresponding to your env environment.
|
374 |
+
3. Then add a line to vllm/model_executor/models/\_\_init\_\_.py
|
375 |
|
376 |
```shell
|
377 |
"ZhinaoForCausalLM": ("zhinao", "ZhinaoForCausalLM"),
|
378 |
```
|
379 |
|
380 |
+
### vLLM Service Start
|
381 |
|
382 |
+
Starting the service
|
383 |
```shell
|
384 |
python -m vllm.entrypoints.openai.api_server \
|
385 |
--served-model-name 360Zhinao-7B-Chat-4K \
|
|
|
391 |
--port 8360
|
392 |
```
|
393 |
|
394 |
+
Use curl to request the service
|
395 |
```shell
|
396 |
curl http://localhost:8360/v1/chat/completions \
|
397 |
-H "Content-Type: application/json" \
|
|
|
414 |
]
|
415 |
}'
|
416 |
```
|
417 |
+
Use python to request the service
|
418 |
```python
|
419 |
from openai import OpenAI
|
|
|
420 |
openai_api_key = "EMPTY"
|
421 |
openai_api_base = "http://localhost:8360/v1"
|
422 |
|
|
|
442 |
print("Chat response:", chat_response)
|
443 |
```
|
444 |
|
445 |
+
> Notice: If you need to enable repetition penalty, recommended to use *presence_penalty* and *frequency_penalty* parameters.
|
446 |
+
|
447 |
+
>
|
448 |
|
449 |
<br>
|
450 |
|
451 |
+
# Model Finetune
|
452 |
+
## Training data
|
453 |
|
454 |
+
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.
|
455 |
|
456 |
+
Data Format:
|
457 |
```json
|
458 |
[
|
459 |
{
|
|
|
475 |
}
|
476 |
]
|
477 |
```
|
478 |
+
## Fine-tuning scripts
|
|
|
|
|
479 |
```shell
|
480 |
set -x
|
481 |
|
|
|
491 |
NUM_GPUS=8
|
492 |
MASTER_PORT=29500
|
493 |
|
494 |
+
IS_CONCAT=False # Whether to concatenate to maximum length (MAX_LEN)
|
495 |
|
496 |
DATA_PATH="./data/training_data_sample.json"
|
497 |
MODEL_PATH="qihoo360/360Zhinao-7B-Base"
|
|
|
531 |
```shell
|
532 |
bash finetune/ds_finetune.sh
|
533 |
```
|
534 |
+
- By configuring the **hostfile**, single-machine and multi-machine training can be realized.
|
535 |
+
- By configuring **ds_config**, realize zero2 and zero3 training
|
536 |
+
- By configuring the **fp16**、**bf16** realize mixed precision training, bf16 is recommended to be consistent with the pre-trained model.
|
537 |
+
- 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.
|
538 |
|
539 |
<br>
|
540 |
|
541 |
+
# License
|
542 |
|
543 |
+
The source code of this warehouse follows the open source license Apache 2.0.
|
544 |
|
545 |
+
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》](https://github.com/Qihoo360/360zhinao/blob/main/360%E6%99%BA%E8%84%91%E5%BC%80%E6%BA%90%E6%A8%A1%E5%9E%8B%E8%AE%B8%E5%8F%AF%E8%AF%81.txt).
|