x = torch.tensor(3.0, requires_grad=True) for i in range(3): y = x ** 2 y.backward() print(f"step {i} grad = {x.grad.item()}")