-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[PIR] Throw error when OP has no grad OP #63914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SigureMo
merged 6 commits into
PaddlePaddle:develop
from
cattidea:pir/throw-error-when-op-has-no-grad-op
Apr 28, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1cfad65
[PIR] Throw error when OP has no grad OP
SigureMo db8b575
add ut
SigureMo d68135f
update error msg
SigureMo 5f6b38a
update allow list
SigureMo f7fa24a
update allow list
SigureMo 22d34ea
move constants to backward_utils.py
SigureMo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import unittest | ||
|
|
||
| from dygraph_to_static_utils import ( | ||
| Dy2StTestBase, | ||
| test_ast_only, | ||
| test_pir_only, | ||
| ) | ||
|
|
||
| import paddle | ||
|
|
||
|
|
||
| class HighOrderNet(paddle.nn.Layer): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.linear = paddle.nn.Linear(3, 4, bias_attr=False) | ||
|
|
||
| def forward(self, x): | ||
| y = self.linear(x) | ||
| z = paddle.pow(y, 2) | ||
| x_grad = paddle.grad(z, x, create_graph=True)[0] | ||
| x_grad_grad = paddle.grad(x_grad, x, create_graph=True)[0] | ||
| return x_grad_grad.mean() | ||
|
|
||
|
|
||
| class TestBackwardHasNoGradError(Dy2StTestBase): | ||
| @test_ast_only | ||
| @test_pir_only | ||
| def test_backward_has_no_grad_error(self): | ||
| net = HighOrderNet() | ||
| static_net = paddle.jit.to_static(net, full_graph=True) | ||
|
|
||
| x = paddle.to_tensor([[1, 1, 1], [1, 1, 1]], 'float32') | ||
| x.stop_gradient = False | ||
|
|
||
| with self.assertRaisesRegex( | ||
| ValueError, | ||
| "op 'pd_op.matmul_double_grad' has no grad op, consider enable prim to decompose it.", | ||
| ): | ||
| x_grad_grad = static_net(x) | ||
| x_grad_grad.backward() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个list 加到backward_utils.py里面吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯,移好了~