From be931dfefd32007785a88046626ee72b4db1ba0e Mon Sep 17 00:00:00 2001 From: WangZhen <23097963+0x45f@users.noreply.github.com> Date: Tue, 9 Aug 2022 19:57:53 +0800 Subject: [PATCH] [JitLayer]Rename class type Name2XX (#45006) * Rename class type Name2XX * Fix return type * Remove EngineMap function in layer --- paddle/fluid/jit/compilation_unit.cc | 4 ++-- paddle/fluid/jit/compilation_unit.h | 7 +++---- paddle/fluid/jit/engine/executor_engine.cc | 2 +- paddle/fluid/jit/engine/executor_engine.h | 2 +- paddle/fluid/jit/engine/pe_engine.cc | 2 +- paddle/fluid/jit/engine/pe_engine.h | 2 +- paddle/fluid/jit/function_utils.cc | 4 ++-- paddle/fluid/jit/function_utils.h | 7 +++---- paddle/fluid/jit/layer.cc | 10 ++++------ paddle/fluid/jit/layer.h | 21 ++++++++------------- paddle/fluid/jit/serializer.cc | 14 +++++++------- paddle/fluid/jit/serializer.h | 7 +++---- 12 files changed, 36 insertions(+), 46 deletions(-) diff --git a/paddle/fluid/jit/compilation_unit.cc b/paddle/fluid/jit/compilation_unit.cc index 796af1a50d8..0f241d864fe 100644 --- a/paddle/fluid/jit/compilation_unit.cc +++ b/paddle/fluid/jit/compilation_unit.cc @@ -27,7 +27,7 @@ std::shared_ptr CompilationUnit::GetEngine( engine_map_.count(name), 1, phi::errors::InvalidArgument( - "Funciton named %s is not exist in engine_map_.", name)); + "Funciton named %s is not existed in engine_map_.", name)); return engine_map_.at(name); } @@ -36,7 +36,7 @@ void CompilationUnit::SetEngine(const std::string &name, engine_map_[name] = engine; } -const Name2EngineMap &CompilationUnit::EngineMap() const { return engine_map_; } +const jit::EngineMap &CompilationUnit::EngineMap() const { return engine_map_; } } // namespace jit } // namespace paddle diff --git a/paddle/fluid/jit/compilation_unit.h b/paddle/fluid/jit/compilation_unit.h index 986612c6672..b862faa23f9 100644 --- a/paddle/fluid/jit/compilation_unit.h +++ b/paddle/fluid/jit/compilation_unit.h @@ -22,8 +22,7 @@ namespace paddle { namespace jit { class BaseEngine; -using Name2EngineMap = - std::unordered_map>; +using EngineMap = std::unordered_map>; class CompilationUnit { public: @@ -35,10 +34,10 @@ class CompilationUnit { void SetEngine(const std::string &name, const std::shared_ptr &engine); - const Name2EngineMap &EngineMap() const; + const jit::EngineMap &EngineMap() const; private: - Name2EngineMap engine_map_; + jit::EngineMap engine_map_; }; } // namespace jit diff --git a/paddle/fluid/jit/engine/executor_engine.cc b/paddle/fluid/jit/engine/executor_engine.cc index f4e56a5a04a..58d80426e5f 100644 --- a/paddle/fluid/jit/engine/executor_engine.cc +++ b/paddle/fluid/jit/engine/executor_engine.cc @@ -22,7 +22,7 @@ namespace paddle { namespace jit { ExecutorEngine::ExecutorEngine(const std::shared_ptr &info, - const Name2VariableMap ¶ms_dict, + const VariableMap ¶ms_dict, const phi::Place &place) : info_(info), place_(place), inner_exe_(place_) { info_->RemoveDescFeedFetch(); diff --git a/paddle/fluid/jit/engine/executor_engine.h b/paddle/fluid/jit/engine/executor_engine.h index 726ebf32893..a39cf85020c 100644 --- a/paddle/fluid/jit/engine/executor_engine.h +++ b/paddle/fluid/jit/engine/executor_engine.h @@ -29,7 +29,7 @@ namespace jit { class ExecutorEngine : public BaseEngine { public: ExecutorEngine(const std::shared_ptr &info, - const Name2VariableMap ¶ms_dict, + const VariableMap ¶ms_dict, const phi::Place &place); ~ExecutorEngine() noexcept {} diff --git a/paddle/fluid/jit/engine/pe_engine.cc b/paddle/fluid/jit/engine/pe_engine.cc index 2fd0f23270c..ddc2de0fc53 100644 --- a/paddle/fluid/jit/engine/pe_engine.cc +++ b/paddle/fluid/jit/engine/pe_engine.cc @@ -58,7 +58,7 @@ static ExecutionStrategy GetExecutionStrategy(const platform::Place &place) { } PEEngine::PEEngine(const std::shared_ptr &info, - const Name2VariableMap ¶ms_dict, + const VariableMap ¶ms_dict, const phi::Place &place) : info_(info), place_(place) { info_->RemoveDescFeedFetch(); diff --git a/paddle/fluid/jit/engine/pe_engine.h b/paddle/fluid/jit/engine/pe_engine.h index 9cef7664b1f..16ade6d77d8 100644 --- a/paddle/fluid/jit/engine/pe_engine.h +++ b/paddle/fluid/jit/engine/pe_engine.h @@ -42,7 +42,7 @@ using Graph = framework::ir::Graph; class PEEngine : public BaseEngine { public: PEEngine(const std::shared_ptr &info, - const Name2VariableMap ¶ms_dict, + const VariableMap ¶ms_dict, const phi::Place &place); ~PEEngine() noexcept {} diff --git a/paddle/fluid/jit/function_utils.cc b/paddle/fluid/jit/function_utils.cc index c3811935a52..b67b5ba5b05 100644 --- a/paddle/fluid/jit/function_utils.cc +++ b/paddle/fluid/jit/function_utils.cc @@ -71,14 +71,14 @@ void ShareIntoScope(const std::vector &ordered_input_names, } void ShareParamsIntoScope(const std::vector ¶m_names, - const Name2VariableMap ¶ms_dict, + const VariableMap ¶ms_dict, framework::Scope *scope) { for (size_t i = 0; i < param_names.size(); ++i) { std::string name = param_names[i]; PADDLE_ENFORCE_EQ(params_dict.count(name), 1, phi::errors::InvalidArgument( - "Parameter named %s is not exist in param_names. " + "Parameter named %s is not existed in params_dict. " "Please check that your model was saved correctly", name)); diff --git a/paddle/fluid/jit/function_utils.h b/paddle/fluid/jit/function_utils.h index 11c61b3179b..d61b720cec8 100644 --- a/paddle/fluid/jit/function_utils.h +++ b/paddle/fluid/jit/function_utils.h @@ -33,8 +33,7 @@ class Scope; namespace jit { using Variable = paddle::framework::Variable; -using Name2VariableMap = - std::unordered_map>; +using VariableMap = std::unordered_map>; using DenseTensor = phi::DenseTensor; using Tensor = paddle::experimental::Tensor; @@ -52,14 +51,14 @@ void ShareIntoScope(const std::vector &ordered_input_names, framework::Scope *scope); void ShareParamsIntoScope(const std::vector ¶m_names, - const Name2VariableMap ¶ms_dict, + const VariableMap ¶ms_dict, framework::Scope *scope); void RemoveFeedFetch(framework::ProgramDesc *program_desc); template std::shared_ptr MakeEngine(const std::shared_ptr &info, - const Name2VariableMap ¶ms_dict, + const VariableMap ¶ms_dict, const phi::Place &place) { return std::make_shared(info, params_dict, place); } diff --git a/paddle/fluid/jit/layer.cc b/paddle/fluid/jit/layer.cc index 868b5a3ee25..9055120e4bb 100644 --- a/paddle/fluid/jit/layer.cc +++ b/paddle/fluid/jit/layer.cc @@ -26,9 +26,9 @@ namespace paddle { namespace jit { -Layer::Layer(const Name2VariableMap& params_map, - const Name2VariableMap& attrs_map, - const Name2FunctionInfoMap& info_map, +Layer::Layer(const VariableMap& params_map, + const VariableMap& attrs_map, + const FunctionInfoMap& info_map, const phi::Place& place) : params_map_(params_map), attrs_map_(attrs_map), info_map_(info_map) { unit_.reset(new CompilationUnit()); @@ -56,15 +56,13 @@ void Layer::SetEngine(const std::string& name, unit_->SetEngine(name, engine); } -const Name2EngineMap& Layer::EngineMap() const { return unit_->EngineMap(); } - const std::shared_ptr& Layer::FunctionInfo( const std::string& name) const { PADDLE_ENFORCE_EQ( info_map_.count(name), 1, phi::errors::InvalidArgument( - "FuncitonInfo named %s is not exist in info_map_.", name)); + "FuncitonInfo named %s is not existed in info_map_.", name)); return info_map_.at(name); } diff --git a/paddle/fluid/jit/layer.h b/paddle/fluid/jit/layer.h index 8a4001cf89c..dd5ff5d9f91 100644 --- a/paddle/fluid/jit/layer.h +++ b/paddle/fluid/jit/layer.h @@ -37,18 +37,15 @@ class FunctionInfo; using DenseTensor = phi::DenseTensor; using Tensor = paddle::experimental::Tensor; using Variable = paddle::framework::Variable; -using Name2VariableMap = - std::unordered_map>; -using Name2EngineMap = - std::unordered_map>; -using Name2FunctionInfoMap = +using VariableMap = std::unordered_map>; +using FunctionInfoMap = std::unordered_map>; class Layer { public: - Layer(const Name2VariableMap& params_map, - const Name2VariableMap& attrs_map_, - const Name2FunctionInfoMap& info_map, + Layer(const VariableMap& params_map, + const VariableMap& attrs_map_, + const FunctionInfoMap& info_map, const phi::Place& place); jit::Function Function(const std::string& name) const; @@ -65,17 +62,15 @@ class Layer { void SetEngine(const std::string& name, const std::shared_ptr& engine); - const Name2EngineMap& EngineMap() const; - const std::shared_ptr& FunctionInfo( const std::string& name) const; std::vector FunctionNames() const; private: - Name2VariableMap params_map_; - Name2VariableMap attrs_map_; - Name2FunctionInfoMap info_map_; + VariableMap params_map_; + VariableMap attrs_map_; + FunctionInfoMap info_map_; std::shared_ptr unit_; }; diff --git a/paddle/fluid/jit/serializer.cc b/paddle/fluid/jit/serializer.cc index 130b16f8dd3..65a39bc7f9a 100644 --- a/paddle/fluid/jit/serializer.cc +++ b/paddle/fluid/jit/serializer.cc @@ -30,14 +30,14 @@ DECLARE_string(jit_engine_type); namespace paddle { namespace jit { -using Name2FunctionInfoMap = +using FunctionInfoMap = std::unordered_map>; Layer Deserializer::operator()(const std::string& path, const phi::Place& place) { const auto& pdmodel_paths = utils::PdmodelFilePaths(path); // set is ordered std::set param_names_set; - Name2FunctionInfoMap info_map; + FunctionInfoMap info_map; for (auto& it : pdmodel_paths) { auto& func_name = it.first; auto program_desc = LoadProgram(it.second); @@ -55,8 +55,8 @@ Layer Deserializer::operator()(const std::string& path, func_name, persist_var_names, program_desc); } - Name2VariableMap params_dict; - Name2VariableMap attrs_dict; + VariableMap params_dict; + VariableMap attrs_dict; ReadTensorData(path + PDPARAMS_SUFFIX, param_names_set, place, ¶ms_dict); if (utils::FileExists(path + PROPERTY_SUFFIX)) { @@ -90,7 +90,7 @@ Layer Deserializer::operator()(const std::string& path, void Deserializer::ReadTensorData(const std::string& file_name, const std::set& var_name, const phi::Place& place, - Name2VariableMap* params_dict) const { + VariableMap* params_dict) const { VLOG(3) << "ReadTensorData from: " << file_name; std::ifstream fin(file_name, std::ios::binary); platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); @@ -106,11 +106,11 @@ void Deserializer::ReadTensorData(const std::string& file_name, } void Deserializer::ReadAttributeData(const std::string& file_path, - Name2VariableMap* attrs_dict) const { + VariableMap* attrs_dict) const { VLOG(3) << "ReadPropertyData from: " << file_path; Property p; p.Deserialization(file_path); - *attrs_dict = static_cast(p.Values()); + *attrs_dict = static_cast(p.Values()); return; } diff --git a/paddle/fluid/jit/serializer.h b/paddle/fluid/jit/serializer.h index 188239f469a..b93eaa44fe6 100644 --- a/paddle/fluid/jit/serializer.h +++ b/paddle/fluid/jit/serializer.h @@ -31,8 +31,7 @@ class ProgramDesc; namespace jit { class Layer; using Variable = paddle::framework::Variable; -using Name2VariableMap = - std::unordered_map>; +using VariableMap = std::unordered_map>; // Export Layer into local disk class Serializer { @@ -56,11 +55,11 @@ class Deserializer { void ReadTensorData(const std::string& file_name, const std::set& var_name, const phi::Place& place, - Name2VariableMap* params_dict) const; + VariableMap* params_dict) const; // property pb void ReadAttributeData(const std::string& file_path, - Name2VariableMap* attrs_dict) const; + VariableMap* attrs_dict) const; // void ReadExtraInfo(const std::string& file_name) const; -- GitLab