wzh99 opened a new issue, #11640:
URL: https://github.com/apache/tvm/issues/11640
Type inference of the following Relay function causes a segmentation fault:
```
def @main(%x: Tensor[(1, 2, 3), float32]) {
sum(%x, axis=[], keepdims=True, exclude=True)
}
```
### Expected behavior
The type inference pass accepts this function, since the type constraints of
the reduction operator `sum` are not violated.
### Actual behavior
Segmentation fault.
### Environment
macOS 12.4. Compiled using Clang 13.1.6 with LLVM support. TVM commit
[`df4f4c0b4`](https://github.com/apache/tvm/commit/df4f4c0b4bccd775af25967fdf057392c1a2826e).
### Steps to reproduce
```python
from tvm import relay, ir
x = relay.var('x', shape=(1, 2, 3))
y = relay.sum(x, axis=(), keepdims=True, exclude=True)
mod = ir.IRModule.from_expr(y)
mod = relay.transform.InferType()(mod)
```
### Possible fix
https://github.com/apache/tvm/blob/df4f4c0b4bccd775af25967fdf057392c1a2826e/src/relay/op/tensor/reduce.cc#L72-L73
```c++
ICHECK(in_axes[in_axes.size() - 1] < indim)
<< "Reduction axis " << in_axes[in_axes.size() - 1] << " exceeds input
dimensions " << indim;
```
When `in_axes` is empty, accessing it by index `in_axes.size() - 1` is
invalid. To fix it, I suggest removing this `ICHECK` because the range of
elements in `in_axes` seems to have been checked already in the previous
for-loop.
--
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]