Premium problem57. Gradient of MSE Loss w.r.t. Weight and Bias

Hard Locked

For a 1-feature linear model pred = w * x + b and the mean-squared-error loss against targets y, use autograd to compute the gradient of the loss with respect to w and b. Return a length-2 tensor [dL/dw, dL/db].

Input

x = tensor([1., 2., 3., 4.])
y = tensor([2.0000, 4.1000, 5.9000, 8.2000])
w = tensor(1.)
b = tensor(0.)

Output

tensor([-15.3500,  -5.1000])

Premium problem

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

Implement solve(...)