Thanks Frank ,
But it seems the code still have some issue, the gradient is constant over the epochs and becomes Nan afterwards.
The output you posted also have same gradient for all the epochs
gradient of the number are tensor([-3.5355])