已关闭
[Bug-Report|缺陷反馈]: glm-4.5-air sft loss异常 #1012
Viper创建于  2025年12月19日关闭于  1月5日
Viper
Viper
2025年12月19日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

mindspeed-llm 2.2.0.
选用3k数据训练,loss正常(起始loss小于1);将序列长度扩展到6k后 loss爆炸(起始loss大于5,grad norm 40+)。数据在其他模型上验证过,没有问题。

尝试过多种重计算和CP方案,loss都不正确。

TP=1
PP=8
EP=16

CP=4

SEQ_LEN=6144

DISTRIBUTED_ARGS="
--nproc_per_node $NPUS_PER_NODE
--nnodes $NODE_NUM
--node_rank $RANK
--master_addr $MASTER_ADDR
--master_port $MASTER_PORT
"

--moe-zero-memory level1 \

MOE_ARGS="
--moe-grouped-gemm
--moe-alltoall-overlap-comm
--moe-permutation-async-comm
--moe-token-dispatcher-type alltoall_seq
--first-k-dense-replace 1
--moe-layer-freq 1
--n-shared-experts 1
--num-experts 128
--moe-router-topk 8
--moe-ffn-hidden-size 1408
--moe-router-load-balancing-type none
--moe-router-num-groups 1
--moe-router-group-topk 1
--norm-topk-prob
--moe-router-score-function sigmoid
--moe-router-enable-expert-bias
--moe-router-dtype fp32
"

# --recompute-method uniform \
# --recompute-granularity full \
# --recompute-num-layers 1 \

# --moe-zero-memory level1 \
# --recompute-activation-function \

# --context-parallel-size ${CP} \
# --use-cp-send-recv-overlap \
# --attention-mask-type general \
# --cp-attention-mask-type general \
# --ulysses-degree-in-cp 2 \
# --context-parallel-algo hybrid_cp_algo \

GPT_ARGS="
--recompute-method uniform
--recompute-granularity full
--recompute-num-layers 1
--tensor-model-parallel-size ${TP}
--pipeline-model-parallel-size ${PP}
--expert-model-parallel-size ${EP}
--noop-layers 1,47
--sequence-parallel
--use-mcore-models
--use-flash-attn
--post-norm
--kv-channels 128
--use-fused-rmsnorm
--use-fused-swiglu
--overlap-grad-reduce
--use-distributed-optimizer
--num-layers 48
--hidden-size 4096
--ffn-hidden-size 10944
--num-attention-heads 96
--seq-length ${SEQ_LEN}
--micro-batch-size 1
--global-batch-size 64
--max-position-embeddings 131072
--padded-vocab-size 151552
--make-vocab-size-divisible-by 1
--group-query-attention
--num-query-groups 8
--disable-bias-linear
--add-qkv-bias
--position-embedding-type rope
--rotary-percent 0.5
--no-rope-fusion
--normalization RMSNorm
--swiglu
--tokenizer-type PretrainedFromHF
--tokenizer-name-or-path ${TOKENIZER_PATH}
--lr 5e-6
--norm-epsilon 1e-05
--train-iters 100
--lr-decay-style cosine
--untie-embeddings-and-output-weights
--attention-dropout 0.0
--init-method-std 0.01
--hidden-dropout 0.0
--no-masked-softmax-fusion
--attention-softmax-in-fp32
--min-lr 1.25e-7
--weight-decay 1e-1
--lr-warmup-fraction 0.01
--clip-grad 1.0
--adam-beta1 0.9
--initial-loss-scale 4096
--adam-beta2 0.95
--no-load-optim
--no-load-rng
--no-save-optim
--no-save-rng
--no-shared-storage
--no-gradient-accumulation-fusion
--no-bias-swiglu-fusion
--bf16
"

SFT_ARGS="
--finetune
--stage sft
--is-instruction-dataset
--prompt-type empty
"

DATA_ARGS="
--data-path ${DATA_PATH}/glm45
--split 100,0,0
"

OUTPUT_ARGS="
--log-interval 1
--save-interval 10
--eval-interval 20000
--eval-iters 0
"

我做数据的时候拼好了prompt,所以训练时template采用的是empty。

Environment / 环境信息 (Mandatory / 必填)

mindspeed-llm 2.2.0
CANN 8.3.RC1 (其余环境均使用CANN配套版本)

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

根据配置文件拉起训练即可复现

Describe the expected behavior / 预期结果 (Mandatory / 必填)

期望loss正常,grad_norm正常

[2025-12-17 08:33:45] iteration 1/ 100 | consumed samples: 64 | elapsed time per iteration (ms): 427079.3 | learning rate: 5.000000E-06 | global batch size: 64 | lm loss: 7.680722E+00 | loss scale: 1.0 | grad norm: 81.220 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-17 08:34:55] iteration 2/ 100 | consumed samples: 128 | elapsed time per iteration (ms): 69876.8 | learning rate: 4.998773E-06 | global batch size: 64 | lm loss: 6.719289E+00 | loss scale: 1.0 | grad norm: 247.244 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-17 08:36:05] iteration 3/ 100 | consumed samples: 192 | elapsed time per iteration (ms): 70662.6 | learning rate: 4.995093E-06 | global batch size: 64 | lm loss: 6.511322E+00 | loss scale: 1.0 | grad norm: 61.512 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-17 08:37:17] iteration 4/ 100 | consumed samples: 256 | elapsed time per iteration (ms): 71810.8 | learning rate: 4.988963E-06 | global batch size: 64 | lm loss: 5.613183E+00 | loss scale: 1.0 | grad norm: 33.555 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-17 08:38:29] iteration 5/ 100 | consumed samples: 320 | elapsed time per iteration (ms): 72076.1 | learning rate: 4.980390E-06 | global batch size: 64 | lm loss: 5.123504E+00 | loss scale: 1.0 | grad norm: 31.639 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |

Special notes for this issue/备注 (Optional / 选填)

likedislike
Viper
Viper
2025年12月19日 评论:

最好的情况,loss起始是2.5,也不是很正常。

[2025-12-19 02:19:31] iteration 1/ 100 | consumed samples: 64 | elapsed time per iteration (ms): 391020.9 | learning rate: 5.000000E-06 | global batch size: 64 | lm loss: 2.511080E+00 | loss scale: 1.0 | grad norm: 29.319 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-19 02:20:01] iteration 2/ 100 | consumed samples: 128 | elapsed time per iteration (ms): 30229.4 | learning rate: 4.998773E-06 | global batch size: 64 | lm loss: 3.145693E+00 | loss scale: 1.0 | grad norm: 38.824 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-19 02:20:33] iteration 3/ 100 | consumed samples: 192 | elapsed time per iteration (ms): 31804.2 | learning rate: 4.995093E-06 | global batch size: 64 | lm loss: 2.417500E+00 | loss scale: 1.0 | grad norm: 23.254 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-19 02:21:01] iteration 4/ 100 | consumed samples: 256 | elapsed time per iteration (ms): 28384.0 | learning rate: 4.988963E-06 | global batch size: 64 | lm loss: 2.363376E+00 | loss scale: 1.0 | grad norm: 17.296 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |
[2025-12-19 02:21:30] iteration 5/ 100 | consumed samples: 320 | elapsed time per iteration (ms): 28935.9 | learning rate: 4.980390E-06 | global batch size: 64 | lm loss: 2.234943E+00 | loss scale: 1.0 | grad norm: 14.641 | num zeros: 0 | number of skipped iterations: 0 | number of nan iterations: 0 |

likedislike
温一盏
温一盏成员
2025年12月19日 评论:

您好,loss在4以下一般认为是正常的

likedislike
温一盏温一盏成员
2025年12月19日 issue状态由 TODO 改变为 WIP
温一盏温一盏成员
2025年12月19日 issue状态由 WIP 改变为 Analysing
Viper
Viper
2025年12月19日 评论:

您好,loss在4以下一般认为是正常的

@qyzqyz

您好,后训练正常情况起始loss应该1左右,因为我是常规数据,并不是垂域数据,而且grad norm非常大,这个也不正常。当我把序列长度扩展到48k后,起始loss能有9,不太正常。

likedislike
温一盏
温一盏成员
2025年12月19日 评论:

您好,loss在4以下一般认为是正常的

@qyzqyz

您好,后训练正常情况起始loss应该1左右,因为我是常规数据,并不是垂域数据,而且grad norm非常大,这个也不正常。当我把序列长度扩展到48k后,起始loss能有9,不太正常。

@Viper403

已收到您的反馈,我们正在复现定位中,如有结果将第一时间告知您。

likedislike
温一盏
温一盏成员
2025年12月20日 评论:

您好,长序列确认无问题,建议您检查脚本,请先不要使用pack模式,并且我看您脚本的--prompt-type empty,模板需要改为--prompt-type glm4_moe,否则也会有精度问题

likedislike
Viper
Viper
2025年12月20日 评论:

您好,长序列确认无问题,建议您检查脚本,请先不要使用pack模式,并且我看您脚本的--prompt-type empty,模板需要改为--prompt-type glm4_moe,否则也会有精度问题

@qyzqyz

您好,非常感谢。我其实怀疑的不是单纯的长序列,因为同样的长序列配置我训练其他模型是没有问题的,我怀疑的是 glm 长序列时 的 精度问题。

开启pack后确实 loss会更高,虽然不太理解为啥,但我在报障前已经关闭了。

我的数据已经用apply_chat_template的方式拼接好了glm4.5-moe的提示词模板,并转换为了bin和idx,所以训练的时候我选用的是empty,避免重复拼接。请问为什么这个prompt-type参数会影响精度?我看代码里面他做的也是字符串操作,是等价的。由于我的数据是多轮数据,所以离线拼接更方便。

如果你们验证无误的话,能否提供一份训练glm45-moe的样例数据和对应的loss曲线图,我可以尝试复现一下,万分感谢!

likedislike
温一盏
温一盏成员
2025年12月20日 评论:

您好,长序列确认无问题,建议您检查脚本,请先不要使用pack模式,并且我看您脚本的--prompt-type empty,模板需要改为--prompt-type glm4_moe,否则也会有精度问题

@qyzqyz

您好,非常感谢。我其实怀疑的不是单纯的长序列,因为同样的长序列配置我训练其他模型是没有问题的,我怀疑的是 glm 长序列时 的 精度问题。

开启pack后确实 loss会更高,虽然不太理解为啥,但我在报障前已经关闭了。

我的数据已经用apply_chat_template的方式拼接好了glm4.5-moe的提示词模板,并转换为了bin和idx,所以训练的时候我选用的是empty,避免重复拼接。请问为什么这个prompt-type参数会影响精度?我看代码里面他做的也是字符串操作,是等价的。由于我的数据是多轮数据,所以离线拼接更方便。

如果你们验证无误的话,能否提供一份训练glm45-moe的样例数据和对应的loss曲线图,我可以尝试复现一下,万分感谢!

@Viper403

已经收到您的反馈,当前对于其他模型,长序列是没有问题的,而对于您提到的“ glm 长序列时 的 精度问题”,由于机时问题,暂无法为您验证该模型,您可以用当前的配置,与当前您使用的权重,跑一个llm的推理脚本,看一下对话回答是否正常,以此作为精度的判断参考

如果您对于数据集的处理和我们内部的模板操作是等价的,请忽略我对Prompt-type参数的提示

对于您使用的2.2.0分支,该分支暂未适配您使用的脚本,glm45-moe-air模型的微调脚本为两周前在master分支脚本适配,不建议您跨分支使用

likedislike
Viper
Viper
2025年12月20日 评论:

感谢帮助~

likedislike
温一盏
温一盏成员
1月5日 评论:

如果您目前没有其他问题,我们将根据流程关闭此 issue。
如后续有新的疑问或补充内容,欢迎随时重新打开本 issue,或另起一个新的 issue 进行提问。
感谢您的理解与支持!

likedislike
温一盏温一盏成员
1月5日 issue状态由 Analysing 改变为 DONE
温一盏温一盏成员
1月5日 关闭了 issue
LLinShua成员
1月14日 关联了pull request:[pytorch][bugfix]Added missing parameter to glm45-moe fine-tune script
ascend-robotascend-robot成员
1月22日 添加了label:resolved