zhaicunqi commited on
Commit
1ac7913
1 Parent(s): 4fbeb62

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +109 -115
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>&nbsp&nbsp | &nbsp&nbsp
22
- 🔥 <a href="https://github.com/Qihoo360/360zhinao/">GitHub</a>&nbsp&nbsp | &nbsp&nbsp
23
- 💬 <a href="https://github.com/Qihoo360/360zhinao/blob/main/assets/WeChat.png">WeChat (微信)</a>&nbsp&nbsp
24
  </div>
25
  <br>
26
  <p align="center">
27
- 欢迎访问360智脑官网<a href="https://ai.360.com"> https://ai.360.com </a>体验更多更强大的功能。
28
  </p>
29
 
30
  <br>
31
 
32
- # 模型介绍
33
- 🎉🎉🎉我们开源了360智脑大模型的系列工作,本次开源了以下模型:
34
  - **360Zhinao-7B-Base**
35
  - **360Zhinao-7B-Chat-4K**
36
  - **360Zhinao-7B-Chat-32K**
37
  - **360Zhinao-7B-Chat-360K**
38
 
39
- 360智脑大模型特点如下:
40
- - **基础模型**:采用 3.4 万亿 Tokens 的高质量语料库训练,以中文、英文、代码为主,在相关基准评测中,同尺寸有竞争力。
41
- - **对话模型**:具有强大的对话能力,开放4K、32K、360K三种不同文本长度。据了解,360K(约50万字)是当前国产开源模型文本长度最长的。
 
42
 
43
  <br>
44
 
45
- # 更新信息
46
- - [2024.04.10] 我们发布了360Zhinao-7B 1.0版本,同时开放Base模型和4K32K360K三种文本长度的Chat模型。
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
- 以上结果,在官方[Opencompass](https://rank.opencompass.org.cn/leaderboard-llm)上可查询或可复现。
96
 
97
- ## Chat模型
98
 
99
- 我们采用两阶段的方式训练长文本模型.
100
-
101
- **第一阶段**:我们增大RoPE base,将上下文长度扩展至32K训练:
102
- - 首先,对基础模型进行了约5B tokens32K窗口继续预训练。
103
- - 接着,SFT阶段使用了多种形式和来源的长文本数据,包括高质量的人工标注32K长文本数据。
104
 
105
- **第二阶段**:我们将上下文长度扩展至360K进行训练,使用数据如下:
106
- - 少量高质量人工标注数据。
107
- - 由于带有标注的超长文本数据的稀缺性,我们构造了多种形式的合成数据:
108
- - 多文档问答:类似[Ziya-Reader](https://arxiv.org/abs/2311.09198),我们基于360自有数据构造了多种类型的多文档问答数据,同时将问答改为多轮,显著提升长文本的训练效率。
109
- - 单文档问答:类似[LLama2 Long](https://arxiv.org/abs/2309.16039),我们构造了基于超长文本各个片段的多轮问答数据。
110
 
111
- 我们在多种长度和多种任务的评测Benchmark上验证不同版本模型的性能。
112
 
113
- - ### 360Zhinao-7B-Chat-32K模型长文本能力评测
114
 
115
 
116
- 我们使用LongBench验证长文本效果。[LongBench](https://github.com/THUDM/LongBench)是第一个多任务、中英双语、针对大语言模型长文本理解能力的评测基准。LongBench由六大类、二十一个不同的任务组成,我们选择其中与中文长文本应用最密切相关的中文单文档问答、多文档问答、摘要、Few-shot等任务进行评测。
117
 
118
- | Model | Avg | 单文档QA | 多文档QA | 摘要 | Few-shot学习 | 代码补全 |
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
- 大海捞针测试([NeedleInAHaystack](https://github.com/gkamradt/LLMTest_NeedleInAHaystack))是将关键信息插入一段长文本的不同位置,再对该关键信息提问,从而测试大模型的长文本能力的一种方法。
131
 
132
- 360Zhinao-7B-Chat-360K在中英文大海捞针中都能达到98%以上的准确率。
133
 
134
- - 英文"大海捞针"(和[NeedleInAHaystack](https://github.com/gkamradt/LLMTest_NeedleInAHaystack)相同)
135
 
136
  <p align="center">
137
  <img src="assets/360Zhinao-7B-Chat-360K.en_score.png" width="600" />
138
  <p>
139
 
140
- **针**:The best thing to do in San Francisco is eat a sandwich and sit in Dolores Park on a sunny day.
141
 
142
- **提问**:What is the best thing to do in San Francisco?
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
- 我们仿照[SuperCLUE-200K测评基准](https://mp.weixin.qq.com/s/QgoRf2LB-7vc3vTFOHJkpw)构造了中文大海捞针:
152
 
153
- **海**:长篇小说。
154
-
155
- **针**:王莽是一名勤奋的店员,他每天凌晨就起床,赶在第一缕阳光照亮大地之前到达店铺,为即将开始的一天做准备。他清扫店铺,整理货架,为顾客提供方便。他对五金的种类和用途了如指掌,无论顾客需要什么,他总能准确地找到。\n然而,他的老板刘秀却总是对他吹毛求疵。刘秀是个挑剔的人,他总能在王莽的工作中找出一些小错误,然后以此为由扣他的工资。他对王莽的工作要求非常严格,甚至有些过分。即使王莽做得再好,刘秀也总能找出一些小问题,让王莽感到非常沮丧。\n王莽虽然对此感到不满,但他并没有放弃。他知道,只有通过自己的努力,才能获得更好的生活。他坚持每天早起,尽管他知道那天可能会再次被刘秀扣工资。他始终保持微笑,尽管他知道刘秀可能会再次对他挑剔。
156
 
157
- **提问**:王莽在谁的手下工作?
158
 
159
  <br>
160
 
161
- # 快速开始
162
- 简单的示例来说明如何利用🤖 ModelScope和🤗 Transformers快速使用360Zhinao-7B-Base360Zhinao-7B-Chat
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
- 我们推荐安装flash-attention(当前已支持flash attention 2)来提高你的运行效率以及降低显存占用。(flash-attention只是可选项,不安装也可正常运行该项目)
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
- 此代码演示使用transformers快速使用360Zhinao-7B-Base模型进行推理
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
- ### Chat模型推理
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
- ## 终端 Demo
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
- ## 网页 Demo
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 --location --request POST 'http://localhost:8360/v1/chat/completions' \
342
- --header 'Content-Type: application/json' \
343
- --data-raw '{
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
- "role": "user",
353
- "content": "你叫什么名字"
354
- }
355
  ]
356
  }'
357
  ```
358
 
359
  <br>
360
 
361
- # 模型推理
362
- ## 模型量化
363
- 我们提供了基于AutoGPTQ的量化方案,并开源了Int4量化模型。
364
 
365
- ## 模型部署
366
- ### vLLM安装环境
367
- 如希望部署及加速推理,我们建议你使用 `vLLM==0.3.3`。
368
 
369
- 如果你使用**CUDA 12.1PyTorch 2.1**,可以直接使用以下命令安装vLLM
370
  ```shell
371
  pip install vllm==0.3.3
372
  ```
373
 
374
- 否则请参考vLLM官方的[安装说明](https://docs.vllm.ai/en/latest/getting_started/installation.html)。
375
 
376
- >安装完成后,还需要以下操作~
377
- 1. vllm/zhinao.py文件复制到env环境对应的vllm/model_executor/models目录下。
378
- 2. vllm/serving_chat.py文件复制到env环境对应的vllm/entrypoints/openai目录下。
379
- 3. 然后在vllm/model_executor/models/\_\_init\_\_.py文件增加一行代码
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
- 使用curl请求服务
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
- 使用python请求服务
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
- > 注意:如需要开启重复惩罚,建议使用 *presence_penalty* *frequency_penalty* 参数。
 
 
452
 
453
  <br>
454
 
455
- # 模型微调
456
- ## 训练数据
457
 
458
- 我们提供了微调训练样例数据 data/test.json,该样例数据是从 [multiturn_chat_0.8M](https://huggingface.co/datasets/BelleGroup/multiturn_chat_0.8M) 采样出 1 万条,并且做了格式转换。
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 # 是否数据拼接到最大长度(MAX_LEN
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
- - 可通过配置hostfile,实现单机、多机训练。
541
- - 可通过配置ds_config,实现zero2zero3
542
- - 可通过配置fp16bf16实现混合精度训练,建议使用bf16,与预训练模型保持一致。
543
- - 可通过配置is_concat参数,控制训练数据是否拼接,当训练数据量级较大时,可通过拼接提升训练效率。
544
 
545
  <br>
546
 
547
- # 许可证
548
 
549
- 本仓库源码遵循开源许可证Apache 2.0
550
 
551
- 360智脑开源模型支持商用,若需将本模型及衍生模型用于商业用途,请通过邮箱(g-zhinao-opensource@360.cn)联系进行申请, 具体许可协议请见[《360智脑开源模型许可证》](./360智脑开源模型许可证.txt)
 
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>&nbsp&nbsp | &nbsp&nbsp
22
  🤖 <a href="https://www.modelscope.cn/profile/qihoo360">ModelScope</a>&nbsp&nbsp | &nbsp&nbsp
23
+ 💬 <a href="./assets/WeChat.png">WeChat (微信)</a>&nbsp&nbsp
 
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).