Skip to content

Conversation

@guan404ming
Copy link
Member

How

  • Implemented InferLayoutRepeat function that:
    • Preserves layout when axis is specified (with axis transformation)
    • Returns 1D layout when axis is not specified (flatten mode)
    • Transforms the axis parameter based on layout changes (e.g., NCHW axis=1 → NHWC axis=3)

@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 enhances the Relax framework by implementing layout inference for the repeat operator. This ensures that repeat operations correctly adapt to existing tensor layouts, either by preserving the layout and adjusting the specified axis or by producing a flattened 1D output when no axis is provided, thereby improving the robustness of layout transformations.

Highlights

  • Layout Inference for relax.repeat: Added FRelaxInferLayout for the relax.repeat operator to enable proper layout handling within the Relax framework.
  • Axis-aware Layout Preservation: When an axis is specified for the repeat operation, the existing tensor layout is preserved, and the axis parameter is automatically transformed to align with the new layout (e.g., NCHW axis=1 becomes NHWC axis=3).
  • Flattened Output for No Axis: If no axis is specified for the repeat operation, the system now correctly infers a 1D (flattened) output layout.
  • New Test Cases: Introduced two new test cases, test_conv2d_repeat and test_conv2d_repeat_flatten, to validate the layout inference behavior for repeat in scenarios involving both axis-specified and flattened outputs.
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 adds layout inference support for the relax.repeat operator. The implementation correctly handles two cases: when an axis is specified, it preserves the layout and transforms the axis accordingly; when no axis is specified, it correctly infers a 1D layout for the flattened output. The changes are well-tested with new unit tests covering both scenarios. My review includes a minor suggestion to improve code conciseness in the C++ implementation.

Comment on lines +1850 to +1857
int64_t new_axis = -1;
for (size_t i = 0; i < new_axis_str.size(); ++i) {
if (new_axis_str.at(i) == '1') {
new_axis = i;
break;
}
}
ICHECK_GE(new_axis, 0) << "Failed to find transformed axis";
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 loop to find the index of '1' can be simplified by using ffi::String::find, which is more idiomatic and concise.

  size_t pos = new_axis_str.find('1');
  ICHECK(pos != std::string::npos) << "Failed to find transformed axis";
  int64_t new_axis = static_cast<int64_t>(pos);

@guan404ming guan404ming marked this pull request as ready for review December 11, 2025 03:49
@guan404ming guan404ming force-pushed the add-repeat-layout-inference branch from 14d3e78 to 1a8740b Compare December 14, 2025 13:32
@guan404ming
Copy link
Member Author

guan404ming commented Dec 14, 2025

cc @tlopex @mshr-h

Copy link
Member

@tlopex tlopex left a comment

Choose a reason for hiding this comment

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

LGTM Thanks

@tlopex tlopex merged commit 44d973b into apache:main Dec 18, 2025
13 checks passed
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