Thanks for the question, @liqun.
The problem looks like you’re passing None as the hidden:
def rnn_loop(x):
hidden = None
**for** x_t **in** x.split(1):
x, hidden = model(x_t, hidden)

However, you’re not handling None hidden values in your model.
Please see the following file https://github.com/pytorch/benchmark/blob/master/rnns/fastrnns/custom_lstms.py 67 for some samples of custom RNNs written with TorchScript.