openvino icon indicating copy to clipboard operation
openvino copied to clipboard

[Good First Issue]: Enable CompiledModel set/get property()

Open almilosz opened this issue 9 months ago • 3 comments

Context

Node.js API is the newest binding of OpenVINO. The task is to expose 2 methods: CompiledModel::set_property() and CompiledModel::get_property(). C++ docs here

What needs to be done?

  • add methods on C++ side (src/bindings/js/node/src/compiled_model.cpp)
  • update TypeScript definition (src/bindings/js/node/lib/addon.ts)
  • create unit test for added functionality using Node.js Test Runner Tip: Before creating a new function to convert an argument, take a look at helper methods to see if it doesn't exist already

Example Pull Requests

  • https://github.com/openvinotoolkit/openvino/pull/22100
  • https://github.com/openvinotoolkit/openvino/pull/23743
  • https://github.com/openvinotoolkit/openvino/pull/24023

Resources

Contact points

@almilosz @vishniakov-nikolai

Ticket

134825

almilosz avatar May 06 '24 06:05 almilosz

.take

Aryan8912 avatar May 07 '24 05:05 Aryan8912

Thank you for looking into this issue! Please let us know if you have any questions or require any help.

github-actions[bot] avatar May 07 '24 05:05 github-actions[bot]

Hello @Aryan8912, there are currently three issues with open PRs assigned to you. Please finish them before picking more tasks.

p-wysocki avatar May 07 '24 16:05 p-wysocki

hello, Is it possible being assigned to this issue?

Plomo-02 avatar May 25 '24 18:05 Plomo-02

.take

Plomo-02 avatar May 25 '24 18:05 Plomo-02

Thank you for looking into this issue! Please let us know if you have any questions or require any help.

github-actions[bot] avatar May 25 '24 18:05 github-actions[bot]

hey @Plomo-02 do you need any help? will you have a time to continue work on this task?

mlukasze avatar Jun 10 '24 11:06 mlukasze

.take

hub-bla avatar Jul 26 '24 16:07 hub-bla

Thank you for looking into this issue! Please let us know if you have any questions or require any help.

github-actions[bot] avatar Jul 26 '24 16:07 github-actions[bot]

Hi @almilosz @vishniakov-nikolai, I have encountered an issue while testing the implementation of CompiledModel::set_property()

  Exception from src/inference/src/cpp/compiled_model.cpp:136:
  Exception from src/plugins/intel_cpu/src/compiled_model.h:39:
  Not Implemented:
  It's not possible to set property of an already compiled model. Set property to Core::compile_model during compilation

It seems like there is a template: https://github.com/openvinotoolkit/openvino/blob/3056b53056d6319666f3fc250bebefb0c4b1a91e/src/plugins/template/src/compiled_model.cpp#L83-L87

But only one plugin implements that: https://github.com/openvinotoolkit/openvino/blob/3056b53056d6319666f3fc250bebefb0c4b1a91e/src/plugins/auto_batch/src/compiled_model.cpp#L163-L175

Other have: https://github.com/openvinotoolkit/openvino/blob/3056b53056d6319666f3fc250bebefb0c4b1a91e/src/plugins/intel_cpu/src/compiled_model.h#L38-L41

My implementation so far:

Napi::Value CompiledModelWrap::set_property(const Napi::CallbackInfo &info) {
    Napi::Env env = info.Env();
    try{
        if (info.Length() != 1 || !info[0].IsObject()) {
            OPENVINO_THROW("Expected a single object argument for setting properties");
        }
        const auto properties = to_anyMap(env, info[0]);
        _compiled_model.set_property(properties);
    }catch (const std::exception& e) {
            reportError(env, e.what());
    }
    return env.Undefined();
}

My question

How should I test it?

hub-bla avatar Jul 27 '24 11:07 hub-bla

@hub-bla @mlukasze Is this still under development? If not can I take this up?

nashez avatar Jul 29 '24 12:07 nashez

Hi @nashez, the issue is still under development. I have everything implemented but this test for set_property(). I'm waiting for a response to my issue.

hub-bla avatar Jul 29 '24 12:07 hub-bla

Hi @hub-bla! Thanks for taking this issue. CompiledModel::set_property() can be tested in Python like this:

timeout = 10
cm = core.compile_model(model, "BATCH:CPU")
cm.set_property(props.auto_batch_timeout(timeout))
assert timeout == cm.get_property('AUTO_BATCH_TIMEOUT')

To do that in Node.js API you will have to expose ov::auto_batch_timeout additionally, which may require more work.
Alternatively, you can wait as we look into the reasons why the option below is not working:

cm.set_property({'AUTO_BATCH_TIMEOUT': 1})

Let me know what you decide to do. If you have any questions, don't hesitate to ask them. You can reach me on Discord _almilosz and ask directly.

Greetings from Poznań, Alicja

almilosz avatar Jul 30 '24 08:07 almilosz

@almilosz I found that if you change 1 in cm.set_property({'AUTO_BATCH_TIMEOUT': 1}) to be a string it doesn't throw error so I guess there is a problem with converting this variable under the hood.

Is it enough reason for not exposing auto_batch_timeout in this issue? Should I also create separate file for testing compiled_model?

Thank you for your hint!

Poznań? Never heard of it ;) Must be like a GitHub project - constantly under 'maintenance' with occasional surprise updates.

hub-bla avatar Jul 30 '24 10:07 hub-bla

Yes, please create a test like this in a new file compiled_model.test.js file Exposing properties will be a separate issue :)

almilosz avatar Jul 30 '24 11:07 almilosz

I looked into the problem with conversion and I think I found the reason why. https://github.com/openvinotoolkit/openvino/blob/dd2f6141b0e162789332bfccc7dfaa90d6584d2a/src/bindings/js/node/src/helper.cpp#L153-L180 js_to_cpp which is used in to_anyMap returns int32_t But in auto-batch CompiledModel::set_property we can see it tries to convert it as uint32_t https://github.com/openvinotoolkit/openvino/blob/d253f4fd89c1a77a68cac0fa3d97e627a8ed4467/src/plugins/auto_batch/src/compiled_model.cpp#L163-L175 and .as<std::uint32_t>() is the operation that fails https://github.com/openvinotoolkit/openvino/blob/d253f4fd89c1a77a68cac0fa3d97e627a8ed4467/src/core/include/openvino/core/any.hpp#L850-L865

hub-bla avatar Jul 30 '24 12:07 hub-bla