-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Relax] Add FRelaxInferLayout and TMixedPrecisionPolicy for dynamic_strided_slice #18633
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
[Relax] Add FRelaxInferLayout and TMixedPrecisionPolicy for dynamic_strided_slice #18633
Conversation
Summary of ChangesHello @guan404ming, 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 integrates the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 correctly adds the TMixedPrecisionPolicy to the dynamic_strided_slice operator, enabling it for mixed-precision transformations. The added test case is also relevant. However, the expected output in the new test contains a redundant and inefficient sequence of data type casts. I've included a specific comment with a suggestion to simplify the test's expected output, which would reflect a more optimal transformation.
| lv3: R.Tensor((2, 4, 26, 26), dtype="float16") = R.astype(lv2, dtype="float16") | ||
| lv4: R.Tensor((2, 4, 26, 26), dtype="float32") = R.astype(lv3, dtype="float32") | ||
| gv: R.Tensor(None, dtype="float32", ndim=4) = R.dynamic_strided_slice(lv4, begin, end, strides) |
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 Expected module contains a redundant sequence of casts. The conv2d output lv2 is float32. It is cast to float16 (as lv3), then immediately back to float32 (as lv4), before being used in dynamic_strided_slice. This is inefficient.
Since dynamic_strided_slice is a kFollow operator and its input from the preceding conv2d is already float32, the intermediate casts are unnecessary. The dynamic_strided_slice operator can directly use the lv2 tensor. The expected transformed code should be more optimal.
| lv3: R.Tensor((2, 4, 26, 26), dtype="float16") = R.astype(lv2, dtype="float16") | |
| lv4: R.Tensor((2, 4, 26, 26), dtype="float32") = R.astype(lv3, dtype="float32") | |
| gv: R.Tensor(None, dtype="float32", ndim=4) = R.dynamic_strided_slice(lv4, begin, end, strides) | |
| gv: R.Tensor(None, dtype="float32", ndim=4) = R.dynamic_strided_slice(lv2, begin, end, strides) |
b79fe03 to
8cbad7a
Compare
| R.output(gv) | ||
| return gv | ||
|
|
||
| _assert_test(Input, Expected) |
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.
Why we don't use tvm.ir.assert_structural_equal here?
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.
_assert_test is shared helper func in this file. I use it for consistency here. Shall we update to use tvm.ir.assert_structural_equal?
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.
No worries, I had a look and it's nearly the same
| R.output(gv) | ||
| return gv | ||
|
|
||
| _assert_test(Input, Expected) |
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.
No worries, I had a look and it's nearly the same
Thanks! |
Why
The dynamic_strided_slice operator was missing FRelaxInferLayout and TMixedPrecisionPolicy attributes, preventing it from participating in layout transformations and mixed precision optimizations.
How
TMixedPrecisionPolicyattribute withkFollowpolicy andInferLayoutDynStridedSlicefunction that falls back to initial layout (since begin/end/strides are dynamic tensors that cannot be transformed at compile time)