while running this code
for e in range(10): 
  y_ = linear_model(x_train)
  loss = get_loss(y_, y_train)
  w.grad.zero_() 
  b.grad.zero_() 
  loss.backward()
  
  w = w - 1e-2 * w.grad 
  b = b - 1e-2 * b.grad 

  print('epoch: {}, loss: {}'.format(e, loss.item()))

my notebook raise an error that the w and b’s grad is None
and in this code
w.data = w.data - 1e-2 * w.grad.data 
b.data = b.data - 1e-2 * b.grad.data

the grad didn’t disappear.
why former one doesn’t work?Thanks for anyone pointing out the reason.