-
Notifications
You must be signed in to change notification settings - Fork 89
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
Resize onnx operator: Optimization for Compute and Space performance of its linear option. #3773
base: develop
Are you sure you want to change the base?
Conversation
Is this sort of dup of #3731? |
No. Orthogonal and a more fundamental change to Resize parsing. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3773 +/- ##
===========================================
+ Coverage 92.28% 92.29% +0.01%
===========================================
Files 519 519
Lines 22227 22233 +6
===========================================
+ Hits 20512 20520 +8
+ Misses 1715 1713 -2 ☔ View full report in Codecov by Sentry. |
Thanks for the explanation. |
(Background: going beyond the issue, #2129, the Resize Op could use more optimization in its basic calculations, hence this PR). |
This build is OK for merge ✅ |
🔴bert_large_uncased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output |
I think these code changes make a merge conflict with the code in #3731 though? |
std::vector<std::vector<std::size_t>> vv_ind(2, std::vector<std::size_t>(out_elements)); | ||
std::vector<std::vector<std::vector<std::size_t>>> vvv_ind(n_dim, vv_ind); | ||
std::vector<std::vector<float>> delta(n_dim, std::vector<float>(out_elements)); | ||
std::vector<std::vector<std::vector<std::size_t>>> vvv_ind(r_dim, vv_ind); |
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.
can we add some brief explanation what these variables are
vvv_ind, 0, 0, std::vector<std::vector<std::size_t>>(out_elements), in_s, out_s); | ||
|
||
auto dim_lens = out_lens; | ||
dim_lens[0] *= (1u << r_dim); |
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.
what does this bitshift do? Brief explanation would be sufficient
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.
Bit-shift was/is basically a calculation of the actual size of the final index tensor that is being generated. It is getting doubled by every lens dimension in the previous algorithm, and now by the just the modified lens dimensions -- the fundamental change in this PR.
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.
I will add a comment.
// get the number of dimensions | ||
std::size_t n_dim = out_lens.size(); | ||
std::size_t n_dim = out_lens.size(); | ||
std::size_t r_dim = 0; // count: lens dimensions that are resized |
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.
std::size_t r_dim = 0; // count: lens dimensions that are resized | |
std::size_t resized_dims = 0; // count: lens dimensions that are resized |
@@ -359,41 +374,55 @@ struct parse_resize : op_parser<parse_resize> | |||
auto nearest_floor = op::resize::get_nearest_op("floor"); | |||
auto nearest_ceil = op::resize::get_nearest_op("ceil"); | |||
|
|||
// get the number of dimensions | |||
std::size_t n_dim = out_lens.size(); | |||
std::size_t n_dim = out_lens.size(); |
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.
std::size_t n_dim = out_lens.size(); | |
std::size_t n_dims = out_lens.size(); |
@@ -35,11 +35,15 @@ namespace onnx { | |||
|
|||
static std::vector<int> | |||
calc_neighbor_points(const std::vector<std::vector<std::vector<std::size_t>>>& vvv_ind, | |||
int i_dim, | |||
size_t i_dim, // input lens index |
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.
size_t i_dim, // input lens index | |
size_t input_ind, // input lens index |
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.
or input_idx
, seems like we're not consistent in this file anyways
@@ -35,11 +35,15 @@ namespace onnx { | |||
|
|||
static std::vector<int> | |||
calc_neighbor_points(const std::vector<std::vector<std::vector<std::size_t>>>& vvv_ind, | |||
int i_dim, | |||
size_t i_dim, // input lens index | |||
size_t r_dim, // resized index |
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.
size_t r_dim, // resized index | |
size_t resized_ind, // resized index |
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.
or resized_idx
Optimize the space overhead required for Linear Resize operation: it is now 4x smaller for its 2D images. There were very large data-structures, getting to be over 16 times the total input_pixels for a 4D tensor. And now it becomes 4x smaller in size, followed with fewer reduction steps. (Similar optimization for its compute overhead.)
A comparison of parsing
test/onnx/upsample_linear_test.onnx
:(Before)
Calculated resize-tensor size:
@4 = @literal{ ... } -> int32_type, {16, 1, 4, 4}, {16, 16, 4, 1}
With this PR:
Calculated resize-tensor size:
@2 = @literal{ ... } -> int32_type, {4, 1, 4, 4}, {16, 16, 4, 1}