From 040d33865ef46e047b3920fcc1a0c31249c26ccb Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 30 Mar 2022 10:01:34 +0800 Subject: [PATCH] fix bug that some op has no op_role attr (#41040) --- paddle/fluid/framework/details/nan_inf_utils_detail.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/framework/details/nan_inf_utils_detail.cc b/paddle/fluid/framework/details/nan_inf_utils_detail.cc index 211fb2f7cb5..da72215653e 100644 --- a/paddle/fluid/framework/details/nan_inf_utils_detail.cc +++ b/paddle/fluid/framework/details/nan_inf_utils_detail.cc @@ -422,8 +422,11 @@ void CheckVarHasNanOrInf(const std::string& op_type, bool IsSkipOp(const framework::OperatorBase& op) { if (op_type_nan_inf_white_list().count(op.Type()) != 0) return true; - int op_role = op.template Attr( - framework::OpProtoAndCheckerMaker::OpRoleAttrName()); + int op_role = 0; + if (op.HasAttr(framework::OpProtoAndCheckerMaker::OpRoleAttrName())) { + op_role = op.template Attr( + framework::OpProtoAndCheckerMaker::OpRoleAttrName()); + } // kForward=0, can't filter if (op_role == static_cast(framework::OpRole::kForward)) { -- GitLab