Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inference]fix openvino engine bug #70288

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ namespace {} // namespace

using framework::ir::Node;

std::string GenerateEngineKey(
const std::unordered_set<const Node *> nodes2remove, int64_t precision) {
std::vector<std::string> engine_inputs;
std::string engine_hash_key = "";
for (auto *node : nodes2remove) {
for (auto *x : node->inputs) {
engine_hash_key += RenameVarBeUnique(x->Name(), std::to_string(x->id()));
engine_hash_key += "#";
}
for (auto *x : node->outputs) {
engine_hash_key += RenameVarBeUnique(x->Name(), std::to_string(x->id()));
engine_hash_key += "#";
}
}
engine_hash_key += std::to_string(precision);
auto engine_key = std::to_string(std::hash<std::string>()(engine_hash_key));
VLOG(2) << "OV engine hash key: " << engine_hash_key;
VLOG(2) << "OV engine key: " << engine_key;
return engine_key;
}
void analysis::OpenVINOSubgraphPass::ApplyImpl(
framework::ir::Graph *graph) const {
framework::ir::FusePassBase::Init("openvino_subgraph_pass", graph);
Expand Down Expand Up @@ -114,6 +134,9 @@ void analysis::OpenVINOSubgraphPass::ApplyImpl(
}
nodes2remove.insert(node);
}
auto inference_precision = Get<int>("inference_precision");
auto engine_key = GenerateEngineKey(nodes2remove, inference_precision);

framework::ir::GraphSafeRemoveNodes(graph, nodes2remove);
auto *scope = param_scope();
for (auto &var_name : repetitive_params) {
Expand All @@ -129,10 +152,7 @@ void analysis::OpenVINOSubgraphPass::ApplyImpl(
params.model_params_path = model_params_path;
params.model_opt_cache_dir = model_opt_cache_dir;
params.cpu_math_library_num_threads = cpu_math_library_num_threads;
auto inference_precision = Get<int>("inference_precision");
params.inference_precision = inference_precision;

std::string engine_key{"openvino"};
openvino::OpenVINOEngine *ov_engine =
inference::Singleton<inference::openvino::OVEngineManager>::Global()
.Create(engine_key, params);
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/operators/openvino/openvino_engine_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OpenVINOEngineOp : public framework::OperatorBase {
std::vector<std::string> input_names_;
std::vector<std::string> output_names_;
std::vector<std::string> runtime_input_names_;
std::string engine_key_ = "openvino";
std::string engine_key_;
std::string model_opt_cache_dir_;
std::string model_program_path_;
std::string model_params_path_;
Expand Down