Skip to content

Commit c5d5d45

Browse files
zuoxingdongfacebook-github-bot
authored andcommitted
Fix numerically instability of SigmoidTransform (#19802)
Summary: fix #18254 for numerically instability of `SigmoidTransform` Pull Request resolved: #19802 Differential Revision: D15701837 Pulled By: ezyang fbshipit-source-id: fe6c755c523487c8bbdcc3bfb8455801617c70a4
1 parent f8cab38 commit c5d5d45

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

torch/distributions/transforms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import weakref
44

55
import torch
6+
import torch.nn.functional as F
67
from torch.distributions import constraints
78
from torch.distributions.utils import (_sum_rightmost, broadcast_all,
89
lazy_property)
@@ -359,7 +360,7 @@ def _inverse(self, y):
359360
return y.log() - (-y).log1p()
360361

361362
def log_abs_det_jacobian(self, x, y):
362-
return -(y.reciprocal() + (1 - y).reciprocal()).log()
363+
return -F.softplus(-x) - F.softplus(x)
363364

364365

365366
class AbsTransform(Transform):

0 commit comments

Comments
 (0)