From 466da73a18731d45b034bfd36011bb3eb150fdd8 Mon Sep 17 00:00:00 2001 From: Sergii Dymchenko Date: Mon, 23 Dec 2024 18:28:48 -0800 Subject: [PATCH] Use expm1 instead of exp - 1 (#2660) Summary: Similarly to https://github.com/pytorch/botorch/pull/2540 and https://github.com/pytorch/botorch/pull/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: https://github.com/pytorch/botorch/pull/2660 Reviewed By: saitcakmak Differential Revision: D67613867 Pulled By: kit1980 fbshipit-source-id: a6305f0f3ec4a3e6ec6f6f6b9c9361a61eaf06e9 --- botorch/test_functions/multi_objective.py | 2 +- test/models/transforms/test_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/botorch/test_functions/multi_objective.py b/botorch/test_functions/multi_objective.py index e76bf78907..c363f3dbae 100644 --- a/botorch/test_functions/multi_objective.py +++ b/botorch/test_functions/multi_objective.py @@ -772,7 +772,7 @@ def penicillin_vectorized(cls, X_input: Tensor) -> Tensor: F_loss = ( V[active] * cls.lambd - * (torch.exp(5 * ((T[active] - cls.T_o) / (cls.T_v - cls.T_o))) - 1) + * torch.special.expm1(5 * ((T[active] - cls.T_o) / (cls.T_v - cls.T_o))) ) dV_dt = F[active] - F_loss mu = ( diff --git a/test/models/transforms/test_utils.py b/test/models/transforms/test_utils.py index a6a41e05e5..da1102f1e1 100644 --- a/test/models/transforms/test_utils.py +++ b/test/models/transforms/test_utils.py @@ -86,7 +86,7 @@ def test_norm_to_lognorm(self): mu_ln_expected = torch.tensor( [1.0, 2.0, 3.0], device=self.device, dtype=dtype ) - var_ln_expected = (torch.exp(var) - 1) * mu_ln_expected**2 + var_ln_expected = torch.special.expm1(var) * mu_ln_expected**2 self.assertAllClose(mu_ln, mu_ln_expected) self.assertAllClose(var_ln, var_ln_expected)