Skip to content

Commit

Permalink
Merge branch 'releases/2024/3' into late_init_rel
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrawins authored Jul 25, 2024
2 parents cad9cb9 + a769b33 commit e263472
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dependencies = [
"openvino_tokenizers~=2024.3.0.0"
"openvino_tokenizers~=2024.3.0.0.dev"
]

[tool.py-build-cmake.module]
Expand Down
29 changes: 29 additions & 0 deletions src/python/py_generate_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,33 @@ OptionalGenerationConfig update_config_from_kwargs(const OptionalGenerationConfi
return res_config;
}

ov::Any py_object_to_any(const py::object& py_obj);

bool py_object_is_any_map(const py::object& py_obj) {
if (!py::isinstance<py::dict>(py_obj)) {
return false;
}
auto dict = py::cast<py::dict>(py_obj);
return std::all_of(dict.begin(), dict.end(), [&](const std::pair<py::object::handle, py::object::handle>& elem) {
return py::isinstance<py::str>(elem.first);
});
}

ov::AnyMap py_object_to_any_map(const py::object& py_obj) {
OPENVINO_ASSERT(py_object_is_any_map(py_obj), "Unsupported attribute type.");
ov::AnyMap return_value = {};
for (auto& item : py::cast<py::dict>(py_obj)) {
std::string key = py::cast<std::string>(item.first);
py::object value = py::cast<py::object>(item.second);
if (py_object_is_any_map(value)) {
return_value[key] = py_object_to_any_map(value);
} else {
return_value[key] = py_object_to_any(value);
}
}
return return_value;
}

ov::Any py_object_to_any(const py::object& py_obj) {
// Python types
py::object float_32_type = py::module_::import("numpy").attr("float32");
Expand Down Expand Up @@ -213,6 +240,8 @@ ov::Any py_object_to_any(const py::object& py_obj) {
}

// OV types
} else if (py_object_is_any_map(py_obj)) {
return py_object_to_any_map(py_obj);
} else if (py::isinstance<ov::Any>(py_obj)) {
return py::cast<ov::Any>(py_obj);
} else if (py::isinstance<ov::element::Type>(py_obj)) {
Expand Down

0 comments on commit e263472

Please sign in to comment.