已合并
perf: defer mxfp8 backward quantization #3852
perf: defer mxfp8 backward quantization #3852
已合并
guihaowen666创建于 8月6日
guihaowen666
8月6日

What this PR does / why we need it?

When doing low-precision matmul and low-precision GMM calculations, using the double-axis quantization method saves the quantized weights and scales for the model's backward pass, which takes up a lot of GPU memory. This PR changes the double-axis quantization to single-axis quantization, so the model doesn’t save the quantized weights and scales during the forward pass but recalculates them during the backward pass, saving GPU memory.

Does this PR introduce any user-facing change?

This is a newly developed feature. Use the --mxfp8-defer-backward-quant parameter to control whether to enable this feature. It doesn't affect other features and involves no user-facing changes.

How was this patch tested?

Local checks and CI checks passed

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 guihaowen666 的贡献)
Gguihaowen666
8月6日 创建了 pull request,commit d3d2da3b
atomgit-bot
atomgit-bot
8月6日 评论:

变更摘要

此 PR 引入了一个新的 --fp8-quant-fb-split 参数,用于将 FP8 量化操作在前向传播和反向传播中进行拆分。当启用该模式时,前向传播不再将量化后的权重/激活张量保存到 ctx 上下文中供反向传播复用,而是在反向传播时重新计算量化值。这主要影响 MoE 分组矩阵乘法(MXFP8GMMFunction)和通用矩阵乘法(MXFP8MatMul)两条路径。

主要改动

  • 新增 --fp8-quant-fb-split 参数:在 transformer_engine_basic.py 中注册该命令行参数(默认 False),并添加与 FP8 训练的依赖校验,仅在 FP8 启用时有效。

  • MXFP8GMMFunction.op_forward 单轴量化分支:当 fp8_quant_fb_splitTrue 时,权重量化从双轴(npu_dynamic_mx_quant_with_dual_axis)切换为仅行方向单轴(npu_dynamic_mx_quantaxis=-2),不再生成列量化权重,也不再向 ctx 保存 w_quant

  • MXFP8GMMFunction.op_dx 反向重算权重量化:反向传播时通过 hasattr(ctx, 'w_quant') 判断前向是否已保存量化权重;若未保存(即拆分模式),则调用 npu_dynamic_mx_quantaxis=-1)重新计算权重量化值。

  • MXFP8MatMul 跳过前向量化保存:在 mxfp8_scaling_recipe.py 中,当 fp8_quant_fb_splitTrue 时,前向不再将 ctx.xctx.x_scale 保存到上下文中(跳过 npu_dynamic_mx_quant_with_dual_axis 的额外输出),使反向传播自行处理量化。

likedislike
不准确?
atomgit-bot
atomgit-bot
8月6日 评论:

代码审查

审查结论

经过对全部 3 个文件的详细审查:


审查总结

优先级 数量 说明
P0 1 grouped_matmul_util.py:211fp8_quant_fb_split=Trueweight_col_mxfp8 未定义导致 NameError,训练直接崩溃
P2 1 transformer_engine_basic.py:116-117 — 错误消息引用了错误的参数名(fp8_reuse_quantized_weight 应为 fp8_quant_fb_split
P3 1 grouped_matmul_util.py:194-200fp8_quant_fb_split 分支缺少 reuse_identity 参数(可能有意,但无注释说明)

逐文件确认:

  • mindspeed/core/transformer/moe/grouped_matmul_util.py:发现 2 个问题(P0 + P3),属于正确性回归和潜在功能遗漏。
  • mindspeed/features_manager/megatron_basic/transformer_engine_basic.py:发现 1 个问题(P2),错误消息复制粘贴错误会误导用户排查。
  • mindspeed/te/pytorch/fp8/recipes/mxfp8_scaling_recipe.py无问题。正向/反向量化轴选择与 hasattr(ctx, 'x') 分发逻辑一致,ctx.save_for_backward / ctx.output_dtype 在各分支均正确设置。

整体风险判断: P0 问题导致该特性完全不可用——一旦启用 --fp8-quant-fb-split,训练会立即因 NameError 崩溃。建议在合入前必须修复 P0 和 P2 两个问题;P3 建议补充注释或补传参数。

类型 数量
🔴 阻塞 1
🟡 建议 1

⛔ 需要修改

likedislike
不准确?
ascend-robotascend-robot成员
8月6日 添加了label:ascend-cla/yes
此处折叠了135条消息 查看更多
ascend-robotascend-robot成员
10 天前 添加了label:approved
ascend-robot
ascend-robot成员
10 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
wuweiqiang24wuweiqiang24成员
10 天前 解决了最后一个问题
ascend-robotascend-robot成员
10 天前 合入了pull request
ascend-robot
ascend-robot成员
10 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike