Skip to content
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

Paddlepaddle avg pool3d #22624

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
args:
- "--preview"
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.0
rev: v2.2.1
hooks:
- id: autoflake
- repo: https://github.com/pycqa/flake8
Expand Down
40 changes: 40 additions & 0 deletions ivy/functional/frontends/paddle/nn/functional/pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,46 @@ def avg_pool2d(
)


@to_ivy_arrays_and_back
@with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle")
def avg_pool3d(
x,
kernel_size,
stride=None,
padding=0,
ceil_mode=False,
exclusive=True,
divisor_override=None,
data_format="NDHWC",
name=None,
):
if stride is None:
stride = kernel_size

count_include_pad = not exclusive
kernel_size = _broadcast_pooling_helper(kernel_size, "3d", name="kernel_size")
padding = _broadcast_pooling_helper(padding, "3d", name="padding")

# Figure out padding string
if all(
[pad == ivy.ceil((kernel - 1) / 2) for kernel, pad in zip(kernel_size, padding)]
):
padding = "SAME"
else:
padding = "VALID"

return ivy.avg_pool3d(
x,
kernel_size,
stride,
padding,
data_format=data_format,
count_include_pad=count_include_pad,
ceil_mode=ceil_mode,
divisor_override=divisor_override,
)


@to_ivy_arrays_and_back
@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
def max_unpool1d(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,66 @@ def test_paddle_avg_pool2d(
)


# avg_pool3d
@handle_frontend_test(
fn_tree="paddle.nn.functional.pooling.avg_pool3d",
df_x_k_s_p=helpers.arrays_for_pooling(
min_dims=4,
max_dims=4,
min_side=2,
max_side=4,
),
exclusive=st.booleans(),
ceil_mode=st.booleans(),
data_format=st.sampled_from(["NDHWC", "NCDHW"]),
)
def test_paddle_avg_pool3d(
df_x_k_s_p,
exclusive,
ceil_mode,
data_format,
*,
test_flags,
backend_fw,
frontend,
fn_tree,
on_device,
):
input_df, x, kernel, stride, padding = df_x_k_s_p

if data_format == "NCDHW":
x[0] = x[0].reshape(
(x[0].shape[0], x[0].shape[4], x[0].shape[1], x[0].shape[2], x[0].shape[3])
)

if len(stride) == 1:
stride = (stride[0], stride[0], stride[0])

if padding == "SAME":
padding = test_pooling_functions.calculate_same_padding(
kernel, stride, x[0].shape[2:]
)
else:
padding = (0, 0, 0)

helpers.test_frontend_function(
input_dtypes=input_df,
test_flags=test_flags,
backend_to_test=backend_fw,
frontend=frontend,
fn_tree=fn_tree,
on_device=on_device,
x=x[0],
kernel_size=kernel,
stride=stride,
padding=padding,
ceil_mode=ceil_mode,
exclusive=exclusive,
divisor_override=None,
data_format=data_format,
)


# max_unpool1d
@handle_frontend_test(
fn_tree="paddle.nn.functional.max_unpool1d",
Expand Down
Loading