未验证 提交 e4247120 编写于 作者: L liym27 提交者: GitHub

[NPU] Fix bug: Fix calculation errors of pow grad npu kernel (#31699)

上级 7ec8459c
...@@ -92,7 +92,7 @@ class PowGradNPUKernel : public framework::OpKernel<T> { ...@@ -92,7 +92,7 @@ class PowGradNPUKernel : public framework::OpKernel<T> {
Tensor x_power_mul_factor(x->type()); Tensor x_power_mul_factor(x->type());
x_power_mul_factor.mutable_data<T>(x->dims(), place); x_power_mul_factor.mutable_data<T>(x->dims(), place);
auto runner_mul_1 = auto runner_mul_1 =
NpuOpRunner("Mul", {factor_bc_tensor, *x}, {x_power_mul_factor}, {}); NpuOpRunner("Mul", {factor_bc_tensor, x_pow}, {x_power_mul_factor}, {});
runner_mul_1.Run(stream); runner_mul_1.Run(stream);
// Step 4: Compute dx = dout * factor * x.pow(factor-1) // Step 4: Compute dx = dout * factor * x.pow(factor-1)
...@@ -309,20 +309,17 @@ class SquareNPUKernel : public framework::OpKernel<T> { ...@@ -309,20 +309,17 @@ class SquareNPUKernel : public framework::OpKernel<T> {
namespace ops = paddle::operators; namespace ops = paddle::operators;
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
pow, pow, ops::PowNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::PowNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::PowNPUKernel<paddle::platform::NPUDeviceContext, ops::PowNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
pow_grad, pow_grad, ops::PowGradNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::PowGradNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::PowGradNPUKernel<paddle::platform::NPUDeviceContext, ops::PowGradNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
relu, relu, ops::ReluNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::ReluNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::ReluNPUKernel<paddle::platform::NPUDeviceContext, ops::ReluNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
...@@ -333,33 +330,28 @@ REGISTER_OP_NPU_KERNEL( ...@@ -333,33 +330,28 @@ REGISTER_OP_NPU_KERNEL(
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
sqrt, sqrt, ops::SqrtNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::SqrtNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::SqrtNPUKernel<paddle::platform::NPUDeviceContext, ops::SqrtNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
sqrt_grad, sqrt_grad,
ops::SqrtGradNPUKernel<paddle::platform::NPUDeviceContext, float>, ops::SqrtGradNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::SqrtGradNPUKernel<paddle::platform::NPUDeviceContext, ops::SqrtGradNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
log, log, ops::LogNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::LogNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::LogNPUKernel<paddle::platform::NPUDeviceContext, ops::LogNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
log_grad, log_grad, ops::LogGradNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::LogGradNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::LogGradNPUKernel<paddle::platform::NPUDeviceContext, ops::LogGradNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
tanh, tanh, ops::TanhNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::TanhNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::TanhNPUKernel<paddle::platform::NPUDeviceContext, ops::TanhNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
...@@ -370,7 +362,6 @@ REGISTER_OP_NPU_KERNEL( ...@@ -370,7 +362,6 @@ REGISTER_OP_NPU_KERNEL(
paddle::platform::float16>); paddle::platform::float16>);
REGISTER_OP_NPU_KERNEL( REGISTER_OP_NPU_KERNEL(
square, square, ops::SquareNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::SquareNPUKernel<paddle::platform::NPUDeviceContext, float>,
ops::SquareNPUKernel<paddle::platform::NPUDeviceContext, ops::SquareNPUKernel<paddle::platform::NPUDeviceContext,
paddle::platform::float16>); paddle::platform::float16>);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册