Skip to content

[Comp] Add view_shape_double_grad for eager mode#76667

Merged
HydrogenSulfate merged 4 commits intoPaddlePaddle:developfrom
HydrogenSulfate:add_view_shape_double_grad
Dec 2, 2025
Merged

[Comp] Add view_shape_double_grad for eager mode#76667
HydrogenSulfate merged 4 commits intoPaddlePaddle:developfrom
HydrogenSulfate:add_view_shape_double_grad

Conversation

@HydrogenSulfate
Copy link
Contributor

@HydrogenSulfate HydrogenSulfate commented Nov 27, 2025

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

Pcard-75624

由于strided机制的引入,view_reshape反向不能简单复用前向view,而是需要插入一些转连续的操作,因此 revert #71086 的修改,并通过添加view_shape_double_grad来支持view的高阶微分计算 @Eddie-Wang1120

This pull request introduces support for the view_shape operation and its gradients (first and second order) throughout the PaddlePaddle codebase. The changes add the forward op, its backward (gradient), and double backward (second derivative) implementations, update relevant op lists and configuration files, and add corresponding test coverage. The most important changes are grouped below by theme.

Operator and Gradient Implementation:

  • Added the view_shape operator to the ops registry with its arguments, output, inference meta, kernel, and backward mapping in ops.yaml. (paddle/phi/ops/yaml/ops.yaml)
  • Implemented the view_shape_double_grad function template in C++ for the second-order gradient of the view_shape op. (paddle/fluid/prim/api/composite_backward/composite_double_backward_api.h)

Operator Registration and Compatibility:

  • Registered the view_shape op and its gradients (view_shape_grad, view_shape_double_grad) in the op compatibility YAML. (paddle/phi/ops/yaml/op_compat.yaml)
  • Added the view_shape_grad op to the VJP interface blacklist to prevent automatic VJP generation. (paddle/fluid/pir/dialect/op_generator/vjp_interface_black_list.py)

Backward and Double Backward Configuration:

  • Added YAML entries for both view_shape_grad (first-order gradient) and view_shape_double_grad (second-order gradient) in the backward op configuration, specifying their forward links, arguments, outputs, meta inference, and composite/implementation functions. (paddle/phi/ops/yaml/backward.yaml)
  • Removed the inconsistent/dygraph YAML entries for view_shape and its gradient, as they are now consistently defined. (paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml, paddle/phi/ops/yaml/inconsistent/dygraph_backward.yaml) [1] [2]

Code Generation and Testing:

  • Added view_shape_double_grad to the list of double grad ops in the eager code generator and cleaned up related code logic. (paddle/fluid/eager/auto_code_generator/generator/eager_gen.py) [1] [2]
  • Added a call to a new test case (call_view8) in the stride tests to ensure coverage for the new op. (test/legacy_test/test_stride.py)

@paddle-bot
Copy link

paddle-bot bot commented Nov 27, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@HydrogenSulfate HydrogenSulfate changed the title add view_shape_double_grad for eager mode [Comp] Add view_shape_double_grad for eager mode Nov 27, 2025
@HydrogenSulfate HydrogenSulfate changed the title [Comp] Add view_shape_double_grad for eager mode [Comp] Add view_shape_double_grad for eager mode Nov 28, 2025
@zhangting2020
Copy link
Contributor

approve for Distribute-stable-test

@HydrogenSulfate HydrogenSulfate merged commit 11e7dc0 into PaddlePaddle:develop Dec 2, 2025
268 of 294 checks passed
@HydrogenSulfate HydrogenSulfate deleted the add_view_shape_double_grad branch December 2, 2025 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants