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+
|
5 |
+
# AquilaChat-7B
|
6 |
+
|
7 |
+
## 简介/Overview
|
8 |
+
Aquila语言大模型在技术上继承了GPT-3、LLaMA等的架构设计优点,替换了一批更高效的底层算子实现、重新设计实现了中英双语的tokenizer,升级了BMTrain并行训练方法,在Aquila的训练过程中实现了比Magtron+DeepSpeed zero-2将近8倍的训练效率。Aquila语言大模型是在中英文高质量语料基础上从0开始训练的,通过数据质量的控制、多种训练的优化方法,实现在更小的数据集、更短的训练时间,获得比其它开源模型更优的性能。也是首个支持中英双语知识、支持商用许可协议、符合国内数据合规需要的大规模开源语言模型。
|
9 |
+
|
10 |
+
The Aquila language model inherits the architectural design advantages of GPT-3 and LLaMA, replacing a batch of more efficient underlying operator implementations and redesigning the tokenizer for Chinese-English bilingual support. It upgrades the BMTrain parallel training method, achieving nearly 8 times the training efficiency of Magtron+DeepSpeed ZeRO-2 in the training process of Aquila. The Aquila language model is trained from scratch on high-quality Chinese and English corpora. Through data quality control and various training optimization methods, it achieves better performance than other open-source models with smaller datasets and shorter training times. It is also the first large-scale open-source language model that supports Chinese-English-Knowledge, commercial licensing, and complies with domestic data regulations.
|
11 |
+
|
12 |
+
AquilaChat-7B是在Aquila-7B模型的基础上,进行SFT微调后的支持中英双语的对话式语言模型。AquilaChat-7B模型由智源研究院研发,其在主流评测数据集上的评测结果如下
|
13 |
+
|
14 |
+
AquilaChat-7B is a conversational language model that supports Chinese-English dialogue. It is based on the Aquila-7B model and fine-tuned using SFT. AquilaChat-7B model was developed by Beijing Academy of Artificial Intelligence. The evaluation results on mainstream benchmark datasets are as follows:
|
15 |
+
|
16 |
+
| 名称/Name | MMLU_Chinese_EM | CLUE-EM |MMLU-EM| BoolQ-EM| TruthfulQA-EM |IMDB-EM| RAFT-EM|
|
17 |
+
| ----- | ---- | ----- | ---- | ----- | ---- | ----- | ----- |
|
18 |
+
| [AcuilaChat-7B](https://model.baai.ac.cn/model-detail/xxxxx) | 0.292 | 0.385|0.269 | 0.731|0.347 |0.939| 0.443|
|
19 |
+
| [BiLLa-7B-LLM](https://model.baai.ac.cn/model-detail/xxxxx) | 0.279 | 0.374|0.257 | 0.76|0.205 |0.864| 0.514|
|
20 |
+
| [Ziya-LLaMA-13B-v1](https://model.baai.ac.cn/model-detail/xxxxx) | 0.273 | 0.404|0.406 | 0.786|0.284 |0.762| 0.191|
|
21 |
+
|
22 |
+
您可以在[FlagEval基础模型评测平台](https://flageval.baai.ac.cn/#/home) 查看更多评测指标
|
23 |
+
|
24 |
+
You can view [FlagEval Model Evaluation Platform](https://flageval.baai.ac.cn/#/home) for more details
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
我们的模型也同时支持[Huggingface平台](hflink)
|
29 |
+
|
30 |
+
We also support [Huggingface](hflink)
|
31 |
+
|
32 |
+
aquila chat 主要为了验证基础模型能力,使用者可以根据自己需要。。。, 免责说明(license那句话改改)
|
33 |
+
|
34 |
+
## 模型细节/Model details
|
35 |
+
|
36 |
+
我们使用了一系列更高效的底层算子来辅助模型训练,其中包括参考[flash-attention](https://github.com/HazyResearch/flash-attention)的方法并替换了一些中间计算,同时还使用了RMSNorm。在此基础上,我们应用了[BMtrain](https://github.com/OpenBMB/BMTrain)技术进行轻量化的并行训练,该技术采用了数据并行、ZeRO(零冗余优化器)、优化器卸载、检查点和操作融合、通信-计算重叠等方法来优化模型训练过程。
|
37 |
+
|
38 |
+
Aquila模型所采用的tokenizer是由我们从头开始训练的,支持中英双语。与其他tokenizer的参数对比见下表:
|
39 |
+
|
40 |
+
我们在处理英文、中文以及代码数据时,采用了不同的分词器对一万个样本进行了抽取。随后,我们统计了每个样本的token数量,并将其记录在表格中。
|
41 |
+
|
42 |
+
|
43 |
+
We used a series of more efficient low-level operators to assist with model training, including methods referenced from [flash-attention](https://github.com/HazyResearch/flash-attention) and replacing some intermediate calculations, as well as using RMSNorm. Building upon this foundation, we applied the [BMtrain](https://github.com/OpenBMB/BMTrain) for lightweight parallel training, which utilizes methods such as data parallelism, ZeRO (zero redundancy optimizer), optimizer offloading, checkpoint and operation fusion, and communication-computation overlap to optimize the model training process.
|
44 |
+
|
45 |
+
The tokenizer used in the Aquila model was trained from scratch by us and supports both English and Chinese. The parameters of this tokenizer are compared to those of other tokenizers in the table below:
|
46 |
+
|
47 |
+
We used different tokenizers to extract ten thousand data samples from English, Chinese, and code data respectively, obtained the count of tokens for each sample, and also included it in the table.
|
48 |
+
|
49 |
+
| 模型/Model | 词表大小/Vocab size | 说明/Note |英文平均tokens量/Avg tokens(English)| 中文平均tokens量/Avg tokens(Chinesse)|代码平均tokens量/Avg tokens(code) |
|
50 |
+
| ----- | ---- | ----- | ---- | ----- | ---- |
|
51 |
+
| gpt2 | 50527 | bpe|1717 | 1764|2323 |
|
52 |
+
| llama | 32000 | sp(bpe)|1805| 1257|1970 |
|
53 |
+
| gpt2_new_100k | 100000 | bpe|1575 | 477|1679 |
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
模型在一台8卡Nvidia A100上训练8小时,总共对15万条数据训练了3个epoch。
|
58 |
+
|
59 |
+
The model was trained on an 8-card Nvidia A100 for 8 hours, and a total of 150,000 lines of data were trained for 3 epochs.
|
60 |
+
|
61 |
+
## 训练数据集/Training data
|
62 |
+
|
63 |
+
我们采用了一系列高质量中英文数据集来训练和微调我们的对话语言模型,并且在不断更新迭代
|
64 |
+
|
65 |
+
We used a series of high-quality Chinese and English datasets to train and fine-tune our conversational language model, and continuously updated it through iterations.
|
66 |
+
|
67 |
+
![Screenshot](../img/data.jpg)
|
68 |
+
|
69 |
+
|
70 |
+
## 使用方式/How to use
|
71 |
+
|
72 |
+
### 1. 推理/Inference
|
73 |
+
|
74 |
+
```python
|
75 |
+
import os
|
76 |
+
import torch
|
77 |
+
from flagai.auto_model.auto_loader import AutoLoader
|
78 |
+
from flagai.model.predictor.predictor import Predictor
|
79 |
+
from flagai.model.predictor.aquila import aquila_generate
|
80 |
+
from flagai.data.tokenizer import Tokenizer
|
81 |
+
import bminf
|
82 |
+
|
83 |
+
state_dict = "./checkpoints_in"
|
84 |
+
model_name = 'aquilachat-30b'
|
85 |
+
|
86 |
+
loader = AutoLoader(
|
87 |
+
"lm",
|
88 |
+
model_dir=state_dict,
|
89 |
+
model_name=model_name,
|
90 |
+
use_cache=True)
|
91 |
+
|
92 |
+
model = loader.get_model()
|
93 |
+
tokenizer = loader.get_tokenizer()
|
94 |
+
cache_dir = os.path.join(state_dict, model_name)
|
95 |
+
model.eval()
|
96 |
+
model.half()
|
97 |
+
model.cuda()
|
98 |
+
|
99 |
+
predictor = Predictor(model, tokenizer)
|
100 |
+
|
101 |
+
text = "北京为什么是中国的首都?"
|
102 |
+
|
103 |
+
def pack_obj(text):
|
104 |
+
obj = dict()
|
105 |
+
obj['id'] = 'demo'
|
106 |
+
|
107 |
+
obj['conversations'] = []
|
108 |
+
human = dict()
|
109 |
+
human['from'] = 'human'
|
110 |
+
human['value'] = text
|
111 |
+
obj['conversations'].append(human)
|
112 |
+
# dummy bot
|
113 |
+
bot = dict()
|
114 |
+
bot['from'] = 'gpt'
|
115 |
+
bot['value'] = ''
|
116 |
+
obj['conversations'].append(bot)
|
117 |
+
|
118 |
+
obj['instruction'] = ''
|
119 |
+
|
120 |
+
return obj
|
121 |
+
|
122 |
+
def delete_last_bot_end_singal(convo_obj):
|
123 |
+
conversations = convo_obj['conversations']
|
124 |
+
assert len(conversations) > 0 and len(conversations) % 2 == 0
|
125 |
+
assert conversations[0]['from'] == 'human'
|
126 |
+
|
127 |
+
last_bot = conversations[len(conversations)-1]
|
128 |
+
assert last_bot['from'] == 'gpt'
|
129 |
+
|
130 |
+
## from _add_speaker_and_signal
|
131 |
+
END_SIGNAL = "\n"
|
132 |
+
len_end_singal = len(END_SIGNAL)
|
133 |
+
len_last_bot_value = len(last_bot['value'])
|
134 |
+
last_bot['value'] = last_bot['value'][:len_last_bot_value-len_end_singal]
|
135 |
+
return
|
136 |
+
|
137 |
+
def convo_tokenize(convo_obj, tokenizer):
|
138 |
+
chat_desc = convo_obj['chat_desc']
|
139 |
+
instruction = convo_obj['instruction']
|
140 |
+
conversations = convo_obj['conversations']
|
141 |
+
|
142 |
+
# chat_desc
|
143 |
+
example = tokenizer.encode_plus(f"{chat_desc}", None, max_length=None)['input_ids']
|
144 |
+
EOS_TOKEN = example[-1]
|
145 |
+
example = example[:-1] # remove eos
|
146 |
+
# instruction
|
147 |
+
instruction = tokenizer.encode_plus(f"{instruction}", None, max_length=None)['input_ids']
|
148 |
+
instruction = instruction[1:-1] # remove bos & eos
|
149 |
+
example += instruction
|
150 |
+
|
151 |
+
for conversation in conversations:
|
152 |
+
role = conversation['from']
|
153 |
+
content = conversation['value']
|
154 |
+
print(f"role {role}, raw content {content}")
|
155 |
+
content = tokenizer.encode_plus(f"{content}", None, max_length=None)['input_ids']
|
156 |
+
content = content[1:-1] # remove bos & eos
|
157 |
+
print(f"role {role}, content {content}")
|
158 |
+
example += content
|
159 |
+
return example
|
160 |
+
|
161 |
+
print('-'*80)
|
162 |
+
print(f"text is {text}")
|
163 |
+
|
164 |
+
from examples.aquila.cyg_conversation import default_conversation
|
165 |
+
|
166 |
+
conv = default_conversation.copy()
|
167 |
+
conv.append_message(conv.roles[0], text)
|
168 |
+
conv.append_message(conv.roles[1], None)
|
169 |
+
|
170 |
+
tokens = tokenizer.encode_plus(f"{conv.get_prompt()}", None, max_length=None)['input_ids']
|
171 |
+
tokens = tokens[1:-1]
|
172 |
+
|
173 |
+
with torch.no_grad():
|
174 |
+
out = aquila_generate(tokenizer, model, [text], max_gen_len:=200, top_p=0.95, prompts_tokens=[tokens])
|
175 |
+
print(f"pred is {out}")
|
176 |
+
|
177 |
+
|
178 |
+
```
|
179 |
+
|
180 |
+
### 2. 可监督微调/Supervised Fine-tuning(SFT)
|
181 |
+
#### Step 1: 配置模型/ Setup Checkpoints
|
182 |
+
在`./checkpoints_in`里新建`aquila-7b`目录。将微调后的checkpoint,以及原始`aquila-7b`模型里的其余文件,包括`config.json`, `mergex.txt`, `vocab.json`, `special_tokens_map.json`放进去
|
183 |
+
|
184 |
+
Create a new directory named `aquila-7b` inside `./checkpoints_in`. Place the fine-tuned checkpoint and all other files from the original `aquila-7b` model, including `config.json`, `mergex.txt`, `vocab.json`, and `special_tokens_map.json`, into this directory.
|
185 |
+
|
186 |
+
#### Step 2: 修改参数/ Modify Parameters
|
187 |
+
* `cd /examples/aquila`
|
188 |
+
* 配置`hostfile`文件, 参考[这里](../../../doc_zh/TUTORIAL_8_ENVIRONMENT_SETUP.md#a配置hostfilehostfile-中的v100-1-与sshconfig-对应) ; Configure the `hostfile` file, refer to [here](../../../docs/TUTORIAL_8_ENVIRONMENT_SETUP.md)
|
189 |
+
* 配置`bmtrain_mgpu.sh`文件, 将`SCRIPT_FILE`改成`aquila_sft.py`; configure the `bmtrain_mgpu.sh` file, change `SCRIPT_FILE` to `aquila_sft.py`
|
190 |
+
* (可选) 在`Aquila-sft.yaml`文件里更改参数 ; (optional) change parameters in `Aquila-sft.yaml`
|
191 |
+
|
192 |
+
| 参数名 Parameter | 类型 Type | 描述 Description |
|
193 |
+
|--------------------------------|------------|-------------------------------------------------------|
|
194 |
+
| batch_size | int | 每次迭代训练时,从数据集中抽取的样本数。一般来说,它越大,处理速度越快,但会占用更多的内存; The number of samples extracted from the dataset for each iteration during training. Generally, a larger batch size can speed up processing but may also consume more memory |
|
195 |
+
| gradient_accumulation_steps | int | 在更新模型权重之前,要对多个小批次进行梯度计算的次数。主要应用于GPU显存较小的情况下,可以使用小的batch_size,通过梯度累积达到与大batch_size相同的效果; The number of samples extracted from the dataset for each iteration during training. Generally, a larger batch size can speed up processing but may also consume more memoryimages |
|
196 |
+
| lr | float | 指控制模型更新参数时的步长或速率。学习率过高可能导致模型不收敛,而学习率过低则可能导致训练时间过长或者陷入局部最优解; The step size or rate at which the model updates its parameters during training. A high learning rate may cause the model not to converge, while a low learning rate may result in long training times or being stuck in a local optimum |
|
197 |
+
| warm_up | float | 初始学习率与原始学习率的比例; The ratio between the initial learning rate and the original learning rate
|
198 |
+
| save_interval | int | 模型保存的间隔,即每训练多少个iteration保存一次模型。当训练时间较长时,保存间隔可以避免因突然中断或出现错误导致训练成果全部丢失; The interval at which the model is saved, i.e., how often the model is saved per epoch during training. When training takes a long time, saving intervals can prevent all training achievements from being lost due to sudden interruptions or errors. |
|
199 |
+
| enable_sft_conversations_dataset_v3 | bool | 数据处理方式; Data preprocessing method |
|
200 |
+
| enable_sft_dataset_dir | str | 可监督微调的数据集目录; Dataset directory of SFT dataset |
|
201 |
+
| enable_sft_dataset_file | str | 可监督微调的数据集文件名; Filename of SFT dataset | |
|
202 |
+
|
203 |
+
|
204 |
+
|
205 |
+
|
206 |
+
#### Step 3: 启动可监督微调/Start SFT
|
207 |
+
```
|
208 |
+
bash dist_trigger_docker.sh hostfile aquila-sft.yaml aquila-7b [实验名]
|
209 |
+
```
|
210 |
+
接下来会输出下列信息,注意`NODES_NUM`应该与节点数相等,`LOGFILE`是模型运行的日志文件;The following information will be output. Note that `NODES_NUM` should be equal to the number of nodes, and `LOGFILE` is the log file for the model run.
|
211 |
+
|
212 |
+
![Screenshot](../img/info.jpg)
|
213 |
+
|
214 |
+
成功训练之前能看到如下信息(具体参数可能不同); Before successful training, you may see the following information with parameters that may differ:
|
215 |
+
|
216 |
+
![Screenshot](../img/info2.jpg)
|
217 |
+
|
218 |
+
|
219 |
+
## 证书/License
|
220 |
+
|
221 |
+
Aquila-7B开源模型使用 [智源Aquila系列模型许可协议](linkhere), 原始代码基于[Apache Licence 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
222 |
+
|
223 |
+
|
224 |
+
Aquila-7B open-source model is licensed under [ BAAI Aquila Model Licence Agreement](linkhere). The source code is under [Apache Licence 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|