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

do you have plan to optimize leaky_relu and tanh op for tflm? #527

Open
nyadla-sys opened this issue Aug 17, 2022 · 16 comments
Open

do you have plan to optimize leaky_relu and tanh op for tflm? #527

nyadla-sys opened this issue Aug 17, 2022 · 16 comments

Comments

@nyadla-sys
Copy link

nyadla-sys commented Aug 17, 2022

We are using himax board to run our custom model that uses leaky_relu and tanh ops on arc processor and currently we are running on tflm with C reference code and it takes lot of cycles to run inference, so could you please accelerate these ops on TFLM.

@nyadla-sys
Copy link
Author

We are in the process of enabling the below kernel for TFLM on HiMax WE1 board as one of our NN models uses the Tanh kernel heavily.
So we like to accelerate Tanh on ARC processors.
mli_status mli_krn_tanh_fx8(const mli_tensor * in, mli_tensor * out);
Do you plan to support this kernel for TFLM? If not please give us guidance to accelerate this kernel on TFLM for ARC EM9 processor(Himax WE1 board).

@nyadla-sys
Copy link
Author

nyadla-sys commented Sep 9, 2022

@mfarag13, @JaccovG, @Hakim7267 Please comment on this..
Actually I have ported mli_krn_leaky_relu_fx8(const mli_tensor * in, mli_tensor * slope_coeffs,mli_tensor * out) to tflm,however it is not outputting expected result.
if you are open to provide the feedback, I can share the patch which does leaky_relu acceleration on ARC processor on TFLM.

@JaccovG
Copy link
Contributor

JaccovG commented Sep 12, 2022

Hi,
Feel free to share the patch, I can review it.

@nyadla-sys
Copy link
Author

nyadla-sys commented Sep 13, 2022

@JaccovG
Please refer the attached patch along with changed leaky_relu files
https://drive.google.com/drive/folders/1lzRuglfxr4QXm_H2NRj3bwYyux_ZL42t?usp=sharing

@nyadla-sys
Copy link
Author

Here is output of one test from tflm leaky_relu_test.cc

Entering to prepare of is_mli_applicable
params->alpha 1.0*2^-1

fixed 8: 0x40

tensor->data.int8:0x40

Exiting to prepare of is_mli_applicable
Inside LeakyReluEval params->alpha:1.0*2^-1
Converted to Q7 fixed point tensor->data.int8:0x40

Entering EvalMLI

params->alpha:1.0*2^-1
mli tensor of slope coeffs Q7 fixed point :0x40
res:0

Exiting EvalMLI

expected_data[i] (1.02^0) near output_data[i] (1.59999932^1) failed at examples/kernel_add_test/add_test.cc:103
expected_data[i] (1.49999992^1) near output_data[i] (1.14999942^3) failed at examples/kernel_add_test/add_test.cc:103
expected_data[i] (1.02^0) near output_data[i] (1.59999932^-3) failed at examples/kernel_add_test/add_test.cc:103
expected_data[i] (-1.02^-1) near output_data[i] (1.59999932^1) failed at examples/kernel_add_test/add_test.cc:103
expected_data[i] (-1.02^0) near output_data[i] (1.02^-127) failed at examples/kernel_add_test/add_test.cc:103
Testing QuantizedActivationsOpTestLeakyReluInt8_2

@nyadla-sys
Copy link
Author

@JaccovG Could you please review patch and let us know your inputs

@nyadla-sys
Copy link
Author

@JaccovG Gentle reminder.!

@JaccovG
Copy link
Contributor

JaccovG commented Sep 20, 2022

I'm not able to access the google drive. could you share it as a github commit? or as a PR?

@nyadla-sys
Copy link
Author

@nyadla-sys
Copy link
Author

@JaccovG Gentle reminder.!

1 similar comment
@nyadla-sys
Copy link
Author

nyadla-sys commented Oct 4, 2022

@JaccovG Gentle reminder.!

@JaccovG
Copy link
Contributor

JaccovG commented Oct 5, 2022

sorry for my late reply, I was very busy.
I had a look at your code, and when you set the slope tensor, you force the exponent to 7.
https://github.com/usefulsensors/for_synopsys_review/blob/main/leaky_relu.cc#L91
I don't know the reason for setting it to 7, but maybe the problem is related to how the slope tensor is constructed.

@nyadla-sys
Copy link
Author

@JaccovG I have created q7 format for slope tensor,if this is something wrong could you please suggest.
What is the correct implementation for this

@JaccovG
Copy link
Contributor

JaccovG commented Oct 5, 2022

I couldn't quickly find how you did the conversion. it is fine to use q7 format as long as you shift the mantissa to match the exponent of 7. So what you need to check is if the slope value is correctly converted to the fixedpoint value.

@nyadla-sys
Copy link
Author

@nyadla-sys
Copy link
Author

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

No branches or pull requests

2 participants