Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/job_cxx_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,19 @@ jobs:
${{ env.SOURCE_COMMAND }} ${{ env.SETUPVARS }}
${{ env.INSTALL_TEST_DIR }}/paddle_tests --gtest_filter="PaddleFuzzyOpTest*" --gtest_print_time=1 --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-PaddleFuzzyOpTests.xml

- name: ONNX frontend tests
- name: ONNX frontend tests (GraphIterator default)
if: ${{ fromJSON(inputs.affected-components).ONNX_FE.test && runner.arch != 'ARM64' }} # Ticket for macOS ARM64: 122663, for Linux ARM64: 126280, 153161
run: |
${{ env.SOURCE_COMMAND }} ${{ env.SETUPVARS }}
${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend.xml
${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend-GraphIteratorEnabled.xml

- name: ONNX frontend tests ONNX_ITERATOR=disabled (legacy implementation)
if: ${{ fromJSON(inputs.affected-components).ONNX_FE.test && runner.arch != 'ARM64' }} # Ticket for macOS ARM64: 122663, for Linux ARM64: 126280, 153161
env:
ONNX_ITERATOR: "0"
run: |
${{ env.SOURCE_COMMAND }} ${{ env.SETUPVARS }}
${{ env.INSTALL_TEST_DIR }}/ov_onnx_frontend_tests --gtest_print_time=1 --gtest_filter=-*IE_GPU* --gtest_output=xml:${{ env.INSTALL_TEST_DIR }}/TEST-ONNXFrontend-GraphIteratorDisabled.xml

- name: TensorFlow Common frontend tests
if: fromJSON(inputs.affected-components).TF_FE.test ||
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/job_python_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,19 @@ jobs:
run: |
# Skip test_onnx/test_zoo_models and test_onnx/test_backend due to long execution time - ONNX Model Zoo tests are run separately
python3 -m pytest -sv ${INSTALL_TEST_DIR}/onnx -k 'not cuda' \
--junitxml=${INSTALL_TEST_DIR}/TEST-onnx_frontend.xml \
--junitxml=${INSTALL_TEST_DIR}/TEST-onnx_frontend.graph_iterator_enabled.xml \
--ignore=${INSTALL_TEST_DIR}/onnx/test_python/test_zoo_models.py

- name: Python ONNX operators tests ONNX_ITERATOR=disabled (legacy implementation)
if: (fromJSON(inputs.affected-components).Python_API.test ||
fromJSON(inputs.affected-components).ONNX_FE.test) &&
runner.arch != 'ARM64' # Ticket: 123325
env:
ONNX_ITERATOR: "0"
run: |
# Skip test_onnx/test_zoo_models and test_onnx/test_backend due to long execution time - ONNX Model Zoo tests are run separately
python3 -m pytest -sv ${INSTALL_TEST_DIR}/onnx -k 'not cuda' \
--junitxml=${INSTALL_TEST_DIR}/TEST-onnx_frontend.graph_iterator_disabled.xml \
--ignore=${INSTALL_TEST_DIR}/onnx/test_python/test_zoo_models.py

- name: OVC unit tests
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/onnx/frontend/src/core/decoder_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <onnx/onnx_pb.h>

#include <fstream>
#include <openvino/frontend/graph_iterator.hpp>

#include "graph_iterator_proto.hpp"
#include "openvino/frontend/graph_iterator.hpp"
#include "openvino/frontend/onnx/graph_iterator.hpp"
#include "openvino/util/wstring_convert_util.hpp"

Expand Down
3 changes: 1 addition & 2 deletions src/frontends/onnx/frontend/src/core/decoder_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#pragma once
#include <onnx/onnx_pb.h>

#include <openvino/frontend/graph_iterator.hpp>

#include "graph_iterator_proto.hpp"
#include "openvino/frontend/graph_iterator.hpp"
#include "openvino/frontend/onnx/decoder.hpp"
#include "openvino/frontend/onnx/graph_iterator.hpp"
#include "openvino/util/wstring_convert_util.hpp"
Expand Down
13 changes: 9 additions & 4 deletions src/frontends/onnx/frontend/src/core/graph_iterator_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,12 @@ GraphIteratorProto::GraphIteratorProto(GraphIteratorProto* parent, const GraphPr
m_model = parent->m_model;
}

void GraphIteratorProto::initialize(const std::string& path) {
m_model_dir = std::make_shared<std::string>(ov::util::get_directory(path).string());
void GraphIteratorProto::initialize_from_path(const std::filesystem::path& path) {
m_model_dir = std::make_shared<std::string>(ov::util::path_to_string(ov::util::get_directory(path)));
const auto path_string = ov::util::path_to_string(path);
try {
std::ifstream model_file(path, std::ios::binary | std::ios::in);
FRONT_END_GENERAL_CHECK(model_file && model_file.is_open(), "Could not open the file: \"", path, "\"");
FRONT_END_GENERAL_CHECK(model_file && model_file.is_open(), "Could not open the file: \"", path_string, "\"");

m_model = std::make_shared<ModelProto>();
FRONT_END_GENERAL_CHECK(m_model->ParseFromIstream(&model_file), "Model can't be parsed");
Expand All @@ -337,9 +338,13 @@ void GraphIteratorProto::initialize(const std::string& path) {
}
}

void GraphIteratorProto::initialize(const std::string& path) {
initialize_from_path(ov::util::make_path(path));
}

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
void GraphIteratorProto::initialize(const std::wstring& path) {
initialize(ov::util::wstring_to_string(path));
initialize_from_path(ov::util::make_path(path));
}
#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#pragma once
#include <onnx/onnx_pb.h>

#include <openvino/frontend/graph_iterator.hpp>
#include <filesystem>

#include "openvino/frontend/graph_iterator.hpp"
#include "openvino/frontend/onnx/decoder.hpp"
#include "openvino/frontend/onnx/graph_iterator.hpp"
#include "openvino/util/file_util.hpp"
Expand Down Expand Up @@ -150,6 +151,9 @@ class GraphIteratorProto : public ov::frontend::onnx::GraphIterator {
/// \param name Name of tensor
/// \param owner Returns real owner of the tensor
std::shared_ptr<DecoderProtoTensor> get_tensor(const std::string& name, GraphIteratorProto** owner);

private:
void initialize_from_path(const std::filesystem::path& path);
};

} // namespace onnx
Expand Down
27 changes: 26 additions & 1 deletion src/frontends/onnx/frontend/src/core/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,32 @@ Subgraph Node::Impl::get_attribute_value(const std::string& name) const {

template <>
ov::Any Node::get_attribute_value(const std::string& name) const {
return get_attribute(name).get_any();
if (m_pimpl != nullptr) {
return get_attribute(name).get_any();
} else if (m_decoder != nullptr) {
if (!m_decoder->has_attribute(name)) {
throw error::node::UnknownAttribute{this->get_name(), name};
}
auto attribute_value = m_decoder->get_attribute(name);
// We upcast decoder-provided floats here to align the behavior of OpExtension with the legacy approach and
// keep both code paths identical.
if (attribute_value.is<float>()) {
return static_cast<double>(attribute_value.as<float>());
} else if (attribute_value.is<std::vector<float>>()) {
const auto& float_values = attribute_value.as<std::vector<float>>();
std::vector<double> double_values;
double_values.reserve(float_values.size());
std::transform(float_values.begin(),
float_values.end(),
std::back_inserter(double_values),
[](float v) -> double {
return v;
});
return double_values;
}
return attribute_value;
}
FRONT_END_NOT_IMPLEMENTED(get_attribute_value);
}

template <>
Expand Down
54 changes: 53 additions & 1 deletion src/frontends/onnx/frontend/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
# include <google/protobuf/stubs/logging.h>
#endif

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <string>

#include "core/graph_iterator_proto.hpp"
#include "input_model.hpp"
Expand Down Expand Up @@ -48,6 +52,54 @@ using ::ONNX_NAMESPACE::ModelProto;
using ::ONNX_NAMESPACE::Version;

namespace {

bool is_graph_iterator_enabled() {
const char* env_value = std::getenv("ONNX_ITERATOR");
if (env_value == nullptr) {
return true; // Enabled by default
}

std::string value(env_value);
// Remove whitespace
value.erase(std::remove_if(value.begin(),
value.end(),
[](unsigned char ch) {
return std::isspace(ch);
}),
value.end());
// Convert to lowercase
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char ch) {
return static_cast<char>(std::tolower(ch));
});

static const std::unordered_map<std::string, bool> valid_values = {{"1", true},
{"true", true},
{"on", true},
{"enable", true},
{"0", false},
{"false", false},
{"off", false},
{"disable", false}};

auto it = valid_values.find(value);
if (it != valid_values.end()) {
if (!it->second) {
OPENVINO_WARN(
"DEPRECATED: Disabling ONNX graph iterator via ONNX_ITERATOR environment variable is deprecated and "
"will be removed in a future release. The graph iterator will become mandatory.");
}
return it->second;
}

// Unknown value - print error and default to enabled
OPENVINO_WARN("Unknown value for ONNX_ITERATOR environment variable: '",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it might actually be better for the user if we exit here (instead of warning and continuing).

Rationale: easy to miss a warning - especially if you don't know what to look for.

env_value,
"'. "
"Expected 1 (enable) or 0 (disable). "
"Defaulting to enabled.");
return true;
}

// !!! Experimental feature, it may be changed or removed in the future !!!
void enumerate_constants(const std::shared_ptr<ov::Model>& model) {
const auto& operations = model->get_ordered_ops();
Expand Down Expand Up @@ -84,7 +136,7 @@ ONNX_FRONTEND_C_API void* get_front_end_data() {
}

ov::frontend::InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& variants) const {
const bool gi_enabled = std::getenv("ONNX_ITERATOR") != nullptr;
const bool gi_enabled = is_graph_iterator_enabled();
if (variants.empty()) {
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontends/onnx/frontend/src/input_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#pragma once

#include <editor.hpp>
#include <fstream>
#include <openvino/frontend/input_model.hpp>

#include "core/place.hpp"
#include "core/tensor.hpp"
#include "editor.hpp"
#include "openvino/frontend/extension/holder.hpp"
#include "openvino/frontend/input_model.hpp"
#include "openvino/frontend/onnx/graph_iterator.hpp"

using ::ONNX_NAMESPACE::ModelProto;
Expand Down
7 changes: 4 additions & 3 deletions src/frontends/onnx/frontend/src/node_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <core/node.hpp>
#include <openvino/frontend/onnx/node_context.hpp>
#include <utils/common.hpp>
#include "openvino/frontend/onnx/node_context.hpp"

#include "core/node.hpp"
#include "utils/common.hpp"

ov::frontend::onnx::NodeContext::NodeContext(const ov::frontend::onnx::Node& context)
: ov::frontend::NodeContext(context.op_type()),
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/onnx/frontend/src/place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "place.hpp"

#include <openvino/frontend/exception.hpp>
#include "openvino/frontend/exception.hpp"

using namespace ov;
using namespace ov::frontend::onnx;
Expand Down
5 changes: 3 additions & 2 deletions src/frontends/onnx/frontend/src/place.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

#pragma once

#include <editor.hpp>
#include <memory>
#include <openvino/frontend/place.hpp>
#include <sstream>

#include "editor.hpp"
#include "openvino/frontend/place.hpp"

namespace ov {
namespace frontend {
namespace onnx {
Expand Down
4 changes: 2 additions & 2 deletions src/frontends/onnx/tests/graph_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <onnx/onnx_pb.h>

#include <fstream>
#include <openvino/frontend/graph_iterator.hpp>
#include <openvino/openvino.hpp>

#include "../frontend/src/core/graph_iterator_proto.hpp"
#include "load_from.hpp"
#include "onnx_utils.hpp"
#include "openvino/frontend/graph_iterator.hpp"
#include "openvino/openvino.hpp"
#include "utils.hpp"

using ::ONNX_NAMESPACE::ModelProto;
Expand Down
Loading
Loading