My code is much like RNN
that is :
for t in length_sequence:
  alphas[t] = torch.logsumexp((potential[t]*alphas[t-1].unsqueeze(dim = 1)),dim = 0)

Where potential is weight of  RNN cell t (which require grad) and alpha[t] is time t output.
After that I compute loss on alpha and backward to change the weight of RNN
You mean store alpha in a list after that convert it to tensor?