-
Notifications
You must be signed in to change notification settings - Fork 88
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
Optimize broadcast + transpose for nonscalars #2271
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2271 +/- ##
========================================
Coverage 91.32% 91.33%
========================================
Files 434 434
Lines 16245 16262 +17
========================================
+ Hits 14836 14853 +17
Misses 1409 1409
|
This build is OK for merge ✅ |
🔴bert_base_cased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output🔴bert_large_uncased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output🔴distilgpt2_fp16: FAILED: MIGraphX is not within tolerance - check verbose output |
…MIGraphX into bcast_transpose_generic
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.
Code and tests look good, but
- Update copyright date
- I see that of all the structs defined in this file, only two have brief comments outlining the transformation that struct defines. Could you take the opportunity to add one for this struct too?
auto sum = m1.add_instruction(migraphx::make_op("add"), xb, yb); | ||
m1.add_instruction(pass_op{}, sum); |
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.
Includes optimizations to find_inner_broadcast because otherwise a bunch of multibroadcasts were appearing after the transformation
Do you have a test for this specific case where multibroadcasts are appearing after find_inner_broadcast that are not being cleaned up by simplify_reshapes ? because for this test it will add multibroadcast but later i think it will get cleaned up by find_nop_reshaper
.
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.
yes, this exact test will fail currently on develop and insert a bunch of multibroadcasts:
./bin/test_simplify_algebra_test simplify_inner_broadcast_no_common_axis
[ RUN ] simplify_inner_broadcast_no_common_axis
void simplify_inner_broadcast_no_common_axis()
/code/AMDMIGraphX/test/simplify_algebra_test.cpp:686:
FAILED: m1 == m2 [ y = @param:y -> int32_type, {1, 5, 1}, {5, 1, 1}, target_id=0
x = @param:x -> int32_type, {5, 10}, {10, 1}, target_id=0
@2 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](x) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@3 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](y) -> int32_type, {1, 5, 10}, {5, 1, 0}, target_id=0
@4 = add(@2,@3) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@5 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@4) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@6 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@5) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@7 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@6) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@8 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@7) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@9 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@8) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@10 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@9) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@11 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@10) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@12 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](@11) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@13 = pass(@12) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
== y = @param:y -> int32_type, {1, 5, 1}, {5, 1, 1}, target_id=0
x = @param:x -> int32_type, {5, 10}, {10, 1}, target_id=0
@2 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](x) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@3 = multibroadcast[out_lens={1, 5, 10},out_dyn_dims={}](y) -> int32_type, {1, 5, 10}, {5, 1, 0}, target_id=0
@4 = add(@2,@3) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
@5 = pass(@4) -> int32_type, {1, 5, 10}, {0, 10, 1}, target_id=0
]
[ FAILED ] simplify_inner_broadcast_no_common_axis: Test failure
[==========] 1 tests ran
[ FAILED ] 1 tests failed
[ FAILED ] simplify_inner_broadcast_no_common_axis
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.
Those multi broadcasts should get cleaned up by find_nop_reshaper later
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.
Also where all those broadcasts are being added. Looks to me that find_inner_broadcast would only add one multibroadcast after add
inside simplify_reshapes, it is only adding unsqueeze if it is not scalar. Is it still an issue ? |
This is the behavior of unsqueeze on a scalar:
Looks like it completely ignores the extra axes and instead converts from scalar to literal with stride 1. |
} | ||
} | ||
// if no common broadcast axis, transformation is not useful | ||
if(std::find_if(common_axis.begin(), common_axis.end(), [](auto num_common) { |
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.
You could use std::none_of
instead.
Includes optimizations to
find_inner_broadcast
because otherwise a bunch of multibroadcasts were appearing after the transformation.TODO: