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

Refactor shape_inference_test for old Op versions PR1 #5263

Merged
merged 19 commits into from
Jun 19, 2023

Conversation

guoyuhong
Copy link
Contributor

@guoyuhong guoyuhong commented May 27, 2023

Description

#4160

Motivation and Context

Shape inference tests for older opset versions are not supported before this PR. This refactor would help to test old-versioned ops.
This PR introduces a function all_versions_for to help generate test functions for all versions of one Op. The users can use @parameterized.expand(all_versions_for("${op_name}")) to annotate the test function to apply the test function to all op versions. The test function should have the arguments like def test_op(self, version_name, op_version). version_name is usually unused but it's better to keep that to make the parameterized test name more readable. For example, with this version_name, the test name will have a version suffix showed as follows.
image

@guoyuhong
Copy link
Contributor Author

@jcwchen Do you have time to take a look at this change?

Copy link
Member

@jcwchen jcwchen left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I like the idea, but IIRC (I tried to test it before), we will probably need to modify quite a few existing tests to accommodate old opset versions. Still, it's great to have a starting point now and we can decouple the modified work if needed.

onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch from 84d442c to a6453ce Compare June 3, 2023 09:08
@guoyuhong guoyuhong changed the title [WIP] Try to refactor shape_inference_test for old ops Refactor shape_inference_test for old ops Jun 3, 2023
@guoyuhong
Copy link
Contributor Author

guoyuhong commented Jun 3, 2023

@jcwchen I refined my code and applied this pattern to several Ops. For most Ops, the one test case fits all versions of this Op. Until now, I found there are Ops that have some incompatible tests. Here is a simple summary:

  1. Reshape's allowzero since Version 14, so test_reshape_static_shape_allowzero before Version 14 is skipped.
  2. Upsample is deprecated from Version 10. I added special test case for Version 10.
  3. Upsample's test case for Version 7 and Version 9 are different. I copied test from the old code from Version 7.
  4. Squeeze's test case for Version 11 and Version 13 are different. I copied test from the old code from Version 11.

By the way, there seems a lot of work to do. Is it better to split this change to several PRs?

@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch from 1e57456 to 194d2c8 Compare June 3, 2023 11:46
@guoyuhong guoyuhong changed the title Refactor shape_inference_test for old ops Refactor shape_inference_test for old ops PR1 Jun 3, 2023
@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch from 194d2c8 to cee20ac Compare June 3, 2023 11:55
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
onnx/test/shape_inference_test.py Outdated Show resolved Hide resolved
@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch 3 times, most recently from 5d82692 to 27357e2 Compare June 6, 2023 14:01
@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch 2 times, most recently from 99b75eb to 15351cb Compare June 6, 2023 15:59
@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch 2 times, most recently from da5069d to 55a27d3 Compare June 7, 2023 04:16
@guoyuhong guoyuhong changed the title Refactor shape_inference_test for old ops PR1 Refactor shape_inference_test for old Op versions PR1 Jun 7, 2023
Yuhong Guo added 9 commits June 13, 2023 13:46
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch from 28f3ac5 to 64811ec Compare June 13, 2023 05:47
Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
@guoyuhong guoyuhong force-pushed the refactor_shapinference_test branch from 64811ec to 3cd4ef4 Compare June 13, 2023 05:47
@guoyuhong
Copy link
Contributor Author

@jcwchen I will apply this test scheme to all other test functions in a later PR and try to fix the Reshape issue when op verison <= 5 after that.

@jcwchen jcwchen added test shape inference Issues related to shape inference labels Jun 14, 2023
@gramalingam gramalingam enabled auto-merge (squash) June 16, 2023 17:59
@gramalingam gramalingam merged commit 925840b into onnx:main Jun 19, 2023
35 checks passed
@guoyuhong guoyuhong deleted the refactor_shapinference_test branch June 19, 2023 03:22
@adityagoel4512
Copy link
Contributor

adityagoel4512 commented Jun 19, 2023

When making updates to shape inference logic, should we reflect these changes in older shape inference implementations (e.g.

.TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
)?

@guoyuhong
Copy link
Contributor Author

guoyuhong commented Jun 19, 2023

When making updates to shape inference logic, should we reflect these changes in older shape inference implementations (e.g.

.TypeAndShapeInferenceFunction([](InferenceContext& ctx) {

)?

@adityagoel4512 I'm not sure. @jcwchen what do you think about this question?

@jcwchen
Copy link
Member

jcwchen commented Jun 19, 2023

When making updates to shape inference logic, should we reflect these changes in older shape inference implementations (e.g.

Good question... It's really case by case. I would say if there is a critical bug in old shape inference, we should. A common scenario is all opset versions do not behave correctly in some corner cases and ONNX should fix them consistently among all versions. Another common scenario is if some situations only happen in the latest opset version (e.g., new attribute or new documentation) rather than older ones, we don't need to update/add such a logic in older opest versions. Also we need to be very careful about some shape inference changes might break runtime backward compatibility.

@adityagoel4512
Copy link
Contributor

That makes sense to me, I suppose it'll require careful reviews then.

@gramalingam
Copy link
Contributor

Agree with Jacky. If the fix makes sense for older op versions, ideally we should make the change to older version too.

adityagoel4512 pushed a commit to adityagoel4512/onnx that referenced this pull request Jul 28, 2023
### Description
<!-- - Describe your changes. -->
onnx#4160

### Motivation and Context
<!-- - Why is this change required? What problem does it solve? -->
<!-- - If it fixes an open issue, please link to the issue here. -->
Shape inference tests for older opset versions are not supported before
this PR. This refactor would help to test old-versioned ops.
This PR introduces a function `all_versions_for` to help generate test
functions for all versions of one Op. The users can use
`@parameterized.expand(all_versions_for("${op_name}"))` to annotate the
test function to apply the test function to all op versions. The test
function should have the arguments like `def test_op(self, version_name,
op_version)`. `version_name` is usually unused but it's better to keep
that to make the parameterized test name more readable. For example,
with this `version_name`, the test name will have a version suffix
showed as follows.

![image](https://github.com/onnx/onnx/assets/19584326/70ab74ec-5108-4c24-80bf-c04802858582)

---------

Signed-off-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Co-authored-by: Yuhong Guo <yuhong.gyh@antgroup.com>
Signed-off-by: Aditya Goel <agoel4512@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shape inference Issues related to shape inference test
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants