-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[TIR][Schedule] FuseReductionEpilogue: Add ReLU support #18508
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
base: main
Are you sure you want to change the base?
[TIR][Schedule] FuseReductionEpilogue: Add ReLU support #18508
Conversation
The FuseReductionEpilogue primitive currently supports fusing bias addition epilogues into reduction blocks. This commit extends the primitive to also support ReLU activation functions in epilogue blocks, enabling fusion of patterns like max(temp + bias, 0) into the reduction computation. The implementation adds an EpilogueType enumeration to distinguish between Bias and BiasReLU patterns. The AnalyzeEpiloguePattern method is extended to detect ReLU patterns by checking for MaxNode expressions with zero constants. This commit also adds comprehensive tests in test_tir_schedule_fuse_reduction_epilogue_relu.py, following the same patterns as the existing bias tests. The tests verify structural equality, numerical correctness with per-iteration ReLU semantics, and multiple epilogue block scenarios. All tests pass successfully.
Summary of ChangesHello @kimm240, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the FuseReductionEpilogue primitive by adding support for ReLU activation functions. This allows for more aggressive fusion of common patterns like max(temp + bias, 0) directly into reduction computations, which can lead to improved performance by reducing memory traffic and increasing computational density. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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 Review
This pull request extends the FuseReductionEpilogue primitive to support ReLU activation functions, which is a great enhancement. The implementation is clean and follows existing patterns. The addition of EpilogueType to differentiate between Bias and BiasReLU is a good approach. The new tests are comprehensive, covering structural equality, numerical correctness with per-iteration ReLU semantics, and multiple epilogue scenarios. I have one minor suggestion to simplify the code.
| bool is_zero_const = false; | ||
| if (tir::is_zero(max_node->b)) { | ||
| is_zero_const = true; | ||
| } else if (const auto* float_imm = max_node->b.as<FloatImmNode>()) { | ||
| is_zero_const = (float_imm->value == 0.0); | ||
| } |
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.
The tir::is_zero function handles both integer and floating-point zero constants, so the else if condition checking for FloatImmNode is redundant. This check can be simplified.
| bool is_zero_const = false; | |
| if (tir::is_zero(max_node->b)) { | |
| is_zero_const = true; | |
| } else if (const auto* float_imm = max_node->b.as<FloatImmNode>()) { | |
| is_zero_const = (float_imm->value == 0.0); | |
| } | |
| bool is_zero_const = tir::is_zero(max_node->b); |
|
@wrongtest-intellif Furthermore, this enhancement allows TVM to accurately recognize complex but standardized patterns, such as |
The FuseReductionEpilogue primitive currently supports fusing bias addition epilogues into reduction blocks. This commit extends the primitive to also support ReLU activation functions in epilogue blocks, enabling fusion of patterns like max(temp + bias, 0) into the reduction computation.
The implementation adds an EpilogueType enumeration to distinguish between Bias and BiasReLU patterns. The AnalyzeEpiloguePattern method is extended to detect ReLU patterns by checking for MaxNode expressions with zero constants.
This commit also adds comprehensive tests in
test_tir_schedule_fuse_reduction_epilogue_relu.py, following the same patterns as the existing bias tests. The tests verify structural equality, numerical correctness with per-iteration ReLU semantics, and multiple epilogue block scenarios. All tests pass successfully.