From dcde6eb35b57bf7f7debc5e430eb40e72b55557e Mon Sep 17 00:00:00 2001 From: lidanqing-intel Date: Wed, 22 Jun 2022 23:25:10 +0000 Subject: [PATCH] remove slowing down pass --- paddle/fluid/inference/api/paddle_pass_builder.cc | 13 ++++++++++++- paddle/fluid/inference/api/paddle_pass_builder.h | 4 ++++ .../slim/quantization/quant2_int8_mkldnn_pass.py | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/inference/api/paddle_pass_builder.cc b/paddle/fluid/inference/api/paddle_pass_builder.cc index 20418e37a7b94..53e3b8b9cf910 100644 --- a/paddle/fluid/inference/api/paddle_pass_builder.cc +++ b/paddle/fluid/inference/api/paddle_pass_builder.cc @@ -20,6 +20,7 @@ #include #endif #include +#include #include namespace paddle { @@ -60,6 +61,12 @@ void PaddlePassBuilder::DeletePass(const std::string &pass_type) { } } +size_t PaddlePassBuilder::GetPassIndex(const std::string &pass_type) { + auto iter = std::find(std::begin(passes_), std::end(passes_), pass_type); + if (iter == std::end(passes_)) return -1; + return std::distance(std::begin(passes_), iter); +} + void PaddlePassBuilder::InsertPass(size_t idx, const std::string &pass_type) { passes_.insert(std::begin(passes_) + idx, pass_type); } @@ -266,7 +273,11 @@ void CpuPassStrategy::EnableMKLDNN() { #ifdef PADDLE_WITH_MKLDNN if (!use_mkldnn_) { passes_.insert(passes_.begin(), "mkldnn_placement_pass"); - + int id = GetPassIndex("gpu_cpu_reshape2_matmul_fuse_pass"); + // this pass slows down FC mkldnn int8 operator + if (id != -1) { + passes_.erase(passes_.begin() + id); + } for (auto &pass : std::vector({ "depthwise_conv_mkldnn_pass", // "conv_bn_fuse_pass", // Execute BN passes again to diff --git a/paddle/fluid/inference/api/paddle_pass_builder.h b/paddle/fluid/inference/api/paddle_pass_builder.h index 02290ed33ff1c..40bec389295ab 100644 --- a/paddle/fluid/inference/api/paddle_pass_builder.h +++ b/paddle/fluid/inference/api/paddle_pass_builder.h @@ -75,6 +75,10 @@ class PD_INFER_DECL PaddlePassBuilder { /// \param[in] pass_type the certain pass type to be deleted. void DeletePass(const std::string &pass_type); + /// \brief Get the certain position of a pass. + // \param[in] pass_type the type of insert pass. + size_t GetPassIndex(const std::string &pass_type); + /// \brief Delete all the passes. void ClearPasses(); 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 9d9fbd39a5767..41816068c885a 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 @@ -411,7 +411,7 @@ def _optimize_fp32_graph(self, graph): graph = self._apply_pass(graph, 'multi_gru_seq_fuse_pass') graph = self._apply_pass(graph, 'seq_concat_fc_fuse_pass') graph = self._apply_pass(graph, 'gpu_cpu_squeeze2_matmul_fuse_pass') - graph = self._apply_pass(graph, 'gpu_cpu_reshape2_matmul_fuse_pass') + #graph = self._apply_pass(graph, 'gpu_cpu_reshape2_matmul_fuse_pass') graph = self._apply_pass(graph, 'gpu_cpu_flatten2_matmul_fuse_pass') graph = self._apply_pass(graph, 'matmul_v2_scale_fuse_pass') graph = self._apply_pass(graph, 'squared_mat_sub_fuse_pass')