RNN to ONNX error "Couldn't export operator aten::rnn_tanh"

soloupis: <p>Hello to everyone!</p>
<p>Trying to export an RNN to ONNX I get to this error stacktrace:</p>
<pre><code class="lang-auto">graph(%input.1 : Long(1, 200)
      %hidden : Float(2, 1, 256)
      %2 : Float(74073, 512)
      %3 : Float(256, 512)
      %4 : Float(256, 256)
      %5 : Float(256)
      %6 : Float(256)
      %7 : Float(256, 256)
      %8 : Float(256, 256)
      %9 : Float(256)
      %10 : Float(256)
      %11 : Float(1, 256)
      %12 : Float(1)) {
  %13 : Long() = onnx::Constant[value={0}](), scope: SentimentRNN
  %14 : Tensor = onnx::Shape(%input.1), scope: SentimentRNN
  %15 : Long() = onnx::Gather[axis=0](%14, %13), scope: SentimentRNN
  %16 : Float(1, 200, 512) = onnx::Gather(%2, %input.1), scope: SentimentRNN/Embedding[embedding]
  %17 : Long() = onnx::Constant[value={1}](), scope: SentimentRNN/RNN[rnn]
  %18 : Long() = onnx::Constant[value={2}](), scope: SentimentRNN/RNN[rnn]
  %19 : Double() = onnx::Constant[value={0.5}](), scope: SentimentRNN/RNN[rnn]
  %20 : Long() = onnx::Constant[value={0}](), scope: SentimentRNN/RNN[rnn]
  %21 : Long() = onnx::Constant[value={0}](), scope: SentimentRNN/RNN[rnn]
  %22 : Long() = onnx::Constant[value={1}](), scope: SentimentRNN/RNN[rnn]
  %23 : Float(1!, 200, 256), %24 : Float(2, 1, 256) = aten::rnn_tanh(%16, %hidden, %3, %4, %5, %6, %7, %8, %9, %10, %17, %18, %19, %20, %21, %22), scope: SentimentRNN
  %25 : Tensor = onnx::Constant[value=  -1  256 [ CPULongType{2} ]](), scope: SentimentRNN
  %26 : Float(200, 256) = onnx::Reshape(%23, %25), scope: SentimentRNN
  %27 : Float(200, 256), %28 : Tensor = onnx::Dropout[ratio=0.7](%26), scope: SentimentRNN/Dropout[dropout]
  %29 : Float(200, 1) = onnx::Gemm[alpha=1, beta=1, transB=1](%27, %11, %12), scope: SentimentRNN/Dropout[dropout]
  %30 : Float(200, 1) = onnx::Sigmoid(%29), scope: SentimentRNN/Sigmoid[sig]
  %31 : Long() = onnx::Constant[value={-1}](), scope: SentimentRNN
  %32 : Tensor = onnx::Unsqueeze[axes=[0]](%15)
  %33 : Tensor = onnx::Unsqueeze[axes=[0]](%31)
  %34 : Tensor = onnx::Concat[axis=0](%32, %33)
  %35 : Float(1, 200) = onnx::Reshape(%30, %34), scope: SentimentRNN
  %36 : Float(1, 200) = onnx::Slice[axes=[0], ends=[9223372036854775807], starts=[0]](%35), scope: SentimentRNN
  %37 : Long() = onnx::Constant[value={-1}](), scope: SentimentRNN
  %38 : Float(1!) = onnx::Gather[axis=1](%36, %37), scope: SentimentRNN
  return (%38, %24);
}

/usr/local/lib/python3.6/dist-packages/torch/onnx/symbolic.py:131: UserWarning: ONNX export failed on RNN/GRU/LSTM because batch_first not supported
  warnings.warn("ONNX export failed on " + op + " because " + msg + " not supported")
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-8-5c9d797dab9b&gt; in &lt;module&gt;()
     16                                "sentiment_analysis.onnx",       # where to save the model (can be a file or file-like object)
     17                                verbose=True,            # where to save the model (can be a file or file-like object)
---&gt; 18                                export_params=True)      # store the trained parameter weights inside the model file

/usr/local/lib/python3.6/dist-packages/torch/onnx/__init__.py in _export(*args, **kwargs)
     20 def _export(*args, **kwargs):
     21     from torch.onnx import utils
---&gt; 22     return utils._export(*args, **kwargs)
     23 
     24 

/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py in _export(model, args, f, export_params, verbose, training, input_names, output_names, operator_export_type, export_type, example_outputs, propagate)
    285     defer_weight_export = export_type is not ExportTypes.PROTOBUF_FILE
    286     if export_params:
--&gt; 287         proto, export_map = graph._export_onnx(params, _onnx_opset_version, defer_weight_export, operator_export_type)
    288     else:
    289         proto, export_map = graph._export_onnx([], _onnx_opset_version, False, operator_export_type)

RuntimeError: ONNX export failed: Couldn't export operator aten::rnn_tanh

Defined at:
&lt;ipython-input-3-ca3d62ed597b&gt;(42): forward
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py(477): _slow_forward
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py(487): __call__
/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py(252): forward
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py(489): __call__
/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py(197): get_trace_graph
/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py(192): _trace_and_get_graph_from_model
/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py(224): _model_to_graph
/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py(281): _export
/usr/local/lib/python3.6/dist-packages/torch/onnx/__init__.py(22): _export
&lt;ipython-input-8-5c9d797dab9b&gt;(18): &lt;module&gt;
/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py(2882): run_code
/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py(2822): run_ast_nodes
/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py(2718): run_cell
/usr/local/lib/python3.6/dist-packages/ipykernel/zmqshell.py(533): run_cell
/usr/local/lib/python3.6/dist-packages/ipykernel/ipkernel.py(196): do_execute
/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py(399): execute_request
/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py(235): dispatch_shell
/usr/local/lib/python3.6/dist-packages/ipykernel/kernelbase.py(283): dispatcher
/usr/local/lib/python3.6/dist-packages/tornado/stack_context.py(277): null_wrapper
/usr/local/lib/python3.6/dist-packages/zmq/eventloop/zmqstream.py(432): _run_callback
/usr/local/lib/python3.6/dist-packages/zmq/eventloop/zmqstream.py(480): _handle_recv
/usr/local/lib/python3.6/dist-packages/zmq/eventloop/zmqstream.py(450): _handle_events
/usr/local/lib/python3.6/dist-packages/tornado/stack_context.py(277): null_wrapper
/usr/local/lib/python3.6/dist-packages/tornado/ioloop.py(888): start
/usr/local/lib/python3.6/dist-packages/ipykernel/kernelapp.py(477): start
/usr/local/lib/python3.6/dist-packages/traitlets/config/application.py(658): launch_instance
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py(16): &lt;module&gt;
/usr/lib/python3.6/runpy.py(85): _run_code
/usr/lib/python3.6/runpy.py(193): _run_module_as_main


Graph we tried to export:
graph(%input.1 : Long(1, 200)
      %hidden : Float(2, 1, 256)
      %2 : Float(74073, 512)
      %3 : Float(256, 512)
      %4 : Float(256, 256)
      %5 : Float(256)
      %6 : Float(256)
      %7 : Float(256, 256)
      %8 : Float(256, 256)
      %9 : Float(256)
      %10 : Float(256)
      %11 : Float(1, 256)
      %12 : Float(1)) {
  %13 : Long() = onnx::Constant[value={0}](), scope: SentimentRNN
  %14 : Tensor = onnx::Shape(%input.1), scope: SentimentRNN
  %15 : Long() = onnx::Gather[axis=0](%14, %13), scope: SentimentRNN
  %16 : Float(1, 200, 512) = onnx::Gather(%2, %input.1), scope: SentimentRNN/Embedding[embedding]
  %17 : Long() = onnx::Constant[value={1}](), scope: SentimentRNN/RNN[rnn]
  %18 : Long() = onnx::Constant[value={2}](), scope: SentimentRNN/RNN[rnn]
  %19 : Double() = onnx::Constant[value={0.5}](), scope: SentimentRNN/RNN[rnn]
  %20 : Long() = onnx::Constant[value={0}](), scope: SentimentRNN/RNN[rnn]
  %21 : Long() = onnx::Constant[value={0}](), scope: SentimentRNN/RNN[rnn]
  %22 : Long() = onnx::Constant[value={1}](), scope: SentimentRNN/RNN[rnn]
  %23 : Float(1!, 200, 256), %24 : Float(2, 1, 256) = aten::rnn_tanh(%16, %hidden, %3, %4, %5, %6, %7, %8, %9, %10, %17, %18, %19, %20, %21, %22), scope: SentimentRNN
  %25 : Tensor = onnx::Constant[value=  -1  256 [ CPULongType{2} ]](), scope: SentimentRNN
  %26 : Float(200, 256) = onnx::Reshape(%23, %25), scope: SentimentRNN
  %27 : Float(200, 256), %28 : Tensor = onnx::Dropout[ratio=0.7](%26), scope: SentimentRNN/Dropout[dropout]
  %29 : Float(200, 1) = onnx::Gemm[alpha=1, beta=1, transB=1](%27, %11, %12), scope: SentimentRNN/Dropout[dropout]
  %30 : Float(200, 1) = onnx::Sigmoid(%29), scope: SentimentRNN/Sigmoid[sig]
  %31 : Long() = onnx::Constant[value={-1}](), scope: SentimentRNN
  %32 : Tensor = onnx::Unsqueeze[axes=[0]](%15)
  %33 : Tensor = onnx::Unsqueeze[axes=[0]](%31)
  %34 : Tensor = onnx::Concat[axis=0](%32, %33)
  %35 : Float(1, 200) = onnx::Reshape(%30, %34), scope: SentimentRNN
  %36 : Float(1, 200) = onnx::Slice[axes=[0], ends=[9223372036854775807], starts=[0]](%35), scope: SentimentRNN
  %37 : Long() = onnx::Constant[value={-1}](), scope: SentimentRNN
  %38 : Float(1!) = onnx::Gather[axis=1](%36, %37), scope: SentimentRNN
  return (%38, %24);
}
</code></pre>
<p>Does anyone know a solution to “ONNX export failed: Couldn’t export operator aten::rnn_tanh” ??</p>
<p>Thanks!</p>