Skip to content

Commit

Permalink
fix bug of batch_norm_grad kernel with fp16 (#42460)
Browse files Browse the repository at this point in the history
* fix bug of batch_norm_grad kernel with fp16

* format code
  • Loading branch information
XiaoguangHu01 authored May 4, 2022
1 parent 2f99869 commit 6570814
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions paddle/phi/kernels/gpu/batch_norm_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -988,10 +988,9 @@ PD_REGISTER_KERNEL(batch_norm_grad,
double,
phi::dtype::float16) {
if (kernel_key.dtype() == phi::DataType::FLOAT16) {
kernel->OutputAt(1).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(2).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(3).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(4).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(0).SetDataType(phi::DataType::FLOAT32); // x_grad
kernel->OutputAt(1).SetDataType(phi::DataType::FLOAT32); // scale_grad
kernel->OutputAt(2).SetDataType(phi::DataType::FLOAT32); // bias_grad
}
}

Expand All @@ -1003,10 +1002,9 @@ PD_REGISTER_KERNEL(batch_norm_grad_raw,
double,
phi::dtype::float16) {
if (kernel_key.dtype() == phi::DataType::FLOAT16) {
kernel->OutputAt(1).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(2).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(3).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(4).SetDataType(phi::DataType::FLOAT32);
kernel->OutputAt(0).SetDataType(phi::DataType::FLOAT32); // x_grad
kernel->OutputAt(1).SetDataType(phi::DataType::FLOAT32); // scale_grad
kernel->OutputAt(2).SetDataType(phi::DataType::FLOAT32); // bias_grad
}
}

Expand All @@ -1019,7 +1017,6 @@ PD_REGISTER_KERNEL(batch_norm_grad_grad,
phi::BatchNormDoubleGradKernel,
float,
double) {}

#else
PD_REGISTER_KERNEL(batch_norm_grad_grad,
GPU,
Expand Down

0 comments on commit 6570814

Please sign in to comment.