Accessing parameter grads as a list

Hi,

You can use grads = autograd.grad(loss, network.parameters()) and it will return to you a list of all the gradients.
If you already did a .backward() that populated the .grad fields, you can do grads = [p.grad for p in network.parameters()] as well.

2 Likes