-
Notifications
You must be signed in to change notification settings - Fork 3k
Avoid inserting Convert operations for irregular ov::Result case #33402
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
Merged
+340
−41
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1270,6 +1270,101 @@ void Snapshot::stripTag(const std::string& tag) { | |
| } | ||
| } | ||
|
|
||
| bool Snapshot::isRegularResultCase() const { | ||
nikita-kud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LOG_INFO("Online partitioning: executing isRegularResultCase pass..."); | ||
| LOG_BLOCK(); | ||
|
|
||
| // This method works around an issue where the final partitioning fails the sanity check | ||
| // because of a different number of output Convert across repeated block groups. | ||
| // The issue was initially observed in a model where only the final block has an additional ov::Result consumer. | ||
| // For example, Group[0..30] has only external consumers (i.e. consumers that belong to other groups): | ||
| // OpA -> OpB(external group) | ||
| // -> OpC(external group) | ||
| // but very last Group[31] has an additional ov::Result consumer: | ||
| // OpA -> ov::Result | ||
| // -> OpB(external group) | ||
| // -> OpC(external group) | ||
| // Later, if NPUW_F16IC is set, "Partitioner::identifySubgraphs" method adds output Converts to each Group[0..30], | ||
| // but skips Group[31] due to internal implementation details. | ||
| // "Partitioner::identifySubgraphs" can't: | ||
| // - add Convert to the Group[31] because it would require adding opposite Convert for the ov::Result | ||
| // - skip adding Converts to Group[0..30] because it would break symmetry of the repeated blocks, i.e. | ||
| // in the given graph `Convert(group0) -> output -> input -> Convert(group1)` input `Convert(group1)` should | ||
| // be also eliminated | ||
| // Therefore, we disable F16IC early in such cases. | ||
|
|
||
| using NodeSPtr = std::shared_ptr<ov::Node>; | ||
| std::unordered_map<std::string, NodeSPtr> node_id_cache; | ||
| for (auto&& node_ptr : m_model->get_ordered_ops()) { | ||
| node_id_cache[node_ptr->get_friendly_name()] = node_ptr; | ||
| } | ||
|
|
||
| auto getReadersMask = [](const NodeSPtr& node_ptr) { | ||
| // each element of the vector is | ||
| // the number of ov::Result readers for the corresponding output | ||
| std::vector<int> mask; | ||
| for (auto&& output_desc : node_ptr->outputs()) { | ||
| auto readers = output_desc.get_target_inputs(); | ||
| int result_count = 0; | ||
| for (auto&& r : readers) { | ||
| auto reader_node_ptr = r.get_node()->shared_from_this(); | ||
| if (ov::op::util::is_output(reader_node_ptr)) { | ||
| result_count++; | ||
| } | ||
| } | ||
| mask.push_back(result_count); | ||
nikita-kud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return mask; | ||
| }; | ||
|
|
||
| auto reptag_to_gset = repeating(); | ||
| if (!reptag_to_gset.empty()) { | ||
| NPUW_ASSERT(!m_layer_matches.empty()); | ||
| } | ||
|
|
||
| for (const auto& reptag_and_gset : reptag_to_gset) { | ||
| auto reptag = reptag_and_gset.first; | ||
| auto gset = reptag_and_gset.second; | ||
|
|
||
| auto matches = m_layer_matches.at(reptag->id()); | ||
|
|
||
| if (gset.size() <= 1) { | ||
| continue; | ||
| } | ||
|
|
||
| auto firstGroup = *(gset.begin()); | ||
| for (auto output_layer : firstGroup->getOutputs()) { | ||
| // this is the reference mask expected from all other matched layers | ||
| // in the remaining groups of the repeated block | ||
| auto expected_readers_mask = getReadersMask(output_layer); | ||
|
|
||
| auto this_layer_name = output_layer->get_friendly_name(); | ||
| auto layer_bank_iter = std::find_if(matches.begin(), matches.end(), [&](const std::set<std::string>& lrs) { | ||
| return lrs.count(this_layer_name) > 0; | ||
| }); | ||
|
|
||
| NPUW_ASSERT(layer_bank_iter != matches.end()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I assume we will have at least one match if we have more than one group. |
||
|
|
||
| // match output layers across all groups in the repeated block | ||
| // and compare their readers mask | ||
| for (const auto& layer_name : *layer_bank_iter) { | ||
| auto layer_ptr = node_id_cache.at(layer_name); | ||
| auto actual_readers_mask = getReadersMask(layer_ptr); | ||
|
|
||
| if (actual_readers_mask != expected_readers_mask) { | ||
| LOG_INFO("This is NOT a regular result case. Readers mask mismatch found for " | ||
| << layer_name << " and " << this_layer_name << " output layers."); | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| LOG_INFO("This is a regular result case"); | ||
| LOG_INFO("DONE"); | ||
| return true; | ||
| } | ||
|
|
||
| size_t Snapshot::getNextRepId() { | ||
| return m_current_rep_count++; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there are no tests for printing/parsing this structure, please let me know if I missed something