You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/02/24 18:40:11 UTC

[GitHub] [tvm] alexwong opened a new pull request #7517: Convert strides and pool_size to int

alexwong opened a new pull request #7517:
URL: https://github.com/apache/tvm/pull/7517


   Was working on a SVDD model and ran into some issues with pool operators. 
   
   ```
     File "tests/python/frontend/pytorch/test_svdd.py", line 39, in <module>
       mod, params = relay.frontend.from_pytorch(model, shape_dict)
     File "/home/ubuntu/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 3160, in from_pytorch
       ret = converter.convert_operators(_get_operator_nodes(graph.nodes()), outputs, ret_name)[0]
     File "/home/ubuntu/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 2582, in convert_operators
       inputs, _get_input_types(op_node, outputs, default_dtype=self.default_dtype)
     File "/home/ubuntu/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 1338, in avg_pool2d
       return func(data)
     File "/home/ubuntu/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 1332, in func
       count_include_pad=count_include_pad,
     File "/home/ubuntu/tvm/tvm/python/tvm/relay/op/nn/nn.py", line 1026, in avg_pool2d
       return _make.avg_pool2d(data, pool_size, strides, padding, layout, ceil_mode, count_include_pad)
     File "/home/ubuntu/tvm/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
       raise get_last_ffi_error()
   tvm._ffi.base.TVMError: Traceback (most recent call last):
     [bt] (4) /home/ubuntu/tvm/tvm/build/libtvm.so(TVMFuncCall+0x5b) [0x7f6ec5b4f8db]
     [bt] (3) /home/ubuntu/tvm/tvm/build/libtvm.so(+0xe41916) [0x7f6ec564d916]
     [bt] (2) /home/ubuntu/tvm/tvm/build/libtvm.so(tvm::runtime::TVMMovableArgValueWithContext_::operator tvm::runtime::Array<tvm::PrimExpr, void><tvm::runtime::Array<tvm::PrimExpr, void> >() const+0x67) [0x7f6ec4df0217]
     [bt] (1) /home/ubuntu/tvm/tvm/build/libtvm.so(tvm::runtime::Array<tvm::PrimExpr, void> tvm::runtime::TVMPODValue_::AsObjectRef<tvm::runtime::Array<tvm::PrimExpr, void> >() const+0x438) [0x7f6ec4df00a8]
     [bt] (0) /home/ubuntu/tvm/tvm/build/libtvm.so(+0x5d5612) [0x7f6ec4de1612]
     File "/home/ubuntu/tvm/tvm/include/tvm/runtime/packed_func.h", line 687
   TVMError: In function relay.op.nn._make.avg_pool2d: error while converting argument 2: [10:04:02] /home/ubuntu/tvm/tvm/include/tvm/runtime/packed_func.h:1564: 
   ---------------------------------------------------------------
   An internal invariant was violated during the execution of TVM.
   Please read TVM's error reporting guidelines.
   More details can be found here: https://discuss.tvm.ai/t/error-reporting/7793.
   ---------------------------------------------------------------
     Check failed: !checked_type.defined() == false: Expected Array[PrimExpr], but got Array[index 0: relay.Constant]
   ```
   
   I found that if the PT graph has aten::Int as the input value for either strides or pool_size, then we get above.
   
   ```
    %125 : int = aten::Int(%124)
    %126 : int[] = prim::ListConstruct(%116, %119)
    %127 : int[] = prim::ListConstruct(%122, %125)
    %128 : int[] = prim::ListConstruct(%111, %111)
    %x.6 : Tensor = aten::avg_pool2d(%x.5, %126, %127, %128, %108, %107, %106)
   
   ```
   This fixes that case by converting relay constants to ints. @masahi 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on pull request #7517: [Torch] Pool ops, convert strides and pool_size to int

Posted by GitBox <gi...@apache.org>.
masahi commented on pull request #7517:
URL: https://github.com/apache/tvm/pull/7517#issuecomment-786423755


   Thanks @alexwong 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on a change in pull request #7517: [Torch] Pool ops, convert strides and pool_size to int

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #7517:
URL: https://github.com/apache/tvm/pull/7517#discussion_r582242014



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1322,6 +1332,16 @@ def avg_pool2d(self, inputs, input_types):
         ceil_mode = int(inputs[4])
         count_include_pad = int(inputs[5])
 
+        if isinstance(pool_size, list):
+            for i in range(len(pool_size)):
+                if isinstance(pool_size[i], _expr.Constant):
+                    pool_size[i] = int(_infer_value_simulated(pool_size[i], {}).asnumpy())
+
+        if isinstance(strides, list):
+            for i in range(len(strides)):
+                if isinstance(strides[i], _expr.Constant):
+                    strides[i] = int(_infer_value_simulated(strides[i], {}).asnumpy())
+

Review comment:
       Let's introduce a helper function to remove all the dups.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] alexwong commented on a change in pull request #7517: [Torch] Pool ops, convert strides and pool_size to int

Posted by GitBox <gi...@apache.org>.
alexwong commented on a change in pull request #7517:
URL: https://github.com/apache/tvm/pull/7517#discussion_r583140165



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1322,6 +1332,16 @@ def avg_pool2d(self, inputs, input_types):
         ceil_mode = int(inputs[4])
         count_include_pad = int(inputs[5])
 
+        if isinstance(pool_size, list):
+            for i in range(len(pool_size)):
+                if isinstance(pool_size[i], _expr.Constant):
+                    pool_size[i] = int(_infer_value_simulated(pool_size[i], {}).asnumpy())
+
+        if isinstance(strides, list):
+            for i in range(len(strides)):
+                if isinstance(strides[i], _expr.Constant):
+                    strides[i] = int(_infer_value_simulated(strides[i], {}).asnumpy())
+

Review comment:
       Done. Thanks. Changed to any type of expr as well.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] alexwong commented on pull request #7517: [Torch] Pool ops, convert strides and pool_size to int

Posted by GitBox <gi...@apache.org>.
alexwong commented on pull request #7517:
URL: https://github.com/apache/tvm/pull/7517#issuecomment-786175478


   > @alexwong can you add a test?
   
   Yep, added a test in maxpool2d. It creates a call expr which hits the new function.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on pull request #7517: [Torch] Pool ops, convert strides and pool_size to int

Posted by GitBox <gi...@apache.org>.
masahi commented on pull request #7517:
URL: https://github.com/apache/tvm/pull/7517#issuecomment-785319410


   @alexwong can you add a test?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi merged pull request #7517: [Torch] Pool ops, convert strides and pool_size to int

Posted by GitBox <gi...@apache.org>.
masahi merged pull request #7517:
URL: https://github.com/apache/tvm/pull/7517


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org