-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[TIR][Transform] HoistIfThenElse added #6066
[TIR][Transform] HoistIfThenElse added #6066
Conversation
239c924
to
fb38da8
Compare
Since nearly all programs will be touched by this pass, potential bugs in this pass would be critical. Could you (maybe temporarily) add this pass into the default building procedure and run all the tests? It would greatly reduce potential bugs. |
@roastduck : Thanks a lot for your input! |
a0d5cbe
to
09bf89f
Compare
09bf89f
to
1f59650
Compare
All the CI issues are resolved now. Also my internal tests shows good result. I think we can start review now. TIA! |
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.
LGTM
3207ea1
to
73e2d02
Compare
cc @ZihengJiang @merrymercy @Hzfengsy @kevinthesun @junrushao1994 @spectrometerHBH @wpan11nv @kparzysz-quic please help to take a look |
This is a limited case of "loop unswitching". Please consider a more general solution, where
is transformed into
Using the same logic you could unswitch attribute statements, if needed. |
Thanks for bringing up this point!
May be we can discuss more about first Challenge. Please suggest if anyone has any optimum solution for it. |
52835fe
to
cc36ae7
Compare
cc36ae7
to
04c5387
Compare
Gentle ping @tqchen , @ZihengJiang @merrymercy @Hzfengsy @kevinthesun @junrushao1994 @spectrometerHBH @wpan11nv @kparzysz-quic !!! Let us discuss and bring a conclusion to the open points / challenges mentioned in my previous comment. TIA! |
also cc @MarisaKirisame !!! |
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.
LGTM
0: I dont think a pass have to handle all cases for it to be merged. We can improve upon it incrementally. |
Thanks @MarisaKirisame for your enlightening response. I am in total agreement with all your points. :) |
I think we can go ahead and merge the PR, as most of the scenarios are handled. @tqchen : Would you please share your opinion on this. TIA! |
Need explicit approval https://tvm.apache.org/docs/contribute/code_review.html#approve-and-request-changes-explicitly from @kparzysz-quic @MarisaKirisame . The most important thing is the code clearity(others can understand the logic) and correctness. cc @ZihengJiang @junrushao1994 @vinx13 @zhiics it would be great if you can also take a look |
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 think this is ok for now.
I'll take a look in the next few days. |
One thing I think it is good to have in this PR is to get some benchmark data, since we now enable this pass by default. IMO this pass is especially valuable when tackling dynamic kernels in GPU which introduces a lot of branchings. It's great to see how much performance improvement we can have. For CPU, we need to make sure this pass doesn't introduce regression for some common workloads, such as resnet. |
@kevinthesun : Thanks a lot for your input! I believe all the cases which are covered now, does not degrade performance in any case either CPU or GPU :) |
Everything is green, but since @kevinthesun want to review it I will wait to merge for a few day. |
@kevinthesun : I have verified the inference time for Resnet50 on CPU. There is no performance impact. In fact i did not find anything as Hoisting candidate. Hoisting Disabled :Hoisting Enabled:Hope it helps. Please let me know, if i have mistaken anything. TIA! |
Usually there are two cases which might involve this pass: 1) Loop tiling with non-factor split. 2) Dynamic shape op. If I remember correctly, a conv2d with symbolic batch size will generate an IR with a lot of hoist candidates. Due to the limitation of nvcc, performance for such as kernel is quite terrible and this pass is able to handle this. It would be nice if we can verify this case for GPU and add a unit test. |
@kevinthesun : Thanks for your response! I think it would be better, i enable this hoisting scenario too and move the position of Hoisting Pass to the end of list during lowering. May be after that we can take the performance data. Please let me know your opinion on this. TIA! |
@ANSHUMAN87 Thanks for clarification. Though we might not need to do so in this PR, it would be great if we can bring this in since AFAIK gpu is the major case for this pass in tvm. |
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.
LGTM
Thanks a lot @MarisaKirisame , @roastduck @kevinthesun @kparzysz-quic @Hzfengsy, @tqchen ! This PR has 2 open points as per discussion with all the members participated. Summarizing as below:
I have kept it on my TODO list. Will ensure support of these cases in my future PRs. |
* [TIR][Transform] HoistIfThenElse added * lint error resolved * Pass position changed * pylint error resolved * CI issues resolved * Frontend tflite test case failure resolved * [1] Review comment handled * [2] Review comment handled * [3] Review comment handled * Lint error resolved
* [TIR][Transform] HoistIfThenElse added * lint error resolved * Pass position changed * pylint error resolved * CI issues resolved * Frontend tflite test case failure resolved * [1] Review comment handled * [2] Review comment handled * [3] Review comment handled * Lint error resolved
* [TIR][Transform] HoistIfThenElse added * lint error resolved * Pass position changed * pylint error resolved * CI issues resolved * Frontend tflite test case failure resolved * [1] Review comment handled * [2] Review comment handled * [3] Review comment handled * Lint error resolved
* [TIR][Transform] HoistIfThenElse added * lint error resolved * Pass position changed * pylint error resolved * CI issues resolved * Frontend tflite test case failure resolved * [1] Review comment handled * [2] Review comment handled * [3] Review comment handled * Lint error resolved
* [TIR][Transform] HoistIfThenElse added * lint error resolved * Pass position changed * pylint error resolved * CI issues resolved * Frontend tflite test case failure resolved * [1] Review comment handled * [2] Review comment handled * [3] Review comment handled * Lint error resolved
This is a follow up PR. Please refer #5559.
cc @kevinthesun , @roastduck , @zhiics , @junrushao1994 , @tqchen .
I have tried to cover all the possible scenarios. Please let me know in case i miss anything. TIA!