README.md 4.55 KB
Newer Older
dcuai's avatar
dcuai committed
1
# InternLM2-Math-7B
2
3
4
5
6
7

## 论文

`InternLM-Math: Open Math Large Language Models Toward Verifiable Reasoning`

- [https://arxiv.org/abs/2402.06332]
zhougaofeng's avatar
zhougaofeng committed
8
9
10
11
12
13
14
15

## 模型结构
Internlm2_math在Internlm2模型上继续用约100B的高质量数学相关令牌进行预训练,并用约200万的双语数学监督数据进行SFT。Internlm2采用LLama+GQA结构,将Internlm中Wqkv矩阵堆叠排放,改进为交错重排,大概能提高5%的训练效率。
<div align=center>
    <img src="doc/struct.png"/>
</div>


16
17
## 算法原理

zhougaofeng's avatar
zhougaofeng committed
18
19
20
21
InternLM-Math是基于InternLM2-Base模型进行数学预训练得到的大型语言模型。融合了链式推理、奖励建模、数据增强和形式推理等多种能力,不仅可以解决数学问题,还可以验证推理过程的正确性。竞赛级别的MATH基准测试的准确率优于更大参数量的qwen-72B、Llemma-34B等模型
<div align=center>
    <img src="./doc/model_accuracy.png"/>
</div>
22
23
24
25
26
27
28
29
30


## 环境配置

### Docker(方法一)

此处提供[光源](https://www.sourcefind.cn/#/service-details)拉取 docker 镜像的地址与使用步骤

```
zhougaofeng's avatar
zhougaofeng committed
31
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-centos7.6-dtk24.04-py310
zhougaofeng's avatar
zhougaofeng committed
32
docker run -it --shm-size=1024G -v <Host Path>:<Container Path> -v /opt/hyhal:/opt/hyhal --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name internlm-math  <your IMAGE ID> bash  # <your IMAGE ID>为以上拉取的docker的镜像ID替换,本镜像为:c85ed27005f2
33
cd /home/internlm-math-pytorch
zhougaofeng's avatar
zhougaofeng committed
34
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
zhougaofeng's avatar
zhougaofeng committed
35
pip uninstall vllm
zhougaofeng's avatar
zhougaofeng committed
36
# bitsandbytes可从whl.zip文件里获取安装:
37
38
39
40
41
42
43
44
45
46
pip install bitsandbytes-0.42.0-py3-none-any.whl

```

### Dockerfile(方法二)

此处提供 dockerfile 的使用方法

```
docker build  -t internlm-math-df:latest .
zhougaofeng's avatar
zhougaofeng committed
47
docker run -it --shm-size=1024G -v <Host Path>:<Container Path> -v /opt/hyhal:/opt/hyhal --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name internlm-math  internlm-math-df:latest  bash
zhougaofeng's avatar
zhougaofeng committed
48
49
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
# bitsandbytes可从whl.zip文件里获取安装:
50
pip install bitsandbytes-0.42.0-py3-none-any.whl
zhougaofeng's avatar
zhougaofeng committed
51
pip uninstall vllm
52
53
54
55
56
57
```

### Anaconda(方法三)

此处提供本地配置、编译的详细步骤,例如:

chenzk's avatar
chenzk committed
58
关于本项目 DCU 显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装。
59
60

```
61
DTK驱动:dtk24.04
62
63
64
65
66
67
68
69
70
71
72
73
74
75
python:python3.10
torch: 2.1.0
torchvision: 0.16.0
deepspeed:0.12.3
bitsandbytes: 0.42.0
triton:2.1.0
```

`Tips:以上dtk驱动、python、paddle等DCU相关工具版本需要严格一一对应`

其它非深度学习库参照 requirements.txt 安装:

```
pip install -r requirements.txt
zhougaofeng's avatar
zhougaofeng committed
76
pip uninstall vllm
77
78
79
```

## 数据集
zhougaofeng's avatar
zhougaofeng committed
80
使用[alpaca_en.json](https://hf-mirror.com/datasets/llamafactory/alpaca_en)数据集,已经包含在finetune/data目录中,具体文件为alpaca_en_demo.json
81
82
83
84
85
86
87
88
89
90
项目中已提供用于试验训练的迷你数据集,训练数据目录结构如下,用于正常训练的完整数据集请按此目录结构进行制备:

```
 ── data
    ├── alpaca_en_demo.json.json
    └── alpaca_zh_demo.json.json
```

## 训练

zhougaofeng's avatar
zhougaofeng committed
91
根据实际路径修改模型路径和数据集路径
92
93
94
95

### 单机单卡

```
96
cd finetune
zhougaofeng's avatar
zhougaofeng committed
97
sh single_node.sh
98
99
100
101
```
### 单机多卡

```
zhougaofeng's avatar
zhougaofeng committed
102
cd finetune
103
104
105
106
107
108
109
sh multi_node.sh
```


## 推理

```
zhougaofeng's avatar
zhougaofeng committed
110
cd inference
zhougaofeng's avatar
zhougaofeng committed
111
python single_dcu.py
112
113
114
115
116
117
118
```

## result

使用的加速卡:2张 DCU-K100-64G

<div align=center>
zhougaofeng's avatar
zhougaofeng committed
119
    <img src="./doc/inf_result.png"/>
120
121
122
123
124
125
126
127
128
129
130
</div>

### 精度
测试数据:[alpaca_en_demo.json],使用的加速卡:K100-64G,2卡训练。

根据测试结果情况填写表格:
| device | train_loss | 
| :------: | :------: | 
| DCU-K100 | 1.0941 | 
| GPU-A800 | 1.0944 | 

zhougaofeng's avatar
zhougaofeng committed
131
使用[opencompass](https://github.com/open-compass/opencompass)得到的测试结果对比
132
133
134
<div align=center>
    <img src="./doc/result.png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
135

zhougaofeng's avatar
zhougaofeng committed
136
## 应用场景
137
138
139

### 算法类别

zhougaofeng's avatar
zhougaofeng committed
140
文本生成
141
142
143

### 热点应用行业

zhougaofeng's avatar
zhougaofeng committed
144
`科研,教育,金融,数学`
145

zhougaofeng's avatar
zhougaofeng committed
146
### 预训练权重
zhougaofeng's avatar
zhougaofeng committed
147
预训练权重下载中心: [huggingface](https://huggingface.co/internlm/internlm2-math-7b)
zhougaofeng's avatar
zhougaofeng committed
148
149
150
151
模型目录结构如下:
<div align=center>
    <img src="./doc/model.png"/>
</div>
152
153
154

## 源码仓库及问题反馈

chenzk's avatar
chenzk committed
155
- https://developer.sourcefind.cn/codes/modelzoo/internlm2_math_7b_pytorch
156
157
158
159
160
161
162

## 参考资料

- https://github.com/hiyouga/LLaMA-Factory/tree/main
- https://github.com/InternLM/InternLM-Math
- https://hf-mirror.com/internlm/internlm2-math-7b