OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CVS-167413][NPUW] Use the Output as index to avoid NPUW error when a node has multiple … (#30494)
liang9b038fe7b76e
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cppindex e68f605ca92..66b933b7c9b 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp@@ -41,7 +41,15 @@ struct std::hash<std::pair<ov::npuw::Subgraph::Ref, T2>> {return h1 ^ (h2 << 1);}};-+namespace std {+template <>+struct hash<ov::Output<ov::Node>> {+ inline size_t operator()(const ov::Output<ov::Node>& x) const {+ // TODO: use a better hash function+ return x.get_node()->get_instance_id() ^ (x.get_index() << 56);+ }+};+} // namespace stdnamespace {class FuncallEverywhere {@@ -365,7 +373,7 @@ void Partitioner::identifySubgraphs() {// Apply partitioning changes to the original model// but first cache all nodes to identify by nameusing NodeSPtr = std::shared_ptr<ov::Node>;- std::unordered_map<NodeSPtr, LinkPtrFrom> result_cache;+ std::unordered_map<ov::Output<ov::Node>, LinkPtrFrom> result_cache;std::unordered_map<std::string, NodeSPtr> node_id_cache;for (auto&& node_ptr : model->get_ordered_ops()) {node_id_cache[node_ptr->get_friendly_name()] = node_ptr;@@ -419,7 +427,7 @@ void Partitioner::identifySubgraphs() {// Input layers may be connected to the same producer nodes, weights,// or parameters. Cache those to avoid duplicating the parameters.- std::unordered_map<NodeSPtr, NodeSPtr> input_mapping;+ std::unordered_map<ov::Output<ov::Node>, NodeSPtr> input_mapping;// In several cases a model can be slightly altered after the partitioning// plan was done. E.g., new slices or converts may be added on inputs/@@ -435,7 +443,7 @@ void Partitioner::identifySubgraphs() {};auto parameter_from = [&input_mapping, connect_in_f16](ov::Output<ov::Node> output) {auto orig_node = output.get_node_shared_ptr();- auto it = input_mapping.find(orig_node);+ auto it = input_mapping.find(output);if (it != input_mapping.end()) {return it->second;}@@ -464,7 +472,7 @@ void Partitioner::identifySubgraphs() {auto new_param = std::make_shared<ov::op::v0::Parameter>(otype, output.get_partial_shape());result = std::static_pointer_cast<ov::Node>(new_param);}- input_mapping[orig_node] = result;+ input_mapping[output] = result;return result;};for (auto&& input_layer_name : group.input_layers) {@@ -505,7 +513,7 @@ void Partitioner::identifySubgraphs() {// This happens when an offline plan is used with a kvcache// model extended with slices to maintain zero-copy (LLM case)auto extra_param = input_node->input(0).get_source_output().get_node_shared_ptr();- input_mapping[input_node] = extra_param;+ input_mapping[input_node->output(0)] = extra_param;extra_params.insert(extra_param);LOG_DEBUG("Registered extra param " << extra_param);} else {@@ -553,18 +561,19 @@ void Partitioner::identifySubgraphs() {group.sg._parameters.clear();// Stabilize input order - sort layers based on names- using PairNodePtr = std::pair<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>>;+ using PairNodePtr = std::pair<ov::Output<ov::Node>, std::shared_ptr<ov::Node>>;std::vector<PairNodePtr> input_mapping_sorted(input_mapping.begin(), input_mapping.end());std::sort(input_mapping_sorted.begin(),input_mapping_sorted.end(),[](const PairNodePtr& p1, const PairNodePtr& p2) {// FIXME: some compilers could potentially compare element with itself- if (p1.first.get() == p2.first.get()) {+ if (p1.first == p2.first) {return false;}// Sanity check- NPUW_ASSERT(p1.first->get_friendly_name() != p2.first->get_friendly_name());- return p1.first->get_friendly_name() < p2.first->get_friendly_name();+ NPUW_ASSERT(p1.first != p2.first);+ return p1.first.get_node_shared_ptr()->get_friendly_name() <+ p2.first.get_node_shared_ptr()->get_friendly_name();});// Now (after unknown slices/converts were introduced) params may be referred to@@ -687,7 +696,7 @@ void Partitioner::identifySubgraphs() {// Keep it to make the ugly top-level I/O matching procedure work.// FIXME: This needs to be refactoredgroup.sg._results.push_back(ov::as_type_ptr<ov::op::v0::Result>(maybe_result));- result_cache[output_layer_ptr] =+ result_cache[output_desc] =LinkPtrFrom{this_group_idx, ov::as_type_ptr<ov::op::v0::Result>(maybe_result)};} else if (has_external_readers) {// Introduce and record a new Result@@ -712,7 +721,7 @@ void Partitioner::identifySubgraphs() {result_src = new_cvt;}auto new_result = std::make_shared<ov::op::v0::Result>(result_src);- result_cache[output_layer_ptr] = LinkPtrFrom{this_group_idx, new_result};+ result_cache[output_desc] = LinkPtrFrom{this_group_idx, new_result};ov::copy_runtime_info(output_desc.get_node_shared_ptr(), new_result);group.sg._results.push_back(new_result);