-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[TIR][Schedule] FuseReductionEpilogue: Add Clipping pattern support #18515
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 Clipping pattern support #18515
Conversation
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 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 is a great pull request that extends FuseReductionEpilogue to support clipping patterns, a common and important operation in deep learning models. The implementation is clean, well-structured, and includes comprehensive test coverage for correctness and various commutative patterns. The documentation is also thoughtfully updated with a clear warning about the semantic change for non-linear epilogues, which is crucial for users. I have a couple of suggestions to make the fusion logic even more robust and general.
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.
Currently, the FuseReductionEpilogue primitive only supports Bias (addition) and BiasReLU (addition + ReLU) epilogue patterns. However, clipping operations (min(max(x, lower), upper)) are commonly used in deep learning models and would benefit from the same fusion optimization. This commit extends FuseReductionEpilogue to support Clipping patterns by: 1. Adding EpilogueType::Clipping to the enum to distinguish clipping patterns from other epilogue types. 2. Adding clipping_lower_ and clipping_upper_ members to ReductionEpilogueFuser to store clipping bounds extracted from the epilogue pattern. 3. Extending AnalyzeEpiloguePattern to detect clipping patterns: - min(max(temp, lower), upper) - max(min(temp, upper), lower) - All commutative variants of min/max at each level 4. Updating BiasReLU pattern matching to handle max(0, x) form in addition to max(x, 0) for better commutativity support. 5. Modifying CreateFusedReductionBlock to apply clipping to the init value: init = min(max(0, lower), upper) 6. Updating BufferReplacer to apply clipping per-iteration: value = min(max(value, lower), upper) 7. Adding validation in BodyPatternAllowFusion to ensure temp appears exactly once in clipping patterns. 8. Creating comprehensive test coverage with 8 test cases: - Basic fusion test - Numerical correctness verification - Multiple epilogue blocks test - 5 commutative variant tests This implementation follows the same per-iteration semantics as BiasReLU, where clipping is applied at each reduction step rather than post-reduction. This semantic change is documented in the docstring with a warning about potential numerical differences. The test suite verifies that all commutative forms of clipping patterns are correctly recognized and that the fused implementation produces numerically identical results to the per-iteration reference implementation.
Currently, the FuseReductionEpilogue primitive only supports Bias (addition) and BiasReLU (addition + ReLU) epilogue patterns. However, clipping operations (min(max(x, lower), upper)) are commonly used in deep learning models and would benefit from the same fusion optimization. This commit extends FuseReductionEpilogue to support Clipping patterns by: 1. Adding EpilogueType::Clipping to the enum to distinguish clipping patterns from other epilogue types. 2. Adding clipping_lower_ and clipping_upper_ members to ReductionEpilogueFuser to store clipping bounds extracted from the epilogue pattern. 3. Extending AnalyzeEpiloguePattern to detect clipping patterns: - min(max(temp, lower), upper) - max(min(temp, upper), lower) - All commutative variants of min/max at each level 4. Updating BiasReLU pattern matching to handle max(0, x) form in addition to max(x, 0) for better commutativity support. 5. Modifying CreateFusedReductionBlock to apply clipping to the init value: init = min(max(0, lower), upper) 6. Updating BufferReplacer to apply clipping per-iteration: value = min(max(value, lower), upper) 7. Adding validation in BodyPatternAllowFusion to ensure temp appears exactly once in clipping patterns. 8. Creating comprehensive test coverage with 8 test cases: - Basic fusion test - Numerical correctness verification - Multiple epilogue blocks test - 5 commutative variant tests This implementation follows the same per-iteration semantics as BiasReLU, where clipping is applied at each reduction step rather than post-reduction. This semantic change is documented in the docstring with a warning about potential numerical differences. The test suite verifies that all commutative forms of clipping patterns are correctly recognized and that the fused implementation produces numerically identical results to the per-iteration reference implementation.
9d4a68a to
b074e04
Compare
…ktrace These submodules were incorrectly added but not defined in .gitmodules, causing CI failures. They should not be tracked as submodules.
Currently, the FuseReductionEpilogue primitive only supports Bias (addition) and BiasReLU (addition + ReLU) epilogue patterns. However, clipping operations (min(max(x, lower), upper)) are commonly used in deep learning models and would benefit from the same fusion optimization. This commit extends FuseReductionEpilogue to support Clipping patterns by: 1. Adding EpilogueType::Clipping to the enum to distinguish clipping patterns from other epilogue types. 2. Adding clipping_lower_ and clipping_upper_ members to ReductionEpilogueFuser to store clipping bounds extracted from the epilogue pattern. 3. Extending AnalyzeEpiloguePattern to detect clipping patterns: - min(max(temp, lower), upper) - max(min(temp, upper), lower) - All commutative variants of min/max at each level 4. Updating BiasReLU pattern matching to handle max(0, x) form in addition to max(x, 0) for better commutativity support. 5. Modifying CreateFusedReductionBlock to apply clipping to the init value: init = min(max(0, lower), upper) 6. Updating BufferReplacer to apply clipping per-iteration: value = min(max(value, lower), upper) 7. Adding validation in BodyPatternAllowFusion to ensure temp appears exactly once in clipping patterns. 8. Creating comprehensive test coverage with 8 test cases: - Basic fusion test - Numerical correctness verification - Multiple epilogue blocks test - 5 commutative variant tests This implementation follows the same per-iteration semantics as BiasReLU, where clipping is applied at each reduction step rather than post-reduction. This semantic change is documented in the docstring with a warning about potential numerical differences. The test suite verifies that all commutative forms of clipping patterns are correctly recognized and that the fused implementation produces numerically identical results to the per-iteration reference implementation.
Currently, the FuseReductionEpilogue primitive only supports Bias (addition) and BiasReLU (addition + ReLU) epilogue patterns. However, clipping operations (min(max(x, lower), upper)) are commonly used in deep learning models and would benefit from the same fusion optimization. This commit extends FuseReductionEpilogue to support Clipping patterns by: 1. Adding EpilogueType::Clipping to the enum to distinguish clipping patterns from other epilogue types. 2. Adding clipping_lower_ and clipping_upper_ members to ReductionEpilogueFuser to store clipping bounds extracted from the epilogue pattern. 3. Extending AnalyzeEpiloguePattern to detect clipping patterns: - min(max(temp, lower), upper) - max(min(temp, upper), lower) - All commutative variants of min/max at each level 4. Updating BiasReLU pattern matching to handle max(0, x) form in addition to max(x, 0) for better commutativity support. 5. Modifying CreateFusedReductionBlock to apply clipping to the init value: init = min(max(0, lower), upper) 6. Updating BufferReplacer to apply clipping per-iteration: value = min(max(value, lower), upper) 7. Adding validation in BodyPatternAllowFusion to ensure temp appears exactly once in clipping patterns. 8. Creating comprehensive test coverage with 8 test cases: - Basic fusion test - Numerical correctness verification - Multiple epilogue blocks test - 5 commutative variant tests This implementation follows the same per-iteration semantics as BiasReLU, where clipping is applied at each reduction step rather than post-reduction. This semantic change is documented in the docstring with a warning about potential numerical differences. The test suite verifies that all commutative forms of clipping patterns are correctly recognized and that the fused implementation produces numerically identical results to the per-iteration reference implementation.
|
@wrongtest-intellif |
Currently, the FuseReductionEpilogue primitive only supports Bias
(addition) and BiasReLU (addition + ReLU) epilogue patterns. However,
clipping operations (min(max(x, lower), upper)) are commonly used in
deep learning models and would benefit from the same fusion optimization.
This commit extends FuseReductionEpilogue to support Clipping patterns
by:
Adding EpilogueType::Clipping to the enum to distinguish clipping
patterns from other epilogue types.
Adding clipping_lower_ and clipping_upper_ members to
ReductionEpilogueFuser to store clipping bounds extracted from the
epilogue pattern.
Extending AnalyzeEpiloguePattern to detect clipping patterns:
Updating BiasReLU pattern matching to handle max(0, x) form in
addition to max(x, 0) for better commutativity support.
Modifying CreateFusedReductionBlock to apply clipping to the init
value: init = min(max(0, lower), upper)
Updating BufferReplacer to apply clipping per-iteration:
value = min(max(value, lower), upper)
Adding validation in BodyPatternAllowFusion to ensure temp appears
exactly once in clipping patterns.
Creating comprehensive test coverage with 8 test cases:
This implementation follows the same per-iteration semantics as BiasReLU,
where clipping is applied at each reduction step rather than
post-reduction. This semantic change is documented in the docstring with
a warning about potential numerical differences.
The test suite verifies that all commutative forms of clipping patterns
are correctly recognized and that the fused implementation produces
numerically identical results to the per-iteration reference
implementation.