未验证 提交 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(
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
......@@ -22,8 +22,7 @@
namespace paddle {
namespace jit {
class BaseEngine;
using Name2EngineMap =
std::unordered_map<std::string, std::shared_ptr<BaseEngine>>;
using EngineMap = std::unordered_map<std::string, std::shared_ptr<BaseEngine>>;
class CompilationUnit {
public:
......@@ -35,10 +34,10 @@ class CompilationUnit {
void SetEngine(const std::string &name,
const std::shared_ptr<BaseEngine> &engine);
const Name2EngineMap &EngineMap() const;
const jit::EngineMap &EngineMap() const;
private:
Name2EngineMap engine_map_;
jit::EngineMap engine_map_;
};
} // namespace jit
......
......@@ -22,7 +22,7 @@ namespace paddle {
namespace jit {
ExecutorEngine::ExecutorEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict,
const VariableMap &params_dict,
const phi::Place &place)
: info_(info), place_(place), inner_exe_(place_) {
info_->RemoveDescFeedFetch();
......
......@@ -29,7 +29,7 @@ namespace jit {
class ExecutorEngine : public BaseEngine {
public:
ExecutorEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict,
const VariableMap &params_dict,
const phi::Place &place);
~ExecutorEngine() noexcept {}
......
......@@ -58,7 +58,7 @@ static ExecutionStrategy GetExecutionStrategy(const platform::Place &place) {
}
PEEngine::PEEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict,
const VariableMap &params_dict,
const phi::Place &place)
: info_(info), place_(place) {
info_->RemoveDescFeedFetch();
......
......@@ -42,7 +42,7 @@ using Graph = framework::ir::Graph;
class PEEngine : public BaseEngine {
public:
PEEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict,
const VariableMap &params_dict,
const phi::Place &place);
~PEEngine() noexcept {}
......
......@@ -71,14 +71,14 @@ void ShareIntoScope(const std::vector<std::string> &ordered_input_names,
}
void ShareParamsIntoScope(const std::vector<std::string> &param_names,
const Name2VariableMap &params_dict,
const VariableMap &params_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));
......
......@@ -33,8 +33,7 @@ class Scope;
namespace jit {
using Variable = paddle::framework::Variable;
using Name2VariableMap =
std::unordered_map<std::string, std::shared_ptr<Variable>>;
using VariableMap = std::unordered_map<std::string, std::shared_ptr<Variable>>;
using DenseTensor = phi::DenseTensor;
using Tensor = paddle::experimental::Tensor;
......@@ -52,14 +51,14 @@ void ShareIntoScope(const std::vector<std::string> &ordered_input_names,
framework::Scope *scope);
void ShareParamsIntoScope(const std::vector<std::string> &param_names,
const Name2VariableMap &params_dict,
const VariableMap &params_dict,
framework::Scope *scope);
void RemoveFeedFetch(framework::ProgramDesc *program_desc);
template <typename T>
std::shared_ptr<T> MakeEngine(const std::shared_ptr<FunctionInfo> &info,
const Name2VariableMap &params_dict,
const VariableMap &params_dict,
const phi::Place &place) {
return std::make_shared<T>(info, params_dict, place);
}
......
......@@ -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<jit::FunctionInfo>& 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);
}
......
......@@ -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<std::string, std::shared_ptr<Variable>>;
using Name2EngineMap =
std::unordered_map<std::string, std::shared_ptr<BaseEngine>>;
using Name2FunctionInfoMap =
using VariableMap = std::unordered_map<std::string, std::shared_ptr<Variable>>;
using FunctionInfoMap =
std::unordered_map<std::string, std::shared_ptr<FunctionInfo>>;
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<BaseEngine>& engine);
const Name2EngineMap& EngineMap() const;
const std::shared_ptr<jit::FunctionInfo>& FunctionInfo(
const std::string& name) const;
std::vector<std::string> FunctionNames() const;
private:
Name2VariableMap params_map_;
Name2VariableMap attrs_map_;
Name2FunctionInfoMap info_map_;
VariableMap params_map_;
VariableMap attrs_map_;
FunctionInfoMap info_map_;
std::shared_ptr<CompilationUnit> unit_;
};
......
......@@ -30,14 +30,14 @@ DECLARE_string(jit_engine_type);
namespace paddle {
namespace jit {
using Name2FunctionInfoMap =
using FunctionInfoMap =
std::unordered_map<std::string, std::shared_ptr<FunctionInfo>>;
Layer Deserializer::operator()(const std::string& path,
const phi::Place& place) {
const auto& pdmodel_paths = utils::PdmodelFilePaths(path);
// set is ordered
std::set<std::string> 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, &params_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<std::string>& 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<Name2VariableMap>(p.Values());
*attrs_dict = static_cast<VariableMap>(p.Values());
return;
}
......
......@@ -31,8 +31,7 @@ class ProgramDesc;
namespace jit {
class Layer;
using Variable = paddle::framework::Variable;
using Name2VariableMap =
std::unordered_map<std::string, std::shared_ptr<Variable>>;
using VariableMap = std::unordered_map<std::string, std::shared_ptr<Variable>>;
// Export Layer into local disk
class Serializer {
......@@ -56,11 +55,11 @@ class Deserializer {
void ReadTensorData(const std::string& file_name,
const std::set<std::string>& 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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册