diff --git a/paddle/fluid/framework/details/nan_inf_utils_detail.cc b/paddle/fluid/framework/details/nan_inf_utils_detail.cc index 211fb2f7cb5511eab3c8eb8c24351cbdcded4bd8..da72215653e75c09dbd10879a17fbb6132b13551 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)) {