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

NPUW: Introduce 'last' keyword for dump options #26841

Merged
merged 5 commits into from
Oct 25, 2024

Conversation

eshiryae
Copy link
Contributor

Details:

  • The problem is that for different networks the number of NPUW's detected block may be different and it is hard to tell what the last block number will be. Now 'last' option can be used to tell NPUW to dump tail block without setting specific number.

Tickets:

  • E-139857

@github-actions github-actions bot added category: NPU OpenVINO NPU plugin category: NPUW NPUW plugin labels Sep 27, 2024
@eshiryae eshiryae marked this pull request as ready for review October 4, 2024 12:54
@eshiryae eshiryae requested review from a team as code owners October 4, 2024 12:54
@dmatveev dmatveev self-assigned this Oct 8, 2024
@dmatveev dmatveev added this to the 2024.5 milestone Oct 8, 2024
@dmatveev
Copy link
Contributor

@AsyaPronina please review

@@ -307,7 +307,9 @@ static constexpr ov::Property<bool> full{"NPUW_DUMP_FULL"};
* Type: std::string.
* Dump the specified subgraph(s) in OpenVINO IR form in the current directory.
* Possible values: Comma-separated list of subgraph indices or "YES" for all
* subgraphs, "NO" or just empty value to turn option off. E.g. "0,1" or "YES".
* subgraphs, "NO" or just empty value to turn option off. Keyword "last" can
* be used for dumping last subgraph without specifying it by specific indice.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: indice typo, but comment might be ignored

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair to be index, why should this comment be ignored

Copy link
Contributor Author

@eshiryae eshiryae Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just aligned with comment message above:

Possible values: Comma-separated list of subgraph indices or "YES" for all subgraphs

Should I change it too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that plural form of index is indices

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -307,7 +307,9 @@ static constexpr ov::Property<bool> full{"NPUW_DUMP_FULL"};
* Type: std::string.
* Dump the specified subgraph(s) in OpenVINO IR form in the current directory.
* Possible values: Comma-separated list of subgraph indices or "YES" for all
* subgraphs, "NO" or just empty value to turn option off. E.g. "0,1" or "YES".
* subgraphs, "NO" or just empty value to turn option off. Keyword "last" can
* be used for dumping last subgraph without specifying it by specific indice.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair to be index, why should this comment be ignored

@@ -211,7 +211,8 @@ void ov::npuw::IBaseInferRequest::infer() {

void ov::npuw::IBaseInferRequest::dump_input_tensors(std::size_t idx) {
const std::string dump_ios_opt = m_npuw_model->m_cfg.get<::intel_npu::NPUW_DUMP_IO>();
if (!ov::npuw::util::is_set(idx, dump_ios_opt)) {
const std::size_t last_idx = m_npuw_model->m_compiled_submodels.size() - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it makes sense to make last_idx be end_idx - exclusive, like end() iterator - so that you have -1 in just a single place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to add method to CompiledModel class which return the index of the last submodel?

Copy link
Contributor

@AsyaPronina AsyaPronina Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be Dmitry means just to rename last_idx to end_idx and use it without -1 when passing to the ov::npuw::util::is_set(idx, dump_ios_opt, end_idx), where you can substract 1 right inside the is_set function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly what @AsyaPronina says

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -695,8 +704,9 @@ ov::SoPtr<ov::ICompiledModel> ov::npuw::CompiledModel::compile_submodel(const st

void ov::npuw::CompiledModel::dump_on_fail(std::size_t id, const std::string& device_to_try, const char* extra) {
const std::string dof_opt = m_cfg.get<::intel_npu::NPUW_DUMP_SUBS_ON_FAIL>();
const std::size_t last_idx = m_compiled_submodels.size() - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surely, it should be end_idx to avoid these recurring -1s.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 346 to 353
std::string fsd_opt = m_cfg.get<::intel_npu::NPUW_SUBMODEL_DEVICE>();
// Change "last" keyword to tail subgraph number
std::size_t last_pos = fsd_opt.find("last");
if (last_pos != std::string::npos) {
fsd_opt.erase(last_pos, 4);
fsd_opt.insert(last_pos, std::to_string(last_sub_idx));
}

forced_sub_devices = ::intel_npu ::OptionParser<std::map<std::size_t, std::string>>::parse(fsd_opt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AsyaPronina is this OptionParser ours? Can we add extra parameters to parse in this case? I'd prefer that code handle last for all its users (assuming the end of the range is passed to parse()).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is NPU OptionParser, it is generic callable to parse from string to requested type. However, we can as it to parse to std::map<std::string, std::string> instead of std::map<std::size_t, std::string>, where key will be string, so it may accept "last". But then we need to parse other indices from string to std::size_t on our own.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is NPU OptionParser, it is generic callable to parse from string to requested type. However, we can as it to parse to std::map<std::string, std::string> instead of std::map<std::size_t, std::string>, where key will be string, so it may accept "last". But then we need to parse other indices from string to std::size_t on our own.

so it means we can also extend it with a new parse() overload for this particular template instantiation, isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, thank you!

@@ -17,20 +17,28 @@
#include "openvino/runtime/make_tensor.hpp" // get_tensor_impl
#include "util_xarch.hpp"

bool ov::npuw::util::is_set(const std::size_t sub_idx, const std::string& opt) {
bool ov::npuw::util::is_set(const std::size_t sub_idx, const std::string& opt, const std::size_t last_idx) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AsyaPronina what tests can you recommend here to add?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that for different networks the number of NPUW's detected
block may be different and it is hard to tell what the last block number
will be. Now 'last' option can be used to tell NPUW to dump tail block
without setting specific number.
Copy link
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it now but please add tests as a follow-up. Thanks!

std::vector<std::size_t> sub_inds{};
sub_inds = ::intel_npu ::OptionParser<std::vector<std::size_t>>::parse(opt);
sub_inds = ::intel_npu ::OptionParser<std::vector<std::size_t>>::parse(str);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to cover ::parse() handle this case - it will be one place for all

@dmatveev dmatveev added this pull request to the merge queue Oct 25, 2024
Merged via the queue into openvinotoolkit:master with commit 8934f90 Oct 25, 2024
134 checks passed
CuriousPanCake pushed a commit to CuriousPanCake/openvino that referenced this pull request Nov 6, 2024
### Details:
- The problem is that for different networks the number of NPUW's
detected block may be different and it is hard to tell what the last
block number will be. Now 'last' option can be used to tell NPUW to dump
tail block without setting specific number.

### Tickets:
 - E-139857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: NPU OpenVINO NPU plugin category: NPUW NPUW plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants