From cb1a0ec1e94f015cdafcbf8e01824b1266c47bee Mon Sep 17 00:00:00 2001 From: Tomasz Socha Date: Thu, 2 Jun 2022 16:16:06 +0200 Subject: [PATCH] Enable fc on bfloat16 (#43154) * Enable fc on bfloat16 * Add pass for residual connection * Dissable Residual connection pass for now * Ban ResidualData from DQ * style * WO for python tests --- paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass.cc | 3 ++- paddle/fluid/inference/api/paddle_pass_builder.cc | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass.cc b/paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass.cc index eebc87f5d9988..879c669bbbee6 100644 --- a/paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass.cc +++ b/paddle/fluid/framework/ir/mkldnn/cpu_bfloat16_pass.cc @@ -188,7 +188,8 @@ class DeQuantizer final : public Quanter { bool IsNotPermittedName(const std::string& output_name) const override { std::unordered_map> block_list{ {"layer_norm", - {"Mean", "Variance"}}}; // not used in inference in MKLDNN + {"Mean", "Variance"}}, // not used in inference in MKLDNN + {"fc", {"ResidualData"}}}; // artifical output, already dequantized std::vector blocked_outputs{"XShape"}; // blocklist for any op auto op_name = op->Name(); diff --git a/paddle/fluid/inference/api/paddle_pass_builder.cc b/paddle/fluid/inference/api/paddle_pass_builder.cc index 3b1c84db4c534..04e77faf2e34f 100644 --- a/paddle/fluid/inference/api/paddle_pass_builder.cc +++ b/paddle/fluid/inference/api/paddle_pass_builder.cc @@ -348,6 +348,10 @@ void CpuPassStrategy::EnableMkldnnQuantizer() { void CpuPassStrategy::EnableMkldnnBfloat16() { #ifdef PADDLE_WITH_MKLDNN if (!use_mkldnn_bfloat16_) { + passes_.push_back("fc_mkldnn_pass"); + passes_.push_back("fc_act_mkldnn_fuse_pass"); + passes_.push_back("fc_elementwise_add_mkldnn_fuse_pass"); + passes_.push_back("cpu_bfloat16_placement_pass"); passes_.push_back("cpu_bfloat16_pass"); passes_.push_back("cpu_quantize_squash_pass");