reduce default attrs for dynamic graph (#22850)

* reduce default attrs for dynamic graph, test=develop

* add some explanations for explicit attr, test=develop

* tweak explicit attr comments, test=develop
revert-22710-feature/integrated_ps_api
hong 5 years ago committed by GitHub
parent aca3f5311d
commit 5191e54494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -339,9 +339,11 @@ class OpAttrChecker {
return *(checker.target<TypedAttrChecker<T>>());
}
void Check(AttributeMap* attr_map) const {
for (const auto& checker : attr_checkers_) {
checker(attr_map, false);
void Check(AttributeMap* attr_map, bool explicit_only = false) const {
auto checker_num = attr_checkers_.size();
if (explicit_only) checker_num = explicit_checker_num_;
for (size_t i = 0; i < checker_num; ++i) {
attr_checkers_[i](attr_map, false);
}
}
@ -353,8 +355,21 @@ class OpAttrChecker {
return default_values_map;
}
void RecordExplicitCheckerNum() {
explicit_checker_num_ = attr_checkers_.size();
}
private:
std::vector<AttrChecker> attr_checkers_;
// in order to improve the efficiency of dynamic graph mode,
// we divede the attribute into explicit type and implicit type.
// for explicit attribute, we mean the attribute added in the customized
// op makers, usually it's defined in the overloaded Make method.
// for implicit attribute, we mean the attribute added outside of the Make
// method like "op_role", "op_role_var", and they are useless in dynamic graph
// mode
size_t explicit_checker_num_;
};
} // namespace framework

@ -62,6 +62,7 @@ void OpProtoAndCheckerMaker::operator()(proto::OpProto* proto,
proto_ = proto;
op_checker_ = attr_checker;
Make();
op_checker_->RecordExplicitCheckerNum();
AddAttr<int>(OpRoleAttrName(), "The role of this operator")
.InEnum(

@ -290,7 +290,7 @@ OpBase::OpBase(size_t id, const std::string& type, const NameVarBaseMap& ins,
// Step 1: Run forward
if (info.Checker() != nullptr) {
info.Checker()->Check(&attrs_);
info.Checker()->Check(&attrs_, true);
}
op_ = framework::OpRegistry::CreateOp(type, {}, {}, {}, false);
@ -301,7 +301,7 @@ OpBase::OpBase(size_t id, const std::string& type, const NameVarBaseMap& ins,
void OpBase::CreateOperatorBase() {
const auto& info = framework::OpInfoMap::Instance().Get(type_);
if (info.Checker() != nullptr) {
info.Checker()->Check(&attrs_);
info.Checker()->Check(&attrs_, true);
}
op_ = framework::OpRegistry::CreateOp(type_, {}, {}, {}, false);
}

Loading…
Cancel
Save