From 68f925a7d2fe36370e7b3948a9bb74c380c79e15 Mon Sep 17 00:00:00 2001 From: Ramya Date: Fri, 19 May 2023 23:19:25 +0530 Subject: [PATCH 1/6] added conv2d backend --- ivy/functional/backends/paddle/layers.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ivy/functional/backends/paddle/layers.py b/ivy/functional/backends/paddle/layers.py index 029c4df9d5716..b5e84912dbe32 100644 --- a/ivy/functional/backends/paddle/layers.py +++ b/ivy/functional/backends/paddle/layers.py @@ -118,8 +118,24 @@ def conv2d( data_format: str = "NHWC", dilations: Union[int, Tuple[int, int]] = 1, out: Optional[paddle.Tensor] = None, -) -> paddle.Tensor: - raise IvyNotImplementedException() +): + if data_format == "NCHW": + x = paddle.transpose(x, perm=(0, 2, 3, 1)) + df = "NHWC" + x = _pad_before_conv(x, filters, strides, padding, 2, dilations, df) + filters = paddle.transpose(filters, perm=(3, 2, 0, 1)) + padding = "VALID" + res = paddle.nn.functional.conv2d( + x, + filters, + data_format=df, + stride=strides, + padding=padding, + dilation=dilations, + ) + if data_format == "NCHW": + res = paddle.transpose(res, perm=(0, 3, 1, 2)) + return res # noinspection PyUnresolvedReferences From d3d9938aad89bbb16c0e15294129184e0133d342 Mon Sep 17 00:00:00 2001 From: Ramya Date: Thu, 25 May 2023 13:18:16 +0530 Subject: [PATCH 2/6] dataformat changed to NCHW --- ivy/functional/backends/paddle/layers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ivy/functional/backends/paddle/layers.py b/ivy/functional/backends/paddle/layers.py index b5e84912dbe32..bed37a5928a83 100644 --- a/ivy/functional/backends/paddle/layers.py +++ b/ivy/functional/backends/paddle/layers.py @@ -115,13 +115,13 @@ def conv2d( padding: Union[str, int, Sequence[Tuple[int, int]]], /, *, - data_format: str = "NHWC", + data_format: str = "NCHW", dilations: Union[int, Tuple[int, int]] = 1, out: Optional[paddle.Tensor] = None, ): - if data_format == "NCHW": - x = paddle.transpose(x, perm=(0, 2, 3, 1)) - df = "NHWC" + df = "NCHW" + if data_format == "NHWC": + df = "NHWC" x = _pad_before_conv(x, filters, strides, padding, 2, dilations, df) filters = paddle.transpose(filters, perm=(3, 2, 0, 1)) padding = "VALID" @@ -133,7 +133,7 @@ def conv2d( padding=padding, dilation=dilations, ) - if data_format == "NCHW": + if data_format == "NHWC": res = paddle.transpose(res, perm=(0, 3, 1, 2)) return res From 0c3005a585afd901a02ac990ebabfb8469b46b9e Mon Sep 17 00:00:00 2001 From: Ramya Date: Thu, 25 May 2023 13:33:20 +0530 Subject: [PATCH 3/6] removed the final axis swap --- ivy/functional/backends/paddle/layers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ivy/functional/backends/paddle/layers.py b/ivy/functional/backends/paddle/layers.py index bed37a5928a83..811b2295f4934 100644 --- a/ivy/functional/backends/paddle/layers.py +++ b/ivy/functional/backends/paddle/layers.py @@ -133,8 +133,6 @@ def conv2d( padding=padding, dilation=dilations, ) - if data_format == "NHWC": - res = paddle.transpose(res, perm=(0, 3, 1, 2)) return res From f5dd058457f12983f0eed214ed6533ebe8def2ea Mon Sep 17 00:00:00 2001 From: Ramya Date: Thu, 25 May 2023 14:04:34 +0530 Subject: [PATCH 4/6] dataformat nhwc --- ivy/functional/backends/paddle/layers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ivy/functional/backends/paddle/layers.py b/ivy/functional/backends/paddle/layers.py index 811b2295f4934..debf63223d008 100644 --- a/ivy/functional/backends/paddle/layers.py +++ b/ivy/functional/backends/paddle/layers.py @@ -115,13 +115,13 @@ def conv2d( padding: Union[str, int, Sequence[Tuple[int, int]]], /, *, - data_format: str = "NCHW", + data_format: str = "NHWC", dilations: Union[int, Tuple[int, int]] = 1, out: Optional[paddle.Tensor] = None, ): - df = "NCHW" - if data_format == "NHWC": - df = "NHWC" + df = "NHWC" + if data_format == "NCHW": + df = "NCHW" x = _pad_before_conv(x, filters, strides, padding, 2, dilations, df) filters = paddle.transpose(filters, perm=(3, 2, 0, 1)) padding = "VALID" From b99a6e6d4ecb6dc071cb000e536af300d2c12042 Mon Sep 17 00:00:00 2001 From: Ramya Date: Thu, 25 May 2023 18:35:27 +0530 Subject: [PATCH 5/6] changed df to dataformat --- ivy/functional/backends/paddle/layers.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ivy/functional/backends/paddle/layers.py b/ivy/functional/backends/paddle/layers.py index debf63223d008..2d59bd7e5be95 100644 --- a/ivy/functional/backends/paddle/layers.py +++ b/ivy/functional/backends/paddle/layers.py @@ -119,16 +119,13 @@ def conv2d( dilations: Union[int, Tuple[int, int]] = 1, out: Optional[paddle.Tensor] = None, ): - df = "NHWC" - if data_format == "NCHW": - df = "NCHW" - x = _pad_before_conv(x, filters, strides, padding, 2, dilations, df) + x = _pad_before_conv(x, filters, strides, padding, 2, dilations, data_format) filters = paddle.transpose(filters, perm=(3, 2, 0, 1)) padding = "VALID" res = paddle.nn.functional.conv2d( x, filters, - data_format=df, + data_format=data_format, stride=strides, padding=padding, dilation=dilations, From 5bca1cba580db643cb4a1a86a338e24d1b5fb9fe Mon Sep 17 00:00:00 2001 From: Ramya Date: Thu, 25 May 2023 18:50:44 +0530 Subject: [PATCH 6/6] support for unsupported datatype --- ivy/functional/backends/paddle/layers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ivy/functional/backends/paddle/layers.py b/ivy/functional/backends/paddle/layers.py index 2d59bd7e5be95..e74aeb9687faf 100644 --- a/ivy/functional/backends/paddle/layers.py +++ b/ivy/functional/backends/paddle/layers.py @@ -108,6 +108,7 @@ def conv1d_transpose( # noinspection PyUnresolvedReferences +# @with_unsupported_dtypes({"2.4.2 and below": ("float16",)}, backend_version) def conv2d( x: paddle.Tensor, filters: paddle.Tensor,