diff --git a/paddle/fluid/jit/compilation_unit.cc b/paddle/fluid/jit/compilation_unit.cc index 796af1a50d8689fdd37ea82d03fe45946ec44b05..0f241d864fe07ecd6998f187b0661c5c3a3f7868 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 986612c6672a3c2c4ca3e60a197c8a0756a18f2d..b862faa23f9785bfd839cc563afd1d5c61e5356d 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 f4e56a5a04a623cd19695b004ba3ba8665db5a11..58d80426e5fbaef258a3cefcaa383fe254deb2a1 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 726ebf328931b5e7138604dd1840d40f10d47250..a39cf85020c1bd8f336c8eb282b12f356ca354e7 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 2fd0f23270c9ae6d22f6b68f7e15a957dfc1d205..ddc2de0fc530e32d75ceb61439fda22a68ecc729 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 9cef7664b1fa5c0d25431b77e6dfc64809fe8cbc..16ade6d77d8acc207bd46f3911569c09edc5695f 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 c3811935a52cce006986fa24fbe88b19bc6093c3..b67b5ba5b0518d8d7e6367ebaf7f155326c34c45 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 11c61b3179b65af5dd10c522c7b3a07372e1446f..d61b720cec88fd1ea8877b4bcc8eb4c2757f1894 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 868b5a3ee250a580f1e134f433dd91d9ef6d6cc2..9055120e4bbb7ad8d9791f33d07f2d9b572db56e 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 8a4001cf89c16103a3307e7de20f56e38947e611..dd5ff5d9f91cd9fa27bd03ae220b201b7982c407 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 130b16f8dd32c4f4a83117b89888588043f56932..65a39bc7f9a564ed9797f0ee94fd5927e70f71f0 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 188239f469a5768e81436701088a858a47f6753d..b93eaa44fe63268b13bfd86b66e998ac77da3392 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;