Skip to content

Conversation

@guan404ming
Copy link
Member

Why

The LegalizeOps transform was using string matching to detect data-dependent operators by checking if "dynamic" appears in the operator name. This approach is fragile and doesn't scale well as new data-dependent operators are added.

How

  • Add FDataDependent operator attribute to properly mark data-dependent operators
  • Set FDataDependent=true for relax.dynamic_strided_slice operator
  • Update LegalizeOps transform to check the FDataDependent attribute instead of string matching

@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 refactors the identification of data-dependent operators within the LegalizeOps transform. Instead of relying on brittle string matching, a dedicated FDataDependent attribute is introduced. This change enhances the maintainability and extensibility of the system by providing a more explicit and robust mechanism for marking operators that exhibit data-dependent behavior, ensuring that the legalization process correctly handles such operations.

Highlights

  • New Operator Attribute: Introduced a new FDataDependent operator attribute to explicitly mark data-dependent operators, replacing a fragile string-matching approach.
  • Attribute Assignment: The relax.dynamic_strided_slice operator is now marked with FDataDependent=true.
  • LegalizeOps Update: The LegalizeOps transform has been updated to check for the FDataDependent attribute when identifying data-dependent operators, improving robustness and scalability.
  • New Test Case: Added a test case to verify the correct application and retrieval of the FDataDependent attribute for relevant operators.

🧠 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 is a great improvement, replacing fragile string matching for data-dependent operators with a dedicated FDataDependent attribute. This makes the LegalizeOps transform more robust and scalable. The changes in src/relax/op/tensor/index.cc to add the attribute and in tests/python/relax/test_transform_legalize_ops_index_linear_algebra.py to test it are clear and correct. I have one suggestion in src/relax/transform/legalize_ops.cc to simplify the attribute checking logic for better readability and conciseness.

Comment on lines +290 to +298
bool is_data_dependent_op = [&]() -> bool {
if (Op::HasAttrMap("FDataDependent")) {
auto op_map = Op::GetAttrMap<Bool>("FDataDependent");
if (op_map.count(op)) {
return op_map[op]->value;
}
}
return false;
}();
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This immediately-invoked lambda expression can be simplified to a more concise and idiomatic one-liner using Op::GetAttrMap and the .get() method with a default value. This will improve readability.

      bool is_data_dependent_op = Op::GetAttrMap<Bool>("FDataDependent").get(op, Bool(false))->value;

@guan404ming
Copy link
Member Author

cc @tlopex @mshr-h

@guan404ming guan404ming marked this pull request as ready for review January 16, 2026 09:55
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.

1 participant