Are LSTM models deployable using Python SDK?

Question/Issue:
Are LSTM models deployable using Python SDK?
Project ID:
ID: 8443567
Context/Use case:
I am trying to deploy a Pytorch model using the LSTM layer. I converted the model to Onnx and deploy it to the Python SDK. This is the error that I got:

Trying conversion using onnx2tf...
e[31mERROR:e[0m LSTM OP is not yet implemented.

Conversion using onnx2tf failed, trying conversion using onnx-tf...
ERROR: Could not load albumentations library. This is a known issue during unit tests on M1 Macs (#3880) and will prevent object detection augmentation from working. 
Original error message:
 No module named 'albumentations'
Traceback (most recent call last):
  File "/app/convert-via-tf-onnx.py", line 68, in <module>
    ei_tensorflow.onnx.conversion.onnx_to_tflite(args.onnx_file, file_float32, file_int8,
  File "/app/./resources/libraries/ei_tensorflow/onnx/conversion.py", line 96, in onnx_to_tflite
    tf_rep.export_graph(tf_model_path)
  File "/usr/local/lib/python3.10/dist-packages/onnx_tf/backend_rep.py", line 143, in export_graph
    signatures=self.tf_module.__call__.get_concrete_function(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1215, in get_concrete_function
    concrete = self._get_concrete_function_garbage_collected(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1195, in _get_concrete_function_garbage_collected
    self._initialize(args, kwargs, add_initializers_to=initializers)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 749, in _initialize
    self._variable_creation_fn    # pylint: disable=protected-access
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 162, in _get_concrete_function_internal_garbage_collected
    concrete_function, _ = self._maybe_define_concrete_function(args, kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 157, in _maybe_define_concrete_function
    return self._maybe_define_function(args, kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 360, in _maybe_define_function
    concrete_function = self._create_concrete_function(args, kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 284, in _create_concrete_function
    func_graph_module.func_graph_from_py_func(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/func_graph.py", line 1283, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 645, in wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 445, in bound_method_wrapper
    return wrapped_fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/func_graph.py", line 1269, in autograph_handler
    raise e.ag_error_metadata.to_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/func_graph.py", line 1258, in autograph_handler
    return autograph.converted_call(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 439, in converted_call
    result = converted_f(*effective_args, **kwargs)
  File "/tmp/__autograph_generated_file6oxxwyd5.py", line 30, in tf____call__
    ag__.for_stmt(ag__.ld(self).graph_def.node, None, loop_body, get_state, set_state, (), {'iterate_names': 'node'})
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 463, in for_stmt
    _py_for_stmt(iter_, extra_test, body, None, None)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 512, in _py_for_stmt
    body(target)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 478, in protected_body
    original_body(protected_iter)
  File "/tmp/__autograph_generated_file6oxxwyd5.py", line 23, in loop_body
    output_ops = ag__.converted_call(ag__.ld(self).backend._onnx_node_to_tensorflow_op, (ag__.ld(onnx_node), ag__.ld(tensor_dict), ag__.ld(self).handlers), dict(opset=ag__.ld(self).opset, strict=ag__.ld(self).strict), fscope)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 439, in converted_call
    result = converted_f(*effective_args, **kwargs)
  File "/tmp/__autograph_generated_fileh0or0oq3.py", line 62, in tf___onnx_node_to_tensorflow_op
    ag__.if_stmt(ag__.ld(handlers), if_body_1, else_body_1, get_state_1, set_state_1, ('do_return', 'retval_'), 2)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1363, in if_stmt
    _py_if_stmt(cond, body, orelse)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1416, in _py_if_stmt
    return body() if cond else orelse()
  File "/tmp/__autograph_generated_fileh0or0oq3.py", line 56, in if_body_1
    ag__.if_stmt(ag__.ld(handler), if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1363, in if_stmt
    _py_if_stmt(cond, body, orelse)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1416, in _py_if_stmt
    return body() if cond else orelse()
  File "/tmp/__autograph_generated_fileh0or0oq3.py", line 48, in if_body
    retval_ = ag__.converted_call(ag__.ld(handler).handle, (ag__.ld(node),), dict(tensor_dict=ag__.ld(tensor_dict), strict=ag__.ld(strict)), fscope)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 439, in converted_call
    result = converted_f(*effective_args, **kwargs)
  File "/tmp/__autograph_generated_filewlu2cz77.py", line 41, in tf__handle
    ag__.if_stmt(ag__.ld(ver_handle), if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1363, in if_stmt
    _py_if_stmt(cond, body, orelse)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/operators/control_flow.py", line 1416, in _py_if_stmt
    return body() if cond else orelse()
  File "/tmp/__autograph_generated_filewlu2cz77.py", line 40, in else_body
    raise ag__.converted_call(ag__.ld(BackendIsNotSupposedToImplementIt), (ag__.converted_call('{} version {} is not implemented.'.format, (ag__.ld(node).op_type, ag__.ld(cls).SINCE_VERSION), None, fscope),), None, fscope)
onnx.backend.test.runner.BackendIsNotSupposedToImplementIt: in user code:

    File "/usr/local/lib/python3.10/dist-packages/onnx_tf/backend_tf_module.py", line 99, in __call__  *
        output_ops = self.backend._onnx_node_to_tensorflow_op(onnx_node,
    File "/usr/local/lib/python3.10/dist-packages/onnx_tf/backend.py", line 347, in _onnx_node_to_tensorflow_op  *
        return handler.handle(node, tensor_dict=tensor_dict, strict=strict)
    File "/usr/local/lib/python3.10/dist-packages/onnx_tf/handlers/handler.py", line 61, in handle  *
        raise BackendIsNotSupposedToImplementIt("{} version {} is not implemented.".format(node.op_type, cls.SINCE_VERSION))

    BackendIsNotSupposedToImplementIt: Unsqueeze version 13 is not implemented.

Are LSTM layers not supported yet? and what do you suggest as a solution?

Ahmed,

Hello @Bouhmid,

I am checking internally I have a doubt about the response I was about to provide.
In short, no we currently don’t support LSTM layers. I’m checking internally to make sure my explanation makes sense and come back to you.

Best,

Louis

See here :slight_smile:

1 Like

Thank you for your reply!

Hope that RNN layers will be supported in the near future!

Bests,
Ahmed