Skip to content

Conversation

@guan404ming
Copy link
Member

Why

The conv1d_transpose and conv2d_transpose operators were missing FInferMixedPrecision and FRelaxInferLayout attribute implementations, which are needed for:

  • Mixed precision training/inference support (e.g., float16 inputs with float32 outputs)
  • Layout transformation optimizations during compilation
  • Consistency with conv1d and conv2d operators which already have these attributes

How

  • Implemented InferLayoutConv1dTranspose and InferMixedPrecisionConv1dTranspose
  • Implemented InferLayoutConv2dTranspose and InferMixedPrecisionConv2dTranspose

@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 conv1d_transpose and conv2d_transpose operators by integrating essential functionalities for mixed-precision processing and optimized data layout handling. These additions are crucial for improving the efficiency and flexibility of these operations within the framework, aligning them with the capabilities of their non-transpose counterparts.

Highlights

  • Mixed Precision Support: Implemented FInferMixedPrecision for conv1d_transpose and conv2d_transpose operators, enabling mixed precision training and inference (e.g., float16 inputs with float32 outputs).
  • Layout Transformation Optimization: Added FRelaxInferLayout for conv1d_transpose and conv2d_transpose, which facilitates layout transformation optimizations during compilation.
  • Consistency and Testing: Ensured consistency with existing conv1d and conv2d operators by adding these attributes and included new unit tests to verify the mixed precision inference for both transpose operations.

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

@guan404ming guan404ming force-pushed the add-conv-transpose-infer-attrs branch from 2adc83b to 5756731 Compare December 31, 2025 15:01
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 FInferMixedPrecision and FRelaxInferLayout support for conv1d_transpose and conv2d_transpose operators, which is a great addition for consistency and enabling optimizations. The implementations look correct and are accompanied by new tests. I've provided a few suggestions to improve code clarity and reduce duplication in the C++ implementation, and to enhance readability in the new Python tests.

Comment on lines +719 to +721
Layout desired_data_layout = (*it).second[0];
Layout desired_weight_layout = (*it).second[1];
Layout desired_output_layout = (*it).second.size() == 3 ? (*it).second[2] : (*it).second[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There is repeated code for accessing desired layouts. To improve readability and maintainability, you can store the desired layout strings in local variables and reuse them. This avoids repeating (*it).second access and the ternary logic for the output layout. You can then use these variables on lines 730-732.

Comment on lines +919 to +921
Layout desired_data_layout = (*it).second[0];
Layout desired_weight_layout = (*it).second[1];
Layout desired_output_layout = (*it).second.size() == 3 ? (*it).second[2] : (*it).second[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There is repeated code for accessing desired layouts. To improve readability and maintainability, you can store the desired layout strings in local variables at the beginning of the if block and reuse them. This avoids repeating (*it).second access and the ternary logic for the output layout. You can then use these variables to update new_attrs in lines 933-935 and 957-959.

Comment on lines +786 to +801
bb = relax.BlockBuilder()
x0 = relax.Var("x", R.Tensor((2, 3, 28), "float16"))
w0 = relax.Var("w", R.Tensor((3, 4, 3), "float16"))
x1 = relax.Var("x", R.Tensor((2, 3, 28), "int8"))
w1 = relax.Var("w", R.Tensor((3, 4, 3), "int8"))

_check_inference(
bb,
relax.op.nn.conv1d_transpose(x0, w0, out_dtype="float32"),
relax.TensorStructInfo((2, 4, 30), "float32"),
)
_check_inference(
bb,
relax.op.nn.conv1d_transpose(x1, w1, out_dtype="int32"),
relax.TensorStructInfo((2, 4, 30), "int32"),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better readability, consider using more descriptive variable names that indicate the data type, like x_f16, w_f16, x_i8, and w_i8.

Suggested change
bb = relax.BlockBuilder()
x0 = relax.Var("x", R.Tensor((2, 3, 28), "float16"))
w0 = relax.Var("w", R.Tensor((3, 4, 3), "float16"))
x1 = relax.Var("x", R.Tensor((2, 3, 28), "int8"))
w1 = relax.Var("w", R.Tensor((3, 4, 3), "int8"))
_check_inference(
bb,
relax.op.nn.conv1d_transpose(x0, w0, out_dtype="float32"),
relax.TensorStructInfo((2, 4, 30), "float32"),
)
_check_inference(
bb,
relax.op.nn.conv1d_transpose(x1, w1, out_dtype="int32"),
relax.TensorStructInfo((2, 4, 30), "int32"),
)
bb = relax.BlockBuilder()
x_f16 = relax.Var("x", R.Tensor((2, 3, 28), "float16"))
w_f16 = relax.Var("w", R.Tensor((3, 4, 3), "float16"))
x_i8 = relax.Var("x", R.Tensor((2, 3, 28), "int8"))
w_i8 = relax.Var("w", R.Tensor((3, 4, 3), "int8"))
_check_inference(
bb,
relax.op.nn.conv1d_transpose(x_f16, w_f16, out_dtype="float32"),
relax.TensorStructInfo((2, 4, 30), "float32"),
)
_check_inference(
bb,
relax.op.nn.conv1d_transpose(x_i8, w_i8, out_dtype="int32"),
relax.TensorStructInfo((2, 4, 30), "int32"),
)

Comment on lines +1594 to +1609
bb = relax.BlockBuilder()
x0 = relax.Var("x", R.Tensor((2, 3, 28, 28), "float16"))
w0 = relax.Var("w", R.Tensor((3, 4, 3, 3), "float16"))
x1 = relax.Var("x", R.Tensor((2, 3, 28, 28), "int8"))
w1 = relax.Var("w", R.Tensor((3, 4, 3, 3), "int8"))

_check_inference(
bb,
relax.op.nn.conv2d_transpose(x0, w0, out_dtype="float32"),
relax.TensorStructInfo((2, 4, 30, 30), "float32"),
)
_check_inference(
bb,
relax.op.nn.conv2d_transpose(x1, w1, out_dtype="int32"),
relax.TensorStructInfo((2, 4, 30, 30), "int32"),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better readability, consider using more descriptive variable names that indicate the data type, like x_f16, w_f16, x_i8, and w_i8.

Suggested change
bb = relax.BlockBuilder()
x0 = relax.Var("x", R.Tensor((2, 3, 28, 28), "float16"))
w0 = relax.Var("w", R.Tensor((3, 4, 3, 3), "float16"))
x1 = relax.Var("x", R.Tensor((2, 3, 28, 28), "int8"))
w1 = relax.Var("w", R.Tensor((3, 4, 3, 3), "int8"))
_check_inference(
bb,
relax.op.nn.conv2d_transpose(x0, w0, out_dtype="float32"),
relax.TensorStructInfo((2, 4, 30, 30), "float32"),
)
_check_inference(
bb,
relax.op.nn.conv2d_transpose(x1, w1, out_dtype="int32"),
relax.TensorStructInfo((2, 4, 30, 30), "int32"),
)
bb = relax.BlockBuilder()
x_f16 = relax.Var("x", R.Tensor((2, 3, 28, 28), "float16"))
w_f16 = relax.Var("w", R.Tensor((3, 4, 3, 3), "float16"))
x_i8 = relax.Var("x", R.Tensor((2, 3, 28, 28), "int8"))
w_i8 = relax.Var("w", R.Tensor((3, 4, 3, 3), "int8"))
_check_inference(
bb,
relax.op.nn.conv2d_transpose(x_f16, w_f16, out_dtype="float32"),
relax.TensorStructInfo((2, 4, 30, 30), "float32"),
)
_check_inference(
bb,
relax.op.nn.conv2d_transpose(x_i8, w_i8, out_dtype="int32"),
relax.TensorStructInfo((2, 4, 30, 30), "int32"),
)

@guan404ming guan404ming force-pushed the add-conv-transpose-infer-attrs branch from 5040008 to f0ce8fb Compare January 1, 2026 08:40
@guan404ming guan404ming marked this pull request as ready for review January 1, 2026 10:32
@guan404ming
Copy link
Member Author

cc @tlopex @mshr-h

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