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

Enhance shape inference: ParseData/Transpose/QuantizeLinear #3806

Merged
merged 10 commits into from Nov 10, 2021

Conversation

jcwchen
Copy link
Member

@jcwchen jcwchen commented Oct 26, 2021

Description

  1. Enhance ParseData check: having raw_data cannot be String
    2 Transpose should check repeated perm to prevent issues
    3 If third input (y_zero_point) of QuantizeLinear is an empty string, shape inference should still work because y_zero_point is an optional input

Motivation and Context

  1. Continues a sub task from Consider multiple types for ParseData according to DataType definition #3787 (comment).
  2. Closes ONNX checker doesn't check repeated permutation for Transpose operator #3709
  3. Closes ONNX shape inference for QuantizeLinear fails on empty string as zero_point #3744

Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
@jcwchen jcwchen added the shape inference Issues related to shape inference label Oct 26, 2021
@jcwchen jcwchen requested a review from a team as a code owner October 26, 2021 01:30
} else {
// check if any perm is repeated
if (seen[fromDimIndex]) {
fail_type_inference("Attribute perm for Transpose cannot be repeated: ", fromDimIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Attribute perm for Transpose has repeated entry for value fromIndex? or something similar?

@@ -64,6 +64,10 @@ namespace ONNX_NAMESPACE {
res.insert(res.end(), data.begin(), data.end()); \
return res; \
} \
if (tensor_proto->data_type() == TensorProto_DataType_STRING) { \
fail_shape_inference("The data_type of tensor: ", tensor_proto->name(), \
" cannot be string because it has raw_data which disallows string."); \
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: tensor_proto->name() data type is string. string content is required to be stored in repeated bytes string_data field. raw_data type cannot be string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Both updated for improving error messages. Thanks

@@ -55,14 +55,14 @@ ONNX_OPERATOR_SET_SCHEMA(
.SetDoc(QuantizeLinear_ver13_doc)
.TypeAndShapeInferenceFunction(
[](ONNX_NAMESPACE::InferenceContext& ctx) {
if (ctx.getNumInputs() == 3) {
if (ctx.getNumInputs() == 3 && ctx.getInputType(2) != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks good. Wondering how can we avoid this issue in case of all optional inputs. Right now I think only QuantizeLinear does type propagation from optional input to output... but if tomorrow there is some other op which does the same then the type inference will have to take care of this condition. May not be worth it right now... @gramalingam thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I was thinking of it too... This situation can happen again in the future. Perhaps we can extend existing getNumInputs with more parameter to represent whether it disallows optional input for certain index (or a set of indexes)

@askhade askhade added this to the 1.11 milestone Oct 27, 2021
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
@jcwchen jcwchen added the run release CIs Use this label to trigger release tests in CI label Oct 27, 2021
@askhade
Copy link
Contributor

askhade commented Nov 2, 2021

The change looks good... please add tests

@jcwchen jcwchen requested a review from a team as a code owner November 3, 2021 20:58
@jcwchen
Copy link
Member Author

jcwchen commented Nov 4, 2021

The change looks good... please add tests

Good point. I added 2 tests for checking repeated perm for Transpose and empty string for QuantizeLinear.

Regarding to test for ParseData with raw_data and string type, actually ParseData does not support parse string type now so the condition cannot be tested... If that is the case, do we still need to add the check here?

@askhade askhade enabled auto-merge (squash) November 10, 2021 14:36
@askhade askhade merged commit f61fd84 into onnx:master Nov 10, 2021
@jcwchen jcwchen deleted the jcw/issues branch April 18, 2022 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run release CIs Use this label to trigger release tests in CI shape inference Issues related to shape inference
Projects
Status: Done
2 participants