Skip to content

Commit

Permalink
ignore grad when parameter not used, has a value of None (#2828)
Browse files Browse the repository at this point in the history
  • Loading branch information
fshipy authored Apr 28, 2021
1 parent 84711a2 commit 8246685
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyro/infer/csis.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def loss_and_grads(self, grads, batch, *args, **kwargs):
for site in particle_param_capture.trace.nodes.values())
guide_grads = torch.autograd.grad(particle_loss, guide_params, allow_unused=True)
for guide_grad, guide_param in zip(guide_grads, guide_params):
if guide_grad is None:
continue
guide_param.grad = guide_grad if guide_param.grad is None else guide_param.grad + guide_grad

loss += torch_item(particle_loss)
Expand Down

0 comments on commit 8246685

Please sign in to comment.