do you want intermediate gradients? or weight gradients?
By record, do you want to print them? or save them?
There are a few threads already answering these questions.
I am also looking for an answer to the same question, and I did not find an answer on the forum. Could someone post a minimal working example of how this is done?
optimizer.zero_grad()
y = net(x)
loss = criterion(y, target)
loss.backward()
grad_of_params = {}
for name, parameter in net.named_parameters():
grad_of_param[name] = parameter.grad