Hi there, there is a puzzle for me about whether the slice operation on a list will be traced back when autograding.
Here is a piece of script of my example
import torch
import torch.nn as nn
import numpy as np

criterion = nn.MSELoss()
x = torch.randn(4, 4, requires_grad=True)
y = torch.randn(4, 4)
z = [2*x]
for i in range(3):
    z.append(z[-1]+x)

loss = criterion(z[-1], y)
loss.backward()

If the slice operation were traced back when autograding, then it would be true that
x.grad == (z[-1] - y)*5*2/16. However, what I got was

I can not figure out what’s wrong with this situation. Any help will be appreciated.
Edit: I’m just trying to implement LISTA 3 which is proposed by LeCun using pytorch. Maybe using RNN should be practical but I have no idea how to do it in this way.