fix asinh gradient at zero (#17758)

This commit is contained in:
Teddy Tennant
2026-08-27 09:51:17 -04:00
committed by GitHub
parent f19d89e29a
commit 5c3d044465
2 changed files with 2 additions and 1 deletions
+1
View File
@@ -1813,6 +1813,7 @@ class TestOps(unittest.TestCase):
helper_test_op([(45,65)], lambda x: x.asinh(), grad_atol=1e-6, low=-300, high=-297)
helper_test_op([(45,65)], lambda x: x.asinh(), grad_atol=1e-6, low=300, high=303)
helper_test_op([(45,65)], lambda x: x.asinh(), grad_atol=1e-6, low=-1e10, high=-1e9)
helper_test_op(None, lambda x: x.asinh(), grad_atol=1e-6, vals=[[-1.0, 0.0, 1.0]])
def test_acosh(self):
helper_test_op([(45,65)], lambda x: x.acosh(), grad_atol=1e-6)
helper_test_op([(45,65)], lambda x: x.acosh(), grad_atol=1e-3, grad_rtol=1e-2, low=-300, high=-297)
+1 -1
View File
@@ -870,7 +870,7 @@ class ElementwiseMixin(CreationMixin):
print(Tensor([-3., -2., -1., 0., 1., 2., 3.]).asinh().numpy())
```
"""
return self.sign() * (self.abs() + (self.square() + 1).sqrt()).log()
return (sg:=(self<0).where(-1.0, 1.0)) * (self*sg + (self.square() + 1).sqrt()).log()
def acosh(self) -> Self:
"""