Skip to content

Commit

Permalink
Merge branch 'master' into issue#22949
Browse files Browse the repository at this point in the history
  • Loading branch information
rkazants authored Mar 30, 2024
2 parents 8ab4260 + 34ebb77 commit 5068c00
Show file tree
Hide file tree
Showing 35 changed files with 1,919 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void regmodule_properties(py::module m) {
.value("ECORE_ONLY", ov::hint::SchedulingCoreType::ECORE_ONLY);

py::enum_<ov::hint::ModelDistributionPolicy>(m_hint, "ModelDistributionPolicy", py::arithmetic())
.value("TENSOR_PARALLEL", ov::hint::ModelDistributionPolicy::TENSOR_PARALLEL);
.value("TENSOR_PARALLEL", ov::hint::ModelDistributionPolicy::TENSOR_PARALLEL)
.value("PIPELINE_PARALLEL", ov::hint::ModelDistributionPolicy::PIPELINE_PARALLEL);

py::enum_<ov::hint::ExecutionMode>(m_hint, "ExecutionMode", py::arithmetic())
.value("PERFORMANCE", ov::hint::ExecutionMode::PERFORMANCE)
Expand Down
28 changes: 28 additions & 0 deletions src/core/include/openvino/core/any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <map>
#include <memory>
#include <set>
#include <string>
#include <typeindex>
#include <typeinfo>
Expand Down Expand Up @@ -209,6 +210,18 @@ struct Read<std::vector<T, A>, typename std::enable_if<std::is_default_construct
}
};

template <typename K, typename C, typename A>
struct Read<std::set<K, C, A>, typename std::enable_if<std::is_default_constructible<K>::value>::type> {
void operator()(std::istream& is, std::set<K, C, A>& set) const {
while (is.good()) {
std::string str;
is >> str;
auto v = from_string<K>(str);
set.insert(std::move(v));
}
}
};

template <typename K, typename T, typename C, typename A>
struct Read<
std::map<K, T, C, A>,
Expand Down Expand Up @@ -343,6 +356,21 @@ struct Write<std::vector<T, A>> {
}
};

template <typename K, typename C, typename A>
struct Write<std::set<K, C, A>> {
void operator()(std::ostream& os, const std::set<K, C, A>& set) const {
if (!set.empty()) {
std::size_t i = 0;
for (auto&& v : set) {
os << to_string(v);
if (i < (set.size() - 1))
os << ' ';
++i;
}
}
}
};

template <typename K, typename T, typename C, typename A>
struct Write<std::map<K, T, C, A>> {
void operator()(std::ostream& os, const std::map<K, T, C, A>& map) const {
Expand Down
17 changes: 17 additions & 0 deletions src/core/tests/any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ TEST_F(AnyTests, AnyAsMapOfAnys) {
ASSERT_EQ(refMap["testParamString"].as<std::string>(), testString);
}

TEST_F(AnyTests, AnyAsSetOfAnys) {
std::set<std::string> refSet0;
std::set<int> refSet1;
refSet0.insert("test");
refSet1.insert(4);
Any s0 = refSet0;
Any s1 = refSet1;
bool isSet0 = s0.is<std::set<std::string>>();
bool isSet1 = s1.is<std::set<int>>();
ASSERT_TRUE(isSet0);
ASSERT_TRUE(isSet1);
auto testSet0 = s0.as<std::set<std::string>>();
auto testSet1 = s1.as<std::set<int>>();
ASSERT_NE(testSet0.count("test"), 0);
ASSERT_NE(testSet1.count(4), 0);
}

TEST_F(AnyTests, AnyAsMapOfMapOfAnys) {
std::map<std::string, Any> refMap1;
refMap1["testParamInt"] = 4;
Expand Down
42 changes: 41 additions & 1 deletion src/frontends/onnx/frontend/src/op/batch_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ ov::OutputVector batch_norm(const ov::frontend::onnx::Node& node) {
OPENVINO_THROW("Cannot create OpenVINO batch norm with unsupported number of inputs");
}
} // namespace set_1
/*
Opset 6 is skipped because there are no significant difference between opset1 and opset6.
Found difference is:
1. In Training, the computation of ReduceMean and ReduceVar uses float
to avoid overflow for float16 inputs.
*/

namespace set_7 {
// This version supports ONNX BatchNormalization-7 and BatchNormalization-9
Expand All @@ -71,8 +77,42 @@ ov::OutputVector batch_norm(const ov::frontend::onnx::Node& node) {

return {std::make_shared<v5::BatchNormInference>(x, scale, bias, mean, var, epsilon)};
}

} // namespace set_7
/*
Opset 9 is skipped because there are no significant difference between opset7 and opset9.
Found difference is:
1. removed -> spatial : int (default is 1)
If true, compute the mean and variance across per activation. If false, compute the mean and variance across
per feature over each mini-batch.
*/

namespace set_14 {
// This version supports ONNX BatchNormalization-14 BatchNormalization-15
ov::OutputVector batch_norm(const ov::frontend::onnx::Node& node) {
ov::OutputVector inputs{node.get_ov_inputs()};
auto x = inputs.at(0);
auto scale = inputs.at(1);
auto bias = inputs.at(2);
auto mean = inputs.at(3);
auto var = inputs.at(4);

double epsilon{node.get_attribute_value<double>("epsilon", 1e-5)};
int64_t training_mode{node.get_attribute_value<int64_t>("training_mode", 0)};

CHECK_VALID_NODE(node,
training_mode == false && node.get_outputs_size() == 1,
"Training mode of BatchNormalization is not supported.");
return {std::make_shared<v5::BatchNormInference>(x, scale, bias, mean, var, epsilon)};
}
} // namespace set_14
/*
Opset 15 is skipped because there are no significant difference between opset14 and opset15.
Found difference is:
1. In Training, the computation of ReduceMean and ReduceVar uses float
to avoid overflow for float16 inputs.
*/

} // namespace op
} // namespace onnx
} // namespace frontend
Expand Down
5 changes: 5 additions & 0 deletions src/frontends/onnx/frontend/src/op/batch_norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace set_7 {
ov::OutputVector batch_norm(const ov::frontend::onnx::Node& node);

} // namespace set_7

namespace set_14 {
ov::OutputVector batch_norm(const ov::frontend::onnx::Node& node);

} // namespace set_14
} // namespace op
} // namespace onnx
} // namespace frontend
Expand Down
1 change: 1 addition & 0 deletions src/frontends/onnx/frontend/src/ops_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("AveragePool", 1, average_pool);
REGISTER_OPERATOR("BatchNormalization", 1, batch_norm);
REGISTER_OPERATOR("BatchNormalization", 7, batch_norm);
REGISTER_OPERATOR("BatchNormalization", 14, batch_norm);
REGISTER_OPERATOR("BitShift", 1, bitshift);
REGISTER_OPERATOR("BitwiseAnd", 1, bitwise_and);
REGISTER_OPERATOR("BitwiseNot", 1, bitwise_not);
Expand Down
113 changes: 113 additions & 0 deletions src/frontends/onnx/tests/models/batchnorm_opset1.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
input: "s"
input: "bias"
input: "mean"
input: "var"
output: "y"
op_type: "BatchNormalization"
}
name: "test_batchnorm_example"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 2
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
}
}
}
}
input {
name: "s"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
input {
name: "bias"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
input {
name: "mean"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
input {
name: "var"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 2
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 1
}
113 changes: 113 additions & 0 deletions src/frontends/onnx/tests/models/batchnorm_opset14.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "x"
input: "s"
input: "bias"
input: "mean"
input: "var"
output: "y"
op_type: "BatchNormalization"
}
name: "test_batchnorm_example"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 2
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
}
}
}
}
input {
name: "s"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
input {
name: "bias"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
input {
name: "mean"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
input {
name: "var"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 2
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 14
}
Loading

0 comments on commit 5068c00

Please sign in to comment.