Skip to content

Commit 466da73

Browse files
kit1980facebook-github-bot
authored andcommitted
Use expm1 instead of exp - 1 (#2660)
Summary: Similarly to #2540 and #2541: use more numerically stable `expm1`. Found with TorchFix https://github.com/pytorch-labs/torchfix/. This should be the last instance to replace in the current codebase. Pull Request resolved: #2660 Reviewed By: saitcakmak Differential Revision: D67613867 Pulled By: kit1980 fbshipit-source-id: a6305f0f3ec4a3e6ec6f6f6b9c9361a61eaf06e9
1 parent 7715ff4 commit 466da73

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

botorch/test_functions/multi_objective.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ def penicillin_vectorized(cls, X_input: Tensor) -> Tensor:
772772
F_loss = (
773773
V[active]
774774
* cls.lambd
775-
* (torch.exp(5 * ((T[active] - cls.T_o) / (cls.T_v - cls.T_o))) - 1)
775+
* torch.special.expm1(5 * ((T[active] - cls.T_o) / (cls.T_v - cls.T_o)))
776776
)
777777
dV_dt = F[active] - F_loss
778778
mu = (

test/models/transforms/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_norm_to_lognorm(self):
8686
mu_ln_expected = torch.tensor(
8787
[1.0, 2.0, 3.0], device=self.device, dtype=dtype
8888
)
89-
var_ln_expected = (torch.exp(var) - 1) * mu_ln_expected**2
89+
var_ln_expected = torch.special.expm1(var) * mu_ln_expected**2
9090
self.assertAllClose(mu_ln, mu_ln_expected)
9191
self.assertAllClose(var_ln, var_ln_expected)
9292

0 commit comments

Comments
 (0)