From 4b89120bf55e48cdc78ceca8c7dadcf349b14060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Siwek?= Date: Tue, 31 May 2022 16:13:41 +0200 Subject: [PATCH] Remove mkldnn attributes from base ops (#42852) * remove attrs from base op * fix typos * remove brelu * undo removing code related to matmul * remove whitespaces * undo changes in matmul * remove empty line --- .../framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc | 8 -------- paddle/fluid/operators/compat/conv2d.pbtxt | 9 --------- paddle/fluid/operators/compat/depthwise_conv2d.pbtxt | 9 --------- paddle/fluid/operators/conv_op.cc | 8 -------- .../contrib/slim/quantization/quant2_int8_mkldnn_pass.py | 7 ------- .../contrib/slim/tests/test_quant2_int8_mkldnn_pass.py | 6 +----- .../tests/unittests/mkldnn/test_conv2d_mkldnn_op.py | 2 -- 7 files changed, 1 insertion(+), 48 deletions(-) diff --git a/paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc b/paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc index 55470db312f..63e402cb529 100644 --- a/paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc +++ b/paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc @@ -489,14 +489,6 @@ void QuantDequantMkldnnPass::UpdateActivations(ir::Graph* graph) const { std::string activation; if (op_desc->GetAttrIfExists("fuse_relu")) { activation = "relu"; - } else if (op_desc->GetAttrIfExists("fuse_brelu")) { - activation = "relu6"; - float alpha = 6.0; - if (op_desc->HasAttr("fuse_brelu_threshold")) { - alpha = BOOST_GET_CONST(float, - op_desc->GetAttr("fuse_brelu_threshold")); - } - op_node->Op()->SetAttr("fuse_alpha", alpha); } op_node->Op()->SetAttr("fuse_activation", activation); } diff --git a/paddle/fluid/operators/compat/conv2d.pbtxt b/paddle/fluid/operators/compat/conv2d.pbtxt index ca07d4a36ff..8de061a3cc2 100644 --- a/paddle/fluid/operators/compat/conv2d.pbtxt +++ b/paddle/fluid/operators/compat/conv2d.pbtxt @@ -77,14 +77,6 @@ extra { name: "fuse_relu" type: BOOLEAN } - attrs { - name: "fuse_brelu" - type: BOOLEAN - } - attrs { - name: "fuse_brelu_threshold" - type: FLOAT - } attrs { name: "fuse_activation" type: STRING @@ -134,4 +126,3 @@ extra { type: BOOLEAN } } - diff --git a/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt b/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt index ded14398615..1fbb99c03e8 100644 --- a/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt +++ b/paddle/fluid/operators/compat/depthwise_conv2d.pbtxt @@ -69,14 +69,6 @@ extra { name: "fuse_relu" type: BOOLEAN } - attrs { - name: "fuse_brelu" - type: BOOLEAN - } - attrs { - name: "fuse_brelu_threshold" - type: FLOAT - } attrs { name: "fuse_activation" type: STRING @@ -126,4 +118,3 @@ extra { type: BOOLEAN } } - diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index 40579478381..f084862b419 100644 --- a/paddle/fluid/operators/conv_op.cc +++ b/paddle/fluid/operators/conv_op.cc @@ -348,14 +348,6 @@ void Conv2DOpMaker::Make() { AddAttr("fuse_relu", "(bool, default false) Only used in mkldnn kernel") .SetDefault(false) .AsExtra(); - AddAttr("fuse_brelu", - "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false) - .AsExtra(); - AddAttr("fuse_brelu_threshold", - "(float, default false 6.0) Only used in mkldnn kernel") - .SetDefault(6.0f) - .AsExtra(); AddAttr("fuse_activation", "(string, default \"\") Only used in mkldnn kernel") .SetDefault("") diff --git a/python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py b/python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py index e543bc1e17b..348d9149435 100644 --- a/python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py +++ b/python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py @@ -376,13 +376,6 @@ class Quant2Int8MkldnnPass(object): activation = "" if op.op().has_attr("fuse_relu") and op.op().attr("fuse_relu"): activation = "relu" - elif op.op().has_attr("fuse_brelu") and op.op().attr( - "fuse_brelu"): - activation = "relu6" - alpha = 6.0 - if op.op().has_attr("fuse_brelu_threshold"): - alpha = op.op().attr("fuse_brelu_threshold") - op.set_attr("fuse_alpha", alpha) op.set_attr("fuse_activation", activation) return graph diff --git a/python/paddle/fluid/contrib/slim/tests/test_quant2_int8_mkldnn_pass.py b/python/paddle/fluid/contrib/slim/tests/test_quant2_int8_mkldnn_pass.py index f0dae081dd4..04e1decd4af 100644 --- a/python/paddle/fluid/contrib/slim/tests/test_quant2_int8_mkldnn_pass.py +++ b/python/paddle/fluid/contrib/slim/tests/test_quant2_int8_mkldnn_pass.py @@ -177,8 +177,7 @@ class TestQuant2Int8MkldnnPassConv2D(unittest.TestCase): 'dilations': self.dilations, 'use_cudnn': self.use_cudnn, 'use_mkldnn': self.use_mkldnn, - 'data_format': self.data_format, - 'fuse_brelu': True + 'data_format': self.data_format }) def remove_fuse_activation_attribute(self, graph): @@ -196,9 +195,6 @@ class TestQuant2Int8MkldnnPassConv2D(unittest.TestCase): self.assertTrue(op.op().has_attr("fuse_activation")) if op.op().has_attr("fuse_relu") and op.op().attr("fuse_relu"): self.assertTrue(op.op().attr("fuse_activation") == "relu") - if op.op().has_attr("fuse_brelu") and op.op().attr( - "fuse_brelu"): - self.assertTrue(op.op().attr("fuse_activation") == "relu6") def test_quant_update_activation(self): program = fluid.Program() diff --git a/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py b/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py index 487a69807e2..39f55fb45b8 100644 --- a/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py +++ b/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py @@ -61,7 +61,6 @@ class TestConv2DMKLDNNOp(TestConv2DOp): self.fuse_activation = "" self.fuse_alpha = 0 self.fuse_beta = 0 - self.fuse_brelu_threshold = 6.0 self.fuse_residual_connection = False self.input_residual_size = None @@ -99,7 +98,6 @@ class TestConv2DMKLDNNOp(TestConv2DOp): self.attrs['fuse_activation'] = self.fuse_activation self.attrs['fuse_alpha'] = self.fuse_alpha self.attrs['fuse_beta'] = self.fuse_beta - self.attrs['fuse_brelu_threshold'] = self.fuse_brelu_threshold self.attrs['fuse_residual_connection'] = self.fuse_residual_connection self.outputs['Output'] = output -- GitLab