[Bug Fix] Fix view grad when out_grad is not contiguous#76679
Merged
Eddie-Wang1120 merged 4 commits intoPaddlePaddle:developfrom Dec 3, 2025
Merged
[Bug Fix] Fix view grad when out_grad is not contiguous#76679Eddie-Wang1120 merged 4 commits intoPaddlePaddle:developfrom
Eddie-Wang1120 merged 4 commits intoPaddlePaddle:developfrom
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Eddie-Wang1120
previously approved these changes
Nov 28, 2025
Contributor
Author
|
/re-run all-failed |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #76679 +/- ##
===========================================
Coverage ? 100.00%
===========================================
Files ? 1
Lines ? 20
Branches ? 0
===========================================
Hits ? 20
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add `no_need_buffer: input` to the view_shape_grad backward operator configuration. This indicates that the gradient computation for view_shape does not require the input tensor buffer, optimizing memory usage during backward passes.
a3527b5
Add a new test case `TestViewGrad.test_dygraph` to verify gradient correctness when using `view` followed by `transpose` in dynamic graph mode. The test ensures that the computed gradients match expected values, improving coverage for tensor manipulation operations.
Contributor
Author
|
/re-run all-failed |
2 similar comments
Contributor
Author
|
/re-run all-failed |
Contributor
Author
|
/re-run all-failed |
Eddie-Wang1120
approved these changes
Dec 3, 2025
zyfncg
approved these changes
Dec 3, 2025
Contributor
Author
|
/re-run approval |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
User Experience
PR Types
Bug fixes
Description
修改 view_shape_grad,当 out_grad 不能原地 view 为目标 shape 时,创建一份副本再 reshape
This pull request updates the
ViewShapeGradKernelimplementation inview_grad_kernel.ccto improve how gradients are handled for tensors with strided memory layouts. The main change is replacing the previous kernel call with logic that attempts to reshape the stride directly, and if that's not possible, falls back to making the tensor contiguous. This enhances support for strided tensors in gradient computations.Improvements to strided tensor gradient handling:
ViewShapeStridedKernelwith logic that first tries to reshape the tensor's stride usingReshapeStride. If successful, it sets the metadata, shape, stride, offset, holder, and version counter directly fromout_gradtoinput_grad. If not, it creates a contiguous copy of the tensor usingStridedTensorContiguous, ensuring correct gradient computation for non-contiguous tensors.Dependency and utility updates:
strided_reshape_utils.handstrided_utils.hto support the new stride handling logic.