Skip to content

Commit

Permalink
Deprecate old ONNX API (#18587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Bencer authored Jul 18, 2023
1 parent ea84e73 commit d363660
Show file tree
Hide file tree
Showing 314 changed files with 1,038 additions and 39 deletions.
9 changes: 7 additions & 2 deletions src/core/template_extension/old/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
#ifdef OPENVINO_ONNX_FRONTEND_ENABLED
# include <onnx_import/onnx_utils.hpp>
#endif

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "openvino/core/deprecated.hpp"

using namespace TemplateExtension;

//! [extension:ctor]
Extension::Extension() {
#ifdef OPENVINO_ONNX_FRONTEND_ENABLED
OPENVINO_SUPPRESS_DEPRECATED_START
ngraph::onnx_import::register_operator(Operation::get_type_info_static().name,
1,
"custom_domain",
Expand All @@ -43,18 +45,21 @@ Extension::Extension() {
return {std::make_shared<FFTOp>(ng_inputs.at(0), inverse)};
});
# endif
OPENVINO_SUPPRESS_DEPRECATED_END
#endif
}
//! [extension:ctor]

//! [extension:dtor]
Extension::~Extension() {
#ifdef OPENVINO_ONNX_FRONTEND_ENABLED
OPENVINO_SUPPRESS_DEPRECATED_START
ngraph::onnx_import::unregister_operator(Operation::get_type_info_static().name, 1, "custom_domain");
# ifdef OPENCV_IMPORT_ENABLED
ngraph::onnx_import::unregister_operator(FFTOp::get_type_info_static().name, 1, "custom_domain");
# endif // OPENCV_IMPORT_ENABLED
#endif // OPENVINO_ONNX_FRONTEND_ENABLED
OPENVINO_SUPPRESS_DEPRECATED_END
#endif // OPENVINO_ONNX_FRONTEND_ENABLED
}
//! [extension:dtor]

Expand Down
15 changes: 14 additions & 1 deletion src/frontends/onnx/frontend/include/onnx_import/core/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

#pragma once

#if !defined(IN_OV_COMPONENT) && !defined(NGRAPH_LEGACY_HEADER_INCLUDED)
# define NGRAPH_LEGACY_HEADER_INCLUDED
# ifdef _MSC_VER
# pragma message( \
"The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# else
# warning("The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# endif
#endif

#include <cstddef>
#include <string>

#include "ngraph/deprecated.hpp"
#include "ngraph/except.hpp"
#include "ngraph/node.hpp"
#include "ngraph/op/constant.hpp"
Expand Down Expand Up @@ -39,7 +50,7 @@ class Tensor;
class SparseTensor;
class Attribute;

class ONNX_IMPORTER_API Node {
class NGRAPH_API_DEPRECATED ONNX_IMPORTER_API Node {
public:
Node() = delete;
// TODO: hide this ctor since it uses protobufs generated structures
Expand Down Expand Up @@ -282,9 +293,11 @@ ONNX_IMPORTER_API std::shared_ptr<ov::op::v0::Constant> Node::get_attribute_as_c
int64_t default_value,
element::Type type) const;

OPENVINO_SUPPRESS_DEPRECATED_START
inline std::ostream& operator<<(std::ostream& outs, const Node& node) {
return (outs << "<Node(" << node.op_type() << "): " << node.get_description() << ">");
}
OPENVINO_SUPPRESS_DEPRECATED_END

} // namespace onnx_import

Expand Down
22 changes: 15 additions & 7 deletions src/frontends/onnx/frontend/include/onnx_import/core/null_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@

#pragma once

#if !defined(IN_OV_COMPONENT) && !defined(NGRAPH_LEGACY_HEADER_INCLUDED)
# define NGRAPH_LEGACY_HEADER_INCLUDED
# ifdef _MSC_VER
# pragma message( \
"The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# else
# warning("The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# endif
#endif

#include <memory>

#include "ngraph/deprecated.hpp"
#include "onnx_import/onnx_importer_visibility.hpp"
#include "openvino/op/op.hpp"

namespace ngraph {
namespace op {
ONNX_IMPORTER_API
bool is_null(const ngraph::Node* node);
ONNX_IMPORTER_API
bool is_null(const std::shared_ptr<ngraph::Node>& node);
ONNX_IMPORTER_API
bool is_null(const Output<ngraph::Node>& output);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API bool is_null(const ngraph::Node* node);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API bool is_null(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API bool is_null(const Output<ngraph::Node>& output);
} // namespace op
namespace onnx_import {
/// \brief Represents a missing optional input or output of an ONNX node
Expand All @@ -28,7 +36,7 @@ namespace onnx_import {
///
/// More:
/// https://github.com/onnx/onnx/blob/master/docs/IR.md#optional-inputs-and-outputs
class ONNX_IMPORTER_API NullNode : public ov::op::Op {
class NGRAPH_API_DEPRECATED ONNX_IMPORTER_API NullNode : public ov::op::Op {
public:
OPENVINO_OP("NullNode");
NullNode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
namespace ngraph {
namespace onnx_import {
/// \brief Function which transforms single ONNX operator to nGraph sub-graph.
OPENVINO_SUPPRESS_DEPRECATED_START
using Operator = std::function<OutputVector(const Node&)>;
OPENVINO_SUPPRESS_DEPRECATED_END

/// \brief Map which contains ONNX operators accessible by std::string value as a key.
using OperatorSet = std::unordered_map<std::string, Operator>;
Expand Down
31 changes: 21 additions & 10 deletions src/frontends/onnx/frontend/include/onnx_import/onnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

#pragma once

#if !defined(IN_OV_COMPONENT) && !defined(NGRAPH_LEGACY_HEADER_INCLUDED)
# define NGRAPH_LEGACY_HEADER_INCLUDED
# ifdef _MSC_VER
# pragma message( \
"The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# else
# warning("The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# endif
#endif

#include <cstdint>
#include <iostream>
#include <memory>
#include <set>
#include <string>

#include "ngraph/deprecated.hpp"
#include "ngraph/function.hpp"
#include "onnx_importer_visibility.hpp"

Expand All @@ -25,8 +36,8 @@ namespace onnx_import {
/// \param[in] domain A domain to get the supported operators for.
///
/// \return The set containing names of supported operators.
ONNX_IMPORTER_API
std::set<std::string> get_supported_operators(std::int64_t version, const std::string& domain);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API std::set<std::string> get_supported_operators(std::int64_t version,
const std::string& domain);

/// \brief Determines whether ONNX operator is supported.
///
Expand All @@ -36,8 +47,9 @@ std::set<std::string> get_supported_operators(std::int64_t version, const std::s
/// If not set, the default domain "ai.onnx" is used.
///
/// \return true if operator is supported, false otherwise.
ONNX_IMPORTER_API
bool is_operator_supported(const std::string& op_name, std::int64_t version, const std::string& domain = "ai.onnx");
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API bool is_operator_supported(const std::string& op_name,
std::int64_t version,
const std::string& domain = "ai.onnx");

/// \brief Imports and converts an serialized ONNX model from the input stream
/// to an nGraph Function representation.
Expand All @@ -52,10 +64,9 @@ bool is_operator_supported(const std::string& op_name, std::int64_t version, con
/// \param[in] enable_mmap Enable mapping files with external weights instead of reading.
///
/// \return An nGraph function that represents a single output from the created graph.
ONNX_IMPORTER_API
std::shared_ptr<Function> import_onnx_model(std::istream& stream,
const std::string& model_path = "",
bool enable_mmap = false);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API std::shared_ptr<Function> import_onnx_model(std::istream& stream,
const std::string& model_path = "",
bool enable_mmap = false);

/// \brief Imports and converts an ONNX model from the input file
/// to an nGraph Function representation.
Expand All @@ -68,8 +79,8 @@ std::shared_ptr<Function> import_onnx_model(std::istream& stream,
/// \param[in] enable_mmap Enable mapping files with external weights instead of reading.
///
/// \return An nGraph function that represents a single output from the created graph.
ONNX_IMPORTER_API
std::shared_ptr<Function> import_onnx_model(const std::string& file_path, bool enable_mmap = false);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API std::shared_ptr<Function> import_onnx_model(const std::string& file_path,
bool enable_mmap = false);
} // namespace onnx_import

} // namespace ngraph
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
// SPDX-License-Identifier: Apache-2.0
//

#if !defined(IN_OV_COMPONENT) && !defined(NGRAPH_LEGACY_HEADER_INCLUDED)
# define NGRAPH_LEGACY_HEADER_INCLUDED
# ifdef _MSC_VER
# pragma message( \
"The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# else
# warning("The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# endif
#endif

#include "ngraph/visibility.hpp"

#ifdef OPENVINO_STATIC_LIBRARY
Expand Down
22 changes: 18 additions & 4 deletions src/frontends/onnx/frontend/include/onnx_import/onnx_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

#pragma once

#if !defined(IN_OV_COMPONENT) && !defined(NGRAPH_LEGACY_HEADER_INCLUDED)
# define NGRAPH_LEGACY_HEADER_INCLUDED
# ifdef _MSC_VER
# pragma message( \
"The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# else
# warning("The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html")
# endif
#endif

#include <cstdint>
#include <string>

#include "ngraph/deprecated.hpp"
#include "onnx_import/core/operator_set.hpp"
#include "onnx_importer_visibility.hpp"

Expand All @@ -24,17 +35,20 @@ namespace onnx_import {
/// \param domain The domain the ONNX operator is registered to.
/// \param fn The function providing the implementation of the operator
/// which transforms the single ONNX operator to an nGraph sub-graph.
ONNX_IMPORTER_API
void register_operator(const std::string& name, std::int64_t version, const std::string& domain, Operator fn);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API void register_operator(const std::string& name,
std::int64_t version,
const std::string& domain,
Operator fn);

/// \brief Unregisters ONNX custom operator.
/// The function unregisters previously registered operator.
///
/// \param name The ONNX operator name.
/// \param version The ONNX operator set version.
/// \param domain The domain the ONNX operator is registered to.
ONNX_IMPORTER_API
void unregister_operator(const std::string& name, std::int64_t version, const std::string& domain);
NGRAPH_API_DEPRECATED ONNX_IMPORTER_API void unregister_operator(const std::string& name,
std::int64_t version,
const std::string& domain);

} // namespace onnx_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

#pragma once

#include "openvino/core/deprecated.hpp"
#include "openvino/frontend/extension/conversion.hpp"
#include "openvino/frontend/node_context.hpp"
#include "openvino/frontend/onnx/visibility.hpp"

OPENVINO_SUPPRESS_DEPRECATED_START
namespace ngraph {
namespace onnx_import {
class Node;
Expand Down Expand Up @@ -39,3 +41,4 @@ using CreatorFunction = std::function<OutputVector(const ngraph::onnx_import::No
} // namespace onnx
} // namespace frontend
} // namespace ov
OPENVINO_SUPPRESS_DEPRECATED_END
10 changes: 8 additions & 2 deletions src/frontends/onnx/frontend/src/core/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ bool common_node_for_all_outputs(const OutputVector& outputs) {
return ret;
};

OPENVINO_SUPPRESS_DEPRECATED_START
OperatorsBridge register_extensions(OperatorsBridge& bridge,
const std::vector<ov::frontend::ConversionExtensionBase::Ptr>& conversions) {
for (const auto& extension : conversions) {
Expand All @@ -59,6 +60,7 @@ OperatorsBridge register_extensions(OperatorsBridge& bridge,
}
return bridge;
}
OPENVINO_SUPPRESS_DEPRECATED_END

OperatorsBridge init_ops_bridge(const std::vector<ov::frontend::ConversionExtensionBase::Ptr>& conversions) {
const auto legacy_conv_ext = std::find_if(std::begin(conversions),
Expand Down Expand Up @@ -175,6 +177,7 @@ Graph::Graph(const std::string& model_dir,
}
}

OPENVINO_SUPPRESS_DEPRECATED_START
void Graph::convert_to_ngraph_nodes() {
const float total = static_cast<float>(m_model->get_graph().node().size());
unsigned int completed = 0u;
Expand Down Expand Up @@ -206,6 +209,7 @@ void Graph::convert_to_ngraph_nodes() {
}
}
}
OPENVINO_SUPPRESS_DEPRECATED_END

void Graph::remove_dangling_parameters() {
const auto any_tensor_name_matches_onnx_output = [](const Output<ov::Node>& param_output,
Expand Down Expand Up @@ -252,6 +256,7 @@ std::shared_ptr<Function> Graph::convert() {
return function;
}

OPENVINO_SUPPRESS_DEPRECATED_START
OutputVector Graph::make_framework_nodes(const Node& onnx_node) {
std::shared_ptr<frontend::ONNXFrameworkNode> framework_node;
if (onnx_node.has_subgraphs()) {
Expand Down Expand Up @@ -304,6 +309,7 @@ void Graph::decode_to_framework_nodes() {
}
}
}
OPENVINO_SUPPRESS_DEPRECATED_END

std::shared_ptr<Function> Graph::create_function() {
auto function = std::make_shared<Function>(get_ng_outputs(), m_parameters, get_name());
Expand Down Expand Up @@ -334,6 +340,7 @@ Output<ngraph::Node> Graph::get_ng_node_from_cache(const std::string& name) {
return m_cache->get_node(name);
}

OPENVINO_SUPPRESS_DEPRECATED_START
OutputVector Graph::get_ng_outputs() {
OutputVector results;
for (const auto& output : m_model->get_graph().output()) {
Expand Down Expand Up @@ -436,13 +443,12 @@ void Graph::set_friendly_names(const Node& onnx_node, const OutputVector& ng_sub
// null node does not have tensor
if (!ngraph::op::is_null(ng_subgraph_outputs[i])) {
ng_subgraph_outputs[i].get_tensor().set_names({onnx_node.output(static_cast<int>(i))});
NGRAPH_SUPPRESS_DEPRECATED_START
ov::descriptor::set_ov_tensor_legacy_name(ng_subgraph_outputs[i].get_tensor(),
onnx_node.output(static_cast<int>(i)));
NGRAPH_SUPPRESS_DEPRECATED_END
}
}
}
OPENVINO_SUPPRESS_DEPRECATED_END

const OpsetImports& Graph::get_opset_imports() const {
return m_model->get_opset_imports();
Expand Down
Loading

0 comments on commit d363660

Please sign in to comment.