Tuple in args to forward in TorchScript

I’m trying to unpack a tuple passed in the arguments of the forward method of a ScriptModule:

def forward(self, input, hidden):
  x, y = hidden

but the compiler complains that a Tensor cannot be used as a tuple. Fair enough, maybe type annotations will help:

def forward(self, input, hidden: tuple):
  x, y = hidden

but this throws RuntimeError: Unknown type name tuple

Is there a way to get TorchScript to recognise a tuple passed in to a traced method?

The answer (as always) is in the docs:


Type annotations are expected in MyPy style, not Python type annotations.