diff --git a/paddle/fluid/operators/matmul_op_npu.cc b/paddle/fluid/operators/matmul_op_npu.cc index b97d0abefda5c6de949dec83aed68ad5f8d8d201..d5606177a559268bf9cc24f76bba7875277f38ca 100644 --- a/paddle/fluid/operators/matmul_op_npu.cc +++ b/paddle/fluid/operators/matmul_op_npu.cc @@ -140,20 +140,22 @@ class MatMulGradNPUKernel : public framework::OpKernel { dy->mutable_data(ctx.GetPlace()); if ((x->dims().size() == 3) && (dout->dims().size() == 3) && (dy->dims().size() == 2)) { - framework::Tensor dout_; - dout_.ShareDataWith(*dout); - std::vector vec_dim = framework::vectorize(dout_.dims()); + framework::Tensor dout_tmp; + dout_tmp.ShareDataWith(*dout); + std::vector vec_dim = + framework::vectorize(dout_tmp.dims()); std::vector vec_dim_v{vec_dim[0] * vec_dim[1], vec_dim[2]}; - dout_.Resize(framework::make_ddim(vec_dim_v)); + dout_tmp.Resize(framework::make_ddim(vec_dim_v)); - framework::Tensor x_; - x_.ShareDataWith(*x); - std::vector vec_dim_x = framework::vectorize(x_.dims()); + framework::Tensor x_tmp; + x_tmp.ShareDataWith(*x); + std::vector vec_dim_x = + framework::vectorize(x_tmp.dims()); std::vector vec_dim_x_v{vec_dim_x[0] * vec_dim_x[1], vec_dim_x[2]}; - x_.Resize(framework::make_ddim(vec_dim_x_v)); + x_tmp.Resize(framework::make_ddim(vec_dim_x_v)); const auto& runner_dy = - NpuOpRunner("MatMul", {x_, dout_}, {*dy}, + NpuOpRunner("MatMul", {x_tmp, dout_tmp}, {*dy}, {{"transpose_x1", true}, {"transpose_x2", false}}); runner_dy.Run(stream); } else { diff --git a/paddle/fluid/operators/matmul_v2_op_npu.cc b/paddle/fluid/operators/matmul_v2_op_npu.cc index 3d77c177500e384e0fa344a70b93ae2ae7582b56..b23b408e9c59a74fb9b426be0ccd4a54465a9082 100644 --- a/paddle/fluid/operators/matmul_v2_op_npu.cc +++ b/paddle/fluid/operators/matmul_v2_op_npu.cc @@ -140,20 +140,22 @@ class MatMulV2GradNPUKernel : public framework::OpKernel { dy->mutable_data(ctx.GetPlace()); if ((x->dims().size() == 3) && (dout->dims().size() == 3) && (dy->dims().size() == 2)) { - framework::Tensor dout_; - dout_.ShareDataWith(*dout); - std::vector vec_dim = framework::vectorize(dout_.dims()); + framework::Tensor dout_tmp; + dout_tmp.ShareDataWith(*dout); + std::vector vec_dim = + framework::vectorize(dout_tmp.dims()); std::vector vec_dim_v{vec_dim[0] * vec_dim[1], vec_dim[2]}; - dout_.Resize(framework::make_ddim(vec_dim_v)); + dout_tmp.Resize(framework::make_ddim(vec_dim_v)); - framework::Tensor x_; - x_.ShareDataWith(*x); - std::vector vec_dim_x = framework::vectorize(x_.dims()); + framework::Tensor x_tmp; + x_tmp.ShareDataWith(*x); + std::vector vec_dim_x = + framework::vectorize(x_tmp.dims()); std::vector vec_dim_x_v{vec_dim_x[0] * vec_dim_x[1], vec_dim_x[2]}; - x_.Resize(framework::make_ddim(vec_dim_x_v)); + x_tmp.Resize(framework::make_ddim(vec_dim_x_v)); const auto& runner_dy = - NpuOpRunner("MatMul", {x_, dout_}, {*dy}, + NpuOpRunner("MatMul", {x_tmp, dout_tmp}, {*dy}, {{"transpose_x1", true}, {"transpose_x2", false}}); runner_dy.Run(stream); } else {