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

[torchlib] Remove adaptive_avg_pool implementation #1751

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 1 addition & 52 deletions onnxscript/function_libs/torch_lib/ops/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,58 +40,7 @@
TFloatUnlessFloat32 = TypeVar("TFloatUnlessFloat32", bound=Union[BFLOAT16, FLOAT16, DOUBLE])


@torch_op("aten::adaptive_avg_pool1d", traceable=True)
def aten_adaptive_avg_pool1d(self: TFloat, output_size: INT64[1]) -> TFloat:
"""adaptive_avg_pool1d(Tensor self, int[1] output_size) -> Tensor"""

# assert output_size == [1]
# TODO(justinchuby): Specify input constraints

if Rank(self) == 2:
# Unbatched case
self = op.Unsqueeze(self, op.Constant(value_ints=[0]))
pooled = op.GlobalAveragePool(self)
result = op.Squeeze(pooled, op.Constant(value_ints=[0]))
else:
result = op.GlobalAveragePool(self)

return result


@torch_op("aten::adaptive_avg_pool2d", traceable=True)
def aten_adaptive_avg_pool2d(self: TFloat, output_size: INT64[2]) -> TFloat:
"""adaptive_avg_pool2d(Tensor self, SymInt[2] output_size) -> Tensor"""

# assert output_size == [1, 1]
# TODO(justinchuby): Specify input constraints

if Rank(self) == 3:
# Unbatched case
self = op.Unsqueeze(self, op.Constant(value_ints=[0]))
pooled = op.GlobalAveragePool(self)
result = op.Squeeze(pooled, op.Constant(value_ints=[0]))
else:
result = op.GlobalAveragePool(self)

return result


@torch_op("aten::adaptive_avg_pool3d", traceable=True)
def aten_adaptive_avg_pool3d(self: TFloat, output_size: INT64[3]) -> TFloat:
"""adaptive_avg_pool3d(Tensor self, SymInt[3] output_size) -> Tensor"""

# assert output_size == [1, 1, 1]
# TODO(justinchuby): Specify input constraints

if Rank(self) == 4:
# Unbatched case
self = op.Unsqueeze(self, op.Constant(value_ints=[0]))
pooled = op.GlobalAveragePool(self)
result = op.Squeeze(pooled, op.Constant(value_ints=[0]))
else:
result = op.GlobalAveragePool(self)

return result
# NOTE: Implementations of adaptive_average_pool are handled by torch decomp


def aten_adaptive_max_pool1d(
Expand Down
33 changes: 0 additions & 33 deletions tests/function_libs/torch_lib/ops_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,39 +1054,6 @@ def _where_input_wrangler(
"new_zeros",
core_ops.aten_new_zeros,
),
TorchLibOpInfo(
"nn.functional.adaptive_avg_pool1d",
nn_ops.aten_adaptive_avg_pool1d,
)
.xfail(
# Shape should be [N, C, D1]
matcher=lambda sample: sample.args[0] not in {1, (1,)},
reason="only global pooling is supported; only batched inputs are supported",
)
.xfail(
reason="ORT fails on a cast node it inserts for float16. https://github.com/microsoft/onnxruntime/issues/16449",
dtypes=(torch.float16,),
test_class_name="TestOutputConsistencyEager",
),
TorchLibOpInfo(
"nn.functional.adaptive_avg_pool2d",
nn_ops.aten_adaptive_avg_pool2d,
).xfail(
matcher=lambda sample: sample.args[0] != (1, 1),
reason="only global pooling is supported; only batched inputs are supported",
),
TorchLibOpInfo(
"nn.functional.adaptive_avg_pool3d",
nn_ops.aten_adaptive_avg_pool3d,
)
.xfail(
matcher=lambda sample: sample.args[0] != (1, 1, 1),
reason="only global pooling is supported; only batched inputs are supported",
)
.xfail(
dtypes=(torch.float16,),
reason="fixme: RuntimeError: ORT inference error GlobalAveragePool. https://github.com/microsoft/onnxruntime/issues/16449",
),
TorchLibOpInfo("nn.functional.celu", nn_ops.aten_celu),
TorchLibOpInfo("nn.functional.celu_type_promoted", nn_ops.aten_celu_type_promoted),
TorchLibOpInfo(
Expand Down
Loading