Thank you very much.
I ran this code, but it’s not giving me the right answer. To test this code, I ran a linear regression: y= w0+w1*x, and then I grabed grad of y w.r.t. x using x.grad.
It should give me an n-long tensor with estimate of w1 on each entry of the tensor. Right? But it gives me this:
tensor([[ 0.1268],
[ 0.2045],
[-0.3171],
…,
[ 0.3761],
[ 0.1287],
[-0.1889]], device=‘cuda:0’)
Do you know what’s going on? Maybe x.grad doesn’t give derivative of y w.r.t. x?