Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHI]fix momentum dtype infer #51353

Merged
merged 8 commits into from
Mar 24, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static std::set<std::string> OpsNeedSetOutputDtypeWhenRegisterPhiKernel = {
"less_equal",
"less_than",
"merged_adam",
"momentum",
"multiclass_nms3",
"multinomial",
"nanmedian",
Expand Down
7 changes: 6 additions & 1 deletion paddle/phi/infermeta/multiary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2108,10 +2108,15 @@ void MomentumInferMeta(const MetaTensor& param,

auto param_dim = param.dims();
param_out->set_dims(param_dim);
auto MPType = (param.dtype() == phi::DataType::FLOAT16 ||
param.dtype() == phi::DataType::BFLOAT16)
? phi::DataType::FLOAT32
: param.dtype();
velocity_out->set_dims(param_dim);

velocity_out->set_dtype(MPType);
if (master_param_out) {
master_param_out->set_dims(param_dim);
master_param_out->set_dtype(MPType);
}
}

Expand Down
10 changes: 8 additions & 2 deletions paddle/phi/kernels/cpu/momentum_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
#include "paddle/phi/kernels/impl/momentum_kernel_impl.h"

PD_REGISTER_KERNEL(
momentum, CPU, ALL_LAYOUT, phi::MomentumDenseKernel, float, double) {}
momentum, CPU, ALL_LAYOUT, phi::MomentumDenseKernel, float, double) {
kernel->OutputAt(1).SetDataType(phi::DataType::UNDEFINED);
AndPuQing marked this conversation as resolved.
Show resolved Hide resolved
kernel->OutputAt(2).SetDataType(phi::DataType::UNDEFINED);
}

PD_REGISTER_KERNEL(momentum_dense_param_sparse_grad,
CPU,
ALL_LAYOUT,
phi::MomentumSparseKernel,
float,
double) {}
double) {
kernel->OutputAt(1).SetDataType(phi::DataType::UNDEFINED);
kernel->OutputAt(2).SetDataType(phi::DataType::UNDEFINED);
}
10 changes: 8 additions & 2 deletions paddle/phi/kernels/gpu/momentum_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ PD_REGISTER_KERNEL(momentum,
phi::MomentumDenseKernel,
float,
double,
phi::dtype::float16) {}
phi::dtype::float16) {
kernel->OutputAt(1).SetDataType(phi::DataType::UNDEFINED);
kernel->OutputAt(2).SetDataType(phi::DataType::UNDEFINED);
}

PD_REGISTER_KERNEL(momentum_dense_param_sparse_grad,
GPU,
ALL_LAYOUT,
phi::MomentumSparseKernel,
float,
double,
phi::dtype::float16) {}
phi::dtype::float16) {
kernel->OutputAt(1).SetDataType(phi::DataType::UNDEFINED);
kernel->OutputAt(2).SetDataType(phi::DataType::UNDEFINED);
}
5 changes: 4 additions & 1 deletion paddle/phi/kernels/xpu/momentum_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ PD_REGISTER_KERNEL(momentum,
ALL_LAYOUT,
phi::MomentumDenseKernel,
float,
phi::dtype::float16) {}
phi::dtype::float16) {
kernel->OutputAt(1).SetDataType(phi::DataType::UNDEFINED);
kernel->OutputAt(2).SetDataType(phi::DataType::UNDEFINED);
}