[RNN] LSTM Model conversion error after upgrading to tf 2.16.1 from 2.15
@sonofisp,
By default the Tensorflow v2.16 contains the keras3.0 which might be the cause for the error. I suggest using the tf_keras 2.16 version for executing the code. Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/f66a1510824cbab5199e3efe3992910e/untitled1922.ipynb). 

Also add the below code for the execution.
```python
!pip install -U tf_keras # Keras 2
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"
```

Thank you!
 That works! Thanks a lot! Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/68797">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/68797">No</a>

### 1. System information

- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10/Debian
- TensorFlow installation (pip package or built from source): pip package
- TensorFlow library (version, if pip package or github SHA, if built from source): 2.16.1

### 2. Code

A minimum example that produced a tflite model when using tf 2.15.

```
import tensorflow as tf
import numpy as np

# generate random train data (32 samples, 1 time step, 10 features)
NUM_FEAT = 10
rand_train_data_x = np.array(np.random.randn(32, 1, NUM_FEAT), dtype=np.float32)
# generate targets of 3 classes
NUM_CLASSES = 3
rand_train_data_y = np.ones(32)
rand_train_data_y[0:11] = 0
rand_train_data_y[20:31] = 2
rand_train_data_y = np.array(tf.one_hot(rand_train_data_y, NUM_CLASSES)).reshape(
    -1, NUM_CLASSES
)
norm_layer = tf.keras.layers.Normalization(axis=-1)
norm_layer.adapt(rand_train_data_x)

x_train = norm_layer(rand_train_data_x)
y_train = tf.constant(rand_train_data_y)

# Build net
input_layer = tf.keras.Input(shape=(1, NUM_FEAT))
lstm_layer = tf.keras.layers.LSTM(
    NUM_FEAT, input_shape=(1, NUM_FEAT), dropout=0.2, recurrent_dropout=0.2
)(input_layer)
dense_layer = tf.keras.layers.Dense(15, activation="relu")(lstm_layer)
outputs = tf.keras.layers.Dense(NUM_CLASSES, activation="softmax")(dense_layer)
model = tf.keras.Model(inputs=[input_layer], outputs=outputs)

loss_fn = tf.keras.losses.MeanSquaredLogarithmicError()

model.compile(optimizer="adam", loss=loss_fn, metrics=["accuracy"])
print(model.summary())

model.fit(
    x_train,
    y_train,
    epochs=10,
)
model.export("test_model")  # , format="tf_saved_model")

converter = tf.lite.TFLiteConverter.from_saved_model("test_model")
converter.experimental_enable_resource_variables = True
converter.target_spec.supported_ops = [
    tf.lite.OpsSet.TFLITE_BUILTINS,
    tf.lite.OpsSet.SELECT_TF_OPS,
]
model_lite = converter.convert()

```

This leads to the following errors:
```
error: 'tfl.assign_variable' op operand #1 must be tensor of 32-bit float or 64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
loc(callsite(callsite(fused["ReadVariableOp:", "functional_1_1/lstm_1/ReadVariableOp_1@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): error: 'tfl.read_variable' op result #0 must be tensor of 32-bit float or 64-bit 
float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex 
type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
loc(callsite(callsite(fused["AssignVariableOp:", "functional_1_1/lstm_1/AssignVariableOp@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): error: 'tfl.assign_variable' op operand #1 must be tensor of 32-bit float or 64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
loc(callsite(callsite(fused["ReadVariableOp:", "functional_1_1/lstm_1/ReadVariableOp_3@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): error: 'tfl.read_variable' op result #0 must be tensor of 32-bit float or 64-bit 
float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex 
type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
loc(callsite(callsite(fused["AssignVariableOp:", "functional_1_1/lstm_1/AssignVariableOp_1@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): error: 'tfl.assign_variable' op operand #1 must be tensor of 32-bit float or 
64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
Traceback (most recent call last):
  File ".\lstm_minimum_bug.py", line 48, in <module>
    model_lite = converter.convert()
                 ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\lite.py", line 1175, in wrapper
    return self._convert_and_export_metrics(convert_func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\lite.py", line 1129, in _convert_and_export_metrics
    result = convert_func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\lite.py", line 1500, in convert
    return self._convert_from_saved_model(graph_def)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\lite.py", line 1367, in _convert_from_saved_model
    result = _convert_saved_model(**converter_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\convert_phase.py", line 212, in wrapper
    raise converter_error from None  # Re-throws the exception.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\convert_phase.py", line 205, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\convert.py", line 1012, in convert_saved_model
    data = convert(
           ^^^^^^^^
  File "C:\Python311\Lib\site-packages\tensorflow\lite\python\convert.py", line 367, in convert
    raise converter_error
tensorflow.lite.python.convert_phase.ConverterError: Variable constant folding is failed. Please consider using enabling `experimental_enable_resource_variables` flag in the TFLite converter object. For example, converter.experimental_enable_resource_variables = True<unknown>:0: error: 'tfl.assign_variable' op operand #1 must be tensor of 32-bit float or 64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 
32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
<unknown>:0: error: loc(callsite(callsite(fused["ReadVariableOp:", "functional_1_1/lstm_1/ReadVariableOp_1@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): 'tfl.read_variable' op result #0 must be tensor of 32-bit float or 64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
<unknown>:0: note: loc(fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"]): called from
<unknown>:0: error: loc(callsite(callsite(fused["AssignVariableOp:", "functional_1_1/lstm_1/AssignVariableOp@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): 'tfl.assign_variable' op operand #1 must be tensor of 32-bit float or 64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
<unknown>:0: note: loc(fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"]): called from
<unknown>:0: error: loc(callsite(callsite(fused["ReadVariableOp:", "functional_1_1/lstm_1/ReadVariableOp_3@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): 'tfl.read_variable' op result #0 must be tensor of 32-bit float or 64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
<unknown>:0: note: loc(fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"]): called from
<unknown>:0: error: loc(callsite(callsite(fused["AssignVariableOp:", "functional_1_1/lstm_1/AssignVariableOp_1@__inference___call___3175"] at fused["StatefulPartitionedCall:", "StatefulPartitionedCall@__inference_signature_wrapper___call___3218"]) at fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"])): 'tfl.assign_variable' op operand #1 must be tensor of 32-bit float or 64-bit float or 1-bit signless integer or 8-bit unsigned integer or 8-bit signless integer or QI8 type or QUI8 type or 32-bit signless integer or 64-bit signless integer or QI16 type or complex type with 32-bit float elements or complex type with 64-bit float elements values, but got 'tensor<2xui32>'
<unknown>:0: note: loc(fused["StatefulPartitionedCall:", "StatefulPartitionedCall_1"]): called from
```

### 5. (optional) Any other info / logs
I'm aware that this is using experimental settings, but I wanted to share the error I got and I'm wondering if there is a way to export a LSTM model to tflite that uses dropout? Or are these not supported for tflite? 
I never really tested the .tflite models that were exported with tf 2.15, because I had trouble with building the tensorflowlite_c.dll for tf 2.15 (this got solved with 2.16.1).
