-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add float16 support for pool 2d operator #9167
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
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -80,18 +80,19 @@ class TestPool2d_Op(OpTest): | |
| def setUp(self): | ||
| self.use_cudnn = False | ||
| self.use_mkldnn = False | ||
| self.dtype = np.float32 | ||
| self.init_test_case() | ||
| self.init_global_pool() | ||
| self.init_op_type() | ||
| self.init_pool_type() | ||
| self.init_ceil_mode() | ||
| if self.global_pool: | ||
| self.paddings = [0 for _ in range(len(self.paddings))] | ||
| input = np.random.random(self.shape).astype("float32") | ||
| input = np.random.random(self.shape).astype(self.dtype) | ||
| output = self.pool2D_forward_naive(input, self.ksize, self.strides, | ||
| self.paddings, self.global_pool, | ||
| self.ceil_mode).astype("float32") | ||
| self.inputs = {'X': input} | ||
| self.ceil_mode).astype(self.dtype) | ||
| self.inputs = {'X': OpTest.np_dtype_to_fluid_dtype(input)} | ||
|
|
||
| self.attrs = { | ||
| 'strides': self.strides, | ||
|
|
@@ -105,7 +106,7 @@ def setUp(self): | |
| 'data_format': 'AnyLayout' # TODO(dzhwinter) : should be fix latter | ||
| } | ||
|
|
||
| self.outputs = {'Out': output.astype('float32')} | ||
| self.outputs = {'Out': output} | ||
|
|
||
| def test_check_output(self): | ||
| if self.use_cudnn: | ||
|
|
@@ -115,6 +116,8 @@ def test_check_output(self): | |
| self.check_output() | ||
|
|
||
| def test_check_grad(self): | ||
| if self.dtype == np.float16: | ||
| return | ||
| if self.use_cudnn and self.pool_type != "max": | ||
| place = core.CUDAPlace(0) | ||
| self.check_grad_with_place( | ||
|
|
@@ -212,36 +215,114 @@ def init_op_type(self): | |
| self.op_type = "pool2d" | ||
|
|
||
|
|
||
| class TestFP16CUDNNCase1(TestPool2d_Op): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
|
||
| self.dtype = np.float16 | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| place = core.CUDAPlace(0) | ||
| if core.is_float16_supported(place): | ||
| self.check_output_with_place(place, atol=1e-3) | ||
|
|
||
|
|
||
| class TestCUDNNCase2(TestCase1): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
|
|
||
|
|
||
| class TestFP16CUDNNCase2(TestCase1): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
| self.dtype = np.float16 | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| place = core.CUDAPlace(0) | ||
| if core.is_float16_supported(place): | ||
| self.check_output_with_place(place, atol=1e-3) | ||
|
|
||
|
|
||
| class TestCUDNNCase3(TestCase2): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
|
|
||
|
|
||
| class TestFP16CUDNNCase3(TestCase2): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
| self.dtype = np.float16 | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| place = core.CUDAPlace(0) | ||
| if core.is_float16_supported(place): | ||
| self.check_output_with_place(place, atol=1e-3) | ||
|
|
||
|
|
||
| class TestCUDNNCase4(TestCase3): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
|
|
||
|
|
||
| class TestFP16CUDNNCase4(TestCase3): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
| self.dtype = np.float16 | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| place = core.CUDAPlace(0) | ||
| if core.is_float16_supported(place): | ||
| self.check_output_with_place(place, atol=1e-3) | ||
|
|
||
|
|
||
| class TestCUDNNCase5(TestCase4): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
|
|
||
|
|
||
| class TestFP16CUDNNCase5(TestCase4): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
| self.dtype = np.float16 | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| place = core.CUDAPlace(0) | ||
| if core.is_float16_supported(place): | ||
| self.check_output_with_place(place, atol=1e-3) | ||
|
|
||
|
|
||
| class TestCUDNNCase6(TestCase5): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
|
|
||
|
|
||
| class TestFP16CUDNNCase6(TestCase5): | ||
| def init_op_type(self): | ||
| self.use_cudnn = True | ||
| self.op_type = "pool2d" | ||
| self.dtype = np.float16 | ||
|
|
||
| def test_check_output(self): | ||
| if core.is_compiled_with_cuda(): | ||
| place = core.CUDAPlace(0) | ||
| if core.is_float16_supported(place): | ||
| self.check_output_with_place(place, atol=1e-3) | ||
|
|
||
|
|
||
| class TestCeilModeCase1(TestCUDNNCase1): | ||
| def init_ceil_mode(self): | ||
| self.ceil_mode = True | ||
|
|
||
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.
self.op_typeshould be placed insetUp, because the unit tests oftest_conv2d_op.pyis all aboutconv2dand the difference is justop_kernels.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.
Good point! Done.