已合并
补充微调README内容 #1836
AtomGit-Bot创建于 2024年10月31日
补充微调README内容 #1836
已合并
AtomGit-Bot创建于 2024年10月31日
refs/pull/1836/head合入到master
9 个文件变更+481-20
MREADME.md+12-6
@@ -330,13 +330,13 @@ MindSpeed-LLM作为昇腾大模型训练框架,旨在为华为 [昇腾芯片](
330<tbody>330<tbody>
331 <tr>331 <tr>
332 <td rowspan="2">微调数据集支持格式</td>332 <td rowspan="2">微调数据集支持格式</td>
333- <td><a href="https://github.com/hiyouga/LLaMA-Factory/blob/main/data/README.md#alpaca-format">Alpaca 风格</a></td>333+ <td><a href="./docs/features/alpaca_dataset.md">Alpaca 风格</a></td>
334 <td>✅</td>334 <td>✅</td>
335 <td>✅</td>335 <td>✅</td>
336 <td>【昇腾】</td>336 <td>【昇腾】</td>
337 </tr>337 </tr>
338 <tr>338 <tr>
339- <td><a href="https://github.com/hiyouga/LLaMA-Factory/blob/main/data/README.md#sharegpt-format">ShareGPT 风格</a></td>339+ <td><a href="./docs/features/sharegpt_dataset.md">ShareGPT 风格</a></td>
340 <td>✅</td>340 <td>✅</td>
341 <td>✅</td>341 <td>✅</td>
342 <td>【昇腾】</td>342 <td>【昇腾】</td>
@@ -435,18 +435,24 @@ MindSpeed-LLM作为昇腾大模型训练框架,旨在为华为 [昇腾芯片](
435 <td>【昇腾】</td>435 <td>【昇腾】</td>
436 </tr>436 </tr>
437 <tr>437 <tr>
438- <td rowspan="2">数据处理</td>438+ <td rowspan="3">数据处理</td>
439- <td>预训练数据处理</td>439+ <td><a href="./docs/features/pretrain_dataset.md">预训练数据处理</a></td>
440 <td>✅</td>440 <td>✅</td>
441 <td>✅</td>441 <td>✅</td>
442 <td>【昇腾】</td>442 <td>【昇腾】</td>
443 </tr>443 </tr>
444 <tr>444 <tr>
445- <td>指令微调数据处理</td>445+ <td><a href="./docs/features/alpaca_dataset.md">Alpaca风格指令微调数据处理</a></td>
446 <td>✅</td>446 <td>✅</td>
447 <td>✅</td>447 <td>✅</td>
448 <td>【昇腾】</td>448 <td>【昇腾】</td>
449 </tr>449 </tr>
450+ <tr>
451+ <td><a href="./docs/features/sharegpt_dataset.md">ShareGPT风格指令微调数据处理</a></td>
452+ <td>✅</td>
453+ <td>✅</td>
454+ <td>【昇腾】</td>
455+ </tr>
450 <tr>456 <tr>
451 <td rowspan="2">分布式推理</td>457 <td rowspan="2">分布式推理</td>
452 <td>流式推理</td>458 <td>流式推理</td>
@@ -470,8 +476,8 @@ MindSpeed-LLM作为昇腾大模型训练框架,旨在为华为 [昇腾芯片](
470 </tbody>476 </tbody>
471</table>477</table>
472 478 
473----
474 479 
480+---
475 481 
476## 昇腾工具链482## 昇腾工具链
477 483 
@@ -109,7 +109,7 @@ pip install -r requirements.txt
109 109 
110从Huggingface等网站下载开源模型权重110从Huggingface等网站下载开源模型权重
111 111 
112-预训练权重链接在 [MindSpeed 预置大模型](./models/pretrain.md/#mindspeed-llm-预置模型) 章节列表的`参数`列链接中可以获取112+预训练权重链接在 [MindSpeed-LLM 预置大模型](./models/pretrain.md/#mindspeed-llm-预置模型) 章节列表的`参数`列链接中可以获取
113 113 
114更多社区资源可以在`模型`列链接中获取,如`Chat/Instruct`权重等114更多社区资源可以在`模型`列链接中获取,如`Chat/Instruct`权重等
115 115 
@@ -778,7 +778,7 @@ CKPT_SAVE_DIR="./ckpt/llama-2-7b" #权重保存路径
778CKPT_LOAD_DIR="./model_weights/llama-2-7b-legacy/" #权重加载路径778CKPT_LOAD_DIR="./model_weights/llama-2-7b-legacy/" #权重加载路径
779TOKENIZER_MODEL="./model_from_hf/llama-2-7b-hf/tokenizer.model" #词表路径779TOKENIZER_MODEL="./model_from_hf/llama-2-7b-hf/tokenizer.model" #词表路径
780DATA_PATH="./dataset/enwiki_text_document" #数据集路径780DATA_PATH="./dataset/enwiki_text_document" #数据集路径
781-```781+ ```
782【--tokenizer-type】 782【--tokenizer-type】
783 783 
784参数值为PretrainedFromHF时, 词表路径仅需要填到模型文件夹即可,不需要到tokenizer.model文件784参数值为PretrainedFromHF时, 词表路径仅需要填到模型文件夹即可,不需要到tokenizer.model文件
@@ -865,7 +865,7 @@ bash examples/mcore/llama2/pretrain_llama2_7b_ptd.sh
865#### <span id="jump5.2"> 2. 配置微调参数865#### <span id="jump5.2"> 2. 配置微调参数
866 866 
867legacy分支的全参微调脚本保存在 examples/legacy 中各模型文件夹下:tune_xxx_xx_full_ptd.sh867legacy分支的全参微调脚本保存在 examples/legacy 中各模型文件夹下:tune_xxx_xx_full_ptd.sh
868- 868+ 
869mcore分支的全参微调脚本保存在 examples/mcore 中各模型文件夹下:tune_xxx_xx_full_ptd.sh869mcore分支的全参微调脚本保存在 examples/mcore 中各模型文件夹下:tune_xxx_xx_full_ptd.sh
870 870 
871需根据实际情况修改路径和参数值:871需根据实际情况修改路径和参数值:
@@ -883,7 +883,7 @@ CKPT_SAVE_DIR="./ckpt/llama-2-7b" #权重保存路径
883CKPT_LOAD_DIR="./model_weights/llama-2-7b-legacy/" #权重加载路径883CKPT_LOAD_DIR="./model_weights/llama-2-7b-legacy/" #权重加载路径
884TOKENIZER_MODEL="./model_from_hf/llama-2-7b-hf/" #词表路径884TOKENIZER_MODEL="./model_from_hf/llama-2-7b-hf/" #词表路径
885DATA_PATH="./finetune_dataset/alpaca" #数据集路径885DATA_PATH="./finetune_dataset/alpaca" #数据集路径
886-```886+ ```
887【--tokenizer-type】 887【--tokenizer-type】
888 888 
889参数值为PretrainedFromHF时, 词表路径仅需要填到模型文件夹即可,不需要到tokenizer.model文件889参数值为PretrainedFromHF时, 词表路径仅需要填到模型文件夹即可,不需要到tokenizer.model文件
@@ -901,12 +901,12 @@ DATA_PATH="./finetune_dataset/alpaca" #数据集路径
901python ./preprocess_data.py \901python ./preprocess_data.py \
902 --output-prefix ./finetune_dataset/alpaca \902 --output-prefix ./finetune_dataset/alpaca \
903 ......903 ......
904-```904+ ```
905则指令微调`DATA_PATH`也应为`"./finetune_dataset/alpaca"`905则指令微调`DATA_PATH`也应为`"./finetune_dataset/alpaca"`
906 906 
907 ```shell907 ```shell
908DATA_PATH="./finetune_dataset/alpaca" #数据集路径908DATA_PATH="./finetune_dataset/alpaca" #数据集路径
909-```909+ ```
910 910 
911【--load】 911【--load】
912 912 
@@ -950,12 +950,12 @@ python ./preprocess_data.py \
950 --tokenizer-type PretrainedFromHF \950 --tokenizer-type PretrainedFromHF \
951 --handler-name AlpacaStyleInstructionHandler \951 --handler-name AlpacaStyleInstructionHandler \
952 --prompt-type llama2952 --prompt-type llama2
953-```953+ ```
954则指令微调`DATA_PATH`也应为`"./finetune_dataset/llama-2-7b/alpaca"`954则指令微调`DATA_PATH`也应为`"./finetune_dataset/llama-2-7b/alpaca"`
955 955 
956 ```shell956 ```shell
957DATA_PATH="./finetune_dataset/llama-2-7b/alpaca" #数据集路径957DATA_PATH="./finetune_dataset/llama-2-7b/alpaca" #数据集路径
958-```958+ ```
959 959 
960【--prompt-type】960【--prompt-type】
961 961 
@@ -985,7 +985,7 @@ NNODES=2 #集群里的节点数,以实际情况填写,
985NODE_RANK="current node id" #当前节点的RANK,多个节点不能重复,主节点为0, 其他节点可以是1,2..985NODE_RANK="current node id" #当前节点的RANK,多个节点不能重复,主节点为0, 其他节点可以是1,2..
986WORLD_SIZE=$(($GPUS_PER_NODE * $NNODES))986WORLD_SIZE=$(($GPUS_PER_NODE * $NNODES))
987```987```
988- 988+ 
989 989 
990#### <span id="jump5.3"> 3. 启动全参微调990#### <span id="jump5.3"> 3. 启动全参微调
991 991 
@@ -0,0 +1,127 @@
1+# Alpaca风格数据集
2+ 
3+## 常用的Alpaca数据集
4+ 
5+常用的对话指令微调数据集有:
6+ 
7+- [单轮对话:Alpaca英文数据集](https://huggingface.co/datasets/tatsu-lab/alpaca)
8+- [单轮对话:Alpaca中文数据集](https://huggingface.co/datasets/llm-wizard/alpaca-gpt4-data-zh/resolve/main/alpaca_gpt4_data_zh.json)
9+- [多轮对话:AlpacaHistroy数据集](https://huggingface.co/datasets/kimnt93/oaast-selected)
10+- [链式思维 (CoT):Alpaca数据集](https://huggingface.co/datasets/QingyiSi/Alpaca-CoT/tree/main/Auto-CoT)
11+- [BELLE:指令微调数据集](https://huggingface.co/datasets/BelleGroup/train_0.5M_CN)
12+ 
13+## Alpaca风格数据集处理方法
14+ 
15+### Alpaca风格数据集下载
16+ 
17+Alpaca风格微调数据集下载可以基于网页直接下载,也可以基于命令行下载,比如:
18+ 
19+```bash
20+cd dataset/
21+wget https://huggingface.co/datasets/tatsu-lab/alpaca/resolve/main/data/train-00000-of-00001-a09b74b3ef9c3b56.parquet
22+cd ..
23+```
24+ 
25+### Alpaca风格数据集处理
26+ 
27+在指令监督微调时,`instruction` 列对应的内容会与 `input` 列对应的内容拼接后作为人类指令,即人类指令为 `instruction\ninput`其中 `\n`为用于连接的换行符。而 `output` 列对应的内容为模型回答。如果指定了history,则会将历史对话内容也加入进来。如果指定system 列,则对应的内容将被作为系统提示词。
28+ 
29+```shell
30+# 请按照您的真实环境 source set_env.sh 环境变量
31+source /usr/local/Ascend/ascend-toolkit/set_env.sh
32+mkdir ./finetune_dataset
33+ 
34+python ./preprocess_data.py \
35+ --input ./dataset/train-00000-of-00001-a09b74b3ef9c3b56.parquet \
36+ --tokenizer-name-or-path ./model_from_hf/llama-2-7b-hf/ \
37+ --output-prefix ./finetune_dataset/alpaca \
38+ --workers 4 \
39+ --log-interval 1000 \
40+ --tokenizer-type PretrainedFromHF \
41+ --handler-name AlpacaStyleInstructionHandler \
42+ --prompt-type llama2 # <-- 需要填入模型模板
43+ # --map-keys '{"prompt":"instruction","query":"input","response":"output"}' # 默认值,可不传
44+```
45+ 
46+【--input】
47+ 
48+可以直接输入到数据集目录或具体文件,如果是目录,则处理全部文件, 支持 .parquet \ .csv \ .json \ .jsonl \ .txt \ .arrow 格式, 同一个文件夹下的数据格式需要保持一致
49+ 
50+【--map-keys】
51+ 
52+`--map-keys`参数用于配置字段映射来使用数据集。
53+ 
54+Alpaca风格示例:
55+ 
56+```
57+[
58+{
59+ "instruction": "人类指令(必填)",
60+ "input": "人类输入(选填)",
61+ "output": "模型回答(必填)",
62+ "system": "系统提示词(选填)",
63+ "history": [
64+ ["第一轮指令(选填)", "第一轮回答(选填)"],
65+ ["第二轮指令(选填)", "第二轮回答(选填)"]
66+ ]
67+}
68+]
69+```
70+ 
71+对于上面格式的数据,`--map-keys`参数完整应为
72+ 
73+`'{"prompt":"instruction","query":"input","response":"output","system":"system","history":"history"}'`
74+ 
75+其中参数的key值`"prompt"、"query"、"response"、"system"、"history"`代表数据集列映射后的属性,在代码中是固定的,不应改变,value值`"instruction"、"input"、"output"、"system"、"history"`对应数据集的列名。
76+ 
77+考虑到alpaca数据集大部分都是`["instruction", "input", "output"]`型格式,因此我们为key值`["prompt", "query", "response"]`设置了默认值。因此上面格式`--map-keys`参数可简略为`'{"system": "system","history": "history"}'`
78+ 
79+若数据集中无`system``history`列,则`--map-keys`可省略。
80+ 
81+ 
82+【--prompt-type】
83+ 
84+用于指定模型模板,能够让base模型微调后能具备更好的对话能力。`prompt-type`的可选项可以在[templates](../../modellink/tasks/preprocess/templates.py)文件内查看。
85+ 
86+【--handler-name】
87+ 
88+微调数据预处理Alpaca风格数据集时,应指定为`AlpacaStyleInstructionHandler`,根据`--map-keys`参数提取对应数据的列。
89+ 
90+**示例1:**
91+ 
92+```
93+--map-keys '{"prompt":"notice","query":"question","response":"answer","system":"system_test","history":"histories"}'
94+```
95+ 
96+则会提取数据集里的`"notice"、"question"、"answer"、"system_test"、"histories"`列。
97+ 
98+**示例2:**
99+ 
100+```
101+--map-keys '{"history":"histories"}'
102+```
103+ 
104+则会提取数据集里的`"instruction"、"input"、"output"、"histories"`列,其中`"instruction"、"input"、"output"`列作为默认值隐式存在。
105+ 
106+### 启动脚本
107+ 
108+MindSpeed-LLM微调数据集处理脚本命名风格及启动方法为:
109+ 
110+```shell
111+# Legacy
112+# 命名及启动:examples/legacy/model_name/data_convert_xxx_instruction.sh
113+bash examples/legacy/llama2/data_convert_llama2_instruction.sh
114+```
115+ 
116+指令微调数据集处理结果如下:
117+ 
118+```shell
119+./finetune_dataset/alpaca_packed_attention_mask_document.bin
120+./finetune_dataset/alpaca_packed_attention_mask_document.idx
121+./finetune_dataset/alpaca_packed_input_ids_document.bin
122+./finetune_dataset/alpaca_packed_input_ids_document.idx
123+./finetune_dataset/alpaca_packed_labels_document.bin
124+./finetune_dataset/alpaca_packed_labels_document.idx
125+```
126+ 
127+微调时,数据集路径输入 `./finetune_dataset/alpaca` 即可
@@ -1,22 +1,34 @@
1# MindSpeed-LLM 单样本指令微调1# MindSpeed-LLM 单样本指令微调
2 2 
3+## 指令微调简介
3 4 
4-MindSpeed-LLM支持指令微调,方案与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>统一,在微调效果保持一致的前提下MindSpeed-LLM可以表现出优异性5+指令微调(Instruction Fine-Tuning)是种使预训练模型能够理解和执行自然语言指令的微调方法广泛应用于大规模语言模型。通过多任务、多样化的数据集上进行微调,指令微调使得模型在应对各种任务时更加灵活并更具泛化力。
6+ 
7+## 指令微调的原理
8+ 
9+指令微调的核心思想是通过多任务和多样化指令数据集,训练模型以理解和执行数据集中不同任务的指令。具体来说,指令微调首先收集多个不同任务的数据集,并将每个任务转换为指令形式的输入,帮助大模型在多样化任务上提升泛化能力。该过程不仅包括直接的监督训练,还可结合人类反馈进行进一步优化。指令微调的基本原理如下:
10+ 
11+![指令微调原理](../../sources/images/instruction_finetune/General_pipline_of_instruction_tuning.png)
12+ 
13+**MindSpeed-LLM支持的指令微调,方案与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>统一,在微调效果保持一致的前提下,MindSpeed-LLM可以表现出优异性能**
14+ 
15+## 【与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>微调Loss对比】
5 16 
6-【与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>微调Loss对比】
7<table>17<table>
8<tr>18<tr>
9<th rowspan="1">Llama2-7b模型与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>微调5个epoch后的loss对比图19<th rowspan="1">Llama2-7b模型与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>微调5个epoch后的loss对比图
10-<p align="center"> <img src="../../sources/images/tune_llama2_7b_MindSpeed-LLM_DeepSpeed_compare.png" height="270px" width="500px"> </p>20+<p align="center"> <img src="../../sources/images/instruction_finetune/tune_llama2_7b_MindSpeed-LLM_DeepSpeed_compare.png" height="270px" width="500px"> </p>
11</th>21</th>
12<th>22<th>
13<th rowspan="1">Qwen-7b模型与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>微调4个epoch后的loss对比图23<th rowspan="1">Qwen-7b模型与<a href="https://github.com/hiyouga/LLaMA-Factory/tree/main">DeepSpeed</a>微调4个epoch后的loss对比图
14-<p align="center"> <img src="../../sources/images/tune_qwen_7b_MindSpeed-LLM_DeepSpeed_compare.png" height="270px" width="500px"> </p>24+<p align="center"> <img src="../../sources/images/instruction_finetune/tune_qwen_7b_MindSpeed-LLM_DeepSpeed_compare.png" height="270px" width="500px"> </p>
15</tr>25</tr>
16</table>26</table>
17 27 
18 28 
19-【Llama2-7b微调后对话效果对比】29+ 
30+## 【Llama2-7b微调后对话效果对比】
31+ 
20<table>32<table>
21 <tr>33 <tr>
22 <th rowspan="1">Question</th>34 <th rowspan="1">Question</th>
@@ -37,6 +49,7 @@ MindSpeed-LLM支持指令微调,方案与<a href="https://github.com/hiyouga/L
37 <th>Generate a poem that expresses joy.</th>49 <th>Generate a poem that expresses joy.</th>
38 <th>I open my arms and accept life's challenge, 50 <th>I open my arms and accept life's challenge,
39 51 
52+ 
40Embracing all of life's uncertainty. 53Embracing all of life's uncertainty.
41 54 
42A future of promise awaits,55A future of promise awaits,
@@ -89,3 +102,58 @@ My hope is high and my spirit runs free,
89My soul is full and my heart does soep.</th>102My soul is full and my heart does soep.</th>
90 </tr>103 </tr>
91</table>104</table>
105+ 
106+## 指令微调示例
107+ 
108+`1x8`的集群配置下,使用`Atlas 900 A2 PODc`进行全参数微调。**以LLaMA2-7B模型在TP8PP1切分后生成的权重作为输入,进行指令微调示例。**
109+ 
110+`Alpaca`数据预处理部分详见[**Alpaca风格数据的说明文档**](alpaca_dataset.md)。
111+ 
112+`ShareGPT`数据预处理部分详见[**ShareGPT风格数据的说明文档**](sharegpt_dataset.md)。
113+ 
114+**接下来将以Alpaca数据集作为输入,进行全参数微调示例。**
115+ 
116+### 启动脚本
117+ 
118+使用LLaMA2-7B模型目录下的<a href="../../examples/legacy/llama2/tune_llama2_7b_full_ptd.sh">微调脚本</a>
119+ 
120+#### 填写相关路径
121+ 
122+`DATA_PATH`:指定数据预处理后的保存路径。
123+ 
124+`TOKENIZER_MODEL`:指定模型的分词器路径(例如`tokenizer.model`)。
125+ 
126+`CKPT_LOAD_DIR`:指向权重转换后保存的路径。
127+ 
128+`CKPT_SAVE_DIR`:指向用户指定的微调后权重保存路径(例如指定保存到`ckpt`文件夹下)。
129+ 
130+因此,根据之前的示例,路径应填写如下:
131+```bash
132+DATA_PATH="./finetune_dataset/alpaca"
133+CKPT_SAVE_DIR="./ckpt/"
134+TOKENIZER_MODEL="./model_from_hf/llama-2-7b-hf/"
135+CKPT_LOAD_DIR="./model_weights/llama-2-7b-legacy/"
136+```
137+#### 指令微调相关参数
138+ 
139+【--is-instruction-dataset】
140+ 
141+用于指定微调过程中采用指令微调数据集,以确保模型依据特定指令数据进行微调。
142+ 
143+【--prompt-type】
144+ 
145+用于指定模型模板,能够让base模型微调后能具备更好的对话能力。`prompt-type`的可选项可以在[`templates`](../../modellink/tasks/preprocess/templates.py)文件内查看。
146+ 
147+【--variable-seq-lengths】
148+ 
149+支持以动态的序列长度进行微调,默认padding到`8`的整数倍,可以通过`--pad-to-multiple-of`参数来修改padding的倍数。
150+ 
151+#### 运行脚本
152+ 
153+```bash
154+bash examples/legacy/llama2/tune_llama2_7b_full_ptd.sh
155+```
156+ 
157+## 参考文献
158+ 
159+[Zhang, S., Dong, L., Li, X., Zhang, S., Sun, X., Wang, S., Li, J., Hu, R., Zhang, T., Wu, F., & Wang, G. (2023). *Instruction Tuning for Large Language Models: A Survey*.](https://arxiv.org/pdf/2308.10792v5)
@@ -0,0 +1,89 @@
1+# 预训练数据集
2+ 
3+## 常用的预训练数据集
4+ 
5+- [Enwiki数据集](https://huggingface.co/datasets/lsb/enwiki20230101)
6+- [C4数据集](https://huggingface.co/datasets/allenai/c4)
7+- [ChineseWebText](https://huggingface.co/datasets/CASIA-LM/ChineseWebText)
8+ 
9+## 数据集下载
10+ 
11+数据集下载可以基于网页直接下载,也可以基于命令行下载,比如:
12+ 
13+```shell
14+mkdir dataset
15+cd dataset/
16+wget https://huggingface.co/datasets/lsb/enwiki20230101/resolve/main/data/train-00000-of-00042-d964455e17e96d5a.parquet
17+cd ..
18+```
19+ 
20+## 数据集处理
21+ 
22+### 预训练数据集处理方法
23+ 
24+```shell
25+# 请按照您的真实环境 source set_env.sh 环境变量
26+source /usr/local/Ascend/ascend-toolkit/set_env.sh
27+mkdir ./dataset
28+ 
29+python ./preprocess_data.py \
30+ --input ./dataset/train-00000-of-00042-d964455e17e96d5a.parquet \
31+ --tokenizer-name-or-path ./model_from_hf/llama-2-hf \
32+ --tokenizer-type PretrainedFromHF \
33+ --handler-name GeneralPretrainHandler \
34+ --output-prefix ./dataset/enwiki \
35+ --json-keys text \
36+ --workers 4 \
37+ --log-interval 1000
38+```
39+ 
40+【--input】
41+ 
42+可以直接输入到数据集目录或具体文件,如果是目录,则处理全部文件, 支持 .parquet \ .csv \ .json \ .jsonl \ .txt \ .arrow 格式, 同一个文件夹下的数据格式需要保持一致
43+ 
44+【--handler-name】
45+ 
46+当前预训练默认使用 `GeneralPretrainHandler`,支持的是预训练数据风格,提取数据的`text`列,格式如下:
47+ 
48+```shell
49+[
50+ {"text": "document"},
51+ {"other keys": "optional content"}
52+]
53+```
54+ 
55+用户可结合具体数据处理需求添加新的Handler进行数据处理
56+ 
57+【--json-keys】
58+ 
59+从文件中提取的列名列表,默认为 `text`,可以为 `text`, `input`, `title` 等多个输入,结合具体需求及数据集内容使用,如:
60+ 
61+```shell
62+--json-keys text input output \
63+```
64+ 
65+【--n-subs】
66+ 
67+数据预处理并行加速参数。当需要预处理的数据集比较大时,可以通过并行处理进行加速,方法为设置参数`--n-subs`,通过该参数设置并行处理数量。在数据预处理过程会将原始数据集切分为`n_sub`个子集,对子集进行并行处理,然后合并,从而实现加速。建议预处理数据集超过GB级别时加上该参数。
68+ 
69+ 
70+MindSpeed-LLM预训练数据集处理脚本命名风格及启动方法为:
71+ 
72+```shell
73+# Legacy
74+# 命名及启动:examples/legacy/model_name/data_convert_xxx_pretrain.sh
75+bash examples/legacy/llama2/data_convert_llama2_pretrain.sh
76+ 
77+# Mcore
78+# 命名及启动:examples/mcore/model_name/data_convert_xxx_pretrain.sh
79+bash examples/mcore/llama2/data_convert_llama2_pretrain.sh
80+```
81+ 
82+预训练数据集处理结果如下:
83+ 
84+```shell
85+./dataset/enwiki_text_document.bin
86+./dataset/enwiki_text_document.idx
87+```
88+ 
89+预训练时,数据集路径输入 `./dataset/enwiki_text_document` 即可
@@ -0,0 +1,171 @@
1+# ShareGPT 数据集
2+ 
3+## 常用的ShareGPT数据集
4+ 
5+常用的对话指令微调数据集有:
6+ 
7+- [Roleplay多轮对话:ShareGPT数据集](https://huggingface.co/datasets/shibing624/roleplay-zh-sharegpt-gpt4-data)
8+- [Chain-of-though: ShareGPT数据集](https://huggingface.co/datasets/isaiahbjork/chain-of-thought-sharegpt)
9+- [Capybara: ShareGPT数据集](https://huggingface.co/datasets/Undi95/Capybara-ShareGPT)
10+ 
11+## ShareGPT风格数据集下载
12+ 
13+`ShareGPT` 风格微调数据集下载可以基于网页直接下载,也可以基于命令行下载,比如:
14+ 
15+```shell
16+cd dataset/
17+wget https://huggingface.co/datasets/shibing624/roleplay-zh-sharegpt-gpt4-data/resolve/main/sharegpt_formatted_data-evol-gpt4.jsonl
18+cd ..
19+```
20+ 
21+## ShareGPT风格数据集处理方法
22+ 
23+`ShareGPT` 格式支持更多的角色种类,例如 `human、gpt、observation、function`等等。它们构成一个对象列表呈现在`conversations`列中。
24+ 
25+`ShareGPT`风格示例:
26+ 
27+```
28+[
29+ {
30+ "conversations": [
31+ {
32+ "from": "human",
33+ "value": "人类指令"
34+ },
35+ {
36+ "from": "function_call",
37+ "value": "工具参数"
38+ },
39+ {
40+ "from": "observation",
41+ "value": "工具结果"
42+ },
43+ {
44+ "from": "gpt",
45+ "value": "模型回答"
46+ }
47+ ],
48+ "system": "系统提示词(选填)",
49+ "tools": "工具描述(选填)"
50+ }
51+]
52+```
53+ 
54+`ShareGPT`格式数据预处理脚本:
55+ 
56+```shell
57+# 请按照您的真实环境 source set_env.sh 环境变量
58+source /usr/local/Ascend/ascend-toolkit/set_env.sh
59+mkdir ./finetune_dataset
60+ 
61+python ./preprocess_data.py \
62+ --input ./dataset/sharegpt_formatted_data-evol-gpt4.jsonl \
63+ --tokenizer-name-or-path ./model_from_hf/llama-2-7b-hf/ \
64+ --output-prefix ./finetune_dataset/sharegpt \
65+ --workers 4 \
66+ --log-interval 1000 \
67+ --tokenizer-type PretrainedFromHF \
68+ --handler-name SharegptStyleInstructionHandler \
69+ --prompt-type llama2 # <-- 需要填入模型模板
70+ # --map-keys '{"messages":"conversations", "tags":{"role_tag": "from","content_tag": "value","user_tag": "human","assistant_tag": "gpt","system_tag": "system", "observation_tag":"observation", "function_tag":"function_call"}}' # 默认值,可不传
71+```
72+ 
73+【--prompt-type】
74+ 
75+用于指定模型模板,能够让base模型微调后能具备更好的对话能力。`prompt-type`的可选项可以在[templates](../../modellink/tasks/preprocess/templates.py)文件内查看。
76+ 
77+【--map-keys】
78+ 
79+`--map-keys`参数用于配置字段映射来使用数据集。默认值为
80+ 
81+`'{"messages":"conversations", "tags":{"role_tag": "from","content_tag": "value","user_tag": "human","assistant_tag": "gpt","system_tag": "system", "observation_tag":"observation", "function_tag":"function_call"}}'`
82+ 
83+其中key值`"messages"、"tags"`代表数据集列映射后的属性,在代码中是固定的,不应改变。value值中`"conversations"`对应数据集的列名、`"from"`对应角色标志、`"human"、"gpt"、"system"、"observation"、"function_call"`对应角色种类、`"value"`对应具体内容标志。
84+ 
85+ 
86+以OpenAI格式为例,OpenAI 格式是 sharegpt 格式的一种特殊情况,其中第一条消息可能是系统提示词。
87+ 
88+OpenAI格式示例:
89+ 
90+```
91+[
92+ {
93+ "messages": [
94+ {
95+ "role": "system",
96+ "content": "系统提示词(选填)"
97+ },
98+ {
99+ "role": "user",
100+ "content": "人类指令"
101+ },
102+ {
103+ "role": "assistant",
104+ "content": "模型回答"
105+ }
106+ ]
107+ }
108+]
109+```
110+ 
111+OpenAI格式数据预处理脚本:
112+ 
113+```shell
114+# 请按照您的真实环境 source set_env.sh 环境变量
115+source /usr/local/Ascend/ascend-toolkit/set_env.sh
116+mkdir ./finetune_dataset
117+ 
118+python ./preprocess_data.py \
119+ --input ./dataset/xxx.json \
120+ --tokenizer-name-or-path ./model_from_hf/llama-2-7b-hf/ \
121+ --output-prefix ./finetune_dataset/openai \
122+ --workers 4 \
123+ --log-interval 1000 \
124+ --tokenizer-type PretrainedFromHF \
125+ --handler-name SharegptStyleInstructionHandler \
126+ --prompt-type llama2 \
127+ --map-keys '{"messages":"messages", "tags":{"role_tag": "role","content_tag": "content","user_tag": "user","assistant_tag": "assistant","system_tag": "system"}}'
128+```
129+ 
130+【--handler-name】
131+ 
132+微调数据预处理`ShareGPT`风格数据集时,应指定为`SharegptStyleInstructionHandler`,并根据`--map-keys`参数提取对应数据的列。
133+ 
134+**示例1:**
135+ 
136+```
137+--map-keys '{"messages":"chat"}'
138+```
139+ 
140+则会提取数据集里的`"chat"`列,其中`"tags"`属性包含角色格式和内容格式,做为默认值隐式存在,角色格式可以为:`"from": "human"、"from": "gpt"、"from": "observation"、"from": "function_call"`,内容格式为`"value": "具体内容"`
141+ 
142+**示例2:**
143+ 
144+```
145+--map-keys '{"messages":"messages", "tags":{"role_tag": "role","content_tag": "content","user_tag": "user","assistant_tag": "assistant"}}'
146+```
147+ 
148+则会提取数据集里的`"messages"`列,其中角色格式可以为:`"role": "user"、"role": "assistant"`,内容格式为`"content": "具体内容"`
149+ 
150+### 启动脚本
151+ 
152+MindSpeed-LLM微调数据集处理脚本命名风格及启动方法为:
153+ 
154+```shell
155+# Legacy
156+# 命名及启动:examples/legacy/model_name/data_convert_xxx_instruction.sh
157+bash examples/legacy/llama2/data_convert_llama2_instruction.sh
158+```
159+ 
160+指令微调数据集处理结果如下:
161+ 
162+```shell
163+./finetune_dataset/openai_packed_attention_mask_document.bin
164+./finetune_dataset/openai_packed_attention_mask_document.idx
165+./finetune_dataset/openai_packed_input_ids_document.bin
166+./finetune_dataset/openai_packed_input_ids_document.idx
167+./finetune_dataset/openai_packed_labels_document.bin
168+./finetune_dataset/openai_packed_labels_document.idx
169+```
170+ 
171+微调时,数据集路径输入 `./finetune_dataset/openai` 即可
Rsources/images/tune_llama2_7b_MindSpeed-LLM_DeepSpeed_compare.pngsources/images/instruction_finetune/tune_llama2_7b_MindSpeed-LLM_DeepSpeed_compare.png+0-0
文件重命名但无更改。
Rsources/images/tune_qwen_7b_MindSpeed-LLM_DeepSpeed_compare.pngsources/images/instruction_finetune/tune_qwen_7b_MindSpeed-LLM_DeepSpeed_compare.png+0-0
文件重命名但无更改。