From 9e527d9956313795f9e15e9d0f5b9bd1830acdf8 Mon Sep 17 00:00:00 2001 From: Jacek Czaja Date: Sat, 6 Feb 2021 13:44:15 +0100 Subject: [PATCH] [oneDNN] Added basic changes for elementwise_add_grad bf16 (#30925) --- .../mkldnn/elementwise_add_mkldnn_op.cc | 1 + .../test_elementwise_add_bf16_mkldnn_op.py | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/operators/elementwise/mkldnn/elementwise_add_mkldnn_op.cc b/paddle/fluid/operators/elementwise/mkldnn/elementwise_add_mkldnn_op.cc index 0ecb6266e4..13acd3fa63 100644 --- a/paddle/fluid/operators/elementwise/mkldnn/elementwise_add_mkldnn_op.cc +++ b/paddle/fluid/operators/elementwise/mkldnn/elementwise_add_mkldnn_op.cc @@ -90,4 +90,5 @@ REGISTER_OP_KERNEL( ops::EltwiseMKLDNNKernel) REGISTER_OP_KERNEL(elementwise_add_grad, MKLDNN, ::paddle::platform::CPUPlace, + ops::EltwiseAddMKLDNNGradKernel, ops::EltwiseAddMKLDNNGradKernel) diff --git a/python/paddle/fluid/tests/unittests/mkldnn/test_elementwise_add_bf16_mkldnn_op.py b/python/paddle/fluid/tests/unittests/mkldnn/test_elementwise_add_bf16_mkldnn_op.py index 7e4a117238..ac235e0075 100644 --- a/python/paddle/fluid/tests/unittests/mkldnn/test_elementwise_add_bf16_mkldnn_op.py +++ b/python/paddle/fluid/tests/unittests/mkldnn/test_elementwise_add_bf16_mkldnn_op.py @@ -30,10 +30,10 @@ class TestElementwiseAddBf16MklDNNOp(OpTest): self.axis = -1 self.generate_data() - self.inputs = { - 'X': convert_float_to_uint16(self.x), - 'Y': convert_float_to_uint16(self.y) - } + self.x_bf16 = convert_float_to_uint16(self.x) + self.y_bf16 = convert_float_to_uint16(self.y) + + self.inputs = {'X': self.x_bf16, 'Y': self.y_bf16} self.attrs = {'axis': self.axis, 'use_mkldnn': self.use_mkldnn} self.outputs = {'Out': convert_float_to_uint16(self.out)} @@ -45,14 +45,30 @@ class TestElementwiseAddBf16MklDNNOp(OpTest): def test_check_output(self): self.check_output_with_place(core.CPUPlace()) + # elementwise_add grad is just passing upper gradients to either X or Y or both def test_check_grad_normal(self): - pass + self.check_grad_with_place( + core.CPUPlace(), ["X", "Y"], + "Out", + check_dygraph=False, + user_defined_grads=[self.x_bf16, self.x_bf16], + user_defined_grad_outputs=[self.x_bf16]) def test_check_grad_ingore_x(self): - pass + self.check_grad_with_place( + core.CPUPlace(), ["Y"], + "Out", + check_dygraph=False, + user_defined_grads=[self.y_bf16], + user_defined_grad_outputs=[self.y_bf16]) def test_check_grad_ingore_y(self): - pass + self.check_grad_with_place( + core.CPUPlace(), ["X"], + "Out", + check_dygraph=False, + user_defined_grads=[self.x_bf16], + user_defined_grad_outputs=[self.x_bf16]) if __name__ == '__main__': -- GitLab