Browse Source

feat(mge): remove fast_tanh

GitOrigin-RevId: 7ad5f7ecce
release-1.1
Megvii Engine Team 4 years ago
parent
commit
67d33303ad
3 changed files with 1 additions and 19 deletions
  1. +0
    -10
      imperative/python/megengine/functional/elemwise.py
  2. +1
    -1
      imperative/python/megengine/module/elemwise.py
  3. +0
    -8
      imperative/python/test/unit/functional/test_elemwise.py

+ 0
- 10
imperative/python/megengine/functional/elemwise.py View File

@@ -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






+ 1
- 1
imperative/python/megengine/module/elemwise.py View File

@@ -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)


+ 0
- 8
imperative/python/test/unit/functional/test_elemwise.py View File

@@ -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")


Loading…
Cancel
Save