Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
5c8f210c
P
Paddle
项目概览
机器未来
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5c8f210c
编写于
8月 29, 2019
作者:
Z
Zeng Jinle
提交者:
GitHub
8月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine inplace inference registry, test=develop (#19032)
上级
b6d1d890
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
36 addition
and
115 deletion
+36
-115
paddle/fluid/framework/inplace_op_inference.h
paddle/fluid/framework/inplace_op_inference.h
+10
-0
paddle/fluid/operators/activation_op.cc
paddle/fluid/operators/activation_op.cc
+3
-7
paddle/fluid/operators/batch_norm_op.cc
paddle/fluid/operators/batch_norm_op.cc
+2
-25
paddle/fluid/operators/elementwise/elementwise_op.h
paddle/fluid/operators/elementwise/elementwise_op.h
+4
-15
paddle/fluid/operators/flatten_op.cc
paddle/fluid/operators/flatten_op.cc
+4
-15
paddle/fluid/operators/group_norm_op.cc
paddle/fluid/operators/group_norm_op.cc
+4
-15
paddle/fluid/operators/reshape_op.cc
paddle/fluid/operators/reshape_op.cc
+4
-15
paddle/fluid/operators/softmax_with_cross_entropy_op.cc
paddle/fluid/operators/softmax_with_cross_entropy_op.cc
+4
-16
paddle/fluid/operators/sum_op.cc
paddle/fluid/operators/sum_op.cc
+1
-7
未找到文件。
paddle/fluid/framework/inplace_op_inference.h
浏览文件 @
5c8f210c
...
...
@@ -53,5 +53,15 @@ class SingleOpInplaceInToOut : public InplaceOpInference {
}
};
#define DECLARE_INPLACE_OP_INFERER(class_name, ...) \
class class_name final : public ::paddle::framework::InplaceOpInference { \
public: \
std::unordered_map<std::string, std::string> operator()( \
const ::paddle::framework::OpDesc& op_desc, \
bool use_cuda) const final { \
return {__VA_ARGS__}; \
} \
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/operators/activation_op.cc
浏览文件 @
5c8f210c
...
...
@@ -774,13 +774,9 @@ class SquareDoubleGradMaker
}
};
class
ActivationGradOpInplaceInference
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)}};
}
};
DECLARE_INPLACE_OP_INFERER
(
ActivationGradOpInplaceInference
,
{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)});
}
// namespace operators
}
// namespace paddle
...
...
paddle/fluid/operators/batch_norm_op.cc
浏览文件 @
5c8f210c
...
...
@@ -598,36 +598,13 @@ std::unique_ptr<framework::OpDesc> BatchNormGradMaker::Apply() const {
return
std
::
unique_ptr
<
framework
::
OpDesc
>
(
op
);
}
class
BatchNormInplaceInToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
"Mean"
,
"MeanOut"
},
{
"Variance"
,
"VarianceOut"
},
{
"X"
,
"Y"
}};
}
};
class
BatchNormGradInplaceInToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
// Scale, Bias, SavedMean, SavedVariance shape is [batch_size, C]
return
{
{
framework
::
GradVarName
(
"Y"
),
framework
::
GradVarName
(
"X"
)},
{
"SavedMean"
,
framework
::
GradVarName
(
"Scale"
)},
{
"SavedVariance"
,
framework
::
GradVarName
(
"Bias"
)},
};
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
batch_norm
,
ops
::
BatchNormOp
,
ops
::
BatchNormOpMaker
,
ops
::
BatchNormOpInferVarType
,
ops
::
BatchNormGradMaker
)
// ops::BatchNormInplaceInToOut);
REGISTER_OPERATOR
(
batch_norm_grad
,
ops
::
BatchNormGradOp
)
// ops::BatchNormGradInplaceInToOut);
ops
::
BatchNormOpInferVarType
,
ops
::
BatchNormGradMaker
);
REGISTER_OPERATOR
(
batch_norm_grad
,
ops
::
BatchNormGradOp
);
REGISTER_OP_CPU_KERNEL
(
batch_norm
,
ops
::
BatchNormKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
...
...
paddle/fluid/operators/elementwise/elementwise_op.h
浏览文件 @
5c8f210c
...
...
@@ -317,21 +317,10 @@ class ElemwiseGradKernel : public framework::OpKernel<T> {
}
};
class
ElementwiseOpInplace
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
"X"
,
"Out"
}};
}
};
class
ElementwiseGradOpInplace
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)}};
}
};
DECLARE_INPLACE_OP_INFERER
(
ElementwiseOpInplace
,
{
"X"
,
"Out"
});
DECLARE_INPLACE_OP_INFERER
(
ElementwiseGradOpInplace
,
{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)});
DECLARE_NO_NEED_BUFFER_VARS_INFERENCE
(
ElementwiseGradNoBufVarsInference
,
"Y"
);
...
...
paddle/fluid/operators/flatten_op.cc
浏览文件 @
5c8f210c
...
...
@@ -268,21 +268,10 @@ class Flatten2GradOp : public framework::OperatorBase {
}
};
class
FlattenOpInplaceInToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
"X"
,
"Out"
}};
}
};
class
FlattenGradInplaceinToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)}};
}
};
DECLARE_INPLACE_OP_INFERER
(
FlattenOpInplaceInToOut
,
{
"X"
,
"Out"
});
DECLARE_INPLACE_OP_INFERER
(
FlattenGradInplaceinToOut
,
{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)});
}
// namespace operators
}
// namespace paddle
...
...
paddle/fluid/operators/group_norm_op.cc
浏览文件 @
5c8f210c
...
...
@@ -170,21 +170,10 @@ class GroupNormGradMaker : public framework::SingleGradOpDescMaker {
}
};
class
GroupNormInplaceInToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
"X"
,
"Y"
}};
}
};
class
GroupNormGradInplaceInToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
framework
::
GradVarName
(
"Y"
),
framework
::
GradVarName
(
"X"
)}};
}
};
DECLARE_INPLACE_OP_INFERER
(
GroupNormInplaceInToOut
,
{
"X"
,
"Y"
});
DECLARE_INPLACE_OP_INFERER
(
GroupNormGradInplaceInToOut
,
{
framework
::
GradVarName
(
"Y"
),
framework
::
GradVarName
(
"X"
)});
class
GroupNormOpInferVarType
:
public
framework
::
PassInDtypeAndVarTypeToOutput
{
...
...
paddle/fluid/operators/reshape_op.cc
浏览文件 @
5c8f210c
...
...
@@ -393,21 +393,10 @@ class Reshape2GradOp : public framework::OperatorWithKernel {
}
};
class
ReshapeOpInplaceInToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
"X"
,
"Out"
}};
}
};
class
ReshapeGradInplaceInToOut
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)}};
}
};
DECLARE_INPLACE_OP_INFERER
(
ReshapeOpInplaceInToOut
,
{
"X"
,
"Out"
});
DECLARE_INPLACE_OP_INFERER
(
ReshapeGradInplaceInToOut
,
{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)});
}
// namespace operators
}
// namespace paddle
...
...
paddle/fluid/operators/softmax_with_cross_entropy_op.cc
浏览文件 @
5c8f210c
...
...
@@ -255,23 +255,11 @@ class SoftmaxGradMaker : public framework::SingleGradOpDescMaker {
}
};
class
SoftmaxWithCrossEntropyInplaceInference
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
{
return
{{
"Logits"
,
"Softmax"
}};
}
};
DECLARE_INPLACE_OP_INFERER
(
SoftmaxWithCrossEntropyInplaceInference
,
{
"Logits"
,
"Softmax"
});
class
SoftmaxWithCrossEntropyGradInplaceInference
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
{
return
{{
"Softmax"
,
framework
::
GradVarName
(
"Logits"
)}};
}
};
DECLARE_INPLACE_OP_INFERER
(
SoftmaxWithCrossEntropyGradInplaceInference
,
{
"Softmax"
,
framework
::
GradVarName
(
"Logits"
)});
}
// namespace operators
}
// namespace paddle
...
...
paddle/fluid/operators/sum_op.cc
浏览文件 @
5c8f210c
...
...
@@ -238,13 +238,7 @@ class SumGradMaker : public framework::GradOpDescMakerBase {
}
};
class
SumInplace
:
public
framework
::
InplaceOpInference
{
public:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
operator
()(
const
framework
::
OpDesc
&
op_desc
,
bool
use_cuda
)
const
override
{
return
{{
"X"
,
"Out"
}};
}
};
DECLARE_INPLACE_OP_INFERER
(
SumInplace
,
{
"X"
,
"Out"
});
}
// namespace operators
}
// namespace paddle
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录