Hi @Wei_Deng,
You are doing everything right, except that you’re not looking for the gradients in the right place.
After a backward pass, only the gradients of the loss with respect to model parameters will be kept. Thus, if your model, has some parameter theta, then you’ll find the gradient of the loss w.r.t. theta in the variable theta.grad.
Therefore, if you want to print gradients, change your final loop to something like:
for name, param in model.named_parameters():
  print(name, param.grad)