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

fix: torch frontend max pooling to support optional batch dim #28490

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
23 changes: 20 additions & 3 deletions ivy/functional/frontends/torch/nn/functional/pooling_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ def max_pool1d(
stride = kernel_size
if not isinstance(padding, int):
padding = [(pad, pad) for pad in padding]
return ivy.max_pool1d(
if input.ndim == 2:
without_batch_dim = True
input = ivy.expand_dims(input, axis=0)
else:
without_batch_dim = False

ret = ivy.max_pool1d(
input,
kernel_size,
stride,
Expand All @@ -246,6 +252,9 @@ def max_pool1d(
dilation=dilation,
ceil_mode=ceil_mode,
)
if without_batch_dim:
ret = ret[0]
return ret


@with_unsupported_dtypes({"2.2 and below": ("float16",)}, "torch")
Expand All @@ -263,7 +272,13 @@ def max_pool2d(
stride = kernel_size
if not isinstance(padding, int):
padding = [(pad, pad) for pad in padding]
return ivy.max_pool2d(
if input.ndim == 3:
without_batch_dim = True
input = ivy.expand_dims(input, axis=0)
else:
without_batch_dim = False

ret = ivy.max_pool2d(
input,
kernel_size,
stride,
Expand All @@ -272,6 +287,9 @@ def max_pool2d(
dilation=dilation,
ceil_mode=ceil_mode,
)
if without_batch_dim:
ret = ret[0]
return ret


@with_unsupported_dtypes({"2.2 and below": ("float16",)}, "torch")
Expand Down Expand Up @@ -306,5 +324,4 @@ def max_pool3d(
)
if without_batch_dim:
ret = ret[0]

return ret
Loading