I don’t know why you wanna do this:
import torch
a = torch.rand(3,3, requires_grad=True)

L = []
for i in range(10):
    b = a * a
    d = b * b
    e = d.sum()
    L.append(e)
    sum(L).backward()

the more normal way is to have sum(L).backward() outside of loop.(and i think it really is the case)
But if your intention is to compute grad for what you asked, then you can go around using retain_graph = True with change in how you backward.
import torch
a = torch.rand(3,3, requires_grad=True)

L = []
for i in range(10):
    b = a * a
    d = b * b
    e = d.sum()
    e.backward(torch.tensor(10-i)) # if you really want to compute 
                                   # grad multiple times,
                                   # i.e. backward for 10 
                                   # times on first item of the list
    L.append(e.item())
sum(L)
# do some thing with a.grad and then
print(a.grad)

a.grad.fill_(0)

This way is more memory efficient.