The TensorFlow Lite interpreter currently implements a subset of TensorFlow operations, meaning some model architectures cannot immediately be converted due to missing operations.
Some RNN-based architectures are affected by this. The following document outlines the current state of play and provides strategies for converting RNN models.
Currently, RNN models using
can be converted successfully as long as no
sequence_length is specified.
tf.nn.rnn_cell operations work with
In addition, TensorFlow Lite provides some experimental drop-in replacements for RNN operations that enable dynamic RNN architectures with TensorFlow Lite.
Drop-in replacements are available for the following:
Not currently supported
TensorFlow Lite does not currently support Control Flow operations. This means that models built with the following TensorFlow functions will not convert successfully unless one of the conversion strategies below are employed:
To convert an RNN model that uses the functions specified above, you will have to modify its architecture and retrain it. The following strategies can be used.
The simplest approach, if possible, is to refactor the model architecture to use
2. Drop-in replacements that use op hints and fused ops
TensorFlow Lite provides the some experimental drop-in replacements for RNN operations that enable dynamic RNN architectures with TensorFlow Lite. Using OpHints, they run normally during training, but are substituted with special fused ops when run by the Lite interpreter.
The following drop-in replacements are available:
- replacement for tf.nn.dynamic_rnn
- replacement for tf.nn.bidirectional_dynamic_rnn
- replacement for tf.nn.rnn_cell.RNNCell
- replacement for tf.nn.rnn_cell.LSTMCell
For a tutorial on using these replacements, see TensorFlow Lite LSTM ops API.
For a Colab demonstrating these classes, refer to TensorFlowLite_LSTM_Keras_Tutorial.