Optional supported_types argument for quantization with lite.TFLiteConverter
@alexrosen45 thanks for your efforts on https://github.com/tensorflow/tensorflow/issues/60884  , it was nice to see your reasoning, even if I was well aware of where and how the problem was happening.  However what you propose is not a solution to the problem. I was aware of the parameter you suggested to change and did not use it for a very good reason.  In effect, by setting converter.target_spec.supported_types = [tf.int8]  as you suggest,  you are telling the converter to ignore the fact that we want 16-8 quantization and and forcing it to quantize at int8 only.  This should not be set automatically or checked in the manner you proposed. @DerryFitz I see, thanks for clarifying. Running
```
import tensorflow as tf
import numpy as np

inp = tf.keras.Input([1, 1], batch_size = 1, name = "input_0")
x = tf.keras.layers.LSTM(inp.shape[2], return_sequences = True)(inp)
model_lstm = tf.keras.Model(inputs=inp, outputs=x)

# pick some representative dataset
rep_data = tf.data.Dataset.from_tensor_slices(np.float32(np.random.random_sample((10,1,1,1))))

def representative_dataset():
    for data in rep_data:
        yield [data]

converter = tf.lite.TFLiteConverter.from_keras_model(model_lstm)
converter.representative_dataset = representative_dataset
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.EXPERIMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8]
tflite_model = converter.convert()

# allocate tensors
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()
```
which should accomplish what you want to do gives ```RuntimeError: Quantization to 16x8-bit not yet supported for op: 'UNIDIRECTIONAL_SEQUENCE_LSTM'```, a better error message than before. This should be addressed in a separate PR. I'm going to keep this PR open anyways because a supported types argument seems cleaner, and I'll get on support for 16-8 quantization for LSTMs soon. Hi @JunyoungLim Can you please review this PR ? Thank you! Hi @JunyoungLim Can you please review this PR ? Thank you! Hi @terryheo Can you please review this PR ? Thank you! Hi @rascani Can you please review this PR ? Thank you! Hi @rascani Can you please review this PR ? Thank you! Hi @alexrosen45 Can you please resolve conflicts? Thank you! This PR is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you. This PR was closed because it has been inactive for 14 days since being marked as stale. Please reopen if you'd like to work on this further.
This is a fix for issue https://github.com/tensorflow/tensorflow/issues/60884. If we initialize some ```TFLiteConverter``` object ```converter = tf.lite.TFLiteConverter.from_keras_model(model)```, then in order to customize quantization, we must first change our converter's supported types. For example, before running
```
converter.target_spec.supported_ops = [
    tf.lite.OpsSet.TFLITE_BUILTINS,
    tf.lite.OpsSet.EXPERIMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8
]
```
we must run ```converter.target_spec.supported_types = [tf.int8]```. This behaviour is clunky and the extra line goes undocumented. The proposed changes allow us to omit ```converter.target_spec.supported_types = [tf.int8]``` and simply change our ```supported_types``` during the initialization of our converter:
```converter = tf.lite.TFLiteConverter.from_keras_model(model, supported_types=[tf.int8])```.