I think a better implementation of powers_of_x(9,X) could be t.pow(X, t.arange(9)):
Updated code:
import torch as t

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

SERIES.backward()
X.grad

Output:
tensor([1793.])