Skip to content

[Test][TFLite] Add unit tests for LEAKY_RELU, HARD_SWISH ReLU_N1_to_1 and LOG_SOFTMAX#19388

Merged
tlopex merged 6 commits into
apache:mainfrom
fnhirwa:main
Apr 11, 2026
Merged

[Test][TFLite] Add unit tests for LEAKY_RELU, HARD_SWISH ReLU_N1_to_1 and LOG_SOFTMAX#19388
tlopex merged 6 commits into
apache:mainfrom
fnhirwa:main

Conversation

@fnhirwa

@fnhirwa fnhirwa commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

This PR adds unit test coverage for activation function operators
in the Relax TFLite frontend, as part of #18971

  • Added the (tf.nn.log_softmax, R.nn.log_softmax) entry to elementwise unit test
  • Added unit test for LEAK_RELU with default alpha
  • Added unit test for HARD_SWISH
  • Added unit test for ReLU_N1_to_1

Bugs fixed:

  • relax.op.tensor.clip -> relax.op.clip in _relu6 helper of convert_hard_swish
  • relax.op.nn.leaky_relu -> relax.op.nn.leakyrelu in convert_leaky_relu

@github-actions github-actions Bot requested a review from tlopex April 11, 2026 02:20

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the TVM Relax TFLite frontend by renaming the leaky_relu operator to leakyrelu and updating the clip operator call. It also adds new test cases for leaky_relu, hard_swish, relu_n1_to_1, and log_softmax. The reviewer suggests using integer literals for the clip bounds in the hard_swish implementation and its associated test to ensure consistency with other activation functions and avoid potential overhead.


def _relu6(data):
return relax.op.tensor.clip(data, 0.0, 6.0)
return relax.op.clip(data, 0.0, 6.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 consistency with other activation functions implemented with clip in this file (like convert_relu6 and convert_relu_n1_to_1), it would be better to use integer literals for the clip bounds. This avoids potential overhead from using float64 bounds on a float32 tensor and improves consistency.

Suggested change
return relax.op.clip(data, 0.0, 6.0)
return relax.op.clip(data, 0, 6)

Comment on lines +1639 to +1641
lv1: R.Tensor((1, 30), dtype="float32") = R.clip(
lv, R.prim_value(T.float64(0.0)), R.prim_value(T.float64(6.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

To align with the suggested change of using integer clip bounds in convert_hard_swish, this expected IR should be updated. Using min and max arguments with integer values is also more consistent with test_relu_n1_to_1.

                lv1: R.Tensor((1, 30), dtype="float32") = R.clip(lv, min=0, max=6)

@tlopex tlopex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thank you

@tlopex tlopex merged commit 7196ac3 into apache:main Apr 11, 2026
6 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