diff --git a/paddle/fluid/platform/device/ipu/popart_canonicalization/activation_ops.cc b/paddle/fluid/platform/device/ipu/popart_canonicalization/activation_ops.cc index 082bb17cac86b97890945e4d4edbbccf536cc6a1..c34cdfd036dcd1713412ee77bdc8325bd30fe036 100644 --- a/paddle/fluid/platform/device/ipu/popart_canonicalization/activation_ops.cc +++ b/paddle/fluid/platform/device/ipu/popart_canonicalization/activation_ops.cc @@ -138,6 +138,10 @@ Node *brelu_handler(Graph *graph, Node *node) { Node *gelu_handler(Graph *graph, Node *node) { auto *op = node->Op(); + // In case of the Op has no `approximate` attr. + if (!op->HasAttr("approximate")) { + return activation_op_handler(graph, node, "popart_gelu_v2"); + } auto approximate_ = PADDLE_GET_CONST(bool, op->GetAttr("approximate")); if (approximate_) { return activation_op_handler(graph, node, "popart_gelu_v2"); diff --git a/paddle/fluid/platform/device/ipu/popart_canonicalization/nn_ops.cc b/paddle/fluid/platform/device/ipu/popart_canonicalization/nn_ops.cc index a016647efc99749b7b3597174654e6666e10b67b..34ab79fb87d500a28dc7a5b83820aa986759ce7a 100644 --- a/paddle/fluid/platform/device/ipu/popart_canonicalization/nn_ops.cc +++ b/paddle/fluid/platform/device/ipu/popart_canonicalization/nn_ops.cc @@ -824,6 +824,14 @@ Node *pad_handler(Graph *graph, Node *node) { {{"mode", mode}}); } +Node *depthwise_conv2d_handler(Graph *graph, Node *node) { + return conv2d_handler(graph, node); +} + +Node *depthwise_conv2d_transpose_handler(Graph *graph, Node *node) { + return conv2d_transpose_handler(graph, node); +} + } // namespace } // namespace ipu } // namespace platform @@ -846,3 +854,6 @@ REGISTER_HANDLER(linear_interp_v2, linear_interp_v2_handler); REGISTER_HANDLER(trilinear_interp_v2, trilinear_interp_v2_handler); REGISTER_HANDLER(data_norm, data_norm_handler); REGISTER_HANDLER(pad3d, pad_handler); +REGISTER_HANDLER(depthwise_conv2d, depthwise_conv2d_handler); +REGISTER_HANDLER(depthwise_conv2d_transpose, + depthwise_conv2d_transpose_handler); diff --git a/python/paddle/fluid/tests/unittests/ipu/test_conv2d_transpose_op_ipu.py b/python/paddle/fluid/tests/unittests/ipu/test_conv2d_transpose_op_ipu.py index 6136bf34ffb671579934cb7447aff5e8958b5027..824b6b628defac6a53520aea06bcc68e0e55741f 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_conv2d_transpose_op_ipu.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_conv2d_transpose_op_ipu.py @@ -150,11 +150,43 @@ class TestCase10(TestBase): class TestCase11(TestBase): - # Depthwise conv2d transpose def set_op_attrs(self): super().set_op_attrs() self.attrs['groups'] = 3 +# depthwise_conv2d_transpose Op +class TestCase12(TestBase): + + def set_feed(self): + data = np.random.uniform(size=[1, 3, 10, 10]) + weight = np.random.uniform(size=[3, 1, 3, 3]) + self.feed_fp32 = { + 'in_0': data.astype(np.float32), + 'in_1': weight.astype(np.float32) + } + self.feed_fp16 = { + 'in_0': data.astype(np.float16), + 'in_1': weight.astype(np.float16) + } + self.feed_shape = [x.shape for x in self.feed_fp32.values()] + self.feed_list = list(self.feed_fp32.keys()) + + def set_op_attrs(self): + self.attrs = {} + self.attrs['groups'] = 3 + + @IPUOpTest.static_graph + def build_model(self): + x = paddle.static.data(name=self.feed_list[0], + shape=self.feed_shape[0], + dtype='float32') + weight = paddle.static.data(name=self.feed_list[1], + shape=self.feed_shape[1], + dtype='float32') + x = paddle.nn.functional.conv2d_transpose(x, weight, **self.attrs) + self.fetch_list = [x.name] + + if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ipu/test_conv_op_ipu.py b/python/paddle/fluid/tests/unittests/ipu/test_conv_op_ipu.py index 3fac45bbbd904869aca47086d31ca85b4bdf72a2..076d51a5e6713de33cadc637e786a7039341a4a9 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_conv_op_ipu.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_conv_op_ipu.py @@ -133,5 +133,38 @@ class TestCase8(TestBase): self.attrs['padding'] = [1, 2, 2, 3] +# depthwise_conv2d Op +class TestCase9(TestBase): + + def set_feed(self): + data = np.random.uniform(size=[1, 3, 10, 10]) + weight = np.random.uniform(size=[3, 1, 3, 3]) + self.feed_fp32 = { + 'in_0': data.astype(np.float32), + 'in_1': weight.astype(np.float32) + } + self.feed_fp16 = { + 'in_0': data.astype(np.float16), + 'in_1': weight.astype(np.float16) + } + self.feed_shape = [x.shape for x in self.feed_fp32.values()] + self.feed_list = list(self.feed_fp32.keys()) + + def set_op_attrs(self): + self.attrs = {} + self.attrs['groups'] = 3 + + @IPUOpTest.static_graph + def build_model(self): + x = paddle.static.data(name=self.feed_list[0], + shape=self.feed_shape[0], + dtype='float32') + weight = paddle.static.data(name=self.feed_list[1], + shape=self.feed_shape[1], + dtype='float32') + x = paddle.nn.functional.conv2d(x, weight, **self.attrs) + self.fetch_list = [x.name] + + if __name__ == "__main__": unittest.main()