From 5db273d8740791622f123fe8c4a6bc3eef4f934d Mon Sep 17 00:00:00 2001 From: luotao1 Date: Thu, 29 Nov 2018 12:05:25 +0800 Subject: [PATCH] enhance HasAttr to fix ci test=develop --- paddle/fluid/framework/op_desc.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/op_desc.cc b/paddle/fluid/framework/op_desc.cc index a31c5336a..ce7ba9673 100644 --- a/paddle/fluid/framework/op_desc.cc +++ b/paddle/fluid/framework/op_desc.cc @@ -238,11 +238,21 @@ void OpDesc::SetOutput(const std::string ¶m_name, } bool OpDesc::HasAttr(const std::string &name) const { - const proto::OpProto &proto = OpInfoMap::Instance().Get(desc_.type()).Proto(); - for (int i = 0; i != proto.attrs_size(); ++i) { - const proto::OpProto::Attr &attr = proto.attrs(i); - if (attr.name() == name) { - return true; + if (attrs_.find(name) != attrs_.end()) { + return true; + } else { + auto &op_info = OpInfoMap::Instance(); + if (op_info.Has(desc_.type())) { + auto op_info_ptr = op_info.Get(desc_.type()); + if (op_info_ptr.HasOpProtoAndChecker()) { + const proto::OpProto &proto = op_info_ptr.Proto(); + for (int i = 0; i != proto.attrs_size(); ++i) { + const proto::OpProto::Attr &attr = proto.attrs(i); + if (attr.name() == name) { + return true; + } + } + } } } return false; -- GitLab