[Operator Mechanism] Add scatter_nd_add double gradient support#79494
[Operator Mechanism] Add scatter_nd_add double gradient support#79494leeleolay wants to merge 1 commit into
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
ed94264 to
c72b9cd
Compare
risemeup1111
left a comment
There was a problem hiding this comment.
未发现需要阻塞合入的问题。关于 optional double-grad 分支的测试覆盖有一条非阻塞建议,详情见行级评论;Pre Commit 已通过,其余 CI 以最终结果为准。
| x_grad, updates_grad = paddle.grad( | ||
| loss, [x, updates], create_graph=True | ||
| ) |
There was a problem hiding this comment.
优先级:P2
处理要求:请针对该评论进行回复(同意并已修改请回复 Done,不同意请说明理由)。
当前用例在第一次 paddle.grad 中同时请求 [x, updates],因此后续 double grad 会同时给 x_grad 和 updates_grad 传入 cotangent;但本 PR 的 YAML/实现新增了 grad_x_grad、grad_updates_grad 两个 optional 分支,且 #79493 的最小复现只请求 updates 的一阶梯度。建议补一个只请求单个一阶梯度输出的断言,避免 optional 输出映射或空分支回归时漏测。
可参考把计算封装成 helper 后增加类似用例:
updates_grad = paddle.grad(loss, updates, create_graph=True)[0]
updates_double_grad = paddle.grad(updates_grad.sum(), updates)[0]
np.testing.assert_allclose(
updates_double_grad.numpy(),
np.array([[4.0, 4.0], [4.0, 4.0], [2.0, 2.0]]),
)若认为现有 [x, updates] 用例已能覆盖单输出可选分支,请说明依据。
There was a problem hiding this comment.
Done. The test now covers only grad_x_grad, only grad_updates_grad, and both optional inputs with duplicate indices. I also added a separate default-eager assertion for the original create_graph=True reproduction. The composite second-gradient numerical checks run with eager prim enabled, consistent with other composite-only higher-gradient tests. Full CPU build and the complete test_scatter_nd_op.py pass.
There was a problem hiding this comment.
已确认当前提交已覆盖原建议:test_create_graph 保留默认 eager 下的 create_graph=True 复现路径,test_double_grad 在 eager prim 下分别覆盖 only grad_x_grad、only grad_updates_grad 和两者同时存在的分支,重复 index 的期望值也对齐。该线程我会标记为已解决。
c72b9cd to
414b60f
Compare
risemeup1111
left a comment
There was a problem hiding this comment.
已复查当前提交,之前关于 optional 分支测试覆盖的建议已补齐,未发现新的阻塞问题。细节见对应的行级讨论。
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-07-17 01:46:21
📋 Review 摘要
PR 概述:为 scatter_nd_add 注册并实现二阶梯度,补充动态图 create_graph/二阶梯度回归测试
变更范围:backward.yaml、composite double backward、PIR VJP 黑名单、legacy 单测
影响面 Tag:[Operator Mechanism] [Execute Infrastructure]
问题
未发现阻塞性问题。PR 规范问题在下面章节报,不要在这里重复
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | 历史指出测试只覆盖两个 optional 同时传入;当前新增 "x"/"updates"/"both" 三个子用例,已分别覆盖 grad_x_grad 与 grad_updates_grad 单独传入。 |
✅ 已修复 |
📝 PR 规范检查
标题缺少官方 Tag;描述结构符合 checklist §D2 模板。
标题建议(可直接复制):
[Operator Mechanism] Add scatter_nd_add double gradient support
总体评价
新增 double grad 公式与现有 scatter_nd_add_grad 的数学关系一致,测试覆盖了 duplicate index 的累加和两个 optional 梯度分支。本轮未拉取 CI,未进行编译/测试运行;完整编译和 CI 仍以流水线为准。
|
/re-run all-failed |
|
The approval gate now passes the review-bot check and reports two remaining code-owner requirements. Could @wanghuancoder please review the Validation completed locally: full CPU |
|
CI status note: the only non-successful job, Mac-CPU / Build and test, was cancelled by the workflow's 60-minute job timeout. The macOS build completed successfully, and 357/1952 tests had passed with no test failure when GitHub emitted 'The operation was canceled' exactly at the timeout. Coverage, CI-Windows, CI-Build, and CI-H all passed. Please rerun the Mac job if a green aggregate CI result is required. |
CI报告基于以下代码生成(30分钟更新一次): 1 Required任务 : 47/49 通过
2 失败详情🔴 Check approval — 需要 Approval(置信度: 高)该 Job 需要人工 Approval,完成审批后 CI 才会继续执行。 |
PR Category
Operator Mechanism
PR Types
Bug fixes
Description
Fixes #79493
Motivation
Molecular force models compute forces as coordinate gradients of energy and differentiate a force loss again during training.
paddle.scatter_nd_addcurrently raises:when the first gradient is requested with
create_graph=True.Changes
scatter_nd_add_double_gradinbackward.yaml.grad_x_grad + scatter_nd(index, grad_updates_grad).scatter_nd_add_gradto the PIR VJP blacklist because its double gradient is composite-only, consistent withindex_put_gradandput_along_axis_grad.create_graph=Truepath and all three optional-input combinations under eager prim.Validation
paddle_pythonbuild completed successfully (1495/1495).python -m unittest test_scatter_nd_op.TestScatterNdAddDoubleGrad: 2 tests passed.test_scatter_nd_op.py: 29 tests passed, 4 device-specific tests skipped.grad_x_grad, onlygrad_updates_grad, and both inputs.是否引起精度变化
否