Hello guys,
I’m implementing A3C and trying to collect the gradients from individuals models and perform them onto the original model. Say I’ve done this:
outputs = network(inputs) loss = criterion(outputs, targets) loss.backward()
What’s next? I only want the gradients of network, but Module doesn’t have gradients method.
params = list(network.parameters())
params will be a list of nn.Parameter objects, which are a subclass of Variable. Each object in params will have a .grad attribute containing the gradients.
nn.Parameter
Variable
params
.grad
For example:
params[0].grad # gradient of first module's first weight.
Wow, thanks. I guess I’m still not used to python.