Skip to content

Commit

Permalink
Clear extra attrs of scale in OpMaker (#45984)
Browse files Browse the repository at this point in the history
* clear extra attr of scale in opmaker

* fix sum bug

* fix merge conflict

* fix minus
  • Loading branch information
zyfncg authored Sep 16, 2022
1 parent 5c3e858 commit 0a904f8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
files: (?!.*third_party)^.*$ | (?!.*book)^.*$
- id: end-of-file-fixer
- id: sort-simple-yaml
files: (api|backward|api_[a-z_]+)\.yaml$
files: (op|backward|op_[a-z_]+)\.yaml$
- id: trailing-whitespace
files: (.*\.(py|bzl|md|rst|c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps|cmake)|BUILD|.*\.BUILD|WORKSPACE|CMakeLists.txt)$
- repo: local
Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/operators/minus_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class MinusGradMaker : public imperative::GradOpBaseMakerBase {
op.SetInput("X", this->OutputGrad("Out"));
op.SetOutput("Out", x_g);
op.SetAttr("scale", 1.0f);
op.SetDefaultAttrsMap(DefaultAttrsMap());
}

if (!y_g.empty()) {
Expand All @@ -138,6 +139,7 @@ class MinusGradMaker : public imperative::GradOpBaseMakerBase {
op.SetInput("X", this->OutputGrad("Out"));
op.SetOutput("Out", y_g);
op.SetAttr("scale", -1.0f);
op.SetDefaultAttrsMap(DefaultAttrsMap());
}

return node;
Expand Down
9 changes: 0 additions & 9 deletions paddle/fluid/operators/scale_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("use_mkldnn",
"(bool, default false) Only used in mkldnn kernel")
.SetDefault(false)
.AsExtra();
}
};

Expand Down Expand Up @@ -108,11 +104,6 @@ class ScaleGradMaker : public framework::SingleGradOpMaker<T> {
VLOG(6) << "Finish Set Attr bias";
grad_op->SetAttr("bias_after_scale", true);
VLOG(6) << "Finish Set Attr bias_after_scale";
if (grad_op->HasAttr("use_mkldnn")) {
VLOG(6) << "Finish Check Attr use_mkldnn";
grad_op->SetAttr("use_mkldnn", this->GetAttr("use_mkldnn"));
VLOG(6) << "Finish Set Attr use_mkldnn";
}
VLOG(6) << "Finish Apply";
}
};
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/operators/sum_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class SumGradOpBaseMaker : public imperative::GradOpBaseMakerBase {
op.SetInput("X", og);
op.SetOutput("Out", InputGradsType{x_grad});
op.SetAttr("scale", 1.0f);
op.SetDefaultAttrsMap(DefaultAttrsMap());
}
return node;
} else {
Expand Down
54 changes: 29 additions & 25 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
extra :
attrs : [bool use_cudnn = false, bool use_mkldnn = false]

- op : acosh
backward : acosh_grad
extra :
attrs : [bool use_mkldnn = false, bool use_cudnn = false]

- op : add (elementwise_add)
backward : add_grad (elementwise_add_grad)
extra :
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]

- op : acosh
backward : acosh_grad
extra :
attrs : [bool use_mkldnn = false, bool use_cudnn = false]

- op : addmm
backward : addmm_grad
extra :
Expand Down Expand Up @@ -266,6 +266,11 @@
inputs: {x: X}
outputs: {out: Out}

- op : floor
backward : floor_grad
extra :
attrs : [bool use_mkldnn = false, bool use_cudnn = false]

- op : floor_divide (elementwise_floordiv)
extra :
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
Expand All @@ -283,11 +288,6 @@
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]

- op : floor
backward : floor_grad
extra :
attrs : [bool use_mkldnn = false, bool use_cudnn = false]

- op : frobenius_norm
backward : frobenius_norm_grad
extra :
Expand All @@ -313,17 +313,17 @@
extra :
attrs : [bool is_test = false]

- op : hard_swish
backward : hard_swish_grad
extra :
attrs : [bool use_mkldnn = false]

- op : heaviside (elementwise_heaviside)
backward : heaviside_grad (elementwise_heaviside_grad)
extra :
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]

- op : hard_swish
backward : hard_swish_grad
extra :
attrs : [bool use_mkldnn = false]

- op : inplace_abn
backward : inplace_abn_grad
extra :
Expand Down Expand Up @@ -404,17 +404,17 @@
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]

- op : mish
backward : mish_grad
extra :
attrs : [bool use_mkldnn = false]

- op : multiply (elementwise_mul)
backward : multiply_grad (elementwise_mul_grad)
extra :
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]

- op : mish
backward : mish_grad
extra :
attrs : [bool use_mkldnn = false]

- op : mv
inputs :
{x : X, vec : Vec}
Expand Down Expand Up @@ -500,11 +500,6 @@
extra :
attrs : [bool use_mkldnn = false]

- op : remainder (elementwise_mod)
extra :
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]

- op : relu
backward : relu_grad
extra :
Expand All @@ -515,6 +510,11 @@
extra :
attrs : [bool use_mkldnn = false]

- op : remainder (elementwise_mod)
extra :
attrs : [bool use_mkldnn = false, str x_data_format = "", str y_data_format = "", str mkldnn_data_type = "float32",
bool use_quantizer = false, float Scale_x = 1.0f, float Scale_y = 1.0f, float Scale_out = 1.0f]

- op : renorm
backward : renorm_grad
extra :
Expand All @@ -535,6 +535,10 @@
extra :
attrs : [bool use_mkldnn = false, bool use_cudnn = false]

- op : scale
extra :
attrs : [bool use_mkldnn = false]

- op : seed
extra :
attrs : [bool deterministic = false, str rng_name = "", bool force_cpu = false]
Expand Down

0 comments on commit 0a904f8

Please sign in to comment.