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

[Torch] Pool ops, convert strides and pool_size to int #7517

Merged
merged 3 commits into from
Feb 26, 2021

Conversation

alexwong
Copy link
Contributor

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

@alexwong alexwong changed the title Convert strides and pool_size to int [Torch] Pool ops, convert strides and pool_size to int Feb 24, 2021
@masahi
Copy link
Member

masahi commented Feb 24, 2021

@alexwong can you add a test?

@masahi masahi self-assigned this Feb 25, 2021
@alexwong
Copy link
Contributor Author

@alexwong can you add a test?

Yep, added a test in maxpool2d. It creates a call expr which hits the new function.

@masahi masahi merged commit c46b187 into apache:main Feb 26, 2021
@masahi
Copy link
Member

masahi commented Feb 26, 2021

Thanks @alexwong

Lokiiiiii pushed a commit to Lokiiiiii/tvm that referenced this pull request Mar 2, 2021
* Convert strides and pool_size to int

* Make helper function, add test

* Fix lint
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Mar 2, 2021
* Convert strides and pool_size to int

* Make helper function, add test

* Fix lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants