Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into mitruska/stft_cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
mitruska committed Dec 13, 2024
2 parents 5947a39 + f1cba31 commit 0f1ea39
Show file tree
Hide file tree
Showing 33 changed files with 972 additions and 294 deletions.
2 changes: 1 addition & 1 deletion docs/articles_en/documentation/openvino-extensibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The first part is required for inference. The second part is required for succes
Definition of Operation Semantics
#################################

If the custom operation can be mathematically represented as a combination of exiting OpenVINO operations and such decomposition gives desired performance, then low-level operation implementation is not required. Refer to the latest OpenVINO operation set, when deciding feasibility of such decomposition. You can use any valid combination of exiting operations. The next section of this document describes the way to map a custom operation.
If the custom operation can be mathematically represented as a combination of existing OpenVINO operations and such decomposition gives desired performance, then low-level operation implementation is not required. Refer to the latest OpenVINO operation set, when deciding feasibility of such decomposition. You can use any valid combination of existing operations. The next section of this document describes the way to map a custom operation.

If such decomposition is not possible or appears too bulky with a large number of constituent operations that do not perform well, then a new class for the custom operation should be implemented, as described in the :doc:`Custom Operation Guide <openvino-extensibility/custom-openvino-operations>`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ make sure to :doc:`install OpenVINO with GenAI <../../get-started/install-openvi
image_write("baseline.bmp", image)
For more information, refer to the
`Python sample <https://github.com/openvinotoolkit/openvino.genai/tree/master/samples/python/text2image/>`__
`Python sample <https://github.com/openvinotoolkit/openvino.genai/tree/master/samples/python/image_generation>`__

.. tab-item:: C++
:sync: cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void regclass_graph_PreProcessSteps(py::module m) {
:param pads_end: Number of elements matches the number of indices in data attribute. Specifies the number of padding elements at the ending of each axis.
:type pads_end: 1D tensor of type T_INT.
:param value: All new elements are populated with this value or with 0 if input not provided. Shouldn’t be set for other pad_mode values.
:type value: scalar tensor of type T.
:type value: scalar tensor of type T.
:param mode: pad_mode specifies the method used to generate new element values.
:type mode: string
:return: Reference to itself, allows chaining of calls in client's code in a builder-like manner.
Expand Down Expand Up @@ -219,7 +219,7 @@ static void regclass_graph_PreProcessSteps(py::module m) {
:param pads_end: Number of elements matches the number of indices in data attribute. Specifies the number of padding elements at the ending of each axis.
:type pads_end: 1D tensor of type T_INT.
:param value: All new elements are populated with this value or with 0 if input not provided. Shouldn’t be set for other pad_mode values.
:type value: scalar tensor of type T.
:type value: scalar tensor of type T.
:param mode: pad_mode specifies the method used to generate new element values.
:type mode: string
:return: Reference to itself, allows chaining of calls in client's code in a builder-like manner.
Expand Down Expand Up @@ -308,7 +308,8 @@ static void regclass_graph_InputTensorInfo(py::module m) {
},
py::arg("layout"),
R"(
Set layout for input tensor info
Set layout for input tensor info
:param layout: layout to be set
:type layout: Union[str, openvino.runtime.Layout]
)");
Expand Down Expand Up @@ -422,7 +423,8 @@ static void regclass_graph_OutputTensorInfo(py::module m) {
},
py::arg("layout"),
R"(
Set layout for output tensor info
Set layout for output tensor info
:param layout: layout to be set
:type layout: Union[str, openvino.runtime.Layout]
)");
Expand Down Expand Up @@ -475,7 +477,8 @@ static void regclass_graph_OutputModelInfo(py::module m) {
},
py::arg("layout"),
R"(
Set layout for output model info
Set layout for output model info
:param layout: layout to be set
:type layout: Union[str, openvino.runtime.Layout]
)");
Expand Down
3 changes: 2 additions & 1 deletion src/bindings/python/tests/test_runtime/test_input_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def test_input_get_source_output(device):
net_input = compiled_model.output(0)
input_node = net_input.get_node().inputs()[0]
name = input_node.get_source_output().get_node().get_friendly_name()
assert name == "relu"
# Expected ReLu node name can be changed if conversion precision applied (new Convert node added)
assert name in ("relu", "relu.0")


def test_input_get_tensor(device):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "itt.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/op/ops.hpp"
#include "openvino/pass/constant_folding.hpp"
#include "openvino/pass/manager.hpp"
Expand Down Expand Up @@ -207,7 +208,8 @@ bool convert_function_precision(const std::shared_ptr<Model>& f,
bool is_changed,
bool is_subgraph,
bool convert_input_output_precision,
bool store_original_precision_as_rt_attribute) {
bool store_original_precision_as_rt_attribute,
bool names_compatibility_mode) {
bool is_output_precision_changed = false;

ov::element::TypeVector orig_result_types;
Expand Down Expand Up @@ -276,7 +278,8 @@ bool convert_function_precision(const std::shared_ptr<Model>& f,
is_changed || is_output_precision_changed,
true,
true,
store_original_precision_as_rt_attribute) ||
store_original_precision_as_rt_attribute,
names_compatibility_mode) ||
is_changed;
}
}
Expand Down Expand Up @@ -324,18 +327,21 @@ bool convert_function_precision(const std::shared_ptr<Model>& f,
if (result->get_input_element_type(0) != orig_result_types[i]) {
auto result_input = result->input_value(0);
const auto convert = std::make_shared<ov::op::v0::Convert>(result_input, orig_result_types[i]);
if (result_input.get_node()->get_output_size() > 1) {
convert->set_friendly_name(result_input.get_node()->get_friendly_name() + "." +
std::to_string(result_input.get_index()));

auto convert_f_name = result_input.get_node()->get_friendly_name();
if (names_compatibility_mode) {
if (result_input.get_node()->get_output_size() > 1) {
convert_f_name += '.' + std::to_string(result_input.get_index());
} else {
result_input.get_node()->set_friendly_name("");
}

convert->get_output_tensor(0).set_names(result_input.get_names());
} else {
convert->set_friendly_name(result_input.get_node()->get_friendly_name());
result_input.get_node()->set_friendly_name("");
convert_f_name += '.' + std::to_string(result_input.get_index());
}
convert->set_friendly_name(convert_f_name);

auto& convert_output_tensor = convert->get_output_tensor(0);
convert_output_tensor.set_names(result_input.get_names());

result_input.set_names({});
result->input(0).replace_source_output(convert->output(0));
result->revalidate_and_infer_types();
}
Expand All @@ -358,6 +364,8 @@ bool convert_precision(ov::pass::PassBase& pass,
// changing precision we need to understand which Constant consumers belongs
// to the current ov::Model
std::unordered_map<const ov::Node*, std::vector<Input<Node>>> const_to_internal_output;

const auto names_compatibility_mode = f->has_rt_info("version") && f->get_rt_info<int64_t>("version") < 11;
return convert_function_precision(f,
type_to_fuse,
type_to_extend,
Expand All @@ -368,7 +376,8 @@ bool convert_precision(ov::pass::PassBase& pass,
false,
false,
convert_input_output_precision,
store_original_precision_as_rt_attribute);
store_original_precision_as_rt_attribute,
names_compatibility_mode);
}

using precisions_set_t = std::unordered_set<ov::element::Type_t, EnumClassHash>;
Expand Down Expand Up @@ -1405,6 +1414,13 @@ bool fuse_type_to_constant(const std::shared_ptr<ov::Node>& node,
new_const->validate_and_infer_types();
new_const->set_friendly_name(constant->get_friendly_name());
ov::copy_runtime_info(constant, new_const);

const auto& rt_info = node->get_rt_info();
auto weightless_caching_attr = rt_info.find(ov::WeightlessCacheAttribute::get_type_info_static());
if (weightless_caching_attr != rt_info.end()) {
new_const->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] =
weightless_caching_attr->second;
}
return true;
}
return false;
Expand Down
57 changes: 51 additions & 6 deletions src/common/transformations/tests/utils/convert_precision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/core/model.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/opsets/opset1.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/opsets/opset15.hpp"
Expand Down Expand Up @@ -2196,8 +2197,9 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsForParameterAndResult)
auto param_1 = make_shared<opset10::Parameter>(element::f64, Shape{3});
auto converted_param = make_shared<opset10::Convert>(param_1, element::f32);
auto sin = make_shared<opset10::Sin>(converted_param);
sin->get_output_tensor(0).add_names({"sine:0"});
auto converted_sin = make_shared<opset10::Convert>(sin, element::f64);
converted_sin->get_output_tensor(0).add_names({"sine:0"});
converted_sin->set_friendly_name("sine.0");
auto result_sin = make_shared<opset10::Result>(converted_sin);
model_ref = make_shared<Model>(result_sin, ParameterVector{param_1});
}
Expand All @@ -2207,7 +2209,7 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsForParameterAndResult)
ASSERT_TRUE(result.valid) << result.message;

const auto& results = model->get_results();
ASSERT_EQ("sine", results[0]->get_input_node_ptr(0)->get_friendly_name());
ASSERT_EQ("sine.0", results[0]->get_input_node_ptr(0)->get_friendly_name());
}

TEST(TransformationTests, ConvertPrecisionExplicitConvertsMultiParam) {
Expand Down Expand Up @@ -2271,8 +2273,8 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsMultiParam) {
auto converted_mul = make_shared<opset10::Convert>(mul, element::f64);
auto sin = make_shared<opset10::Sin>(convert_1);

converted_add->get_output_tensor(0).add_names({"add:0"});
converted_mul->get_output_tensor(0).add_names({"mul:0"});
add->get_output_tensor(0).add_names({"add:0"});
mul->get_output_tensor(0).add_names({"mul:0"});
sin->get_output_tensor(0).add_names({"sine:0"});

auto result_add = make_shared<opset10::Result>(converted_add);
Expand All @@ -2288,8 +2290,8 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsMultiParam) {
ASSERT_TRUE(result.valid) << result.message;

const auto& results = model->get_results();
ASSERT_EQ("add", results[0]->get_input_node_ptr(0)->get_friendly_name());
ASSERT_EQ("mul", results[1]->get_input_node_ptr(0)->get_friendly_name());
ASSERT_EQ("add.0", results[0]->get_input_node_ptr(0)->get_friendly_name());
ASSERT_EQ("mul.0", results[1]->get_input_node_ptr(0)->get_friendly_name());
ASSERT_EQ("sine", results[2]->get_input_node_ptr(0)->get_friendly_name());
}

Expand All @@ -2305,6 +2307,8 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsSingleNodeMultipleOutp
split->get_output_tensor(1).add_names({"split:1"});
split->get_output_tensor(2).add_names({"split:2"});
model = make_shared<Model>(split->outputs(), ParameterVector{param_1});
// set version 10 to use names compatibility mode
model->get_rt_info()["version"] = static_cast<int64_t>(10);

type_to_fuse_map empty_type_to_fuse_map = {};
bool keep_precision_sensitive_in_fp32 = false;
Expand All @@ -2321,6 +2325,9 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsSingleNodeMultipleOutp
auto convert_1 = make_shared<opset10::Convert>(param_1, element::f32);
auto axis = opset10::Constant::create(element::i32, Shape{}, {0});
auto split = make_shared<opset10::Split>(convert_1, axis, 3);
split->get_output_tensor(0).add_names({"split:0"});
split->get_output_tensor(1).add_names({"split:1"});
split->get_output_tensor(2).add_names({"split:2"});

auto convert_split_0 = make_shared<opset10::Convert>(split->output(0), element::f64);
auto convert_split_1 = make_shared<opset10::Convert>(split->output(1), element::f64);
Expand Down Expand Up @@ -2389,6 +2396,8 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsMultiSubgraphs) {
result.get_node()->set_friendly_name("if_result");
result.add_names({"if_result:0"});
model = make_shared<Model>(OutputVector{result}, ParameterVector{cond, param_1, param_2});
// set version 10 to use names compatibility mode
model->get_rt_info()["version"] = static_cast<int64_t>(10);

type_to_fuse_map empty_type_to_fuse_map = {};
bool keep_precision_sensitive_in_fp32 = false;
Expand Down Expand Up @@ -2442,6 +2451,7 @@ TEST(TransformationTests, ConvertPrecisionExplicitConvertsMultiSubgraphs) {
if_op->set_input(convert_1, param_1_then, param_1_else);
if_op->set_input(convert_2, param_2_then, param_2_else);
auto result = if_op->set_output(result_then, result_else);
result.add_names({"if_result:0"});
auto converted_result = make_shared<opset10::Convert>(result, element::f64);
converted_result->get_output_tensor(0).add_names({"if_result:0"});

Expand Down Expand Up @@ -2702,3 +2712,38 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_orig_types
FunctionsComparator::Result result = func_comparator(model_ref, model);
ASSERT_TRUE(result.valid) << result.message;
}

TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_weightless_cache_info_as_rt_attribute) {
pass::Manager manager;

auto some_value = opset10::Constant::create(element::f32, Shape{1}, {2});
auto& node_rt_info = some_value->get_rt_info();
ov::WeightlessCacheAttribute attr(element::f32.size(), 0, element::f32);
node_rt_info[ov::WeightlessCacheAttribute::get_type_info_static()] = attr;

ov::ParameterVector inputParams;
ov::ResultVector results;
results.push_back(std::make_shared<ov::op::v0::Result>(some_value->output(0)));
auto model = std::make_shared<ov::Model>(results, inputParams);

type_to_fuse_map empty_type_to_fuse_map = {};
bool keep_precision_sensitive_in_fp32 = false;
bool convert_input_output_precision = false;
bool store_original_precision_as_rt_attribute = true;
manager.register_pass<pass::ConvertPrecision>(precisions_map{{element::f32, element::f16}},
empty_type_to_fuse_map,
keep_precision_sensitive_in_fp32,
convert_input_output_precision,
store_original_precision_as_rt_attribute);
manager.run_passes(model);

const auto& ops = model->get_ops();
auto it = std::find_if(ops.begin(), ops.end(), [](const std::shared_ptr<Node>& node) {
return ov::op::util::is_constant(node);
});

ASSERT_TRUE(it != ops.end());
const auto& new_rt_info = (*it)->get_rt_info();
auto weightless_caching_attr_it = new_rt_info.find(ov::WeightlessCacheAttribute::get_type_info_static());
ASSERT_TRUE(weightless_caching_attr_it != new_rt_info.end());
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "openvino/core/core_visibility.hpp"
#include "openvino/core/node.hpp"
#include "openvino/core/runtime_attribute.hpp"

namespace ov {
Expand All @@ -25,14 +26,16 @@ class OPENVINO_API WeightlessCacheAttribute : public RuntimeAttribute {

WeightlessCacheAttribute() = delete;

WeightlessCacheAttribute(size_t original_size, size_t bin_offset)
WeightlessCacheAttribute(size_t original_size, size_t bin_offset, ov::element::Type original_dtype)
: original_size(original_size),
bin_offset(bin_offset) {}
bin_offset(bin_offset),
original_dtype(original_dtype) {}

bool is_copyable() const override;

size_t original_size;
size_t bin_offset;
ov::element::Type original_dtype;
};

} // namespace ov
Loading

0 comments on commit 0f1ea39

Please sign in to comment.