Why doesn't script module serialization support returning multiple outputs?

Hi All,
I am curious to understand the reasoning behind https://github.com/pytorch/pytorch/blob/v1.2.0/torch/csrc/jit/passes/python_print.cpp#L788? Why would jit module export not support multiple values? I also see that the python-c++ interface is only returning at the last element in the stack vector (stack.back()) when we invoke a scriptmodule from python, but why this limitation? Why not return all elements in the stack vector? I am surely missing more technical details and would love to understand this further.


We follow the same conventions as Python here, if a function has multiple return values they all get wrapped up into a tuple, so it’s actually only 1 return value.

You can have as many returns as you want, they will just be wrapped into a tuple that you will have to unpack.

Thanks. I think I understand now. I will dig into the code to look at where this creation of tuples happens on the C++ side :slight_smile:

We have an open issue to document it better and make it a nicer experience: https://github.com/pytorch/pytorch/issues/17165