Skip to content

Commit 112551d

Browse files
akuporosCopilot
andauthored
[PyOV] fix ov::hint::model (#30363)
### Details: - Added conversion from ov::Any to py::object and back in order to support `ov::hint::model` property. - Added one more method `get_property` method for Core - Fix error message ### Tickets: - CVS-166766 --------- Co-authored-by: Copilot <[email protected]>
1 parent 7ddab17 commit 112551d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/bindings/python/src/pyopenvino/core/core.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,31 @@ void regclass_Core(py::module m) {
9191
:type property: typing.Tuple[str, typing.Any]
9292
)");
9393

94+
cls.def(
95+
"get_property",
96+
[](ov::Core& self,
97+
const std::string& device_name,
98+
const std::string& name,
99+
const std::map<std::string, py::object>& arguments) -> py::object {
100+
std::map<std::string, ov::Any> _properties = Common::utils::properties_to_any_map(arguments);
101+
return Common::utils::from_ov_any(self.get_property(device_name, name, _properties));
102+
},
103+
py::arg("device_name"),
104+
py::arg("name"),
105+
py::arg("arguments"),
106+
R"(
107+
Gets properties dedicated to device behaviour.
108+
109+
:param device_name: A name of a device to get a properties value.
110+
:type device_name: str
111+
:param name: Property or name of Property.
112+
:type name: str
113+
:param arguments: Additional arguments to get a property.
114+
:type arguments: dict[str, typing.Any]
115+
:return: Extracted information from property.
116+
:rtype: typing.Any
117+
)");
118+
94119
cls.def(
95120
"get_property",
96121
[](ov::Core& self, const std::string& device_name, const std::string& property) -> py::object {

src/bindings/python/src/pyopenvino/utils/utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ py::object from_ov_any(const ov::Any& any) {
237237
return py::cast(any.as<ov::hint::SchedulingCoreType>());
238238
} else if (any.is<std::set<ov::hint::ModelDistributionPolicy>>()) {
239239
return py::cast(any.as<std::set<ov::hint::ModelDistributionPolicy>>());
240+
} else if (any.is<std::shared_ptr<const ov::Model>>()) {
241+
auto model = std::const_pointer_cast<ov::Model>(any.as<std::shared_ptr<const ov::Model>>());
242+
return py::cast(model);
240243
} else if (any.is<ov::hint::ExecutionMode>()) {
241244
return py::cast(any.as<ov::hint::ExecutionMode>());
242245
} else if (any.is<ov::log::Level>()) {
@@ -316,6 +319,9 @@ std::map<std::string, ov::Any> properties_to_any_map(const std::map<std::string,
316319
};
317320
ov::EncryptionCallbacks encryption_callbacks{encrypt_func, decrypt_func};
318321
properties_to_cpp[property.first] = encryption_callbacks;
322+
} else if (property.first == ov::hint::model.name()) {
323+
auto model = Common::utils::convert_to_model(property.second);
324+
properties_to_cpp[property.first] = std::static_pointer_cast<const ov::Model>(model);
319325
} else {
320326
properties_to_cpp[property.first] = Common::utils::py_object_to_any(property.second);
321327
}

src/plugins/intel_gpu/src/plugin/plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ uint32_t Plugin::get_optimal_batch_size(const ov::AnyMap& options) const {
815815
try {
816816
model = model_param->second.as<std::shared_ptr<const ov::Model>>();
817817
} catch (...) {
818-
OPENVINO_THROW("[OPTIMAL_BATCH_SIZE] ov::hint::model should be std::shared_ptr<ov::Model> type");
818+
OPENVINO_THROW("[OPTIMAL_BATCH_SIZE] ov::hint::model should be std::shared_ptr<const ov::Model> type");
819819
}
820820
GPU_DEBUG_INFO << "DEVICE_INFO:"
821821
<< "gfx_version.major, " << device_info.gfx_ver.major

0 commit comments

Comments
 (0)