Skip to content

Conversation

@guan404ming
Copy link
Member

@guan404ming guan404ming commented Jan 4, 2026

Why

The dynamic_strided_slice operator was missing FRelaxInferLayout and TMixedPrecisionPolicy attributes, preventing it from participating in layout transformations and mixed precision optimizations.

How

  • Add TMixedPrecisionPolicy attribute with kFollow policy and
  • Add InferLayoutDynStridedSlice function that falls back to initial layout (since begin/end/strides are dynamic tensors that cannot be transformed at compile time)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 relax.dynamic_strided_slice operator into the mixed precision transformation system. Previously, this operator was not considered during mixed precision optimizations, which could hinder performance in scenarios utilizing lower precision computations like FP16. By adding the necessary policy and corresponding tests, the operator can now seamlessly participate in mixed precision graphs, contributing to more efficient model execution.

Highlights

  • Mixed Precision Support: The relax.dynamic_strided_slice operator now supports mixed precision transformations by registering the TMixedPrecisionPolicy attribute.
  • Precision Policy: The TMixedPrecisionPolicy for dynamic_strided_slice is set to MixedPrecisionPolicyKind::kFollow, meaning it will adapt its precision based on its input.
  • Test Coverage: New test cases have been added to test_transform_to_mixed_precision.py to validate the correct behavior of dynamic_strided_slice within mixed precision workflows.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 1109 to 1111
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

@guan404ming guan404ming changed the title [Relax] Add TMixedPrecisionPolicy for dynamic_strided_slice [Relax] Add FRelaxInferLayout and TMixedPrecisionPolicy for dynamic_strided_slice Jan 4, 2026
@guan404ming guan404ming force-pushed the add-tmixedprecisionpolicy-dynamic-strided-slice branch from b79fe03 to 8cbad7a Compare January 4, 2026 17:27
@guan404ming guan404ming marked this pull request as ready for review January 5, 2026 11:17
@guan404ming
Copy link
Member Author

cc @tlopex @mshr-h

R.output(gv)
return gv

_assert_test(Input, Expected)
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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)
Copy link
Member

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

@tlopex tlopex merged commit 304a74a into apache:main Jan 5, 2026
17 checks passed
@guan404ming
Copy link
Member Author

No worries, I had a look and it's nearly the same

Thanks!

@guan404ming guan404ming deleted the add-tmixedprecisionpolicy-dynamic-strided-slice branch January 5, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants