Remove legacy API from FEs (except ONNX) (#20849)
* Remove `ngraph` from PT FE and FE tests utils * Remove `ngraph` from Paddle FE * Remove `InferenceEngine` from some ONNX FE test * Port `generate_embedding.py` to API2.0 * CLangFormat * Fix comments
This commit is contained in:
parent
95aef4bf51
commit
e3d7dffa83
@ -5,10 +5,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <ie_core.hpp>
|
||||
|
||||
#include "common_test_utils/file_utils.hpp"
|
||||
#include "ie_common.h"
|
||||
#include "openvino/runtime/core.hpp"
|
||||
|
||||
namespace {
|
||||
std::string model_path(const char* model) {
|
||||
@ -22,51 +21,47 @@ std::string model_path(const char* model) {
|
||||
TEST(ONNXReader_ModelSupported, basic_model) {
|
||||
// this model is a basic ONNX model taken from ngraph's unit test (add_abc.onnx)
|
||||
// it contains the minimum number of fields required to accept this file as a valid model
|
||||
EXPECT_NO_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("supported/basic.onnx")));
|
||||
EXPECT_NO_THROW(ov::Core{}.read_model(model_path("supported/basic.onnx")));
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelSupported, basic_reverse_fields_order) {
|
||||
// this model contains the same fields as basic.onnx but serialized in reverse order
|
||||
EXPECT_NO_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("supported/basic_reverse_fields_order.onnx")));
|
||||
EXPECT_NO_THROW(ov::Core{}.read_model(model_path("supported/basic_reverse_fields_order.onnx")));
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelSupported, more_fields) {
|
||||
// this model contains some optional fields (producer_name and doc_string) but 5 fields in total
|
||||
EXPECT_NO_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("supported/more_fields.onnx")));
|
||||
EXPECT_NO_THROW(ov::Core{}.read_model(model_path("supported/more_fields.onnx")));
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelSupported, varint_on_two_bytes) {
|
||||
// the docstring's payload length is encoded as varint using 2 bytes which should be parsed correctly
|
||||
EXPECT_NO_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("supported/varint_on_two_bytes.onnx")));
|
||||
EXPECT_NO_THROW(ov::Core{}.read_model(model_path("supported/varint_on_two_bytes.onnx")));
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelSupported, scrambled_keys) {
|
||||
// same as the prototxt_basic but with a different order of keys
|
||||
EXPECT_NO_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("supported/scrambled_keys.onnx")));
|
||||
EXPECT_NO_THROW(ov::Core{}.read_model(model_path("supported/scrambled_keys.onnx")));
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelUnsupported, no_graph_field) {
|
||||
// this model contains only 2 fields (it doesn't contain a graph in particular)
|
||||
EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/no_graph_field.onnx")),
|
||||
InferenceEngine::NetworkNotRead);
|
||||
EXPECT_THROW(ov::Core{}.read_model(model_path("unsupported/no_graph_field.onnx")), ov::Exception);
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelUnsupported, incorrect_onnx_field) {
|
||||
// in this model the second field's key is F8 (field number 31) which is doesn't exist in ONNX
|
||||
// this test will have to be changed if the number of fields in onnx.proto
|
||||
// (ModelProto message definition) ever reaches 31 or more
|
||||
EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/incorrect_onnx_field.onnx")),
|
||||
InferenceEngine::NetworkNotRead);
|
||||
EXPECT_THROW(ov::Core{}.read_model(model_path("unsupported/incorrect_onnx_field.onnx")), ov::Exception);
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelUnsupported, unknown_wire_type) {
|
||||
// in this model the graph key contains wire type 7 encoded in it - this value is incorrect
|
||||
EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/unknown_wire_type.onnx")),
|
||||
InferenceEngine::NetworkNotRead);
|
||||
EXPECT_THROW(ov::Core{}.read_model(model_path("unsupported/unknown_wire_type.onnx")), ov::Exception);
|
||||
}
|
||||
|
||||
TEST(ONNXReader_ModelUnsupported, duplicate_fields) {
|
||||
// the model contains the IR_VERSION field twice - this is not correct
|
||||
EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/duplicate_onnx_fields.onnx")),
|
||||
std::exception);
|
||||
EXPECT_THROW(ov::Core{}.read_model(model_path("unsupported/duplicate_onnx_fields.onnx")), ov::Exception);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "openvino/core/so_extension.hpp"
|
||||
#include "openvino/frontend/extension/conversion.hpp"
|
||||
#include "openvino/frontend/paddle/node_context.hpp"
|
||||
#include "openvino/runtime/aligned_buffer.hpp"
|
||||
#include "openvino/util/common_util.hpp"
|
||||
#include "paddle_fw_node.hpp"
|
||||
#include "paddle_utils.hpp"
|
||||
@ -139,8 +140,8 @@ OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
std::istream* variant_to_stream_ptr(const ov::Any& variant, std::fstream& fs, std::stringstream& ss) {
|
||||
if (variant.is<std::istream*>()) {
|
||||
return variant.as<std::istream*>();
|
||||
} else if (variant.is<std::shared_ptr<ngraph::runtime::AlignedBuffer>>()) {
|
||||
auto& aligned_weights_buffer = variant.as<std::shared_ptr<ngraph::runtime::AlignedBuffer>>();
|
||||
} else if (variant.is<std::shared_ptr<ov::AlignedBuffer>>()) {
|
||||
auto& aligned_weights_buffer = variant.as<std::shared_ptr<ov::AlignedBuffer>>();
|
||||
ss.write(aligned_weights_buffer->get_ptr<char>(), aligned_weights_buffer->size());
|
||||
FRONT_END_INITIALIZATION_CHECK(ss && ss.good(), "Cannot open ov::tensor.");
|
||||
return &ss;
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include "internal/op/conditional_block.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ngraph/validation_util.hpp>
|
||||
|
||||
#include "ngraph/op/constant.hpp"
|
||||
#include "openvino/core/validation_util.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/util/precision_sensitive_attribute.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include "internal/op/tensorarray_write.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ngraph/validation_util.hpp>
|
||||
|
||||
#include "ngraph/op/constant.hpp"
|
||||
#include "openvino/core/validation_util.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/util/precision_sensitive_attribute.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
@ -5,10 +5,6 @@
|
||||
#include "internal/op/while.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ngraph/validation_util.hpp>
|
||||
|
||||
#include "ngraph/op/constant.hpp"
|
||||
#include "openvino/op/util/precision_sensitive_attribute.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
|
@ -4,15 +4,9 @@
|
||||
|
||||
#include "internal/pass/transform_fakequantize.hpp"
|
||||
|
||||
#include <ngraph/ngraph.hpp>
|
||||
#include <ngraph/op/util/op_types.hpp>
|
||||
#include <ngraph/pattern/matcher.hpp>
|
||||
#include <ngraph/pattern/op/or.hpp>
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
|
||||
#include "default_opset.hpp"
|
||||
#include "openvino/pass/pattern/op/label.hpp"
|
||||
#include "openvino/pass/pattern/matcher.hpp"
|
||||
#include "openvino/pass/pattern/op/wrap_type.hpp"
|
||||
#include "transformations/utils/utils.hpp"
|
||||
|
||||
using namespace ov::frontend::paddle::op::default_opset;
|
||||
@ -43,24 +37,24 @@ using namespace ov::frontend::paddle::op;
|
||||
Multiply
|
||||
*/
|
||||
ov::frontend::paddle::pass::TransformFakeQuantize::TransformFakeQuantize() {
|
||||
const auto input_label = ngraph::pattern::any_input();
|
||||
const auto q_zp_label = ngraph::pattern::any_input();
|
||||
const auto input_label = pattern::any_input();
|
||||
const auto q_zp_label = pattern::any_input();
|
||||
// quantize phase
|
||||
const auto q_zp_cvt_label = ngraph::pattern::wrap_type<Convert>({q_zp_label});
|
||||
const auto q_sub_label = ngraph::pattern::wrap_type<Subtract>({input_label, q_zp_cvt_label});
|
||||
const auto q_real_scale_label = ngraph::pattern::wrap_type<Multiply>();
|
||||
const auto div_label = ngraph::pattern::wrap_type<Divide>({q_sub_label, q_real_scale_label});
|
||||
const auto round_label = ngraph::pattern::wrap_type<Round>({div_label});
|
||||
const auto q_clamp_label = ngraph::pattern::wrap_type<Clamp>({round_label});
|
||||
const auto q_zp_cvt_label = pattern::wrap_type<Convert>({q_zp_label});
|
||||
const auto q_sub_label = pattern::wrap_type<Subtract>({input_label, q_zp_cvt_label});
|
||||
const auto q_real_scale_label = pattern::wrap_type<Multiply>();
|
||||
const auto div_label = pattern::wrap_type<Divide>({q_sub_label, q_real_scale_label});
|
||||
const auto round_label = pattern::wrap_type<Round>({div_label});
|
||||
const auto q_clamp_label = pattern::wrap_type<Clamp>({round_label});
|
||||
// dequantize phase
|
||||
const auto dq_cvt_label = ngraph::pattern::wrap_type<Convert>({q_clamp_label});
|
||||
const auto dq_zp_label = ngraph::pattern::any_input();
|
||||
const auto dq_zp_cvt_label = ngraph::pattern::wrap_type<Convert>({dq_zp_label});
|
||||
const auto dq_sub_label = ngraph::pattern::wrap_type<Subtract>({dq_cvt_label, dq_zp_cvt_label});
|
||||
const auto dq_real_scale_label = ngraph::pattern::wrap_type<Multiply>();
|
||||
const auto output_label = ngraph::pattern::wrap_type<Multiply>({dq_sub_label, dq_real_scale_label});
|
||||
const auto dq_cvt_label = pattern::wrap_type<Convert>({q_clamp_label});
|
||||
const auto dq_zp_label = pattern::any_input();
|
||||
const auto dq_zp_cvt_label = pattern::wrap_type<Convert>({dq_zp_label});
|
||||
const auto dq_sub_label = pattern::wrap_type<Subtract>({dq_cvt_label, dq_zp_cvt_label});
|
||||
const auto dq_real_scale_label = pattern::wrap_type<Multiply>();
|
||||
const auto output_label = pattern::wrap_type<Multiply>({dq_sub_label, dq_real_scale_label});
|
||||
|
||||
matcher_pass_callback callback = [=](ngraph::pattern::Matcher& m) -> bool {
|
||||
matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {
|
||||
const auto& opsMap = m.get_pattern_value_map();
|
||||
if (transformation_callback(m.get_match_root())) {
|
||||
return false;
|
||||
@ -127,6 +121,6 @@ ov::frontend::paddle::pass::TransformFakeQuantize::TransformFakeQuantize() {
|
||||
replace_node(output_node, fake_node);
|
||||
return true;
|
||||
};
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(output_label, "TransformFakeQuantize");
|
||||
auto m = std::make_shared<pattern::Matcher>(output_label, "TransformFakeQuantize");
|
||||
this->register_matcher(m, callback);
|
||||
}
|
||||
|
@ -4,20 +4,12 @@
|
||||
|
||||
#include "internal/pass/transform_if.hpp"
|
||||
|
||||
#include <ngraph/ngraph.hpp>
|
||||
#include <ngraph/pattern/matcher.hpp>
|
||||
#include <ngraph/pattern/op/or.hpp>
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
#include <transformations/common_optimizations/fold_subgraph_empty_inputs.hpp>
|
||||
|
||||
#include "default_opset.hpp"
|
||||
#include "internal/op/conditional_block.hpp"
|
||||
#include "internal/op/tensorarray_write.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "openvino/frontend/paddle/exception.hpp"
|
||||
#include "openvino/op/util/op_types.hpp"
|
||||
#include "openvino/pass/pattern/op/label.hpp"
|
||||
#include "openvino/pass/pattern/matcher.hpp"
|
||||
#include "openvino/pass/pattern/op/wrap_type.hpp"
|
||||
#include "transformations/common_optimizations/fold_subgraph_empty_inputs.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
@ -28,7 +20,7 @@ using namespace ov::frontend::paddle::op::default_opset;
|
||||
// The contional_block only has "then" branch, while If op requires both "then" and "else" branch the same time.
|
||||
// Thus a "pass-through" model is built on purpose for "else" branch with the same outputs as "then" branch.
|
||||
ov::frontend::paddle::pass::TransformIf::TransformIf(std::vector<std::shared_ptr<Model>> funcs) {
|
||||
const auto cond_label = ngraph::pattern::wrap_type<ov::op::internal::ConditionalBlock>();
|
||||
const auto cond_label = pattern::wrap_type<ov::op::internal::ConditionalBlock>();
|
||||
|
||||
matcher_pass_callback callback = [funcs](pattern::Matcher& m) -> bool {
|
||||
const auto conditional_block =
|
||||
@ -104,6 +96,6 @@ ov::frontend::paddle::pass::TransformIf::TransformIf(std::vector<std::shared_ptr
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(cond_label, "condtionalblock_if");
|
||||
auto m = std::make_shared<pattern::Matcher>(cond_label, "condtionalblock_if");
|
||||
this->register_matcher(m, callback);
|
||||
}
|
||||
|
@ -4,22 +4,11 @@
|
||||
|
||||
#include "internal/pass/transform_tensorarray.hpp"
|
||||
|
||||
#include <ngraph/log.hpp>
|
||||
#include <ngraph/ngraph.hpp>
|
||||
#include <ngraph/pattern/matcher.hpp>
|
||||
#include <ngraph/pattern/op/or.hpp>
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
#include <transformations/common_optimizations/remove_concat_zero_dim_input.hpp>
|
||||
|
||||
#include "default_opset.hpp"
|
||||
#include "internal/op/conditional_block.hpp"
|
||||
#include "internal/op/tensorarray_write.hpp"
|
||||
#include "internal/op/while.hpp"
|
||||
#include "openvino/frontend/paddle/exception.hpp"
|
||||
#include "openvino/op/util/op_types.hpp"
|
||||
#include "openvino/pass/constant_folding.hpp"
|
||||
#include "openvino/pass/pattern/op/label.hpp"
|
||||
#include "openvino/pass/pattern/matcher.hpp"
|
||||
#include "openvino/pass/pattern/op/wrap_type.hpp"
|
||||
#include "transformations/common_optimizations/remove_concat_zero_dim_input.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
@ -29,11 +18,10 @@ using namespace frontend::paddle::op::default_opset;
|
||||
// Transform pattern "TensorArrayLength->TensorArrayWrite" to OV concat, which
|
||||
// will append to the end of array after unsqueeze along axis 0.
|
||||
ov::frontend::paddle::pass::TransformTensorArray::TransformTensorArray(std::vector<std::shared_ptr<Model>> functions) {
|
||||
const auto shape_label = ngraph::pattern::wrap_type<ShapeOf>();
|
||||
const auto length_label = ngraph::pattern::wrap_type<StridedSlice>(
|
||||
{shape_label, ngraph::pattern::any_input(), ngraph::pattern::any_input(), ngraph::pattern::any_input()});
|
||||
auto write_label =
|
||||
ngraph::pattern::wrap_type<ov::op::internal::TensorArrayWrite>({ngraph::pattern::any_input(), length_label});
|
||||
const auto shape_label = pattern::wrap_type<ShapeOf>();
|
||||
const auto length_label = pattern::wrap_type<StridedSlice>(
|
||||
{shape_label, pattern::any_input(), pattern::any_input(), pattern::any_input()});
|
||||
auto write_label = pattern::wrap_type<ov::op::internal::TensorArrayWrite>({pattern::any_input(), length_label});
|
||||
|
||||
matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {
|
||||
const auto& opsMap = m.get_pattern_value_map();
|
||||
@ -57,6 +45,6 @@ ov::frontend::paddle::pass::TransformTensorArray::TransformTensorArray(std::vect
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(write_label, "tensorarray");
|
||||
auto m = std::make_shared<pattern::Matcher>(write_label, "tensorarray");
|
||||
this->register_matcher(m, callback);
|
||||
}
|
||||
|
@ -4,21 +4,13 @@
|
||||
|
||||
#include "internal/pass/transform_while.hpp"
|
||||
|
||||
#include <ngraph/ngraph.hpp>
|
||||
#include <ngraph/pattern/matcher.hpp>
|
||||
#include <ngraph/pattern/op/or.hpp>
|
||||
#include <ngraph/pattern/op/wrap_type.hpp>
|
||||
#include <ngraph/rt_info.hpp>
|
||||
#include <transformations/common_optimizations/fold_subgraph_empty_inputs.hpp>
|
||||
|
||||
#include "default_opset.hpp"
|
||||
#include "internal/op/conditional_block.hpp"
|
||||
#include "internal/op/tensorarray_write.hpp"
|
||||
#include "internal/op/while.hpp"
|
||||
#include "openvino/core/rt_info.hpp"
|
||||
#include "openvino/frontend/paddle/exception.hpp"
|
||||
#include "openvino/op/util/op_types.hpp"
|
||||
#include "openvino/pass/constant_folding.hpp"
|
||||
#include "openvino/pass/pattern/op/label.hpp"
|
||||
#include "openvino/pass/pattern/matcher.hpp"
|
||||
#include "openvino/pass/pattern/op/wrap_type.hpp"
|
||||
#include "transformations/common_optimizations/fold_subgraph_empty_inputs.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
@ -34,7 +26,7 @@ using namespace ov::frontend::paddle::op::default_opset;
|
||||
// TensorArray could be a non-empty input of the loop body, which needs extra concat.
|
||||
// What's more, we have to tell which output is of TensorArray type to concate.
|
||||
ov::frontend::paddle::pass::TransformWhile::TransformWhile(std::vector<std::shared_ptr<Model>> functions) {
|
||||
const auto while_label = ngraph::pattern::wrap_type<ov::op::internal::While>();
|
||||
const auto while_label = pattern::wrap_type<ov::op::internal::While>();
|
||||
|
||||
matcher_pass_callback callback = [functions](pattern::Matcher& m) -> bool {
|
||||
const auto& while_node = std::dynamic_pointer_cast<ov::op::internal::While>(m.get_match_root());
|
||||
@ -98,6 +90,6 @@ ov::frontend::paddle::pass::TransformWhile::TransformWhile(std::vector<std::shar
|
||||
return true;
|
||||
};
|
||||
|
||||
auto m = std::make_shared<ngraph::pattern::Matcher>(while_label, "while_loop");
|
||||
auto m = std::make_shared<pattern::Matcher>(while_label, "while_loop");
|
||||
this->register_matcher(m, callback);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ NamedOutputs reduce_ops(const NodeContext& node) {
|
||||
} else {
|
||||
dims = node.get_attribute<std::vector<int32_t>>("dim");
|
||||
}
|
||||
auto axesNode = default_opset::Constant::create(ngraph::element::i32, {dims.size()}, dims);
|
||||
auto axesNode = default_opset::Constant::create(ov::element::i32, {dims.size()}, dims);
|
||||
bool scalar_output = !keep_dim;
|
||||
if (scalar_output) {
|
||||
for (int32_t i = 0; i < input_rank; i++) {
|
||||
|
@ -16,24 +16,22 @@ NamedOutputs softshrink(const NodeContext& node) {
|
||||
PADDLE_OP_CHECK(node, lambda >= 0, "Softshrink op lambda must be non-negative.");
|
||||
PADDLE_OP_CHECK(node, input_element_type.is_signed(), "Softshrink op input must be signed type.");
|
||||
|
||||
std::shared_ptr<ngraph::Node> output;
|
||||
std::shared_ptr<Node> output;
|
||||
const auto positive_lambda = default_opset::Constant::create(input_element_type, Shape{}, {lambda});
|
||||
const auto negative_lambda = default_opset::Constant::create(input_element_type, Shape{}, {-lambda});
|
||||
std::shared_ptr<ngraph::Node> negative_node = std::make_shared<default_opset::Subtract>(data, positive_lambda);
|
||||
std::shared_ptr<ngraph::Node> positive_node = std::make_shared<default_opset::Add>(data, positive_lambda);
|
||||
std::shared_ptr<Node> negative_node = std::make_shared<default_opset::Subtract>(data, positive_lambda);
|
||||
std::shared_ptr<Node> positive_node = std::make_shared<default_opset::Add>(data, positive_lambda);
|
||||
|
||||
std::shared_ptr<ngraph::Node> zero_node = default_opset::Constant::create(input_element_type, Shape{}, {0});
|
||||
std::shared_ptr<Node> zero_node = default_opset::Constant::create(input_element_type, Shape{}, {0});
|
||||
|
||||
// Create masks for values below negative lambda and above positive lambda
|
||||
std::shared_ptr<ngraph::Node> values_below_neg_lambda =
|
||||
std::make_shared<default_opset::Less>(data, negative_lambda);
|
||||
std::shared_ptr<ngraph::Node> values_above_pos_lambda =
|
||||
std::make_shared<default_opset::Greater>(data, positive_lambda);
|
||||
std::shared_ptr<Node> values_below_neg_lambda = std::make_shared<default_opset::Less>(data, negative_lambda);
|
||||
std::shared_ptr<Node> values_above_pos_lambda = std::make_shared<default_opset::Greater>(data, positive_lambda);
|
||||
|
||||
output = std::make_shared<default_opset::Select>(values_above_pos_lambda, negative_node, data);
|
||||
output = std::make_shared<default_opset::Select>(values_below_neg_lambda, positive_node, output);
|
||||
|
||||
std::shared_ptr<ngraph::Node> zero_mask =
|
||||
std::shared_ptr<Node> zero_mask =
|
||||
std::make_shared<default_opset::LogicalOr>(values_below_neg_lambda, values_above_pos_lambda);
|
||||
|
||||
output = std::make_shared<default_opset::Select>(zero_mask, output, zero_node);
|
||||
|
@ -12,20 +12,20 @@ import sys
|
||||
|
||||
from save_model import saveModel
|
||||
|
||||
def ngraph_embedding(ids, vocab_embeddings, vocab_size, embedding_dim, padding_idx, sparse):
|
||||
def ov_embedding(ids, vocab_embeddings, vocab_size, embedding_dim, padding_idx, sparse):
|
||||
"""
|
||||
decomposing embedding with OpenVINO ops.
|
||||
"""
|
||||
import ngraph as ng
|
||||
from ngraph import opset8 as opset
|
||||
from openvino.inference_engine import IECore
|
||||
import openvino as ov
|
||||
from openvino.runtime import opset8
|
||||
from openvino import Core
|
||||
|
||||
if vocab_embeddings is None:
|
||||
#
|
||||
vocab_embeddings = np.zeros((vocab_size, embedding_dim)).astype("float32")
|
||||
|
||||
node_ids = ng.parameter(shape=ids.shape, name='ids', dtype=ids.dtype)
|
||||
node_w = ng.parameter(shape=vocab_embeddings.shape, name='w', dtype=vocab_embeddings.dtype)
|
||||
node_ids = opset8.parameter(shape=ids.shape, name='ids', dtype=ids.dtype)
|
||||
node_w = opset8.parameter(shape=vocab_embeddings.shape, name='w', dtype=vocab_embeddings.dtype)
|
||||
|
||||
if padding_idx == -1:
|
||||
padding_idx += vocab_size
|
||||
@ -37,24 +37,22 @@ def ngraph_embedding(ids, vocab_embeddings, vocab_size, embedding_dim, padding_i
|
||||
masked_embeddings = np.ones(vocab_embeddings.shape, dtype='int64')
|
||||
masked_embeddings[padding_idx,:] = 0 # mask
|
||||
|
||||
node_mask = ng.constant(masked_embeddings, name='mask', dtype=vocab_embeddings.dtype)
|
||||
node_masked_w = ng.multiply(node_w, node_mask)
|
||||
node_mask = opset8.constant(masked_embeddings, name='mask', dtype=vocab_embeddings.dtype)
|
||||
node_masked_w = opset8.multiply(node_w, node_mask)
|
||||
|
||||
node_axis = ng.constant([0], name='const0', dtype=np.int64)
|
||||
node_gather = opset.gather(data=node_masked_w if padding_idx else node_w, indices=node_ids, axis=node_axis, batch_dims=0)
|
||||
node_axis = opset8.constant([0], name='const0', dtype=np.int64)
|
||||
node_gather = opset8.gather(data=node_masked_w if padding_idx else node_w, indices=node_ids, axis=node_axis, batch_dims=0)
|
||||
|
||||
graph = ng.result(node_gather, name='y')
|
||||
graph = opset8.result(node_gather, name='y')
|
||||
|
||||
parameters = [node_ids, node_w]
|
||||
inputs_dict = {'ids': ids, "w": vocab_embeddings}
|
||||
|
||||
#
|
||||
function = ng.Function(graph, parameters, "embedding")
|
||||
|
||||
ie_network = ng.function_to_cnn(function)
|
||||
ie = IECore()
|
||||
executable_network = ie.load_network(ie_network, 'CPU')
|
||||
output = executable_network.infer(inputs_dict)
|
||||
ov_model = ov.Model(graph, parameters, "embedding")
|
||||
core = Core()
|
||||
compiled_model = core.compile_model(ov_model, 'CPU')
|
||||
output = compiled_model(inputs_dict)
|
||||
|
||||
return output
|
||||
|
||||
@ -97,8 +95,7 @@ def embedding(name : str, ids, vocab_size, embedding_dim, padding_idx=None, spar
|
||||
|
||||
#
|
||||
if compare:
|
||||
ng_result = ngraph_embedding(ids, vocab_embeddings, vocab_size, embedding_dim, padding_idx, sparse)
|
||||
|
||||
ng_result = ov_embedding(ids, vocab_embeddings, vocab_size, embedding_dim, padding_idx, sparse)
|
||||
ng_result = list(ng_result.values())[0]
|
||||
paddle_result = list(outputs.values())[0]
|
||||
|
||||
|
@ -4,9 +4,8 @@
|
||||
|
||||
#include "softmax_reshape_elimination.hpp"
|
||||
|
||||
#include <ngraph/validation_util.hpp>
|
||||
|
||||
#include "openvino/core/rt_info.hpp"
|
||||
#include "openvino/core/validation_util.hpp"
|
||||
#include "openvino/op/reshape.hpp"
|
||||
#include "openvino/op/softmax.hpp"
|
||||
#include "openvino/pass/pattern/op/wrap_type.hpp"
|
||||
|
@ -8,12 +8,12 @@
|
||||
#include "utils.hpp"
|
||||
#include "common_test_utils/file_utils.hpp"
|
||||
|
||||
#include "ngraph/file_util.hpp"
|
||||
#include "openvino/util/file_util.hpp"
|
||||
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
static const std::string s_manifest{
|
||||
#ifdef MANIFEST
|
||||
ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), MANIFEST)
|
||||
ov::util::path_join({ov::test::utils::getExecutableDirectory(), MANIFEST})
|
||||
#endif
|
||||
};
|
||||
OPENVINO_SUPPRESS_DEPRECATED_END
|
||||
|
Loading…
Reference in New Issue
Block a user