Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear extra attributes of some Op in OpMaker (Part2) #45684

Merged
merged 7 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions paddle/fluid/framework/op_desc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions paddle/fluid/framework/op_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ std::unique_ptr<OperatorBase> 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<OperatorBase>(
info.Creator()(type, inputs, outputs, standard_attrs));
Expand Down
4 changes: 0 additions & 4 deletions paddle/fluid/operators/data_norm_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,6 @@ class DataNormOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr<std::string>("data_layout", "").SetDefault("NCHW");
AddAttr<bool>("sync_stats", "(bool, default false) only used in multi-GPU")
.SetDefault(false);
AddAttr<bool>("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 "
Expand Down
9 changes: 0 additions & 9 deletions paddle/fluid/operators/dropout_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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<int>("seed", "Dropout random seed.").SetDefault(0).AsExtra();
AddAttr<std::string>(
"dropout_implementation",
"[\"downgrade_in_infer\"|\"upscale_in_train\"]"
Expand Down
18 changes: 1 addition & 17 deletions paddle/fluid/operators/gelu_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -100,21 +99,6 @@ class GeluOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr<bool>("approximate",
"(bool, default false) use approximation of gelu")
.SetDefault(false);
AddAttr<bool>("use_mkldnn",
"(bool, default false) Only used in mkldnn kernel")
.SetDefault(false)
.AsExtra();
AddAttr<std::string>(
"mkldnn_data_type",
"(string, default \"float32\"). Data type of mkldnn kernel")
.SetDefault("float32")
.InEnum({"float32", "int8", "bfloat16"})
.AsExtra();
AddAttr<bool>("use_cudnn",
"(bool, default false) Only used in cudnn kernel, need "
"install cudnn")
.SetDefault(false)
.AsExtra();
AddComment(R"DOC(
Gelu Activation Operator.

Expand Down
6 changes: 0 additions & 6 deletions paddle/fluid/operators/grid_sampler_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(
"use_cudnn",
"(bool, default true) Only used in cudnn kernel, need install cudnn")
.SetDefault(true)
.AsExtra();

AddAttr<bool>(
"align_corners",
"(bool, default true) If align_corners is true, it will project"
Expand Down
3 changes: 0 additions & 3 deletions paddle/fluid/operators/gru_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ class GRUOpMaker : public framework::OpProtoAndCheckerMaker {
"(bool, default: False) "
"whether to compute reversed GRU.")
.SetDefault(false);
AddAttr<bool>("is_test", "True if in test phase.")
.SetDefault(false)
.AsExtra();
AddAttr<bool>("origin_mode",
"bool"
"use origin mode in article https://arxiv.org/abs/1412.3555")
Expand Down
4 changes: 0 additions & 4 deletions paddle/fluid/operators/interpolate_v2_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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\"
Expand Down
16 changes: 0 additions & 16 deletions paddle/fluid/operators/layer_norm_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,6 @@ class LayerNormOpMaker : public framework::OpProtoAndCheckerMaker {
"greater than zero. But received [%d].",
begin_norm_axis));
});
AddAttr<bool>("use_mkldnn",
"(bool, default false) Only used in mkldnn kernel")
.SetDefault(false)
.AsExtra();
AddAttr<std::string>(
"mkldnn_data_type",
"(string, default \"float32\"). Data type of mkldnn kernel")
.SetDefault("float32")
.InEnum({"float32", "bfloat16"})
.AsExtra();
AddAttr<bool>("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
Expand Down
4 changes: 0 additions & 4 deletions paddle/fluid/operators/log_softmax_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("use_mkldnn",
"(bool, default false) Only used in mkldnn kernel")
.SetDefault(false)
.AsExtra();
AddComment(R"DOC(
LogSoftmax Operator.

Expand Down
10 changes: 0 additions & 10 deletions paddle/fluid/operators/lrn_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,13 @@ class LRNOpMaker : public framework::OpProtoAndCheckerMaker {
"beta is the power number.")
.SetDefault(0.75)
.GreaterThan(0.0);
AddAttr<bool>("use_mkldnn",
"(bool, default false) Only used in mkldnn kernel")
.SetDefault(false)
.AsExtra();
AddAttr<std::string>(
"data_format",
"(string, default NCHW) Only used in "
"An optional string from: \"NHWC\", \"NCHW\". "
"Defaults to \"NHWC\". Specify the data format of the output data, "
"the input will be transformed automatically. ")
.SetDefault("AnyLayout");
AddAttr<bool>("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.

Expand Down
4 changes: 0 additions & 4 deletions paddle/fluid/operators/pad2d_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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'.
Expand Down
4 changes: 0 additions & 4 deletions paddle/fluid/operators/pad3d_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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'.
Expand Down
5 changes: 0 additions & 5 deletions paddle/fluid/operators/partial_sum_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(
"use_mkldnn",
"(bool, default false) Indicates if MKL-DNN kernel will be used")
.SetDefault(false)
.AsExtra();
AddAttr<int>("start_index", "The start index of tensor wanted to be added.")
.SetDefault(0);
AddAttr<int>("length", "The length of tensor wanted to be added.")
Expand Down
15 changes: 0 additions & 15 deletions paddle/fluid/operators/prelu_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,6 @@ There are modes:
AddAttr<std::string>("data_format",
"Data format that specifies the layout of input")
.SetDefault("NCHW");
AddAttr<bool>("use_mkldnn",
"(bool, default false) Only used in mkldnn kernel")
.SetDefault(false)
.AsExtra();
AddAttr<std::string>(
"mkldnn_data_type",
"(string, default \"float32\"). Data type of mkldnn kernel")
.SetDefault("float32")
.InEnum({"float32", "bfloat16"})
.AsExtra();
AddAttr<bool>("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();
}
};

Expand Down
9 changes: 0 additions & 9 deletions paddle/fluid/operators/renorm_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ class RenormOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr<int>("axis",
"int,the dimension to slice over to get the sub-tensors");
AddAttr<float>("max_norm", "(float, the norm upper-bound");
AddAttr<bool>("use_cudnn",
"(bool, default false) Only used in cudnn kernel, need "
"install cudnn")
.SetDefault(false)
.AsExtra();
AddAttr<bool>("use_mkldnn",
"(bool, default false) Only used in mkldnn kernel")
.SetDefault(false)
.AsExtra();
AddComment(R"DOC(
Renorm Operator.

Expand Down
Loading