[Performance] Reduce SonicMoE metadata launch overhead - #1458
[Performance] Reduce SonicMoE metadata launch overhead#1458A-nnonymous wants to merge 2 commits into
Conversation
risemeup1111
left a comment
There was a problem hiding this comment.
已完成初轮代码审查。当前发现一个需要提交新 commit 修复的阻塞问题,另有一个关于新 packed-scale combine 分支可达性的中优先级问题,详情已放在行级评论里。
CI 里仍有多项测试在运行中;请等相关检查结束后再合入。
| grad_x, grad_scale = grad_x | ||
| ctx.combine_grad_handle["data"] = grad_x | ||
| ctx.combine_grad_handle["scale"] = grad_scale | ||
| grad_x = _record_fp8_combine_grad(grad_x, ctx.combine_grad_handle) |
There was a problem hiding this comment.
问题:RR DeepEP combine 分支没有把 fp8_dispatch / combine_grad_handle 继续传给 DeepEPCombineAsyncFunctor。
证据与影响: 这里新增的 _record_fp8_combine_grad(...) 只有在 ctx.fp8_dispatch=True 时才会把 DeepEP combine backward 的 FP8 data/scale 写回 handle。但 fused_combine(..., use_rr_deepep_combine=True) 当前调用 _rr_fusedcombined(..., fn=...) 时没有传 fp8_dispatch 和 combine_grad_handle,而 DeepEPCombineAsyncRefinedRecompute._second_fwd() 又用默认参数调用 DeepEPCombineAsyncFunctor.apply(..., fn=fn)。因此 fp8_dispatch_bwd + use_rr_deepep_combine 的实际路径会跳过这段写回逻辑,_DownProjection.backward 收到的 fp8_combine_grad_handle 无法拿到 DeepEP combine backward 产生的 FP8 梯度/scale,至少会丢掉该配置下的 FP8 backward 通信优化,并可能和 Sonic backward 对 handle 的预期不一致。
期望处理: 请把这两个参数从 fused_combine 的 RR 分支一路传到 DeepEPCombineAsyncFunctor.apply,并补一个覆盖 use_rr_deepep_combine=True, fp8_dispatch=True, combine_grad_handle=... 的测试。修复形态可以类似:
# fused_combine RR branch
combined_x, *fn_out = _rr_fusedcombined(
x,
group,
states,
*(combine_overlap_handle["fn_args"]),
fn=combine_overlap_handle["fn"],
fp8_dispatch=fp8_dispatch,
combine_grad_handle=combine_grad_handle,
)
class DeepEPCombineAsyncRefinedRecompute:
def forward(
self,
x,
group,
states,
*fn_args,
fn,
fp8_dispatch=False,
combine_grad_handle=None,
):
...
output = self._second_fwd(
hold_tensors,
x,
group,
states,
fn,
*fn_args,
fp8_dispatch=fp8_dispatch,
combine_grad_handle=combine_grad_handle,
)
def _second_fwd(
self,
hold_tensors,
x,
group,
states,
fn,
*fn_args,
fp8_dispatch=False,
combine_grad_handle=None,
):
return DeepEPCombineAsyncFunctor.apply(
hold_tensors,
x,
group,
states,
*fn_args,
fn=fn,
fp8_dispatch=fp8_dispatch,
combine_grad_handle=combine_grad_handle,
)处理要求:请针对该评论修复并提交新的 commit。
| grad_output = grad_output.contiguous() | ||
| using_sonic = bool( | ||
| combine_grad_handle | ||
| and combine_grad_handle.get("using_sonic_moe", False) |
There was a problem hiding this comment.
问题:这个 Sonic packed-scale combine 分支依赖 combine_grad_handle["using_sonic_moe"],但生产路径创建的是普通 {},目前没有看到任何调用链会写入这个字段。
证据与影响: MoELayer.fusion_moe_forward() 在 self.fp8_dispatch_bwd 时只创建 fp8_combine_grad_handle = {},随后传给 run_sonic_moe() 和 _DeepEPManager.combine();全仓搜索也只有本次新增单测手工构造了 {"using_sonic_moe": True}。这会让 _quantize_combine_grad_for_deepep() 在真实 Sonic+DeepEP combine backward 中始终走 scale_dtype=paddle.int32 的旧路径,新增的 pack_scale_words / _unpack_sonic_fp8_scale_from_deepep() 分支基本不可达,PR 里关于 combine-grad scale 字节打包的优化和覆盖容易产生误判。
期望处理: 请在生产调用链里明确标记该 handle,或改成由调用方直接传入 using_sonic_moe 布尔值,避免依赖测试专用状态。例如可以在创建 handle 时带上标记,并补一个不 mock handle 内容的端到端单测:
fp8_combine_grad_handle = (
{"using_sonic_moe": self.using_sonic_moe}
if self.fp8_dispatch_bwd
else None
)如果你的设计是只优化 dispatch scale 而不优化 combine-grad scale,也请删掉这部分不可达分支或调整测试断言,避免后续维护者以为真实路径已覆盖。
处理要求:请针对该评论进行回复(同意并已修改请回复 Done,不同意请说明理由)。
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (62.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #1458 +/- ##
==========================================
Coverage ? 62.00%
==========================================
Files ? 2
Lines ? 100
Branches ? 21
==========================================
Hits ? 62
Misses ? 36
Partials ? 2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
PaddleFleet Log Analysis
日志分析报告
失败的测试 case: 根本原因分析: 本 PR( 修复建议:
🔄 每次 Re-run 后自动更新 |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-07-14 01:53:40
📋 Review 摘要
PR 概述:优化 DeepEP dispatch 到 SonicMoE gated GEMM 之间的 FP8 scale carrier、metadata 和 router-score 梯度桥接路径。
变更范围:src/paddlefleet/transformer/moe/fused_a2a.py、src/paddlefleet/transformer/moe/fusion_layer_utils.py 以及对应单卡桥接测试。
影响面 Tag:MoE FP8
问题
未发现新的阻塞性问题。PR 规范问题在下面章节报,不要在这里重复。
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | fp8_combine_grad_handle 未携带 using_sonic_moe,导致 combine backward 的 Sonic pack/unpack 分支无法命中 |
📝 PR 规范检查
符合规范。
总体评价
本轮重点复核了 MoE Sonic FP8 dispatch/combine 对称性、metadata bridge 的 router-score 梯度路径,以及新增测试对新旧 Sonic capability fallback 的覆盖。最新提交已补上 stopped router score 不应挂梯度边的判断,但历史 F1 指向的真实 handle 标记仍未在当前 diff 中修复,本轮不重复发 inline comment。
PR Category
Performance Optimization
PR Types
Performance
Description
This PR removes avoidable host and GPU launch overhead between DeepEP dispatch and SonicMoE gated GEMM.
Root causes addressed:
stop_gradientbefore entering the Sonic PyLayer. Stopped scores remain forward-only and do not receive an invalid backward edge; differentiable scores retain the fused scatter path.Compatibility is capability-gated. Legacy quantization, metadata, and router-gradient paths remain available with older Sonic versions. No barrier logic, optimizer bypass, layout conversion, or persistent parameter/gradient buffer ownership is changed.
Companion PR: PFCCLab/supersonic-moe#68
The Sonic submodule pointer remains at the current upstream revision. It can advance after the companion PR lands.
Validation
main_gradaccumulation.6.49e-4, versus1.91e-2before the companion wgrad fix, under the same nondeterministic settings.