-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[TOPI][OP]change float multiplication of resize op to integer division #12315
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94c3f08 to
cb6a348
Compare
wrongtest-intellif
requested changes
Aug 9, 2022
Member
|
cc @masahi |
Hzfengsy
approved these changes
Aug 9, 2022
Member
Hzfengsy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM
088a3d6 to
cfb0b80
Compare
cfb0b80 to
7bfbf07
Compare
wrongtest-intellif
approved these changes
Aug 14, 2022
wrongtest-intellif
pushed a commit
that referenced
this pull request
Aug 30, 2022
#12315) * [TOPI][OP]change float multiplication of resize op to integer division * add unittest. * 1. add docstring 2. rename param
xinetzone
pushed a commit
to daobook/tvm
that referenced
this pull request
Nov 25, 2022
apache#12315) * [TOPI][OP]change float multiplication of resize op to integer division * add unittest. * 1. add docstring 2. rename param
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is aim to change floating point multiplication of resize operator to integer division when
methodis nearest_neighbor andcoordinate_transformation_modeis asymmetric.Why this change?
When using
create_prim_functo convert topi.upsampling into primfunc, tir analyzer cannot parse complex floating point operations in tir block body. In the following case, the dimensions of read buffer are inferred as 0 : 128. We expect to betir.reads([x[i0_1, i1_1, i2_1/scale_h, i3_1/scale_w]])in line 18,so it can perform compute_at schedule on this prim_func.Why can it be changed?
This PR only modify float multiplication to integer division when
methodisnearest_neighborandcoordinate_transformation_modeisasymmetric(it's default setting for topi.upsampling op).Go further, we expect to convert$\lfloor s * x + \epsilon_1 \rfloor$ to $x//a$ , $s$ is scale, a float number, $x$ is input, $\epsilon_1$ is 1e-5 in resize op, $a$ is the reciprocal of $s$ , an integer.
So, we can represent output as this:
$y = \lfloor s * x + \epsilon_1 \rfloor = \lfloor ( \frac{1}{a} + \epsilon_0 ) * x + \epsilon_1 \rfloor = \lfloor \frac{x}{a} + \epsilon_0 * x + \epsilon_1 \rfloor$ , let $x = a * m + n$ , where $m = x // a, n = x % a$ , then we can get $y = m + \lfloor \frac{n}{a} + \epsilon_0 * x + \epsilon_1 \rfloor$ . In the case of upsampling op, $x$ and $a$ are always integers, so inequality $\frac{n}{a} \le \frac{a-1}{a}$ always holds. If $\epsilon_0 * x + \epsilon_1 < \frac{1}{a}$ , we can get $0 < \frac{n}{a} + \epsilon_0 * x + \epsilon_1 < 1$ ,then $y = m + \lfloor \frac{n}{a} + \epsilon_0 * x + \epsilon_1 \rfloor = m = x // a$ .
To sum up, when$\epsilon_0 * x + \epsilon_1 < \frac{1}{a}$ , we can get $y = \lfloor s*x + \epsilon_1 \rfloor = x // a$ .
In this PR, we assume$\epsilon_0 = \epsilon_1 = 1e-5$ and $\epsilon_0 * x + \epsilon_1 < \frac{1}{a}$ .
can_convert_multiply_to_intdivto check