Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
urhero
Paddle
提交
359fec05
P
Paddle
项目概览
urhero
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
359fec05
编写于
4月 01, 2019
作者:
Z
Zeng Jinle
提交者:
GitHub
4月 01, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16527 from sneaxiy/feature/check_default_grad_maker
Check default grad op maker revision
上级
2e1e76e7
10249c0b
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
242 addition
and
43 deletion
+242
-43
paddle/fluid/framework/details/op_registry.h
paddle/fluid/framework/details/op_registry.h
+5
-0
paddle/fluid/framework/grad_op_desc_maker.h
paddle/fluid/framework/grad_op_desc_maker.h
+6
-12
paddle/fluid/framework/op_info.cc
paddle/fluid/framework/op_info.cc
+15
-0
paddle/fluid/framework/op_info.h
paddle/fluid/framework/op_info.h
+7
-0
paddle/fluid/op_use_default_grad_op_maker.spec
paddle/fluid/op_use_default_grad_op_maker.spec
+94
-0
paddle/fluid/operators/fused/fused_embedding_seq_pool_op.cc
paddle/fluid/operators/fused/fused_embedding_seq_pool_op.cc
+1
-12
paddle/fluid/operators/lookup_table_op.cc
paddle/fluid/operators/lookup_table_op.cc
+2
-10
paddle/fluid/operators/nce_op.cc
paddle/fluid/operators/nce_op.cc
+3
-9
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+4
-0
paddle/scripts/paddle_build.sh
paddle/scripts/paddle_build.sh
+10
-0
tools/diff_use_default_grad_op_maker.py
tools/diff_use_default_grad_op_maker.py
+66
-0
tools/generate_op_use_grad_op_desc_maker_spec.py
tools/generate_op_use_grad_op_desc_maker_spec.py
+29
-0
未找到文件。
paddle/fluid/framework/details/op_registry.h
浏览文件 @
359fec05
...
...
@@ -16,6 +16,7 @@ limitations under the License. */
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
...
...
@@ -183,6 +184,10 @@ struct OpInfoFiller<T, kGradOpDescMaker> {
T
maker
(
fwd_op
,
no_grad_set
,
grad_to_var
,
grad_block
);
return
maker
();
};
info
->
use_default_grad_op_desc_maker_
=
std
::
is_base_of
<
DefaultGradOpDescMaker
<
true
>
,
T
>::
value
||
std
::
is_base_of
<
DefaultGradOpDescMaker
<
false
>
,
T
>::
value
;
}
};
...
...
paddle/fluid/framework/grad_op_desc_maker.h
浏览文件 @
359fec05
...
...
@@ -147,7 +147,7 @@ class SingleGradOpDescMaker : public GradOpDescMakerBase {
public:
using
GradOpDescMakerBase
::
GradOpDescMakerBase
;
std
::
vector
<
std
::
unique_ptr
<
OpDesc
>>
operator
()()
const
{
std
::
vector
<
std
::
unique_ptr
<
OpDesc
>>
operator
()()
const
final
{
std
::
vector
<
std
::
unique_ptr
<
OpDesc
>>
retv
;
retv
.
emplace_back
(
this
->
Apply
());
return
retv
;
...
...
@@ -158,14 +158,14 @@ class SingleGradOpDescMaker : public GradOpDescMakerBase {
};
template
<
bool
DropEmptyIG
=
true
>
class
DefaultGradOpDescMaker
:
public
SingleGradOpDescMaker
{
class
DefaultGradOpDescMaker
final
:
public
SingleGradOpDescMaker
{
public:
using
SingleGradOpDescMaker
::
SingleGradOpDescMaker
;
protected:
virtual
std
::
unique_ptr
<
OpDesc
>
Apply
()
const
{
std
::
unique_ptr
<
OpDesc
>
Apply
()
const
final
{
auto
*
grad
=
new
OpDesc
();
grad
->
SetType
(
this
->
GradOpType
()
);
grad
->
SetType
(
this
->
ForwardOpType
()
+
"_grad"
);
for
(
auto
&
input_param
:
this
->
InputNames
())
{
grad
->
SetInput
(
input_param
,
this
->
Input
(
input_param
));
...
...
@@ -182,18 +182,12 @@ class DefaultGradOpDescMaker : public SingleGradOpDescMaker {
return
std
::
unique_ptr
<
OpDesc
>
(
grad
);
}
virtual
std
::
string
GradOpType
()
const
{
return
this
->
ForwardOpType
()
+
"_grad"
;
}
};
class
EmptyGradOpMaker
:
public
GradOpDescMakerBase
{
class
EmptyGradOpMaker
final
:
public
GradOpDescMakerBase
{
public:
using
GradOpDescMakerBase
::
GradOpDescMakerBase
;
std
::
vector
<
std
::
unique_ptr
<
OpDesc
>>
operator
()()
const
override
{
return
{};
}
std
::
vector
<
std
::
unique_ptr
<
OpDesc
>>
operator
()()
const
final
{
return
{};
}
};
}
// namespace framework
...
...
paddle/fluid/framework/op_info.cc
浏览文件 @
359fec05
...
...
@@ -13,6 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/framework/op_info.h"
#include <set>
#include <string>
#include <vector>
namespace
paddle
{
namespace
framework
{
...
...
@@ -24,5 +27,17 @@ OpInfoMap& OpInfoMap::Instance() {
static
OpInfoMap
g_op_info_map
;
return
g_op_info_map
;
}
std
::
vector
<
std
::
string
>
OpInfoMap
::
GetUseDefaultGradOpDescMakerOps
()
const
{
// Use set to sort op names
std
::
set
<
std
::
string
>
result_ops
;
for
(
auto
&
pair
:
map_
)
{
if
(
pair
.
second
.
use_default_grad_op_desc_maker_
)
{
result_ops
.
insert
(
pair
.
first
);
}
}
return
std
::
vector
<
std
::
string
>
(
result_ops
.
begin
(),
result_ops
.
end
());
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/op_info.h
浏览文件 @
359fec05
...
...
@@ -17,6 +17,7 @@ limitations under the License. */
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "paddle/fluid/framework/attribute.h"
#include "paddle/fluid/framework/no_need_buffer_vars_inference.h"
...
...
@@ -42,6 +43,10 @@ struct OpInfo {
InferInplaceOpFN
infer_inplace_
;
InferNoNeedBufferVarsFN
infer_no_need_buffer_vars_
;
// NOTE(zjl): this flag is added to check whether
// the grad maker is the default one.
bool
use_default_grad_op_desc_maker_
{
false
};
bool
HasOpProtoAndChecker
()
const
{
return
proto_
!=
nullptr
&&
checker_
!=
nullptr
;
}
...
...
@@ -105,6 +110,8 @@ class OpInfoMap {
std
::
unordered_map
<
std
::
string
,
OpInfo
>*
mutable_map
()
{
return
&
map_
;
}
std
::
vector
<
std
::
string
>
GetUseDefaultGradOpDescMakerOps
()
const
;
private:
OpInfoMap
()
=
default
;
std
::
unordered_map
<
std
::
string
,
OpInfo
>
map_
;
...
...
paddle/fluid/op_use_default_grad_op_maker.spec
0 → 100644
浏览文件 @
359fec05
abs
acos
asin
atan
attention_lstm
bilinear_tensor_product
brelu
conv_shift
cos
cos_sim
dequantize
elementwise_div
elementwise_max
elementwise_min
elu
fc
flatten
fsp
fused_embedding_fc_lstm
fused_embedding_seq_pool
fusion_gru
fusion_lstm
fusion_repeated_fc_relu
fusion_seqconv_eltadd_relu
fusion_seqexpand_concat_fc
fusion_seqpool_concat
fusion_squared_mat_sub
gelu
gru
hard_shrink
hierarchical_sigmoid
hinge_loss
huber_loss
leaky_relu
log
logsigmoid
lookup_table
lrn
lstm_unit
lstmp
max_pool2d_with_index
max_pool3d_with_index
maxout
modified_huber_loss
nce
norm
pool2d
pool3d
pow
prelu
quantize
rank_loss
reduce_max
reduce_mean
reduce_min
reduce_prod
reduce_sum
requantize
reshape
rnn_memory_helper
round
row_conv
sequence_concat
sequence_conv
sequence_expand
sequence_expand_as
sequence_pad
sequence_scatter
sequence_slice
sequence_softmax
sequence_unpad
sigmoid_cross_entropy_with_logits
sin
softplus
softshrink
softsign
space_to_depth
spp
square
squared_l2_distance
squared_l2_norm
squeeze
stanh
swish
tanh_shrink
teacher_student_sigmoid_loss
temporal_shift
tensor_array_to_tensor
thresholded_relu
transpose
tree_conv
unpool
unsqueeze
warpctc
paddle/fluid/operators/fused/fused_embedding_seq_pool_op.cc
浏览文件 @
359fec05
...
...
@@ -107,17 +107,6 @@ And the output will change the LoD information with input Ids.
}
};
class
FusedEmbeddingSeqPoolOpGradDescMaker
:
public
framework
::
DefaultGradOpDescMaker
<
true
>
{
using
::
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>::
DefaultGradOpDescMaker
;
protected:
virtual
std
::
string
GradOpType
()
const
{
return
"fused_embedding_seq_pool_grad"
;
}
};
class
FusedEmbeddingSeqPoolOpGrad
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
...
...
@@ -160,7 +149,7 @@ class FusedEmbeddingSeqPoolOpGradVarTypeInference
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
fused_embedding_seq_pool
,
ops
::
FusedEmbeddingSeqPoolOp
,
ops
::
FusedEmbeddingSeqPoolOpGradDescMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
,
ops
::
FusedEmbeddingSeqPoolOpMaker
);
REGISTER_OPERATOR
(
fused_embedding_seq_pool_grad
,
ops
::
FusedEmbeddingSeqPoolOpGrad
,
...
...
paddle/fluid/operators/lookup_table_op.cc
浏览文件 @
359fec05
...
...
@@ -119,15 +119,6 @@ or not. And the output only shares the LoD information with input Ids.
}
};
class
LookupTableOpGradDescMaker
:
public
framework
::
DefaultGradOpDescMaker
<
true
>
{
using
::
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>::
DefaultGradOpDescMaker
;
protected:
virtual
std
::
string
GradOpType
()
const
{
return
"lookup_table_grad"
;
}
};
class
LookupTableOpGrad
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
...
...
@@ -169,7 +160,8 @@ class LookupTableOpGradVarTypeInference : public framework::VarTypeInference {
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
lookup_table
,
ops
::
LookupTableOp
,
ops
::
LookupTableOpGradDescMaker
,
ops
::
LookupTableOpMaker
);
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
,
ops
::
LookupTableOpMaker
);
REGISTER_OPERATOR
(
lookup_table_grad
,
ops
::
LookupTableOpGrad
,
ops
::
LookupTableOpGradVarTypeInference
);
...
...
paddle/fluid/operators/nce_op.cc
浏览文件 @
359fec05
...
...
@@ -187,14 +187,6 @@ By default this operator uses a uniform distribution for sampling.
}
};
class
NCEOpGradDescMaker
:
public
framework
::
DefaultGradOpDescMaker
<
true
>
{
using
::
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>::
DefaultGradOpDescMaker
;
protected:
virtual
std
::
string
GradOpType
()
const
{
return
"nce_grad"
;
}
};
class
NCEOpGrad
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
...
...
@@ -259,7 +251,9 @@ class NCEOpGradVarTypeInference : public framework::VarTypeInference {
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
nce
,
ops
::
NCEOp
,
ops
::
NCEOpGradDescMaker
,
ops
::
NCEOpMaker
);
REGISTER_OPERATOR
(
nce
,
ops
::
NCEOp
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
,
ops
::
NCEOpMaker
);
REGISTER_OPERATOR
(
nce_grad
,
ops
::
NCEOpGrad
,
ops
::
NCEOpGradVarTypeInference
);
REGISTER_OP_CPU_KERNEL
(
nce
,
ops
::
NCEKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
NCEKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
359fec05
...
...
@@ -29,6 +29,7 @@ limitations under the License. */
#include "paddle/fluid/framework/lod_rank_table.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/lod_tensor_array.h"
#include "paddle/fluid/framework/op_info.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/parallel_executor.h"
#include "paddle/fluid/framework/prune.h"
...
...
@@ -156,6 +157,9 @@ PYBIND11_MODULE(core, m) {
return
paddle
::
operators
::
AppendPythonCallableObjectAndReturnId
(
py_obj
);
});
m
.
def
(
"_get_use_default_grad_op_desc_maker_ops"
,
[]
{
return
OpInfoMap
::
Instance
().
GetUseDefaultGradOpDescMakerOps
();
});
// NOTE(zjl): ctest would load environment variables at the beginning even
// though we have not `import paddle.fluid as fluid`. So we add this API
// to enable eager deletion mode in unittest.
...
...
paddle/scripts/paddle_build.sh
浏览文件 @
359fec05
...
...
@@ -425,6 +425,13 @@ function assert_api_not_changed() {
sed
-i
'/.*ComposeNotAligned.*/d'
new.spec
python
${
PADDLE_ROOT
}
/tools/diff_api.py
${
PADDLE_ROOT
}
/paddle/fluid/API.spec new.spec
# Currently, we only check in PR_CI python 2.7
if
[
"
$SYSTEM
"
!=
"Darwin"
]
;
then
if
[
"
$1
"
==
""
]
||
[
"
$1
"
==
"cp27-cp27m"
]
||
[
"
$1
"
==
"cp27-cp27mu"
]
;
then
python
${
PADDLE_ROOT
}
/tools/diff_use_default_grad_op_maker.py
${
PADDLE_ROOT
}
/paddle/fluid/op_use_default_grad_op_maker.spec
fi
fi
deactivate
}
...
...
@@ -434,9 +441,12 @@ function assert_api_spec_approvals() {
fi
API_FILES
=(
"paddle/fluid/API.spec"
"paddle/fluid/op_use_default_grad_op_maker.spec"
"python/paddle/fluid/parallel_executor.py"
"paddle/fluid/framework/operator.h"
"paddle/fluid/framework/tensor.h"
"paddle/fluid/framework/details/op_registry.h"
"paddle/fluid/framework/grad_op_desc_maker.h"
"paddle/fluid/framework/lod_tensor.h"
"paddle/fluid/framework/selected_rows.h"
"paddle/fluid/framework/op_desc.h"
...
...
tools/diff_use_default_grad_op_maker.py
0 → 100644
浏览文件 @
359fec05
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
''
import
paddle.fluid
as
fluid
import
sys
def
get_op_diff
(
filename
):
ops_created_by_py_func
=
set
(
fluid
.
core
.
_get_use_default_grad_op_desc_maker_ops
())
with
open
(
filename
,
'r'
)
as
f
:
ops_read_from_file
=
set
([
line
.
strip
()
for
line
in
f
.
readlines
()])
diff_ops
=
[]
for
op
in
ops_read_from_file
:
if
op
not
in
ops_created_by_py_func
:
diff_ops
.
append
(
op
)
else
:
ops_created_by_py_func
.
remove
(
op
)
err_msg
=
[]
diff_ops
=
list
(
diff_ops
)
if
len
(
diff_ops
)
>
0
:
err_msg
.
append
(
'Added grad op with DefaultGradOpDescMaker: '
+
str
(
diff_ops
))
ops_created_by_py_func
=
list
(
ops_created_by_py_func
)
if
len
(
ops_created_by_py_func
)
>
0
:
err_msg
.
append
(
'Remove grad op with DefaultGradOpDescMaker: '
+
str
(
ops_created_by_py_func
))
return
err_msg
if
len
(
sys
.
argv
)
!=
2
:
print
(
'Usage: python diff_use_default_grad_op_maker.py [filepath]'
)
sys
.
exit
(
1
)
file_path
=
str
(
sys
.
argv
[
1
])
err_msg
=
get_op_diff
(
file_path
)
if
len
(
err_msg
)
>
0
:
_
,
filename
=
os
.
path
.
split
(
file_path
)
print
(
'File `{}` is wrong compared to your PR revision!'
.
format
(
filename
))
print
(
'Please use `python generate_op_use_grad_op_desc_maker_spec.py [filepath]` to generate new `{}` file'
.
format
(
filename
))
print
(
'Error message is: '
+
'; '
.
join
(
err_msg
))
sys
.
exit
(
1
)
tools/generate_op_use_grad_op_desc_maker_spec.py
0 → 100644
浏览文件 @
359fec05
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
os
.
environ
[
'CUDA_VISIBLE_DEVICES'
]
=
''
import
paddle.fluid
as
fluid
import
sys
if
len
(
sys
.
argv
)
!=
2
:
print
(
'Usage: python generate_op_use_grad_op_desc_maker_spec.py [filepath]'
)
sys
.
exit
(
1
)
with
open
(
sys
.
argv
[
1
],
'w'
)
as
f
:
ops
=
fluid
.
core
.
_get_use_default_grad_op_desc_maker_ops
()
for
op
in
ops
:
f
.
write
(
op
+
'
\n
'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录