Skip to content

Commit 348fa91

Browse files
authored
[API Compatibility] add out parameter to sqrt (#74795)
* update * fix * update * update * update
1 parent 8bb6606 commit 348fa91

26 files changed

+120
-6563
lines changed

paddle/phi/ops/yaml/ops.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5222,6 +5222,10 @@
52225222

52235223
- op : sqrt
52245224
args : (Tensor x)
5225+
python_api :
5226+
name : [paddle.sqrt,paddle.Tensor.sqrt]
5227+
args_alias:
5228+
x : [input]
52255229
output : Tensor(out)
52265230
infer_meta :
52275231
func : UnchangedInferMeta

python/paddle/_paddle_docs.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,43 @@ def floor(
11301130
""",
11311131
)
11321132
# hehongyu
1133+
add_doc_and_signature(
1134+
"sqrt",
1135+
"""
1136+
Sqrt Activation Operator.
1137+
1138+
.. math::
1139+
out=\\sqrt{x}=x^{1/2}
1140+
1141+
Args:
1142+
x (Tensor): Input of Sqrt operator, an N-D Tensor, with data type float32, float64, float16, bfloat16
1143+
uint8, int8, int16, int32, int64.
1144+
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
1145+
1146+
Returns:
1147+
Tensor. Output of Sqrt operator, a Tensor with shape same as input
1148+
(integer types are autocasted into float32).
1149+
1150+
Examples:
1151+
.. code-block:: python
1152+
1153+
>>> import paddle
1154+
1155+
>>> x = paddle.to_tensor([0.1, 0.2, 0.3, 0.4])
1156+
>>> out = paddle.sqrt(x)
1157+
>>> print(out)
1158+
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
1159+
[0.31622776, 0.44721359, 0.54772258, 0.63245553])
1160+
""",
1161+
"""
1162+
def sqrt(
1163+
x: Tensor,
1164+
name: str | None = None,
1165+
*,
1166+
out: Tensor | None = None,
1167+
) -> Tensor
1168+
""",
1169+
)
11331170

11341171
# lousiyu
11351172

python/paddle/tensor/ops.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
floor,
2121
rsqrt,
2222
sin,
23+
sqrt,
2324
)
2425
from paddle.utils.inplace_utils import inplace_apis_in_dygraph_only
2526

@@ -872,60 +873,6 @@ def sinh(x: Tensor, name: str | None = None) -> Tensor:
872873
return out
873874

874875

875-
def sqrt(x: Tensor, name: str | None = None) -> Tensor:
876-
"""
877-
Sqrt Activation Operator.
878-
879-
.. math::
880-
out=\\sqrt{x}=x^{1/2}
881-
882-
Args:
883-
x (Tensor): Input of Sqrt operator, an N-D Tensor, with data type float32, float64, float16, bfloat16
884-
uint8, int8, int16, int32, int64.
885-
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
886-
887-
Returns:
888-
Tensor. Output of Sqrt operator, a Tensor with shape same as input
889-
(integer types are autocasted into float32).
890-
891-
Examples:
892-
.. code-block:: python
893-
894-
>>> import paddle
895-
896-
>>> x = paddle.to_tensor([0.1, 0.2, 0.3, 0.4])
897-
>>> out = paddle.sqrt(x)
898-
>>> print(out)
899-
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
900-
[0.31622776, 0.44721359, 0.54772258, 0.63245553])
901-
"""
902-
if in_dynamic_or_pir_mode():
903-
return _C_ops.sqrt(x)
904-
else:
905-
check_variable_and_dtype(
906-
x,
907-
'x',
908-
[
909-
'float16',
910-
'uint16',
911-
'float32',
912-
'float64',
913-
'uint8',
914-
'int8',
915-
'int16',
916-
'int32',
917-
'int64',
918-
'complex64',
919-
'complex128',
920-
],
921-
'sqrt',
922-
)
923-
helper = LayerHelper('sqrt', **locals())
924-
out = helper.create_variable_for_type_inference(dtype=x.dtype)
925-
helper.append_op(type='sqrt', inputs={"X": x}, outputs={"Out": out})
926-
return out
927-
928-
929876
def square(x: Tensor, name: str | None = None) -> Tensor:
930877
"""
931878
Square each elements of the inputs.

test/amp/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,3 @@ endfunction()
5353
foreach(TEST_OP ${TEST_OPS})
5454
py_test_modules(${TEST_OP} MODULES ${TEST_OP})
5555
endforeach()
56-
57-
if(APPLE)
58-
set_tests_properties(test_model_cast_to_bf16 PROPERTIES TIMEOUT 300)
59-
endif()

test/amp/test_amp_master_grad_static.py

Lines changed: 0 additions & 216 deletions
This file was deleted.

0 commit comments

Comments
 (0)