Get Dictionary of Gradient Values

I have a network (an nn.module) that I’ve defined, run on a set of inputs, and called the member function backward().

I would like access to the values of the gradients. It’d be great, for example, if I could have a dictionary with the values of the gradient.

How can I get this gradient?

If you model contains a parameter named model.param then you can access the gradients with respect to that parameter using model.param.grad.

1 Like

you can add hooks to your members and when doing backward add the gradients to a dictionary of your members.