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

[TOPI] Average Pool2D Bug. #3607

Merged
merged 2 commits into from
Jul 25, 2019
Merged

[TOPI] Average Pool2D Bug. #3607

merged 2 commits into from
Jul 25, 2019

Conversation

anijain2305
Copy link
Contributor

@FrozenGene
Copy link
Member

As #3581 discussed, TFLite's tvm.sum type is UINT16 (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/kernels/internal/optimized/optimized_ops.h#L2976), not int32. Could we consider this corner case? @tqchen 's said, we could compose this op to handle it, if so, could we add one test to cover?

@anijain2305
Copy link
Contributor Author

@FrozenGene Upcasting to uint16 as done in TFLite is little out of context in this PR.

For now, I have added one more test case checking uint16 datatype to ensure that accumulation and division happens at the right time. I think that should be good enough for now.

Let me know your comments on the CPP code changes. I am not very familiar with this section of code. Lets try to get this in quickly because this is a functional bug which will certainly affect automatic quantization accuracy as well.

Array<Expr> indices;
for (const Var& var : output) indices.push_back(var);
indices.Set(height_axis, output[height_axis] * stride_height + dheight);
indices.Set(width_axis, output[width_axis] * stride_width + dwidth);
return tvm::sum(temp(indices) / divide_factor, { dheight, dwidth });
};
return tvm::sum(temp(indices), { dheight, dwidth });
Copy link
Member

@FrozenGene FrozenGene Jul 24, 2019

Choose a reason for hiding this comment

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

If we could leave one comment of TODO here, it is better. Remind us there is one potential issue we should care in the future parsing TFLite model.

Copy link
Member

Choose a reason for hiding this comment

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

@FrozenGene If you mean int8<->uint8 casting for tflite, I think the TODO can be put into tflite frontend instead. The bugfix here in topi is complete IMO. what do you think?

Copy link
Member

@FrozenGene FrozenGene Jul 24, 2019

Choose a reason for hiding this comment

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

I mean the tvm.sum type should be uint16 for tflite's average_pool2d, not int32.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For TFLite adaptation, we can cast the input to uint16 and then pass the casted input to avg_pool2d. This is purely the job of framework parser. It does not need any code in the TOPI layer.

Copy link
Member

Choose a reason for hiding this comment

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

yes my understanding is avg_pool2d(int_8_value.astype("uint16")).astype("int8") will be in frontend, right?

Copy link
Member

Choose a reason for hiding this comment

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

I understand the way you want to do. Even the output dtype is "int32", you also want to do avg_pool2d(int_8_value.astype("int32")).astype("int8") in frontend.

Copy link
Member

Choose a reason for hiding this comment

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

If so, the way is ok.

@tqchen tqchen merged commit 3aa2eae into apache:master Jul 25, 2019
@tqchen
Copy link
Member

tqchen commented Jul 25, 2019

Thanks @FrozenGene @anijain2305 @yzhliu .

@anijain2305 anijain2305 deleted the pool_int8 branch July 25, 2019 04:41
anijain2305 added a commit to anijain2305/tvm that referenced this pull request Aug 2, 2019
* [TOPI] Average Pool2D Bug.

Issue - apache#3581

* Add uint16 test.
wweic pushed a commit to wweic/tvm that referenced this pull request Aug 9, 2019
* [TOPI] Average Pool2D Bug.

Issue - apache#3581

* Add uint16 test.
wweic pushed a commit to neo-ai/tvm that referenced this pull request Sep 6, 2019
* [TOPI] Average Pool2D Bug.

Issue - apache#3581

* Add uint16 test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants