I understand. I think torch is complaining about the index assignment…
This version might be slower but works and bases the next value upon the previous one:
import torch as t

def powers_of_x(N,X):
    Y = [t.tensor([1])]
    for _ in range(1,N):
        Y.append(Y[-1] * X)
    return t.stack(Y)

X = t.tensor([2.0], requires_grad=True)
SERIES = powers_of_x(9,X).sum()

SERIES.backward()
X.grad

Output:
tensor([1793.])