@@ -35,7 +35,7 @@ using VarType = AutoMixedPrecisionPass::VarType;
3535bool PhiKernelSupportPrecision (
3636 const std::string& op_type,
3737 phi::Backend backend,
38- phi:: DataType data_type,
38+ DataType data_type,
3939 phi::DataLayout layout = phi::DataLayout::ALL_LAYOUT ) {
4040 const auto & kernels = phi::KernelFactory::Instance ().kernels ();
4141 if (kernels.count (op_type) == 0 ) {
@@ -63,7 +63,7 @@ static phi::Backend ConvertPlaceToBackend(const phi::Place& place) {
6363bool KernelSupportPrecision (
6464 const std::string& op_type,
6565 phi::Backend backend,
66- phi:: DataType precision,
66+ DataType precision,
6767 phi::DataLayout layout = phi::DataLayout::ALL_LAYOUT ) {
6868 auto phi_op_type = phi::TransToPhiKernelName (op_type);
6969
@@ -176,7 +176,7 @@ void DoInsertCastOp(Graph* graph,
176176
177177bool OpSupportPrecision (const std::string& op_type,
178178 phi::Backend backend,
179- phi:: DataType precision,
179+ DataType precision,
180180 const std::unordered_set<std::string>& black_list,
181181 const std::unordered_set<std::string>& white_list) {
182182 if (white_list.count (op_type)) return true ;
@@ -235,12 +235,11 @@ void AutoMixedPrecisionPass::Init(Graph* graph) const {
235235 }
236236
237237 if (Has (" mixed_precision_mode" )) {
238- low_precision_ =
239- static_cast <phi::DataType>(Get<int >(" mixed_precision_mode" ));
238+ low_precision_ = static_cast <DataType>(Get<int >(" mixed_precision_mode" ));
240239 }
241240
242241 skip_pass_ = (backend_ == phi::Backend::UNDEFINED ) ||
243- (low_precision_ == phi:: DataType::UNDEFINED );
242+ (low_precision_ == DataType::UNDEFINED );
244243
245244 if (skip_pass_) return ;
246245
@@ -452,17 +451,16 @@ void AutoMixedPrecisionPass::GetOpPrecision() const {
452451 if (GetOpOriginalType (op_node->Op ()->Type ()) == " scale" ) {
453452 auto scale = op_node->Op ()->GetAttrIfExists <float >(" scale" );
454453 auto bias = op_node->Op ()->GetAttrIfExists <float >(" bias" );
455- if (low_precision_ == phi:: DataType::FLOAT16 ) {
454+ if (low_precision_ == DataType::FLOAT16 ) {
456455 support_low_precision =
457456 support_low_precision &&
458- phi::dtype::isfinite (static_cast <phi::dtype:: float16>(scale)) &&
459- phi::dtype::isfinite (static_cast <phi::dtype:: float16>(bias));
460- } else if (low_precision_ == phi:: DataType::BFLOAT16 ) {
457+ phi::dtype::isfinite (static_cast <phi::float16>(scale)) &&
458+ phi::dtype::isfinite (static_cast <phi::float16>(bias));
459+ } else if (low_precision_ == DataType::BFLOAT16 ) {
461460 support_low_precision =
462461 support_low_precision &&
463- phi::dtype::isfinite (
464- static_cast <phi::dtype::bfloat16>(scale)) &&
465- phi::dtype::isfinite (static_cast <phi::dtype::bfloat16>(bias));
462+ phi::dtype::isfinite (static_cast <phi::bfloat16>(scale)) &&
463+ phi::dtype::isfinite (static_cast <phi::bfloat16>(bias));
466464 }
467465 }
468466
@@ -572,7 +570,7 @@ void AutoMixedPrecisionPass::UpdateOpPrecision() const {
572570 GetOpOriginalType (op_type) != " tensorrt_engine" &&
573571 white_list_.count (GetOpOriginalType (op_type)) == 0 &&
574572 !KernelSupportPrecision (
575- GetOpOriginalType (op_type), backend_, phi:: DataType::FLOAT32 )) {
573+ GetOpOriginalType (op_type), backend_, DataType::FLOAT32 )) {
576574 for (auto * out_var_node : op_node->outputs ) {
577575 PADDLE_ENFORCE_EQ (
578576 out_var_node->IsVar (),
@@ -946,32 +944,28 @@ void AutoMixedPrecisionPass::ConvertWeightsData() const {
946944 low_precision_tensor.Resize (origin_tensor->dims ());
947945 low_precision_tensor.set_type (low_precision_);
948946
949- if (low_precision_ == phi:: DataType::FLOAT16 ) {
947+ if (low_precision_ == DataType::FLOAT16 ) {
950948 auto * low_precision_data =
951- low_precision_tensor.mutable_data <phi::dtype:: float16>(CPUPlace{});
949+ low_precision_tensor.mutable_data <phi::float16>(CPUPlace{});
952950 for (int64_t i = 0 ; i < origin_tensor->numel (); i++) {
953- if (origin_tensor->dtype () == phi:: DataType::FLOAT64 ) {
951+ if (origin_tensor->dtype () == DataType::FLOAT64 ) {
954952 auto * origin_data = origin_tensor->data <double >();
955- low_precision_data[i] =
956- static_cast <phi::dtype::float16>(origin_data[i]);
957- } else if (origin_tensor->dtype () == phi::DataType::FLOAT32 ) {
953+ low_precision_data[i] = static_cast <phi::float16>(origin_data[i]);
954+ } else if (origin_tensor->dtype () == DataType::FLOAT32 ) {
958955 auto * origin_data = origin_tensor->data <float >();
959- low_precision_data[i] =
960- static_cast <phi::dtype::float16>(origin_data[i]);
956+ low_precision_data[i] = static_cast <phi::float16>(origin_data[i]);
961957 }
962958 }
963- } else if (low_precision_ == phi:: DataType::BFLOAT16 ) {
959+ } else if (low_precision_ == DataType::BFLOAT16 ) {
964960 auto * low_precision_data =
965- low_precision_tensor.mutable_data <phi::dtype:: bfloat16>(CPUPlace{});
961+ low_precision_tensor.mutable_data <phi::bfloat16>(CPUPlace{});
966962 for (int64_t i = 0 ; i < origin_tensor->numel (); i++) {
967- if (origin_tensor->dtype () == phi:: DataType::FLOAT64 ) {
963+ if (origin_tensor->dtype () == DataType::FLOAT64 ) {
968964 auto * origin_data = origin_tensor->data <double >();
969- low_precision_data[i] =
970- static_cast <phi::dtype::bfloat16>(origin_data[i]);
971- } else if (origin_tensor->dtype () == phi::DataType::FLOAT32 ) {
965+ low_precision_data[i] = static_cast <phi::bfloat16>(origin_data[i]);
966+ } else if (origin_tensor->dtype () == DataType::FLOAT32 ) {
972967 auto * origin_data = origin_tensor->data <float >();
973- low_precision_data[i] =
974- static_cast <phi::dtype::bfloat16>(origin_data[i]);
968+ low_precision_data[i] = static_cast <phi::bfloat16>(origin_data[i]);
975969 }
976970 }
977971 }
0 commit comments