Skip to content

Commit 81f2565

Browse files
committed
Merge branch 'develop' into cAlign-weak-use-count
2 parents d1344c4 + b97d327 commit 81f2565

280 files changed

Lines changed: 4236 additions & 2231 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

paddle/common/flags.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ PHI_DEFINE_EXPORTED_int32(
102102
0,
103103
"Setting the check and print level when FLAGS_check_nan_inf is set.");
104104

105+
/**
106+
* Operator related FLAG
107+
* Name: FLAGS_check_nan_inf_blacklist
108+
* Since Version:
109+
* Value Range: string, default=""
110+
* Example: FLAGS_check_nan_inf_blacklist="op1,op2,op3"
111+
* Note: Blacklist of ops to skip when checking NAN/INF
112+
*/
113+
PHI_DEFINE_EXPORTED_string(
114+
check_nan_inf_blacklist,
115+
"",
116+
"Blacklist of ops to skip when checking NAN/INF, split by ','");
117+
105118
/**
106119
* Operator related FLAG
107120
* Name: FLAGS_check_nan_inf

paddle/fluid/eager/nan_inf_utils.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "paddle/phi/core/distributed/auto_parallel/dist_tensor.h"
2424
#include "paddle/phi/core/selected_rows.h"
2525

26+
COMMON_DECLARE_string(check_nan_inf_blacklist);
2627
COMMON_DECLARE_int32(check_nan_inf_level);
2728
namespace egr {
2829

@@ -82,6 +83,27 @@ bool CheckOp(const std::string& api_name) {
8283
}
8384

8485
void CheckTensorHasNanOrInf(const std::string& api_name, const Tensor& tensor) {
86+
if (api_name == "empty") {
87+
VLOG(4) << "Current op is \"empty\", skip nan inf check.";
88+
return;
89+
}
90+
91+
if (api_name == "empty_like") {
92+
VLOG(4) << "Current op is \"empty_like\", skip nan inf check.";
93+
return;
94+
}
95+
96+
if (!FLAGS_check_nan_inf_blacklist.empty()) {
97+
std::stringstream blacklist_ss(FLAGS_check_nan_inf_blacklist);
98+
std::string blacklisted_op;
99+
while (std::getline(blacklist_ss, blacklisted_op, ',')) {
100+
if (api_name == blacklisted_op) {
101+
VLOG(4) << "Current op is in blacklist, skip nan inf check: "
102+
<< api_name;
103+
return;
104+
}
105+
}
106+
}
85107
auto op_name = phi::TransToFluidOpName(api_name);
86108
if (tensor.initialized() && CheckOp(op_name)) {
87109
auto& tensor_name = tensor.name();

paddle/fluid/framework/ir/auto_mixed_precision_pass.cc

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using VarType = AutoMixedPrecisionPass::VarType;
3535
bool 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) {
6363
bool 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

177177
bool 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
}

paddle/fluid/framework/ir/auto_mixed_precision_pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class AutoMixedPrecisionPass : public FusePassBase {
7070

7171
mutable bool enable_low_precision_io_{false};
7272
// float16 or bfloat16 now
73-
mutable phi::DataType low_precision_{phi::DataType::UNDEFINED};
73+
mutable DataType low_precision_{DataType::UNDEFINED};
7474

7575
mutable phi::Backend backend_{phi::Backend::UNDEFINED};
7676

@@ -93,7 +93,7 @@ class AutoMixedPrecisionPass : public FusePassBase {
9393

9494
bool OpSupportPrecision(const std::string& op_type,
9595
phi::Backend backend,
96-
phi::DataType precision,
96+
DataType precision,
9797
const std::unordered_set<std::string>& black_list,
9898
const std::unordered_set<std::string>& white_list);
9999

paddle/fluid/framework/ir/conv2d_trans_filter_dilations_nxn_to_1x1_pass.cc

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void Conv2dTransFilterDilationsNxNTo1x1Pass::conv2d_dilation_trans(
124124
new_weights->Resize({weights_shape[0], weights_shape[1], new_kh, new_kw});
125125
auto* cpu_ctx = static_cast<phi::CPUContext*>(
126126
phi::DeviceContextPool::Instance().Get(CPUPlace()));
127-
if (weights->dtype() == phi::DataType::FLOAT32) {
127+
if (weights->dtype() == DataType::FLOAT32) {
128128
auto weights_data = weights->data<float>();
129129
auto* new_weights_data = cpu_ctx->Alloc<float>(new_weights);
130130
memset(new_weights_data, 0, new_weights->numel() * sizeof(float));
@@ -138,24 +138,21 @@ void Conv2dTransFilterDilationsNxNTo1x1Pass::conv2d_dilation_trans(
138138
new_kw,
139139
dilations[0],
140140
dilations[1]);
141-
} else if (weights->dtype() == phi::DataType::FLOAT16) {
142-
auto weights_data = weights->data<phi::dtype::float16>();
143-
auto* new_weights_data = cpu_ctx->Alloc<phi::dtype::float16>(new_weights);
144-
memset(new_weights_data,
145-
0,
146-
new_weights->numel() * sizeof(phi::dtype::float16));
147-
conv2d_dilation_trans_fn<phi::dtype::float16>(
148-
weights_data,
149-
new_weights_data,
150-
static_cast<int>(weights_shape[0]),
151-
static_cast<int>(weights_shape[1]),
152-
kh,
153-
kw,
154-
new_kh,
155-
new_kw,
156-
dilations[0],
157-
dilations[1]);
158-
} else if (weights->dtype() == phi::DataType::INT8) {
141+
} else if (weights->dtype() == DataType::FLOAT16) {
142+
auto weights_data = weights->data<phi::float16>();
143+
auto* new_weights_data = cpu_ctx->Alloc<phi::float16>(new_weights);
144+
memset(new_weights_data, 0, new_weights->numel() * sizeof(phi::float16));
145+
conv2d_dilation_trans_fn<phi::float16>(weights_data,
146+
new_weights_data,
147+
static_cast<int>(weights_shape[0]),
148+
static_cast<int>(weights_shape[1]),
149+
kh,
150+
kw,
151+
new_kh,
152+
new_kw,
153+
dilations[0],
154+
dilations[1]);
155+
} else if (weights->dtype() == DataType::INT8) {
159156
auto weights_data = weights->data<int8_t>();
160157
auto* new_weights_data = cpu_ctx->Alloc<int8_t>(new_weights);
161158
memset(new_weights_data, 0, new_weights->numel() * sizeof(int8_t));

paddle/fluid/framework/ir/conv_bn_fuse_pass.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const {
354354
scope->FindVar(conv_weight->Name())->GetMutable<DenseTensor>();
355355
auto tensor_type = conv_weight_tensor->dtype();
356356

357-
if (tensor_type == phi::DataType::FLOAT16) {
357+
if (tensor_type == DataType::FLOAT16) {
358358
ConvertTensorType<float16, float>(conv_weight_tensor);
359359
}
360360

@@ -404,7 +404,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const {
404404
epsilon,
405405
conv_type());
406406

407-
if (tensor_type == phi::DataType::FLOAT16) {
407+
if (tensor_type == DataType::FLOAT16) {
408408
ConvertTensorType<float, float16>(conv_weight_tensor);
409409
ConvertTensorType<float, float16>(eltwise_y_in_tensor);
410410
}
@@ -446,7 +446,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const {
446446
epsilon,
447447
conv_type());
448448

449-
if (tensor_type == phi::DataType::FLOAT16) {
449+
if (tensor_type == DataType::FLOAT16) {
450450
ConvertTensorType<float, float16>(conv_weight_tensor);
451451
ConvertTensorType<float, float16>(conv_bias_tensor);
452452
}
@@ -673,7 +673,7 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const {
673673
scope->FindVar(conv_weight->Name())->GetMutable<DenseTensor>();
674674
auto tensor_type = conv_weight_tensor->dtype();
675675

676-
if (tensor_type == phi::DataType::FLOAT16) {
676+
if (tensor_type == DataType::FLOAT16) {
677677
ConvertTensorType<float16, float>(conv_weight_tensor);
678678
ConvertTensorType<float16, float>(eltwise_y_in_tensor);
679679
}
@@ -732,7 +732,7 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const {
732732
conv_type());
733733
}
734734

735-
if (tensor_type == phi::DataType::FLOAT16) {
735+
if (tensor_type == DataType::FLOAT16) {
736736
ConvertTensorType<float, float16>(conv_weight_tensor);
737737
ConvertTensorType<float, float16>(eltwise_y_in_tensor);
738738
}

paddle/fluid/framework/ir/conv_elementwise_add2_act_fuse_pass.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ void ConvElementwiseAdd2ActFusePass::ApplyImpl(ir::Graph* graph) const {
147147
std::unordered_set<std::string> all_act_set = cudnn_act_set;
148148

149149
bool is_fp16_precision =
150-
static_cast<phi::DataType>(Get<int>("model_precision")) ==
151-
phi::DataType::FLOAT16 ||
150+
static_cast<DataType>(Get<int>("model_precision")) == DataType::FLOAT16 ||
152151
Get<bool>("enable_gpu_mixed");
153152
bool cutlass_enable = Get<bool>("use_cutlass");
154153
if (is_fp16_precision && cutlass_enable) {

paddle/fluid/framework/ir/conv_elementwise_add_act_fuse_pass.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ void ConvElementwiseAddActFusePass::ApplyImpl(ir::Graph* graph) const {
168168
std::unordered_set<std::string> all_act_set = cudnn_act_set;
169169

170170
bool is_fp16_precision =
171-
static_cast<phi::DataType>(Get<int>("model_precision")) ==
172-
phi::DataType::FLOAT16 ||
171+
static_cast<DataType>(Get<int>("model_precision")) == DataType::FLOAT16 ||
173172
Get<bool>("enable_gpu_mixed");
174173
bool cutlass_enable = Get<bool>("use_cutlass");
175174
if (is_fp16_precision && cutlass_enable) {

paddle/fluid/framework/ir/conv_elementwise_add_fuse_pass.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ void ConvElementwiseAddFusePass::ApplyImpl(ir::Graph* graph) const {
122122
new_op_desc.SetAttr("use_cudnn", true);
123123

124124
bool is_fp16_precision =
125-
static_cast<phi::DataType>(Get<int>("model_precision")) ==
126-
phi::DataType::FLOAT16 ||
125+
static_cast<DataType>(Get<int>("model_precision")) ==
126+
DataType::FLOAT16 ||
127127
Get<bool>("enable_gpu_mixed");
128128

129129
bool cutlass_enable = Get<bool>("use_cutlass");

paddle/fluid/framework/ir/delete_cast_op_pass.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,16 +690,16 @@ int DeleteCastOpPass::ApplyCastLookupTablePass(ir::Graph* graph) const {
690690
auto* w_tensor =
691691
scope->Var(lookup_table_w->Name())->GetMutable<DenseTensor>();
692692
lookup_table_w->Var()->SetDataType(proto::VarType::FP16);
693-
if (w_tensor->dtype() != phi::DataType::FLOAT16) {
693+
if (w_tensor->dtype() != DataType::FLOAT16) {
694694
auto* cpu_ctx = static_cast<phi::CPUContext*>(
695695
phi::DeviceContextPool::Instance().Get(CPUPlace()));
696696
DenseTensor w_fp32_tensor;
697697
w_fp32_tensor.Resize(w_tensor->dims());
698698
w_fp32_tensor.set_type(w_tensor->dtype());
699699
phi::AssignKernel(*cpu_ctx, *w_tensor, &w_fp32_tensor);
700-
w_tensor->set_type(phi::DataType::FLOAT16);
700+
w_tensor->set_type(DataType::FLOAT16);
701701
phi::CastKernel<float>(
702-
*cpu_ctx, w_fp32_tensor, phi::DataType::FLOAT16, w_tensor);
702+
*cpu_ctx, w_fp32_tensor, DataType::FLOAT16, w_tensor);
703703
}
704704

705705
for (auto* next_op : cast_out->outputs) {

0 commit comments

Comments
 (0)