From 5177f8de2b9a53b4dec05d4ec00b00d1fe8f76ec Mon Sep 17 00:00:00 2001 From: Dmytro Dzhulgakov Date: Mon, 5 Oct 2020 15:07:16 -0700 Subject: [PATCH] Revert D23398534: [pytorch][PR] [ONNX] Improve error handling for adaptive_pool Test Plan: revert-hammer Differential Revision: D23398534 (https://github.com/pytorch/pytorch/commit/45ddeb5ce6d0a7e2a719fac3d7e32a3643b46379) Original commit changeset: f2d60d40340f fbshipit-source-id: acc9d6c3d031662c37447fcee027b0c97b8492a7 --- test/onnx/test_pytorch_onnx_onnxruntime.py | 9 +-------- torch/onnx/symbolic_opset9.py | 10 ++-------- torch/onnx/utils.py | 3 ++- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/test/onnx/test_pytorch_onnx_onnxruntime.py b/test/onnx/test_pytorch_onnx_onnxruntime.py index 77577f687de..23d4879a8a4 100644 --- a/test/onnx/test_pytorch_onnx_onnxruntime.py +++ b/test/onnx/test_pytorch_onnx_onnxruntime.py @@ -1667,14 +1667,7 @@ class TestONNXRuntime(unittest.TestCase): y = torch.randn(16, 16, requires_grad=True) self.run_test(MyModel(), (x, y)) - def test_interpolate_adaptive_pooling_error(self): - x = torch.randn(1, 2, 6, requires_grad=True) - with self.assertRaises(RuntimeError) as cm: - self._interpolate(x, "area", True, True) - - with self.assertRaises(RuntimeError) as cm: - self._interpolate(x, "area", False, True) - + @disableScriptTest() def test_groupnorm(self): model = torch.nn.GroupNorm(3, 6, 0.002) x = torch.randn(4, 6, 180, 180, 180) diff --git a/torch/onnx/symbolic_opset9.py b/torch/onnx/symbolic_opset9.py index e11e52bad50..7e8b04bf161 100644 --- a/torch/onnx/symbolic_opset9.py +++ b/torch/onnx/symbolic_opset9.py @@ -826,6 +826,7 @@ avg_pool3d = _avg_pool('avg_pool3d', _triple) def _adaptive_pool(name, type, tuple_fn, fn=None): + @parse_args('v', 'is') def symbolic_fn(g, input, output_size): # _adaptive_pool is supported for cases where output_size is 1 for all dimensions, # by executing a GlobalPool. @@ -836,10 +837,6 @@ def _adaptive_pool(name, type, tuple_fn, fn=None): # so we try using max_poolxd_with_indices, and if it is not possible # (input is not a complete tensor or output size not factor of input size) # then we call GlobalAveragePool and return None for the indices - try: - output_size = _parse_arg(output_size, 'is') - except Exception: - return sym_help._onnx_unsupported('adaptive pooling, since output_size is not constant.') if output_size == [1] * len(output_size) and type == "AveragePool": return g.op("GlobalAveragePool", input) if not input.isCompleteTensor(): @@ -852,10 +849,7 @@ def _adaptive_pool(name, type, tuple_fn, fn=None): if mod != [0] * len(mod): if output_size == [1] * len(output_size): return g.op("GlobalMaxPool", input), None - if sym_help._operator_export_type == torch.onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK: - return _unimplemented(name, 'output size that are not factor of input size') - else: - return sym_help._onnx_unsupported(name, ', since output size is not factor of input size') + return _unimplemented(name, 'output size that are not factor of input size') k = [int(dim[i] / output_size[i]) for i in range(0, len(dim))] # call max_poolxd_with_indices to get indices in the output if type == "MaxPool": diff --git a/torch/onnx/utils.py b/torch/onnx/utils.py index 587e6d5b75c..98dc79d6546 100644 --- a/torch/onnx/utils.py +++ b/torch/onnx/utils.py @@ -1003,7 +1003,8 @@ def _run_symbolic_function(g, n, inputs, env, operator_export_type=OperatorExpor else: raise RuntimeError("ONNX export failed on an operator with unrecognized namespace {}::{}. " "If you are trying to export a custom operator, make sure you registered " - "it with the right domain and version.".format(ns, op_name)) + "it with the right domain and version. " + "Otherwise, please report a bug.".format(ns, op_name)) except RuntimeError: if operator_export_type == OperatorExportTypes.ONNX_FALLTHROUGH: return None