README.md 3.75 KB
Newer Older
luopl's avatar
luopl committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
## DeepSeek-V4
## 论文
[DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence](https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro/blob/main/DeepSeek_V4.pdf)

## 模型简介
DeepSeek-V4 系列的预览版本,包含两款强大的混合专家(Mixture-of-Experts, MoE)语言模型:DeepSeek-V4-Pro(总参数量 1.6T,激活参数量 49B)和 DeepSeek-V4-Flash(总参数量 284B,激活参数量 13B),两者均支持 百万 token 的上下文长度。

DeepSeek-V4 系列在架构与优化方面引入了多项关键升级:

- 混合注意力架构:设计了一种混合注意力机制,结合压缩稀疏注意力(Compressed Sparse Attention, CSA)与重度压缩注意力(Heavily Compressed Attention, HCA),显著提升长上下文处理效率。在百万 token 上下文场景下,DeepSeek-V4-Pro 相比 DeepSeek-V3.2 仅需 27% 的单 token 推理 FLOPs 和 10% 的 KV 缓存。
- 流形约束超连接(Manifold-Constrained Hyper-Connections, mHC):在传统残差连接基础上引入 mHC,增强跨层信号传播的稳定性,同时保留模型的表达能力。
- Muon 优化器:采用 Muon 优化器,以实现更快的收敛速度和更高的训练稳定性。

## 环境依赖
| 软件 |   版本    |
| :------: |:-------:|
|     DTK      |  26.04  |
chenych's avatar
chenych committed
18
19
20
|    Python    | 3.10.12 |
|    Torch     |  2.9.0+das.opt1.dtk2604.20260331.g4e3c1e7  |
|   Tilelang   |  0.1.7.post3+cpu.git52700923  |
luopl's avatar
luopl committed
21

chenych's avatar
chenych committed
22
当前仅支持镜像: harbor.sourcefind.cn:5443/dcu/admin/base/custom:torch-2.9.0-ubuntu22.04-dtk26.04-deepseek-v4-0425
luopl's avatar
luopl committed
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

- 挂载地址`-v`根据实际模型情况修改

```bash
docker run -it \
    --shm-size 200g \
    --network=host \
    --name deepseek-v4 \
    --privileged \
    --device=/dev/kfd \
    --device=/dev/dri \
    --device=/dev/mkfd \
    --group-add video \
    --cap-add=SYS_PTRACE \
    --security-opt seccomp=unconfined \
    -u root \
    -v /opt/hyhal/:/opt/hyhal/:ro \
    -v /path/your_code_data/:/path/your_code_data/ \
    harbor.sourcefind.cn:5443/dcu/admin/base/custom:torch-2.9.0-ubuntu22.04-dtk26.04-deepseek-v4-0425 bash
```

更多镜像可前往[光源](https://sourcefind.cn/#/service-list)下载使用。

## 数据集
`暂无`

## 训练
`暂无`

## 推理
luopl's avatar
luopl committed
53
### Pytorch
luopl's avatar
luopl committed
54
#### 单机推理
chenych's avatar
chenych committed
55
##### BF16
luopl's avatar
luopl committed
56
57
58
1. 模型转换与切分
```bash
#注意将脚本中对应的路径及参数设置成用户实际值
chenych's avatar
chenych committed
59
#其中:INPUT_FP8_HF_PATH为原始模型路径;OUTPUT_BF16_HF_PATH为bf16模型存放路径;SAVE_PATH为切分好的模型路径;mp根据实际卡数调整
luopl's avatar
luopl committed
60
61
62
63
64
65
66
cd convert_weight
bash convert_weight.sh
```

2. 启动对话推理
```bash
#注意将脚本中对应的路径及参数设置成用户实际值
chenych's avatar
chenych committed
67
cd ../inference-bf16
luopl's avatar
luopl committed
68
69
70
sh start_torch.sh
```

chenych's avatar
chenych committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
##### FP8
1. 模型转换与切分
```bash
#注意将脚本中对应的路径及参数设置成用户实际值
#其中:--hf-ckpt-path为原始模型路径;--save-path为切分好的FP8模型的存放路径;MP根据实际卡数调整(默认为8)
cd inference-fp8
bash cast_fp4_to_fp8.sh
```

2. 启动对话推理
```bash
#注意将脚本中对应的路径及参数设置成用户实际值
sh start_torch_fp8.sh
```

luopl's avatar
luopl committed
86
## 效果展示
luopl's avatar
luopl committed
87
88
89

**注意**:首次对话时由于kernel编译,可能会出现dtk hipcc编译警告,属于正常现象

luopl's avatar
luopl committed
90
91
92
93
94
95
96
97
98
99
<div align=center>
    <img src="./doc/result_dcu.png"/>
</div>

### 精度
`DCU与GPU精度一致,推理框架:pytorch。`

## 预训练权重
| 模型名称  | 权重大小 | DCU型号  | 最低卡数需求 |下载地址|
|:-----:|:----:|:------:|:------:|:----------:|
luopl's avatar
luopl committed
100
| DeepSeek-V4-Flash | 284B | BW1100 |   8    | [Hugging Face](https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash) |
luopl's avatar
luopl committed
101
102
103
104
105
106

## 源码仓库及问题反馈
- https://developer.sourcefind.cn/codes/modelzoo/deepseek-v4

## 参考资料
- https://github.com/deepseek-ai