Skip to content

Commit 7986f42

Browse files
authored
fix (#62814)
1 parent add9b32 commit 7986f42

8 files changed

Lines changed: 77 additions & 39 deletions

paddle/fluid/pir/transforms/auto_mixed_precision_pass.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ class AutoMixedPrecisionPass : public pir::Pass {
6060
precision_mode_(phi::DataType::FLOAT16) {}
6161

6262
bool Initialize(pir::IrContext* context) override {
63-
IR_ENFORCE(Has(pir::kPlaceAttr),
64-
"Pass initialize failed."
65-
"When using AutoMixedPrecisionPass, place attribute is required!"
66-
"Use Set method to set the place attribute.");
67-
IR_ENFORCE(Has("__mixed_precision_mode__"),
68-
"Pass initialize failed."
69-
"When using AutoMixedPrecisionPass, precision_mode attribute is "
70-
"required!"
71-
"Use Set method to set the scope attribute.");
63+
PADDLE_ENFORCE_EQ(
64+
Has(pir::kPlaceAttr),
65+
true,
66+
phi::errors::InvalidArgument(
67+
"Pass initialize failed."
68+
"When using AutoMixedPrecisionPass, place attribute is required!"
69+
"Use Set method to set the place attribute."));
70+
PADDLE_ENFORCE_EQ(
71+
Has("__mixed_precision_mode__"),
72+
true,
73+
phi::errors::InvalidArgument(
74+
"Pass initialize failed."
75+
"When using AutoMixedPrecisionPass, precision_mode attribute is "
76+
"required!"
77+
"Use Set method to set the scope attribute."));
7278

7379
place_ = Get<phi::Place>(pir::kPlaceAttr);
7480
precision_mode_ = Get<phi::DataType>("__mixed_precision_mode__");

paddle/fluid/pir/transforms/constant_folding_pass.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,20 @@ class ConstantFoldingPass : public pir::Pass {
468468

469469
private:
470470
bool Initialize(pir::IrContext* context) override {
471-
IR_ENFORCE(Has(pir::kPlaceAttr),
472-
"Pass initialize failed."
473-
"When using ConstantFoldingPass, place attribute is required!"
474-
"Use Set method to set the place attribute.");
475-
IR_ENFORCE(Has(pir::kParamScopeAttr),
476-
"Pass initialize failed."
477-
"When using ConstantFoldingPass, scope attribute is required!"
478-
"Use Set method to set the scope attribute.");
471+
PADDLE_ENFORCE_EQ(
472+
Has(pir::kPlaceAttr),
473+
true,
474+
phi::errors::InvalidArgument(
475+
"Pass initialize failed."
476+
"When using ConstantFoldingPass, place attribute is required!"
477+
"Use Set method to set the place attribute."));
478+
PADDLE_ENFORCE_EQ(
479+
Has(pir::kParamScopeAttr),
480+
true,
481+
phi::errors::InvalidArgument(
482+
"Pass initialize failed."
483+
"When using ConstantFoldingPass, scope attribute is required!"
484+
"Use Set method to set the scope attribute."));
479485

480486
place_ = Get<phi::Place>(pir::kPlaceAttr);
481487
scope_ = &Get<paddle::framework::Scope>(pir::kParamScopeAttr);

paddle/fluid/pir/transforms/fusion/conv2d_add_act_fuse_pass.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ class Conv2dAddActFusePattern
4343
if (!conv2d_out.HasOneUse()) return false;
4444

4545
pir::Value add_input = op.x();
46-
IR_ENFORCE(add_input == conv2d_out);
46+
PADDLE_ENFORCE_EQ(
47+
add_input && conv2d_out,
48+
true,
49+
phi::errors::PreconditionNotMet("The type of add input should be the "
50+
"same as the type of conv2d's out."));
4751

4852
if (!pir::ValueIsPersistable(op.y())) return false;
4953

paddle/fluid/pir/transforms/inplace_pass.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,11 @@ std::unordered_set<pir::Value> GetSkipDeletionValues(const pir::Block& block) {
203203
0) {
204204
continue;
205205
}
206-
IR_ENFORCE(op.attributes().count("op_name") > 0,
207-
"kernel_dialect op should own an 'op_name' attribute.");
206+
PADDLE_ENFORCE_GT(
207+
op.attributes().count("op_name"),
208+
0UL,
209+
phi::errors::InvalidArgument(
210+
"kernel_dialect op should own an 'op_name' attribute."));
208211
auto upper_op_name =
209212
op.attributes().at("op_name").dyn_cast<pir::StrAttribute>().AsString();
210213

@@ -234,8 +237,11 @@ void GetEagerDelValueOfOp(
234237
std::string upper_op_name = op.name();
235238
if (op.dialect()->name().compare(paddle::dialect::KernelDialect::name()) ==
236239
0) {
237-
IR_ENFORCE(op.attributes().count("op_name") > 0,
238-
"kernel_dialect op should own an 'op_name' attribute.");
240+
PADDLE_ENFORCE_GT(
241+
op.attributes().count("op_name"),
242+
0UL,
243+
phi::errors::InvalidArgument(
244+
"kernel_dialect op should own an 'op_name' attribute."));
239245
upper_op_name = op.attributes()
240246
.at("op_name")
241247
.dyn_cast<pir::StrAttribute>()
@@ -479,9 +485,11 @@ class InplacePass : public pir::Pass {
479485
.AsString();
480486
pir::Block::Iterator insert_pos =
481487
std::find(block.begin(), block.end(), *kv.first);
482-
IR_ENFORCE(insert_pos != block.end(),
483-
"Operator %s not found in block.",
484-
kv.first->name());
488+
PADDLE_ENFORCE_NE(
489+
insert_pos,
490+
block.end(),
491+
phi::errors::InvalidArgument("Operator %s not found in block.",
492+
kv.first->name()));
485493

486494
kv.first->set_attribute(
487495
"op_name",

paddle/fluid/pir/transforms/params_sync_among_devices_pass.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,20 @@ class ParamsSyncAmongDevicesPass : public pir::Pass {
3737
: pir::Pass("params_sync_among_devices_pass", 0) {}
3838

3939
bool Initialize(pir::IrContext* context) override {
40-
IR_ENFORCE(Has(pir::kPlaceAttr),
41-
"Pass initialize failed."
42-
"When using ConstantFoldingPass, place attribute is required!"
43-
"Use Set method to set the place attribute.");
44-
IR_ENFORCE(Has(pir::kParamScopeAttr),
45-
"Pass initialize failed."
46-
"When using ConstantFoldingPass, scope attribute is required!"
47-
"Use Set method to set the scope attribute.");
40+
PADDLE_ENFORCE_EQ(
41+
Has(pir::kPlaceAttr),
42+
true,
43+
phi::errors::InvalidArgument(
44+
"Pass initialize failed."
45+
"When using ConstantFoldingPass, place attribute is required!"
46+
"Use Set method to set the place attribute."));
47+
PADDLE_ENFORCE_EQ(
48+
Has(pir::kParamScopeAttr),
49+
true,
50+
phi::errors::InvalidArgument(
51+
"Pass initialize failed."
52+
"When using ConstantFoldingPass, scope attribute is required!"
53+
"Use Set method to set the scope attribute."));
4854

4955
place_ = Get<phi::Place>(pir::kPlaceAttr);
5056
scope_ = &Get<paddle::framework::Scope>(pir::kParamScopeAttr);

paddle/fluid/pir/transforms/shape_optimization_pass.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ class ShapeOptimizationPass : public pir::Pass {
245245
<< "===================== ShapeOptimizationPass Run start... "
246246
"=====================";
247247
auto module_op = op->dyn_cast<pir::ModuleOp>();
248-
IR_ENFORCE(module_op, "ShapeOptimizationPass should run on module op.");
248+
PADDLE_ENFORCE_EQ(module_op.name(),
249+
"builtin.module",
250+
phi::errors::InvalidArgument(
251+
"ShapeOptimizationPass should run on module op."));
249252
PrintProgram(module_op, "Origin Program");
250253

251254
InferSymExprForAllValues(module_op);

paddle/fluid/pir/transforms/sub_graph_detector.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ std::vector<pir::Operation*> InverselyTopologicalSort(pir::Block* block) {
9191
}
9292
}
9393

94-
IR_ENFORCE(
95-
block->size() == sort_ops.size(),
96-
"sort_ops.size() must be equal to block.size(), but received %d != %d",
94+
PADDLE_ENFORCE_EQ(
9795
block->size(),
98-
sort_ops.size());
96+
sort_ops.size(),
97+
phi::errors::InvalidArgument("sort_ops.size() must be equal to "
98+
"block.size(), but received %d != %d",
99+
block->size(),
100+
sort_ops.size()));
99101

100102
return sort_ops;
101103
}

paddle/fluid/pir/transforms/sub_graph_extract_pass.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class SubGraphExtractPass : public pir::Pass {
4646

4747
void Run(pir::Operation* op) override {
4848
auto module_op = op->dyn_cast<pir::ModuleOp>();
49-
IR_ENFORCE(module_op, "sub_graph_extract_pass should run on module op.");
49+
PADDLE_ENFORCE_EQ(module_op.name(),
50+
"builtin.module",
51+
phi::errors::InvalidArgument(
52+
"sub_graph_extract_pass should run on module op."));
5053
auto& block = module_op.block();
5154

5255
std::vector<GroupOpsVec> groups =

0 commit comments

Comments
 (0)