Skip to content

Commit 0a948ee

Browse files
committed
add doc.
1 parent 1f7612e commit 0a948ee

1 file changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# 1. 背景说明
2+
3+
### 1.1. 单步 MTP(Single-Step MTP)
4+
单步 MTP 是模型在单次前向传播中,仅预测**未来1个token**的多token预测模式。
5+
- 本质:在传统单token预测基础上,新增独立MTP输出头,仅学习单步预测能力。
6+
- 推理适配:仅支持**1步投机解码**,无法直接支撑多步递归预测,多步推理时需依赖模型递归调用,接受率与效率较低。
7+
- 训练定位:作为多步MTP的基础热启模型,快速搭建MTP训练基线。
8+
9+
### 1.2. 多步 MTP(Multi-Step MTP)
10+
多步 MTP 是模型在单次前向传播中,**递归预测未来N个token**(如3步)的模式,通过级联MTP模块实现因果预测。
11+
- 核心机制:第1步MTP预测t+1,第2步基于第1步输出预测t+2,第3步基于第2步输出预测t+3,保持序列逻辑连贯。
12+
- 推理适配:直接支持**N步投机解码**,无需额外递归调用,提升接受率与生成速度。
13+
- 训练收益:投机解码从1步预测变为3步预测,平均接受长度显著提升。
14+
15+
### 1.3. 单步 vs 多步 MTP 核心对比
16+
| 维度 | 单步 MTP | 多步 MTP |
17+
|------|----------|----------|
18+
| 预测步数 | 1步 | N步(如3步) |
19+
| 模块结构 | 单个MTP输出头 | 单个MTP输出头 |
20+
| 推理支持 | 仅1步投机 | N步投机解码 |
21+
22+
PaddleFormers 提供冻结主干的MTP权重训练,可以基于无MTP(或只有一层MTP权重)的模型进行进N步MTP能力训练,让模型具有多步MTP能力。
23+
24+
25+
# 2. 硬件配置要求
26+
27+
## 2.1. 最低配置
28+
29+
GPU: NVIDIA H100 80GB (推荐) 或 H800、H20等
30+
31+
数量: 如果基于GLM-4.5-Air模型(103B)进行训练,需要最少32卡(4机),如果需要进行128k长文训练则需要8机(64卡)
32+
33+
网络要求:支持 NCCL 通信
34+
35+
## 2.2. 环境要求
36+
37+
操作系统: Ubuntu 20.04/22.04 LTS
38+
39+
CUDA: 12.9
40+
41+
cuDNN: 8.9.7+
42+
43+
NCCL: 2.18.3+
44+
45+
Python: 3.10
46+
47+
推荐使用官方镜像。
48+
49+
# 3. 启动训练
50+
在这里给出了8机冻结主干3步MTP训练的参数:
51+
52+
```yaml
53+
### data
54+
train_dataset_type: erniekit
55+
eval_dataset_type: erniekit
56+
train_dataset_path: ./tests/fixtures/dummy/sft/train.jsonl
57+
train_dataset_prob: "1.0"
58+
eval_dataset_path: ./tests/fixtures/dummy/sft/eval.jsonl
59+
eval_dataset_prob: "1.0"
60+
61+
max_seq_len: 65536
62+
packing: true
63+
use_template: false
64+
random_shuffle: true
65+
mix_strategy: concat
66+
truncate_packing: false
67+
padding_free: true
68+
69+
### model
70+
model_name_or_path: GLM-4.5-Air
71+
_attn_implementation: flashmask
72+
73+
### finetuning
74+
# base
75+
stage: SFT
76+
fine_tuning: full
77+
seed: 23
78+
do_train: true
79+
do_eval: false
80+
per_device_eval_batch_size: 1
81+
per_device_train_batch_size: 1
82+
num_train_epochs: 1
83+
max_steps: 1100
84+
eval_iters: 1000
85+
eval_steps: 1000000
86+
evaluation_strategy: steps
87+
save_steps: 50000
88+
save_hf_steps: 100
89+
save_strategy: steps
90+
save_total_limit: 3
91+
logging_steps: 1
92+
gradient_accumulation_steps: 32
93+
logging_dir: ./vdl_log
94+
output_dir: ./output
95+
disable_tqdm: true
96+
eval_accumulation_steps: 16
97+
98+
# train
99+
warmup_steps: 110
100+
learning_rate: 1.0e-5
101+
weight decay: 0.1
102+
103+
104+
# performance
105+
context_parallel_size: 1
106+
tensor_model_parallel_size: 8
107+
expert_model_parallel_size: 16
108+
sequence_parallel: true
109+
use_expert_parallel: true
110+
pipeline_model_parallel_size: 4
111+
num_empty_layers_add_in_head: 0
112+
num_empty_layers_add_in_tail: 14
113+
114+
# performance
115+
recompute_granularity: full
116+
recompute_method: uniform
117+
recompute_num_layers: 1
118+
119+
120+
moe_grouped_gemm: false
121+
moe_deep_gemm: false
122+
moe_shared_expert_overlap: true
123+
124+
apply_rope_fusion: true
125+
fuse_rms_norm: true
126+
moe_router_force_load_balancing: false
127+
router_aux_loss_coef: 0.0001
128+
129+
split_param: true
130+
sharding: stage1
131+
stage1_overlap: true
132+
133+
# pp
134+
pp_delay_scale_loss: true
135+
overlap_p2p_comm: true
136+
variable_seq_lengths: true
137+
best_unbalanced_scheduler: true
138+
pp_release_grads: true
139+
140+
tp_delay_scale_loss: True
141+
142+
amp_master_grad: true
143+
bf16: true
144+
fp16_opt_level: O2
145+
fa_version: 3
146+
147+
save_checkpoint_format: flex_checkpoint
148+
load_checkpoint_format: flex_checkpoint
149+
dataloader_shuffle: false
150+
151+
dataloader_num_workers: 8
152+
prefetch_factor: 2
153+
154+
fp32_residual_connection: false
155+
tensorwise_offload_optimizer: true
156+
157+
mtp_loss_scaling_factor: 0.1
158+
num_nextn_predict_layers: 1
159+
mtp_distillation_loss: false
160+
mtp_num_layers: 1
161+
train_mtp_only: true
162+
```
163+
164+
#### (1)核心训练配置(以3步为例)
165+
```yaml
166+
# 模型实际拥有多少层MTP权重(如果热启模型没有MTP层则需要在此手动指定)
167+
num_nextn_predict_layers: 1
168+
# MTP训练步数,填1则为单步,填3则为3步
169+
mtp_num_layers: 3
170+
# 是否冻结主干权重(MTP-only训练必开)
171+
train_mtp_only: true
172+
```
173+
174+
## 四、MTP 模型推理部署(多步投机解码)
175+
### 1. 多步 MTP 推理配置(FastDeploy)
176+
```bash
177+
python -m fastdeploy.entrypoints.openai.api_server \
178+
--model checkpoint/ \ # 多步MTP训练后模型
179+
--port 8390 \
180+
--engine-worker-queue-port 8392 \
181+
--cache-queue-port 8393 \
182+
--metrics-port 8394 \
183+
--tensor-parallel-size 8 \
184+
--max-model-len 131072 \
185+
# 多步MTP核心推理配置
186+
--speculative-config '{"method": "mtp", "num_speculative_tokens": 3, "num_model_steps": 3,"model": "checkpoint/"}' \
187+
--max-num-seqs 32
188+
```
189+
- 关键参数:
190+
- `num_speculative_tokens: 3`:投机生成3个token
191+
- `num_model_steps: 3`:匹配训练时的3步MTP,实现训推一致
192+

0 commit comments

Comments
 (0)