Skip to content

Commit

Permalink
enable gradient calculation in dist.topk() by default (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyanpeng committed Mar 10, 2020
1 parent 0e47fe9 commit d921f30
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions torch_struct/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def topk(self, k):
Returns:
kmax (*k x batch_shape x event_shape*)
"""
return self._struct(KMaxSemiring(k)).marginals(
self.log_potentials, self.lengths, _raw=True
)
with torch.enable_grad():
return self._struct(KMaxSemiring(k)).marginals(
self.log_potentials, self.lengths, _raw=True
)

@lazy_property
def mode(self):
Expand Down

0 comments on commit d921f30

Please sign in to comment.