Skip to content

[Relax][Frontend][TFLite] Add Conv3D support#19523

Merged
tlopex merged 1 commit intoapache:mainfrom
weicheng-hsu:relax/tflite-conv3d
May 9, 2026
Merged

[Relax][Frontend][TFLite] Add Conv3D support#19523
tlopex merged 1 commit intoapache:mainfrom
weicheng-hsu:relax/tflite-conv3d

Conversation

@weicheng-hsu
Copy link
Copy Markdown
Contributor

Description
This PR adds support for the CONV_3D operator in the TFLite frontend for Relax.

Key Changes

  • Operator Mapping: Added CONV_3D to the OperatorConverter mapping in tflite_frontend.py.
  • Implementation:
    • Implemented convert_conv3d to handle 3D convolution attributes such as StrideD/H/W, DilationD/H/W, and Padding.
    • Correctly handled the TFLite 3D kernel layout, which is expected to be DHWIO (Depth, Height, Width, Input Channels, Output Channels).
    • Integrated support for fused activation functions (ReLU, ReLU6, etc.) directly following the convolution.
  • Unit Tests:
    • Added comprehensive tests in tests/python/relax/test_frontend_tflite.py covering:
      • VALID and SAME padding modes.
      • Various stride and dilation configurations.
      • Verification against expected Relax IR structure.

Testing:

  • python3 -m pytest tests/python/relax/test_frontend_tflite.py -k "test_conv3d"

Notes for Reviewers
The implementation follows the existing pattern used for CONV_2D but extends it to the 5D case (NDHWC layout). I've ensured that the kernel layout mapping aligns with TVM's R.nn.conv3d requirements.

Related to: #19519

Copy link
Copy Markdown
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 implements the CONV_3D operator in the TFLite frontend for Relax, including the convert_conv3d method which handles attribute extraction, layout mapping (NDHWC/DHWIO), and padding calculations. Unit tests for "VALID" and "SAME" padding modes have also been added. The review feedback suggests removing commented-out code, ensuring consistency by using a 6-element padding list for 3D convolutions, and correcting a typo in an error message.

Comment on lines +2498 to +2499
# "kernel_size": [kernel_d, kernel_h, kernel_w],
"strides": [stride_d, stride_h, stride_w],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Remove the commented-out code to keep the implementation clean and maintainable.

Suggested change
# "kernel_size": [kernel_d, kernel_h, kernel_w],
"strides": [stride_d, stride_h, stride_w],
"strides": [stride_d, stride_h, stride_w],

# "kernel_size": [kernel_d, kernel_h, kernel_w],
"strides": [stride_d, stride_h, stride_w],
"dilation": [dilation_d, dilation_h, dilation_w],
"padding": [0, 0, 0],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For 3D convolution, it is more consistent to use a 6-element padding list (front, top, left, back, bottom, right) even for the zero-padding case. This aligns with the 6-element format used in the SAME padding logic and matches the expected IR structure in the unit tests.

Suggested change
"padding": [0, 0, 0],
"padding": [0, 0, 0, 0, 0, 0],

params["kernel_layout"] = "DHWIO"
if input_c != in_channels:
assert input_c % in_channels == 0, (
"Input channels is not divisible of kernel in_channels."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Typo in the error message: "divisible of" should be "divisible by".

Suggested change
"Input channels is not divisible of kernel in_channels."
"Input channels is not divisible by kernel in_channels."

This PR adds support for the CONV_3D operator in the TFLite frontend for Relax.
It includes:
- Implementation of convert_conv3d in OperatorConverter.
- Mapping of CONV_3D builtin operator.
- Unit tests to verify correctness with various padding and stride configurations.
@weicheng-hsu weicheng-hsu force-pushed the relax/tflite-conv3d branch from 9da3b2f to 9a361cc Compare May 8, 2026 20:31
@weicheng-hsu
Copy link
Copy Markdown
Contributor Author

weicheng-hsu commented May 8, 2026

Done. Updated the implementation to use consistent 6-element padding, removed redundant comments, and fixed the typo in the error message. Thanks!
#19523 (review)

Copy link
Copy Markdown
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

@tlopex tlopex merged commit 4ab312b into apache:main May 9, 2026
9 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