Skip to content

feat(moe): support more hidden and latent sizes in the fused MoE tail… - #52

Merged
lizhenyun01 merged 1 commit into
PaddlePaddle:mainfrom
ZhangX-21:moe-tail-hidden-latent-sizes
Dec 2, 2026
Merged

lizhenyun01 merged 1 commit into
PaddlePaddle:mainfrom
ZhangX-21:moe-tail-hidden-latent-sizes

Conversation

@ZhangX-21

@ZhangX-21 ZhangX-21 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description / 变更说明

扩展 fused MoE Tail 内核在编译期支持的 Hidden(H)和 latent(L)形状。

  • Hidden 分块:将 H 均分为 TpSize × GroupSize 个 chunk,编译期检查每个 chunk 的行数是 16 的倍数。这样每个 16 行 MMA tile 都落在同一个 128 行 Blockwise FP8 scale block 内,可以移除 Hidden 余数分配和 M 维 padding。
  • Latent 分块:当 L 不能整除 K-split 的计算粒度时,将计算长度向上对齐到 Lg,对 [L, Lg) 的 activation 和暂存权重补零,并限制 scale 读取范围。
  • 计算与归约:Round B 统一使用同一个循环处理单个或多个 Hidden tile,Round C 根据编译期已知的 chunk 大小计算各 rank 的归约范围。

Accuracy impact / 精度影响

生产配置 H=4096, L=2048, TpSize=4, GroupSize=32 通过完整回归,运行 python -m pytest tests/test_latent_moe.py -q 得到 93 passed。

扩展形状通过独立 TP1 Tail 测试与 MoERef.tail 对比。下表为每组 6 个 token 数下的最大逐 token 相对 L2 误差,验收阈值为 0.005。

测试结果

H L Blockwise FP8 MXFP8 Plain MXFP8 SfAtom
3072 2176 0.001734 0.001723 0.001723
3584 1664 0.001722 0.001698 0.001698

Performance impact / 性能影响

完整 Fused MoE 延迟测试

1. 测试环境与配置

量化模式 Batch Size 清理前 (µs) 本次提交 (µs) 延迟变化
Blockwise FP8 8 45.780 45.582 -0.43%
Blockwise FP8 16 71.290 71.367 +0.11%
MXFP8 8 49.149 49.278 +0.26%
MXFP8 16 74.593 74.452 -0.19%

与 PR 基线对比

此前,H/L 扩展版本相对 PR 基线 A/B 测量结果为:

  • 最小延迟变化:-0.02%
  • 最大延迟变化:+0.24%

本组数据以已经包含 H/L 扩展和统一 tile 循环的版本为对照,主要衡量最后一轮 Round C 优化及 Scale 路径清理 对完整 Fused MoE 延迟的影响。

Checklist / 检查项

  • Focused change, linked to an issue or task / 变更聚焦于 fused MoE Tail,待补充关联 issue 或任务
  • Python, PyBind and CUDA/C++ interfaces are consistent / 接口保持一致,完整算子回归通过
  • Related unit tests pass / tests/test_latent_moe.py 全部 93 项通过
  • Accuracy and performance impact are filled in above / 已填写精度与性能实测结果
  • README and docs updated for public behavior changes / 不适用,本次仅扩展内核的编译期能力

mma_f16_m16n8k16(g, a0, a1, a2, a3, xb[2 * mm], xb[2 * mm + 1]);
}
const float sA = scale_of(s.sfa, sb), sB = scale_of(s.sfb, sb);
const float sA = scale_of(s.sfa, sb);

@lizhenyun01 lizhenyun01 Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看到比较多这样的改动,并没有改变实际代码但是换了写法,是必要的吗

@ZhangX-21 ZhangX-21 Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前的代码规范不是很好,需要调整一下。

const uint32_t bw[4] = {B.x, B.y, B.z, B.w};
#pragma unroll
for (int mm = 0; mm < 4; ++mm) {
uint32_t a0, a1, a2, a3;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是以什么标准做的规范呢 我看起来例如这种改动之前的代码似乎更简洁明了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

从可维护性,可读性来讲这样写会更好一些,方便调试。也没有那么绝对吧。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的 可以确认一下不是AI自由发挥就没问题

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯呢,这些处理,AI没有干预那。

@lizhenyun01
lizhenyun01 merged commit 755f852 into PaddlePaddle:main Dec 2, 2026
5 checks passed
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.

2 participants