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

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

Merged
merged 9 commits into from
Oct 31, 2024

Conversation

PatrikPerssonInceptron
Copy link
Contributor

@PatrikPerssonInceptron PatrikPerssonInceptron commented Oct 24, 2024

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
Copy link
Member

tqchen commented Oct 25, 2024

cc @Hzfengsy can you help to take a look

@Hzfengsy
Copy link
Member

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

@PatrikPerssonInceptron
Copy link
Contributor Author

PatrikPerssonInceptron commented Oct 28, 2024

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

@Hzfengsy
Copy link
Member

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

check for tuple or None type axis where relevant
added isinstance(tvm_out, (int, float, bool)) in check_correctness since
the VM can return primitive types

added test case for squeeze with constant input
added test case for squeeze with dynamic input shape
added test case for squeeze with dynamic shape expression

added test case for slice with dynamic shape expression

fixed bug in test_split which cased the constant split case never to occur
@Hzfengsy
Copy link
Member

LGTM. Thanks for the contribution!!!

@PatrikPerssonInceptron
Copy link
Contributor Author

Happy to help!

@Hzfengsy Hzfengsy merged commit de93c37 into apache:main Oct 31, 2024
22 of 23 checks passed
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.

3 participants