This is an automated email from the ASF dual-hosted git repository.

masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 80079b6493 Fix type parse error about AdaptiveMaxPool (#15016)
80079b6493 is described below

commit 80079b64933f05975f54bd2f55c79496f18a4406
Author: Qingchao Shen <[email protected]>
AuthorDate: Sun Jun 4 19:45:01 2023 +0800

    Fix type parse error about AdaptiveMaxPool (#15016)
    
    * fix type parse error about max_pool
    
    Fix the bug when the output_size=(3, None).
    Crash message: Check failed: (!checked_type.defined()) is false: Expected 
Array[PrimExpr], but got Array[index 1: relay.Constant]
    
    * add new test case to caputure bug in adaptive_max_pool
---
 python/tvm/relay/frontend/pytorch.py          | 4 ++++
 tests/python/frontend/pytorch/test_forward.py | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/python/tvm/relay/frontend/pytorch.py 
b/python/tvm/relay/frontend/pytorch.py
index 5eada41753..5e4d755996 100644
--- a/python/tvm/relay/frontend/pytorch.py
+++ b/python/tvm/relay/frontend/pytorch.py
@@ -1124,6 +1124,10 @@ class PyTorchOpConverter:
     def adaptive_max_pool(self, op, inputs, input_types):
         data = inputs[0]
         output_size = inputs[1]
+        for i, item in enumerate(output_size):
+            if isinstance(item, tvm.relay.expr.Constant):
+                # convert Constant to int
+                output_size[i] = item.data.numpy()[()]
         # returns dummy indices too
         return op(data, output_size=output_size), None
 
diff --git a/tests/python/frontend/pytorch/test_forward.py 
b/tests/python/frontend/pytorch/test_forward.py
index c8972828ab..83930d1ea8 100644
--- a/tests/python/frontend/pytorch/test_forward.py
+++ b/tests/python/frontend/pytorch/test_forward.py
@@ -886,6 +886,8 @@ def test_forward_adaptive_avgpool():
 
     input_data = torch.rand([1, 3, 5, 6]).float()
     verify_model(torch.nn.AdaptiveAvgPool2d([3, None]).eval(), 
input_data=input_data)
+    input_data = torch.rand([1, 1, 3, 5, 6]).float()
+    verify_model(torch.nn.AdaptiveAvgPool3d([3, None, None]).eval(), 
input_data=input_data)
 
 
 @tvm.testing.uses_gpu
@@ -901,6 +903,11 @@ def test_forward_adaptive_maxpool():
     verify_model(torch.nn.AdaptiveMaxPool1d([1]).eval(), input_data=input_data)
     verify_model(torch.nn.AdaptiveMaxPool1d([5]).eval(), input_data=input_data)
 
+    input_data = torch.rand([1, 3, 5, 6]).float()
+    verify_model(torch.nn.AdaptiveMaxPool2d([3, None]).eval(), 
input_data=input_data)
+    input_data = torch.rand([1, 1, 3, 5, 6]).float()
+    verify_model(torch.nn.AdaptiveMaxPool3d([3, None, None]).eval(), 
input_data=input_data)
+
 
 @tvm.testing.uses_gpu
 def test_forward_maxpool2d():

Reply via email to