diff --git a/paddle/fluid/operators/fused/onednn/fusion_lstm_onednn_op.cc b/paddle/fluid/operators/fused/onednn/fusion_lstm_onednn_op.cc index 9338fe4fa76c3..05c517fd9ac09 100644 --- a/paddle/fluid/operators/fused/onednn/fusion_lstm_onednn_op.cc +++ b/paddle/fluid/operators/fused/onednn/fusion_lstm_onednn_op.cc @@ -398,15 +398,13 @@ class FusionLSTMMKLDNNKernel : public framework::OpKernel { std::shared_ptr h0_memory_p, weight_h_memory_p, weight_x_memory_p; - if (framework::TransToProtoVarType(weight_h->dtype()) == - paddle::framework::proto::VarType_Type_FP32) { + if (weight_h->dtype() == phi::DataType::FLOAT32) { h0_memory_p = handler.template AcquireH0Memory(h0); weight_x_memory_p = handler.template AcquireWeightXMemory(weight_x); weight_h_memory_p = handler.template AcquireWeightHMemory(weight_h); - } else if (framework::TransToProtoVarType(weight_h->dtype()) == - paddle::framework::proto::VarType_Type_BF16) { + } else if (weight_h->dtype() == phi::DataType::BFLOAT16) { h0_memory_p = handler.template AcquireH0Memory(h0); weight_x_memory_p = handler.template AcquireWeightXMemory(weight_x); diff --git a/paddle/fluid/operators/fused/resnet_basic_block_op.cc b/paddle/fluid/operators/fused/resnet_basic_block_op.cc index 37315367189fa..63e82dfab5d2f 100644 --- a/paddle/fluid/operators/fused/resnet_basic_block_op.cc +++ b/paddle/fluid/operators/fused/resnet_basic_block_op.cc @@ -225,26 +225,22 @@ class ResNetBasicBlockOp : public framework::OperatorWithKernel { // By default, the type of the scale, bias, mean, // and var tensors should be float when input tensor's dtype is float16. - auto bn_param_type = framework::proto::VarType::FP32; + auto bn_param_type = phi::DataType::FLOAT32; PADDLE_ENFORCE_EQ( bn_param_type, - framework::TransToProtoVarType( - ctx.Input("Scale1")->dtype()), + ctx.Input("Scale1")->dtype(), phi::errors::InvalidArgument("Scale input should be of float type")); PADDLE_ENFORCE_EQ( bn_param_type, - framework::TransToProtoVarType( - ctx.Input("Bias1")->dtype()), + ctx.Input("Bias1")->dtype(), phi::errors::InvalidArgument("Bias input should be of float type")); PADDLE_ENFORCE_EQ( bn_param_type, - framework::TransToProtoVarType( - ctx.Input("Scale2")->dtype()), + ctx.Input("Scale2")->dtype(), phi::errors::InvalidArgument("Scale input should be of float type")); PADDLE_ENFORCE_EQ( bn_param_type, - framework::TransToProtoVarType( - ctx.Input("Bias2")->dtype()), + ctx.Input("Bias2")->dtype(), phi::errors::InvalidArgument("Bias input should be of float type")); return phi::KernelKey(input_data_type, ctx.GetPlace()); diff --git a/paddle/fluid/operators/fused/resnet_unit_op.cc b/paddle/fluid/operators/fused/resnet_unit_op.cc index d1c74b6ac1cf5..30f1aff92a256 100644 --- a/paddle/fluid/operators/fused/resnet_unit_op.cc +++ b/paddle/fluid/operators/fused/resnet_unit_op.cc @@ -206,17 +206,15 @@ class ResNetUnitOp : public framework::OperatorWithKernel { auto input_data_type = OperatorWithKernel::IndicateVarDataType(ctx, "X"); // By default, the type of the scale, bias, mean, // and var tensors should be float when input tensor's dtype is float16. - auto bn_param_type = framework::proto::VarType::FP32; + auto bn_param_type = phi::DataType::FLOAT32; PADDLE_ENFORCE_EQ( bn_param_type, - framework::TransToProtoVarType( - ctx.Input("ScaleX")->dtype()), + ctx.Input("ScaleX")->dtype(), phi::errors::InvalidArgument("Scale input should be of float type")); PADDLE_ENFORCE_EQ( bn_param_type, - framework::TransToProtoVarType( - ctx.Input("BiasX")->dtype()), + ctx.Input("BiasX")->dtype(), phi::errors::InvalidArgument("Bias input should be of float type")); return phi::KernelKey(input_data_type, ctx.GetPlace()); } diff --git a/paddle/fluid/operators/lod_tensor_to_array_op.cc b/paddle/fluid/operators/lod_tensor_to_array_op.cc index a080038db3914..0e1060c9d2572 100644 --- a/paddle/fluid/operators/lod_tensor_to_array_op.cc +++ b/paddle/fluid/operators/lod_tensor_to_array_op.cc @@ -80,8 +80,7 @@ struct LoDTensorToArrayFunctor { LoDTensorToArrayFunctorImpl func; func.prev_functor_ = this; func.dev_ctx_ = dev_ctx; - framework::VisitDataType(framework::TransToProtoVarType(input_.dtype()), - func); + phi::VisitDataType(input_.dtype(), func); } }; diff --git a/paddle/fluid/operators/lookup_table_op.h b/paddle/fluid/operators/lookup_table_op.h index 864cd3176a65d..3d1a38292edbf 100644 --- a/paddle/fluid/operators/lookup_table_op.h +++ b/paddle/fluid/operators/lookup_table_op.h @@ -90,8 +90,7 @@ class LookupTableKernel : public framework::OpKernel { int64_t row_width = table_t.value().dims()[1]; const auto *table = table_t.value().data(); auto *output = output_t->mutable_data(context.GetPlace()); - auto input_data_type = - framework::TransToProtoVarType(table_t.value().dtype()); + auto input_data_type = table_t.value().dtype(); for (int64_t i = 0; i < ids_numel; ++i) { if (padding_idx != kNoPadding && ids[i] == padding_idx) { memset(output + i * row_width, 0, row_width * sizeof(T)); @@ -107,9 +106,9 @@ class LookupTableKernel : public framework::OpKernel { auto id_index = table_t.GetIndexFromId(ids[i]); if (id_index != -1) { - if (input_data_type == framework::proto::VarType::INT8 || - input_data_type == framework::proto::VarType::INT16 || - input_data_type == framework::proto::VarType::BF16) { + if (input_data_type == phi::DataType::INT8 || + input_data_type == phi::DataType::INT16 || + input_data_type == phi::DataType::BFLOAT16) { memcpy(output + i * row_width, table + id_index * row_width, row_width * sizeof(T)); @@ -140,9 +139,9 @@ class LookupTableKernel : public framework::OpKernel { "the input key should be exists. But received %d.", id_index)); - if (input_data_type == framework::proto::VarType::INT8 || - input_data_type == framework::proto::VarType::INT16 || - input_data_type == framework::proto::VarType::BF16) { + if (input_data_type == phi::DataType::INT8 || + input_data_type == phi::DataType::INT16 || + input_data_type == phi::DataType::BFLOAT16) { memcpy(output + i * row_width, table + id_index * row_width, row_width * sizeof(T)); diff --git a/paddle/fluid/operators/optimizers/sparse_momentum_op.h b/paddle/fluid/operators/optimizers/sparse_momentum_op.h index b23295e64c197..e53edbe475389 100644 --- a/paddle/fluid/operators/optimizers/sparse_momentum_op.h +++ b/paddle/fluid/operators/optimizers/sparse_momentum_op.h @@ -304,11 +304,11 @@ class SparseMomentumOpKernel : public framework::OpKernel { const bool multi_precision = ctx.Attr("multi_precision"); bool use_nesterov = ctx.Attr("use_nesterov"); auto index = ctx.Input("Index"); - const auto& index_type = framework::TransToProtoVarType(index->dtype()); + const auto& index_type = index->dtype(); if (multi_precision) { if (use_nesterov) { auto update_method = UseNesterov(); - if (index_type == framework::proto::VarType::INT32) { + if (index_type == phi::DataType::INT32) { InnerCompute>( ctx, multi_precision, update_method); } else { @@ -317,7 +317,7 @@ class SparseMomentumOpKernel : public framework::OpKernel { } } else { auto update_method = NoNesterov(); - if (index_type == framework::proto::VarType::INT32) { + if (index_type == phi::DataType::INT32) { InnerCompute>( ctx, multi_precision, update_method); } else { @@ -328,7 +328,7 @@ class SparseMomentumOpKernel : public framework::OpKernel { } else { if (use_nesterov) { auto update_method = UseNesterov(); - if (index_type == framework::proto::VarType::INT32) { + if (index_type == phi::DataType::INT32) { InnerCompute>( ctx, multi_precision, update_method); } else { @@ -337,7 +337,7 @@ class SparseMomentumOpKernel : public framework::OpKernel { } } else { auto update_method = NoNesterov(); - if (index_type == framework::proto::VarType::INT32) { + if (index_type == phi::DataType::INT32) { InnerCompute>( ctx, multi_precision, update_method); } else { @@ -371,11 +371,10 @@ class SparseMomentumOpKernel : public framework::OpKernel { phi::DenseTensor cpu_axis; const phi::DenseTensor* axis_tensor = ctx.Input("Axis"); framework::TensorCopy(*axis_tensor, phi::CPUPlace(), &cpu_axis); - const auto& axis_type = - framework::TransToProtoVarType(axis_tensor->dtype()); - if (axis_type == framework::proto::VarType::INT32) { + const auto& axis_type = axis_tensor->dtype(); + if (axis_type == phi::DataType::INT32) { axis = static_cast(cpu_axis.data()[0]); - } else if (axis_type == framework::proto::VarType::INT64) { + } else if (axis_type == phi::DataType::INT64) { axis = static_cast(cpu_axis.data()[0]); } } else { diff --git a/paddle/fluid/operators/uniform_random_op.h b/paddle/fluid/operators/uniform_random_op.h index 7c0d5a82b373a..22428597aceed 100644 --- a/paddle/fluid/operators/uniform_random_op.h +++ b/paddle/fluid/operators/uniform_random_op.h @@ -33,8 +33,7 @@ namespace operators { inline std::vector GetNewDataFromShapeTensor( const phi::DenseTensor* new_data_tensor) { - if (framework::TransToProtoVarType(new_data_tensor->dtype()) == - framework::proto::VarType::INT64) { + if (new_data_tensor->dtype() == phi::DataType::INT64) { auto* new_data = new_data_tensor->data(); phi::DenseTensor cpu_starts_tensor; if (new_data_tensor->place().GetType() == phi::AllocationType::GPU) { @@ -45,8 +44,7 @@ inline std::vector GetNewDataFromShapeTensor( std::vector vec_new_data(new_data, new_data + new_data_tensor->numel()); return vec_new_data; - } else if (framework::TransToProtoVarType(new_data_tensor->dtype()) == - framework::proto::VarType::INT32) { + } else if (new_data_tensor->dtype() == phi::DataType::INT32) { auto* new_data = new_data_tensor->data(); std::vector vec_new_data; phi::DenseTensor cpu_starts_tensor; @@ -81,8 +79,7 @@ inline std::vector GetNewDataFromShapeTensorList( "But received tensor's dim=%s.", tensor->dims())); - if (framework::TransToProtoVarType(tensor->dtype()) == - framework::proto::VarType::INT32) { + if (tensor->dtype() == phi::DataType::INT32) { if (tensor->place().GetType() == phi::AllocationType::GPU) { phi::DenseTensor temp; paddle::framework::TensorCopySync(*tensor, phi::CPUPlace(), &temp); @@ -90,8 +87,7 @@ inline std::vector GetNewDataFromShapeTensorList( } else { vec_new_shape.push_back(static_cast(*tensor->data())); } - } else if (framework::TransToProtoVarType(tensor->dtype()) == - framework::proto::VarType::INT64) { + } else if (tensor->dtype() == phi::DataType::INT64) { if (tensor->place().GetType() == phi::AllocationType::GPU) { phi::DenseTensor temp; paddle::framework::TensorCopySync(*tensor, phi::CPUPlace(), &temp); @@ -105,8 +101,7 @@ inline std::vector GetNewDataFromShapeTensorList( "But got " "unsupport dtype: %s.", i, - paddle::framework::DataTypeToString( - framework::TransToProtoVarType(tensor->dtype())))); + phi::DataTypeToString(tensor->dtype()))); } }