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)
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
Each object in
params will have a
.grad attribute containing the gradients.
params.grad # gradient of first module's first weight.
Wow, thanks. I guess I’m still not used to python.