Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
6fc3e8ec
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6fc3e8ec
编写于
11月 20, 2019
作者:
D
danleifeng
提交者:
gongweibao
11月 20, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
edit elementwise_mul doublegrad inplace (#21245)
上级
508b898d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
25 deletion
+39
-25
paddle/fluid/operators/elementwise/elementwise_div_op.cc
paddle/fluid/operators/elementwise/elementwise_div_op.cc
+1
-1
paddle/fluid/operators/elementwise/elementwise_div_op.h
paddle/fluid/operators/elementwise/elementwise_div_op.h
+0
-2
paddle/fluid/operators/elementwise/elementwise_mul_op.cc
paddle/fluid/operators/elementwise/elementwise_mul_op.cc
+1
-1
paddle/fluid/operators/elementwise/elementwise_mul_op.h
paddle/fluid/operators/elementwise/elementwise_mul_op.h
+37
-21
未找到文件。
paddle/fluid/operators/elementwise/elementwise_div_op.cc
浏览文件 @
6fc3e8ec
...
...
@@ -128,7 +128,7 @@ REGISTER_OPERATOR(
ops
::
ElementwiseDivDoubleGradMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OPERATOR
(
elementwise_div_grad_grad
,
ops
::
ElementwiseDivOpDoubleGrad
,
ops
::
ElementwiseD
ivD
oubleGradOpInplace
);
ops
::
ElementwiseDoubleGradOpInplace
);
REGISTER_OP_CPU_KERNEL
(
elementwise_div
,
...
...
paddle/fluid/operators/elementwise/elementwise_div_op.h
浏览文件 @
6fc3e8ec
...
...
@@ -246,7 +246,5 @@ class ElementwiseDivDoubleGradKernel : public framework::OpKernel<T> {
}
};
DECLARE_INPLACE_OP_INFERER
(
ElementwiseDivDoubleGradOpInplace
,
{
"DDX"
,
"DDOut"
});
}
// namespace operators
}
// namespace paddle
paddle/fluid/operators/elementwise/elementwise_mul_op.cc
浏览文件 @
6fc3e8ec
...
...
@@ -127,7 +127,7 @@ REGISTER_OPERATOR(
ops
::
ElementwiseMulDoubleGradMaker
<
paddle
::
imperative
::
OpBase
>
);
REGISTER_OPERATOR
(
elementwise_mul_grad_grad
,
ops
::
ElementwiseOpDoubleGrad
,
ops
::
Elementwise
Mul
DoubleGradOpInplace
);
ops
::
ElementwiseDoubleGradOpInplace
);
REGISTER_OP_CPU_KERNEL
(
elementwise_mul
,
...
...
paddle/fluid/operators/elementwise/elementwise_mul_op.h
浏览文件 @
6fc3e8ec
...
...
@@ -172,34 +172,50 @@ class ElementwiseMulDoubleGradKernel : public framework::OpKernel<T> {
// (2) dy = dout * ddx
// (3) ddout = ddx * y
// (4) ddout = ddout + dx
// (5) dx = dout *ddy
// (5) dx = dout *
ddy
if
(
ddout
)
{
// use dx to save memory, other than alloc tmp tensor
Tensor
*
ddout_tmp
=
dx
;
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
x
,
&
ddy_safe
,
ddout_tmp
);
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
// NOTE: in the following ElemwiseGradCompute, for the
// first output tensor is nullptr, the branch to calculate first
// output tensor will not be activated, DivGradDx function will not
// be called and can be ignored, the first branch has little effect
// on running speed.
ElemwiseGradCompute
<
DeviceContext
,
T
,
MulGradDX
<
T
>
,
MulGradDY
<
T
>>
(
ctx
,
ddx_safe
,
ddy_safe
,
*
dout
,
*
dout
,
axis
,
nullptr
,
dy
,
MulGradDX
<
T
>
(),
MulGradDY
<
T
>
());
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
&
ddx_safe
,
y
,
ddout
);
auto
&
place
=
*
ctx
.
template
device_context
<
DeviceContext
>().
eigen_device
();
auto
ddout_t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
ddout
);
auto
ddout_tmp_t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
ddout_tmp
);
ddout_t
.
device
(
place
)
=
ddout_t
+
ddout_tmp_t
;
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
dout
,
&
ddy_safe
,
dx
);
// size(ddout) > size(ddx), ddout can't use memory of ddx using inplace
if
(
ddout
->
numel
()
>
ddx
->
numel
())
{
ElemwiseGradCompute
<
DeviceContext
,
T
,
MulGradDX
<
T
>
,
MulGradDY
<
T
>>
(
ctx
,
ddx_safe
,
ddy_safe
,
*
dout
,
*
dout
,
axis
,
dx
,
dy
,
MulGradDX
<
T
>
(),
MulGradDY
<
T
>
());
Tensor
ddout_tmp
;
ddout_tmp
.
mutable_data
<
T
>
(
ddout
->
dims
(),
ctx
.
GetPlace
());
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
y
,
&
ddx_safe
,
ddout
);
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
&
ddy_safe
,
x
,
&
ddout_tmp
);
auto
ddout_t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
ddout
);
auto
ddout_tmp_t
=
framework
::
EigenVector
<
T
>::
Flatten
(
ddout_tmp
);
ddout_t
.
device
(
place
)
=
ddout_t
+
ddout_tmp_t
;
}
else
{
// use dx to save memory, other than alloc tmp tensor
Tensor
*
ddout_tmp
=
dx
;
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
x
,
&
ddy_safe
,
ddout_tmp
);
// NOTE: in the following ElemwiseGradCompute, for the
// first output tensor is nullptr, the branch to calculate first
// output tensor will not be activated, DivGradDx function will not
// be called and can be ignored, the first branch has little effect
// on running speed.
ElemwiseGradCompute
<
DeviceContext
,
T
,
MulGradDX
<
T
>
,
MulGradDY
<
T
>>
(
ctx
,
ddx_safe
,
ddy_safe
,
*
dout
,
*
dout
,
axis
,
nullptr
,
dy
,
MulGradDX
<
T
>
(),
MulGradDY
<
T
>
());
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
&
ddx_safe
,
y
,
ddout
);
auto
ddout_t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
ddout
);
auto
ddout_tmp_t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
ddout_tmp
);
ddout_t
.
device
(
place
)
=
ddout_t
+
ddout_tmp_t
;
default_elementwise_mul
<
DeviceContext
,
T
>
(
ctx
,
dout
,
&
ddy_safe
,
dx
);
}
}
}
};
DECLARE_INPLACE_OP_INFERER
(
ElementwiseMulDoubleGradOpInplace
,
{
"DDX"
,
"DDOut"
});
}
// namespace operators
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录