Hello to everyone!
I want to convert a custom layer to onnx format. But I get an error
RuntimeError: tuple appears in op that does not forward tuples.
To Reproduce
My code to reproduce the error:
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)

Expected behavior
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-7-6ff6d6df1bca> in <module>
     19 model = Custom()
     20 batch = torch.FloatTensor(1, 3)
---> 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
---> 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,
--> 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,
--> 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,
--> 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
--> 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<std::string ()>::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&) + 0x2a (0x7f9b0c2b2d7a in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #2: <unknown function> + 0xaf61f5 (0x7f9b0b4b41f5 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch.so.1)
frame #3: <unknown function> + 0xaf6464 (0x7f9b0b4b4464 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch.so.1)
frame #4: torch::jit::LowerAllTuples(std::shared_ptr<torch::jit::Graph>&) + 0x13 (0x7f9b0b4b44a3 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch.so.1)
frame #5: <unknown function> + 0x3f9444 (0x7f9b4b87b444 in /home/videoanalytics/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #6: <unknown function> + 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: <unknown function> + 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: <unknown function> + 0x171cc6 (0x564a1c093cc6 in /home/videoanalytics/anaconda3/bin/python)
frame #53: <unknown function> + 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: <unknown function> + 0x171cc6 (0x564a1c093cc6 in /home/videoanalytics/anaconda3/bin/python)
frame #61: <unknown function> + 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)

Environment


PyTorch version: 1.1.0


Is debug build: No


CUDA used to build PyTorch: 9.0.176


OS: Ubuntu 18.04.2 LTS


GCC version: (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0


CMake version: Could not collect


Python version: 3.7


Is CUDA available: Yes


CUDA runtime version: Could not collect


GPU models and configuration: GPU 0: GeForce RTX 2080 Ti


Nvidia driver version: 418.56


cuDNN version: Could not collect


Versions of relevant libraries:
[pip] numpy==1.14.6
[pip] numpydoc==0.8.0
[pip] torch==1.1.0
[pip] torchvision==0.2.2.post3
[conda] blas                      1.0                         mkl
[conda] mkl                       2019.3                      199
[conda] mkl-service               1.1.2            py37he904b0f_5
[conda] mkl_fft                   1.0.10           py37ha843d7b_0
[conda] mkl_random                1.0.2            py37hd81dba3_0
[conda] torch                     1.1.0                    pypi_0    pypi
[conda] torchvision               0.2.2.post3              pypi_0    pypi