Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5c669ad1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
5c669ad1
编写于
4月 21, 2020
作者:
W
wawltor
提交者:
GitHub
4月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add the support dygraph out attribute for the op of mm in api2.0 (#23978)
Fix the dygraph mode in matmul, add the support in Linear Op
上级
f5d76b50
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
51 addition
and
8 deletion
+51
-8
paddle/fluid/pybind/op_function_generator.cc
paddle/fluid/pybind/op_function_generator.cc
+2
-1
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+3
-2
python/paddle/fluid/tests/unittests/test_matmul_op.py
python/paddle/fluid/tests/unittests/test_matmul_op.py
+36
-0
python/paddle/tensor/linalg.py
python/paddle/tensor/linalg.py
+5
-3
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+5
-2
未找到文件。
paddle/fluid/pybind/op_function_generator.cc
浏览文件 @
5c669ad1
...
...
@@ -37,7 +37,8 @@ std::map<std::string, std::set<std::string>> op_passing_out_map = {
{
"momentum"
,
{
"ParamOut"
,
"VelocityOut"
}},
{
"batch_norm"
,
{
"MeanOut"
,
"VarianceOut"
}},
{
"accuracy"
,
{
"Correct"
,
"Total"
}},
{
"fill_constant"
,
{
"Out"
}}};
{
"fill_constant"
,
{
"Out"
}},
{
"matmul"
,
{
"Out"
}}};
// clang-format off
const
char
*
OUT_INITIALIZER_TEMPLATE
=
...
...
python/paddle/fluid/dygraph/nn.py
浏览文件 @
5c669ad1
...
...
@@ -936,8 +936,9 @@ class Linear(layers.Layer):
def
forward
(
self
,
input
):
if
in_dygraph_mode
():
pre_bias
=
core
.
ops
.
matmul
(
input
,
self
.
weight
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
pre_bias
=
_varbase_creator
(
dtype
=
input
.
dtype
)
core
.
ops
.
matmul
(
input
,
self
.
weight
,
pre_bias
,
'transpose_X'
,
False
,
'transpose_Y'
,
False
,
"alpha"
,
1
)
pre_act
=
dygraph_utils
.
_append_bias_in_dygraph
(
pre_bias
,
self
.
bias
,
axis
=
len
(
input
.
shape
)
-
1
)
...
...
python/paddle/fluid/tests/unittests/test_matmul_op.py
浏览文件 @
5c669ad1
...
...
@@ -280,6 +280,42 @@ class API_TestMm(unittest.TestCase):
"two value is
\
{}
\n
{}, check diff!"
.
format
(
np_res
,
expected_result
))
def
test_dygraph_with_out
(
self
):
device
=
fluid
.
CPUPlace
()
with
fluid
.
dygraph
.
guard
(
device
):
input_array1
=
np
.
random
.
rand
(
3
,
4
).
astype
(
"float64"
)
input_array2
=
np
.
random
.
rand
(
4
,
3
).
astype
(
"float64"
)
out_array
=
np
.
random
.
rand
(
3
,
3
).
astype
(
"float64"
)
data1
=
fluid
.
dygraph
.
to_variable
(
input_array1
)
data2
=
fluid
.
dygraph
.
to_variable
(
input_array2
)
paddle_out_holder
=
fluid
.
dygraph
.
to_variable
(
out_array
)
out
=
paddle
.
mm
(
data1
,
data2
,
out
=
paddle_out_holder
)
self
.
assertTrue
(
np
.
allclose
(
paddle_out_holder
.
numpy
(),
out
.
numpy
()))
def
test_dygraph_without_out
(
self
):
device
=
fluid
.
CPUPlace
()
with
fluid
.
dygraph
.
guard
(
device
):
input_array1
=
np
.
random
.
rand
(
3
,
4
).
astype
(
"float64"
)
input_array2
=
np
.
random
.
rand
(
4
,
3
).
astype
(
"float64"
)
data1
=
fluid
.
dygraph
.
to_variable
(
input_array1
)
data2
=
fluid
.
dygraph
.
to_variable
(
input_array2
)
out
=
paddle
.
mm
(
data1
,
data2
)
expected_result
=
np
.
matmul
(
input_array1
,
input_array2
)
self
.
assertTrue
(
np
.
allclose
(
expected_result
,
out
.
numpy
()))
class
Test_API_Matmul
(
unittest
.
TestCase
):
def
test_dygraph_without_out
(
self
):
device
=
fluid
.
CPUPlace
()
with
fluid
.
dygraph
.
guard
(
device
):
input_array1
=
np
.
random
.
rand
(
3
,
4
).
astype
(
"float64"
)
input_array2
=
np
.
random
.
rand
(
4
,
3
).
astype
(
"float64"
)
data1
=
fluid
.
dygraph
.
to_variable
(
input_array1
)
data2
=
fluid
.
dygraph
.
to_variable
(
input_array2
)
out
=
paddle
.
matmul
(
data1
,
data2
)
expected_result
=
np
.
matmul
(
input_array1
,
input_array2
)
self
.
assertTrue
(
np
.
allclose
(
expected_result
,
out
.
numpy
()))
class
API_TestMmError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
...
...
python/paddle/tensor/linalg.py
浏览文件 @
5c669ad1
...
...
@@ -15,7 +15,7 @@
from
paddle.common_ops_import
import
*
from
..fluid.layer_helper
import
LayerHelper
from
..fluid.data_feeder
import
check_variable_and_dtype
,
check_type
from
..fluid.framework
import
in_dygraph_mode
from
..fluid.framework
import
in_dygraph_mode
,
_varbase_creator
__all__
=
[
'matmul'
,
...
...
@@ -111,8 +111,10 @@ def matmul(x, y, transpose_x=False, transpose_y=False, alpha=1.0, name=None):
}
if
in_dygraph_mode
():
return
core
.
ops
.
matmul
(
x
,
y
,
'transpose_X'
,
transpose_x
,
'transpose_Y'
,
transpose_y
,
'alpha'
,
float
(
alpha
))
out
=
_varbase_creator
(
dtype
=
x
.
dtype
)
core
.
ops
.
matmul
(
x
,
y
,
out
,
'transpose_X'
,
transpose_x
,
'transpose_Y'
,
transpose_y
,
'alpha'
,
float
(
alpha
))
return
out
def
__check_input
(
x
,
y
):
var_names
=
{
'x'
:
x
,
'y'
:
y
}
...
...
python/paddle/tensor/math.py
浏览文件 @
5c669ad1
...
...
@@ -19,7 +19,7 @@ from __future__ import print_function
from
paddle.common_ops_import
import
*
from
..fluid
import
layers
from
..fluid.framework
import
core
from
..fluid.framework
import
core
,
_varbase_creator
from
..fluid.layers.layer_function_generator
import
_generate_doc_string_
import
sys
...
...
@@ -904,7 +904,10 @@ def mm(input, mat2, out=None, name=None):
out = paddle.mm(x, mat2) # out shape is [2, 2]
"""
if
in_dygraph_mode
():
return
core
.
ops
.
matmul
(
input
,
mat2
)
if
out
is
None
:
out
=
_varbase_creator
(
dtype
=
input
.
dtype
)
core
.
ops
.
matmul
(
input
,
mat2
,
out
)
return
out
def
__check_input
(
x
,
y
):
var_names
=
{
'x'
:
x
,
'y'
:
y
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录