Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions paddle/phi/ops/yaml/python_api_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
x : [input]
args_mapper :
func : GeluMapper

- op : sum
name : [paddle.sum, paddle.Tensor.sum]
args_alias:
Expand All @@ -192,3 +193,8 @@
func : SumPreProcess(x, axis)
args_mapper :
func : ArgSumMapper

- op : tanh
name : [paddle.tanh, paddle.Tensor.tanh, paddle.nn.functional.tanh]
args_alias:
use_default_mapping : True
40 changes: 40 additions & 0 deletions python/paddle/_paddle_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,46 @@ def dot(
""",
)

add_doc_and_signature(
"tanh",
r"""
Tanh Activation Operator.

.. math::
out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}

.. note::
Alias Support:
1. The parameter name ``input`` can be used as an alias for ``x``.

Args:
x (Tensor): Input of Tanh operator, an N-D Tensor, with data type bfloat16, float32, float64,
float16, uint8, int8, int16, int32, int64. Alias: ``input``.
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
out (Tensor|None, optional): The output tensor.

Returns:
Output of Tanh operator, a Tensor with same data type and shape as input
(integer types are autocasted into float32).

Examples:

.. code-block:: python

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.tanh(x)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.37994900, -0.19737528, 0.09966799, 0.29131261])
""",
"""
def tanh(
x: Tensor, name: str | None = None, *, out: Tensor | None = None
) -> Tensor
""",
)
# lubingxin

# chenhuangrun
Expand Down
55 changes: 1 addition & 54 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
sign,
sin,
sum,
tanh,
)
from paddle.base.libpaddle import DataType
from paddle.common_ops_import import VarDesc, dygraph_utils
Expand Down Expand Up @@ -4454,60 +4455,6 @@ def prod(
return out


def tanh(x: Tensor, name: str | None = None) -> Tensor:
r"""
Tanh Activation Operator.

.. math::
out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}

Args:
x (Tensor): Input of Tanh operator, an N-D Tensor, with data type bfloat16, float32, float64,
float16, uint8, int8, int16, int32, int64.
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
Output of Tanh operator, a Tensor with same data type and shape as input
(integer types are autocasted into float32).

Examples:

.. code-block:: python

>>> import paddle

>>> x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
>>> out = paddle.tanh(x)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.37994900, -0.19737528, 0.09966799, 0.29131261])
"""
if in_dynamic_or_pir_mode():
return _C_ops.tanh(x)
else:
check_variable_and_dtype(
x,
'x',
[
'uint16',
'float16',
'float32',
'float64',
'uint8',
'int8',
'int16',
'int32',
'int64',
],
'tanh',
)
check_type(x, 'x', (Variable), 'tanh')
helper = LayerHelper('tanh', **locals())
out = helper.create_variable_for_type_inference(x.dtype)
helper.append_op(type='tanh', inputs={'X': x}, outputs={'Out': out})
return out


@inplace_apis_in_dygraph_only
def tanh_(x: Tensor, name: str | None = None) -> Tensor:
r"""
Expand Down
2 changes: 2 additions & 0 deletions test/standalone_executor/test_standalone_custom_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

import paddle
Expand All @@ -23,6 +24,7 @@
split_program,
)

os.environ['FLAGS_enable_pir_api'] = '1'
paddle.enable_static()


Expand Down
2 changes: 2 additions & 0 deletions test/standalone_executor/test_standalone_custom_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import unittest

Expand All @@ -22,6 +23,7 @@
import paddle
from paddle.base import core

os.environ['FLAGS_enable_pir_api'] = '1'
paddle.enable_static()


Expand Down
1 change: 1 addition & 0 deletions test/standalone_executor/test_standalone_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from paddle.base import core
from paddle.profiler import profiler

os.environ['FLAGS_enable_pir_api'] = '1'
paddle.enable_static()


Expand Down
Loading