Why relay.frontend.from_pytorch unpacks inner tuples

Apparently this is due to _jit_pass_lower_all_tuples PyTorch jit pass we run in preprocessing:

See [Bug] [Frontend][Pytorch] Relay IR is inconsistent with that of the original model - #4 by masahi for why we do this.

But running this pass is not supposed to modify the user API, so this is a bug. We have a check to decide if we can run this pass safely. Right now we only check inputs, but your use case shows that we also need to check output types. Would you be interested in contributing a fix?

Also note that nested tuples are not supported by our graph runtime (what you’d be using if you use relay.build), so they are flattened during memory planning. You can use our VM runtime, if you want to preserve nested tuples at runtime.