From 22f042bae41ba367540428554d30a5aa81b59490 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Tue, 6 Sep 2022 10:56:12 +0800 Subject: [PATCH] clear extra attrs of some op in opmaker (#45758) --- paddle/fluid/operators/rnn_op.cc | 3 -- paddle/fluid/operators/seed_op.cc | 17 -------- paddle/fluid/operators/shape_op.cc | 10 ----- paddle/fluid/operators/shuffle_channel_op.cc | 5 --- paddle/fluid/operators/slice_op.cc | 10 ----- paddle/fluid/operators/softmax_op.cc | 20 ---------- paddle/fluid/operators/squeeze_op.cc | 35 +++++++++++++++- paddle/phi/api/yaml/api_compat.yaml | 42 +++++++++++++++++--- 8 files changed, 70 insertions(+), 72 deletions(-) diff --git a/paddle/fluid/operators/rnn_op.cc b/paddle/fluid/operators/rnn_op.cc index aba720a99b..4a97afdfc4 100644 --- a/paddle/fluid/operators/rnn_op.cc +++ b/paddle/fluid/operators/rnn_op.cc @@ -103,9 +103,6 @@ class RNNOpMaker : public framework::OpProtoAndCheckerMaker { "mode", "(string) rnn types, including: LSTM, GRU, RNN_RELU, RNN_TANH."); AddAttr("seed", "seed to used if fix_seed is True").SetDefault(0); - AddAttr("is_test", "True if in test phase.") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( )DOC"); } diff --git a/paddle/fluid/operators/seed_op.cc b/paddle/fluid/operators/seed_op.cc index 527884ec9c..7de155b01c 100644 --- a/paddle/fluid/operators/seed_op.cc +++ b/paddle/fluid/operators/seed_op.cc @@ -39,23 +39,6 @@ class SeedOpMaker : public framework::OpProtoAndCheckerMaker { void Make() override { AddOutput("Out", "The output of seed op."); AddAttr("seed", "Dropout random seed.").SetDefault(0); - AddAttr("deterministic", - "(bool, default false) Whether to use deterministic " - "RandomSeedGenerator which " - "generate by `set_random_seed_generator`") - .SetDefault(false) - .AsExtra(); - AddAttr( - "rng_name", - "use deterministic RandomSeedGenerator which name is `rng_name`") - .SetDefault("") - .AsExtra(); - AddAttr("force_cpu", - "(bool, default false) Force fill output variable to cpu " - "memory. Otherwise, fill output variable to the running " - "device") - .SetDefault(false) - .AsExtra(); AddComment(R"DOC( Seed Operator. )DOC"); diff --git a/paddle/fluid/operators/shape_op.cc b/paddle/fluid/operators/shape_op.cc index cbd1015352..14f4b00b60 100644 --- a/paddle/fluid/operators/shape_op.cc +++ b/paddle/fluid/operators/shape_op.cc @@ -66,16 +66,6 @@ Shape Operator. Return the shape of the input. )DOC"); - 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", "int8"}) - .AsExtra(); } }; diff --git a/paddle/fluid/operators/shuffle_channel_op.cc b/paddle/fluid/operators/shuffle_channel_op.cc index 4a3668b114..9fc7c6488f 100644 --- a/paddle/fluid/operators/shuffle_channel_op.cc +++ b/paddle/fluid/operators/shuffle_channel_op.cc @@ -69,11 +69,6 @@ class ShuffleChannelOpMaker : public framework::OpProtoAndCheckerMaker { platform::errors::InvalidArgument( "group should be larger than 0.")); }); - AddAttr("use_mkldnn", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); - AddComment(R"DOC( Shuffle Channel operator This opearator shuffles the channels of input x. diff --git a/paddle/fluid/operators/slice_op.cc b/paddle/fluid/operators/slice_op.cc index f42ebbe039..9d9e5816db 100644 --- a/paddle/fluid/operators/slice_op.cc +++ b/paddle/fluid/operators/slice_op.cc @@ -260,16 +260,6 @@ class SliceOpMaker : public framework::OpProtoAndCheckerMaker { .SetDefault({}); AddAttr>("decrease_axis", "(list) decrease_axis") .SetDefault({}); - 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(); AddComment(R"DOC( Slice Operator. diff --git a/paddle/fluid/operators/softmax_op.cc b/paddle/fluid/operators/softmax_op.cc index d468e4a17f..3966b850c7 100644 --- a/paddle/fluid/operators/softmax_op.cc +++ b/paddle/fluid/operators/softmax_op.cc @@ -85,11 +85,6 @@ class SoftmaxOpMaker : public framework::OpProtoAndCheckerMaker { "The dimension index of Input(x) to perform softmax," "default -1 for last dimension") .SetDefault(-1); - AddAttr( - "use_cudnn", - "(bool, default false) Only used in cudnn kernel, need install cudnn") - .SetDefault(false) - .AsExtra(); AddAttr( "data_format", "(string, default NCHW) Only used in " @@ -97,21 +92,6 @@ class SoftmaxOpMaker : public framework::OpProtoAndCheckerMaker { "Defaults to \"NHWC\". Specify the data format of the output data, " "the input will be transformed automatically. ") .SetDefault("AnyLayout"); - 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( Softmax Operator. diff --git a/paddle/fluid/operators/squeeze_op.cc b/paddle/fluid/operators/squeeze_op.cc index 2d9e1e121c..561d1d31f1 100644 --- a/paddle/fluid/operators/squeeze_op.cc +++ b/paddle/fluid/operators/squeeze_op.cc @@ -296,15 +296,46 @@ class SqueezeDoubleGradOpMaker : public framework::SingleGradOpMaker { // squeeze_grad, in this way, the framework can reuse the memory of X // immediately the squeeze2_op is finished. // Considering compatibility issues, we could not fix squeeze2_op -class Squeeze2OpMaker : public SqueezeOpMaker { +class Squeeze2OpMaker : public framework::OpProtoAndCheckerMaker { public: void Make() override { - SqueezeOpMaker::Make(); + AddInput("X", "(Tensor). The input tensor of squeeze operator."); + AddOutput("Out", "(Tensor). The output tensor of squeeze operator."); AddOutput("XShape", "XShape is just used to store the shape and lod of X, which will " "be used in SqueezeGradOp.") .AsIntermediate() .AsExtra(); + AddAttr>("axes", + "(std::vector). List of integers," + " indicating the dimensions to squeeze.") + .SetDefault({}) + .SupportTensor(); + AddComment(R"DOC( + Squeeze2 Operator. + + Remove single-dimensional entries from the shape of a tensor. + Takes a parameter axes with a list of axes to squeeze. + If axes is not provided, all the single dimensions will be removed from the shape. + If an axis is selected with shape entry not equal to one, an error is raised. + + Examples: + Case 1: + Given + X.shape = (1, 3, 1, 5) + and + axes = [0] + we get: + Out.shape = (3, 1, 5) + + Case 2: + Given + X.shape = (1, 3, 1, 5) + and + axes = [] + we get: + Out.shape = (3, 5) + )DOC"); } }; diff --git a/paddle/phi/api/yaml/api_compat.yaml b/paddle/phi/api/yaml/api_compat.yaml index 473dc9a178..14d54df783 100644 --- a/paddle/phi/api/yaml/api_compat.yaml +++ b/paddle/phi/api/yaml/api_compat.yaml @@ -281,22 +281,54 @@ 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 : rnn + backward : rnn_grad + extra : + attrs : [bool is_test = false] + +- api : seed + extra : + attrs : [bool deterministic = false, str rng_name = "", bool force_cpu = false] + +- api : shape + extra : + attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32"] + +- api : shuffle_channel + backward : shuffle_channel_grad + extra : + attrs : [bool use_mkldnn = false] + +- api : slice + backward : slice_grad + extra : + attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32"] + +- api : softmax + backward : softmax_grad + extra : + attrs : [bool use_cudnn = false, bool use_mkldnn = false, str mkldnn_data_type = "float32", bool is_test = false] +- api : prelu + backward : prelu_grad + extra : + attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32", bool is_test = false] + - api : solve inputs : {x : X, y : Y} outputs : out : Out +- api : squeeze (squeeze2) + backward : squeeze_grad (squeeze2_grad) + extra : + attrs : [bool use_mkldnn = false, str mkldnn_data_type = "float32"] + - api : stack backward : stack_grad extra : -- GitLab