From e878137bb3171f51390dcecfd22f8eaa2a8143c6 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Wed, 18 Oct 2023 14:31:29 +0200 Subject: [PATCH] RF safe_log, better default eps --- returnn/frontend/math_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/returnn/frontend/math_.py b/returnn/frontend/math_.py index 3b9316b2b6..d1b5ee24f5 100644 --- a/returnn/frontend/math_.py +++ b/returnn/frontend/math_.py @@ -378,7 +378,7 @@ def log(a: Tensor) -> Tensor: def safe_log(a: Tensor, *, eps: Optional[float] = None) -> Tensor: """safe_log""" if eps is None: - eps = numpy.nextafter(numpy.array(0, dtype=a.dtype), numpy.array(1, dtype=a.dtype)) + eps = {"float16": 6e-08, "bfloat16": 9.1835e-41, "float32": 1.4013e-45, "float64": 4.9407e-324}[a.dtype] # noinspection PyProtectedMember return a._raw_backend.safe_log(a, eps=eps)