From 7682478701f914d35913857d67a414246c7fd9df Mon Sep 17 00:00:00 2001 From: Haoyang Date: Mon, 24 Jul 2023 00:09:08 +0800 Subject: [PATCH 01/13] Fix an adaptive_max_pool1d operator conversion bug --- python/tvm/relay/frontend/pytorch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index eadd0a3c464f..b3bf6eae9c5a 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4291,7 +4291,7 @@ def _handel_nested_input(inputs): self.current_op.pop() - return [_wrap_const(outputs[ret_name]) for ret_name in ret_names] + return [_wrap_const(outputs[ret_name]) for ret_name in ret_names if outputs[ret_name] != None] def _set_parameter_source_name(self, op_node, outputs): """A helper function to rewrite source_name of parameter.""" From 101cd3a738e080836a510bbfa8e315faaf5b92ab Mon Sep 17 00:00:00 2001 From: Haoyang Date: Mon, 24 Jul 2023 11:57:08 +0800 Subject: [PATCH 02/13] Fix an adaptive_max_pool1d operator conversion bug --- python/tvm/relay/frontend/pytorch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index b3bf6eae9c5a..19231d2a078a 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4291,7 +4291,9 @@ def _handel_nested_input(inputs): self.current_op.pop() - return [_wrap_const(outputs[ret_name]) for ret_name in ret_names if outputs[ret_name] != None] + return [ + _wrap_const(outputs[ret_name]) for ret_name in ret_names if outputs[ret_name] != None + ] def _set_parameter_source_name(self, op_node, outputs): """A helper function to rewrite source_name of parameter.""" From d6ef77f8eea0ce9630f67d0224d06aa35f31c26f Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Mon, 24 Jul 2023 13:12:45 +0800 Subject: [PATCH 03/13] add tests for Fix an adaptive_max_pool1d operator conversion bug --- tests/python/frontend/pytorch/test_forward.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index cb49e837fe6e..075295868095 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -3439,6 +3439,15 @@ def forward(self, *args): verify_model(Full2().float().eval(), input_data=[]) +@tvm.testing.uses_gpu +def test_forward_adaptive_max_pool1d(): + """test_forward_adaptive_max_pool1d""" + torch.set_grad_enabled(False) + input_data=[torch.randn([2,2,4], dtype=torch.float32)] + m = torch.nn.AdaptiveMaxPool1d(3, return_indices=True) + + verify_model(m.float().eval(), input_date=input_data) + @tvm.testing.uses_gpu def test_forward_full_like(): """test_forward_full_like""" From d6cf54c9eee4fdb24ff8482ccb463b0e7231afa8 Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Mon, 24 Jul 2023 13:17:41 +0800 Subject: [PATCH 04/13] add tests for Fix an adaptive_max_pool1d operator conversion bug --- tests/python/frontend/pytorch/test_forward.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index 075295868095..9baee5c574d7 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -3448,6 +3448,7 @@ def test_forward_adaptive_max_pool1d(): verify_model(m.float().eval(), input_date=input_data) + @tvm.testing.uses_gpu def test_forward_full_like(): """test_forward_full_like""" From fa18f86cbad4f06b13bf732bef9131c549d8e15a Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Mon, 24 Jul 2023 13:43:28 +0800 Subject: [PATCH 05/13] add tests for Fix an adaptive_max_pool1d operator conversion bug --- tests/python/frontend/pytorch/test_forward.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index 9baee5c574d7..3ca44a5241f1 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -3443,7 +3443,7 @@ def forward(self, *args): def test_forward_adaptive_max_pool1d(): """test_forward_adaptive_max_pool1d""" torch.set_grad_enabled(False) - input_data=[torch.randn([2,2,4], dtype=torch.float32)] + input_data = [torch.randn([2, 2, 4], dtype=torch.float32)] m = torch.nn.AdaptiveMaxPool1d(3, return_indices=True) verify_model(m.float().eval(), input_date=input_data) From 66a99a99757e7ec82ba51aa1967ac3f163adda69 Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Mon, 24 Jul 2023 14:49:57 +0800 Subject: [PATCH 06/13] add tests for Fix an adaptive_max_pool1d operator conversion bug --- python/tvm/relay/frontend/pytorch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 19231d2a078a..6836942651aa 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4292,7 +4292,7 @@ def _handel_nested_input(inputs): self.current_op.pop() return [ - _wrap_const(outputs[ret_name]) for ret_name in ret_names if outputs[ret_name] != None + _wrap_const(outputs[ret_name]) for ret_name in ret_names if outputs[ret_name] is not None ] def _set_parameter_source_name(self, op_node, outputs): From 92a9eb191a369cb278be919b6045f342d086618f Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Mon, 24 Jul 2023 15:50:02 +0800 Subject: [PATCH 07/13] add tests for Fix an adaptive_max_pool1d operator conversion bug --- python/tvm/relay/frontend/pytorch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 6836942651aa..73c30960b9f9 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4292,7 +4292,9 @@ def _handel_nested_input(inputs): self.current_op.pop() return [ - _wrap_const(outputs[ret_name]) for ret_name in ret_names if outputs[ret_name] is not None + _wrap_const(outputs[ret_name]) + for ret_name in ret_names + if outputs[ret_name] is not None ] def _set_parameter_source_name(self, op_node, outputs): From 3d33e2266c3fc8d259702a90c019d7d532a658fa Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Mon, 24 Jul 2023 19:15:18 +0800 Subject: [PATCH 08/13] add tests for Fix an adaptive_max_pool1d operator conversion bug --- tests/python/frontend/pytorch/test_forward.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index 3ca44a5241f1..7a5d0f4d9b09 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -3446,7 +3446,7 @@ def test_forward_adaptive_max_pool1d(): input_data = [torch.randn([2, 2, 4], dtype=torch.float32)] m = torch.nn.AdaptiveMaxPool1d(3, return_indices=True) - verify_model(m.float().eval(), input_date=input_data) + verify_model(m.float().eval(), input_data=input_data) @tvm.testing.uses_gpu From c479f83ccd8360944abc5e874ff6818260ea6845 Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Fri, 1 Sep 2023 20:44:08 +0800 Subject: [PATCH 09/13] Fix an adaptive_max_pool1d operator conversion bug --- python/tvm/relay/frontend/pytorch.py | 4 ++-- tests/python/frontend/pytorch/test_forward.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index c34676b9d6d7..54af18e8ebc8 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4290,11 +4290,11 @@ def _handel_nested_input(inputs): outputs[node_name] = relay_out self.current_op.pop() - + return [ _wrap_const(outputs[ret_name]) for ret_name in ret_names - if outputs[ret_name] is not None + if ret_name != 'aten::adaptive_max_pool1d_0_1' ] def _set_parameter_source_name(self, op_node, outputs): diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index 7a5d0f4d9b09..8c1cdbb0cf0b 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -3444,7 +3444,7 @@ def test_forward_adaptive_max_pool1d(): """test_forward_adaptive_max_pool1d""" torch.set_grad_enabled(False) input_data = [torch.randn([2, 2, 4], dtype=torch.float32)] - m = torch.nn.AdaptiveMaxPool1d(3, return_indices=True) + m = torch.nn.AdaptiveMaxPool1d(3) verify_model(m.float().eval(), input_data=input_data) From 37f5a83590e6ec9d5d6e477c56577329d09be0ca Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Fri, 1 Sep 2023 23:44:07 +0800 Subject: [PATCH 10/13] Fix an adaptive_max_pool1d operator conversion bug --- python/tvm/relay/frontend/pytorch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 54af18e8ebc8..7062921560f4 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4290,11 +4290,11 @@ def _handel_nested_input(inputs): outputs[node_name] = relay_out self.current_op.pop() - + return [ _wrap_const(outputs[ret_name]) for ret_name in ret_names - if ret_name != 'aten::adaptive_max_pool1d_0_1' + if ret_name != "aten::adaptive_max_pool1d_0_1" ] def _set_parameter_source_name(self, op_node, outputs): From 8ae112c37ead4db6287037c5e3fd0543558febf2 Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Sun, 3 Sep 2023 15:14:39 +0800 Subject: [PATCH 11/13] Add a TODO --- python/tvm/relay/frontend/pytorch.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 7062921560f4..e10f1a71f26a 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4291,6 +4291,10 @@ def _handel_nested_input(inputs): self.current_op.pop() + # TODO(@haoyang9804): outputs[ret_name] could be None and cause some issue + # revealed by https://github.com/apache/tvm/issues/15004 + # Now only adaptive_max_pool1d is considered. Maybe other ops could also + # trigger this problem. return [ _wrap_const(outputs[ret_name]) for ret_name in ret_names From ab35b6584d13aef39ca2c3499573802caefda3b5 Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Sun, 3 Sep 2023 16:55:24 +0800 Subject: [PATCH 12/13] Add a TODO --- python/tvm/relay/frontend/pytorch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index e10f1a71f26a..dd16b2081479 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4291,8 +4291,10 @@ def _handel_nested_input(inputs): self.current_op.pop() + # TODO(@haoyang9804): outputs[ret_name] could be None and cause some issue # revealed by https://github.com/apache/tvm/issues/15004 + # Now only adaptive_max_pool1d is considered. Maybe other ops could also # trigger this problem. return [ From 12d1d785762f4e79b6b9f8bdf4b6759ce9886448 Mon Sep 17 00:00:00 2001 From: haoyang9804 Date: Sun, 3 Sep 2023 19:34:37 +0800 Subject: [PATCH 13/13] Add a TODO --- python/tvm/relay/frontend/pytorch.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index dd16b2081479..683b94dd9290 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -4291,11 +4291,9 @@ def _handel_nested_input(inputs): self.current_op.pop() - - # TODO(@haoyang9804): outputs[ret_name] could be None and cause some issue + # TODO(@haoyang9804): outputs[ret_name] could be None and cause some issue # revealed by https://github.com/apache/tvm/issues/15004 - - # Now only adaptive_max_pool1d is considered. Maybe other ops could also + # Now only adaptive_max_pool1d is considered. Maybe other ops could also # trigger this problem. return [ _wrap_const(outputs[ret_name])