README.md 4.34 KB
Newer Older
zhougaofeng's avatar
zhougaofeng committed
1
# DeepSeekMath
zhougaofeng's avatar
zhougaofeng committed
2
3
4
5
6
7
8

## 论文

`DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models`

- [https://arxiv.org/pdf/2402.03300]

zhougaofeng's avatar
zhougaofeng committed
9
10
## 模型结构

zhougaofeng's avatar
zhougaofeng committed
11
DeepSeekMath在DeepSeek-Coder-Base-v1.5-7B的基础上进行预训练,使用了来自Common Crawl的120B与数学相关的token,以及自然语言和代码数据。DeepSeekMath 7B在没有依赖外部工具包和投票技术的情况下,在竞争级别的MATH基准上取得了令人印象深刻的51.7%的分数,接近Gemini-Ultra和GPT-4的性能水平。
zhougaofeng's avatar
zhougaofeng committed
12
13
14
15
<div align=center>
    <img src="./doc/model_accuracy.png"/>
</div>

zhougaofeng's avatar
zhougaofeng committed
16
17
## 算法原理

zhougaofeng's avatar
zhougaofeng committed
18
首先,DeepSeekMath通过精心设计的 数据选择管道,充分利用了公开可用的网络数据的巨大潜力。其次,引入了群组相对策略优化(GRPO),GRPO放弃了价值模型,而是从组分数估计基线,它在增强数学推理能力的同时,还优化了PPO的内存使用。
zhougaofeng's avatar
zhougaofeng committed
19

zhougaofeng's avatar
zhougaofeng committed
20
21
22
<div align=center>
    <img src="./doc/model_grpo.png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
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 deepseek-math  <your IMAGE ID> bash  # <your IMAGE ID>为以上拉取的docker的镜像ID替换,本镜像为:c85ed27005f2
zhougaofeng's avatar
zhougaofeng committed
33
cd /home/deepseek-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
# bitsandbytes可从whl.zip文件里获取安装:
zhougaofeng's avatar
zhougaofeng committed
36
37
pip install bitsandbytes-0.42.0-py3-none-any.whl

zhougaofeng's avatar
zhougaofeng committed
38
39
pip uninstall vllm

zhougaofeng's avatar
zhougaofeng committed
40
41
42
43
44
45
46
47
```

### Dockerfile(方法二)

此处提供 dockerfile 的使用方法

```
docker build  -t deepseek-math-df:latest .
zhougaofeng's avatar
zhougaofeng committed
48
49
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 deepseek-math  deepseek-math-df  bash
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
zhougaofeng's avatar
zhougaofeng committed
50
# bitsandbytes可从whl.zip文件里获取安装:
zhougaofeng's avatar
zhougaofeng committed
51
52
pip install bitsandbytes-0.42.0-py3-none-any.whl

zhougaofeng's avatar
zhougaofeng committed
53
pip uninstall vllm
zhougaofeng's avatar
zhougaofeng committed
54
55
56
57
58
59
60
61
62
```

### Anaconda(方法三)

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

关于本项目 DCU 显卡所需的特殊深度学习库可从[光合](https://developer.hpccube.com/tool/)开发者社区下载安装。

```
zhougaofeng's avatar
zhougaofeng committed
63
DTK驱动:dtk24.04
zhougaofeng's avatar
zhougaofeng committed
64
65
66
67
68
69
70
71
72
73
74
75
76
python:python3.10
torch: 2.1.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
77
pip uninstall vllm
zhougaofeng's avatar
zhougaofeng committed
78
79
80
```

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

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

## 训练

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

### 单机单卡

```
cd fintune
zhougaofeng's avatar
zhougaofeng committed
98
sh single_node.sh
zhougaofeng's avatar
zhougaofeng committed
99
100
101
102
103
104
105
106
107
108
```
### 单机多卡

```
sh multi_node.sh
```

## 推理

```
zhougaofeng's avatar
zhougaofeng committed
109
110
cd inference
sh 7B_single_node.sh
zhougaofeng's avatar
zhougaofeng committed
111
112
113
114
115
116
117
```

## result

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

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

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

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

zhougaofeng's avatar
zhougaofeng committed
130

zhougaofeng's avatar
zhougaofeng committed
131
132
133
134
135
136
137
138
139

### 算法类别

数学推理

### 热点应用行业

`科研,教育,金融`

zhougaofeng's avatar
zhougaofeng committed
140
141
142
143
144
145
### 预训练权重
预训练权重下载中心: huggingface[https://huggingface.co/deepseek-ai/deepseek-math-7b-base]
模型目录结构如下:
<div align=center>
    <img src="./doc/model.png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
146
147
148

## 源码仓库及问题反馈

zhougaofeng's avatar
zhougaofeng committed
149
- https://developer.hpccube.com/codes/modelzoo/deepseek_math_7b_pytorch
zhougaofeng's avatar
zhougaofeng committed
150
151
152
153
154
155

## 参考资料

- https://github.com/hiyouga/LLaMA-Factory/tree/main
- https://github.com/deepseek-ai/DeepSeek-Math
- https://hf-mirror.com/deepseek-ai/deepseek-math-7b-base
zhougaofeng's avatar
zhougaofeng committed
156