-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[CodeStyle][F821] fix test_exception in test_unpool3d_op and test_unpool_op #47756
Merged
luotao1
merged 10 commits into
PaddlePaddle:develop
from
cattidea:F821/fix/unpool-op-ut
Nov 10, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
37d6139
[Fix][F821] fix TestUnpoolOpException
SigureMo e9b22b4
fix TestUnpoolOpException
SigureMo 560f16a
fix TestUnpool3DOpException
SigureMo e267a95
remove unused variables
SigureMo 8a26069
fix the regexp does not match the C++ traceback
SigureMo 17ef7a1
add missing error message for gpu unpool_kernel
SigureMo 18a2a63
Revert "add missing error message for gpu unpool_kernel"
SigureMo 91bdf1c
assertion indices_value_error errors are only reported on the CPU
SigureMo 1b0269c
for test
SigureMo e484904
run test_exception in dygraph mode
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 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from op_test import OpTest | ||
import paddle | ||
import paddle.nn.functional as F | ||
from paddle.fluid import core | ||
|
||
paddle.enable_static() | ||
paddle.seed(2022) | ||
|
@@ -178,36 +179,42 @@ def init_test_case(self): | |
|
||
|
||
class TestUnpool3DOpException(unittest.TestCase): | ||
def setUp(self): | ||
paddle.disable_static() | ||
|
||
def tearDown(self): | ||
paddle.enable_static() | ||
|
||
def test_exception(self): | ||
def indices_size_error(): | ||
data = paddle.randint(shape=[1, 1, 3, 3, 3]) | ||
data = paddle.rand(shape=[1, 1, 3, 3, 3]) | ||
indices = paddle.reshape( | ||
paddle.arange(0, 36), shape=[1, 1, 3, 3, 4] | ||
) | ||
MaxUnPool3D = F.maxunpool3d(data, indices, kernel_size=2, stride=2) | ||
).astype("int32") | ||
F.max_unpool3d(data, indices, kernel_size=2, stride=2) | ||
|
||
def indices_value_error(): | ||
data = paddle.randint(shape=[1, 1, 3, 3, 3]) | ||
data = paddle.rand(shape=[1, 1, 3, 3, 3]) | ||
indices = paddle.reshape( | ||
paddle.arange(4, 40), shape=[1, 1, 3, 3, 3] | ||
) | ||
MaxUnPool3D = F.maxunpool3d(data, indices, kernel_size=2, stride=2) | ||
paddle.arange(195, 222), shape=[1, 1, 3, 3, 3] | ||
).astype("int32") | ||
F.max_unpool3d(data, indices, kernel_size=2, stride=2) | ||
|
||
def data_format_error(): | ||
data = paddle.randint(shape=[1, 1, 3, 3, 3]) | ||
data = paddle.rand(shape=[1, 1, 3, 3, 3]) | ||
indices = paddle.reshape( | ||
paddle.arange(0, 27), shape=[1, 1, 3, 3, 3] | ||
) | ||
MaxUnPool3D = F.maxunpool3d( | ||
).astype("int32") | ||
F.max_unpool3d( | ||
data, indices, kernel_size=2, stride=2, data_format="NDHWC" | ||
) | ||
|
||
def data_outputsize_error(): | ||
data = paddle.randint(shape=[1, 1, 3, 3, 3]) | ||
data = paddle.rand(shape=[1, 1, 3, 3, 3]) | ||
indices = paddle.reshape( | ||
paddle.arange(0, 27), shape=[1, 1, 3, 3, 3] | ||
) | ||
MaxUnPool3D = F.maxunpool3d( | ||
).astype("int32") | ||
F.max_unpool3d( | ||
data, | ||
indices, | ||
kernel_size=2, | ||
|
@@ -216,19 +223,36 @@ def data_outputsize_error(): | |
) | ||
|
||
def data_outputsize_error2(): | ||
data = paddle.randint(shape=[1, 1, 3, 3, 3]) | ||
data = paddle.rand(shape=[1, 1, 3, 3, 3]) | ||
indices = paddle.reshape( | ||
paddle.arange(0, 27), shape=[1, 1, 3, 3, 3] | ||
) | ||
MaxUnPool3D = F.maxunpool3d( | ||
F.max_unpool3d( | ||
data, indices, kernel_size=2, stride=2, output_size=[10, 10, 10] | ||
) | ||
|
||
self.assertRaises(ValueError, indices_size_error) | ||
self.assertRaises(ValueError, indices_value_error) | ||
self.assertRaises(ValueError, data_format_error) | ||
self.assertRaises(ValueError, data_outputsize_error) | ||
self.assertRaises(ValueError, data_outputsize_error2) | ||
self.assertRaisesRegex( | ||
ValueError, | ||
r"The dimensions of Input\(X\) must equal to", | ||
indices_size_error, | ||
) | ||
if not core.is_compiled_with_cuda(): | ||
self.assertRaisesRegex( | ||
ValueError, | ||
r"index should less than output", | ||
indices_value_error, | ||
) | ||
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. GPU 是没有这个报错的,因此这里仅在 CPU assert |
||
self.assertRaisesRegex( | ||
ValueError, | ||
r"Attr\(data_format\) should be 'NCDHW'", | ||
data_format_error, | ||
) | ||
self.assertRaisesRegex( | ||
ValueError, r"invalid output_size", data_outputsize_error | ||
) | ||
self.assertRaisesRegex( | ||
ValueError, r"invalid output_size", data_outputsize_error2 | ||
) | ||
|
||
|
||
class TestUnpool3DOpAPI_dygraph(unittest.TestCase): | ||
|
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
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.
test_exception 使用动态图进行测试