Hmmm, maybe I’m doing something wrong?
q = torch.tensor([2], requires_grad = True, dtype = torch.double)

XR = torch.zeros([2], dtype = torch.double)

XR[0] = 2

XR[1] = (q[0]**XR[0]).clone()

z = torch.sum(XR)
z.backward()
q.grad

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

Also, I should have put this in the initial post, I will eventually be considering the case where X[0] is not just a scalar, but a function of q as well and I will want to get the gradient of X[0] with respect to q.