README.md 3.19 KB
Newer Older
mashun1's avatar
mashun1 committed
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
# DeepSeek-R1

## 论文

`DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning`

* https://github.com/deepseek-ai/DeepSeek-R1/blob/main/DeepSeek_R1.pdf


## 模型结构

该模型基于Transformer,采用Multi-Head Latent Attention和DeepSeekMoE架构,其中MLA通过减少KV缓存降低内存占用可用于高效推理,DeepSeekMoE通过auxiliary loss平衡专家负载。

![alt text](readme_imgs/arch.png)

## 算法原理

DeepSeek-R1的模型结构通过MLA、DeepSeekMoE、辅助损失无关的负载均衡策略、多令牌预测和FP8混合精度训练等创新技术,显著提升了模型的性能和训练效率,使用强化学习训练模型,增强模型的思考能力,这些设计使得DeepSeek-R1在保持高性能的同时,大幅降低了训练成本。


## 环境配置

### Docker(方法一)
    
    docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.3.0-ubuntu22.04-dtk24.04.3-py3.10

    docker run --shm-size 500g --network=host --name=dpskr1 --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash

    cd inference
    pip install -r requirements.txt

### Dockerfile(方法二)

    docker build -t <IMAGE_NAME>:<TAG> .

    docker run --shm-size 500g --network=host --name=dpskr1 --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash

    cd inference
    pip install -r requirements.txt


## 数据集



## 训练



## 推理

注意:运行该模型需要4x8x64(GB)显存。

### 模型转换

```bash
# fp8 -> bf16
cd inference
python fp8_cast_bf16.py --input-fp8-hf-path /path/to/fp8_weights --output-bf16-hf-path /path/to/bf16_weights
```

```bash
# 模型划分
python convert.py --hf-ckpt-path /path/to/DeepSeek-R1-bf16 --save-path /path/to/DeepSeek-R1-Demo --n-experts 256 --model-parallel 32
```

### run

```bash
# chat
torchrun --nnodes 4 --nproc-per-node 8 --node-rank $RANK --master-addr $ADDR generate.py --ckpt-path /path/to/DeepSeek-R1-Demo --config configs/config_671B.json --interactive --temperature 0.7 --max-new-tokens 200
```

```bash
# 直接推理
torchrun --nnodes 4 --nproc-per-node 8 --node-rank $RANK --master-addr $ADDR generate.py --ckpt-path /path/to/DeepSeek-R1-Demo --config configs/config_671B.json --input-file $FILE
```

注意:需要将/path/to/fp8_weights中的json文件复制到/path/to/DeepSeek-V3-Demo中。
shantf's avatar
shantf committed
80
81
82
在K100_AI和ECO显卡上需要添加环境变量
export NCCL_ALGO=Ring
export NCCL_PROTO=Simple
mashun1's avatar
mashun1 committed
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

## result

![alt text](readme_imgs/result.png)

### 精度



## 应用场景

### 算法类别

`对话问答`

### 热点应用行业

`电商,教育,广媒`

## 预训练权重

[huggingface](https://hf-mirror.com/deepseek-ai/DeepSeek-R1) | [SCNet高速下载通道](http://113.200.138.88:18080/aimodels/deepseek-ai/DeepSeek-R1)


## 源码仓库及问题反馈

mashun1's avatar
mashun1 committed
109
* https://developer.sourcefind.cn/codes/modelzoo/deepseek-r1_pytorch
mashun1's avatar
mashun1 committed
110
111
112
113

## 参考资料

* https://github.com/deepseek-ai/DeepSeek-R1