apache / tvm

Open deep learning compiler stack for cpu, gpu and specialized accelerators
https://tvm.apache.org/
Apache License 2.0
11.56k stars 3.43k forks source link

[Bug] [Relay] Crash when return_indices=True for AdaptiveMaxPool1d in PyTorch frontend #14883

Open jikechao opened 1 year ago

jikechao commented 1 year ago

For the AdaptiveMaxPool1d. if the attribute return_indices was set to True, (e.g., AdaptiveMaxPool1d(2,return_indices=True)), when loading it to RelayIR, TVM will crash and throw: AttributeError: 'NoneType' object has no attribute 'dtype'

Actual behavior

Traceback (most recent call last):
  File "7_crash_none_type.py", line 11, in <module>
    mod, params = relay.frontend.from_pytorch(trace, input_shapes)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 4969, in from_pytorch
    outputs = converter.convert_operators(operator_nodes, outputs, ret_name)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 4256, in convert_operators
    return [_wrap_const(outputs[ret_name]) for ret_name in ret_names]
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 4256, in <listcomp>
    return [_wrap_const(outputs[ret_name]) for ret_name in ret_names]
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/pytorch.py", line 4403, in _wrap_const
    return _expr.const(c)
  File "/workplace/software/tvm/tvm/python/tvm/relay/expr.py", line 677, in const
    value.dtype, None
AttributeError: 'NoneType' object has no attribute 'dtype'

Steps to reproduce

import torch
from tvm import relay

m = torch.nn.AdaptiveMaxPool1d(3, return_indices=True) # crash when return_indices=True
input_data=[torch.randn([2,2,4], dtype=torch.float32)]
trace = torch.jit.trace(m, input_data)

input_shapes = [('input0', torch.Size([2, 2, 4]))]

mod, params = relay.frontend.from_pytorch(trace, input_shapes)

Triage

cc @shingjan

jikechao commented 1 year ago

BTW, AdaptiveMaxPool2d, and AdaptiveMaxPool3d can also trigger the same crash.

haoyang9804 commented 11 months ago

Seems that this issue has been fixed.