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

[Relay][Frontend][Onnx] Compare against onnxruntime more consistently during testing #7300

Merged
merged 5 commits into from
Jan 19, 2021

Conversation

jwfromm
Copy link
Contributor

@jwfromm jwfromm commented Jan 17, 2021

I noticed that many of our onnx frontend tests compare to results produced by numpy rather than onnx itself. This is somewhat counterproductive because it makes assumptions about what onnx should do rather than checking what it actually does. I decided to go through all the tests in test_forward.py and make them use the new verify_with_ort helper function. This makes our testing suite more consistent and align more closely with their intention. In the process of making this conversion, I discovered many bugs with the importer that are also fixed in this PR. Although this PR might be a little painful to review due to its scope, I think that the result is an overall much cleaner and easier to maintain test suite.

@jwfromm
Copy link
Contributor Author

jwfromm commented Jan 17, 2021

@masahi @mbrookhart can you guys let me know what you think of this PR?

input_data = np.random.uniform(size=input_size).astype("int32")
verify_with_ort_with_inputs(onnx_model, [input_data])
input_data = np.random.uniform(size=input_size).astype("float32")
verify_with_ort_with_inputs(onnx_model, [input_data], apply_softmax=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fun one that I wanted to point out. Previously we were casting inputs to int32, however because they were generated with np.random.uniform they all were just being cast to 0. Using non-zero inputs caused some minor mismatch on outputs due to numerical instability but applying softmax (which torchvision models don't use by default) reduces the numerical difference well below our test threshold.

Copy link
Member

@masahi masahi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the heroic effort 👍

@tqchen tqchen merged commit f91b51d into apache:main Jan 19, 2021
Copy link
Contributor

@mbrookhart mbrookhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm late, because I was in holiday weekend mode, but this looks awesome, thanks @jwfromm and @masahi

@jwfromm jwfromm deleted the onnx_test_cleanup branch January 19, 2021 19:09
TusharKanekiDey pushed a commit to TusharKanekiDey/tvm that referenced this pull request Jan 20, 2021
… during testing (apache#7300)



Co-authored-by: Josh Fromm <jwfromm@uw.edu>
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Jan 21, 2021
… during testing (apache#7300)



Co-authored-by: Josh Fromm <jwfromm@uw.edu>
electriclilies pushed a commit to electriclilies/tvm that referenced this pull request Feb 18, 2021
… during testing (apache#7300)



Co-authored-by: Josh Fromm <jwfromm@uw.edu>
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.

4 participants