TFLite for LSTM: Downscale accumulation from 32-bit to 16-bit before applying to activation
hi @Kullka ,

Can you please share the code to reproduce the issue ?  Hi @sawantkumar,

Thank you for responding me. I have converted LSTM model from TensorFlow to TensorFlow Lite by following code:
![image](https://github.com/tensorflow/tensorflow/assets/93808532/5a157d51-8290-470e-9e7e-216625e5c29a)

After converting, I used netron app to visualize the model and use the parameters on tflite model to implement inference LSTM on FPGA. 
![image](https://github.com/tensorflow/tensorflow/assets/93808532/ad0d3b70-9292-4694-b565-86b7ea240169)

The Input and Weight are quantized as int8, so I found in https://github.com/tensorflow/tensorflow/blob/e33a5ea470d1ef02107b595737d23670f7a1eda4/tensorflow/lite/kernels/unidirectional_sequence_lstm.cc#L1482-L1497 the method lstm_eval::EvalInteger8x8_16 match with the model's parameters. In this method, I found the code here with many parameters and not sure how to get these parameters. https://github.com/tensorflow/tensorflow/blob/e33a5ea470d1ef02107b595737d23670f7a1eda4/tensorflow/lite/kernels/lstm_eval.cc#L2438

I saw the way to find the parameter input_to_gate_effective_bias in method _prepare_ in file unidirectional_sequence_lstm.cc but the parameter gate_layer_norm_coefficients can't found anywhere. 

Finally, assume I have all parameters, should I follow method https://github.com/tensorflow/tensorflow/blob/e33a5ea470d1ef02107b595737d23670f7a1eda4/tensorflow/lite/kernels/lstm_eval.cc#L1420 and then https://github.com/tensorflow/tensorflow/blob/e33a5ea470d1ef02107b595737d23670f7a1eda4/tensorflow/lite/kernels/lstm_eval.cc#L554 to understand the way to implement LSTM?  Correct me if I wrong!

Thank you.
 Hi @Kullka, we're wondering if you may be able to resolve your issue by using [AI-Edge-Torch](https://github.com/google-ai-edge/ai-edge-torch), you can find more information here: [googleblog](https://developers.googleblog.com/en/ai-edge-torch-high-performance-inference-of-pytorch-models-on-mobile-devices/).

I have actually created a simple script for converting an LSTM model here:

```py
import torch
import torchvision
import ai_edge_torch

rnn = torch.nn.LSTM(10, 20, 2)
sample_inputs = (torch.randn(5, 3, 10),)

edge_model = ai_edge_torch.convert(rnn.eval(), sample_inputs)
edge_model.export("rnn.tflite")
```

If you want to, you can actually try visualizing the result in [model-explorer](https://github.com/google-ai-edge/model-explorer) as well.

Please try them out and let us know if this resolves your issue. If you still need further help, feel free to open a new issue at the respective repos.
Hello everyone,

I have converted LSTM model from TensorFlow to TensorFlow Lite. I realized that Inputs and Weights (include input_input(forget, cell, output)_weights and recurrent_input(forget, cell, output)_weights) are quantized to Int8 but Biases are quantized to 32-bit. After performing Weights*Inputs + Biases, I have 32-bit accumulation. These results are applied to activation (Sigmoid and Tanh) but the input of these activation is 16-bit. I wonder how to downscale the accumulation from 32-bit to 16-bit before applying activation. Can you help me. Thanks!