[XPU] handle inplace return value for XPU.#7463
[XPU] handle inplace return value for XPU.#7463Jiajun-Ji wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
There was a problem hiding this comment.
Pull request overview
该 PR 主要用于修复 XPU 场景下单测对自定义算子 speculate_set_value_by_flags_and_idx 的返回值处理:XPU 侧算子表现为 in-place 更新输入张量,因此单测不应依赖其返回值再取 .numpy()。
Changes:
- XPU 分支不再接收
speculate_set_value_by_flags_and_idx的返回值,改为直接读取被原地更新后的pre_ids_all。 - 非 XPU 分支保持原先逻辑:使用算子返回的 Tensor 并转换为 numpy 进行对比校验。
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-17 16:44 CST
📋 Review 摘要
PR 概述:修复 XPU 平台 speculate_set_value_by_flags_and_idx 单测中对 inplace 返回值的处理方式
变更范围:custom_ops/xpu_ops/test/
影响面 Tag:XPU OP
📝 PR 规范检查
PR 标题包含 [XPU] Tag ✅;描述中 Motivation 仅写了"单测修复",建议补充更具体的说明,例如:
描述建议(可直接复制):
Motivation:XPU 版本的
speculate_set_value_by_flags_and_idx算子通过 inplace 方式修改pre_ids_all,C++ 函数返回void,不应使用返回值。修复单测以直接从pre_ids_all读取结果,并将 GPU 分支的.numpy()调用移入else块以修正缩进逻辑。Modifications:修正 XPU 分支不再捕获返回值,改为直接读取 inplace 修改后的
pre_ids_all;将 GPU 分支的out_xpu.numpy()缩进到else块内,避免 XPU 分支执行时引用未定义的返回值。
问题
未发现阻塞性问题。
代码分析
已验证 XPU 算子的 C++ 实现(speculate_set_value_by_flags.cc):
- 函数签名为
void SpeculateSetValueByFlagsAndIdx(...),确认无返回值 PD_BUILD_STATIC_OP使用.SetInplaceMap({{"pre_ids_all", "pre_ids_all_out"}})声明 inplace 语义- 修改后的测试正确地忽略返回值,直接从
pre_ids_all.numpy()获取结果
同时确认 GPU 版本(cpp_extensions.cc pybind 暴露)同样为 void 返回,但 GPU 测试分支通过 efficientllm.ops.gpu 导入的是 static op 版本(有 inplace 返回),因此 else 分支保留 out_xpu = ... 赋值是正确的。
总体评价
变更逻辑正确,准确处理了 XPU 算子的 inplace 语义差异。out_xpu.numpy() 的缩进修复也消除了 XPU 路径下潜在的变量引用问题。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7463 +/- ##
==========================================
Coverage ? 74.14%
==========================================
Files ? 398
Lines ? 54977
Branches ? 8613
==========================================
Hits ? 40762
Misses ? 11484
Partials ? 2731
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation
单测修复
Modifications
Usage or Command
Accuracy Tests
Checklist
[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]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.