[TF FE] Speed up compilation - part 4 (#21269)
Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>
This commit is contained in:
1 parent
965313ba0b
commit
9f87f72ca6
21 files changed
+206
-145
No files matched your search
@@ -2,11 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/random_uniform.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -21,9 +23,9 @@ ov::OutputVector translate_random_uniform_op(const NodeContext& node) {
|
||||
auto seed2 = node.get_attribute<int64_t>("seed2", 0);
|
||||
auto output_type = node.get_attribute<ov::element::Type>("dtype");
|
||||
|
||||
auto minval = make_shared<Constant>(output_type, Shape{}, 0);
|
||||
auto maxval = make_shared<Constant>(output_type, Shape{}, 1);
|
||||
auto random = std::make_shared<RandomUniform>(shape, minval, maxval, output_type, seed, seed2);
|
||||
auto minval = make_shared<v0::Constant>(output_type, Shape{}, 0);
|
||||
auto maxval = make_shared<v0::Constant>(output_type, Shape{}, 1);
|
||||
auto random = std::make_shared<v8::RandomUniform>(shape, minval, maxval, output_type, seed, seed2);
|
||||
|
||||
set_node_name(node.get_name(), random);
|
||||
return random->outputs();
|
||||
@@ -42,10 +44,10 @@ ov::OutputVector translate_random_uniform_int_op(const NodeContext& node) {
|
||||
auto output_type = minval.get_element_type();
|
||||
Output<Node> random;
|
||||
if (output_type.is_static()) {
|
||||
random = std::make_shared<RandomUniform>(shape, minval, maxval, output_type, seed, seed2);
|
||||
random = std::make_shared<v8::RandomUniform>(shape, minval, maxval, output_type, seed, seed2);
|
||||
} else {
|
||||
random = std::make_shared<RandomUniform>(shape, minval, maxval, element::i64, seed, seed2);
|
||||
random = make_shared<ConvertLike>(random, minval);
|
||||
random = std::make_shared<v8::RandomUniform>(shape, minval, maxval, element::i64, seed, seed2);
|
||||
random = make_shared<v1::ConvertLike>(random, minval);
|
||||
}
|
||||
|
||||
set_node_name(node.get_name(), random.get_node_shared_ptr());
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/range.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/convert_like.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -22,10 +24,10 @@ OutputVector translate_range_op(const NodeContext& node) {
|
||||
auto start_type = start.get_element_type();
|
||||
Output<Node> range;
|
||||
if (start_type.is_static()) {
|
||||
range = make_shared<Range>(start, limit, delta, start_type);
|
||||
range = make_shared<v4::Range>(start, limit, delta, start_type);
|
||||
} else {
|
||||
range = make_shared<Range>(start, limit, delta, element::f32);
|
||||
range = make_shared<ConvertLike>(range, start);
|
||||
range = make_shared<v4::Range>(start, limit, delta, element::f32);
|
||||
range = make_shared<v1::ConvertLike>(range, start);
|
||||
}
|
||||
set_node_name(node.get_name(), range.get_node_shared_ptr());
|
||||
return {range};
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/shape_of.hpp"
|
||||
#include "openvino/op/squeeze.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -16,9 +17,9 @@ namespace op {
|
||||
ov::OutputVector translate_rank_op(const NodeContext& node) {
|
||||
default_op_checks(node, 1, {"Rank"});
|
||||
auto input = node.get_input(0);
|
||||
auto input_shape = make_shared<ShapeOf>(input, ov::element::i32);
|
||||
auto unsqueeze_input_rank = make_shared<ShapeOf>(input_shape, ov::element::i32);
|
||||
auto input_rank = make_shared<Squeeze>(unsqueeze_input_rank);
|
||||
auto input_shape = make_shared<v3::ShapeOf>(input, ov::element::i32);
|
||||
auto unsqueeze_input_rank = make_shared<v3::ShapeOf>(input_shape, ov::element::i32);
|
||||
auto input_rank = make_shared<v0::Squeeze>(unsqueeze_input_rank);
|
||||
set_node_name(node.get_name(), input_rank);
|
||||
return {input_rank};
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/power.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -19,7 +19,7 @@ OutputVector translate_reciprocal_op(const NodeContext& node) {
|
||||
default_op_checks(node, 1, {"Reciprocal"});
|
||||
auto x = node.get_input(0);
|
||||
auto minus_one_const = create_same_type_const_scalar<int32_t>(x, -1);
|
||||
auto reciprocal = make_shared<Power>(x, minus_one_const);
|
||||
auto reciprocal = make_shared<v1::Power>(x, minus_one_const);
|
||||
set_node_name(node.get_name(), reciprocal);
|
||||
return {reciprocal};
|
||||
}
|
||||
|
||||
@@ -3,10 +3,16 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/reduce_l2.hpp"
|
||||
#include "openvino/op/reduce_logical_and.hpp"
|
||||
#include "openvino/op/reduce_logical_or.hpp"
|
||||
#include "openvino/op/reduce_max.hpp"
|
||||
#include "openvino/op/reduce_mean.hpp"
|
||||
#include "openvino/op/reduce_min.hpp"
|
||||
#include "openvino/op/reduce_sum.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -24,14 +30,14 @@ OutputVector translate_direct_reduce_op(const NodeContext& node) {
|
||||
return {reduce_op};
|
||||
}
|
||||
|
||||
template OutputVector translate_direct_reduce_op<ReduceLogicalOr>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<ReduceLogicalAnd>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<ReduceMax>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<ReduceMean>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<ReduceMin>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<ReduceProd>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<ReduceSum>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<ReduceL2>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v1::ReduceLogicalOr>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v1::ReduceLogicalAnd>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v1::ReduceMax>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v1::ReduceMean>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v1::ReduceMin>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v1::ReduceProd>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v1::ReduceSum>(const NodeContext& node);
|
||||
template OutputVector translate_direct_reduce_op<v4::ReduceL2>(const NodeContext& node);
|
||||
} // namespace op
|
||||
} // namespace tensorflow
|
||||
} // namespace frontend
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/reshape.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -17,7 +18,7 @@ OutputVector translate_reshape_op(const NodeContext& node) {
|
||||
default_op_checks(node, 2, {"Reshape"});
|
||||
auto tensor = node.get_input(0);
|
||||
auto shape = node.get_input(1);
|
||||
auto reshape = make_shared<Reshape>(tensor, shape, false);
|
||||
auto reshape = make_shared<v1::Reshape>(tensor, shape, false);
|
||||
set_node_name(node.get_name(), reshape);
|
||||
return {reshape};
|
||||
}
|
||||
|
||||
@@ -3,23 +3,28 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset9.hpp"
|
||||
#include "openvino/op/broadcast.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/gather.hpp"
|
||||
#include "openvino/op/reverse_sequence.hpp"
|
||||
#include "openvino/op/squeeze.hpp"
|
||||
#include "openvino/op/unsqueeze.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
using namespace ov::opset9;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
namespace tensorflow {
|
||||
namespace op {
|
||||
shared_ptr<Node> compute_sequence_lengths(const Output<Node>& input_shape, int64_t batch_axis, int64_t seq_axis) {
|
||||
auto batch_axis_const = make_shared<Constant>(element::i32, Shape{1}, batch_axis);
|
||||
auto seq_axis_const = make_shared<Constant>(element::i32, Shape{1}, seq_axis);
|
||||
auto gather_axis = make_shared<Constant>(element::i32, Shape{}, 0);
|
||||
auto batch_dim = make_shared<Gather>(input_shape, batch_axis_const, gather_axis);
|
||||
auto seq_dim = make_shared<Gather>(input_shape, seq_axis_const, gather_axis);
|
||||
auto seq_lengths = make_shared<Broadcast>(seq_dim, batch_dim);
|
||||
auto batch_axis_const = make_shared<v0::Constant>(element::i32, Shape{1}, batch_axis);
|
||||
auto seq_axis_const = make_shared<v0::Constant>(element::i32, Shape{1}, seq_axis);
|
||||
auto gather_axis = make_shared<v0::Constant>(element::i32, Shape{}, 0);
|
||||
auto batch_dim = make_shared<v8::Gather>(input_shape, batch_axis_const, gather_axis);
|
||||
auto seq_dim = make_shared<v8::Gather>(input_shape, seq_axis_const, gather_axis);
|
||||
auto seq_lengths = make_shared<v3::Broadcast>(seq_dim, batch_dim);
|
||||
|
||||
return seq_lengths;
|
||||
}
|
||||
@@ -56,18 +61,20 @@ OutputVector translate_reverse_base_op(const NodeContext& node,
|
||||
auto batched_input = input;
|
||||
if (unsqueeze_axes.size() > 0) {
|
||||
// prepare input to issue auxiliary dimensions for batch
|
||||
auto unsqueeze_axes_const = make_shared<Constant>(element::i32, Shape{unsqueeze_axes.size()}, unsqueeze_axes);
|
||||
batched_input = make_shared<Unsqueeze>(input, unsqueeze_axes_const);
|
||||
auto unsqueeze_axes_const =
|
||||
make_shared<v0::Constant>(element::i32, Shape{unsqueeze_axes.size()}, unsqueeze_axes);
|
||||
batched_input = make_shared<v0::Unsqueeze>(input, unsqueeze_axes_const);
|
||||
}
|
||||
|
||||
auto input_shape = make_shared<ShapeOf>(batched_input, element::i32);
|
||||
auto input_shape = make_shared<v3::ShapeOf>(batched_input, element::i32);
|
||||
auto seq_lenghts = compute_sequence_lengths(input_shape, batch_axis, seq_axis);
|
||||
auto reverse_sequence = make_shared<ReverseSequence>(batched_input, seq_lenghts, batch_axis, seq_axis)->output(0);
|
||||
auto reverse_sequence =
|
||||
make_shared<v0::ReverseSequence>(batched_input, seq_lenghts, batch_axis, seq_axis)->output(0);
|
||||
|
||||
if (unsqueeze_axes.size() > 0) {
|
||||
// remove earlier added additional dimensions from the result
|
||||
auto squeeze_axes_const = make_shared<Constant>(element::i32, Shape{unsqueeze_axes.size()}, unsqueeze_axes);
|
||||
reverse_sequence = make_shared<Squeeze>(reverse_sequence, squeeze_axes_const);
|
||||
auto squeeze_axes_const = make_shared<v0::Constant>(element::i32, Shape{unsqueeze_axes.size()}, unsqueeze_axes);
|
||||
reverse_sequence = make_shared<v0::Squeeze>(reverse_sequence, squeeze_axes_const);
|
||||
}
|
||||
|
||||
set_node_name(node.get_name(), reverse_sequence.get_node_shared_ptr());
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/reverse_sequence.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -21,7 +22,7 @@ OutputVector translate_reverse_sequence_op(const NodeContext& node) {
|
||||
auto seq_dim = node.get_attribute<int64_t>("seq_dim");
|
||||
auto batch_dim = node.get_attribute<int64_t>("batch_dim", 0);
|
||||
|
||||
auto reverse_sequence = make_shared<ReverseSequence>(input, seq_lengths, batch_dim, seq_dim);
|
||||
auto reverse_sequence = make_shared<v0::ReverseSequence>(input, seq_lengths, batch_dim, seq_dim);
|
||||
set_node_name(node.get_name(), reverse_sequence);
|
||||
return {reverse_sequence};
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/broadcast.hpp"
|
||||
#include "openvino/op/scatter_nd_update.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -20,8 +21,8 @@ OutputVector translate_scatter_nd_op(const NodeContext& node) {
|
||||
auto shape = node.get_input(2);
|
||||
|
||||
auto input_data = create_same_type_const<int32_t>(updates, vector<int32_t>{0}, Shape{1});
|
||||
auto broadcast = make_shared<opset8::Broadcast>(input_data, shape);
|
||||
auto scatter_nd = make_shared<opset8::ScatterNDUpdate>(broadcast, input_indices, updates);
|
||||
auto broadcast = make_shared<v3::Broadcast>(input_data, shape);
|
||||
auto scatter_nd = make_shared<v3::ScatterNDUpdate>(broadcast, input_indices, updates);
|
||||
set_node_name(node.get_name(), scatter_nd);
|
||||
return {scatter_nd};
|
||||
}
|
||||
|
||||
@@ -3,12 +3,18 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset9.hpp"
|
||||
#include "openvino/op/add.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/embedding_segments_sum.hpp"
|
||||
#include "openvino/op/range.hpp"
|
||||
#include "openvino/op/reduce_max.hpp"
|
||||
#include "openvino/op/shape_of.hpp"
|
||||
#include "openvino/op/squeeze.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
using namespace ov::opset9;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -28,18 +34,18 @@ OutputVector translate_segment_sum_op(const NodeContext& node) {
|
||||
auto indices_type = segment_ids.get_element_type();
|
||||
// 1. compute a number of segments using segment_ids values
|
||||
// do not forget that segment ids are counting from zero
|
||||
auto reduction_axis = make_shared<Constant>(element::i32, Shape{1}, 0);
|
||||
auto num_segments_minus1 = make_shared<ReduceMax>(segment_ids, reduction_axis, false);
|
||||
auto num_segments = make_shared<Add>(num_segments_minus1, const_one);
|
||||
auto reduction_axis = make_shared<v0::Constant>(element::i32, Shape{1}, 0);
|
||||
auto num_segments_minus1 = make_shared<v1::ReduceMax>(segment_ids, reduction_axis, false);
|
||||
auto num_segments = make_shared<v1::Add>(num_segments_minus1, const_one);
|
||||
|
||||
// 2. generate indices input for EmbeddingSegmentSum
|
||||
// that will collect slices consequently from data for each segment
|
||||
auto squeeze_axis = make_shared<Constant>(element::i32, Shape{1}, 0);
|
||||
auto segment_ids_shape = make_shared<ShapeOf>(segment_ids, indices_type);
|
||||
auto num_indices = make_shared<Squeeze>(segment_ids_shape, squeeze_axis);
|
||||
auto indices = make_shared<Range>(const_zero, num_indices, const_one, indices_type);
|
||||
auto squeeze_axis = make_shared<v0::Constant>(element::i32, Shape{1}, 0);
|
||||
auto segment_ids_shape = make_shared<v3::ShapeOf>(segment_ids, indices_type);
|
||||
auto num_indices = make_shared<v0::Squeeze>(segment_ids_shape, squeeze_axis);
|
||||
auto indices = make_shared<v4::Range>(const_zero, num_indices, const_one, indices_type);
|
||||
|
||||
auto emb_segment_sum = make_shared<EmbeddingSegmentsSum>(data, indices, segment_ids, num_segments);
|
||||
auto emb_segment_sum = make_shared<v3::EmbeddingSegmentsSum>(data, indices, segment_ids, num_segments);
|
||||
set_node_name(node.get_name(), emb_segment_sum);
|
||||
return {emb_segment_sum};
|
||||
}
|
||||
|
||||
@@ -2,12 +2,20 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/select.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset10.hpp"
|
||||
#include "openvino/op/broadcast.hpp"
|
||||
#include "openvino/op/concat.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/reshape.hpp"
|
||||
#include "openvino/op/shape_of.hpp"
|
||||
#include "openvino/op/squeeze.hpp"
|
||||
#include "openvino/op/subtract.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
using namespace ov::opset10;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -18,7 +26,7 @@ OutputVector translate_select_base_op(const NodeContext& node,
|
||||
const Output<Node>& x,
|
||||
const Output<Node>& y) {
|
||||
// at this point all inputs are NumPy broadcastable
|
||||
auto select = make_shared<opset10::Select>(condition, x, y);
|
||||
auto select = make_shared<v1::Select>(condition, x, y);
|
||||
set_node_name(node.get_name(), select);
|
||||
return {select};
|
||||
}
|
||||
@@ -54,21 +62,21 @@ OutputVector translate_select_op(const NodeContext& node) {
|
||||
// compute number of dimensions to unsqueeze the condition
|
||||
auto cond_rank = compute_subgraph_scalar_rank(condition, element::i32);
|
||||
auto x_rank = compute_subgraph_scalar_rank(x, element::i32);
|
||||
auto num_new_axes = make_shared<Subtract>(x_rank, cond_rank);
|
||||
auto num_new_axes = make_shared<v1::Subtract>(x_rank, cond_rank);
|
||||
|
||||
// generate a new shape for the condition
|
||||
auto const_one = make_shared<Constant>(element::i32, Shape{1}, 1);
|
||||
auto new_subshape = make_shared<Broadcast>(const_one, num_new_axes);
|
||||
auto cond_shape = make_shared<ShapeOf>(condition, element::i32);
|
||||
auto const_one = make_shared<v0::Constant>(element::i32, Shape{1}, 1);
|
||||
auto new_subshape = make_shared<v3::Broadcast>(const_one, num_new_axes);
|
||||
auto cond_shape = make_shared<v3::ShapeOf>(condition, element::i32);
|
||||
// use extra dimensions in the begin to avoid concatenation of empty tensors that is not supported by Concat
|
||||
auto const_1 = make_shared<Constant>(element::i32, Shape{1}, 1);
|
||||
auto new_cond_shape = make_shared<Concat>(OutputVector{const_1, cond_shape, new_subshape}, 0);
|
||||
auto const_1 = make_shared<v0::Constant>(element::i32, Shape{1}, 1);
|
||||
auto new_cond_shape = make_shared<v0::Concat>(OutputVector{const_1, cond_shape, new_subshape}, 0);
|
||||
|
||||
// prepare the condition to have the same rank as operands `x` and `y`
|
||||
auto prep_cond = make_shared<Reshape>(condition, new_cond_shape, false)->output(0);
|
||||
auto prep_cond = make_shared<v1::Reshape>(condition, new_cond_shape, false)->output(0);
|
||||
// squeeze prep_cond by one extra dimension specially added
|
||||
auto const_0 = make_shared<Constant>(element::i32, Shape{1}, 0);
|
||||
prep_cond = make_shared<Squeeze>(prep_cond, const_0);
|
||||
auto const_0 = make_shared<v0::Constant>(element::i32, Shape{1}, 0);
|
||||
prep_cond = make_shared<v0::Squeeze>(prep_cond, const_0);
|
||||
|
||||
return translate_select_base_op(node, prep_cond, x, y);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/reduce_prod.hpp"
|
||||
#include "openvino/op/shape_of.hpp"
|
||||
#include "openvino/op/unsqueeze.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -23,13 +26,13 @@ ov::OutputVector translate_size_op(const NodeContext& node) {
|
||||
auto out_type = node.get_attribute<element::Type>("out_type", element::i32);
|
||||
|
||||
// introduce extra dimension in order to compute size in case of a scalar input
|
||||
auto const_zero = make_shared<Constant>(element::i32, Shape{1}, 0);
|
||||
input = make_shared<Unsqueeze>(input, const_zero);
|
||||
auto const_zero = make_shared<v0::Constant>(element::i32, Shape{1}, 0);
|
||||
input = make_shared<v0::Unsqueeze>(input, const_zero);
|
||||
|
||||
// compute the input tensor size
|
||||
auto shape_of = make_shared<ShapeOf>(input, out_type);
|
||||
auto axis = make_shared<Constant>(element::i32, Shape{}, 0);
|
||||
auto size = make_shared<ReduceProd>(shape_of, axis);
|
||||
auto shape_of = make_shared<v3::ShapeOf>(input, out_type);
|
||||
auto axis = make_shared<v0::Constant>(element::i32, Shape{}, 0);
|
||||
auto size = make_shared<v1::ReduceProd>(shape_of, axis);
|
||||
set_node_name(node.get_name(), size);
|
||||
return {size};
|
||||
}
|
||||
|
||||
@@ -2,12 +2,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/slice.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/add.hpp"
|
||||
#include "openvino/op/broadcast.hpp"
|
||||
#include "openvino/op/convert_like.hpp"
|
||||
#include "openvino/op/less.hpp"
|
||||
#include "openvino/op/select.hpp"
|
||||
#include "openvino/op/shape_of.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -25,25 +32,25 @@ OutputVector translate_slice_op(const NodeContext& node) {
|
||||
auto const_zero = create_same_type_const_scalar<int32_t>(start, 0);
|
||||
|
||||
// compute stop values in case non-negative sizes
|
||||
auto stop_pos = make_shared<Add>(start, size);
|
||||
auto stop_pos = make_shared<v1::Add>(start, size);
|
||||
|
||||
// compute stop values in case negative sizes
|
||||
// since TensorFlow supports only -1 among negative sizes
|
||||
// assign stop values to the data shape
|
||||
Output<Node> stop_neg = make_shared<ShapeOf>(input);
|
||||
stop_neg = make_shared<ConvertLike>(stop_neg, size);
|
||||
Output<Node> stop_neg = make_shared<v3::ShapeOf>(input);
|
||||
stop_neg = make_shared<v1::ConvertLike>(stop_neg, size);
|
||||
|
||||
// select the correct stop value based on a sign of size value
|
||||
auto negative_sizes_mask = make_shared<Less>(size, const_zero);
|
||||
auto negative_sizes_mask = make_shared<v1::Less>(size, const_zero);
|
||||
// TODO: investigate if we can simplify and replace Select with FloorMod operation
|
||||
// like FloorMod(size, input_shape)
|
||||
auto stop = make_shared<Select>(negative_sizes_mask, stop_neg, stop_pos);
|
||||
auto stop = make_shared<v1::Select>(negative_sizes_mask, stop_neg, stop_pos);
|
||||
|
||||
// broadcast step value
|
||||
auto start_shape = make_shared<ShapeOf>(start);
|
||||
auto step = make_shared<Broadcast>(const_one, start_shape);
|
||||
auto start_shape = make_shared<v3::ShapeOf>(start);
|
||||
auto step = make_shared<v3::Broadcast>(const_one, start_shape);
|
||||
|
||||
auto res = make_shared<Slice>(input, start, stop, step);
|
||||
auto res = make_shared<v8::Slice>(input, start, stop, step);
|
||||
set_node_name(node.get_name(), res);
|
||||
return res->outputs();
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/softmax.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -15,7 +16,7 @@ namespace op {
|
||||
OutputVector translate_softmax_op(const NodeContext& node) {
|
||||
default_op_checks(node, 1, {"Softmax"});
|
||||
auto logits = node.get_input(0);
|
||||
auto softmax = make_shared<opset8::Softmax>(logits, -1);
|
||||
auto softmax = make_shared<v8::Softmax>(logits, -1);
|
||||
set_node_name(node.get_name(), softmax);
|
||||
return {softmax};
|
||||
}
|
||||
|
||||
@@ -3,11 +3,18 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/batch_to_space.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/convert_like.hpp"
|
||||
#include "openvino/op/pad.hpp"
|
||||
#include "openvino/op/shape_of.hpp"
|
||||
#include "openvino/op/split.hpp"
|
||||
#include "openvino/op/squeeze.hpp"
|
||||
#include "openvino/op/subtract.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -23,34 +30,35 @@ void normalize_block_shape_pads_crops(const NodeContext& node,
|
||||
auto paddings_crops = node.get_input(2);
|
||||
|
||||
// make sure that paddings_crops and block_shape to have the same type
|
||||
paddings_crops = make_shared<ConvertLike>(paddings_crops, block_shape)->output(0);
|
||||
paddings_crops = make_shared<v1::ConvertLike>(paddings_crops, block_shape)->output(0);
|
||||
|
||||
// compute the input rank and a shape of block_shape [M]
|
||||
// it is needed to normalize block_shape, pads_begin and pads_end
|
||||
auto input_rank = compute_subgraph_scalar_rank(input, element::i32, false);
|
||||
auto M = make_shared<ShapeOf>(block_shape, element::i32);
|
||||
auto M = make_shared<v3::ShapeOf>(block_shape, element::i32);
|
||||
|
||||
// compute a number of padding elements required to normalize block_shape
|
||||
// in the beggining and in the end
|
||||
auto num_begin = make_shared<Constant>(element::i32, Shape{1}, 1);
|
||||
auto num_end = make_shared<Subtract>(input_rank, M)->output(0);
|
||||
num_end = make_shared<Subtract>(num_end, num_begin)->output(0);
|
||||
auto num_begin = make_shared<v0::Constant>(element::i32, Shape{1}, 1);
|
||||
auto num_end = make_shared<v1::Subtract>(input_rank, M)->output(0);
|
||||
num_end = make_shared<v1::Subtract>(num_end, num_begin)->output(0);
|
||||
|
||||
// split paddings of shape [M, 2] into pads_begin and pads_end of shape [M]
|
||||
auto split_axis = make_shared<Constant>(element::i32, Shape{}, 1);
|
||||
auto paddings_crops_split = make_shared<Split>(paddings_crops, split_axis, 2);
|
||||
pads_crops_begin = make_shared<Squeeze>(paddings_crops_split->output(0), split_axis)->output(0);
|
||||
pads_crops_end = make_shared<Squeeze>(paddings_crops_split->output(1), split_axis)->output(0);
|
||||
auto split_axis = make_shared<v0::Constant>(element::i32, Shape{}, 1);
|
||||
auto paddings_crops_split = make_shared<v1::Split>(paddings_crops, split_axis, 2);
|
||||
pads_crops_begin = make_shared<v0::Squeeze>(paddings_crops_split->output(0), split_axis)->output(0);
|
||||
pads_crops_end = make_shared<v0::Squeeze>(paddings_crops_split->output(1), split_axis)->output(0);
|
||||
|
||||
// normalize block_shape to have it of the same length as the input rank
|
||||
auto one_const = create_same_type_const_scalar<int32_t>(block_shape, 1);
|
||||
block_shape = make_shared<Pad>(block_shape, num_begin, num_end, one_const, ov::op::PadMode::CONSTANT)->output(0);
|
||||
block_shape =
|
||||
make_shared<v1::Pad>(block_shape, num_begin, num_end, one_const, ov::op::PadMode::CONSTANT)->output(0);
|
||||
|
||||
// normalize pads_begin and pads_end to have it of the same length as the input rank
|
||||
auto zero_const = create_same_type_const_scalar<int32_t>(pads_crops_begin, 0);
|
||||
auto pad_mode = ov::op::PadMode::CONSTANT;
|
||||
pads_crops_begin = make_shared<Pad>(pads_crops_begin, num_begin, num_end, zero_const, pad_mode)->output(0);
|
||||
pads_crops_end = make_shared<Pad>(pads_crops_end, num_begin, num_end, zero_const, pad_mode)->output(0);
|
||||
pads_crops_begin = make_shared<v1::Pad>(pads_crops_begin, num_begin, num_end, zero_const, pad_mode)->output(0);
|
||||
pads_crops_end = make_shared<v1::Pad>(pads_crops_end, num_begin, num_end, zero_const, pad_mode)->output(0);
|
||||
}
|
||||
|
||||
OutputVector translate_space_to_batch_nd_op(const NodeContext& node) {
|
||||
@@ -59,7 +67,7 @@ OutputVector translate_space_to_batch_nd_op(const NodeContext& node) {
|
||||
Output<Node> block_shape, pads_begin, pads_end;
|
||||
|
||||
normalize_block_shape_pads_crops(node, block_shape, pads_begin, pads_end);
|
||||
auto space_to_batch = make_shared<SpaceToBatch>(input, block_shape, pads_begin, pads_end);
|
||||
auto space_to_batch = make_shared<v1::SpaceToBatch>(input, block_shape, pads_begin, pads_end);
|
||||
set_node_name(node.get_name(), space_to_batch);
|
||||
return {space_to_batch};
|
||||
}
|
||||
@@ -70,7 +78,7 @@ OutputVector translate_batch_to_space_nd_op(const NodeContext& node) {
|
||||
Output<Node> block_shape, crops_begin, crops_end;
|
||||
|
||||
normalize_block_shape_pads_crops(node, block_shape, crops_begin, crops_end);
|
||||
auto batch_to_space = make_shared<BatchToSpace>(input, block_shape, crops_begin, crops_end);
|
||||
auto batch_to_space = make_shared<v1::BatchToSpace>(input, block_shape, crops_begin, crops_end);
|
||||
set_node_name(node.get_name(), batch_to_space);
|
||||
return {batch_to_space};
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/space_to_depth.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -27,8 +28,8 @@ OutputVector translate_space_to_depth_op(const NodeContext& node) {
|
||||
bool is_nhwc = (data_format == "NHWC");
|
||||
|
||||
convert_nhwc_to_nchw(is_nhwc, input_data);
|
||||
auto mode = SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
|
||||
auto space_to_depth = make_shared<SpaceToDepth>(input_data, mode, block_size)->output(0);
|
||||
auto mode = v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
|
||||
auto space_to_depth = make_shared<v0::SpaceToDepth>(input_data, mode, block_size)->output(0);
|
||||
convert_nchw_to_nhwc(is_nhwc, space_to_depth);
|
||||
set_node_name(node.get_name(), space_to_depth.get_node_shared_ptr());
|
||||
return {space_to_depth};
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/broadcast.hpp"
|
||||
#include "openvino/op/scatter_nd_update.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -26,16 +27,16 @@ OutputVector translate_sparse_to_dense_op(const NodeContext& node) {
|
||||
auto indices = node.get_input(0);
|
||||
auto dense_shape = node.get_input(1);
|
||||
auto values = node.get_input(2);
|
||||
shared_ptr<Broadcast> broadcast = nullptr;
|
||||
shared_ptr<v3::Broadcast> broadcast = nullptr;
|
||||
if (input_size == 3) {
|
||||
auto const_zero = create_same_type_const_scalar<int32_t>(values, 0);
|
||||
broadcast = make_shared<Broadcast>(const_zero, dense_shape);
|
||||
broadcast = make_shared<v3::Broadcast>(const_zero, dense_shape);
|
||||
} else {
|
||||
auto default_value = node.get_input(3);
|
||||
broadcast = make_shared<Broadcast>(default_value, dense_shape);
|
||||
broadcast = make_shared<v3::Broadcast>(default_value, dense_shape);
|
||||
}
|
||||
|
||||
auto scatternd = make_shared<ScatterNDUpdate>(broadcast, indices, values);
|
||||
auto scatternd = make_shared<v3::ScatterNDUpdate>(broadcast, indices, values);
|
||||
set_node_name(node.get_name(), scatternd);
|
||||
return {scatternd};
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/split.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/variadic_split.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -19,7 +21,7 @@ OutputVector translate_split_op(const NodeContext& node) {
|
||||
auto value = node.get_input(1);
|
||||
auto num_split = node.get_attribute<int64_t>("num_split");
|
||||
|
||||
auto split = make_shared<Split>(value, axis, num_split);
|
||||
auto split = make_shared<v1::Split>(value, axis, num_split);
|
||||
set_node_name(node.get_name(), split);
|
||||
return split->outputs();
|
||||
}
|
||||
@@ -30,7 +32,7 @@ OutputVector translate_split_v_op(const NodeContext& node) {
|
||||
auto size_splits = node.get_input(1);
|
||||
auto axis = node.get_input(2);
|
||||
|
||||
auto splitv = make_shared<VariadicSplit>(value, axis, size_splits);
|
||||
auto splitv = make_shared<v1::VariadicSplit>(value, axis, size_splits);
|
||||
set_node_name(node.get_name(), splitv);
|
||||
return splitv->outputs();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/power.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -18,7 +18,7 @@ OutputVector translate_sqrt_op(const NodeContext& node) {
|
||||
default_op_checks(node, 1, {"Sqrt", "SQRT"});
|
||||
auto input = node.get_input(0);
|
||||
auto exponent = create_same_type_const_scalar<float>(input, 0.5f);
|
||||
auto sqrt_node = make_shared<Power>(input, exponent);
|
||||
auto sqrt_node = make_shared<v1::Power>(input, exponent);
|
||||
set_node_name(node.get_name(), sqrt_node);
|
||||
return {sqrt_node};
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/squeeze.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -23,8 +25,8 @@ OutputVector translate_squeeze_op(const NodeContext& node) {
|
||||
// check deprecated name
|
||||
axis = node.get_attribute<std::vector<int64_t>>("squeeze_dims", {});
|
||||
}
|
||||
auto axis_const = make_shared<Constant>(element::i32, Shape{axis.size()}, axis);
|
||||
auto squeeze = make_shared<Squeeze>(input, axis_const);
|
||||
auto axis_const = make_shared<v0::Constant>(element::i32, Shape{axis.size()}, axis);
|
||||
auto squeeze = make_shared<v0::Squeeze>(input, axis_const);
|
||||
set_node_name(node.get_name(), squeeze);
|
||||
return {squeeze};
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/strided_slice.hpp"
|
||||
|
||||
#include <climits>
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov::opset8;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
@@ -55,15 +56,15 @@ OutputVector translate_strided_slice_op(const NodeContext& node) {
|
||||
ellipsis_mask.resize(max_length, 0);
|
||||
shrink_axis_mask.resize(max_length, 0);
|
||||
|
||||
auto strided_slice = make_shared<StridedSlice>(input,
|
||||
begin,
|
||||
end,
|
||||
strides,
|
||||
begin_mask,
|
||||
end_mask,
|
||||
new_axis_mask,
|
||||
shrink_axis_mask,
|
||||
ellipsis_mask);
|
||||
auto strided_slice = make_shared<v1::StridedSlice>(input,
|
||||
begin,
|
||||
end,
|
||||
strides,
|
||||
begin_mask,
|
||||
end_mask,
|
||||
new_axis_mask,
|
||||
shrink_axis_mask,
|
||||
ellipsis_mask);
|
||||
set_node_name(node.get_name(), strided_slice);
|
||||
return {strided_slice};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user