From 8bc0a31b1ad3c6fefd43d0a08f5d125d7606b668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=99=93=E4=BC=9F?= <39303645+Shixiaowei02@users.noreply.github.com> Date: Wed, 23 Dec 2020 20:19:00 +0800 Subject: [PATCH] update the operator registration for incompatible upgrade, test=develop (#29720) (#29774) --- paddle/fluid/framework/op_version_registry.cc | 31 ++++++++++++ paddle/fluid/framework/op_version_registry.h | 47 ++++++++++++++----- .../framework/op_version_registry_test.cc | 13 +++++ 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/framework/op_version_registry.cc b/paddle/fluid/framework/op_version_registry.cc index 38eb8af77db..bab1f20079c 100644 --- a/paddle/fluid/framework/op_version_registry.cc +++ b/paddle/fluid/framework/op_version_registry.cc @@ -62,6 +62,37 @@ OpVersionDesc&& OpVersionDesc::BugfixWithBehaviorChanged( return std::move(*this); } +OpVersionDesc&& OpVersionDesc::DeleteAttr(const std::string& name, + const std::string& remark) { + infos_.emplace_back( + new_update(OpAttrInfo(name, remark))); + return std::move(*this); +} +OpVersionDesc&& OpVersionDesc::ModifyInput(const std::string& name, + const std::string& remark) { + infos_.emplace_back( + new_update(OpInputOutputInfo(name, remark))); + return std::move(*this); +} +OpVersionDesc&& OpVersionDesc::ModifyOutput(const std::string& name, + const std::string& remark) { + infos_.emplace_back( + new_update(OpInputOutputInfo(name, remark))); + return std::move(*this); +} +OpVersionDesc&& OpVersionDesc::DeleteInput(const std::string& name, + const std::string& remark) { + infos_.emplace_back( + new_update(OpInputOutputInfo(name, remark))); + return std::move(*this); +} +OpVersionDesc&& OpVersionDesc::DeleteOutput(const std::string& name, + const std::string& remark) { + infos_.emplace_back( + new_update(OpInputOutputInfo(name, remark))); + return std::move(*this); +} + OpVersion& OpVersionRegistrar::Register(const std::string& op_type) { PADDLE_ENFORCE_EQ( op_version_map_.find(op_type), op_version_map_.end(), diff --git a/paddle/fluid/framework/op_version_registry.h b/paddle/fluid/framework/op_version_registry.h index c121e6429db..125346cb227 100644 --- a/paddle/fluid/framework/op_version_registry.h +++ b/paddle/fluid/framework/op_version_registry.h @@ -20,6 +20,7 @@ limitations under the License. */ #include #include +#include #include #include "paddle/fluid/framework/framework.pb.h" #include "paddle/fluid/framework/op_version_proto.h" @@ -30,16 +31,17 @@ namespace framework { namespace compatible { using OpAttrVariantT = - boost::variant, /* AttrType::BOOLS */ - std::vector, /* AttrType::FLOATS */ - std::vector, /* AttrType::INTS */ - std::vector, /* AttrType::LONGS */ - std::vector /* AttrType::STRINGS */ + boost::variant, /* AttrType::BOOLS */ + std::vector, /* AttrType::FLOATS */ + std::vector, /* AttrType::INTS */ + std::vector, /* AttrType::LONGS */ + std::vector, /* AttrType::STRINGS */ + boost::none_t /* None */ >; struct OpUpdateInfo { @@ -48,7 +50,7 @@ struct OpUpdateInfo { struct OpAttrInfo : OpUpdateInfo { OpAttrInfo(const std::string& name, const std::string& remark, - const OpAttrVariantT& default_value) + const OpAttrVariantT& default_value = boost::none) : name_{name}, default_value_{default_value}, remark_{remark} {} const std::string& name() const { return name_; } @@ -83,11 +85,18 @@ struct OpBugfixInfo : OpUpdateInfo { enum class OpUpdateType { kInvalid = 0, + /* Compatibility upgrade */ kModifyAttr, kNewAttr, kNewInput, kNewOutput, kBugfixWithBehaviorChanged, + /* Incompatible upgrade, only for existing registration. */ + kDeleteAttr = 100, + kModifyInput, + kModifyOutput, + kDeleteInput, + kDeleteOutput, }; class OpUpdateBase { @@ -111,6 +120,7 @@ class OpUpdate : public OpUpdateBase { class OpVersionDesc { public: + /* Compatibility upgrade */ OpVersionDesc&& ModifyAttr(const std::string& name, const std::string& remark, const OpAttrVariantT& default_value); OpVersionDesc&& NewAttr(const std::string& name, const std::string& remark, @@ -118,10 +128,23 @@ class OpVersionDesc { OpVersionDesc&& NewInput(const std::string& name, const std::string& remark); OpVersionDesc&& NewOutput(const std::string& name, const std::string& remark); OpVersionDesc&& BugfixWithBehaviorChanged(const std::string& remark); + + /* Incompatible upgrade, only for existing registration. */ + OpVersionDesc&& DeleteAttr(const std::string& name, + const std::string& remark); + OpVersionDesc&& ModifyInput(const std::string& name, + const std::string& remark); + OpVersionDesc&& ModifyOutput(const std::string& name, + const std::string& remark); + OpVersionDesc&& DeleteInput(const std::string& name, + const std::string& remark); + OpVersionDesc&& DeleteOutput(const std::string& name, + const std::string& remark); + + public: const std::vector>& infos() const { return infos_; } - OpVersionDesc() = default; OpVersionDesc(OpVersionDesc&&) = default; OpVersionDesc& operator=(OpVersionDesc&&) = default; diff --git a/paddle/fluid/framework/op_version_registry_test.cc b/paddle/fluid/framework/op_version_registry_test.cc index 888dd6de061..e66d0dc5a1f 100644 --- a/paddle/fluid/framework/op_version_registry_test.cc +++ b/paddle/fluid/framework/op_version_registry_test.cc @@ -53,6 +53,19 @@ TEST(test_operator_version, test_operator_version) { framework::compatible::OpVersionDesc() .NewInput("X2", "The second input.") .NewOutput("Y2", "The second output.")); + + REGISTER_OP_VERSION(op_name_0__) + .AddCheckpoint( + R"ROC( + Incompatible upgrade of attribute [height], input [X2] and output [Y2] + )ROC", + framework::compatible::OpVersionDesc() + .DeleteAttr("height", + "Parameters deleted due to interface alignment.") + .ModifyInput("X2", "Modify input due to interface alignment.") + .ModifyOutput("Y2", "Modify output due to interface alignment.") + .DeleteInput("X2", "Delete input due to interface alignment.") + .DeleteOutput("Y2", "Delete output due to interface alignment.")); } TEST(test_pass_op_version_checker, test_pass_op_version_checker) { -- GitLab