I have a custom rnn class, where i have defined the weights in a dictionary in the constructor. In forward function i have written custom operations . Also wrote a separate  function to calculate loss and update the parameters. For first pass everything is working fine but in second pass few of the variables (Hidden_memory and output of forward pass which is passed to next time step) becoming volatile and giving error “element 0 of variables tuple is volatile” .
Input and output is a time series data
x=torch.from_numpy(x)
x=Variable(x,requires_grad=True)
y=torch.from_numpy(y)
y=Variable(y)
the code of rnn class and error i have attached.Thanks in advance

d_1.PNG1158×906 66.2 KB

d_2.PNG1059×744 27.9 KB

d_3.PNG1168×850 41.7 KB