From 05643dc3c79b53156087e7ab726e3db7ef6692ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=98=8E=E5=86=AC?= <78149749+winter-wang@users.noreply.github.com> Date: Thu, 8 Jul 2021 14:17:02 +0800 Subject: [PATCH] [pass_enhance]add global extra attributes for op def, test=develop (#34009) --- .../framework/ir/op_compat_sensible_pass.cc | 12 +++- .../operators/compat/affine_channel.pbtxt | 22 -------- .../fluid/operators/compat/batch_norm.pbtxt | 40 ++----------- paddle/fluid/operators/compat/concat.pbtxt | 34 ----------- paddle/fluid/operators/compat/conv2d.pbtxt | 56 +++---------------- .../operators/compat/conv2d_transpose.pbtxt | 36 ------------ paddle/fluid/operators/compat/conv3d.pbtxt | 26 +-------- paddle/fluid/operators/compat/cvm.pbtxt | 22 -------- .../operators/compat/depthwise_conv2d.pbtxt | 48 ---------------- .../operators/compat/elementwise_add.pbtxt | 37 ------------ .../operators/compat/elementwise_div.pbtxt | 32 ----------- .../operators/compat/elementwise_mul.pbtxt | 32 ----------- .../operators/compat/elementwise_pow.pbtxt | 32 ----------- .../operators/compat/elementwise_sub.pbtxt | 32 ----------- ...fake_channel_wise_dequantize_max_abs.pbtxt | 27 --------- .../fake_channel_wise_quantize_abs_max.pbtxt | 26 --------- paddle/fluid/operators/compat/relu.pbtxt | 42 +------------- 17 files changed, 31 insertions(+), 525 deletions(-) diff --git a/paddle/fluid/framework/ir/op_compat_sensible_pass.cc b/paddle/fluid/framework/ir/op_compat_sensible_pass.cc index c0f17af3160..1574bb739dd 100644 --- a/paddle/fluid/framework/ir/op_compat_sensible_pass.cc +++ b/paddle/fluid/framework/ir/op_compat_sensible_pass.cc @@ -19,6 +19,15 @@ limitations under the License. */ #include "paddle/fluid/framework/op_def_api.h" #include "paddle/fluid/framework/op_info.h" +namespace { +std::unordered_set global_extra_attrs = { + "op_role", "op_role_var", "op_namescope", + "op_callstack", "op_device", "@ENABLE_CACHE_RUNTIME_CONTEXT@", + "is_test", "use_mkldnn", "mkldnn_data_type", + "use_quantizer", "mkldnn_data_type", "use_cudnn", + "name"}; +} + namespace paddle { namespace framework { namespace ir { @@ -171,7 +180,8 @@ bool OpCompat::Judge(const OpDesc& op_desc) { for (auto& attr_map : op_desc.GetAttrMap()) { if (attr_compats_.find(attr_map.first) == attr_compats_.end()) { - if (extra_attrs_.find(attr_map.first) != extra_attrs_.end()) { + if (global_extra_attrs.find(attr_map.first) != global_extra_attrs.end() || + extra_attrs_.find(attr_map.first) != extra_attrs_.end()) { continue; } if (!AttrCompat(attr_map.first, this).IsLeftDefault()(op_desc)) { diff --git a/paddle/fluid/operators/compat/affine_channel.pbtxt b/paddle/fluid/operators/compat/affine_channel.pbtxt index 444fde59a96..83a55ab3a7d 100644 --- a/paddle/fluid/operators/compat/affine_channel.pbtxt +++ b/paddle/fluid/operators/compat/affine_channel.pbtxt @@ -17,25 +17,3 @@ def { name: "Out" } } -extra { - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } -} diff --git a/paddle/fluid/operators/compat/batch_norm.pbtxt b/paddle/fluid/operators/compat/batch_norm.pbtxt index 92b5647a507..4bfd0842132 100644 --- a/paddle/fluid/operators/compat/batch_norm.pbtxt +++ b/paddle/fluid/operators/compat/batch_norm.pbtxt @@ -15,6 +15,9 @@ def { inputs { name: "Variance" } + inputs { + name: "MomentumTensor" + } outputs { name: "Y" } @@ -39,29 +42,18 @@ def { } } extra { - inputs { - name: "MomentumTensor" - } - attrs { - name: "@ENABLE_CACHE_RUNTIME_CONTEXT@" - type: BOOLEAN - } attrs { - name: "is_test" - type: BOOLEAN + name: "momentum" + type: FLOAT } attrs { - name: "momentum" + name: "Y0_threshold" type: FLOAT } attrs { name: "data_layout" type: STRING } - attrs { - name: "use_mkldnn" - type: BOOLEAN - } attrs { name: "fuse_with_relu" type: BOOLEAN @@ -74,25 +66,5 @@ extra { name: "trainable_statistics" type: BOOLEAN } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } } diff --git a/paddle/fluid/operators/compat/concat.pbtxt b/paddle/fluid/operators/compat/concat.pbtxt index 54c8e089829..24e62fc30a9 100644 --- a/paddle/fluid/operators/compat/concat.pbtxt +++ b/paddle/fluid/operators/compat/concat.pbtxt @@ -14,37 +14,3 @@ def { type: INT } } -extra { - attrs { - name: "use_mkldnn" - type: BOOLEAN - } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } -} diff --git a/paddle/fluid/operators/compat/conv2d.pbtxt b/paddle/fluid/operators/compat/conv2d.pbtxt index 9e4c8b796a8..ca07d4a36ff 100644 --- a/paddle/fluid/operators/compat/conv2d.pbtxt +++ b/paddle/fluid/operators/compat/conv2d.pbtxt @@ -45,6 +45,14 @@ extra { name: "Input_scale" type: FLOAT } + attrs { + name: "Input0_threshold" + type: FLOAT + } + attrs { + name: "weight_scale" + type: FLOAT + } attrs { name: "quantization_type" type: STRING @@ -57,42 +65,14 @@ extra { name: "out_threshold" type: FLOAT } - attrs { - name: "@ENABLE_CACHE_RUNTIME_CONTEXT@" - type: BOOLEAN - } attrs { name: "skip_quant" type: BOOLEAN } - attrs { - name: "is_test" - type: BOOLEAN - } - attrs { - name: "name" - type: STRING - } - attrs { - name: "use_cudnn" - type: BOOLEAN - } attrs { name: "fuse_relu_before_depthwise_conv" type: BOOLEAN } - attrs { - name: "use_mkldnn" - type: BOOLEAN - } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "fuse_relu" type: BOOLEAN @@ -153,25 +133,5 @@ extra { name: "exhaustive_search" type: BOOLEAN } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } } diff --git a/paddle/fluid/operators/compat/conv2d_transpose.pbtxt b/paddle/fluid/operators/compat/conv2d_transpose.pbtxt index 474043718e4..06549079340 100644 --- a/paddle/fluid/operators/compat/conv2d_transpose.pbtxt +++ b/paddle/fluid/operators/compat/conv2d_transpose.pbtxt @@ -46,26 +46,10 @@ def { } } extra { - attrs { - name: "is_test" - type: BOOLEAN - } - attrs { - name: "use_cudnn" - type: BOOLEAN - } - attrs { - name: "use_mkldnn" - type: BOOLEAN - } attrs { name: "force_fp32_output" type: BOOLEAN } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "fuse_relu" type: BOOLEAN @@ -86,25 +70,5 @@ extra { name: "workspace_size_MB" type: INT } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } } diff --git a/paddle/fluid/operators/compat/conv3d.pbtxt b/paddle/fluid/operators/compat/conv3d.pbtxt index 51d4c0d8e3b..ec88172faab 100644 --- a/paddle/fluid/operators/compat/conv3d.pbtxt +++ b/paddle/fluid/operators/compat/conv3d.pbtxt @@ -6,6 +6,9 @@ def { inputs { name: "Filter" } + inputs { + name: "ResidualData" + } outputs { name: "Output" } @@ -35,33 +38,10 @@ def { } } extra { - inputs { - name: "ResidualData" - } - attrs { - name: "is_test" - type: BOOLEAN - } - attrs { - name: "use_cudnn" - type: BOOLEAN - } attrs { name: "fuse_relu_before_depthwise_conv" type: BOOLEAN } - attrs { - name: "use_mkldnn" - type: BOOLEAN - } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "fuse_relu" type: BOOLEAN diff --git a/paddle/fluid/operators/compat/cvm.pbtxt b/paddle/fluid/operators/compat/cvm.pbtxt index ccbeabc1f15..f94e6d276c3 100644 --- a/paddle/fluid/operators/compat/cvm.pbtxt +++ b/paddle/fluid/operators/compat/cvm.pbtxt @@ -14,26 +14,4 @@ def { type: BOOLEAN } } -extra { - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } -} diff --git a/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt b/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt index 901ed164608..ded14398615 100644 --- a/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt +++ b/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt @@ -57,42 +57,14 @@ extra { name: "out_threshold" type: FLOAT } - attrs { - name: "@ENABLE_CACHE_RUNTIME_CONTEXT@" - type: BOOLEAN - } attrs { name: "skip_quant" type: BOOLEAN } - attrs { - name: "is_test" - type: BOOLEAN - } - attrs { - name: "name" - type: STRING - } - attrs { - name: "use_cudnn" - type: BOOLEAN - } attrs { name: "fuse_relu_before_depthwise_conv" type: BOOLEAN } - attrs { - name: "use_mkldnn" - type: BOOLEAN - } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "fuse_relu" type: BOOLEAN @@ -153,25 +125,5 @@ extra { name: "exhaustive_search" type: BOOLEAN } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } } diff --git a/paddle/fluid/operators/compat/elementwise_add.pbtxt b/paddle/fluid/operators/compat/elementwise_add.pbtxt index 25da11905d4..081c0b6cd6e 100644 --- a/paddle/fluid/operators/compat/elementwise_add.pbtxt +++ b/paddle/fluid/operators/compat/elementwise_add.pbtxt @@ -15,10 +15,6 @@ def { } } extra { - attrs { - name: "@ENABLE_CACHE_RUNTIME_CONTEXT@" - type: BOOLEAN - } attrs { name: "out_threshold" type: FLOAT @@ -37,19 +33,6 @@ extra { type: STRING # no longer to use } - attrs { - name: "use_quantizer" - type: BOOLEAN - # no longer to use, Use 'mkldnn_data_type' instead. - } - attrs { - name: "use_mkldnn" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "Scale_x" type: FLOAT @@ -62,24 +45,4 @@ extra { name: "Scale_out" type: FLOAT } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } } diff --git a/paddle/fluid/operators/compat/elementwise_div.pbtxt b/paddle/fluid/operators/compat/elementwise_div.pbtxt index 40e9d90dbfd..a73d2072029 100644 --- a/paddle/fluid/operators/compat/elementwise_div.pbtxt +++ b/paddle/fluid/operators/compat/elementwise_div.pbtxt @@ -15,10 +15,6 @@ def { } } extra { - attrs { - name: "use_mkldnn" - type: BOOLEAN - } attrs { name: "x_data_format" type: STRING @@ -27,14 +23,6 @@ extra { name: "y_data_format" type: STRING } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "Scale_x" type: FLOAT @@ -47,26 +35,6 @@ extra { name: "Scale_out" type: FLOAT } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } attrs { name: "act" type: STRING diff --git a/paddle/fluid/operators/compat/elementwise_mul.pbtxt b/paddle/fluid/operators/compat/elementwise_mul.pbtxt index 3bc2186ba30..22289e2689c 100644 --- a/paddle/fluid/operators/compat/elementwise_mul.pbtxt +++ b/paddle/fluid/operators/compat/elementwise_mul.pbtxt @@ -15,10 +15,6 @@ def { } } extra { - attrs { - name: "use_mkldnn" - type: BOOLEAN - } attrs { name: "x_data_format" type: STRING @@ -27,14 +23,6 @@ extra { name: "y_data_format" type: STRING } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "Scale_x" type: FLOAT @@ -47,24 +35,4 @@ extra { name: "Scale_out" type: FLOAT } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } } diff --git a/paddle/fluid/operators/compat/elementwise_pow.pbtxt b/paddle/fluid/operators/compat/elementwise_pow.pbtxt index 3ad21423e40..a2ab73f409b 100644 --- a/paddle/fluid/operators/compat/elementwise_pow.pbtxt +++ b/paddle/fluid/operators/compat/elementwise_pow.pbtxt @@ -15,10 +15,6 @@ def { } } extra { - attrs { - name: "use_mkldnn" - type: BOOLEAN - } attrs { name: "x_data_format" type: STRING @@ -27,14 +23,6 @@ extra { name: "y_data_format" type: STRING } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "Scale_x" type: FLOAT @@ -47,26 +35,6 @@ extra { name: "Scale_out" type: FLOAT } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } attrs { name: "act" type: STRING diff --git a/paddle/fluid/operators/compat/elementwise_sub.pbtxt b/paddle/fluid/operators/compat/elementwise_sub.pbtxt index b449e76ca06..9f38601f585 100644 --- a/paddle/fluid/operators/compat/elementwise_sub.pbtxt +++ b/paddle/fluid/operators/compat/elementwise_sub.pbtxt @@ -15,10 +15,6 @@ def { } } extra { - attrs { - name: "use_mkldnn" - type: BOOLEAN - } attrs { name: "x_data_format" type: STRING @@ -27,14 +23,6 @@ extra { name: "y_data_format" type: STRING } - attrs { - name: "use_quantizer" - type: BOOLEAN - } - attrs { - name: "mkldnn_data_type" - type: STRING - } attrs { name: "Scale_x" type: FLOAT @@ -47,26 +35,6 @@ extra { name: "Scale_out" type: FLOAT } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } attrs { name: "act" type: STRING diff --git a/paddle/fluid/operators/compat/fake_channel_wise_dequantize_max_abs.pbtxt b/paddle/fluid/operators/compat/fake_channel_wise_dequantize_max_abs.pbtxt index 542a0ff649f..ec80ffaaf32 100644 --- a/paddle/fluid/operators/compat/fake_channel_wise_dequantize_max_abs.pbtxt +++ b/paddle/fluid/operators/compat/fake_channel_wise_dequantize_max_abs.pbtxt @@ -18,30 +18,3 @@ def { type: INT } } -extra { - attrs { - name: "is_test" - type: BOOLEAN - } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } -} - diff --git a/paddle/fluid/operators/compat/fake_channel_wise_quantize_abs_max.pbtxt b/paddle/fluid/operators/compat/fake_channel_wise_quantize_abs_max.pbtxt index 22954c9ba22..04fa10cc2b3 100644 --- a/paddle/fluid/operators/compat/fake_channel_wise_quantize_abs_max.pbtxt +++ b/paddle/fluid/operators/compat/fake_channel_wise_quantize_abs_max.pbtxt @@ -18,29 +18,3 @@ def { type: INT } } -extra { - attrs { - name: "is_test" - type: BOOLEAN - } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } -} diff --git a/paddle/fluid/operators/compat/relu.pbtxt b/paddle/fluid/operators/compat/relu.pbtxt index b70458aaa3c..a3dc65ae35c 100644 --- a/paddle/fluid/operators/compat/relu.pbtxt +++ b/paddle/fluid/operators/compat/relu.pbtxt @@ -8,9 +8,9 @@ def { } } extra { - attrs { - name: "@ENABLE_CACHE_RUNTIME_CONTEXT@" - type: BOOLEAN + attrs { + name: "X0_threshold" + type: FLOAT } attrs { name: "X0_threshold" @@ -24,40 +24,4 @@ extra { name: "Out0_threshold" type: FLOAT } - attrs { - name: "use_mkldnn" - type: BOOLEAN - } - attrs { - name: "use_cudnn" - type: BOOLEAN - } - attrs { - name: "op_role" - type: INT - } - attrs { - name: "op_role_var" - type: STRINGS - } - attrs { - name: "op_namescope" - type: STRING - } - attrs { - name: "op_callstack" - type: STRINGS - } - attrs { - name: "op_device" - type: STRING - } - attrs { - name: "is_test" - type: BOOLEAN - } - attrs { - name: "name" - type: STRINGS - } } -- GitLab