【Hackathon 9th No.59】add test_speculate_set_value [cf]#7712
【Hackathon 9th No.59】add test_speculate_set_value [cf]#7712ghost wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
CI报告基于以下代码生成(30分钟更新一次): 1 任务总览当前 2 个可统计任务全部通过,无 required 失败。但有 7 个 Workflow 处于
2 任务状态汇总2.1 Required 任务:0/0 通过
2.2 可选任务 — 2/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:44:19
📋 Review 摘要
PR 概述:为 speculate_set_value_by_flags_and_idx GPU 算子新增单元测试,包含 NumPy reference 对比验证
变更范围:tests/operators/
影响面 Tag:[Speculative Decoding] [OP]
📝 PR 规范检查
PR 标题缺少官方 Tag,且描述中 Motivation / Modifications / Usage or Command / Accuracy Tests 四个段落均为 TODO 占位符,不符合模板要求,建议按如下内容替换。
标题建议(可直接复制):
[Speculative Decoding] Add unit test for speculate_set_value_by_flags_and_idx op
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
为 `speculate_set_value_by_flags_and_idx` GPU 算子补充单元测试,提升投机解码模块的测试覆盖率。
## Modifications
- 新增 `tests/operators/test_speculate_set_value_by_flags_and_idx.py`,包含:
- `_reference`:基于 NumPy 的参考实现,与 GPU 算子结果对比
- `_build_inputs`:随机输入构造辅助函数
- `TestSpeculateSetValue`:3 个测试用例,覆盖随机批次、prompt 偏移、混合停止状态
## Usage or Command
```bash
python -m pytest tests/operators/test_speculate_set_value_by_flags_and_idx.py -v
```
## Accuracy Tests
N/A(算子正确性由 NumPy reference 逐元素对比验证,无模型精度数据)
## 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]`, `[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.
- [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.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | tests/operators/test_speculate_set_value_by_flags_and_idx.py:60 |
step_idx == 0 边界场景未覆盖,该分支在 kernel 中合法存在 |
| ❓ 疑问 | tests/operators/test_speculate_set_value_by_flags_and_idx.py:68 |
_check_output 的 tc 参数在函数体中从未使用 |
总体评价
测试整体结构清晰,reference 逻辑与 CUDA kernel 实现对齐,用例覆盖了 stop_flags / prompt_offset 等核心场景。主要问题是 PR 规范未完善,另有一处边界覆盖不足和一处无用参数,建议修复后合入。
| sld = np.random.randint(0, 3, (batch_size,)).astype("int32") | ||
| step = np.zeros(batch_size, dtype="int64") | ||
| for i in range(batch_size): | ||
| hi = max_len - int(plens[i, 0]) - max_draft - 1 |
There was a problem hiding this comment.
❓ 疑问 _check_output 的 tc 参数(TestCase 实例)在函数体中从未被使用,所有断言均走 np.testing.assert_array_equal。
建议移除 tc 参数,或改用 self.assert* 风格,保持接口一致性:
def _check_output(inputs_np): # 移除未使用的 tc 参数| """Create random inputs for the op.""" | ||
| ids = np.full((batch_size, max_len), -1, dtype="int64") | ||
| plens = np.random.randint(0, max_len // 4, (batch_size, 1)).astype("int64") | ||
| atoks = np.random.randint(100, 50000, (batch_size, max_draft)).astype("int64") |
There was a problem hiding this comment.
🟡 建议 _build_inputs 中 step[i] 的下界固定为 max_draft(此处为 4),因此所有随机用例都满足 step_idx > 0,step_idx == 0 的边界场景从未覆盖。
根据 kernel 实现,step_idx == 0 时跳过写入,是一个合法且不同于主路径的分支,建议补充该边界用例:
def test_step_idx_zero(self):
"""step_idx=0 should not write any tokens."""
bs, max_len = 2, 64
ids = np.full((bs, max_len), -1, dtype='int64')
plens = np.zeros((bs, 1), dtype='int64')
atoks = np.array([[10, 20], [30, 40]], dtype='int64')
anum = np.array([1, 2], dtype='int32')
stop = np.array([False, False])
slt = np.ones(bs, dtype='int32')
sle = np.array([1, 1], dtype='int32')
sld = np.array([2, 3], dtype='int32')
step = np.array([0, 0], dtype='int64') # step_idx == 0
_check_output(self, (ids, plens, atoks, anum, stop, slt, sle, sld, step))
Motivation
Modifications
Usage or Command
Accuracy Tests
Checklist