Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b3caa233
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b3caa233
编写于
3月 15, 2023
作者:
G
Guoxia Wang
提交者:
GitHub
3月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add inplace sigmoid_ and multiply_ (#50267)
上级
77d9b4c3
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
86 addition
and
0 deletion
+86
-0
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+1
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+1
-0
python/paddle/fluid/tests/unittests/test_multiply.py
python/paddle/fluid/tests/unittests/test_multiply.py
+52
-0
python/paddle/tensor/__init__.py
python/paddle/tensor/__init__.py
+6
-0
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+25
-0
python/paddle/tensor/ops.py
python/paddle/tensor/ops.py
+1
-0
未找到文件。
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
b3caa233
...
...
@@ -1196,6 +1196,7 @@
kernel
:
func
:
multiply {dense, dense -> dense},
multiply_sr {selected_rows, dense -> selected_rows}
inplace
:
(x -> out)
backward
:
multiply_grad
-
op
:
nms
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
b3caa233
...
...
@@ -1261,6 +1261,7 @@
func
:
UnchangedInferMeta
kernel
:
func
:
sigmoid
inplace
:
(x -> out)
backward
:
sigmoid_grad
-
op
:
sign
...
...
python/paddle/fluid/tests/unittests/test_multiply.py
浏览文件 @
b3caa233
...
...
@@ -181,5 +181,57 @@ class TestMultiplyError(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
paddle
.
multiply
,
x_data
,
y_data
)
class
TestMultiplyInplaceApi
(
TestMultiplyApi
):
def
_run_static_graph_case
(
self
,
x_data
,
y_data
):
with
program_guard
(
Program
(),
Program
()):
paddle
.
enable_static
()
x
=
paddle
.
static
.
data
(
name
=
'x'
,
shape
=
x_data
.
shape
,
dtype
=
x_data
.
dtype
)
y
=
paddle
.
static
.
data
(
name
=
'y'
,
shape
=
y_data
.
shape
,
dtype
=
y_data
.
dtype
)
res
=
x
.
multiply_
(
y
)
place
=
(
paddle
.
CUDAPlace
(
0
)
if
paddle
.
is_compiled_with_cuda
()
else
paddle
.
CPUPlace
()
)
exe
=
paddle
.
static
.
Executor
(
place
)
outs
=
exe
.
run
(
paddle
.
static
.
default_main_program
(),
feed
=
{
'x'
:
x_data
,
'y'
:
y_data
},
fetch_list
=
[
res
],
)
res
=
outs
[
0
]
return
res
def
_run_dynamic_graph_case
(
self
,
x_data
,
y_data
):
paddle
.
disable_static
()
with
paddle
.
no_grad
():
x
=
paddle
.
to_tensor
(
x_data
)
y
=
paddle
.
to_tensor
(
y_data
)
x
.
multiply_
(
y
)
return
x
.
numpy
()
class
TestMultiplyInplaceError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
paddle
.
disable_static
()
# test dynamic computation graph: inputs must be broadcastable
x_data
=
np
.
random
.
rand
(
3
,
4
)
y_data
=
np
.
random
.
rand
(
2
,
3
,
4
)
x
=
paddle
.
to_tensor
(
x_data
)
y
=
paddle
.
to_tensor
(
y_data
)
def
multiply_shape_error
():
with
paddle
.
no_grad
():
x
.
multiply_
(
y
)
self
.
assertRaises
(
ValueError
,
multiply_shape_error
)
paddle
.
enable_static
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/tensor/__init__.py
浏览文件 @
b3caa233
...
...
@@ -192,6 +192,7 @@ from .math import remainder_ # noqa: F401
from
.math
import
mod
# noqa: F401
from
.math
import
floor_mod
# noqa: F401
from
.math
import
multiply
# noqa: F401
from
.math
import
multiply_
# noqa: F401
from
.math
import
add
# noqa: F401
from
.math
import
add_
# noqa: F401
from
.math
import
subtract
# noqa: F401
...
...
@@ -243,6 +244,8 @@ from .math import frac # noqa: F401
from
.math
import
sgn
# noqa: F401
from
.math
import
take
# noqa: F401
from
.math
import
frexp
# noqa: F401
from
.math
import
sigmoid
# noqa: F401
from
.math
import
sigmoid_
# noqa: F401
from
.random
import
multinomial
# noqa: F401
from
.random
import
standard_normal
# noqa: F401
...
...
@@ -380,6 +383,7 @@ tensor_method_func = [ # noqa
'mod'
,
'floor_mod'
,
'multiply'
,
'multiply_'
,
'add'
,
'add_'
,
'subtract'
,
...
...
@@ -525,6 +529,8 @@ tensor_method_func = [ # noqa
'bucketize'
,
'sgn'
,
'frexp'
,
'sigmoid'
,
'sigmoid_'
,
]
# this list used in math_op_patch.py for magic_method bind
...
...
python/paddle/tensor/math.py
浏览文件 @
b3caa233
...
...
@@ -34,6 +34,7 @@ from ..fluid.data_feeder import (
)
from
..framework
import
(
LayerHelper
,
_dygraph_tracer
,
convert_np_dtype_to_dtype_
,
core
,
in_dygraph_mode
,
...
...
@@ -64,6 +65,8 @@ from .ops import round # noqa: F401
from
.ops
import
round_
# noqa: F401
from
.ops
import
rsqrt
# noqa: F401
from
.ops
import
rsqrt_
# noqa: F401
from
.ops
import
sigmoid
# noqa: F401
from
.ops
import
sigmoid_
# noqa: F401
from
.ops
import
sin
# noqa: F401
from
.ops
import
sinh
# noqa: F401
from
.ops
import
sqrt
# noqa: F401
...
...
@@ -893,6 +896,28 @@ def multiply(x, y, name=None):
return
_elementwise_op
(
LayerHelper
(
'elementwise_mul'
,
**
locals
()))
@
inplace_apis_in_dygraph_only
def
multiply_
(
x
,
y
,
name
=
None
):
"""
Inplace version of ``multiply`` API, the output Tensor will be inplaced with input ``x``.
Please refer to :ref:`api_tensor_multiply`.
"""
assert
(
_dygraph_tracer
().
_has_grad
is
False
),
"The current inplace version of multiply_ needs to be used in the context of paddle.no_grad() since inplace multiply_grad is not yet supported."
out_shape
=
broadcast_shape
(
x
.
shape
,
y
.
shape
)
if
out_shape
!=
x
.
shape
:
raise
ValueError
(
"The shape of broadcast output {} is different from that of inplace tensor {} in the Inplace operation."
.
format
(
out_shape
,
x
.
shape
)
)
return
_C_ops
.
multiply_
(
x
,
y
)
@
dygraph_only
def
_elementwise_op_with_axis_in_dygraph
(
x
,
y
,
axis
=-
1
,
name
=
None
,
op_type
=
"Undifined"
...
...
python/paddle/tensor/ops.py
浏览文件 @
b3caa233
...
...
@@ -47,6 +47,7 @@ __inplace_unary_func__ = [
'floor_'
,
'round_'
,
'reciprocal_'
,
'sigmoid_'
,
]
__all__
=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录