How to realize VAR in pytorch

I want to realize VAR by pytorch, where for time shot t, Y[t]=W1Y[t-1]+W2Y[t-3]. The general part of my pytorch code is just like the below one:

for i in range(3,Y.shape[0]):

However, when I backward the loss function of Y, there became an error:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [1, 100]], which is output 0 of UnsqueezeBackward0, is at version 5040; expected version 5039 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

Is there an easy way to realize VAR by pytorch? Thank you!