From 1a4378ba933a62ba8bae6c9fadfd881f52267445 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Fri, 2 Sep 2022 06:43:27 +0000 Subject: [PATCH 1/6] remove extra attr of opmaker --- paddle/fluid/operators/data_norm_op.cc | 4 - paddle/fluid/operators/dropout_op.cc | 9 -- paddle/fluid/operators/gelu_op.cc | 15 ---- paddle/fluid/operators/grid_sampler_op.cc | 6 -- paddle/fluid/operators/interpolate_v2_op.cc | 4 - paddle/fluid/operators/layer_norm_op.cc | 16 ---- paddle/fluid/operators/log_softmax_op.cc | 4 - paddle/fluid/operators/lrn_op.cc | 10 --- paddle/fluid/operators/pad2d_op.cc | 4 - paddle/fluid/operators/pad3d_op.cc | 4 - paddle/fluid/operators/partial_sum_op.cc | 5 -- paddle/fluid/operators/prelu_op.cc | 15 ---- paddle/fluid/operators/renorm_op.cc | 9 -- paddle/fluid/operators/scale_op.cc | 4 - paddle/phi/api/yaml/api_compat.yaml | 99 +++++++++++++++++++++ 15 files changed, 99 insertions(+), 109 deletions(-) diff --git a/paddle/fluid/operators/data_norm_op.cc b/paddle/fluid/operators/data_norm_op.cc index 6685e54e43b60..a4cfb82bf8aaa 100644 --- a/paddle/fluid/operators/data_norm_op.cc +++ b/paddle/fluid/operators/data_norm_op.cc @@ -251,10 +251,6 @@ class DataNormOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr("data_layout", "").SetDefault("NCHW"); AddAttr("sync_stats", "(bool, default false) only used in multi-GPU") .SetDefault(false); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); AddInput("X", "The input tensor"); AddInput("BatchSize", "BatchSize is a 1-dimensional tensor of size C " diff --git a/paddle/fluid/operators/dropout_op.cc b/paddle/fluid/operators/dropout_op.cc index 84784c3c6034c..43ae066b527fd 100644 --- a/paddle/fluid/operators/dropout_op.cc +++ b/paddle/fluid/operators/dropout_op.cc @@ -77,15 +77,6 @@ class DropoutOpMaker : public framework::OpProtoAndCheckerMaker { "(bool, default false) Set to true for inference only, false " "for training. Some layers may run faster when this is true.") .SetDefault(false); - AddAttr("fix_seed", - "A flag indicating whether to use a fixed seed to generate " - "random mask. NOTE: DO NOT set this flag to true in " - "training. Setting this flag to true is only useful in " - "unittest or for debug that always the same output units " - "will be dropped.") - .SetDefault(false) - .AsExtra(); - AddAttr("seed", "Dropout random seed.").SetDefault(0).AsExtra(); AddAttr( "dropout_implementation", "[\"downgrade_in_infer\"|\"upscale_in_train\"]" diff --git a/paddle/fluid/operators/gelu_op.cc b/paddle/fluid/operators/gelu_op.cc index 40d9752f0a9d0..cfb9aec929e41 100644 --- a/paddle/fluid/operators/gelu_op.cc +++ b/paddle/fluid/operators/gelu_op.cc @@ -100,21 +100,6 @@ class GeluOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr("approximate", "(bool, default false) use approximation of gelu") .SetDefault(false); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); - AddAttr( - "mkldnn_data_type", - "(string, default \"float32\"). Data type of mkldnn kernel") - .SetDefault("float32") - .InEnum({"float32", "int8", "bfloat16"}) - .AsExtra(); - AddAttr("use_cudnn", - "(bool, default false) Only used in cudnn kernel, need " - "install cudnn") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( Gelu Activation Operator. diff --git a/paddle/fluid/operators/grid_sampler_op.cc b/paddle/fluid/operators/grid_sampler_op.cc index 5bfdfcdf7e4d3..97ec937911526 100644 --- a/paddle/fluid/operators/grid_sampler_op.cc +++ b/paddle/fluid/operators/grid_sampler_op.cc @@ -67,12 +67,6 @@ class GridSampleOpMaker : public framework::OpProtoAndCheckerMaker { AddOutput("Output", "(Tensor) Output tensor with shape [N, C, H, W] or shape [N,C, " "D, H ,W]"); - AddAttr( - "use_cudnn", - "(bool, default true) Only used in cudnn kernel, need install cudnn") - .SetDefault(true) - .AsExtra(); - AddAttr( "align_corners", "(bool, default true) If align_corners is true, it will project" diff --git a/paddle/fluid/operators/interpolate_v2_op.cc b/paddle/fluid/operators/interpolate_v2_op.cc index b902c4b38feda..07ecae637a7bf 100644 --- a/paddle/fluid/operators/interpolate_v2_op.cc +++ b/paddle/fluid/operators/interpolate_v2_op.cc @@ -550,10 +550,6 @@ class InterpolateV2OpMaker : public framework::OpProtoAndCheckerMaker { "can be \'0\' for src_idx = scale*(dst_indx+0.5)-0.5 , " "can be \'1\' for src_idx = scale*dst_index .") .SetDefault(1); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( This operator samples input X to given output shape by using specified interpolation method, the interpolation methods can be \"nearest\" diff --git a/paddle/fluid/operators/layer_norm_op.cc b/paddle/fluid/operators/layer_norm_op.cc index 9e7a078b63fbf..0346e9b82868a 100644 --- a/paddle/fluid/operators/layer_norm_op.cc +++ b/paddle/fluid/operators/layer_norm_op.cc @@ -171,22 +171,6 @@ class LayerNormOpMaker : public framework::OpProtoAndCheckerMaker { "greater than zero. But received [%d].", begin_norm_axis)); }); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); - AddAttr( - "mkldnn_data_type", - "(string, default \"float32\"). Data type of mkldnn kernel") - .SetDefault("float32") - .InEnum({"float32", "bfloat16"}) - .AsExtra(); - AddAttr("is_test", - "(bool, default false) Set to true for inference only, false " - "for training. Some layers may run faster when this is true.") - .SetDefault(false) - .AsExtra(); - AddComment(R"DOC( Assume feature vectors exist on dimensions :attr:`begin_norm_axis ... rank(input)` and calculate the moment statistics diff --git a/paddle/fluid/operators/log_softmax_op.cc b/paddle/fluid/operators/log_softmax_op.cc index 1878a56dbd01b..a4286aea07842 100644 --- a/paddle/fluid/operators/log_softmax_op.cc +++ b/paddle/fluid/operators/log_softmax_op.cc @@ -57,10 +57,6 @@ class LogSoftmaxOpMaker : public framework::OpProtoAndCheckerMaker { "The dimension index of Input(x) to perform log_softmax," "default -1 for last dimension") .SetDefault(-1); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( LogSoftmax Operator. diff --git a/paddle/fluid/operators/lrn_op.cc b/paddle/fluid/operators/lrn_op.cc index 73fe170f6d5e8..bd495664de601 100644 --- a/paddle/fluid/operators/lrn_op.cc +++ b/paddle/fluid/operators/lrn_op.cc @@ -302,10 +302,6 @@ class LRNOpMaker : public framework::OpProtoAndCheckerMaker { "beta is the power number.") .SetDefault(0.75) .GreaterThan(0.0); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); AddAttr( "data_format", "(string, default NCHW) Only used in " @@ -313,12 +309,6 @@ class LRNOpMaker : public framework::OpProtoAndCheckerMaker { "Defaults to \"NHWC\". Specify the data format of the output data, " "the input will be transformed automatically. ") .SetDefault("AnyLayout"); - AddAttr("is_test", - "(bool, default false) Set to true for inference only, false " - "for training. Some layers may run faster when this is true.") - .SetDefault(false) - .AsExtra(); - AddComment(R"DOC( Local Response Normalization Operator. diff --git a/paddle/fluid/operators/pad2d_op.cc b/paddle/fluid/operators/pad2d_op.cc index 0af4261c279bf..0f2873d73e768 100644 --- a/paddle/fluid/operators/pad2d_op.cc +++ b/paddle/fluid/operators/pad2d_op.cc @@ -773,10 +773,6 @@ class Pad2dOpMaker : public framework::OpProtoAndCheckerMaker { "An optional string from: \"NHWC\", \"NCHW\". " "Defaults to \"NHWC\". Specify the data format of the input data.") .SetDefault("NCHW"); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( Pad2d Operator. Pad 2-d images according to 'paddings' and 'mode'. diff --git a/paddle/fluid/operators/pad3d_op.cc b/paddle/fluid/operators/pad3d_op.cc index e4b32b3d7a76e..301c21b2fcdcf 100644 --- a/paddle/fluid/operators/pad3d_op.cc +++ b/paddle/fluid/operators/pad3d_op.cc @@ -111,10 +111,6 @@ class Pad3dOpMaker : public framework::OpProtoAndCheckerMaker { "An optional string from: \"NDHWC\", \"NCDHW\". " "Defaults to \"NDHWC\". Specify the data format of the input data.") .SetDefault("NCDHW"); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( Pad3d Operator. Pad 3-d images according to 'paddings' and 'mode'. diff --git a/paddle/fluid/operators/partial_sum_op.cc b/paddle/fluid/operators/partial_sum_op.cc index 4d4c1e54cff27..148eb8806b5d8 100644 --- a/paddle/fluid/operators/partial_sum_op.cc +++ b/paddle/fluid/operators/partial_sum_op.cc @@ -155,11 +155,6 @@ class PartialSumOpMaker : public framework::OpProtoAndCheckerMaker { void Make() override { AddInput("X", "Input tensors of partial_sum operator.").AsDuplicable(); AddOutput("Out", "Output tensor of partial_sum operator."); - AddAttr( - "use_mkldnn", - "(bool, default false) Indicates if MKL-DNN kernel will be used") - .SetDefault(false) - .AsExtra(); AddAttr("start_index", "The start index of tensor wanted to be added.") .SetDefault(0); AddAttr("length", "The length of tensor wanted to be added.") diff --git a/paddle/fluid/operators/prelu_op.cc b/paddle/fluid/operators/prelu_op.cc index ebcce12372554..df58a2abe87b5 100644 --- a/paddle/fluid/operators/prelu_op.cc +++ b/paddle/fluid/operators/prelu_op.cc @@ -104,21 +104,6 @@ There are modes: AddAttr("data_format", "Data format that specifies the layout of input") .SetDefault("NCHW"); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); - AddAttr( - "mkldnn_data_type", - "(string, default \"float32\"). Data type of mkldnn kernel") - .SetDefault("float32") - .InEnum({"float32", "bfloat16"}) - .AsExtra(); - AddAttr("is_test", - "(bool, default false) Set to true for inference only, false " - "for training. Some layers may run faster when this is true.") - .SetDefault(false) - .AsExtra(); } }; diff --git a/paddle/fluid/operators/renorm_op.cc b/paddle/fluid/operators/renorm_op.cc index 9ed911f8f69a0..1dc333460b6ed 100644 --- a/paddle/fluid/operators/renorm_op.cc +++ b/paddle/fluid/operators/renorm_op.cc @@ -39,15 +39,6 @@ class RenormOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr("axis", "int,the dimension to slice over to get the sub-tensors"); AddAttr("max_norm", "(float, the norm upper-bound"); - AddAttr("use_cudnn", - "(bool, default false) Only used in cudnn kernel, need " - "install cudnn") - .SetDefault(false) - .AsExtra(); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( Renorm Operator. diff --git a/paddle/fluid/operators/scale_op.cc b/paddle/fluid/operators/scale_op.cc index 3c2b5363d81ce..5f867cfb56aaf 100644 --- a/paddle/fluid/operators/scale_op.cc +++ b/paddle/fluid/operators/scale_op.cc @@ -75,10 +75,6 @@ if bias_after_scale=True: "Apply bias addition after or before scaling. It is useful for " "numeric stability in some circumstances.") .SetDefault(true); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); } }; diff --git a/paddle/phi/api/yaml/api_compat.yaml b/paddle/phi/api/yaml/api_compat.yaml index e2d714e362028..578e66c3a9d26 100644 --- a/paddle/phi/api/yaml/api_compat.yaml +++ b/paddle/phi/api/yaml/api_compat.yaml @@ -15,6 +15,16 @@ outputs : out : Out +- api : bicubic_interp (bicubic_interp_v2) + backward : bicubic_interp_grad (bicubic_interp_v2_grad) + extra : + attrs : [bool use_mkldnn = false] + +- api : bilinear_interp (bilinear_interp_v2) + backward : bilinear_interp_grad (bilinear_interp_v2_grad) + extra : + attrs : [bool use_mkldnn = false] + - api : cholesky inputs : x : X @@ -54,6 +64,11 @@ outputs : out : Out +- api : data_norm + backward : data_norm_grad + extra : + attrs : [bool use_mkldnn = false] + - api : depthwise_conv2d backward : depthwise_conv2d_grad extra : @@ -96,6 +111,11 @@ outputs : out : Out +- api : dropout + backward : dropout_grad + extra : + attrs : [bool fix_seed = false, int seed = 0] + - api : erf inputs : x : X @@ -108,36 +128,115 @@ outputs : out : Out +- api : gelu + backward : gelu_grad + extra : + attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32", bool use_cudnn = false] + +- api : grid_sampler + backward : grid_sampler_grad + extra : + attrs : [bool use_cudnn = true] + +- api : gru + backward : gru_grad + extra : + attrs : [bool is_test = false] + +- api : layer_norm + backward : layer_norm_grad + extra : + attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32", bool is_test = false] + - api : lgamma inputs : x : X outputs : out : Out +- api : linear_interp (linear_interp_v2) + backward : linear_interp_grad (linear_interp_v2_grad) + extra : + attrs : [bool use_mkldnn = false] + +- api : log_softmax + backward : log_softmax_grad + extra : + attrs : [bool use_mkldnn = false] + +- api : lrn + backward : lrn_grad + extra : + attrs : [bool use_mkldnn = false, bool is_test = false] + - api : mv inputs : {x : X, vec : Vec} outputs : out : Out +- api : nearest_interp (nearest_interp_v2) + backward : nearest_interp_grad (nearest_interp_v2_grad) + extra : + attrs : [bool use_mkldnn = false] + +- api : pad2d + backward : pad2d_grad + extra : + attrs : [bool use_mkldnn = false] + +- api : pad3d + backward : pad3d_grad + extra : + attrs : [bool use_mkldnn = false] + +- api : partial_sum + backward : partial_sum_grad + extra : + attrs : [bool use_mkldnn = false] + - api : poisson inputs : x : X outputs : out : Out +- api : prelu + backward : prelu_grad + extra : + attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32", bool is_test = false] + +- api : renorm + backward : renorm_grad + extra : + attrs : [bool use_mkldnn = false, bool use_cudnn = false] + +- api : scale + extra : + attrs : [bool use_mkldnn = false] + - api : solve inputs : {x : X, y : Y} outputs : out : Out +- api : stack + backward : stack_grad + extra : + attrs : [bool use_mkldnn = false] + - api : trace inputs : x : Input outputs : out : Out +- api : trilinear_interp (trilinear_interp_v2) + backward : trilinear_interp_grad (trilinear_interp_v2_grad) + extra : + attrs : [bool use_mkldnn = false] + - api : trunc inputs : x : X From 2f856d33adec623f75e5868159066c19d3dc5a24 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Fri, 2 Sep 2022 07:17:30 +0000 Subject: [PATCH 2/6] remove extra attr of gru --- paddle/fluid/operators/gru_op.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/paddle/fluid/operators/gru_op.cc b/paddle/fluid/operators/gru_op.cc index f5cfd7a162c8d..1040f2c2ea066 100644 --- a/paddle/fluid/operators/gru_op.cc +++ b/paddle/fluid/operators/gru_op.cc @@ -180,9 +180,6 @@ class GRUOpMaker : public framework::OpProtoAndCheckerMaker { "(bool, default: False) " "whether to compute reversed GRU.") .SetDefault(false); - AddAttr("is_test", "True if in test phase.") - .SetDefault(false) - .AsExtra(); AddAttr("origin_mode", "bool" "use origin mode in article https://arxiv.org/abs/1412.3555") From c5e6433f65bb003b52342b072d4e7d7480da8415 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Fri, 2 Sep 2022 09:54:16 +0000 Subject: [PATCH 3/6] revert scale --- paddle/fluid/operators/scale_op.cc | 4 ++++ paddle/phi/api/yaml/api_compat.yaml | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/scale_op.cc b/paddle/fluid/operators/scale_op.cc index 5f867cfb56aaf..3c2b5363d81ce 100644 --- a/paddle/fluid/operators/scale_op.cc +++ b/paddle/fluid/operators/scale_op.cc @@ -75,6 +75,10 @@ if bias_after_scale=True: "Apply bias addition after or before scaling. It is useful for " "numeric stability in some circumstances.") .SetDefault(true); + AddAttr("use_mkldnn", + "(bool, default false) Only used in mkldnn kernel") + .SetDefault(false) + .AsExtra(); } }; diff --git a/paddle/phi/api/yaml/api_compat.yaml b/paddle/phi/api/yaml/api_compat.yaml index 9febe7c6fe180..473dc9a17844c 100644 --- a/paddle/phi/api/yaml/api_compat.yaml +++ b/paddle/phi/api/yaml/api_compat.yaml @@ -174,6 +174,11 @@ extra : attrs : [bool fix_seed = false, int seed = 0] +- api : dropout_nd + backward : dropout_nd_grad + extra : + attrs : [bool fix_seed = false, int seed = 0] + - api : erf inputs : x : X @@ -286,10 +291,6 @@ extra : attrs : [bool use_mkldnn = false, bool use_cudnn = false] -- api : scale - extra : - attrs : [bool use_mkldnn = false] - - api : solve inputs : {x : X, y : Y} From 5e3db9f1fbe3f56f71dee6daef00b27424d83e15 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Fri, 2 Sep 2022 13:02:19 +0000 Subject: [PATCH 4/6] fix bug of create_op --- paddle/fluid/framework/op_registry.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/framework/op_registry.cc b/paddle/fluid/framework/op_registry.cc index a60563620ad65..f84d814c84a04 100644 --- a/paddle/fluid/framework/op_registry.cc +++ b/paddle/fluid/framework/op_registry.cc @@ -38,8 +38,17 @@ std::unique_ptr OpRegistry::CreateOp( } } auto& info = OpInfoMap::Instance().Get(type); - if (attr_check && info.Checker() != nullptr) { - info.Checker()->Check(&standard_attrs); + if (attr_check) { + if (info.Checker() != nullptr) { + info.Checker()->Check(&standard_attrs); + } + const auto& extra_attr_checkers = + operators::ExtraInfoUtils::Instance().GetExtraAttrsChecker(type); + if (!extra_attr_checkers.empty()) { + for (const auto& checker : extra_attr_checkers) { + checker(&runtime_attrs, false); + } + } } auto op_base = std::unique_ptr( info.Creator()(type, inputs, outputs, standard_attrs)); From dea246182cac527ff208e541eaf93627dff173a9 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Sun, 4 Sep 2022 17:33:34 +0000 Subject: [PATCH 5/6] add extra attr checker in infer_shape --- paddle/fluid/framework/op_desc.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/paddle/fluid/framework/op_desc.cc b/paddle/fluid/framework/op_desc.cc index 22061d7cb2a14..749630b009f7d 100644 --- a/paddle/fluid/framework/op_desc.cc +++ b/paddle/fluid/framework/op_desc.cc @@ -1018,6 +1018,13 @@ void OpDesc::CheckAttrs() { } VLOG(10) << "begin to check attribute of " << Type(); checker->Check(&attrs_); + const auto &extra_attr_checkers = + operators::ExtraInfoUtils::Instance().GetExtraAttrsChecker(Type()); + if (!extra_attr_checkers.empty()) { + for (const auto &extra_checker : extra_attr_checkers) { + extra_checker(&runtime_attrs_, false); + } + } } void OpDesc::InferShape(const BlockDesc &block) { From 88dc0a76960c573352400926dac7ad2921ac92cd Mon Sep 17 00:00:00 2001 From: zyfncg Date: Mon, 5 Sep 2022 02:57:29 +0000 Subject: [PATCH 6/6] fix gelu --- paddle/fluid/operators/gelu_op.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/paddle/fluid/operators/gelu_op.cc b/paddle/fluid/operators/gelu_op.cc index cfb9aec929e41..add87fdd3c112 100644 --- a/paddle/fluid/operators/gelu_op.cc +++ b/paddle/fluid/operators/gelu_op.cc @@ -39,9 +39,8 @@ class GeluOp : public framework::OperatorWithKernel { framework::DataLayout layout = framework::DataLayout::kAnyLayout; auto data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); #ifdef PADDLE_WITH_MKLDNN - auto it = this->Attrs().find("use_mkldnn"); if (library == framework::LibraryType::kPlain && - it != this->Attrs().end() && this->CanMKLDNNBeUsed(ctx, data_type)) { + this->CanMKLDNNBeUsed(ctx, data_type)) { library = framework::LibraryType::kMKLDNN; layout = framework::DataLayout::kMKLDNN; }