jingyaogong
commited on
Commit
•
c173da2
1
Parent(s):
9acf1fc
Upload 9 files
Browse files- README.md +690 -199
- README_en.md +774 -0
- images/2-eval.png +0 -0
- images/LLM-structure-moe.png +0 -0
- images/LLM-structure.png +0 -0
- images/fastgpt.png +0 -0
- images/gpt3_config.png +0 -0
- images/logger.png +0 -0
- images/logo.png +0 -0
README.md
CHANGED
@@ -1,199 +1,690 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
![logo](./images/logo.png)
|
2 |
+
<div align="center">
|
3 |
+
|
4 |
+
[![GitHub Repo stars](https://img.shields.io/github/stars/jingyaogong/minimind?style=social)](https://github.com/jingyaogong/minimind/stargazers)
|
5 |
+
[![GitHub Code License](https://img.shields.io/github/license/jingyaogong/minimind)](LICENSE)
|
6 |
+
[![GitHub last commit](https://img.shields.io/github/last-commit/jingyaogong/minimind)](https://github.com/jingyaogong/minimind/commits/master)
|
7 |
+
[![GitHub pull request](https://img.shields.io/badge/PRs-welcome-blue)](https://github.com/jingyaogong/minimind/pulls)
|
8 |
+
[![Collection](https://img.shields.io/badge/🤗-MiniMind%20%20Collection-blue)](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5)
|
9 |
+
|
10 |
+
</div>
|
11 |
+
|
12 |
+
<div align="center">
|
13 |
+
<h3>"大道至简"</h3>
|
14 |
+
</div>
|
15 |
+
|
16 |
+
<div align="center">
|
17 |
+
|
18 |
+
中文 | [English](./README_en.md)
|
19 |
+
|
20 |
+
</div>
|
21 |
+
|
22 |
+
|
23 |
+
* 本开源项目旨在完全从0开始,训练出仅为26M大小的微型语言模型**MiniMind**。
|
24 |
+
* **MiniMind**极其轻量,体积约是 GPT3 的 $\frac{1}{7000}$,力求做到CPU也可快速推理甚至训练。
|
25 |
+
* **MiniMind**改进自DeepSeek-V2、Llama3结构,项目包含整个数据处理、pretrain、sft、dpo的全部阶段,包含混合专家(MoE)模型。
|
26 |
+
* 这是一个既是开源项目,又是入门LLM教程,同时也是一个初具雏形的开源模型,希望能起到抛砖引玉的作用。
|
27 |
+
|
28 |
+
---
|
29 |
+
|
30 |
+
# 📌 Introduction
|
31 |
+
|
32 |
+
大语言模型(LLM)领域,如 GPT、LLaMA、GLM 等,虽然它们效果惊艳,
|
33 |
+
但动辄10 Bilion庞大的模型参数个人设备显存远不够训练,甚至推理困难。
|
34 |
+
几乎所有人都不会只满足于用Lora等方案fine-tuing大模型学会一些新的指令,
|
35 |
+
这约等于在教牛顿玩21世纪的智能手机,然而,这远远脱离了学习物理本身的奥妙。
|
36 |
+
此外,卖课付费订阅的营销号漏洞百出的一知半解讲解AI的教程遍地,
|
37 |
+
让理解LLM的优质内容雪上加霜,严重阻碍了学习者。
|
38 |
+
|
39 |
+
因此,本项目的目标是把上手LLM的门槛无限降低,
|
40 |
+
直接从0开始训练一个极其轻量的语言模型。
|
41 |
+
|
42 |
+
(截至2024.8.27)MiniMind首发包含3个型号模型,最小仅需26M(0.02B),即可具备Amazing的对话能力!
|
43 |
+
|
44 |
+
| 模型 (大小) | 速度 (Tokens/s) | 推理占用 | 训练占用(`batch_size=8`) |
|
45 |
+
|------------------------|---------------|--------|----------------------|
|
46 |
+
| MiniMind-small-T (26M) | 91.9 | 0.5 GB | 3.6 GB |
|
47 |
+
| MiniMind-small (56M) | 85.2 | 0.7 GB | 4.5 GB |
|
48 |
+
| MiniMind (218M) | 57.6 | 2.1 GB | 10.4 GB |
|
49 |
+
| MiniMind-MoE (166M) | 64.9 | 1.6 GB | 7.4 GB |
|
50 |
+
|
51 |
+
> 该分析在一个带有Torch 2.1.2、CUDA 12.2和Flash Attention 2的RTX 3090 GPU上运行。
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
项目包含:
|
56 |
+
|
57 |
+
- 公开MiniMind模型代码(包含Dense和MoE模型)、Pretrain、SFT指令微调、LoRA微调、DPO偏好优化的全过程代码、数据集和来源。
|
58 |
+
- 兼容`transformers`、`accelerate`、`trl`、`peft`等流行框架。
|
59 |
+
- 训练支持单机单卡、单机多卡训练。训练过程中支持在任意位置停止,及在任意位置继续训练。
|
60 |
+
- 在Ceval数据集上进行模型测试的代码。
|
61 |
+
- 实现Openai-Api基本的chat接口,便于集成到第三方ChatUI使用(FastGPT、Open-WebUI等)。
|
62 |
+
|
63 |
+
希望此开源项目可以帮助LLM初学者快速入门!
|
64 |
+
|
65 |
+
👉**最近更新**
|
66 |
+
|
67 |
+
<details close>
|
68 |
+
<summary> <b>2024-08-27</b> </summary>
|
69 |
+
- 项目首次开源
|
70 |
+
</details>
|
71 |
+
|
72 |
+
# 📌 Environment
|
73 |
+
|
74 |
+
仅是我个人的软硬件环境配置,自行酌情更改:
|
75 |
+
|
76 |
+
* Ubuntu == 20.04
|
77 |
+
* Python == 3.9
|
78 |
+
* Pytorch == 2.1.2
|
79 |
+
* CUDA == 12.2
|
80 |
+
* [requirements.txt](./requirements.txt)
|
81 |
+
|
82 |
+
# 📌 Start Inference
|
83 |
+
|
84 |
+
<div align="center" style="font-size: 1.5em; font-weight: bold;">
|
85 |
+
<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="Hugging Face Logo" style="vertical-align: middle; height: 30px;" />
|
86 |
+
Hugging Face
|
87 |
+
|
88 |
+
[MiniMind-Collection](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5)
|
89 |
+
</div>
|
90 |
+
|
91 |
+
```bash
|
92 |
+
# step 1
|
93 |
+
git clone https://huggingface.co/jingyaogong/minimind
|
94 |
+
```
|
95 |
+
|
96 |
+
```bash
|
97 |
+
# step 2
|
98 |
+
python 2-eval.py
|
99 |
+
```
|
100 |
+
|
101 |
+
# 📌 Quick Start
|
102 |
+
|
103 |
+
* 1、克隆项目代码
|
104 |
+
```text
|
105 |
+
git clone https://github.com/jingyaogong/minimind.git
|
106 |
+
```
|
107 |
+
* 2、如果你需要自己训练
|
108 |
+
|
109 |
+
* 2.1 下载[数据集下载地址](#数据集下载地址)放到`./dataset`目录下
|
110 |
+
|
111 |
+
* 2.2 `python data_process.py`处理数据集,例如pretrain数据提前进行token-encoder、sft数据集抽离qa到csv文件。
|
112 |
+
|
113 |
+
* 2.3 在`./model/LMConfig.py` 中调整model的参数配置。
|
114 |
+
* 2.4 `python 1-pretrain.py` 执行预训练。
|
115 |
+
* 2.5 `python 3-full_sft.py` 执行指令微调。
|
116 |
+
* 2.6 `python 4-lora_sft.py` 执行lora微调(非必须)。
|
117 |
+
* 2.7 `python 5-dpo_train.py` 执行DPO人类偏好强化学习对齐(非必须)。
|
118 |
+
* 3、测试模型推理效果
|
119 |
+
* 从下面【训练完成的模型权重】下载权重到`./out/`目录下
|
120 |
+
```text
|
121 |
+
out
|
122 |
+
├── multi_chat
|
123 |
+
│ ├── full_sft_1024.pth
|
124 |
+
│ ├── full_sft_512.pth
|
125 |
+
│ ├── full_sft_640_moe.pth
|
126 |
+
│ └── full_sft_640.pth
|
127 |
+
├── single_chat
|
128 |
+
│ ├── full_sft_1024.pth
|
129 |
+
│ ├── full_sft_512.pth
|
130 |
+
│ ├── full_sft_640_moe.pth
|
131 |
+
│ └── full_sft_640.pth
|
132 |
+
├── full_sft_1024.pth
|
133 |
+
├── full_sft_512.pth
|
134 |
+
├── full_sft_640_moe.pth
|
135 |
+
├── full_sft_640.pth
|
136 |
+
├── pretrain_1024.pth
|
137 |
+
├── pretrain_640_moe.pth
|
138 |
+
├── pretrain_640.pth
|
139 |
+
```
|
140 |
+
* `python 0-eval_pretrain.py`测试预训练模型的接龙效果
|
141 |
+
* `python 2-eval.py`测试模型的对话效果
|
142 |
+
![2-eval](./images/2-eval.png)
|
143 |
+
|
144 |
+
🍭 【Tip】预训练和全参微调pretrain和full_sft均支持DDP多卡加速
|
145 |
+
|
146 |
+
* 单机N卡启动训练
|
147 |
+
|
148 |
+
```text
|
149 |
+
torchrun --nproc_per_node N 1-pretrain.py
|
150 |
+
```
|
151 |
+
|
152 |
+
```text
|
153 |
+
torchrun --nproc_per_node N 3-full_sft.py
|
154 |
+
```
|
155 |
+
|
156 |
+
# 📌 Data sources
|
157 |
+
|
158 |
+
- 🤖 分词器:nlp中的Tokenizer类似于词典,将单词从自然语言通过“词典”映射到0,1,36这样的数字,可以理解为数字就代表了单词在“词典”中的页码。
|
159 |
+
LLM分词器的构建方式有两种:一种是自己构造词表训练一个分词器,代码可见`train_tokenizer.py`;另一种是选择开源模型训练好的分词器。
|
160 |
+
“词典”当然可以直接选择用新华词典或是牛津词典,优点是token转化压缩率很好,但缺点是词表太长,动辄数十万个词汇短语;
|
161 |
+
也可以使用自己训练的分词器,优点是词表随意控制,缺点是压缩率不够理想,且生僻词不容易面面俱到。
|
162 |
+
当然,“词典”的选择很重要,LLM的输出本质上是SoftMax到词典N个词的多分类问题,然后通过“词典”解码到自然语言。
|
163 |
+
因为LLM体积非常小,为了避免模型头重脚轻(词嵌入embedding层参数占整个LLM比太高),所以词表长度需要选择比较小。
|
164 |
+
强大的开源模型例如01万物、千问、chatglm、mistral、Llama3等,它们的tokenizer词表长度如下:
|
165 |
+
|
166 |
+
| Tokenizer 模型 | 词表大小 | 来源 |
|
167 |
+
|--------------------|---------|------------|
|
168 |
+
| yi tokenizer | 64,000 | 01万物(中国) |
|
169 |
+
| qwen2 tokenizer | 151,643 | 阿里云(中国) |
|
170 |
+
| glm tokenizer | 151,329 | 智谱AI(中国) |
|
171 |
+
| mistral tokenizer | 32,000 | Mistral AI(法国) |
|
172 |
+
| llama3 tokenizer | 128,000 | Meta(美国) |
|
173 |
+
| minimind tokenizer | 6400 | 自定义 |
|
174 |
+
|
175 |
+
> 尽管Mistral中文词语占比很少,编解码效率弱于qwen2、glm等中文友好型分词器。
|
176 |
+
但MiniMind这里选择了mistral tokenizer作为分词器以保持整体参数轻量,避免头重脚轻,因为mistral的词表大小只有32,000。
|
177 |
+
且MiniMind在实际测试中几乎没有出现过生僻词汇解码失败的情况,效果良好。
|
178 |
+
|
179 |
+
> 方便对比测试效果,额外训练了一个自定义Tokenizer模型的版本**MiniMind(-T)**,自定义词表压缩长度到6400,使得LLM总参数进一步降低到40M左右。
|
180 |
+
|
181 |
+
---
|
182 |
+
|
183 |
+
- 📙【Pretrain数据】:[seq-monkey通用文本数据集](https://github.com/mobvoi/seq-monkey-data/blob/main/docs/pretrain_open_corpus.md)
|
184 |
+
是由多种公开来源的数据(如网页、百科、博客、开源代码、书籍等)汇总清洗而成。
|
185 |
+
整理成统一的JSONL格式,并经过了严格的筛选和去重,确保数据的全面性、规模、可信性和高质量。
|
186 |
+
总量大约在10B token,适合中文大语言模型的预训练。
|
187 |
+
|
188 |
+
---
|
189 |
+
|
190 |
+
- 📕【SFT数据】:[匠数大模型SFT数据集](https://www.modelscope.cn/datasets/deepctrl/deepctrl-sft-data)
|
191 |
+
是一个完整、格式统一、安全的大模型训练和研究资源。
|
192 |
+
从网络上的公开数据源收集并整理了大量开源数据集,对其进行了格式统一,数据清洗,
|
193 |
+
包含10M条数据的中文数据集和包含2M条数据的英文数据集。
|
194 |
+
总量大约在3B token,适合中文大语言模型的SFT。
|
195 |
+
数据集整合来源于以下所有数据(仅供参考,因此无需单独下载,仅需下载一个完整的【SFT数据】):
|
196 |
+
- [BelleGroup/train_3.5M_CN](https://huggingface.co/datasets/BelleGroup/train_3.5M_CN)
|
197 |
+
- [LinkSoul/instruction_merge_set](https://huggingface.co/datasets/LinkSoul/instruction_merge_set)
|
198 |
+
- [stingning/ultrachat](https://huggingface.co/datasets/stingning/ultrachat)
|
199 |
+
- [BAAI/COIG-PC-core](https://huggingface.co/datasets/BAAI/COIG-PC-core)
|
200 |
+
- [shibing624/sharegpt_gpt4](https://huggingface.co/datasets/shibing624/sharegpt_gpt4)
|
201 |
+
- [shareAI/ShareGPT-Chinese-English-90k](https://huggingface.co/datasets/shareAI/ShareGPT-Chinese-English-90k)
|
202 |
+
- [Tiger Research](https://huggingface.co/TigerResearch/sft_zh)
|
203 |
+
- [BelleGroup/school_math_0.25M](https://huggingface.co/datasets/BelleGroup/school_math_0.25M)
|
204 |
+
- [YeungNLP/moss-003-sft-data](https://huggingface.co/datasets/YeungNLP/moss-003-sft-data)
|
205 |
+
|
206 |
+
---
|
207 |
+
|
208 |
+
- 📘【DPO数据】:大约合并后共8万条dpo数据,人工标注的偏好数据,均来自[活字模型](https://github.com/HIT-SCIR/huozi)
|
209 |
+
,可以用于训练奖励模型,优化模型回复质量,使其更加符合人类偏好。
|
210 |
+
|
211 |
+
---
|
212 |
+
|
213 |
+
- 【更多数据集】目前已经有[HqWu-HITCS/Awesome-Chinese-LLM](https://github.com/HqWu-HITCS/Awesome-Chinese-LLM)
|
214 |
+
在收集和梳理中文LLM相关的开源模型、应用、数据集及教程等资料,并持续更新这方面的最新进展。全面且专业,Respect!
|
215 |
+
|
216 |
+
---
|
217 |
+
|
218 |
+
### 数据集下载地址
|
219 |
+
|
220 |
+
| MiniMind训练数据集 | 下载地址 |
|
221 |
+
|------------------|---------------------------------------------------------------------------------------------------------------|
|
222 |
+
| **【Pretrain数据】** | [seq-monkey通用文本数据集](http://share.mobvoi.com:5000/sharing/O91blwPkY) |
|
223 |
+
| **【SFT数据】** | [匠数大模型SFT数据集](https://www.modelscope.cn/datasets/deepctrl/deepctrl-sft-data/resolve/master/sft_data_zh.jsonl) |
|
224 |
+
| **【DPO数据】** | [活字数据集1](https://huggingface.co/datasets/Skepsun/huozi_rlhf_data_json) |
|
225 |
+
| **【DPO数据】** | [活字数据集2](https://huggingface.co/datasets/beyond/rlhf-reward-single-round-trans_chinese) |
|
226 |
+
|
227 |
+
# 📌 Model
|
228 |
+
|
229 |
+
MiniMind-Dense(和[Llama3.1](https://ai.meta.com/blog/meta-llama-3-1/)一样)使用了Transformer的Decoder-Only结构,跟GPT-3的区别在于:
|
230 |
+
|
231 |
+
* 采用了GPT-3的预标准化方法,也就是在每个Transformer子层的输入上进行归一化,而不是在输出上。具体来说,使用的是RMSNorm归一化函数。
|
232 |
+
* 用SwiGLU激活函数替代了ReLU,这样做是为了提高性能。
|
233 |
+
* 像GPT-Neo一样,去掉了绝对位置嵌入,改用了旋转位置嵌入(RoPE),这样在处理超出训练长度的推理时效果更好。
|
234 |
+
|
235 |
+
---
|
236 |
+
|
237 |
+
MiniMind-MoE模型,它的结构基于Llama3和[Deepseek-V2](https://arxiv.org/pdf/2405.04434)中的MixFFN混合专家模块。
|
238 |
+
|
239 |
+
* DeepSeek-V2在前馈网络(FFN)方面,采用了更细粒度的专家分割和共享的专家隔离技术,以提高Experts的效果。
|
240 |
+
|
241 |
+
---
|
242 |
+
|
243 |
+
MiniMind的整体结构一致,只是在RoPE计算、推理函数和FFN层的代码上做了一些小调整。
|
244 |
+
其结构如下图(重绘版):
|
245 |
+
|
246 |
+
![](./images/LLM-structure.png)
|
247 |
+
![](./images/LLM-structure-moe.png)
|
248 |
+
|
249 |
+
模型配置见[./model/LMConfig.py](./model/LMConfig.py)。模型型号和参数见下表:
|
250 |
+
|
251 |
+
| Model Name | params | len_vocab | n_layers | d_model | kv_heads | q_heads | share+route | TopK |
|
252 |
+
|------------------|--------|-----------|----------|---------|----------|---------|-------------|------|
|
253 |
+
| minimind-small-T | 26M | 6400 | 8 | 512 | 8 | 16 | - | - |
|
254 |
+
| minimind-small | 56M | 32000 | 8 | 640 | 8 | 16 | - | - |
|
255 |
+
| minimind | 218M | 32000 | 16 | 1024 | 8 | 16 | - | - |
|
256 |
+
| minimind-MoE | 166M | 32000 | 8 | 640 | 8 | 16 | 2+4 | 2 |
|
257 |
+
|
258 |
+
此外作为参考,GPT3的层数和维度参数见下表:
|
259 |
+
![gpt3_config.png](./images/gpt3_config.png)
|
260 |
+
|
261 |
+
# 📌 Experiment
|
262 |
+
|
263 |
+
```bash
|
264 |
+
CPU: Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz
|
265 |
+
内存:128 GB
|
266 |
+
显卡:NVIDIA GeForce RTX 3090(24GB) * 2
|
267 |
+
环境:python 3.9 + Torch 2.1.2 + DDP多卡训练
|
268 |
+
```
|
269 |
+
|
270 |
+
| Model Name | params | len_vocab | batch_size | pretrain_time | sft_single_time | sft_multi_time |
|
271 |
+
|------------------|--------|-----------|------------|--------------------|-------------------|---------------------|
|
272 |
+
| minimind-small-T | 26M | 6400 | 64 | ≈5 hour (1 epoch) | ≈2 hour (1 epoch) | ≈0.5 hour (1 epoch) |
|
273 |
+
| minimind-small | 56M | 32000 | 24 | ≈6 hour (1 epoch) | ≈2 hour (1 epoch) | ≈0.5 hour (1 epoch) |
|
274 |
+
| minimind | 218M | 32000 | 16 | ≈15 hour (1 epoch) | ≈5 hour (1 epoch) | ≈1 hour (1 epoch) |
|
275 |
+
| minimind-MoE | 166M | 32000 | 16 | ≈13 hour (1 epoch) | ≈5 hour (1 epoch) | ≈1 hour (1 epoch) |
|
276 |
+
|
277 |
+
---
|
278 |
+
|
279 |
+
1. **预训练(Text-to-Text)**:
|
280 |
+
- LLM首先要学习的并非直接与人交流,而是让肚子中充满知识的墨水,至于墨水理论上喝的越饱越好,产生大量的对世界的认知积累。
|
281 |
+
- 预训练就是让Model先埋头苦学大量基本的知识,例如从维基百科、新闻、常识、书籍等。
|
282 |
+
- 它无监督的从大量的文本数据中压缩知识到自己模型的权重,目的是:学会词语接龙。例如我们输入“秦始皇是”四个字,它在大量学习后能预测出下一句话大概率是“中国的第一位皇帝”。
|
283 |
+
> pretrain的学习率设置为1e-4到1e-5的动态学习率,预训练epoch数设为2,预训练时间不到1天。
|
284 |
+
```bash
|
285 |
+
torchrun --nproc_per_node 2 1-pretrain.py
|
286 |
+
```
|
287 |
+
2. **单轮次对话有监督微调(Single dialog Fine-tuning)**:
|
288 |
+
- 经过预训练,半成品LLM此时已经掌握了几乎所有的语言知识和百科常识。此时它还不会与人聊天,相反它只会无脑地进行输入词语的接龙,生成下一个词。
|
289 |
+
- 此时需要对半成品LLM做限制在聊天模板中进行微调,例如当它遇到这样的模板“<聊天开始>秦始皇是<聊天终止>
|
290 |
+
”后不再无脑接龙,而是意识到这是一段完整的对话结束。
|
291 |
+
- 我们称这个过程为指令微调,就如同让学富五车的「牛顿」先生适应21世纪的聊天习惯,学习屏幕左侧是对方消息,右侧是本人消息这个规律。
|
292 |
+
- 在训练时,MiniMind的指令和回答长度被截断在512,是为了节省显存空间。就像我们学习时,会先从短的文章开始,当学会阅读200字作文后,800字长文章就不需要再单独学习。
|
293 |
+
> 在推理时通过调整RoPE线性差值,实现长度外推到1024或2048及以上很方便。学习率设置为1e-5到1e-6的动态学习率,微调epoch数为5。
|
294 |
+
|
295 |
+
```bash
|
296 |
+
# 3-full_sft.py中设置数据集为sft_data_single.csv
|
297 |
+
torchrun --nproc_per_node 2 3-full_sft.py
|
298 |
+
```
|
299 |
+
3. **多轮对话微调(Multi dialog Fine-tuning)**:
|
300 |
+
- 在2的基础上,LLM已经学会一个问题->一个回答的聊天模板。此时仅需在具备历史问答的更长聊天模板上进一步微调即可。
|
301 |
+
- 我们仅需使用数据集的history_chat 字段,即历史对话,以及history_chat_response字段,即历史对话的回答。
|
302 |
+
- 构建【问题->回答,问题->回答,问题->】的新聊天模板,然后使用这个数据集进行微调。
|
303 |
+
- 学习完成的模型不仅仅只能回答当前问题,还能根据历史对话进行连贯的对话。
|
304 |
+
- 这一步并非必须,因为小模型长上文对话能力很弱,强行对齐多轮问答模板会损失一定程度的单轮SFT效果。
|
305 |
+
> 学习率设置为1e-5到1e-6的动态学习率,微调epoch数为2。
|
306 |
+
```bash
|
307 |
+
# 3-full_sft.py中设置数据集为sft_data.csv
|
308 |
+
torchrun --nproc_per_node 2 3-full_sft.py
|
309 |
+
```
|
310 |
+
4. **直接偏好优化,强化学习微调(Direct Preference Optimization, DPO)**:
|
311 |
+
- 在前面的训练中,机器人已经具备了基本的对话能力。但是,我们希望它能够更符合人的偏好,给出更让人满意的回答。
|
312 |
+
- 这个过程就像是让机器人参加工作培训,从优秀员工的作为例子,消极员工作为反例,学习如何更好地服务客户。
|
313 |
+
> 活字三元组(q,chose,reject)数据集,学习率le-5,半精度fp16,共1个epoch,耗时1h。
|
314 |
+
```bash
|
315 |
+
python 5-dpo_train.py
|
316 |
+
```
|
317 |
+
|
318 |
+
---
|
319 |
+
🔗训练完成的模型权重:
|
320 |
+
|
321 |
+
| Model Name | params | Config | pretrain_model | single_sft_model | multi_sft_model |
|
322 |
+
|------------------|--------|-------------------------------------------------|----------------------------------------------------------------|----------------------------------------------------------------|----------------------------------------------------------------|
|
323 |
+
| minimind-small-T | 26M | d_model=512<br/>n_layers=8 | - | [链接](https://pan.baidu.com/s/1_COe0FQRDmeapSsvArahCA?pwd=6666) | [链接](https://pan.baidu.com/s/1GsGsWSL0Dckl0YPRXiBIFQ?pwd=6666) |
|
324 |
+
| minimind-small | 56M | d_model=640<br/>n_layers=8 | [链接](https://pan.baidu.com/s/1nJuOpnu5115FDuz6Ewbeqg?pwd=6666) | [链接](https://pan.baidu.com/s/1lRX0IcpjNFSySioeCfifRQ?pwd=6666) | [链接](https://pan.baidu.com/s/1LzVxBpL0phtGUH267Undqw?pwd=6666) |
|
325 |
+
| minimind | 218M | d_model=1024<br/>n_layers=16 | [链接](https://pan.baidu.com/s/1jzA7uLEi-Jen2fW5olCmEg?pwd=6666) | [链接](https://pan.baidu.com/s/1Hvt0Q_UB_uW2sWTw6w1zRQ?pwd=6666) | [链接](https://pan.baidu.com/s/1fau9eat3lXilnrG3XNhG5Q?pwd=6666) |
|
326 |
+
| minimind-MoE | 166M | d_model=1024<br/>n_layers=8<br/>share+route=2+4 | [链接](https://pan.baidu.com/s/11CneDVTkw2Y6lNilQX5bWw?pwd=6666) | [链接](https://pan.baidu.com/s/1fRq4MHZec3z-oLK6sCzj_A?pwd=6666) | [链接](https://pan.baidu.com/s/1HC2KSM_-RHRtgv7ZDkKI9Q?pwd=6666) |
|
327 |
+
|
328 |
+
---
|
329 |
+
|
330 |
+
关于LLM的参数配置,有一篇很有意思的论文[MobileLLM](https://arxiv.org/pdf/2402.14905)做了详细的研究和实验。
|
331 |
+
scaling law在小模型中有自己独特的规律。
|
332 |
+
引起Transformer参数成规模变化的参数几乎只取决于`d_model`和`n_layers`。
|
333 |
+
|
334 |
+
* `d_model`↑+`n_layers`↓->矮胖子
|
335 |
+
* `d_model`↓+`n_layers`↑->瘦高个
|
336 |
+
|
337 |
+
2020年提出Scaling Law的论文认为,训练数据量、参数量以及训练迭代次数才是决定性能的关键因素,而模型架构的影响几乎可以忽视。
|
338 |
+
然而似乎这个定律对小模型并不完全适用。
|
339 |
+
MobileLLM提出架构的深度比宽度更重要,「深而窄」的「瘦长」模型可以学习到比「宽而浅」模型更多的抽象概念。
|
340 |
+
例如当模型参数固定在125M或者350M时,30~42层的「狭长」模型明显比12层左右的「矮胖」模型有更优越的性能,
|
341 |
+
在常识推理、问答、阅读理解等8个基准测试上都有类似的趋势。
|
342 |
+
这其实是非常有趣的发现,因为以往为100M左右量级的小模型设计架构时,几乎没人尝试过叠加超过12层。
|
343 |
+
|
344 |
+
这与MiniMind在训练过程中,模型参数量在`d_model`和`n_layers`之间进行调整实验观察到的效果是一致的。
|
345 |
+
然而「深而窄」的「窄」也是有维度极限的,当d_model<512时,词嵌入维度坍塌的劣势非常明显,
|
346 |
+
增加的layers并不能弥补词嵌入在固定q_head带来d_head不足的劣势。
|
347 |
+
当d_model>1536时,layers的增加似乎比d_model的优先级更高,更能带来具有“性价比”的参数->效果增益。
|
348 |
+
因此MiniMind设定small模型的d_model=640,n_layers=8来获取的「极小体积<->更好效果」的平衡。
|
349 |
+
设定d_model=1024,n_layers=16来获取效果的更大收益,更加符合小模型scaling-law的变化曲线。
|
350 |
+
|
351 |
+
# 📌 Eval
|
352 |
+
|
353 |
+
[A] [minimind-small-T(0.02B)](https://pan.baidu.com/s/1_COe0FQRDmeapSsvArahCA?pwd=6666)<br/>
|
354 |
+
[B] [minimind-small(0.05B)](https://pan.baidu.com/s/1lRX0IcpjNFSySioeCfifRQ?pwd=6666)<br/>
|
355 |
+
[C] [minimind-MoE(0.16B)](https://pan.baidu.com/s/1fRq4MHZec3z-oLK6sCzj_A?pwd=6666)<br/>
|
356 |
+
[D] [minimind(0.2B)](https://pan.baidu.com/s/1Hvt0Q_UB_uW2sWTw6w1zRQ?pwd=6666)<br/>
|
357 |
+
[E] [baby-llama2-chinese(0.2B)](https://github.com/DLLXW/baby-llama2-chinese)<br/>
|
358 |
+
[F] [chatlm-mini-chinese(0.2B)](https://github.com/charent/ChatLM-mini-Chinese)<br/>
|
359 |
+
|
360 |
+
```angular2html
|
361 |
+
[Q]: 一星期有多少天?
|
362 |
+
[A]: 一星期有七天。
|
363 |
+
[B]: 一星期有7天。
|
364 |
+
[C]: 根据您的计算,一星期有12个小时。因此,我们需要将小时数乘以12。这样,我们就可以得到12的小时数。
|
365 |
+
[D]: 一星期共有七天。
|
366 |
+
[E]: 作为一个人工智能助手,我无法确定您所描述的星期数。 如果您能够提供您所描述的星期数,我可以为您提供有关该星期天数的信息。
|
367 |
+
[F]: 一星期有七天,也就是七天的积,也就是 7 x 7 = 24 天。这个数字是通过将 24 除以 7 得到的,因为一周有七天,所以一星期有 24 x 7 = 24 天。
|
368 |
+
|
369 |
+
|
370 |
+
[Q]: 你知道长江吗?
|
371 |
+
[A]: 是的,长江是中国最长的河流,全长超过3300千米。
|
372 |
+
[B]: 是的,长江是中国最长的河流,全长约7100公里。它的流域面积约为3328万平方公里,是中国最大的河流之一,也是世界第三大河流,总长度约为6300千米。
|
373 |
+
[C]: 我知道。长江是我国的一个重要水系,有着悠久的历史和文化。长江是中华民族的象征和精神支柱,也是世界上最美丽的自然景观之一。长江沿岸地区的人们,特别是在长江流域生活了数千年。长江在中国的历史和文化中,尤其是历史悠久的文化,有着深厚的历史和文化底蕴。
|
374 |
+
[D]: 长江是中国的第一大河流,全长约6380公里。它是亚洲最长的河流,也是中国第一大河流。长江流域是中国的重要河流之一,有着丰富的自然资源和文化遗产。长江流域是中国最重要的农业和经济发展区,拥有众多的文化遗产和历史景点,是中国最重要的文化旅游目的地之一。
|
375 |
+
[E]: 同时也知道,中国是世界上最长的城市之一,拥有超过3400万人口。
|
376 |
+
[F]: 是的,长江是中国最长的河流,也是世界上最长的河流之一。它发源于青藏高原,流经九个省区,最终注入东海。长江流域的气候温和,四季分明,是中国重要的农业和工业基地。长江流域的水产资源丰富,是中国的重要渔业资源之一。
|
377 |
+
|
378 |
+
|
379 |
+
[Q]: 第一颗人造卫星是哪个国家发射的?
|
380 |
+
[A]: 第一颗人造卫星是斯普特尼克1号。
|
381 |
+
[B]: 第一颗人造卫星是美国发射的。
|
382 |
+
[C]: 第一颗人造卫星是中国国家航天科技集团有限公司的卫星,它是中国航天科技集团公司的卫星,由中国航天科技集���公司发射。
|
383 |
+
[D]: 第一颗人造卫星是苏联于1957年发射的。
|
384 |
+
[E]: 这颗名为“阿姆斯特朗”的卫星,于1961年11月20日发射,是第一个成功将人类送入太空的卫星。
|
385 |
+
[F]: 第一颗人造卫星是苏联于1957年4月4日发射的,它是由苏联宇航员尤里·加加林(Yuri Gagarin)和苏联工程师罗尔德·谢尔盖耶夫(Roald Skohley)共同发射的。在发射过程中,加加林和谢尔盖耶夫使用了一个名为“斯普特尼克1号”的小型卫星,它的直径为4.3米,重量为1,051公斤。这枚卫星被称为“斯普特尼克1号”,是苏联太空竞赛中的一个里程碑,也是人类历史上第一次在太空中进行太空行走。
|
386 |
+
|
387 |
+
|
388 |
+
[Q]: 你知道泰山在哪里吗?
|
389 |
+
[A]: 泰山位于中国东部地区,是中国五岳之一。
|
390 |
+
[B]: 泰山位于山东省泰安市,是中国五岳之一。
|
391 |
+
[C]: 泰山在哪里呢?
|
392 |
+
[D]: 泰山位于中国山东省昆山市,是中国古代文化的瑰宝之一,也是世界著名的山岳风景区之一。泰山是五岳之一,以其险峻的山峰、秀丽的自然风光和丰富的文化底蕴而闻名于世。
|
393 |
+
[E]: 作为一个人工智能助手,我无法访问互联网,因此无法提供关于你所在位置的信息。不过,你可以通过搜索或搜索相关关键词来获取有关你所在位置的信息,或者查看相关新闻或网站来获取有关你所在位置的信息。
|
394 |
+
[F]: 泰山位于中国山东省泰安市境内,是中国五岳之一,也是中国文化和历史的重要象征之一。它是中国五岳之一,也是中国道教和佛教的发源地之一。泰山的海拔高度为1,545米,是中国五岳之一,也是中国最著名的旅游景点之一。它的历史可以追溯到公元前5世纪,是中国古代帝王祭祀的场所。泰山也是中国文化的重要组成部分,被誉为“五岳之首”,是中国文化的重要遗产之一。
|
395 |
+
|
396 |
+
|
397 |
+
[Q]: 世界上最高的山峰是什么?
|
398 |
+
[A]: 世界上最高的山峰是珠穆朗玛峰,位于尼泊尔和中国的边境上,海拔8848米。
|
399 |
+
[B]: 珠穆朗玛峰是世界上最高的山峰,位于喜马拉雅山脉,海拔8848米。
|
400 |
+
[C]: 世界上最高的山峰是珠穆朗玛峰。
|
401 |
+
[D]: 世界上最高的山峰是珠穆朗玛峰,位于喜马拉雅山脉,海拔8,848.86米。
|
402 |
+
[E]: 世界上最高的山峰是珠穆朗玛峰,位于喜马拉雅山脉,海拔8,848.86米(29,031.69英尺)。
|
403 |
+
[F]: 世界上最高的山峰是珠穆朗玛峰,也称为萨加玛塔,位于喜马拉雅山脉的尼泊尔和中国边境之间,海拔8,848.86米(29,031.69英尺)。它是世界上最著名的登山目标之一,吸引着来自世界各地的登山者前来挑战。珠穆朗玛峰的名字来自藏语,意思是“女神的额峰”,它是由两个不同的山峰组成的,其中一个是位于尼泊尔的珠穆朗玛峰,另一个则位于中国。它的高度是通过测量海拔高度来确定的,因为它是通过测量地球的平均高度来确定的。尽管珠穆朗玛峰是世界上最高的山峰,但它并不是地球上任何其他地方都能到达的。地球上的其他地方,如南美洲的安第斯山脉,也是世界上最高的山脉,但它并不是地球上最高的山峰。总之,珠穆朗玛峰是世界上最高的山峰,但它并不是地球上任何地方都能到达的。它是地球上最高的山脉,但它并不是地球上任何地方都能到达的。
|
404 |
+
|
405 |
+
|
406 |
+
[Q]: 万有引力是谁提出的?
|
407 |
+
[A]: 万有引力是由英国物理学家牛顿提出的。他认为,所有物体都会产生引力,这个引力是由物体的质量和距离决定的。这个理论揭示了质量和距离之间的关系,并证明了万有引力的本质。
|
408 |
+
[B]: 万有引力是由牛顿发现的,它是由英国物理学家詹姆斯·瓦特于1879年提出的。
|
409 |
+
[C]: 万有引力是谁提出的?
|
410 |
+
[D]: 万有引力是由牛顿提出的,他发现每个物体都会对其他物体施加引力,这些力的大小取决于物体的质量和距离。
|
411 |
+
[E]: 引力是宇宙中一种力量,它是由质量或能量所组成的。根据牛顿的万有引力定律,一个物体之间的引力大小与它的质量成正比,与它的质量成反比。因此,牛顿的万有引力定律表明,一个物体之间的引力大小与它的质量成正比,与它的质量成反比。这个定律在物理学、天文学和物理学中都有广泛的应用。
|
412 |
+
[F]: 万有引力是由英国物理学家艾萨克·牛顿于1687年提出的。他在1687年发表了一篇著名的论文,题为《自然哲学的数学原理》,其中提出了万有引力定律,指出任何两个物体之间都存在着一种引力,这种引力的大小与它们的质量成正比,与它们之间的距离的平方成反比。这个定律被称为万有引力定律,它描述了质量和距离之间的关系。它表明,两个物体之间的引力与它们的质量成正比,与它们之间的距离的平方成反比。这个定律对于解释宇宙中的许多现象和现象之间的相互作用非常重要,例如行星绕太阳运动、恒星之间的引力透镜效应等等。它也被广泛应用于天文学、物理学和工程学等领域,为我们理解宇宙的本质和演化提供了重要的理论基础。
|
413 |
+
|
414 |
+
|
415 |
+
[Q]: 你知道大熊猫的主要食物是什么吗?
|
416 |
+
[A]: 大熊猫的主要食物是竹子。它们通常吃竹子,每天需要吃掉大约30公斤的竹子。
|
417 |
+
[B]: 大熊猫主要是竹子,它们的主要食物是竹子。大熊猫的消化系统比较特殊,它们每天需要消化大量的竹子才能维持其生存需要。除了竹子外,大熊猫还在野外生存。
|
418 |
+
[C]: 大熊猫的主要食物是竹子、蘑菇、蘑菇、甜菜和蘑菇。
|
419 |
+
[D]: 大熊猫是一种以竹子为食的哺乳动物,但主要食物来源是竹笋、竹叶、茎、茎等。
|
420 |
+
[E]: 大熊猫的主要食物是竹子。
|
421 |
+
[F]: 大熊猫是一种以竹子为主要食物的植食动物,它们的肠道结构适合消化纤维素含量高的竹子,但也会吃一些其他植物,如草本植物和小型哺乳动物。大熊猫的肠道结构也适应了高纤维的竹子,这使得它们能够消化大量的纤维素,从而帮助它们在野外生存。大熊猫的肠道中还含有一种叫做“纤维素酶”的酶类物质,这种酶能够帮助大熊猫分解纤维素,从而帮助它们消化大量的水分和营养物质。此外,大熊猫的肠道还含有一种叫做“纤维素蛋白”的蛋白质,这种蛋白质能够帮助大熊猫维持体内的能量水平,从而帮助它们在野外生存。总的来说,大熊猫的主要食物是竹子,但它们也会吃一些其他植物,如草本植物和小型哺乳动物。
|
422 |
+
|
423 |
+
[Q]: 海水为什么是咸的?
|
424 |
+
[A]: 海水中含有许多盐分,这些盐分可以导致海水咸度的增加。海水中的盐分主要来自于海水中的盐分,这些盐分可以从海水中的盐分中获得。海水中的氧化物和盐分可以与海水中的盐分形成氢键,从而使海水咸度增加。
|
425 |
+
[B]: 海水中含有丰富的钙、磷、钾和磷等元素,这些元素在海洋中的数量和分布非常有限。此外,海水中还含有各种生物和微生物的营养物质,如贝壳和海藻等。
|
426 |
+
[C]: 咸的是海水,因为海水的溶解度高于海水。海水的碳酸盐和盐基度也高于海水,这是因为海水的碳酸盐和盐基度都非常高,海水的碳酸盐和盐基度也非常高。
|
427 |
+
[D]: 海水中含有溶解盐类和其他矿物质,这些物质来自于地壳的侵蚀和吸附作用,而这些物质会溶解在水中,导致海水呈现咸味。
|
428 |
+
[E]: 因为水是许多生物的生存所必需的,它能够吸收和释放二氧化碳,释放氧气,维持大气中的水蒸气,以及维持水循环。水中的盐类和化学物质会释放出氧气,使地球上的生物呼吸。此外,水还具有许多其他功能,如保持水循环、维持水循环、调节气候和环境等。水是许多生物生存所必需的,它也是许多自然现象的重要基础。
|
429 |
+
[F]: 海水是咸的主要原因是因为其中含有大量的溶解盐类,其中最主要的是氯化钠(NaCl)。氯化钠是一种非常常见的盐类,它存在于地球上的大部分地区,包括海洋、湖泊、河流和地下水。当水从海洋中蒸发时,它会带走一部分盐分,使海水变得咸。此外,海中还含有其他溶解盐类的物质,如硫酸盐、硫酸镁、硫酸钙、硫酸镁盐、硫酸镁钾、硫酸镁钠、硫酸镁钙、硫酸镁镁钙、硫酸镁镁钙、硫酸镁镁钙、硫酸镁镁钠、硫酸镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁钙、硫酸镁镁镁镁钙、硫酸镁镁镁镁钙、硫酸镁镁镁镁钙、硫酸镁镁镁镁钙、硫酸镁镁镁镁钙、硫酸镁镁镁镁钙、硫酸镁镁镁镁镁钙、硫酸镁镁镁镁镁钙、硫酸镁镁镁镁镁钙、硫酸镁镁镁镁镁钙、硫酸镁镁镁镁镁镁钙、硫酸镁镁镁镁镁镁钙、硫酸镁镁镁镁镁镁钙、硫酸镁镁镁镁镁镁镁钙、硫酸镁镁镁镁
|
430 |
+
```
|
431 |
+
|
432 |
+
🙋♂️直接把上述模型的回答丢给GPT-4o,让它帮忙打个分:
|
433 |
+
|
434 |
+
---
|
435 |
+
根据你的要求,我将根据准确性、清晰性和完整性来评价每个模型的表现,并给出评分和排序。
|
436 |
+
|
437 |
+
### 模型评分和表现总结:
|
438 |
+
|
439 |
+
**A模型**
|
440 |
+
|
441 |
+
- **准确性**:大部分回答准确,但偶尔会有轻微错误。
|
442 |
+
- **清晰性**:回答简洁明了,语言流畅。
|
443 |
+
- **完整性**:回答内容有时略显简单,但整体信息足够。
|
444 |
+
- **评分**:80分
|
445 |
+
|
446 |
+
**B模型**
|
447 |
+
|
448 |
+
- **准确性**:多数回答准确,但有部分小错误(如第一颗人造卫星的问题)。
|
449 |
+
- **清晰性**:语言较为清晰,但有时表达稍显混乱。
|
450 |
+
- **完整性**:回答内容较全面,但存在信息误差。
|
451 |
+
- **评���**:75分
|
452 |
+
|
453 |
+
**C模型**
|
454 |
+
|
455 |
+
- **准确性**:回答内容不准确,且多次出现自问自答的情况。
|
456 |
+
- **清晰性**:语言流畅,但回答内容的逻辑性差。
|
457 |
+
- **完整性**:信息不完整,有时缺乏重要细节。
|
458 |
+
- **评分**:55分
|
459 |
+
|
460 |
+
**D模型**
|
461 |
+
|
462 |
+
- **准确性**:大多数回答准确,基本符合事实。
|
463 |
+
- **清晰性**:表达清晰,信息量适中。
|
464 |
+
- **完整性**:回答较为完整,但有些答案可能包含不必要的细节。
|
465 |
+
- **评分**:85分
|
466 |
+
|
467 |
+
**E模型**
|
468 |
+
|
469 |
+
- **准确性**:准确度较低,部分回答甚至与问题无关。
|
470 |
+
- **清晰性**:表达不够清晰,容易引起混淆。
|
471 |
+
- **完整性**:信息不完整,且有时偏离主题。
|
472 |
+
- **评分**:50分
|
473 |
+
|
474 |
+
**F模型**
|
475 |
+
|
476 |
+
- **准确性**:部分回答不准确,且有明显错误(如“24天”)。
|
477 |
+
- **清晰性**:表达冗长,容易造成混淆。
|
478 |
+
- **完整性**:信息过度冗长,且有重复内容,降低了答案的可读性。
|
479 |
+
- **评分**:60分
|
480 |
+
|
481 |
+
### 排序(从高到低):
|
482 |
+
|
483 |
+
1. **D模型** - 85分
|
484 |
+
2. **A模型** - 80分
|
485 |
+
3. **B模型** - 75分
|
486 |
+
4. **F模型** - 60分
|
487 |
+
5. **C模型** - 55分
|
488 |
+
6. **E模型** - 50分
|
489 |
+
|
490 |
+
这些评分和排序基于每个模型在准确性、清晰性和完整性三个方面的综合表现。
|
491 |
+
|
492 |
+
---
|
493 |
+
|
494 |
+
## 👉效果总结
|
495 |
+
|
496 |
+
* minimind系列(ABCD)的排序符合直觉,minimind(0.2B)评分最高,常识性问题的回答基本没有错误和幻觉。
|
497 |
+
* 出乎意料的是,minimind-small-T(0.02B)仅有26M参数,却可以接近minimind(0.2B)的表现。
|
498 |
+
* minimind(0.2B)的sft轮数`epochs`仅有不到2,因为训练时间是0.02B的好几倍,所以偷懒提前kill腾出资源给小模型,0.2B没有得到充分训练的情况下依然做到了最强,其实还是底大一级压死人。
|
499 |
+
* minimind-MoE(0.16B)表现很差,甚至不如它同配置的dense模型minimind(0.05B)
|
500 |
+
,其实这并非MoE的锅。同样是因为偷懒提前kill腾出资源给小模型,但是MoE模型多专家模式需要的训练轮次本来就需要酌情更高,在epochs设置为2时训练的极其不充分。minimind不久前实验阶段在Yi
|
501 |
+
tokenizer上试验过MoE的充分训练版本,可以做到比dense表现肉眼可见的好。现在先这样了hh,日后腾出服务器再训练更新v2 v3版本。
|
502 |
+
*
|
503 |
+
|
504 |
+
F模型的回答看起来是这里最完美的,尽管存在些许幻觉瞎编的情况。但GPT-4o和kimi的评分都一致认为它“信息过度冗长,且有重复内容,存在幻觉”。其实这种评价太严格了,100个字中有10个字是幻觉,就很容易把它归到0分。由于F模型训练文本默认长度更长,数据集大得多,所以回答的看起来很完备,在体积近似的情况下,数据比模型更重要得多。
|
505 |
+
|
506 |
+
> 🙋♂️个人主观评价:F>D>A≈B>C>E
|
507 |
+
|
508 |
+
> 🤖GPT-4o评价:D>A>B>F>C>E
|
509 |
+
|
510 |
+
总而言之scaling law:模型参数越大,训练数据越多模型的性能越强。
|
511 |
+
|
512 |
+
# 📌 Objective dataset: C-Eval
|
513 |
+
|
514 |
+
C-Eval评测代码见:`./eval_ceval.py`,
|
515 |
+
小模型的测评通常为了避免回复格式的难以固定的特点,
|
516 |
+
而直接判断`A`,`B`,`C`,`D`四个字母对应token预测概率,取最大的作为回答答案,与标准答案计算正确率。
|
517 |
+
minimind模型本身没有使用较大的数据集训练,也没有针对回答选择题的指令做微调,测评结果可以当个参考。
|
518 |
+
|
519 |
+
* 例如minimind-small的结果细项:
|
520 |
+
|
521 |
+
| 类别 | 正确数量/总题数 | 正确率 |
|
522 |
+
|---------------------------------|----------------|------------|
|
523 |
+
| probability_and_statistics_val | 3/18 | 16.67% |
|
524 |
+
| law_val | 5/24 | 20.83% |
|
525 |
+
| middle_school_biology_val | 4/21 | 19.05% |
|
526 |
+
| high_school_chemistry_val | 7/19 | 36.84% |
|
527 |
+
| high_school_physics_val | 5/19 | 26.32% |
|
528 |
+
| legal_professional_val | 2/23 | 8.70% |
|
529 |
+
| high_school_chinese_val | 4/19 | 21.05% |
|
530 |
+
| high_school_history_val | 6/20 | 30.00% |
|
531 |
+
| tax_accountant_val | 10/49 | 20.41% |
|
532 |
+
| modern_chinese_history_val | 4/23 | 17.39% |
|
533 |
+
| middle_school_physics_val | 4/19 | 21.05% |
|
534 |
+
| middle_school_history_val | 4/22 | 18.18% |
|
535 |
+
| basic_medicine_val | 1/19 | 5.26% |
|
536 |
+
| operating_system_val | 3/19 | 15.79% |
|
537 |
+
| logic_val | 4/22 | 18.18% |
|
538 |
+
| electrical_engineer_val | 7/37 | 18.92% |
|
539 |
+
| civil_servant_val | 11/47 | 23.40% |
|
540 |
+
| chinese_language_and_literature_val | 5/23 | 21.74% |
|
541 |
+
| college_programming_val | 10/37 | 27.03% |
|
542 |
+
| accountant_val | 9/49 | 18.37% |
|
543 |
+
| plant_protection_val | 7/22 | 31.82% |
|
544 |
+
| middle_school_chemistry_val | 4/20 | 20.00% |
|
545 |
+
| metrology_engineer_val | 3/24 | 12.50% |
|
546 |
+
| veterinary_medicine_val | 6/23 | 26.09% |
|
547 |
+
| marxism_val | 5/19 | 26.32% |
|
548 |
+
| advanced_mathematics_val | 5/19 | 26.32% |
|
549 |
+
| high_school_mathematics_val | 4/18 | 22.22% |
|
550 |
+
| business_administration_val | 8/33 | 24.24% |
|
551 |
+
| mao_zedong_thought_val | 8/24 | 33.33% |
|
552 |
+
| ideological_and_moral_cultivation_val | 5/19 | 26.32% |
|
553 |
+
| college_economics_val | 17/55 | 30.91% |
|
554 |
+
| professional_tour_guide_val | 10/29 | 34.48% |
|
555 |
+
| environmental_impact_assessment_engineer_val | 7/31 | 22.58% |
|
556 |
+
| computer_architecture_val | 6/21 | 28.57% |
|
557 |
+
| urban_and_rural_planner_val | 11/46 | 23.91% |
|
558 |
+
| college_physics_val | 5/19 | 26.32% |
|
559 |
+
| middle_school_mathematics_val | 3/19 | 15.79% |
|
560 |
+
| high_school_politics_val | 4/19 | 21.05% |
|
561 |
+
| physician_val | 13/49 | 26.53% |
|
562 |
+
| college_chemistry_val | 3/24 | 12.50% |
|
563 |
+
| high_school_biology_val | 5/19 | 26.32% |
|
564 |
+
| high_school_geography_val | 4/19 | 21.05% |
|
565 |
+
| middle_school_politics_val | 6/21 | 28.57% |
|
566 |
+
| clinical_medicine_val | 6/22 | 27.27% |
|
567 |
+
| computer_network_val | 2/19 | 10.53% |
|
568 |
+
| sports_science_val | 2/19 | 10.53% |
|
569 |
+
| art_studies_val | 14/33 | 42.42% |
|
570 |
+
| teacher_qualification_val | 12/44 | 27.27% |
|
571 |
+
| discrete_mathematics_val | 6/16 | 37.50% |
|
572 |
+
| education_science_val | 7/29 | 24.14% |
|
573 |
+
| fire_engineer_val | 9/31 | 29.03% |
|
574 |
+
| middle_school_geography_val | 1/12 | 8.33% |
|
575 |
+
|
576 |
+
```text
|
577 |
+
总题数: 1346
|
578 |
+
总正确数: 316
|
579 |
+
总正确率: 23.48%
|
580 |
+
```
|
581 |
+
|
582 |
+
---
|
583 |
+
|
584 |
+
#### 结果汇总:
|
585 |
+
|
586 |
+
| category | correct | question_count | accuracy |
|
587 |
+
|:-----------------|:--------:|:--------------:|:---------:|
|
588 |
+
| minimind-small-T | 344 | 1346 | 25.56% |
|
589 |
+
| minimind-small | 312 | 1346 | 23.18% |
|
590 |
+
| minimind | 351 | 1346 | 26.08% |
|
591 |
+
| minimind-moe | 316 | 1346 | 23.48% |
|
592 |
+
|
593 |
+
#### 以下来自GPT-4o对minimind表现的瞎猜:
|
594 |
+
|
595 |
+
```text
|
596 |
+
### 模型擅长的领域:
|
597 |
+
1. 高中的化学:正确率为42.11%,是最高的一个领域。说明模型在这方面的知识可能较为扎实。
|
598 |
+
2. 离散数学:正确率为37.50%,属于数学相关领域,表现较好。
|
599 |
+
3. 教育科学:正确率为37.93%,说明模型在教育相关问题上的表现也不错。
|
600 |
+
4. 基础医学:正确率为36.84%,在医学基础知识方面表现也比较好。
|
601 |
+
5. 操作系统:正确率为36.84%,说明模型在计算机操作系统方面的表现较为可靠。
|
602 |
+
|
603 |
+
### 模型不擅长的领域:
|
604 |
+
1. 法律相关:如法律专业(8.70%)和税务会计(20.41%),表现相对较差。
|
605 |
+
2. 中学和大学的物理:如中学物理(26.32%)和大学物理(21.05%),模型在物理相关的领域表现不佳。
|
606 |
+
3. 高中的政治、地理:如高中政治(15.79%)和高中地理(21.05%),模型在这些领域的正确率较低。
|
607 |
+
4. 计算机网络与体系结构:如计算机网络(21.05%)和计算机体系结构(9.52%),在这些计算机专业课程上的表现也不够好。
|
608 |
+
5. 环境影响评估工程师:正确率仅为12.90%,在环境科学领域的表现也不理想。
|
609 |
+
|
610 |
+
### 总结:
|
611 |
+
- 擅长领域:化学、数学(特别是离散数学)、教育科学、基础医学、计算机操作系统。
|
612 |
+
- 不擅长领域:法律、物理、政治、地理、计算机网络与体系结构、环境科学。
|
613 |
+
|
614 |
+
这表明模型在涉及逻辑推理、基础科学和一些工程技术领域的问题上表现较好,但在人文社科、环境科学以及某些特定专业领域(如法律和税务)上表现较弱。如果要提高模型的性能,可能需要加强它在人文社科、物理、法律、以及环境科学等方面的训练。
|
615 |
+
```
|
616 |
+
|
617 |
+
# 📌 Others
|
618 |
+
|
619 |
+
### 推理与导出
|
620 |
+
|
621 |
+
* [./export_model.py](./export_model.py)可以导出模型到transformers格式,推送到huggingface
|
622 |
+
*
|
623 |
+
MiniMind的huggingface集合地址:[MiniMind](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5)
|
624 |
+
|
625 |
+
---
|
626 |
+
|
627 |
+
### API推理
|
628 |
+
|
629 |
+
[./my_openai_api.py](./my_openai_api.py)完成了openai_api的聊天接口,方便将自己的模型接入第三方UI
|
630 |
+
例如fastgpt、OpenWebUI等
|
631 |
+
|
632 |
+
* 从[Huggingface](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5)下载模型权重文件
|
633 |
+
```
|
634 |
+
minimind (root dir)
|
635 |
+
├─minimind
|
636 |
+
| ├── config.json
|
637 |
+
| ├── generation_config.json
|
638 |
+
| ├── LMConfig.py
|
639 |
+
| ├── model.py
|
640 |
+
| ├── pytorch_model.bin
|
641 |
+
| ├── special_tokens_map.json
|
642 |
+
| ├── tokenizer_config.json
|
643 |
+
| ├── tokenizer.json
|
644 |
+
```
|
645 |
+
|
646 |
+
* 启动聊天服务端
|
647 |
+
```bash
|
648 |
+
python my_openai_api.py
|
649 |
+
```
|
650 |
+
* 测试服务接口
|
651 |
+
```bash
|
652 |
+
python chat_openai_api.py
|
653 |
+
```
|
654 |
+
* API接口示例,兼容openai api格式
|
655 |
+
```bash
|
656 |
+
curl http://ip:port/v1/chat/completions \
|
657 |
+
-H "Content-Type: application/json" \
|
658 |
+
-d '{
|
659 |
+
"model": "model-identifier",
|
660 |
+
"messages": [
|
661 |
+
{ "role": "user", "content": "世界上最高的山是什么?" }
|
662 |
+
],
|
663 |
+
"temperature": 0.7,
|
664 |
+
"max_tokens": -1,
|
665 |
+
"stream": true
|
666 |
+
}'
|
667 |
+
```
|
668 |
+
|
669 |
+
![images](./images/logger.png)
|
670 |
+
|
671 |
+
### 在fastgpt中接入使用minimind api
|
672 |
+
|
673 |
+
![images](./images/fastgpt.png)
|
674 |
+
|
675 |
+
# 📌 Acknowledge
|
676 |
+
|
677 |
+
如果你觉得本项目对你有所帮助,欢迎Star🎉✨。
|
678 |
+
|
679 |
+
篇幅不短水平有限难免纰漏,欢迎提issue交流或批评指正。
|
680 |
+
|
681 |
+
感谢以下开源项目的提供的灵感和开源数据集
|
682 |
+
|
683 |
+
* [baby-llama2-chinese](https://github.com/DLLXW/baby-llama2-chinese)
|
684 |
+
* [ChatLM-mini-Chinese](https://github.com/charent/ChatLM-mini-Chinese)
|
685 |
+
* [Zero-Chatgpt](https://github.com/AI-Study-Han/Zero-Chatgpt/tree/main)
|
686 |
+
|
687 |
+
# 📌 Statement
|
688 |
+
|
689 |
+
本项目不承担开源模型和代码导致的数据安全、舆情风险或发生任何模型被误导、滥用、传播、不当利用而产生的风险和责任。
|
690 |
+
|
README_en.md
ADDED
@@ -0,0 +1,774 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
![logo](./images/logo.png)
|
2 |
+
<div align="center">
|
3 |
+
|
4 |
+
[![GitHub Repo stars](https://img.shields.io/github/stars/jingyaogong/minimind?style=social)](https://github.com/jingyaogong/minimind/stargazers)
|
5 |
+
[![GitHub Code License](https://img.shields.io/github/license/jingyaogong/minimind)](LICENSE)
|
6 |
+
[![GitHub last commit](https://img.shields.io/github/last-commit/jingyaogong/minimind)](https://github.com/jingyaogong/minimind/commits/master)
|
7 |
+
[![GitHub pull request](https://img.shields.io/badge/PRs-welcome-blue)](https://github.com/jingyaogong/minimind/pulls)
|
8 |
+
[![Collection](https://img.shields.io/badge/🤗-MiniMind%20%20Collection-blue)](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5)
|
9 |
+
|
10 |
+
|
11 |
+
</div>
|
12 |
+
|
13 |
+
<div align="center">
|
14 |
+
<h3>"The Greatest Path is the Simplest"</h3>
|
15 |
+
</div>
|
16 |
+
|
17 |
+
<div align="center">
|
18 |
+
|
19 |
+
[中文](./README.md) | English
|
20 |
+
|
21 |
+
</div>
|
22 |
+
|
23 |
+
|
24 |
+
* This open-source project aims to train a miniature language model **MiniMind** from scratch, with a size of just 26MB.
|
25 |
+
* **MiniMind** is extremely lightweight, approximately $\frac{1}{7000}$ the size of GPT-3, designed to enable fast
|
26 |
+
inference and even training on CPUs.
|
27 |
+
* **MiniMind** is an improvement on the DeepSeek-V2 and Llama3 architectures. The project includes all stages of data
|
28 |
+
processing, pretraining, SFT, and DPO, and features a Mixture of Experts (MoE) model.
|
29 |
+
* This project is not only an open-source initiative but also a beginner's tutorial for LLMs, and serves as a nascent
|
30 |
+
open-source model with the hope of inspiring further development.
|
31 |
+
|
32 |
+
---
|
33 |
+
|
34 |
+
# 📌 Introduction
|
35 |
+
|
36 |
+
In the field of large language models (LLMs) such as GPT, LLaMA, GLM, etc., while their performance is impressive, the
|
37 |
+
massive model parameters—often in the range of 10 billion—make them difficult to train or even infer on personal devices
|
38 |
+
with limited memory. Most users do not settle for merely fine-tuning large models using methods like LoRA to learn a few
|
39 |
+
new instructions. It's akin to teaching Newton to use a 21st-century smartphone, which is far removed from the essence
|
40 |
+
of learning physics itself.
|
41 |
+
|
42 |
+
Additionally, the abundance of flawed, superficial AI tutorials offered by subscription-based marketing accounts
|
43 |
+
exacerbates the problem of finding quality content to understand LLMs, severely hindering learners.
|
44 |
+
|
45 |
+
Therefore, the goal of this project is to lower the barrier to entry for working with LLMs as much as possible, by
|
46 |
+
training an extremely lightweight language model from scratch.
|
47 |
+
|
48 |
+
(As of August 27, 2024) The initial release of MiniMind includes three model variants, with the smallest being just
|
49 |
+
26MB (0.02B) and still exhibiting amazing conversational capabilities!
|
50 |
+
|
51 |
+
| Model (Size) | Speed (Tokens/s) | Inference Memory | Training Memory (`batch_size=8`) |
|
52 |
+
|------------------------|------------------|------------------|----------------------------------|
|
53 |
+
| MiniMind-small-T (26M) | 91.9 | 0.5 GB | 3.6 GB |
|
54 |
+
| MiniMind-small (56M) | 85.2 | 0.7 GB | 4.5 GB |
|
55 |
+
| MiniMind (218M) | 57.6 | 2.1 GB | 10.4 GB |
|
56 |
+
| MiniMind-MoE (166M) | 64.9 | 1.6 GB | 7.4 GB |
|
57 |
+
|
58 |
+
> This analysis was conducted on an RTX 3090 GPU with Torch 2.1.2, CUDA 12.2, and Flash Attention 2.
|
59 |
+
|
60 |
+
The project includes:
|
61 |
+
|
62 |
+
- Public MiniMind model code (including Dense and MoE models), code for Pretrain, SFT instruction fine-tuning, LoRA
|
63 |
+
fine-tuning, and DPO preference optimization, along with datasets and sources.
|
64 |
+
- Compatibility with popular frameworks such as `transformers`, `accelerate`, `trl`, and `peft`.
|
65 |
+
- Training support for single-GPU and multi-GPU setups. The training process allows for stopping and resuming at any
|
66 |
+
point.
|
67 |
+
- Code for testing the model on the Ceval dataset.
|
68 |
+
- Implementation of a basic chat interface compatible with OpenAI's API, facilitating integration into third-party Chat
|
69 |
+
UIs (such as FastGPT, Open-WebUI, etc.).
|
70 |
+
|
71 |
+
We hope this open-source project helps LLM beginners get started quickly!
|
72 |
+
|
73 |
+
👉**Recent Updates**
|
74 |
+
|
75 |
+
<details close>
|
76 |
+
<summary> <b>2024-08-27</b> </summary>
|
77 |
+
- Project first open-sourced
|
78 |
+
</details>
|
79 |
+
|
80 |
+
# 📌 Environment
|
81 |
+
|
82 |
+
These are my personal software and hardware environment configurations. Please adjust according to your own setup:
|
83 |
+
|
84 |
+
* Ubuntu == 20.04
|
85 |
+
* Python == 3.9
|
86 |
+
* Pytorch == 2.1.2
|
87 |
+
* CUDA == 12.2
|
88 |
+
* [requirements.txt](./requirements.txt)
|
89 |
+
|
90 |
+
# 📌 Start Inference
|
91 |
+
|
92 |
+
<div align="center" style="font-size: 1.5em; font-weight: bold;">
|
93 |
+
<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="Hugging Face Logo" style="vertical-align: middle; height: 30px;" />
|
94 |
+
Hugging Face
|
95 |
+
|
96 |
+
[MiniMind-Collection](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5)
|
97 |
+
</div>
|
98 |
+
|
99 |
+
```bash
|
100 |
+
# step 1
|
101 |
+
git clone https://huggingface.co/jingyaogong/minimind
|
102 |
+
```
|
103 |
+
|
104 |
+
```bash
|
105 |
+
# step 2
|
106 |
+
python 2-eval.py
|
107 |
+
```
|
108 |
+
|
109 |
+
# 📌 Quick Start
|
110 |
+
|
111 |
+
*
|
112 |
+
1. Clone the project code
|
113 |
+
|
114 |
+
```text
|
115 |
+
git clone https://github.com/jingyaogong/minimind.git
|
116 |
+
```
|
117 |
+
|
118 |
+
*
|
119 |
+
2. If you need to train the model yourself
|
120 |
+
|
121 |
+
* 2.1 Download the [dataset download link](#dataset-download-link) and place it in the `./dataset` directory.
|
122 |
+
|
123 |
+
* 2.2 Run `python data_process.py` to process the dataset, such as token-encoding pretrain data and extracting QA
|
124 |
+
data to CSV files for the SFT dataset.
|
125 |
+
|
126 |
+
* 2.3 Adjust the model parameter configuration in `./model/LMConfig.py`.
|
127 |
+
* 2.4 Execute pretraining with `python 1-pretrain.py`.
|
128 |
+
* 2.5 Perform instruction fine-tuning with `python 3-full_sft.py`.
|
129 |
+
* 2.6 Perform LoRA fine-tuning (optional) with `python 4-lora_sft.py`.
|
130 |
+
* 2.7 Execute DPO human preference reinforcement learning alignment (optional) with `python 5-dpo_train.py`.
|
131 |
+
|
132 |
+
*
|
133 |
+
3. Test model inference performance
|
134 |
+
|
135 |
+
* Download the weights from the [trained model weights](#trained-model-weights) section below and place them in
|
136 |
+
the `./out/` directory
|
137 |
+
```text
|
138 |
+
out
|
139 |
+
├── multi_chat
|
140 |
+
│ ├── full_sft_1024.pth
|
141 |
+
│ ├── full_sft_512.pth
|
142 |
+
│ ├── full_sft_640_moe.pth
|
143 |
+
│ └── full_sft_640.pth
|
144 |
+
├── single_chat
|
145 |
+
│ ├── full_sft_1024.pth
|
146 |
+
│ ├── full_sft_512.pth
|
147 |
+
│ ├── full_sft_640_moe.pth
|
148 |
+
│ └── full_sft_640.pth
|
149 |
+
├── full_sft_1024.pth
|
150 |
+
├── full_sft_512.pth
|
151 |
+
├── full_sft_640_moe.pth
|
152 |
+
├── full_sft_640.pth
|
153 |
+
├── pretrain_1024.pth
|
154 |
+
├── pretrain_640_moe.pth
|
155 |
+
├── pretrain_640.pth
|
156 |
+
```
|
157 |
+
|
158 |
+
* Test the pretraining model's chain effect with `python 0-eval_pretrain.py`
|
159 |
+
* Test the model's conversational effect with `python 2-eval.py`
|
160 |
+
![2-eval](./images/2-eval.png)
|
161 |
+
|
162 |
+
🍭 **Tip**: Pretraining and full parameter fine-tuning (`pretrain` and `full_sft`) support DDP multi-GPU acceleration.
|
163 |
+
|
164 |
+
* Start training on a single machine with N GPUs
|
165 |
+
|
166 |
+
```text
|
167 |
+
torchrun --nproc_per_node N 1-pretrain.py
|
168 |
+
```
|
169 |
+
|
170 |
+
```text
|
171 |
+
torchrun --nproc_per_node N 3-full_sft.py
|
172 |
+
```
|
173 |
+
|
174 |
+
# 📌 Data sources
|
175 |
+
|
176 |
+
- 🤖 Tokenizer: In NLP, a Tokenizer is similar to a dictionary, mapping words from natural language to numbers like 0, 1,
|
177 |
+
36, etc., which can be understood as page numbers in the "dictionary" representing words. There are two ways to build
|
178 |
+
an LLM tokenizer: one is to create a vocabulary and train a tokenizer yourself, as seen in `train_tokenizer.py`; the
|
179 |
+
other is to use a pre-trained tokenizer from an open-source model.
|
180 |
+
|
181 |
+
You can use a standard dictionary like Xinhua or Oxford. The advantage is that token conversion has a good compression
|
182 |
+
rate, but the downside is that the vocabulary can be very large, with tens of thousands of words and phrases.
|
183 |
+
Alternatively, you can use a custom-trained tokenizer. The advantage is that you can control the vocabulary size, but
|
184 |
+
the compression rate may not be ideal, and rare words might be missed.
|
185 |
+
|
186 |
+
The choice of "dictionary" is crucial. The output of an LLM is essentially a multi-class classification problem over N
|
187 |
+
words in the dictionary, which is then decoded back into natural language. Because LLMs are very small, to avoid the
|
188 |
+
model being top-heavy (with the embedding layer's parameters taking up too much of the model), the vocabulary length
|
189 |
+
should be kept relatively small.
|
190 |
+
|
191 |
+
Powerful open-source models like 01万物, 千问, chatglm, mistral, and Llama3 have the following tokenizer vocabulary
|
192 |
+
sizes:
|
193 |
+
|
194 |
+
| Tokenizer Model | Vocabulary Size | Source |
|
195 |
+
|----------------------|------------------|-----------------------|
|
196 |
+
| yi tokenizer | 64,000 | 01-AI (China) |
|
197 |
+
| qwen2 tokenizer | 151,643 | Alibaba Cloud (China) |
|
198 |
+
| glm tokenizer | 151,329 | Zhipu AI (China) |
|
199 |
+
| mistral tokenizer | 32,000 | Mistral AI (France) |
|
200 |
+
| llama3 tokenizer | 128,000 | Meta (USA) |
|
201 |
+
| minimind tokenizer | 6,400 | Custom |
|
202 |
+
|
203 |
+
> Although Mistral’s Chinese vocabulary proportion is small and its encoding/decoding efficiency is weaker than
|
204 |
+
Chinese-friendly tokenizers like qwen2 and glm, MiniMind chose the Mistral tokenizer to keep the overall model
|
205 |
+
lightweight and avoid being top-heavy, as Mistral’s vocabulary size is only 32,000. MiniMind has shown excellent
|
206 |
+
performance in practical tests, with almost no failures in decoding rare words.
|
207 |
+
|
208 |
+
> For comparison purposes, an additional custom Tokenizer version **MiniMind(-T)** was trained, reducing the
|
209 |
+
vocabulary size to 6,400, which further decreases the total model parameters to around 40M.
|
210 |
+
|
211 |
+
---
|
212 |
+
|
213 |
+
- 📙 **[Pretrain Data](https://github.com/mobvoi/seq-monkey-data/blob/main/docs/pretrain_open_corpus.md)**:
|
214 |
+
The [Seq-Monkey General Text Dataset](https://github.com/mobvoi/seq-monkey-data/blob/main/docs/pretrain_open_corpus.md)
|
215 |
+
is a collection of data from various public sources such as websites, encyclopedias, blogs, open-source code, books,
|
216 |
+
etc. It has been compiled, cleaned, and organized into a unified JSONL format, with rigorous filtering and
|
217 |
+
deduplication to ensure data comprehensiveness, scale, reliability, and high quality. The total amount is
|
218 |
+
approximately 10B tokens, suitable for pretraining Chinese large language models.
|
219 |
+
|
220 |
+
---
|
221 |
+
|
222 |
+
- 📕 **[SFT Data](https://www.modelscope.cn/datasets/deepctrl/deepctrl-sft-data)**:
|
223 |
+
The [Jiangshu Large Model SFT Dataset](https://www.modelscope.cn/datasets/deepctrl/deepctrl-sft-data) is a
|
224 |
+
comprehensive, uniformly formatted, and secure resource for large model training and research. It includes a large
|
225 |
+
amount of open-source data collected and organized from publicly available online sources, with format unification and
|
226 |
+
data cleaning. It comprises a Chinese dataset with 10M entries and an English dataset with 2M entries. The total
|
227 |
+
amount is approximately 3B tokens, suitable for SFT of Chinese large language models. The dataset integration includes
|
228 |
+
all data from the following sources (for reference only, no need to download separately, just download the
|
229 |
+
complete [SFT Data]):
|
230 |
+
|
231 |
+
- [BelleGroup/train_3.5M_CN](https://huggingface.co/datasets/BelleGroup/train_3.5M_CN)
|
232 |
+
- [LinkSoul/instruction_merge_set](https://huggingface.co/datasets/LinkSoul/instruction_merge_set)
|
233 |
+
- [stingning/ultrachat](https://huggingface.co/datasets/stingning/ultrachat)
|
234 |
+
- [BAAI/COIG-PC-core](https://huggingface.co/datasets/BAAI/COIG-PC-core)
|
235 |
+
- [shibing624/sharegpt_gpt4](https://huggingface.co/datasets/shibing624/sharegpt_gpt4)
|
236 |
+
- [shareAI/ShareGPT-Chinese-English-90k](https://huggingface.co/datasets/shareAI/ShareGPT-Chinese-English-90k)
|
237 |
+
- [Tiger Research](https://huggingface.co/TigerResearch/sft_zh)
|
238 |
+
- [BelleGroup/school_math_0.25M](https://huggingface.co/datasets/BelleGroup/school_math_0.25M)
|
239 |
+
- [YeungNLP/moss-003-sft-data](https://huggingface.co/datasets/YeungNLP/moss-003-sft-data)
|
240 |
+
- 📘 **DPO Data**: Approximately 80,000 DPO (Direct Preference Optimization) data entries, which are manually labeled
|
241 |
+
preference data, come from [Huozi Model](https://github.com/HIT-SCIR/huozi). These can be used to train reward models
|
242 |
+
to optimize response quality and align more closely with human preferences.
|
243 |
+
|
244 |
+
---
|
245 |
+
|
246 |
+
- **More Datasets**: [HqWu-HITCS/Awesome-Chinese-LLM](https://github.com/HqWu-HITCS/Awesome-Chinese-LLM) is currently
|
247 |
+
collecting and organizing open-source models, applications, datasets, and tutorials related to Chinese LLMs, with
|
248 |
+
continuous updates on the latest developments in this field. Comprehensive and professional, respect!
|
249 |
+
|
250 |
+
---
|
251 |
+
|
252 |
+
### Dataset Download Links
|
253 |
+
|
254 |
+
| MiniMind Training Dataset | Download Link |
|
255 |
+
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------|
|
256 |
+
| **[Pretrain Data]** | [Seq-Monkey General Text Dataset](http://share.mobvoi.com:5000/sharing/O91blwPkY) |
|
257 |
+
| **[SFT Data]** | [Jiangshu Large Model SFT Dataset](https://www.modelscope.cn/datasets/deepctrl/deepctrl-sft-data/resolve/master/sft_data_zh.jsonl) |
|
258 |
+
| **[DPO Data]** | [Huozi Dataset 1](https://huggingface.co/datasets/Skepsun/huozi_rlhf_data_json) |
|
259 |
+
| **[DPO Data]** | [Huozi Dataset 2](https://huggingface.co/datasets/beyond/rlhf-reward-single-round-trans_chinese) |
|
260 |
+
|
261 |
+
# 📌 Model
|
262 |
+
|
263 |
+
MiniMind-Dense (like [Llama3.1](https://ai.meta.com/blog/meta-llama-3-1/)) uses a Transformer Decoder-Only architecture.
|
264 |
+
The differences from GPT-3 are:
|
265 |
+
|
266 |
+
* It employs GPT-3's pre-normalization method, which normalizes the input of each Transformer sub-layer rather than the
|
267 |
+
output. Specifically, it uses the RMSNorm normalization function.
|
268 |
+
* It replaces ReLU with the SwiGLU activation function to enhance performance.
|
269 |
+
* Like GPT-Neo, it omits absolute position embeddings in favor of Rotary Position Embeddings (RoPE), which improves
|
270 |
+
performance for inference beyond the training length.
|
271 |
+
|
272 |
+
---
|
273 |
+
|
274 |
+
The MiniMind-MoE model is based on the MixFFN mixture-of-experts module from Llama3
|
275 |
+
and [DeepSeek-V2](https://arxiv.org/pdf/2405.04434).
|
276 |
+
|
277 |
+
* DeepSeek-V2 adopts more granular expert partitioning and shared expert isolation techniques in the feed-forward
|
278 |
+
network (FFN) to improve the performance of experts.
|
279 |
+
|
280 |
+
---
|
281 |
+
|
282 |
+
The overall structure of MiniMind remains consistent, with minor adjustments in RoPE calculations, inference functions,
|
283 |
+
and FFN layer code. The structure is illustrated in the figure below (redrawn):
|
284 |
+
|
285 |
+
![](./images/LLM-structure.png)
|
286 |
+
![](./images/LLM-structure-moe.png)
|
287 |
+
Model configurations can be found in [./model/LMConfig.py](./model/LMConfig.py). The model types and parameters are
|
288 |
+
shown in the table below:
|
289 |
+
|
290 |
+
| Model Name | Params | Vocabulary Size | Layers | Model Dimension | KV Heads | Query Heads | Share+Route | TopK |
|
291 |
+
|------------------|--------|-----------------|--------|-----------------|----------|-------------|-------------|------|
|
292 |
+
| minimind-small-T | 26M | 6400 | 8 | 512 | 8 | 16 | - | - |
|
293 |
+
| minimind-small | 56M | 32000 | 8 | 640 | 8 | 16 | - | - |
|
294 |
+
| minimind | 218M | 32000 | 16 | 1024 | 8 | 16 | - | - |
|
295 |
+
| minimind-MoE | 166M | 32000 | 8 | 640 | 8 | 16 | 2+4 | 2 |
|
296 |
+
|
297 |
+
For reference, the configuration details for GPT-3 are shown in the table below:
|
298 |
+
![gpt3_config.png](./images/gpt3_config.png)
|
299 |
+
|
300 |
+
# 📌 Experiment
|
301 |
+
|
302 |
+
```bash
|
303 |
+
CPU: Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz
|
304 |
+
Memory: 128 GB
|
305 |
+
GPU: NVIDIA GeForce RTX 3090 (24GB) * 2
|
306 |
+
Environment: python 3.9 + Torch 2.1.2 + DDP multi-GPU training
|
307 |
+
```
|
308 |
+
|
309 |
+
| Model Name | params | len_vocab | batch_size | pretrain_time | sft_single_time | sft_multi_time |
|
310 |
+
|------------------|--------|-----------|------------|--------------------|-------------------|---------------------|
|
311 |
+
| minimind-small-T | 26M | 6400 | 64 | ≈5 hour (1 epoch) | ≈2 hour (1 epoch) | ≈0.5 hour (1 epoch) |
|
312 |
+
| minimind-small | 56M | 32000 | 24 | ≈6 hour (1 epoch) | ≈2 hour (1 epoch) | ≈0.5 hour (1 epoch) |
|
313 |
+
| minimind | 218M | 32000 | 16 | ≈15 hour (1 epoch) | ≈5 hour (1 epoch) | ≈1 hour (1 epoch) |
|
314 |
+
| minimind-MoE | 166M | 32000 | 16 | ≈13 hour (1 epoch) | ≈5 hour (1 epoch) | ≈1 hour (1 epoch) |
|
315 |
+
|
316 |
+
---
|
317 |
+
|
318 |
+
1. **Pretraining (Text-to-Text)**:
|
319 |
+
- LLMs first need to absorb a vast amount of knowledge, much like filling a well with ink. The more "ink" it has,
|
320 |
+
the better its understanding of the world will be.
|
321 |
+
- Pretraining involves the model learning a large amount of basic knowledge from sources such as Wikipedia, news
|
322 |
+
articles, common knowledge, books, etc.
|
323 |
+
- It unsupervisedly compresses knowledge from vast text data into its model weights with the aim of learning word
|
324 |
+
sequences. For instance, if we input “Qin Shi Huang is,” after extensive training, the model can predict that the
|
325 |
+
next probable sentence is “the first emperor of China.”
|
326 |
+
> The learning rate for pretraining is set dynamically between 1e-4 and 1e-5, with 2 epochs and a training time of
|
327 |
+
less than one day.
|
328 |
+
```bash
|
329 |
+
torchrun --nproc_per_node 2 1-pretrain.py
|
330 |
+
```
|
331 |
+
|
332 |
+
2. **Single Dialog Fine-Tuning**:
|
333 |
+
- After pretraining, the semi-finished LLM has almost all language knowledge and encyclopedic common sense. At this
|
334 |
+
stage, it only performs word sequences without understanding how to chat with humans.
|
335 |
+
- The model needs fine-tuning to adapt to chat templates. For example, it should recognize that a template
|
336 |
+
like “<chat start> Qin Shi Huang is <chat end>” indicates the end of a complete conversation, rather than just
|
337 |
+
generating the next word.
|
338 |
+
- This process is known as instruction fine-tuning, akin to teaching a knowledgeable person like Newton to adapt to
|
339 |
+
21st-century chat habits, learning the pattern of messages on the left and responses on the right.
|
340 |
+
- During training, MiniMind’s instruction and response lengths are truncated to 512 to save memory. Just as we start
|
341 |
+
with shorter texts when learning, we don’t need to separately learn longer articles once we master shorter ones.
|
342 |
+
> During inference, RoPE can be linearly interpolated to extend lengths to 1024 or 2048 or more. The learning rate is
|
343 |
+
set dynamically between 1e-5 and 1e-6, with 5 epochs for fine-tuning.
|
344 |
+
```bash
|
345 |
+
# Set dataset to sft_data_single.csv in 3-full_sft.py
|
346 |
+
torchrun --nproc_per_node 2 3-full_sft.py
|
347 |
+
```
|
348 |
+
|
349 |
+
3. **Multi-Dialog Fine-Tuning**:
|
350 |
+
- Building on step 2, the LLM has learned a single-question-to-answer chat template. Now, it only needs further
|
351 |
+
fine-tuning on longer chat templates with historical question-and-answer pairs.
|
352 |
+
- Use the `history_chat` field for historical dialogues and `history_chat_response` for historical responses in the
|
353 |
+
dataset.
|
354 |
+
- Construct new chat templates like [question->answer, question->answer, question->] and use this dataset for
|
355 |
+
fine-tuning.
|
356 |
+
- The trained model will not only answer the current question but also conduct coherent dialogues based on
|
357 |
+
historical interactions.
|
358 |
+
- This step is not strictly necessary, as small models have weak long-context dialogue abilities, and forcing
|
359 |
+
multi-turn Q&A templates may slightly compromise single-turn SFT performance.
|
360 |
+
> The learning rate is set dynamically between 1e-5 and 1e-6, with 2 epochs for fine-tuning.
|
361 |
+
```bash
|
362 |
+
# Set dataset to sft_data.csv in 3-full_sft.py
|
363 |
+
torchrun --nproc_per_node 2 3-full_sft.py
|
364 |
+
```
|
365 |
+
|
366 |
+
4. **Direct Preference Optimization (DPO)**:
|
367 |
+
- After the previous training steps, the model has basic conversational abilities. However, we want it to align more
|
368 |
+
closely with human preferences and provide more satisfactory responses.
|
369 |
+
- This process is similar to workplace training for the model, where it learns from examples of excellent employees
|
370 |
+
and negative examples to better serve customers.
|
371 |
+
> For the Huozi trio (q, chose, reject) dataset, the learning rate is set to 1e-5, with half-precision fp16, 1 epoch,
|
372 |
+
and it takes about 1 hour.
|
373 |
+
```bash
|
374 |
+
python 5-dpo_train.py
|
375 |
+
```
|
376 |
+
|
377 |
+
---
|
378 |
+
🔗 **Trained Model Weights**:
|
379 |
+
|
380 |
+
| Model Name | params | Config | pretrain_model | single_sft_model | multi_sft_model |
|
381 |
+
|------------------|--------|-------------------------------------------------|----------------------------------------------------------------|----------------------------------------------------------------|----------------------------------------------------------------|
|
382 |
+
| minimind-small-T | 26M | d_model=512<br/>n_layers=8 | - | [链接](https://pan.baidu.com/s/1_COe0FQRDmeapSsvArahCA?pwd=6666) | [链接](https://pan.baidu.com/s/1GsGsWSL0Dckl0YPRXiBIFQ?pwd=6666) |
|
383 |
+
| minimind-small | 56M | d_model=640<br/>n_layers=8 | [链接](https://pan.baidu.com/s/1nJuOpnu5115FDuz6Ewbeqg?pwd=6666) | [链接](https://pan.baidu.com/s/1lRX0IcpjNFSySioeCfifRQ?pwd=6666) | [链接](https://pan.baidu.com/s/1LzVxBpL0phtGUH267Undqw?pwd=6666) |
|
384 |
+
| minimind | 218M | d_model=1024<br/>n_layers=16 | [链接](https://pan.baidu.com/s/1jzA7uLEi-Jen2fW5olCmEg?pwd=6666) | [链接](https://pan.baidu.com/s/1Hvt0Q_UB_uW2sWTw6w1zRQ?pwd=6666) | [链接](https://pan.baidu.com/s/1fau9eat3lXilnrG3XNhG5Q?pwd=6666) |
|
385 |
+
| minimind-MoE | 166M | d_model=1024<br/>n_layers=8<br/>share+route=2+4 | [链接](https://pan.baidu.com/s/11CneDVTkw2Y6lNilQX5bWw?pwd=6666) | [链接](https://pan.baidu.com/s/1fRq4MHZec3z-oLK6sCzj_A?pwd=6666) | [链接](https://pan.baidu.com/s/1HC2KSM_-RHRtgv7ZDkKI9Q?pwd=6666) |
|
386 |
+
|
387 |
+
---
|
388 |
+
|
389 |
+
Regarding the parameter configuration of LLMs, an interesting paper [MobileLLM](https://arxiv.org/pdf/2402.14905) has
|
390 |
+
conducted detailed research and experiments.
|
391 |
+
|
392 |
+
The scaling laws exhibit unique patterns in small models.
|
393 |
+
|
394 |
+
The parameters that cause the scaling of Transformer models almost solely depend on `d_model` and `n_layers`.
|
395 |
+
|
396 |
+
* `d_model`↑ + `n_layers`↓ -> Short and Fat
|
397 |
+
* `d_model`↓ + `n_layers`↑ -> Tall and Thin
|
398 |
+
|
399 |
+
The paper proposing the Scaling Law in 2020 suggested that the amount of training data, the number of parameters, and
|
400 |
+
the number of training iterations are the key factors determining performance, while the impact of model architecture
|
401 |
+
can be nearly ignored. However, this law does not seem to fully apply to small models.
|
402 |
+
|
403 |
+
MobileLLM proposes that the depth of the architecture is more important than its width. A "deep and narrow" model can
|
404 |
+
learn more abstract concepts compared to a "wide and shallow" model. For example, when the model parameters are fixed at
|
405 |
+
125M or 350M, a "narrow" model with 30–42 layers performs significantly better than a "short and fat" model with around
|
406 |
+
12 layers. This trend is observed across eight benchmark tests, including common-sense reasoning, question answering,
|
407 |
+
and reading comprehension.
|
408 |
+
|
409 |
+
This is a very interesting finding, as previously, almost no one attempted to stack more than 12 layers when designing
|
410 |
+
architectures for models around the 100M parameter scale.
|
411 |
+
|
412 |
+
This observation aligns with the results of MiniMind, where experiments adjusting the model parameter quantities
|
413 |
+
between `d_model` and `n_layers` during training observed similar effects. However, there is a dimensional limit to "
|
414 |
+
deep and narrow" models. When `d_model` < 512, the drawbacks of collapsing word embedding dimensions are quite
|
415 |
+
pronounced. Increasing the number of layers cannot compensate for the deficiencies in `d_head` caused by fixed `q_head`.
|
416 |
+
|
417 |
+
When `d_model` > 1536, increasing the number of layers seems to take precedence over `d_model`, providing a more "
|
418 |
+
cost-effective" parameter-to-performance gain. Therefore, MiniMind sets the `d_model` of the small model to 640
|
419 |
+
and `n_layers` to 8 to achieve a balance of "small size -> better performance". Setting `d_model` to 1024 and `n_layers`
|
420 |
+
to 16 provides greater performance gains, aligning better with the scaling-law curve for small models.
|
421 |
+
|
422 |
+
---
|
423 |
+
|
424 |
+
# 📌 Eval
|
425 |
+
|
426 |
+
[A] [minimind-small-T(0.02B)](https://pan.baidu.com/s/1_COe0FQRDmeapSsvArahCA?pwd=6666)<br/>
|
427 |
+
[B] [minimind-small(0.05B)](https://pan.baidu.com/s/1lRX0IcpjNFSySioeCfifRQ?pwd=6666)<br/>
|
428 |
+
[C] [minimind-MoE(0.16B)](https://pan.baidu.com/s/1fRq4MHZec3z-oLK6sCzj_A?pwd=6666)<br/>
|
429 |
+
[D] [minimind(0.2B)](https://pan.baidu.com/s/1Hvt0Q_UB_uW2sWTw6w1zRQ?pwd=6666)<br/>
|
430 |
+
[E] [baby-llama2-chinese(0.2B)](https://github.com/DLLXW/baby-llama2-chinese)<br/>
|
431 |
+
[F] [chatlm-mini-chinese(0.2B)](https://github.com/charent/ChatLM-mini-Chinese)<br/>
|
432 |
+
|
433 |
+
```
|
434 |
+
[Q]: How many days are there in a week?
|
435 |
+
[A]: There are seven days in a week.
|
436 |
+
[B]: There are 7 days in a week.
|
437 |
+
[C]: According to your calculation, there are 12 hours in a week. Therefore, we need to multiply the number of hours by 12. This will give us the number of hours in 12.
|
438 |
+
[D]: There are seven days in a week.
|
439 |
+
[E]: As an AI assistant, I cannot determine the number of weeks you are referring to. If you can provide the number of weeks you are describing, I can provide information about the number of days in that week.
|
440 |
+
[F]: There are seven days in a week, which is the product of seven days, i.e., 7 x 7 = 24 days. This number is obtained by dividing 24 by 7, because a week has seven days, so a week has 24 x 7 = 24 days.
|
441 |
+
|
442 |
+
[Q]: Do you know about the Yangtze River?
|
443 |
+
[A]: Yes, the Yangtze River is the longest river in China, with a length of over 3300 kilometers.
|
444 |
+
[B]: Yes, the Yangtze River is the longest river in China, with a length of approximately 7100 kilometers. Its basin area is about 33.28 million square kilometers, making it one of the largest rivers in China and the third-longest river in the world, with a total length of about 6300 kilometers.
|
445 |
+
[C]: I know. The Yangtze River is an important water system in China, with a long history and culture. The Yangtze River is a symbol and spiritual pillar of the Chinese nation, and it is also one of the most beautiful natural landscapes in the world. People living along the Yangtze River, especially those in the Yangtze River basin, have lived there for thousands of years. The Yangtze River has deep historical and cultural significance in China, especially in its ancient culture.
|
446 |
+
[D]: The Yangtze River is the largest river in China, with a length of about 6380 kilometers. It is the longest river in Asia and the largest river in China. The Yangtze River basin is one of China’s important river basins, rich in natural resources and cultural heritage. The Yangtze River basin is a major agricultural and economic development area in China, with numerous cultural heritage sites and historical attractions, making it one of China's most important cultural tourism destinations.
|
447 |
+
[E]: Also, China is one of the longest cities in the world, with a population of over 34 million.
|
448 |
+
[F]: Yes, the Yangtze River is the longest river in China and one of the longest rivers in the world. It originates from the Tibetan Plateau, flows through nine provinces and regions, and finally empties into the East China Sea. The Yangtze River basin has a mild climate with distinct seasons, making it an important agricultural and industrial base in China. The Yangtze River basin is rich in aquatic resources and is one of China’s important fishing resources.
|
449 |
+
|
450 |
+
[Q]: Which country launched the first artificial satellite?
|
451 |
+
[A]: The first artificial satellite was Sputnik 1.
|
452 |
+
[B]: The first artificial satellite was launched by the United States.
|
453 |
+
[C]: The first artificial satellite was launched by the China National Space Administration, which is a satellite launched by the China National Space Administration.
|
454 |
+
[D]: The first artificial satellite was launched by the Soviet Union in 1957.
|
455 |
+
[E]: The satellite named "Armstrong" was launched on November 20, 1961, and was the first to successfully send humans into space.
|
456 |
+
[F]: The first artificial satellite was launched by the Soviet Union on April 4, 1957. It was launched by Soviet astronaut Yuri Gagarin and Soviet engineer Roald Skohley. During the launch, Gagarin and Skohley used a small satellite named "Sputnik 1," which had a diameter of 4.3 meters and weighed 1,051 kilograms. This satellite, called "Sputnik 1," was a milestone in the Soviet space race and marked the first time humans conducted a spacewalk in space.
|
457 |
+
|
458 |
+
[Q]: Do you know where Mount Tai is located?
|
459 |
+
[A]: Mount Tai is located in the eastern part of China and is one of the Five Great Mountains of China.
|
460 |
+
[B]: Mount Tai is located in Tai'an, Shandong Province, and is one of the Five Great Mountains of China.
|
461 |
+
[C]: Where is Mount Tai?
|
462 |
+
[D]: Mount Tai is located in Kunshan, Shandong Province, China. It is one of the treasures of ancient Chinese culture and one of the world-famous mountain scenic spots. Mount Tai is one of the Five Great Mountains, known for its steep peaks, beautiful natural scenery, and rich cultural heritage.
|
463 |
+
[E]: As an AI assistant, I do not have internet access and therefore cannot provide information about your location. However, you can search or look up related keywords to obtain information about your location, or check news or websites for information about your location.
|
464 |
+
[F]: Mount Tai is located in Tai'an, Shandong Province, China, and is one of the Five Great Mountains of China. It is also one of the important symbols of Chinese culture and history. Mount Tai is one of the Five Great Mountains, and it is one of the origins of Taoism and Buddhism in China. The elevation of Mount Tai is 1,545 meters, making it one of the most famous tourist attractions in China. Its history dates back to the 5th century BC and was a place for ancient emperors to offer sacrifices. Mount Tai is also an important part of Chinese culture, known as the "First of the Five Great Mountains," and is one of China's important cultural heritage sites.
|
465 |
+
|
466 |
+
[Q]: What is the highest mountain in the world?
|
467 |
+
[A]: The highest mountain in the world is Mount Everest, located on the border between Nepal and China, with an elevation of 8848 meters.
|
468 |
+
[B]: Mount Everest is the highest mountain in the world, located in the Himalayas, with an elevation of 8848 meters.
|
469 |
+
[C]: The highest mountain in the world is Mount Everest.
|
470 |
+
[D]: The highest mountain in the world is Mount Everest, located in the Himalayas, with an elevation of 8,848.86 meters.
|
471 |
+
[E]: The highest mountain in the world is Mount Everest, located in the Himalayas, with an elevation of 8,848.86 meters (29,031.69 feet).
|
472 |
+
[F]: The highest mountain in the world is Mount Everest, also known as Sagarmatha, located on the border between Nepal and China in the Himalayas, with an elevation of 8,848.86 meters (29,031.69 feet). It is one of the most famous climbing targets in the world, attracting climbers from around the globe. The name Everest comes from the Tibetan language and means "Goddess's forehead peak." It consists of two different peaks, one in Nepal and the other in China. Its height is determined by measuring sea level elevation, as it is calculated based on Earth's average height. Although Mount Everest is the highest mountain in the world, it is not accessible from any other place on Earth. Other places, such as the Andes Mountains in South America, are also high mountains, but they are not the highest mountains in the world. In summary, Mount Everest is the highest mountain in the world, but it is not accessible from anywhere else on Earth. It is the highest mountain range on Earth, but it is not accessible from anywhere else on Earth.
|
473 |
+
|
474 |
+
[Q]: Who proposed the law of universal gravitation?
|
475 |
+
[A]: The law of universal gravitation was proposed by British physicist Newton. He believed that all objects produce gravitational force, which is determined by the mass of the objects and their distance. This theory reveals the relationship between mass and distance and proves the nature of universal gravitation.
|
476 |
+
[B]: The law of universal gravitation was discovered by Newton and was proposed by British physicist James Watt in 1879.
|
477 |
+
[C]: Who proposed the law of universal gravitation?
|
478 |
+
[D]: The law of universal gravitation was proposed by Newton, who discovered that every object exerts a gravitational force on other objects, and the magnitude of this force depends on the mass and distance of the objects.
|
479 |
+
[E]: Gravity is a force in the universe composed of mass or energy. According to Newton's law of universal gravitation, the gravitational force between two objects is directly proportional to their mass and inversely proportional to their distance. Therefore, Newton's law of universal gravitation shows that the gravitational force between two objects is directly proportional to their mass and inversely proportional to their distance. This law has wide applications in physics, astronomy, and other fields.
|
480 |
+
[F]: The law of universal gravitation was proposed by British physicist Isaac Newton in 1687. He published a famous paper titled "Mathematical Principles of Natural Philosophy" in 1687, in which he proposed the law of universal gravitation, stating that there is a gravitational force between any two objects, which is directly proportional to their mass and inversely proportional to the square of their distance. This law, known as the law of universal gravitation, describes the relationship between mass and distance. It shows that the gravitational force between two objects is proportional to their mass and inversely proportional to the square of the distance between them. This law is crucial for explaining many phenomena in the universe, such as planetary motion around the sun, gravitational lensing between stars, etc. It is also widely used in astronomy, physics, and engineering, providing an important theoretical foundation for understanding the nature and evolution of the universe.
|
481 |
+
|
482 |
+
[Q]: Do you know what the main food of giant pandas is?
|
483 |
+
[A]: The main food of giant pandas is bamboo. They typically eat bamboo and need to consume about 30 kilograms of bamboo daily.
|
484 |
+
[B]: Giant pandas primarily eat bamboo. Their digestive system is quite specialized, and they need to digest a large amount of bamboo daily to meet their survival needs. Besides bamboo, giant pandas also survive in the wild.
|
485 |
+
[C]: The main food of giant pandas includes bamboo, mushrooms, beetroot, and mushrooms.
|
486 |
+
[D]: Giant pandas are herbivorous mammals that mainly eat bamboo, including bamboo shoots, bamboo leaves, and stems.
|
487 |
+
[E]: The main food of giant pandas is bamboo.
|
488 |
+
[F]: Giant pandas are herbivores whose main food is bamboo. Their digestive system is adapted to digest high-fiber bamboo, but they also eat some other plants, such as herbaceous plants and small mammals. The digestive system of giant pandas is adapted to high-fiber bamboo, which allows them to digest large amounts of cellulose, helping them survive in the wild. Additionally, giant pandas have an enzyme called "cellulase" in their digestive tract that helps them break down cellulose, aiding in the digestion of a lot of water and nutrients. Their digestive tract also contains a protein called "cellulase protein," which helps maintain their energy levels, supporting their survival in the wild. Overall, the main food of giant pandas is bamboo, but they also consume some other plants, such as herbaceous plants and small mammals.
|
489 |
+
|
490 |
+
[Q]: Why is seawater salty?
|
491 |
+
[A]: Seawater contains many salts, which can lead to an increase in the salinity of seawater. The salts in seawater primarily come from the salt content in seawater, and these salts can form hydrogen bonds with the seawater, increasing its salinity.
|
492 |
+
[B]: Seawater contains rich elements like calcium, phosphorus, potassium, and phosphorus, which are limited in quantity and distribution in the ocean. Additionally, seawater contains various nutrients from organisms and microorganisms, such as shells and seaweed.
|
493 |
+
[C]: The salinity of seawater is higher than that of seawater because of its high carbonate and base levels. The carbonate and base levels in seawater are higher than in seawater, making the seawater salty.
|
494 |
+
[D]: Seawater contains dissolved salts and other minerals, which come from the erosion and adsorption of the Earth's crust, and these substances dissolve in the water, causing the seawater to taste salty.
|
495 |
+
[E]: Water is essential for many living organisms as it can absorb and release carbon dioxide, release oxygen, maintain atmospheric water vapor, and regulate the climate and environment. The salts and chemicals in water release oxygen, which allows organisms on Earth to breathe. Additionally, water plays many other roles, such as maintaining the water cycle, regulating the climate, and supporting the environment. Water is essential for many living organisms and is also a fundamental aspect of many natural phenomena.
|
496 |
+
[F]: Seawater is salty primarily because it contains a large amount of dissolved salts, with sodium chloride (NaCl) being the most prominent. Sodium chloride is a common type of salt found in many places on Earth, including oceans, lakes, rivers, and groundwater. When water evaporates from the ocean, it carries away some of the salts, making the seawater salty. Additionally, seawater contains other dissolved salts, such as sulfate, magnesium sulfate, calcium sulfate, and potassium sulfate.
|
497 |
+
```
|
498 |
+
|
499 |
+
🙋♂️Directly throw the answer of the above model to GPT-4o and ask it to help score it:
|
500 |
+
|
501 |
+
---
|
502 |
+
|
503 |
+
According to your request, I will evaluate the performance of each model based on accuracy, clarity, and completeness,
|
504 |
+
and provide ratings and rankings.
|
505 |
+
|
506 |
+
### Model Performance Ratings and Summary
|
507 |
+
|
508 |
+
**Model A**
|
509 |
+
|
510 |
+
- **Accuracy**: Most answers are accurate, but there are occasional minor errors.
|
511 |
+
- **Clarity**: Responses are concise and fluent.
|
512 |
+
- **Completeness**: Responses are sometimes slightly simplistic, but overall the information is sufficient.
|
513 |
+
- **Score**: 80
|
514 |
+
|
515 |
+
**Model B**
|
516 |
+
|
517 |
+
- **Accuracy**: Most answers are accurate, but there are some minor errors (e.g., regarding the first artificial
|
518 |
+
satellite).
|
519 |
+
- **Clarity**: Language is relatively clear, but sometimes expressions are slightly confusing.
|
520 |
+
- **Completeness**: Responses are fairly comprehensive but contain information discrepancies.
|
521 |
+
- **Score**: 75
|
522 |
+
|
523 |
+
**Model C**
|
524 |
+
|
525 |
+
- **Accuracy**: Responses are inaccurate, with several instances of self-asking and answering.
|
526 |
+
- **Clarity**: Language is fluent, but the logic of responses is poor.
|
527 |
+
- **Completeness**: Information is incomplete and sometimes lacks important details.
|
528 |
+
- **Score**: 55
|
529 |
+
|
530 |
+
**Model D**
|
531 |
+
|
532 |
+
- **Accuracy**: Most answers are accurate and generally correct.
|
533 |
+
- **Clarity**: Expression is clear, with appropriate information density.
|
534 |
+
- **Completeness**: Responses are relatively complete, but some answers might include unnecessary details.
|
535 |
+
- **Score**: 85
|
536 |
+
|
537 |
+
**Model E**
|
538 |
+
|
539 |
+
- **Accuracy**: Accuracy is lower, with some answers unrelated to the questions.
|
540 |
+
- **Clarity**: Expression is unclear and can cause confusion.
|
541 |
+
- **Completeness**: Information is incomplete and sometimes deviates from the topic.
|
542 |
+
- **Score**: 50
|
543 |
+
|
544 |
+
**Model F**
|
545 |
+
|
546 |
+
- **Accuracy**: Some answers are inaccurate, with notable errors (e.g., "24 days").
|
547 |
+
- **Clarity**: Expression is lengthy and can cause confusion.
|
548 |
+
- **Completeness**: Information is excessively lengthy and repetitive, reducing readability.
|
549 |
+
- **Score**: 60
|
550 |
+
|
551 |
+
### Ranking (from highest to lowest):
|
552 |
+
|
553 |
+
1. **Model D** - 85
|
554 |
+
2. **Model A** - 80
|
555 |
+
3. **Model B** - 75
|
556 |
+
4. **Model F** - 60
|
557 |
+
5. **Model C** - 55
|
558 |
+
6. **Model E** - 50
|
559 |
+
|
560 |
+
These scores and rankings are based on each model’s overall performance in accuracy, clarity, and completeness.
|
561 |
+
|
562 |
+
---
|
563 |
+
|
564 |
+
### 👉 Summary of Results
|
565 |
+
|
566 |
+
* The ranking of the minimind series (ABCD) is intuitive. minimind(0.2B) scores the highest, with minimal errors and
|
567 |
+
hallucinations in answering common-sense questions.
|
568 |
+
* Surprisingly, minimind-small-T (0.02B) with only 26M parameters performs close to minimind(0.2B).
|
569 |
+
* minimind(0.2B) had less than 2 epochs of SFT training. Despite the training time being several times that of
|
570 |
+
0.02B, the model was terminated early to free up resources for smaller models. Even with insufficient training,
|
571 |
+
0.2B achieved the best performance, highlighting the impact of model size.
|
572 |
+
* minimind-MoE (0.16B) performed poorly, even worse than its dense counterpart minimind(0.05B). This isn't due to
|
573 |
+
the MoE approach itself but rather because the model was terminated early due to resource constraints. MoE models
|
574 |
+
typically require more training epochs, and with only 2 epochs, the training was extremely insufficient. A
|
575 |
+
well-trained MoE version was previously tested on Yi tokenizer and showed visibly better performance compared to
|
576 |
+
dense models. Further training for updates to v2 and v3 versions will be conducted when server resources are
|
577 |
+
available.
|
578 |
+
|
579 |
+
* Model F's responses appear the most complete, despite some hallucinations. Both GPT-4o and Kimi's evaluations agree
|
580 |
+
that it is "overly verbose with repetitive content and contains hallucinations." This evaluation may seem too
|
581 |
+
harsh—hallucinations accounting for 10 out of 100 words can unfairly lead to a 0 score. Model F, having a default
|
582 |
+
longer training text and a much larger dataset, provides seemingly more complete answers, with data proving more
|
583 |
+
crucial than model size in similar contexts.
|
584 |
+
|
585 |
+
> 🙋♂️ Personal subjective rating: F > D > A ≈ B > C > E
|
586 |
+
|
587 |
+
> 🤖 GPT-4o rating: D > A > B > F > C > E
|
588 |
+
|
589 |
+
In summary, the scaling law suggests that larger model parameters and more training data generally lead to stronger
|
590 |
+
model performance.
|
591 |
+
|
592 |
+
# 📌 Objective Dataset: C-Eval
|
593 |
+
|
594 |
+
C-Eval evaluation code is located at: `./eval_ceval.py`.
|
595 |
+
|
596 |
+
For small models, to avoid issues with fixed response formatting, we directly judge the prediction probabilities of the
|
597 |
+
four tokens `A`, `B`, `C`, `D`, and choose the one with the highest probability as the answer, then calculate accuracy
|
598 |
+
against the standard answer. Note that minimind models were not trained on larger datasets or fine-tuned for question
|
599 |
+
answering, so results should be considered as reference only.
|
600 |
+
|
601 |
+
* For example, detailed results for minimind-small:
|
602 |
+
|
603 |
+
| category | Correct/Total | Accuracy |
|
604 |
+
|----------------------------------------------|---------------|----------|
|
605 |
+
| probability_and_statistics_val | 3/18 | 16.67% |
|
606 |
+
| law_val | 5/24 | 20.83% |
|
607 |
+
| middle_school_biology_val | 4/21 | 19.05% |
|
608 |
+
| high_school_chemistry_val | 7/19 | 36.84% |
|
609 |
+
| high_school_physics_val | 5/19 | 26.32% |
|
610 |
+
| legal_professional_val | 2/23 | 8.70% |
|
611 |
+
| high_school_chinese_val | 4/19 | 21.05% |
|
612 |
+
| high_school_history_val | 6/20 | 30.00% |
|
613 |
+
| tax_accountant_val | 10/49 | 20.41% |
|
614 |
+
| modern_chinese_history_val | 4/23 | 17.39% |
|
615 |
+
| middle_school_physics_val | 4/19 | 21.05% |
|
616 |
+
| middle_school_history_val | 4/22 | 18.18% |
|
617 |
+
| basic_medicine_val | 1/19 | 5.26% |
|
618 |
+
| operating_system_val | 3/19 | 15.79% |
|
619 |
+
| logic_val | 4/22 | 18.18% |
|
620 |
+
| electrical_engineer_val | 7/37 | 18.92% |
|
621 |
+
| civil_servant_val | 11/47 | 23.40% |
|
622 |
+
| chinese_language_and_literature_val | 5/23 | 21.74% |
|
623 |
+
| college_programming_val | 10/37 | 27.03% |
|
624 |
+
| accountant_val | 9/49 | 18.37% |
|
625 |
+
| plant_protection_val | 7/22 | 31.82% |
|
626 |
+
| middle_school_chemistry_val | 4/20 | 20.00% |
|
627 |
+
| metrology_engineer_val | 3/24 | 12.50% |
|
628 |
+
| veterinary_medicine_val | 6/23 | 26.09% |
|
629 |
+
| marxism_val | 5/19 | 26.32% |
|
630 |
+
| advanced_mathematics_val | 5/19 | 26.32% |
|
631 |
+
| high_school_mathematics_val | 4/18 | 22.22% |
|
632 |
+
| business_administration_val | 8/33 | 24.24% |
|
633 |
+
| mao_zedong_thought_val | 8/24 | 33.33% |
|
634 |
+
| ideological_and_moral_cultivation_val | 5/19 | 26.32% |
|
635 |
+
| college_economics_val | 17/55 | 30.91% |
|
636 |
+
| professional_tour_guide_val | 10/29 | 34.48% |
|
637 |
+
| environmental_impact_assessment_engineer_val | 7/31 | 22.58% |
|
638 |
+
| computer_architecture_val | 6/21 | 28.57% |
|
639 |
+
| urban_and_rural_planner_val | 11/46 | 23.91% |
|
640 |
+
| college_physics_val | 5/19 | 26.32% |
|
641 |
+
| middle_school_mathematics_val | 3/19 | 15.79% |
|
642 |
+
| high_school_politics_val | 4/19 | 21.05% |
|
643 |
+
| physician_val | 13/49 | 26.53% |
|
644 |
+
| college_chemistry_val | 3/24 | 12.50% |
|
645 |
+
| high_school_biology_val | 5/19 | 26.32% |
|
646 |
+
| high_school_geography_val | 4/19 | 21.05% |
|
647 |
+
| middle_school_politics_val | 6/21 | 28.57% |
|
648 |
+
| clinical_medicine_val | 6/22 | 27.27% |
|
649 |
+
| computer_network_val | 2/19 | 10.53% |
|
650 |
+
| sports_science_val | 2/19 | 10.53% |
|
651 |
+
| art_studies_val | 14/33 | 42.42% |
|
652 |
+
| teacher_qualification_val | 12/44 | 27.27% |
|
653 |
+
| discrete_mathematics_val | 6/16 | 37.50% |
|
654 |
+
| education_science_val | 7/29 | 24.14% |
|
655 |
+
| fire_engineer_val | 9/31 | 29.03% |
|
656 |
+
| middle_school_geography_val | 1/12 | 8.33% |
|
657 |
+
|
658 |
+
**Total number of questions**: 1346
|
659 |
+
|
660 |
+
**Total confirmed number**: 316
|
661 |
+
|
662 |
+
**Total accuracy rate**: 23.48%
|
663 |
+
|
664 |
+
---
|
665 |
+
|
666 |
+
#### Results summary:
|
667 |
+
|
668 |
+
| category | correct | question_count | accuracy |
|
669 |
+
|:-----------------|:--------:|:--------------:|:---------:|
|
670 |
+
| minimind-small-T | 344 | 1346 | 25.56% |
|
671 |
+
| minimind-small | 312 | 1346 | 23.18% |
|
672 |
+
| minimind | 351 | 1346 | 26.08% |
|
673 |
+
| minimind-moe | 316 | 1346 | 23.48% |
|
674 |
+
|
675 |
+
### Model Performance Insights from GPT-4o
|
676 |
+
|
677 |
+
```text
|
678 |
+
### Areas Where the Model Excels:
|
679 |
+
1. **High School Chemistry**: With an accuracy of 42.11%, this is the strongest area for the model, suggesting a solid grasp of chemistry-related knowledge.
|
680 |
+
2. **Discrete Mathematics**: Achieving an accuracy of 37.50%, the model performs well in mathematics-related fields.
|
681 |
+
3. **Education Science**: The model shows good performance in education-related topics with a 37.93% accuracy.
|
682 |
+
4. **Basic Medicine**: The accuracy of 36.84% indicates strong performance in foundational medical knowledge.
|
683 |
+
5. **Operating Systems**: With a 36.84% accuracy, the model demonstrates reliable performance in computer operating systems.
|
684 |
+
|
685 |
+
### Areas Where the Model Struggles:
|
686 |
+
1. **Legal Topics**: The model performs poorly in legal-related areas such as Legal Professional (8.70%) and Tax Accountant (20.41%).
|
687 |
+
2. **Physics**: Both high school (26.32%) and college-level (21.05%) physics topics are challenging for the model.
|
688 |
+
3. **High School Politics and Geography**: The model shows low accuracy in these areas, with High School Politics at 15.79% and High School Geography at 21.05%.
|
689 |
+
4. **Computer Networking and Architecture**: The model struggles with Computer Networking (21.05%) and Computer Architecture (9.52%).
|
690 |
+
5. **Environmental Impact Assessment Engineering**: The accuracy is only 12.90%, indicating weak performance in environmental science.
|
691 |
+
|
692 |
+
### Summary:
|
693 |
+
- **Strengths**: Chemistry, Mathematics (especially Discrete Mathematics), Education Science, Basic Medicine, and Operating Systems.
|
694 |
+
- **Weaknesses**: Legal Topics, Physics, Politics, Geography, Computer Networking and Architecture, and Environmental Science.
|
695 |
+
|
696 |
+
This suggests that the model performs well in logical reasoning, foundational sciences, and some engineering disciplines but is weaker in humanities, social sciences, and certain specialized fields (such as law and taxation). To improve the model's performance, additional training in humanities, physics, law, and environmental science may be beneficial.
|
697 |
+
```
|
698 |
+
|
699 |
+
|
700 |
+
# 📌 Others
|
701 |
+
|
702 |
+
### Inference and Export
|
703 |
+
|
704 |
+
* [./export_model.py](./export_model.py) can export the model to the transformers format and push it to Hugging Face.
|
705 |
+
|
706 |
+
* MiniMind's Hugging Face collection address: [MiniMind](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5)
|
707 |
+
|
708 |
+
---
|
709 |
+
|
710 |
+
### API Inference
|
711 |
+
|
712 |
+
[./my_openai_api.py](./my_openai_api.py) provides a chat interface for the OpenAI API, making it easier to integrate your model with third-party UIs, such as fastgpt, OpenWebUI, etc.
|
713 |
+
|
714 |
+
* Download the model weight files from [Hugging Face](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5):
|
715 |
+
```
|
716 |
+
minimind (root dir)
|
717 |
+
├─minimind
|
718 |
+
| ├── config.json
|
719 |
+
| ├── generation_config.json
|
720 |
+
| ├── LMConfig.py
|
721 |
+
| ├── model.py
|
722 |
+
| ├── pytorch_model.bin
|
723 |
+
| ├── special_tokens_map.json
|
724 |
+
| ├── tokenizer_config.json
|
725 |
+
| ├── tokenizer.json
|
726 |
+
```
|
727 |
+
|
728 |
+
* Start the chat server:
|
729 |
+
```bash
|
730 |
+
python my_openai_api.py
|
731 |
+
```
|
732 |
+
* Test the service interface:
|
733 |
+
```bash
|
734 |
+
python chat_openai_api.py
|
735 |
+
```
|
736 |
+
* API interface example, compatible with the OpenAI API format:
|
737 |
+
```bash
|
738 |
+
curl http://ip:port/v1/chat/completions \
|
739 |
+
-H "Content-Type: application/json" \
|
740 |
+
-d '{
|
741 |
+
"model": "model-identifier",
|
742 |
+
"messages": [
|
743 |
+
{ "role": "user", "content": "What is the highest mountain in the world?" }
|
744 |
+
],
|
745 |
+
"temperature": 0.7,
|
746 |
+
"max_tokens": -1,
|
747 |
+
"stream": true
|
748 |
+
}'
|
749 |
+
```
|
750 |
+
|
751 |
+
![images](./images/logger.png)
|
752 |
+
|
753 |
+
### Integrating MiniMind API in FastGPT
|
754 |
+
|
755 |
+
![images](./images/fastgpt.png)
|
756 |
+
|
757 |
+
|
758 |
+
---
|
759 |
+
|
760 |
+
# 📌 Acknowledge
|
761 |
+
|
762 |
+
If you find this project helpful, feel free to give it a Star 🎉✨.
|
763 |
+
|
764 |
+
The document is somewhat lengthy and may contain errors due to my limited proficiency. Please feel free to open issues for discussion or criticism.
|
765 |
+
|
766 |
+
Special thanks to the following open-source projects for their inspiration and datasets:
|
767 |
+
|
768 |
+
* [baby-llama2-chinese](https://github.com/DLLXW/baby-llama2-chinese)
|
769 |
+
* [ChatLM-mini-Chinese](https://github.com/charent/ChatLM-mini-Chinese)
|
770 |
+
* [Zero-Chatgpt](https://github.com/AI-Study-Han/Zero-Chatgpt/tree/main)
|
771 |
+
|
772 |
+
# 📌 Statement
|
773 |
+
|
774 |
+
This project does not assume responsibility for data security, public opinion risks, or any risks and liabilities arising from model misguidance, misuse, dissemination, or improper use related to open-source models and code.
|
images/2-eval.png
ADDED
images/LLM-structure-moe.png
ADDED
images/LLM-structure.png
ADDED
images/fastgpt.png
ADDED
images/gpt3_config.png
ADDED
images/logger.png
ADDED
images/logo.png
ADDED