未验证 提交 be931dfe 编写于 作者: W WangZhen 提交者: GitHub

[JitLayer]Rename class type Name2XX (#45006)

* Rename class type Name2XX

* Fix return type

* Remove EngineMap function in layer
上级 42c694df
...@@ -27,7 +27,7 @@ std::shared_ptr<BaseEngine> CompilationUnit::GetEngine( ...@@ -27,7 +27,7 @@ std::shared_ptr<BaseEngine> CompilationUnit::GetEngine(
engine_map_.count(name), engine_map_.count(name),
1, 1,
phi::errors::InvalidArgument( 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); return engine_map_.at(name);
} }
...@@ -36,7 +36,7 @@ void CompilationUnit::SetEngine(const std::string &name, ...@@ -36,7 +36,7 @@ void CompilationUnit::SetEngine(const std::string &name,
engine_map_[name] = engine; engine_map_[name] = engine;
} }
const Name2EngineMap &CompilationUnit::EngineMap() const { return engine_map_; } const jit::EngineMap &CompilationUnit::EngineMap() const { return engine_map_; }
} // namespace jit } // namespace jit
} // namespace paddle } // namespace paddle
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
namespace paddle { namespace paddle {
namespace jit { namespace jit {
class BaseEngine; class BaseEngine;
using Name2EngineMap = using EngineMap = std::unordered_map<std::string, std::shared_ptr<BaseEngine>>;
std::unordered_map<std::string, std::shared_ptr<BaseEngine>>;
class CompilationUnit { class CompilationUnit {
public: public:
...@@ -35,10 +34,10 @@ class CompilationUnit { ...@@ -35,10 +34,10 @@ class CompilationUnit {
void SetEngine(const std::string &name, void SetEngine(const std::string &name,
const std::shared_ptr<BaseEngine> &engine); const std::shared_ptr<BaseEngine> &engine);
const Name2EngineMap &EngineMap() const; const jit::EngineMap &EngineMap() const;
private: private:
Name2EngineMap engine_map_; jit::EngineMap engine_map_;
}; };
} // namespace jit } // namespace jit
......
...@@ -22,7 +22,7 @@ namespace paddle { ...@@ -22,7 +22,7 @@ namespace paddle {
namespace jit { namespace jit {
ExecutorEngine::ExecutorEngine(const std::shared_ptr<FunctionInfo> &info, ExecutorEngine::ExecutorEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict, const VariableMap &params_dict,
const phi::Place &place) const phi::Place &place)
: info_(info), place_(place), inner_exe_(place_) { : info_(info), place_(place), inner_exe_(place_) {
info_->RemoveDescFeedFetch(); info_->RemoveDescFeedFetch();
......
...@@ -29,7 +29,7 @@ namespace jit { ...@@ -29,7 +29,7 @@ namespace jit {
class ExecutorEngine : public BaseEngine { class ExecutorEngine : public BaseEngine {
public: public:
ExecutorEngine(const std::shared_ptr<FunctionInfo> &info, ExecutorEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict, const VariableMap &params_dict,
const phi::Place &place); const phi::Place &place);
~ExecutorEngine() noexcept {} ~ExecutorEngine() noexcept {}
......
...@@ -58,7 +58,7 @@ static ExecutionStrategy GetExecutionStrategy(const platform::Place &place) { ...@@ -58,7 +58,7 @@ static ExecutionStrategy GetExecutionStrategy(const platform::Place &place) {
} }
PEEngine::PEEngine(const std::shared_ptr<FunctionInfo> &info, PEEngine::PEEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict, const VariableMap &params_dict,
const phi::Place &place) const phi::Place &place)
: info_(info), place_(place) { : info_(info), place_(place) {
info_->RemoveDescFeedFetch(); info_->RemoveDescFeedFetch();
......
...@@ -42,7 +42,7 @@ using Graph = framework::ir::Graph; ...@@ -42,7 +42,7 @@ using Graph = framework::ir::Graph;
class PEEngine : public BaseEngine { class PEEngine : public BaseEngine {
public: public:
PEEngine(const std::shared_ptr<FunctionInfo> &info, PEEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict, const VariableMap &params_dict,
const phi::Place &place); const phi::Place &place);
~PEEngine() noexcept {} ~PEEngine() noexcept {}
......
...@@ -71,14 +71,14 @@ void ShareIntoScope(const std::vector<std::string> &ordered_input_names, ...@@ -71,14 +71,14 @@ void ShareIntoScope(const std::vector<std::string> &ordered_input_names,
} }
void ShareParamsIntoScope(const std::vector<std::string> &param_names, void ShareParamsIntoScope(const std::vector<std::string> &param_names,
const Name2VariableMap &params_dict, const VariableMap &params_dict,
framework::Scope *scope) { framework::Scope *scope) {
for (size_t i = 0; i < param_names.size(); ++i) { for (size_t i = 0; i < param_names.size(); ++i) {
std::string name = param_names[i]; std::string name = param_names[i];
PADDLE_ENFORCE_EQ(params_dict.count(name), PADDLE_ENFORCE_EQ(params_dict.count(name),
1, 1,
phi::errors::InvalidArgument( 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", "Please check that your model was saved correctly",
name)); name));
......
...@@ -33,8 +33,7 @@ class Scope; ...@@ -33,8 +33,7 @@ class Scope;
namespace jit { namespace jit {
using Variable = paddle::framework::Variable; using Variable = paddle::framework::Variable;
using Name2VariableMap = using VariableMap = std::unordered_map<std::string, std::shared_ptr<Variable>>;
std::unordered_map<std::string, std::shared_ptr<Variable>>;
using DenseTensor = phi::DenseTensor; using DenseTensor = phi::DenseTensor;
using Tensor = paddle::experimental::Tensor; using Tensor = paddle::experimental::Tensor;
...@@ -52,14 +51,14 @@ void ShareIntoScope(const std::vector<std::string> &ordered_input_names, ...@@ -52,14 +51,14 @@ void ShareIntoScope(const std::vector<std::string> &ordered_input_names,
framework::Scope *scope); framework::Scope *scope);
void ShareParamsIntoScope(const std::vector<std::string> &param_names, void ShareParamsIntoScope(const std::vector<std::string> &param_names,
const Name2VariableMap &params_dict, const VariableMap &params_dict,
framework::Scope *scope); framework::Scope *scope);
void RemoveFeedFetch(framework::ProgramDesc *program_desc); void RemoveFeedFetch(framework::ProgramDesc *program_desc);
template <typename T> template <typename T>
std::shared_ptr<T> MakeEngine(const std::shared_ptr<FunctionInfo> &info, std::shared_ptr<T> MakeEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict, const VariableMap &params_dict,
const phi::Place &place) { const phi::Place &place) {
return std::make_shared<T>(info, params_dict, place); return std::make_shared<T>(info, params_dict, place);
} }
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
namespace paddle { namespace paddle {
namespace jit { namespace jit {
Layer::Layer(const Name2VariableMap& params_map, Layer::Layer(const VariableMap& params_map,
const Name2VariableMap& attrs_map, const VariableMap& attrs_map,
const Name2FunctionInfoMap& info_map, const FunctionInfoMap& info_map,
const phi::Place& place) const phi::Place& place)
: params_map_(params_map), attrs_map_(attrs_map), info_map_(info_map) { : params_map_(params_map), attrs_map_(attrs_map), info_map_(info_map) {
unit_.reset(new CompilationUnit()); unit_.reset(new CompilationUnit());
...@@ -56,15 +56,13 @@ void Layer::SetEngine(const std::string& name, ...@@ -56,15 +56,13 @@ void Layer::SetEngine(const std::string& name,
unit_->SetEngine(name, engine); unit_->SetEngine(name, engine);
} }
const Name2EngineMap& Layer::EngineMap() const { return unit_->EngineMap(); }
const std::shared_ptr<jit::FunctionInfo>& Layer::FunctionInfo( const std::shared_ptr<jit::FunctionInfo>& Layer::FunctionInfo(
const std::string& name) const { const std::string& name) const {
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
info_map_.count(name), info_map_.count(name),
1, 1,
phi::errors::InvalidArgument( 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); return info_map_.at(name);
} }
......
...@@ -37,18 +37,15 @@ class FunctionInfo; ...@@ -37,18 +37,15 @@ class FunctionInfo;
using DenseTensor = phi::DenseTensor; using DenseTensor = phi::DenseTensor;
using Tensor = paddle::experimental::Tensor; using Tensor = paddle::experimental::Tensor;
using Variable = paddle::framework::Variable; using Variable = paddle::framework::Variable;
using Name2VariableMap = using VariableMap = std::unordered_map<std::string, std::shared_ptr<Variable>>;
std::unordered_map<std::string, std::shared_ptr<Variable>>; using FunctionInfoMap =
using Name2EngineMap =
std::unordered_map<std::string, std::shared_ptr<BaseEngine>>;
using Name2FunctionInfoMap =
std::unordered_map<std::string, std::shared_ptr<FunctionInfo>>; std::unordered_map<std::string, std::shared_ptr<FunctionInfo>>;
class Layer { class Layer {
public: public:
Layer(const Name2VariableMap& params_map, Layer(const VariableMap& params_map,
const Name2VariableMap& attrs_map_, const VariableMap& attrs_map_,
const Name2FunctionInfoMap& info_map, const FunctionInfoMap& info_map,
const phi::Place& place); const phi::Place& place);
jit::Function Function(const std::string& name) const; jit::Function Function(const std::string& name) const;
...@@ -65,17 +62,15 @@ class Layer { ...@@ -65,17 +62,15 @@ class Layer {
void SetEngine(const std::string& name, void SetEngine(const std::string& name,
const std::shared_ptr<BaseEngine>& engine); const std::shared_ptr<BaseEngine>& engine);
const Name2EngineMap& EngineMap() const;
const std::shared_ptr<jit::FunctionInfo>& FunctionInfo( const std::shared_ptr<jit::FunctionInfo>& FunctionInfo(
const std::string& name) const; const std::string& name) const;
std::vector<std::string> FunctionNames() const; std::vector<std::string> FunctionNames() const;
private: private:
Name2VariableMap params_map_; VariableMap params_map_;
Name2VariableMap attrs_map_; VariableMap attrs_map_;
Name2FunctionInfoMap info_map_; FunctionInfoMap info_map_;
std::shared_ptr<CompilationUnit> unit_; std::shared_ptr<CompilationUnit> unit_;
}; };
......
...@@ -30,14 +30,14 @@ DECLARE_string(jit_engine_type); ...@@ -30,14 +30,14 @@ DECLARE_string(jit_engine_type);
namespace paddle { namespace paddle {
namespace jit { namespace jit {
using Name2FunctionInfoMap = using FunctionInfoMap =
std::unordered_map<std::string, std::shared_ptr<FunctionInfo>>; std::unordered_map<std::string, std::shared_ptr<FunctionInfo>>;
Layer Deserializer::operator()(const std::string& path, Layer Deserializer::operator()(const std::string& path,
const phi::Place& place) { const phi::Place& place) {
const auto& pdmodel_paths = utils::PdmodelFilePaths(path); const auto& pdmodel_paths = utils::PdmodelFilePaths(path);
// set is ordered // set is ordered
std::set<std::string> param_names_set; std::set<std::string> param_names_set;
Name2FunctionInfoMap info_map; FunctionInfoMap info_map;
for (auto& it : pdmodel_paths) { for (auto& it : pdmodel_paths) {
auto& func_name = it.first; auto& func_name = it.first;
auto program_desc = LoadProgram(it.second); auto program_desc = LoadProgram(it.second);
...@@ -55,8 +55,8 @@ Layer Deserializer::operator()(const std::string& path, ...@@ -55,8 +55,8 @@ Layer Deserializer::operator()(const std::string& path,
func_name, persist_var_names, program_desc); func_name, persist_var_names, program_desc);
} }
Name2VariableMap params_dict; VariableMap params_dict;
Name2VariableMap attrs_dict; VariableMap attrs_dict;
ReadTensorData(path + PDPARAMS_SUFFIX, param_names_set, place, &params_dict); ReadTensorData(path + PDPARAMS_SUFFIX, param_names_set, place, &params_dict);
if (utils::FileExists(path + PROPERTY_SUFFIX)) { if (utils::FileExists(path + PROPERTY_SUFFIX)) {
...@@ -90,7 +90,7 @@ Layer Deserializer::operator()(const std::string& path, ...@@ -90,7 +90,7 @@ Layer Deserializer::operator()(const std::string& path,
void Deserializer::ReadTensorData(const std::string& file_name, void Deserializer::ReadTensorData(const std::string& file_name,
const std::set<std::string>& var_name, const std::set<std::string>& var_name,
const phi::Place& place, const phi::Place& place,
Name2VariableMap* params_dict) const { VariableMap* params_dict) const {
VLOG(3) << "ReadTensorData from: " << file_name; VLOG(3) << "ReadTensorData from: " << file_name;
std::ifstream fin(file_name, std::ios::binary); std::ifstream fin(file_name, std::ios::binary);
platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance();
...@@ -106,11 +106,11 @@ void Deserializer::ReadTensorData(const std::string& file_name, ...@@ -106,11 +106,11 @@ void Deserializer::ReadTensorData(const std::string& file_name,
} }
void Deserializer::ReadAttributeData(const std::string& file_path, void Deserializer::ReadAttributeData(const std::string& file_path,
Name2VariableMap* attrs_dict) const { VariableMap* attrs_dict) const {
VLOG(3) << "ReadPropertyData from: " << file_path; VLOG(3) << "ReadPropertyData from: " << file_path;
Property p; Property p;
p.Deserialization(file_path); p.Deserialization(file_path);
*attrs_dict = static_cast<Name2VariableMap>(p.Values()); *attrs_dict = static_cast<VariableMap>(p.Values());
return; return;
} }
......
...@@ -31,8 +31,7 @@ class ProgramDesc; ...@@ -31,8 +31,7 @@ class ProgramDesc;
namespace jit { namespace jit {
class Layer; class Layer;
using Variable = paddle::framework::Variable; using Variable = paddle::framework::Variable;
using Name2VariableMap = using VariableMap = std::unordered_map<std::string, std::shared_ptr<Variable>>;
std::unordered_map<std::string, std::shared_ptr<Variable>>;
// Export Layer into local disk // Export Layer into local disk
class Serializer { class Serializer {
...@@ -56,11 +55,11 @@ class Deserializer { ...@@ -56,11 +55,11 @@ class Deserializer {
void ReadTensorData(const std::string& file_name, void ReadTensorData(const std::string& file_name,
const std::set<std::string>& var_name, const std::set<std::string>& var_name,
const phi::Place& place, const phi::Place& place,
Name2VariableMap* params_dict) const; VariableMap* params_dict) const;
// property pb // property pb
void ReadAttributeData(const std::string& file_path, void ReadAttributeData(const std::string& file_path,
Name2VariableMap* attrs_dict) const; VariableMap* attrs_dict) const;
// void ReadExtraInfo(const std::string& file_name) const; // void ReadExtraInfo(const std::string& file_name) const;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册