From 83f81eb573a515844d546ee403c183c8278ce15b Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 5 Mar 2021 12:33:39 +0800 Subject: [PATCH] Fix pow, refine code (#31440) --- paddle/fluid/operators/activation_op_npu.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/operators/activation_op_npu.cc b/paddle/fluid/operators/activation_op_npu.cc index 24ebc00c48..02ebdefc38 100644 --- a/paddle/fluid/operators/activation_op_npu.cc +++ b/paddle/fluid/operators/activation_op_npu.cc @@ -73,24 +73,19 @@ class PowGradNPUKernel : public framework::OpKernel { runner_pow.Run(stream); // Step 2: Construct a broadcast factor, which has the same shape with x. - // 2.1 Get the shape of x - Tensor x_shape(framework::proto::VarType::INT32); - x_shape.mutable_data({x_dims.size()}, place); - TensorFromVector(framework::vectorize(x_dims), - ctx.device_context(), &x_shape); - // 2.2 Get a factor tensor with shape [1]. + // 2.1 Get a factor tensor with shape [1]. Tensor factor_tensor(framework::proto::VarType::FP32); factor_tensor.mutable_data({1}, place); TensorFromVector(std::vector{factor}, ctx.device_context(), &factor_tensor); - // 2.3 Get the factor which has the shape with x and the same value with + // 2.2 Get the factor which has the shape with x and the same value with // factor. Tensor factor_bc_tensor(framework::proto::VarType::FP32); factor_bc_tensor.mutable_data(x_dims, place); auto runner_bc = NpuOpRunner("FillD", {factor_tensor}, {factor_bc_tensor}, - {{"dims", x_dims}}); + {{"dims", framework::vectorize(x_dims)}}); runner_bc.Run(stream); // Step 3: Compute x_power_mul_factor = factor * x.pow(factor-1) -- GitLab