Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add int16 support to RELU #2727

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

andresovela
Copy link
Contributor

This PR adds int16 support to RELU

bug=#2726

TF_LITE_MICRO_TEST(SimpleReluTestInt16) {
const int elements_count = 10;

int input_shape[] = {2, 1, 5};
Copy link
Member

Choose a reason for hiding this comment

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

This should be 2, 2, 5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

int input_shape[] = {2, 1, 5};
const float input_data[] = {1, 2, 3, 4, 5, -1, -2, -3, -4, -5};
int16_t input_quantized[elements_count];
int output_shape[] = {2, 1, 5};
Copy link
Member

Choose a reason for hiding this comment

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

This should be 2, 2, 5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

In ReluPrepare the following code should be used to conform with TfLite (LiteRT):

  if (input->type == kTfLiteInt8) {
    CalculateReluOpData<int8_t>(input, output, data);
  }
  else if (input->type == kTfLiteInt16) {
    TF_LITE_ENSURE_EQ(context, input->params.zero_point, 0);
    TF_LITE_ENSURE_EQ(context, output->params.zero_point, 0);
    CalculateReluOpData<int16_t>(input, output, data);
  }

I am very surprised (and concerned) that the unit test passed, even though CalculateReluIOpData<int16_t> was not being called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might have had something to do with the chosen input data values. I changed them so that they need to are actually int16 values and then the test failed. Could be just a coincidence that it happened to work or there might be something else going elsewhere

@ddavis-2015
Copy link
Member

ddavis-2015 commented Oct 19, 2024

@andresovela

Thank you for submitting this PR. I have flagged the errors in the kernel and unit test above. On to @suleshahid for approval.

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.

3 participants