From 8185cecdc48a001e3f58278945d379352c9009a3 Mon Sep 17 00:00:00 2001 From: yeliang2258 <30516196+yeliang2258@users.noreply.github.com> Date: Tue, 9 Aug 2022 11:08:42 +0800 Subject: [PATCH] Fix a bug in transpose2 when run native cpu (#44659) * fix a bug in transpose2 about mkldnn * fix bug --- paddle/fluid/framework/ir/gpu_cpu_map_matmul_to_mul_pass.cc | 2 +- paddle/fluid/operators/transpose_op.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 paddle/fluid/framework/ir/gpu_cpu_map_matmul_to_mul_pass.cc diff --git a/paddle/fluid/framework/ir/gpu_cpu_map_matmul_to_mul_pass.cc b/paddle/fluid/framework/ir/gpu_cpu_map_matmul_to_mul_pass.cc old mode 100644 new mode 100755 index 6edd8c3e4de..570da9a879f --- a/paddle/fluid/framework/ir/gpu_cpu_map_matmul_to_mul_pass.cc +++ b/paddle/fluid/framework/ir/gpu_cpu_map_matmul_to_mul_pass.cc @@ -356,7 +356,7 @@ void GpuCpuMapMatmulV2ToMulPass::ApplyImpl(ir::Graph* graph) const { size_t x_rank = x_shape.size(); size_t y_rank = y_shape.size(); flag = flag && x_rank >= 2 && y_rank == 2; - + flag = flag && x_shape[x_rank - 1] == y_shape[0]; if (flag) { if (!IsCompat(subgraph, g)) { LOG(WARNING) << "GpuCpuMapMatmulV2ToMulPass in op compat failed."; diff --git a/paddle/fluid/operators/transpose_op.cc b/paddle/fluid/operators/transpose_op.cc index 4722a1fc9cc..610d6e1f48a 100644 --- a/paddle/fluid/operators/transpose_op.cc +++ b/paddle/fluid/operators/transpose_op.cc @@ -80,7 +80,7 @@ class TransposeOp : public framework::OperatorWithKernel { #ifdef PADDLE_WITH_MKLDNN // Here we need to match dims to paddle layout // as we are producing non-oneDNN result - if ((x_dims.size() >= 3) && + if (ctx->IsRunMKLDNNKernel() && (x_dims.size() >= 3) && (paddle::platform::MKLDNNDeviceContext::tls() .get_cur_paddle_data_layout() == framework::DataLayout::kNHWC)) { auto dims = phi::vectorize(x_dims); -- GitLab