Error when converting to onnx format

3123f2121a27c2cebf0c: <p>Hello to everyone!</p>
<p>I want to convert a custom layer to onnx format. But I get an error<br>
<code>RuntimeError: tuple appears in op that does not forward tuples</code>.</p>
<h2>To Reproduce</h2>
<p>My code to reproduce the error:</p>
<pre><code class="lang-python">import torch


class CustomFunction(torch.autograd.Function):
    @staticmethod
    def symbolic(g, input):
        return g.op('Custom', input, outputs=2)

    @staticmethod
    def forward(ctx, input):
        return input, input

    
class Custom(torch.nn.Module):

    def forward(self, input):
        return CustomFunction.apply(input)
    
model = Custom()
batch = torch.FloatTensor(1, 3)
torch.onnx.export(model, batch, "test.onnx", verbose=True)
</code></pre>
<h2>Expected behavior</h2>
<pre><code class="lang-python">---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-7-6ff6d6df1bca&gt; in &lt;module&gt;
     19 model = Custom()
     20 batch = torch.FloatTensor(1, 3)
---&gt; 21 torch.onnx.export(model, batch, "test.onnx", verbose=True)

~/anaconda3/lib/python3.7/site-packages/torch/onnx/__init__.py in export(*args, **kwargs)
     23 def export(*args, **kwargs):
     24     from torch.onnx import utils
---&gt; 25     return utils.export(*args, **kwargs)
     26 
     27 

~/anaconda3/lib/python3.7/site-packages/torch/onnx/utils.py in export(model, args, f, export_params, verbose, training, input_names, output_names, aten, export_raw_ir, operator_export_type, opset_version, _retain_param_name, do_constant_folding, strip_doc_string)
    129             operator_export_type=operator_export_type, opset_version=opset_version,
    130             _retain_param_name=_retain_param_name, do_constant_folding=do_constant_folding,
--&gt; 131             strip_doc_string=strip_doc_string)
    132 
    133 

~/anaconda3/lib/python3.7/site-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, opset_version, _retain_param_name, do_constant_folding, strip_doc_string)
    361                                                         output_names, operator_export_type,
    362                                                         example_outputs, propagate,
--&gt; 363                                                         _retain_param_name, do_constant_folding)
    364 
    365         # TODO: Don't allocate a in-memory string for the protobuf

~/anaconda3/lib/python3.7/site-packages/torch/onnx/utils.py in _model_to_graph(model, args, verbose, training, input_names, output_names, operator_export_type, example_outputs, propagate, _retain_param_name, do_constant_folding, _disable_torch_constant_prop)
    276 
    277     graph = _optimize_graph(graph, operator_export_type,
--&gt; 278                             _disable_torch_constant_prop=_disable_torch_constant_prop)
    279 
    280     # NB: ONNX requires complete information about output types, which might be

~/anaconda3/lib/python3.7/site-packages/torch/onnx/utils.py in _optimize_graph(graph, operator_export_type, _disable_torch_constant_prop)
    181     torch._C._jit_pass_erase_number_types(graph)
    182     # onnx does not support tuples, so try to remove them
--&gt; 183     torch._C._jit_pass_lower_all_tuples(graph)
    184     torch._C._jit_pass_peephole(graph, True)
    185     torch._C._jit_pass_lint(graph)

RuntimeError: tuple appears in op that does not forward tuples (VisitNode at /pytorch/torch/csrc/jit/passes/lower_tuples.cpp:117)
frame #0: std::function&lt;std::string ()&gt;::operator()() const + 0x11 (0x7f9b0c2b3441 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #1: c10::Error::Error(c10::SourceLocation, std::string const&amp;) + 0x2a (0x7f9b0c2b2d7a in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #2: &lt;unknown function&gt; + 0xaf61f5 (0x7f9b0b4b41f5 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch.so.1)
frame #3: &lt;unknown function&gt; + 0xaf6464 (0x7f9b0b4b4464 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch.so.1)
frame #4: torch::jit::LowerAllTuples(std::shared_ptr&lt;torch::jit::Graph&gt;&amp;) + 0x13 (0x7f9b0b4b44a3 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch.so.1)
frame #5: &lt;unknown function&gt; + 0x3f9444 (0x7f9b4b87b444 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #6: &lt;unknown function&gt; + 0x130fac (0x7f9b4b5b2fac in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #7: _PyMethodDef_RawFastCallKeywords + 0x264 (0x564a1c09b6e4 in /home/videoanalytics/anaconda3/bin/python)
frame #8: _PyCFunction_FastCallKeywords + 0x21 (0x564a1c09b801 in /home/videoanalytics/anaconda3/bin/python)
frame #9: _PyEval_EvalFrameDefault + 0x4e8c (0x564a1c0f72bc in /home/videoanalytics/anaconda3/bin/python)
frame #10: _PyEval_EvalCodeWithName + 0x2f9 (0x564a1c0384f9 in /home/videoanalytics/anaconda3/bin/python)
frame #11: _PyFunction_FastCallKeywords + 0x387 (0x564a1c09aa27 in /home/videoanalytics/anaconda3/bin/python)
frame #12: _PyEval_EvalFrameDefault + 0x14ce (0x564a1c0f38fe in /home/videoanalytics/anaconda3/bin/python)
frame #13: _PyEval_EvalCodeWithName + 0x2f9 (0x564a1c0384f9 in /home/videoanalytics/anaconda3/bin/python)
frame #14: _PyFunction_FastCallKeywords + 0x325 (0x564a1c09a9c5 in /home/videoanalytics/anaconda3/bin/python)
frame #15: _PyEval_EvalFrameDefault + 0x416 (0x564a1c0f2846 in /home/videoanalytics/anaconda3/bin/python)
frame #16: _PyEval_EvalCodeWithName + 0xbb9 (0x564a1c038db9 in /home/videoanalytics/anaconda3/bin/python)
frame #17: _PyFunction_FastCallKeywords + 0x387 (0x564a1c09aa27 in /home/videoanalytics/anaconda3/bin/python)
frame #18: _PyEval_EvalFrameDefault + 0x14ce (0x564a1c0f38fe in /home/videoanalytics/anaconda3/bin/python)
frame #19: _PyEval_EvalCodeWithName + 0x2f9 (0x564a1c0384f9 in /home/videoanalytics/anaconda3/bin/python)
frame #20: _PyFunction_FastCallDict + 0x400 (0x564a1c039800 in /home/videoanalytics/anaconda3/bin/python)
frame #21: _PyEval_EvalFrameDefault + 0x1e20 (0x564a1c0f4250 in /home/videoanalytics/anaconda3/bin/python)
frame #22: _PyEval_EvalCodeWithName + 0x2f9 (0x564a1c0384f9 in /home/videoanalytics/anaconda3/bin/python)
frame #23: _PyFunction_FastCallKeywords + 0x387 (0x564a1c09aa27 in /home/videoanalytics/anaconda3/bin/python)
frame #24: _PyEval_EvalFrameDefault + 0x14ce (0x564a1c0f38fe in /home/videoanalytics/anaconda3/bin/python)
frame #25: _PyEval_EvalCodeWithName + 0x2f9 (0x564a1c0384f9 in /home/videoanalytics/anaconda3/bin/python)
frame #26: PyEval_EvalCodeEx + 0x44 (0x564a1c0393c4 in /home/videoanalytics/anaconda3/bin/python)
frame #27: PyEval_EvalCode + 0x1c (0x564a1c0393ec in /home/videoanalytics/anaconda3/bin/python)
frame #28: &lt;unknown function&gt; + 0x1e004d (0x564a1c10204d in /home/videoanalytics/anaconda3/bin/python)
frame #29: _PyMethodDef_RawFastCallKeywords + 0xe9 (0x564a1c09b569 in /home/videoanalytics/anaconda3/bin/python)
frame #30: _PyCFunction_FastCallKeywords + 0x21 (0x564a1c09b801 in /home/videoanalytics/anaconda3/bin/python)
frame #31: _PyEval_EvalFrameDefault + 0x4755 (0x564a1c0f6b85 in /home/videoanalytics/anaconda3/bin/python)
frame #32: _PyGen_Send + 0x2a2 (0x564a1c094672 in /home/videoanalytics/anaconda3/bin/python)
frame #33: _PyEval_EvalFrameDefault + 0x1a6d (0x564a1c0f3e9d in /home/videoanalytics/anaconda3/bin/python)
frame #34: _PyGen_Send + 0x2a2 (0x564a1c094672 in /home/videoanalytics/anaconda3/bin/python)
frame #35: _PyEval_EvalFrameDefault + 0x1a6d (0x564a1c0f3e9d in /home/videoanalytics/anaconda3/bin/python)
frame #36: _PyGen_Send + 0x2a2 (0x564a1c094672 in /home/videoanalytics/anaconda3/bin/python)
frame #37: _PyMethodDef_RawFastCallKeywords + 0x8c (0x564a1c09b50c in /home/videoanalytics/anaconda3/bin/python)
frame #38: _PyMethodDescr_FastCallKeywords + 0x4f (0x564a1c09b86f in /home/videoanalytics/anaconda3/bin/python)
frame #39: _PyEval_EvalFrameDefault + 0x4c4c (0x564a1c0f707c in /home/videoanalytics/anaconda3/bin/python)
frame #40: _PyFunction_FastCallKeywords + 0xfb (0x564a1c09a79b in /home/videoanalytics/anaconda3/bin/python)
frame #41: _PyEval_EvalFrameDefault + 0x416 (0x564a1c0f2846 in /home/videoanalytics/anaconda3/bin/python)
frame #42: _PyFunction_FastCallKeywords + 0xfb (0x564a1c09a79b in /home/videoanalytics/anaconda3/bin/python)
frame #43: _PyEval_EvalFrameDefault + 0x6a0 (0x564a1c0f2ad0 in /home/videoanalytics/anaconda3/bin/python)
frame #44: _PyEval_EvalCodeWithName + 0x2f9 (0x564a1c0384f9 in /home/videoanalytics/anaconda3/bin/python)
frame #45: _PyFunction_FastCallDict + 0x400 (0x564a1c039800 in /home/videoanalytics/anaconda3/bin/python)
frame #46: _PyObject_Call_Prepend + 0x63 (0x564a1c050c43 in /home/videoanalytics/anaconda3/bin/python)
frame #47: PyObject_Call + 0x6e (0x564a1c04595e in /home/videoanalytics/anaconda3/bin/python)
frame #48: _PyEval_EvalFrameDefault + 0x1e20 (0x564a1c0f4250 in /home/videoanalytics/anaconda3/bin/python)
frame #49: _PyEval_EvalCodeWithName + 0x5da (0x564a1c0387da in /home/videoanalytics/anaconda3/bin/python)
frame #50: _PyFunction_FastCallKeywords + 0x387 (0x564a1c09aa27 in /home/videoanalytics/anaconda3/bin/python)
frame #51: _PyEval_EvalFrameDefault + 0x14ce (0x564a1c0f38fe in /home/videoanalytics/anaconda3/bin/python)
frame #52: &lt;unknown function&gt; + 0x171cc6 (0x564a1c093cc6 in /home/videoanalytics/anaconda3/bin/python)
frame #53: &lt;unknown function&gt; + 0x171ecb (0x564a1c093ecb in /home/videoanalytics/anaconda3/bin/python)
frame #54: _PyMethodDef_RawFastCallKeywords + 0xe9 (0x564a1c09b569 in /home/videoanalytics/anaconda3/bin/python)
frame #55: _PyCFunction_FastCallKeywords + 0x21 (0x564a1c09b801 in /home/videoanalytics/anaconda3/bin/python)
frame #56: _PyEval_EvalFrameDefault + 0x4755 (0x564a1c0f6b85 in /home/videoanalytics/anaconda3/bin/python)
frame #57: _PyEval_EvalCodeWithName + 0x5da (0x564a1c0387da in /home/videoanalytics/anaconda3/bin/python)
frame #58: _PyFunction_FastCallKeywords + 0x387 (0x564a1c09aa27 in /home/videoanalytics/anaconda3/bin/python)
frame #59: _PyEval_EvalFrameDefault + 0x6a0 (0x564a1c0f2ad0 in /home/videoanalytics/anaconda3/bin/python)
frame #60: &lt;unknown function&gt; + 0x171cc6 (0x564a1c093cc6 in /home/videoanalytics/anaconda3/bin/python)
frame #61: &lt;unknown function&gt; + 0x171ecb (0x564a1c093ecb in /home/videoanalytics/anaconda3/bin/python)
frame #62: _PyMethodDef_RawFastCallKeywords + 0xe9 (0x564a1c09b569 in /home/videoanalytics/anaconda3/bin/python)
frame #63: _PyCFunction_FastCallKeywords + 0x21 (0x564a1c09b801 in /home/videoanalytics/anaconda3/bin/python)
</code></pre>
<h2>Environment</h2>
<ul>
<li>
<p>PyTorch version: 1.1.0</p>
</li>
<li>
<p>Is debug build: No</p>
</li>
<li>
<p>CUDA used to build PyTorch: 9.0.176</p>
</li>
<li>
<p>OS: Ubuntu 18.04.2 LTS</p>
</li>
<li>
<p>GCC version: (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0</p>
</li>
<li>
<p>CMake version: Could not collect</p>
</li>
<li>
<p>Python version: 3.7</p>
</li>
<li>
<p>Is CUDA available: Yes</p>
</li>
<li>
<p>CUDA runtime version: Could not collect</p>
</li>
<li>
<p>GPU models and configuration: GPU 0: GeForce RTX 2080 Ti</p>
</li>
<li>
<p>Nvidia driver version: 418.56</p>
</li>
<li>
<p>cuDNN version: Could not collect</p>
</li>
<li>
<p>Versions of relevant libraries:<br>
[pip] numpy==1.14.6<br>
[pip] numpydoc==0.8.0<br>
[pip] torch==1.1.0<br>
[pip] torchvision==0.2.2.post3<br>
[conda] blas                      1.0                         mkl<br>
[conda] mkl                       2019.3                      199<br>
[conda] mkl-service               1.1.2            py37he904b0f_5<br>
[conda] mkl_fft                   1.0.10           py37ha843d7b_0<br>
[conda] mkl_random                1.0.2            py37hd81dba3_0<br>
[conda] torch                     1.1.0                    pypi_0    pypi<br>
[conda] torchvision               0.2.2.post3              pypi_0    pypi</p>
</li>
</ul>