Premium problem41. Autograd: Compute a Gradient

Hard Locked

Given a float tensor x, compute the gradient of y = (x ** 2).sum() with respect to x using automatic differentiation, and return the resulting gradient tensor (which equals 2 * x).

Hint: enable gradient tracking on a copy of x, run the forward computation, then trigger backpropagation to populate the gradient.

Input

tensor([1., 2., 3.])

Output

tensor([2., 4., 6.])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)