【Hackathon 9th No.39】add test_moe_expert_ffn_wint2 [cf]#7710
【Hackathon 9th No.39】add test_moe_expert_ffn_wint2 [cf]#7710ghost wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-03 01:24:51
📋 Review 摘要
PR 概述:PR 标题声称新增 test_moe_expert_ffn_wint2 单测,但实际变更仅为 README_EN.md 末尾新增一个空行,未见任何测试文件提交
变更范围:README_EN.md
影响面 Tag:[Docs]
📝 PR 规范检查
存在以下规范问题:① 标题未使用官方 [Tag] 描述 格式(当前使用了 【】 书名号格式);② PR 描述各 section 内容均为 TODO 占位符,未填写实际信息;③ Checklist 结构与 §D2 模板不符。
标题建议(可直接复制):
[Docs] Add trailing newline in README_EN.md
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
在 `README_EN.md` 末尾补充换行符,修复文件末尾缺少换行的格式问题。
## Modifications
- `README_EN.md`:在文件末尾新增一个空行
## Usage or Command
N/A
## Accuracy Tests
N/A
## Checklist
- [ ] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 📝 PR 规范 | — | 标题未使用 [Tag] 描述 格式,且各描述 section 均为 TODO 占位符 |
| 🟡 建议 | — | PR 标题声称新增 test_moe_expert_ffn_wint2 单测,但 diff 仅含 README_EN.md 末尾空行,测试文件未见提交,请确认是否漏提交 |
总体评价
本次 PR 实际变更仅为 README_EN.md 末尾新增一个空行,与标题所描述的新增单测内容不符;PR 描述各 section 均未填写实际内容,建议作者补全描述,并确认是否漏提交测试文件后再合入。
CI报告基于以下代码生成(30分钟更新一次): 1 任务总览所有 Required 任务均已通过(当前未检测到 Required 任务配置)。有 1 个可选任务失败,7 个工作流等待人工审批。
2 任务状态汇总2.1 Required任务 : 0/0 通过
2.2 可选任务 — 1/2 通过
3 失败详情(仅 required)无 required 失败任务。
|
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-03 21:47:17
📋 Review 摘要
PR 概述:为 WINT2 权重量化的 MoE Expert FFN 算子新增单元测试,验证融合算子与分解参考实现的数值一致性。
变更范围:tests/operators/test_moe_expert_ffn_wint2.py(新增)
影响面 Tag:[OP]
📝 PR 规范检查
PR 标题未使用 [Tag] 描述 标准格式(当前使用 【】 中文书名号,且末尾 [cf] 非官方 Tag);PR 描述各 section 内容均为 TODO 占位符,需补充具体内容。
标题建议(可直接复制):
[OP] Add unit test for moe_expert_ffn_wint2 operator
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
为 WINT2 权重量化的 MoE Expert FFN 算子(`moe_expert_ffn_wint2`)补充单元测试,验证融合算子的输出与分解参考实现(winx_unzip 反量化 + matmul + SwiGLU + matmul)在 BF16/FP16 数据类型及不同 token 分布下的数值一致性。
## Modifications
- 新增 `tests/operators/test_moe_expert_ffn_wint2.py`:
- `_cutlass_rearrange`:按 CUTLASS WINT2 权重布局重排辅助函数
- `_build_inputs`:生成随机输入张量(权重、scale、zero-point 等)
- `_call_op`:调用 `moe_expert_ffn_wint2` 融合算子
- `_reference_moe_expert_ffn`:基于 `winx_unzip` 的分解参考实现
- `TestMoeExpertFFNWint2`:包含 BF16、FP16 及非均匀 token 分布三组正确性测试
## Usage or Command
`python -m pytest tests/operators/test_moe_expert_ffn_wint2.py -v`
## Accuracy Tests
N/A(单元测试通过 `np.testing.assert_allclose(rtol=5e-2, atol=5e-2)` 验证融合算子与分解实现的数值一致性,无端到端精度对比数据)
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [x] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 📝 PR 规范 | 标题 / 描述 | 标题未使用官方 Tag 格式;描述各 section 为 TODO 占位符 |
| ❓ 疑问 | tests/operators/test_moe_expert_ffn_wint2.py:93 |
_call_op 末尾参数 False 含义未注释,可读性差 |
| 🟡 建议 | tests/operators/test_moe_expert_ffn_wint2.py:99 |
_up_weight_raw 仅用于取 E,实际权重数据未使用,属冗余字段 |
| ❓ 疑问 | tests/operators/test_moe_expert_ffn_wint2.py:124 |
if end <= start 零 token 分支未被现有测试覆盖 |
总体评价
测试结构清晰,使用 winx_unzip 分解参考验证融合算子数值正确性的思路合理。建议修复 PR 规范问题并补充零 token 专家测试用例后合入。
| inputs["down_proj_local_scale"], | ||
| inputs["down_proj_code_scale"], | ||
| inputs["down_proj_code_zp"], | ||
| False, |
There was a problem hiding this comment.
❓ 疑问 _call_op 末尾第 14 个位置参数 False 含义未注释,可读性差,读者无法从代码判断该布尔值控制什么行为。
建议添加注释说明:
False, # TODO: 说明该参数含义,例如 use_bias=False或在函数 docstring 中补充各参数说明。
|
|
||
| def _reference_moe_expert_ffn(inputs): | ||
| """Decomposed reference: winx_unzip dequant -> matmul -> SwiGLU -> matmul.""" | ||
| E = inputs["_up_weight_raw"].shape[0] |
There was a problem hiding this comment.
🟡 建议 _up_weight_raw 在此处仅用于取专家数 E,其实际权重数据在引用实现中并未使用(传给 _winx_unzip_op 的是经过重排的 up_gate_proj_weight)。
建议改为:
E = inputs["up_gate_proj_weight"].shape[0]并移除 _build_inputs 返回字典中的 _up_weight_raw 和 _down_weight_raw 两个冗余字段,减少误导。
| for e in range(E): | ||
| start, end = int(starts[e]), int(prefix[e]) | ||
| if end <= start: | ||
| continue |
There was a problem hiding this comment.
❓ 疑问 if end <= start: continue 分支(某专家分配 0 个 token)在现有所有测试用例中均未被触发(TOKENS=[4,6,2,4] 和 [1,5,3,7] 均无零分配),该分支的正确性未经验证。
建议补充一个覆盖零 token 专家的测试用例,例如:
def test_correctness_zero_token_expert(self):
"""Expert receiving 0 tokens is silently skipped."""
self._check_output(tokens=[4, 0, 2, 4])
Motivation
Modifications
Usage or Command
Accuracy Tests
Checklist