Skip to content

【Hackathon 9th No.59】add test_speculate_set_value [cf]#7712

Open
ghost wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/059-speculate-set-value-unit-test-v3
Open

【Hackathon 9th No.59】add test_speculate_set_value [cf]#7712
ghost wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/059-speculate-set-value-unit-test-v3

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented May 2, 2026

Motivation

Modifications

Usage or Command

Accuracy Tests

Checklist

  • I have submitted the CLA (only first PR)
  • My PR title follows the convention
  • My changes pass all tests

@ghost ghost temporarily deployed to Metax_ci May 2, 2026 17:15 — with GitHub Actions Inactive
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 2, 2026

CLA assistant check
All committers have signed the CLA.

@ghost ghost temporarily deployed to Metax_ci May 2, 2026 17:15 — with GitHub Actions Inactive
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 2, 2026

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label May 2, 2026
PaddlePaddle-bot

This comment was marked as outdated.

@PaddlePaddle-bot
Copy link
Copy Markdown

PaddlePaddle-bot commented May 2, 2026

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-03 21:59:03

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

当前 2 个可统计任务全部通过,无 required 失败。但有 7 个 Workflow 处于 action_required 状态,主要 CI(含单测)尚未运行,需人工审批触发。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
2(0) 2 2 0 0 0 0

⚠️ 注意:以下 7 个 Workflow 处于 action_required 状态(等待审批后才会执行):ApprovalCheck PR TemplateCodestyle-CheckCI_HPUILUVATAR-CICI_XPUPR Build and Test。这些 Workflow 需人工审批触发,其中包含主要单元测试任务 Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage当前实际 CI 尚未完成

注意:action_required workflows 不计入上表的任务统计。


2 任务状态汇总

2.1 Required 任务:0/0 通过

当前未检测到必选(Required)任务配置,或 GitHub Branch Protection Rules 未设置。7 个核心 Workflow 处于 action_required 状态,待审批后方可执行。

状态 任务 备注
⚠️ 无可统计的 required 任务 7 个核心 Workflow 等待审批

2.2 可选任务 — 2/2 通过

可选任务不阻塞合并,失败仅供参考。

状态 任务 耗时 日志 重跑
其余 2 个可选任务通过 - - -

3 失败详情(仅 required)

无 required 失败任务。

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

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

🤖 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_outputtc 参数在函数体中从未使用

总体评价

测试整体结构清晰,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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❓ 疑问 _check_outputtc 参数(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")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 _build_inputsstep[i] 的下界固定为 max_draft(此处为 4),因此所有随机用例都满足 step_idx > 0step_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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants