TFLite NNAPI Delegate converts INT8 UnidirectionalSequenceLSTM to incorrect NN operation type
I've checked a few NNAPI delegate related posts. It looks like @miaowang14 has knowledge on this topic? If so I'd really appreciate some pointer! Thanks! Here is the dummy TFLite model to reproduce the NNAPI delegate issue: [lstm_w_emb_and_dense_3.8b.tflite.zip](https://github.com/tensorflow/tensorflow/files/11154211/lstm_w_emb_and_dense_3.8b.tflite.zip)
 Additionally, I've also tried the post-training dynamic range quantization which I would prefer to use. The result TFLite model of such quantization has float32 weights. Running that model with `use-nnapi` enabled shows that LSTM is not partitioned on NNAPI delegate. With `setprop debug.nn.vlog 1`, logcat info still does not show why LSTM cannot be partitioned to NNAPI delegate.

With the full integer INT8 quantization in post, at least I see that the entire graph is partitioned to NNAPI delegate. Would appreciate your thoughts here too! Hi @tiruk007, any chance dev can take a look? Thanks! For LSTM operation types, TFLite `builtin_ops.h` contains 3 variants `kTfLiteBuiltinLstm`, `kTfLiteBuiltinUnidirectionalSequenceLstm` and `kTfLiteBuiltinBidirectionalSequenceLstm` which is not distinguished by data types, see [here](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/builtin_ops.h#L74). On the NNAPI side, there're more LSTM operation variants, especially the quantized op has a separate operation type `ANEURALNETWORKS_QUANTIZED_LSTM`, which is distinguished from the float `ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_LSTM` variant, [here](https://developer.android.com/ndk/reference/group/neural-networks#group___neural_networks_1ggaabbe492c60331b13038e39d4207940e0aaf30e491ad0b1fc7602cbde695b2c859).

My understanding is that a full int8 TFLite `kTfLiteBuiltinUnidirectionalSequenceLstm` should be converted to NNAPI `ANEURALNETWORKS_QUANTIZED_LSTM` instead of the float variant.

However, in TFLite's `nnapi_delegate.cc`'s `Map` function, `kTfLiteBuiltinUnidirectionalSequenceLstm` is mapped to `ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_LSTM`, see [here](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc#L3810-L3837). This seems to lead to the NNAPI operation creation issue in post? Pls point out what i'm missing.

Besides, the `Validate` function seems to check and ensure `kTfLiteBuiltinUnidirectionalSequenceLstm` is not hybrid - which is a bit confusing. Could someone explain to me pls?
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

tf 2.12.0

### Custom Code

No

### OS Platform and Distribution

Android 12, aarch64

### Mobile device

Pixel 4 xl

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
I am trying to run a basic LSTM TFLite model with NNAPI delegate to explore the acceleration from Snapdragon 855's DSP Hexagon 690. I converted the simple LSTM model with full integer post-training quantization with intention to maximize hardware acceleration support, and ran this model on Pixel 4xl (snapdragon 855) with the latest pre-downloaded TFLite benchmark binary tool.

I am able to run other non-8bit model - env setup is correct. But 8bit model encountered error ` Unsupported input operand type for UNIDIRECTIONAL_SEQUENCE_LSTM op: TENSOR_QUANT8_ASYMM_SIGNED`.

I looked at NNAPI's operation support doc. It seems that operation `ANEURALNETWORKS_QUANTIZED_LSTM` is supported with the int8 inputs/outputs weights. But logcat suggests that TFLite NNAPI Model building process has converted the 8bit TFlite `UnidirectionalSequenceLSTM` to the non-quantized version `ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_LSTM`. Could this incorrect TFLite->NN operation conversion led to [this error](https://android.googlesource.com/platform/frameworks/ml/+/master/nn/common/operations/UnidirectionalSequenceLSTM.cpp#156)?
```


### Standalone code to reproduce the issue

```shell
### To make the dummy TFLite model

def representative_dataset():
"""Just to make dummy input data for full integer quantization"""
    for _ in range(100):
        data = np.random.rand(8, 16)
        yield [data.astype(np.float32)]

import tensorflow as tf
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Embedding, LSTM, Dense

# make keras model
units = 512
batch_size = 8

model_in = Input(shape=(16,), batch_size=batch_size)
model = Model(model_in, Dense(units, activation="relu")(LSTM(736)(Embedding(4001, units,)(model_in))))

# convert to TFLite format
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset
converter._experimental_default_to_single_batch_in_tensor_list_ops = True
tflite_model = converter.convert()
``` 

### To run on device with TFLite benchmark tool
Whether to turn `disable_nnapi_cpu`  to true or false makes no difference.
```
./android_aarch64_benchmark_model --graph=/data/local/model/lstm_w_emb_and_dense_3.8b.tflite --use_nnapi=true --verbose=true
```
```


### Relevant log output

```shell
--------- beginning of main
2023-04-04 17:24:18.427 19036-19036 tflite                  pid-19036                            I  STARTING!
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Log parameter values verbosely: [1]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Min num runs: [50]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Min runs duration (seconds): [1]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Max runs duration (seconds): [150]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Inter-run delay (seconds): [-1]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Number of prorated runs per second: [-1]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Num threads: [-1]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Use caching: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Benchmark name: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Output prefix: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Min warmup runs: [1]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Min warmup runs duration (seconds): [0.5]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Run w/o invoking kernels: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Report the peak memory footprint: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Memory footprint check interval (ms): [50]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Graph: [/data/local/model/lstm_w_emb_and_dense_3.8b.tflite]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Input layers: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Input shapes: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Input value ranges: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Input value files: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Allow fp16: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Require full delegation: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Enable op profiling: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Max initial profiling buffer entries: [1024]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Allow dynamic increase on profiling buffer entries: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  CSV File to export profiling data to: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Print pre-invoke interpreter state: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Print post-invoke interpreter state: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Release dynamic tensor memory: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Optimize memory usage for large tensors: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Disable delegate clustering: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  File path to export outputs layer to: []
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  print out all supported flags: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  #threads used for CPU inference: [-1]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Max number of delegated partitions: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Min nodes per partition: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Index of the first node that could be delegated: [0]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Index of the first node that could be delegated: [2147483647]
2023-04-04 17:24:18.428 19036-19036 tflite                  pid-19036                            I  Directory for delegate serialization: []
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Model-specific token/key for delegate serialization.: []
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  External delegate path: []
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  External delegate options: []
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Use gpu: [0]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Allow lower precision in gpu: [1]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Enable running quant models in gpu: [1]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Prefer maximizing the throughput in gpu: [0]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  GPU backend: []
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Use Hexagon: [0]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Hexagon lib path: [/data/local/tmp]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Hexagon profiling: [0]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Use NNAPI: [1]
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  NNAPI execution preference: []
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  Model execution priority in nnapi: []
2023-04-04 17:24:18.429 19036-19036 tflite                  pid-19036                            I  NNAPI accelerator name: []
2023-04-04 17:24:18.475 19036-19036 Manager                 pid-19036                            I  DeviceManager::DeviceManager
2023-04-04 17:24:18.475 19036-19036 Manager                 pid-19036                            I  findAvailableDevices
2023-04-04 17:24:18.475 19036-19036 ProcessState            pid-19036                            D  Binder ioctl to enable oneway spam detection failed: Invalid argument
2023-04-04 17:24:17.843     0-0     <no-tag>                kernel                               I  c7  19036 binder: 19036:19036 ioctl 40046210 7ff47b1524 returned -22
2023-04-04 17:24:18.476 19036-19036 hw-ProcessState         pid-19036                            D  Binder ioctl to enable oneway spam detection failed: Invalid argument
2023-04-04 17:24:17.844     0-0     <no-tag>                kernel                               I  c6  19036 binder: 19036:19036 ioctl 40046210 7ff47b1484 returned -22
2023-04-04 17:24:18.480 19036-19036 Manager                 pid-19036                            I  Found interface qti-default
2023-04-04 17:24:18.480 19036-19036 Manager                 pid-19036                            I  Found interface qti-dsp
2023-04-04 17:24:18.480 19036-19036 Manager                 pid-19036                            I  Found interface qti-gpu
2023-04-04 17:24:18.480 19036-19036 Manager                 pid-19036                            I  Found interface google-edgetpu
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  NNAPI accelerators available: [qti-default,qti-dsp,qti-gpu,google-edgetpu,nnapi-reference]
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  Disable NNAPI cpu: [0]
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  Allow fp16 in NNAPI: [0]
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  Allow dynamic dimensions in NNAPI: [0]
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  Use burst mode in NNAPI: [0]
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  Use xnnpack: [0]
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  Loaded model /data/local/model/lstm_w_emb_and_dense_3.8b.tflite
2023-04-04 17:24:18.480 19036-19036 tflite                  pid-19036                            I  Initialized TensorFlow Lite runtime.
2023-04-04 17:24:18.481 19036-19036 tflite                  pid-19036                            I  Created TensorFlow Lite delegate for NNAPI.
2023-04-04 17:24:18.481 19036-19036 tflite                  pid-19036                            I  NNAPI delegate created.
2023-04-04 17:24:18.482 19036-19036 tflite                  pid-19036                            I  Replacing 6 node(s) with delegate (TfLiteNnapiDelegate) node, yielding 1 partitions for the whole graph.
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 2 size 2048512
2023-04-04 17:24:18.482 19036-19036 TypeManager             pid-19036                            I  TypeManager::TypeManager
2023-04-04 17:24:18.482 19036-19036 TypeManager             pid-19036                            I  Failed to read /vendor/etc/nnapi_extensions_app_allowlist ; No app allowlisted for vendor extensions use.
2023-04-04 17:24:18.482 19036-19036 TypeManager             pid-19036                            I  NNAPI Vendor extensions enabled: 1
2023-04-04 17:24:18.482 19036-19036 TypeManager             pid-19036                            I  Registered extension com.google.edgetpu_precompiled
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 3 size 4
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  Copied small value to offset 0
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 5 size 376832
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 6 size 376832
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 7 size 376832
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 8 size 376832
2023-04-04 17:24:18.482 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 9 size 541696
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 10 size 541696
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 11 size 541696
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 12 size 541696
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 13 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 14 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 15 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 16 size 2944
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 17 size 2944
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 18 size 2944
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 19 size 2944
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Saving large value
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 20 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 21 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 24 size 4
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Copied small value to offset 4
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 25 size 4
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Copied small value to offset 8
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 26 size 4
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Copied small value to offset 12
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 27 size 1
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  Copied small value to offset 16
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 28 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 29 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 30 size 0
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            I  setOperandValue for operand 31 size 0
2023-04-04 17:24:18.483 19036-19036 Operations              pid-19036                            E  NN_RET_CHECK failed (packages/modules/NeuralNetworks/common/operations/UnidirectionalSequenceLSTM.cpp:160): Unsupported input operand type for UNIDIRECTIONAL_SEQUENCE_LSTM op: TENSOR_QUANT8_ASYMM_SIGNED
2023-04-04 17:24:18.483 19036-19036 ModelBuilder            pid-19036                            E  Invalid Operation: NN_RET_CHECK failed (packages/modules/NeuralNetworks/common/operations/UnidirectionalSequenceLSTM.cpp:160): Unsupported input operand type for UNIDIRECTIONAL_SEQUENCE_LSTM op: TENSOR_QUANT8_ASYMM_SIGNED
2023-04-04 17:24:18.483 19036-19036 tflite                  pid-19036                            E  NN API returned error ANEURALNETWORKS_BAD_DATA at line 1131 while adding operation.
2023-04-04 17:24:18.483 19036-19036 tflite                  pid-19036                            E  Node number 6 (TfLiteNnapiDelegate) failed to prepare.
2023-04-04 17:24:18.483 19036-19036 tflite                  pid-19036                            E  Restored original execution plan after delegate application failure.
2023-04-04 17:24:18.484 19036-19036 tflite                  pid-19036                            E  Failed to apply NNAPI delegate.
2023-04-04 17:24:18.484 19036-19036 tflite                  pid-19036                            E  Benchmarking failed.
```
</details>