ganler opened a new pull request #10593: URL: https://github.com/apache/tvm/pull/10593
Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @ them in the pull request thread. Simple Flatten operator's shape cannot be evaluated when using ONNX. This is because the flatten op does not try to do constant folding thus creating unnecessary dynamic operator, causing graph executor unable to execute it. To trigger this bug, simply use this script to generate a ONNX model and run it with graph executor. ```python import torch N = 1 # can be something else class Net(torch.nn.Module): def __init__(self) -> None: super().__init__() def forward(self, x): return x.flatten() net = Net().eval() o = net(torch.zeros((N), dtype=torch.float)) print(o.shape) with torch.no_grad(): torch.onnx.export(net, ( torch.ones((N), dtype=torch.float)), "output.onnx", verbose=True, opset_version=14) ``` It will throw errors: ``` def @main(%v0: Tensor[(1), float32]) -> Tensor[(?, ?), float32] { %0 = shape_of(%v0, dtype="int32") /* ty=Tensor[(1), int32] */; %1 = strided_slice(%0, begin=[0], end=[0], strides=[1], axes=None) /* ty=Tensor[(0), int32] */; %2 = strided_slice(%0, begin=[0], end=[1], strides=[1], axes=None) /* ty=Tensor[(1), int32] */; %3 = prod(%1, keepdims=True) /* ty=Tensor[(1), int32] */; %4 = prod(%2, keepdims=True) /* ty=Tensor[(1), int32] */; %5 = (%3, %4); %6 = concatenate(%5) /* ty=Tensor[(2), int32] */; dyn.reshape(%v0, %6, newshape=[]) /* ty=Tensor[(?, ?), float32] */ } Traceback (most recent call last): ... executor = relay.build_module.create_executor( File "/home/ganler/Documents/tvm/python/tvm/relay/backend/interpreter.py", line 171, in evaluate return self._make_executor() File "/home/ganler/Documents/tvm/python/tvm/relay/build_module.py", line 621, in _make_executor raise ValueError( ValueError: ('Graph Executor only supports static graphs, got output type', TensorType([?, ?], float32)) ``` cc: @AndrewZhaoLuo @vinx13 @jwfromm -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
