Skip to content

Model accuracy alignment#1

Open
zhengshengning wants to merge 7 commits into
PFCCLab:mainfrom
zhengshengning:minimax_model_new
Open

Model accuracy alignment#1
zhengshengning wants to merge 7 commits into
PFCCLab:mainfrom
zhengshengning:minimax_model_new

Conversation

@zhengshengning

Copy link
Copy Markdown

问题1: sequentialMLP 权重代理
问题描述: SequentialMLP 缺少 weight{i} 接口,导致权重访问不兼容 GroupedMLP。
修复文件: Megatron-LM/megatron/core/transformer/moe/experts.py

问题2: 禁用 TE 配置 (ms-swift前置修改)
问题描述: 为了使拆分后的独立 LayerNorm 模块正常工作,需要禁用 Transformer Engine 融合算子。
修复文件: ms-swift-test/swift/megatron/model/register.py

问题3: 不添加任何后缀token (ms-swift前置修改)
修复文件: swift/template/templates/utils.py

问题4: 保留TopKRouter 偏差(expert_bias 被 Float16Module 截断成 bf16)
描述:MG 的 TopKRouter 把 expert_bias 注册成 fp32 buffer,但 Float16Module 在 module.bfloat16() 时把它一起 cast 成 bf16。routing 的 topk 是离散选择,对 bias 末位敏感,bf16 截断直接让 scores_for_choice → topk → probs/routing_map 全部分叉。
修改:改在 Megatron-LM/megatron/core/transformer/module.py 的 Float16Module.init

  • cast 前 _snapshot_expert_bias_fp32(module) 快照所有 expert_bias 的 fp32 值
  • cast 后 _restore_expert_bias_fp32 把 expert_bias.data 还原回 fp32
  • 顺带强制 moe_router_bias_update_rate=0(PF 无在线更新路径)

问题5: Router TE GEMM 精度差异
问题描述: MoE Router 的 logits 计算在 MG 和 PF 之间存在差异,输入和权重完全一致但输出不同。

问题6: CrossEntropyLoss 精度差异
【修复的问题描述】:Megatron 默认走 tensor_parallel.vocab_parallel_cross_entropy,在 TP=1 场景下其内部累加顺序与 paddle nn.CrossEntropyLoss / F.cross_entropy 不一致,导致两框架 LM loss 末位存在 diff。此处在 TP=1 且 logits 未做 vocab 切分时切换到 torch.nn.functional.cross_entropy,与 Paddle 侧 CE 路径对齐。

问题7: MoE unpermute 阶段 scatter_add_ 在 bf16 下存在随机性
【修复的问题描述】:MoE unpermute 阶段 scatter_add_ 在 bf16 下走 atomic 累加,多 expert 输出回写到同一 token 行时累加顺序不可复现,与 PaddleFleet 末位 diff。在 unpermute(无 probs、非 drop_and_pad)的标准路径上改走 fp32 累加。

问题8: SwiGLU 数值路径不一致(bias_activation_fusion=false情况)
【修复的问题描述】:MoE expert 内 SwiGLU 与 router prob 相乘的计算精度对齐。GLU 已在 fp32 下计算,这里把 per_token_scale 也 cast 到 fp32 相乘,最后一次性 cast 回原始 bf16 dtype,对齐 PaddleFleet fused_swiglu_scale「fp32 激活 × fp32 prob → 单次 bf16 round」的数值路径。

@zhengshengning zhengshengning changed the title Minimax model new Model accuracy alignment Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant