[TF FE] Speed up compilation - part 1 (#21144)

Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>
This commit is contained in:
Roman Kazantsev authored and GitHub committed 2023-11-17 10:26:28 +00:00
1 parent e4311aae46
commit b380eb06ee
11 files changed
+155 -115

No files matched your search

@@ -3,10 +3,12 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/result.hpp"
using namespace std;
using namespace ov::opset10;
using namespace ov;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -14,16 +16,16 @@ namespace tensorflow {
namespace op {
OutputVector translate_input_arg_op(const NodeContext& node) {
default_op_checks(node, 0, {"input_arg"});
auto param_type = node.get_attribute<ov::element::Type>("type");
auto param_type = node.get_attribute<element::Type>("type");
auto param = std::make_shared<Parameter>(param_type, ov::PartialShape::dynamic());
auto param = std::make_shared<v0::Parameter>(param_type, PartialShape::dynamic());
set_node_name(node.get_name(), param);
return param->outputs();
}
OutputVector translate_output_arg_op(const NodeContext& node) {
default_op_checks(node, 1, {"output_arg"});
auto result = std::make_shared<Result>(node.get_input(0));
auto result = std::make_shared<v0::Result>(node.get_input(0));
set_node_name(node.get_name(), result);
return result->outputs();
}
@@ -2,11 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/avg_pool.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 {
@@ -46,14 +47,14 @@ OutputVector translate_avg_pool_op(const NodeContext& node) {
convert_nhwc_to_hw(is_nhwc, tf_ksize, kernel_shape);
convert_nhwc_to_nchw(is_nhwc, input, ov::Rank(spatial_dim + 2));
auto avg_pool = make_shared<AvgPool>(input,
strides,
Shape({}),
Shape({}),
kernel_shape,
true,
ov::op::RoundingType::FLOOR,
auto_pad);
auto avg_pool = make_shared<v1::AvgPool>(input,
strides,
Shape({}),
Shape({}),
kernel_shape,
true,
ov::op::RoundingType::FLOOR,
auto_pad);
auto avg_pool_output = avg_pool->output(0);
convert_nchw_to_nhwc(is_nhwc, avg_pool_output, ov::Rank(spatial_dim + 2));
set_node_name(node.get_name(), avg_pool_output.get_node_shared_ptr());
@@ -3,10 +3,12 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/unsqueeze.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -42,11 +44,12 @@ OutputVector translate_bias_add_op(const NodeContext& node) {
axes_unsqueeze.push_back(dim_ind);
}
}
auto axes_unsqueeze_node = make_shared<Constant>(element::i64, Shape{axes_unsqueeze.size()}, axes_unsqueeze);
bias_reshaped = make_shared<Unsqueeze>(bias, axes_unsqueeze_node);
auto axes_unsqueeze_node =
make_shared<v0::Constant>(element::i64, Shape{axes_unsqueeze.size()}, axes_unsqueeze);
bias_reshaped = make_shared<v0::Unsqueeze>(bias, axes_unsqueeze_node);
}
auto res = make_shared<Add>(value, bias_reshaped);
auto res = make_shared<v1::Add>(value, bias_reshaped);
set_node_name(node.get_name(), res);
return res->outputs();
}
@@ -3,10 +3,33 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset13.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/bitwise_and.hpp"
#include "openvino/op/bitwise_or.hpp"
#include "openvino/op/bitwise_xor.hpp"
#include "openvino/op/divide.hpp"
#include "openvino/op/equal.hpp"
#include "openvino/op/floor.hpp"
#include "openvino/op/floor_mod.hpp"
#include "openvino/op/greater.hpp"
#include "openvino/op/greater_eq.hpp"
#include "openvino/op/less.hpp"
#include "openvino/op/less_eq.hpp"
#include "openvino/op/logical_and.hpp"
#include "openvino/op/logical_or.hpp"
#include "openvino/op/logical_xor.hpp"
#include "openvino/op/maximum.hpp"
#include "openvino/op/minimum.hpp"
#include "openvino/op/mod.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/not_equal.hpp"
#include "openvino/op/power.hpp"
#include "openvino/op/prelu.hpp"
#include "openvino/op/squared_difference.hpp"
#include "openvino/op/subtract.hpp"
using namespace std;
using namespace ov::opset13;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -25,7 +48,7 @@ OutputVector translate_binary_op(const NodeContext& node,
OutputVector translate_floor_div_op(const NodeContext& node) {
auto floordiv_fn = [](const Output<Node>& x, const Output<Node>& y) {
return make_shared<Floor>(make_shared<Divide>(x, y));
return make_shared<v0::Floor>(make_shared<v1::Divide>(x, y));
};
return translate_binary_op(node, floordiv_fn);
}
@@ -37,29 +60,29 @@ OutputVector translate_binary_op(const NodeContext& node) {
});
}
template OutputVector translate_binary_op<Add>(const NodeContext& node);
template OutputVector translate_binary_op<BitwiseAnd>(const NodeContext& node);
template OutputVector translate_binary_op<BitwiseOr>(const NodeContext& node);
template OutputVector translate_binary_op<BitwiseXor>(const NodeContext& node);
template OutputVector translate_binary_op<Equal>(const NodeContext& node);
template OutputVector translate_binary_op<FloorMod>(const NodeContext& node);
template OutputVector translate_binary_op<Greater>(const NodeContext& node);
template OutputVector translate_binary_op<GreaterEqual>(const NodeContext& node);
template OutputVector translate_binary_op<Less>(const NodeContext& node);
template OutputVector translate_binary_op<LessEqual>(const NodeContext& node);
template OutputVector translate_binary_op<LogicalAnd>(const NodeContext& node);
template OutputVector translate_binary_op<LogicalOr>(const NodeContext& node);
template OutputVector translate_binary_op<LogicalXor>(const NodeContext& node);
template OutputVector translate_binary_op<Maximum>(const NodeContext& node);
template OutputVector translate_binary_op<Minimum>(const NodeContext& node);
template OutputVector translate_binary_op<Multiply>(const NodeContext& node);
template OutputVector translate_binary_op<Mod>(const NodeContext& node);
template OutputVector translate_binary_op<NotEqual>(const NodeContext& node);
template OutputVector translate_binary_op<Power>(const NodeContext& node);
template OutputVector translate_binary_op<PRelu>(const NodeContext& node);
template OutputVector translate_binary_op<Divide>(const NodeContext& node);
template OutputVector translate_binary_op<SquaredDifference>(const NodeContext& node);
template OutputVector translate_binary_op<Subtract>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Add>(const NodeContext& node);
template OutputVector translate_binary_op<v13::BitwiseAnd>(const NodeContext& node);
template OutputVector translate_binary_op<v13::BitwiseOr>(const NodeContext& node);
template OutputVector translate_binary_op<v13::BitwiseXor>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Equal>(const NodeContext& node);
template OutputVector translate_binary_op<v1::FloorMod>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Greater>(const NodeContext& node);
template OutputVector translate_binary_op<v1::GreaterEqual>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Less>(const NodeContext& node);
template OutputVector translate_binary_op<v1::LessEqual>(const NodeContext& node);
template OutputVector translate_binary_op<v1::LogicalAnd>(const NodeContext& node);
template OutputVector translate_binary_op<v1::LogicalOr>(const NodeContext& node);
template OutputVector translate_binary_op<v1::LogicalXor>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Maximum>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Minimum>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Multiply>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Mod>(const NodeContext& node);
template OutputVector translate_binary_op<v1::NotEqual>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Power>(const NodeContext& node);
template OutputVector translate_binary_op<v0::PRelu>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Divide>(const NodeContext& node);
template OutputVector translate_binary_op<v0::SquaredDifference>(const NodeContext& node);
template OutputVector translate_binary_op<v1::Subtract>(const NodeContext& node);
} // namespace op
} // namespace tensorflow
@@ -3,11 +3,14 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/maximum.hpp"
#include "openvino/op/pad.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/subtract.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -19,20 +22,20 @@ OutputVector translate_broadcast_args_op(const NodeContext& node) {
auto s1 = node.get_input(1);
// compute a number of shape elements to append for broadcasting
auto size0 = make_shared<ShapeOf>(s0);
auto size1 = make_shared<ShapeOf>(s1);
auto max_size = make_shared<Maximum>(size0, size1);
auto diff1 = make_shared<Subtract>(max_size, size0);
auto diff2 = make_shared<Subtract>(max_size, size1);
auto size0 = make_shared<v3::ShapeOf>(s0);
auto size1 = make_shared<v3::ShapeOf>(s1);
auto max_size = make_shared<v1::Maximum>(size0, size1);
auto diff1 = make_shared<v1::Subtract>(max_size, size0);
auto diff2 = make_shared<v1::Subtract>(max_size, size1);
// pad the shortest shape value with minus ones
// to take dynamic shapes into account
auto const_zero = create_same_type_const<int64_t>(diff1, std::vector<int64_t>{0}, Shape{1});
auto const_minus_one = create_same_type_const_scalar<int64_t>(s0, -1);
auto padded_s0 = make_shared<Pad>(s0, diff1, const_zero, const_minus_one, ov::op::PadMode::CONSTANT);
auto padded_s1 = make_shared<Pad>(s1, diff2, const_zero, const_minus_one, ov::op::PadMode::CONSTANT);
auto padded_s0 = make_shared<v1::Pad>(s0, diff1, const_zero, const_minus_one, ov::op::PadMode::CONSTANT);
auto padded_s1 = make_shared<v1::Pad>(s1, diff2, const_zero, const_minus_one, ov::op::PadMode::CONSTANT);
auto broadcasted_shape = make_shared<Maximum>(padded_s0, padded_s1);
auto broadcasted_shape = make_shared<v1::Maximum>(padded_s0, padded_s1);
set_node_name(node.get_name(), broadcasted_shape);
return {broadcasted_shape};
}
@@ -3,10 +3,10 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/broadcast.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -16,7 +16,7 @@ OutputVector translate_broadcast_to_op(const NodeContext& node) {
default_op_checks(node, 2, {"BroadcastTo"});
auto input = node.get_input(0);
auto shape = node.get_input(1);
auto broadcast_to = make_shared<Broadcast>(input, shape);
auto broadcast_to = make_shared<v3::Broadcast>(input, shape);
set_node_name(node.get_name(), broadcast_to);
return {broadcast_to};
}
@@ -2,11 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/bucketize.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 {
@@ -20,10 +22,10 @@ OutputVector translate_bucketize_op(const NodeContext& node) {
auto boundaries = node.get_attribute<std::vector<float>>("boundaries");
auto bucketize =
make_shared<Bucketize>(input,
make_shared<Constant>(ov::element::f32, Shape{boundaries.size()}, boundaries),
ov::element::i32,
false);
make_shared<v3::Bucketize>(input,
make_shared<v0::Constant>(ov::element::f32, Shape{boundaries.size()}, boundaries),
ov::element::i32,
false);
set_node_name(node.get_name(), bucketize);
return {bucketize};
}
@@ -3,10 +3,11 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/op/maximum.hpp"
#include "openvino/op/minimum.hpp"
using namespace std;
using namespace ov::opset10;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -20,10 +21,10 @@ OutputVector translate_clip_by_value_op(const NodeContext& node) {
// it can be case that clip_value_min > clip_value_max
// in this case both values are equal to clip_value_min
clip_value_max = make_shared<Maximum>(clip_value_min, clip_value_max);
clip_value_max = make_shared<v1::Maximum>(clip_value_min, clip_value_max);
auto clip_by_min = make_shared<Maximum>(t, clip_value_min);
auto clip_by_max = make_shared<Minimum>(clip_by_min, clip_value_max);
auto clip_by_min = make_shared<v1::Maximum>(t, clip_value_min);
auto clip_by_max = make_shared<v1::Minimum>(clip_by_min, clip_value_max);
set_node_name(node.get_name(), clip_by_max);
return {clip_by_max};
@@ -2,12 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/op/concat.hpp"
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
using namespace std;
using namespace ov;
using namespace opset8;
using namespace ov::op;
using namespace ov::frontend;
using namespace ov::frontend::tensorflow;
@@ -67,7 +68,7 @@ OutputVector translate_concat_op(const NodeContext& node) {
axis += input_rank.get_length();
}
auto concat = make_shared<Concat>(inputs, axis);
auto concat = make_shared<v0::Concat>(inputs, axis);
set_node_name(node.get_name(), concat);
return {concat};
}
@@ -3,12 +3,14 @@
//
#include "common_op_table.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convolution.hpp"
#include "openvino/op/strided_slice.hpp"
#include "openvino/op/util/attr_types.hpp"
#include "openvino/opsets/opset8.hpp"
#include "utils.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -76,31 +78,31 @@ OutputVector translate_conv_2d_backprop_input_op(const NodeContext& node) {
convert_nhwc_to_nchw(is_nhwc, out_backprop, ov::Rank(4));
// initially think that output shape defined for NCHW layout
auto ss_begin = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{2});
auto ss_end = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{4});
auto ss_strides = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
auto ss_begin = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{2});
auto ss_end = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{4});
auto ss_strides = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
// change range of indices for spatial dimensions in case NHWC layout
if (is_nhwc) {
ss_begin = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
ss_end = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{3});
ss_begin = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
ss_end = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{3});
}
auto spatial_shape = make_shared<StridedSlice>(input_sizes,
ss_begin,
ss_end,
ss_strides,
std::vector<int64_t>{},
std::vector<int64_t>{});
auto spatial_shape = make_shared<v1::StridedSlice>(input_sizes,
ss_begin,
ss_end,
ss_strides,
std::vector<int64_t>{},
std::vector<int64_t>{});
auto conv_backprop = make_shared<ConvolutionBackpropData>(out_backprop,
filter,
spatial_shape,
strides,
pads_begin,
pads_end,
dilations,
auto_pad);
auto conv_backprop = make_shared<v1::ConvolutionBackpropData>(out_backprop,
filter,
spatial_shape,
strides,
pads_begin,
pads_end,
dilations,
auto_pad);
// insert Transpose only if original Conv2DBackpropInput is in NHWC layout
auto conv_backprop_output = conv_backprop->output(0);
@@ -3,10 +3,12 @@
//
#include "common_op_table.hpp"
#include "openvino/opsets/opset8.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convolution.hpp"
#include "openvino/op/strided_slice.hpp"
using namespace std;
using namespace ov::opset8;
using namespace ov::op;
namespace ov {
namespace frontend {
@@ -78,31 +80,31 @@ OutputVector translate_conv_3d_backprop_input_v2_op(const NodeContext& node) {
convert_nhwc_to_nchw(is_nhwc, out_backprop, ov::Rank(5));
// initially think that output shape defined for NCDHW layout
auto ss_begin = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{2});
auto ss_end = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{5});
auto ss_strides = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
auto ss_begin = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{2});
auto ss_end = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{5});
auto ss_strides = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
// change range of indices for spatial dimensions in case NDHWC layout
if (is_nhwc) {
ss_begin = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
ss_end = make_shared<Constant>(element::i64, Shape{1}, std::vector<int64_t>{4});
ss_begin = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{1});
ss_end = make_shared<v0::Constant>(element::i64, Shape{1}, std::vector<int64_t>{4});
}
auto spatial_shape = make_shared<StridedSlice>(input_sizes,
ss_begin,
ss_end,
ss_strides,
std::vector<int64_t>{},
std::vector<int64_t>{});
auto spatial_shape = make_shared<v1::StridedSlice>(input_sizes,
ss_begin,
ss_end,
ss_strides,
std::vector<int64_t>{},
std::vector<int64_t>{});
auto conv_backprop = make_shared<ConvolutionBackpropData>(out_backprop,
filter,
spatial_shape,
strides,
pads_begin,
pads_end,
dilations,
auto_pad);
auto conv_backprop = make_shared<v1::ConvolutionBackpropData>(out_backprop,
filter,
spatial_shape,
strides,
pads_begin,
pads_end,
dilations,
auto_pad);
// insert Transpose only if original Conv3DBackpropInput is in NDHWC layout
auto conv_backprop_output = conv_backprop->output(0);