-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
【Inplace api】Add copy for inplace #54683
Merged
jeff41404
merged 11 commits into
PaddlePaddle:develop
from
GGBond8488:add_clone_for_inplace_input
Jun 28, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
03aeb98
add clone for inpalce
GGBond8488 83155b5
fix name
GGBond8488 4cf782a
add inplace pow
GGBond8488 915f711
fix typro
GGBond8488 63e7c08
add note
GGBond8488 b3e23c0
fix typro
GGBond8488 3510e07
fix typro
GGBond8488 46eb460
fix bug
GGBond8488 7378b79
fix test error
GGBond8488 6ac3f04
add type error test
GGBond8488 ed31049
adjust indentation
GGBond8488 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 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 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 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 |
---|---|---|
|
@@ -1762,6 +1762,7 @@ | |
kernel : | ||
func : pow | ||
data_type : x | ||
inplace: (x -> out) | ||
backward : pow_grad | ||
|
||
- op : prelu | ||
|
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import unittest | ||
|
||
import numpy as np | ||
from test_inplace import TestDygraphInplace | ||
|
||
import paddle | ||
from paddle.fluid import core | ||
|
@@ -213,5 +214,40 @@ def test_errors(self): | |
self.assertRaises(TypeError, paddle.pow, x, str(y)) | ||
|
||
|
||
class TestInplacePowerScalar(TestDygraphInplace): | ||
def set_np_compare_func(self): | ||
self.np_compare = np.allclose | ||
|
||
def inplace_api_processing(self, var): | ||
return paddle.pow_(var, 2) | ||
|
||
def non_inplace_api_processing(self, var): | ||
return paddle.pow(var, 2) | ||
|
||
|
||
class TestInplacePowerTensor(TestDygraphInplace): | ||
def init_data(self): | ||
self.input_var_numpy = np.random.uniform(-5, 5, [10, 20, 1]) | ||
self.dtype = "float32" | ||
self.y = paddle.ones([10, 20, 1], dtype="float32") * 2 | ||
|
||
def set_np_compare_func(self): | ||
self.np_compare = np.allclose | ||
|
||
def inplace_api_processing(self, var): | ||
return paddle.pow_(var, self.y) | ||
|
||
def non_inplace_api_processing(self, var): | ||
return paddle.pow(var, self.y) | ||
|
||
def test_type_error(self): | ||
var = paddle.to_tensor(self.input_var_numpy, dtype=self.dtype) | ||
with self.assertRaisesRegex( | ||
TypeError, | ||
'y must be scalar or tensor type, but received: %s ' % (type([2])), | ||
): | ||
paddle.pow_(var, [2]) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we check gradients of inplace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TestInplacePowerScalar(Tensor) inherit from TestDygraphInplace, which contains the backward test |
||
|
||
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.
好像这个标签不正确,导致没有正确引用。试试改成
api_paddle_pow
,或者在api_label 中加入该标签