apache / tvm

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

[FIX][ONNX][RELAX] Add support for dynamic ShapeExpr in Slice, Squeeze and Flatten #17490

Closed PatrikPerssonInceptron closed 3 weeks ago

PatrikPerssonInceptron commented 4 weeks ago

Squeeze

I added a tuple wrapping around axis when sending it to _np.squeeze since it does not support list objects. I added an additional check to see if the data is a ShapeExpr. If this is the case I perform the inverse of the operations done in the Unsqueeze operation.

Slice

I fixed a bug where the dimensions were assumed to be of IntImm data type by adding an additional check to handle the constant and dynamic case separately.

Flatten

I fixed a bug where the dimensions were assumed to be of IntImm data type by adding an additional check to handle the constant and dynamic case separately.

Split

I replaced asnumpy with numpy since asnumpy is deprecated. I added a call to .item() to convert from numpy data types to python primitives.

Regression Tests

I extracted generate_random_value function from generate_random_inputs. I added isinstance(tvm_out, (int, float, bool)) in check_correctness since the VM can return python primitive types

Squeeze

I added a test case for squeeze with constant input since it was missing I added a test case for squeeze with dynamic input shape I added a test case for squeeze with dynamic shape expression

Slice

I added a test case for slice with dynamic shape expression

Split

I fixed a bug in test_split which caused the constant split case never to occur

tqchen commented 4 weeks ago

cc @Hzfengsy can you help to take a look

Hzfengsy commented 4 weeks ago

Thanks for the contribution, please add a regression test :)

PatrikPerssonInceptron commented 3 weeks ago

My pleasure, where exactly in the code should I add the regression tests? :)

Hzfengsy commented 3 weeks ago

tests/python/relax/test_frontend_onnx.py would be great:)

Hzfengsy commented 3 weeks ago

LGTM. Thanks for the contribution!!!

PatrikPerssonInceptron commented 3 weeks ago

Happy to help!