@@ -33,7 +33,6 @@ __all__ = [ | |||||
"equal", | "equal", | ||||
"exp", | "exp", | ||||
"expm1", | "expm1", | ||||
"fast_tanh", | |||||
"floor", | "floor", | ||||
"floor_div", | "floor_div", | ||||
"greater", | "greater", | ||||
@@ -369,15 +368,6 @@ def atanh(x): | |||||
return log1p(2 * x / (1 - x)) / 2 | return log1p(2 * x / (1 - x)) / 2 | ||||
def fast_tanh(x): | |||||
r"""Element-wise `fast tanh`; this is an approximation: | |||||
.. math:: | |||||
\text{fast_tanh}(x) = x * (27. + x * x) / (27. + 9. * x * x) | |||||
""" | |||||
return _elwise(x, mode="fast_tanh") | |||||
# bit-twiddling functions | # bit-twiddling functions | ||||
@@ -34,7 +34,7 @@ class Elemwise(Module): | |||||
* "EXP": exp(x) | * "EXP": exp(x) | ||||
* "TANH": tanh(x) | * "TANH": tanh(x) | ||||
* "FUSE_MUL_ADD3": x * y + z | * "FUSE_MUL_ADD3": x * y + z | ||||
* "FAST_TANH": fast_tanh(x) | |||||
* "FAST_TANH": x * (27. + x * x) / (27. + 9. * x * x) | |||||
* "NEGATE": -x | * "NEGATE": -x | ||||
* "ACOS": acos(x) | * "ACOS": acos(x) | ||||
* "ASIN": asin(x) | * "ASIN": asin(x) | ||||
@@ -113,14 +113,6 @@ def test_atanh(): | |||||
np.testing.assert_almost_equal(y_np, y_mge, decimal=5) | np.testing.assert_almost_equal(y_np, y_mge, decimal=5) | ||||
def test_fast_tanh(): | |||||
np.random.seed(42) | |||||
x = np.random.randn(100).astype("float32") | |||||
y_np = x * (27.0 + x * x) / (27.0 + 9.0 * x * x) | |||||
y_mge = F.fast_tanh(tensor(x)).numpy() | |||||
np.testing.assert_almost_equal(y_np, y_mge, decimal=6) | |||||
def test_hswish(): | def test_hswish(): | ||||
np.random.seed(42) | np.random.seed(42) | ||||
x = np.random.randn(100).astype("float32") | x = np.random.randn(100).astype("float32") | ||||