[core]Remove deprecated function from Loop (#21299)

* Migrate leftovers in Loop operator to new API
- use new version of `get_constant_from_source`
- migrate `is_rank_compatible_any_of` to dev API
- Improve rank compatibility checks

* Use new version of `is_rank_compatible_any_of`
instead deprecated to reduce bin-size

* Remove deprecated `is_rank_compatible_any_of`
This commit is contained in:
Pawel Raasz 2023-11-28 07:37:15 +01:00 committed by GitHub
parent 01b4faf47f
commit 53baeacc2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 105 deletions

View File

@ -91,5 +91,13 @@ bool try_apply_auto_padding(const PartialShape& image_shape,
/// @param tensors Input tensors vector to get their shapes.
/// @return Vector of partial shapes same size as input tensor vector.
OPENVINO_API std::vector<PartialShape> get_tensors_partial_shapes(const TensorVector& tensors);
/// \brief Check if rank is compatible to any of others ranks.
///
/// \param r Rank to check.
/// \param others List of ranks used to check compatibility.
///
/// \return True if rank compatible to any of others, otherwise false.
OPENVINO_API bool is_rank_compatible_any_of(const Rank& r, std::initializer_list<Rank> others);
} // namespace util
} // namespace ov

View File

@ -180,13 +180,4 @@ OPENVINO_API bool has_no_labels(const TensorLabel& labels);
OPENVINO_DEPRECATED("This function is deprecated and will be moved to dev api in 2024.0 release.")
OPENVINO_API std::vector<PartialShape> get_node_input_partial_shapes(const ov::Node& node);
/// \brief Check if rank is compatible to any of rank from container.
///
/// \param rank Rank to check.
/// \param ranks VEctor of ranks used to check input rank compatibility.
///
/// \return True if rank compatible to any from ranks, otherwise false.
OPENVINO_DEPRECATED("This function is deprecated and will be moved to dev api in 2024.0 release.")
OPENVINO_API bool is_rank_compatible_any_of(const ov::Rank& rank, const std::vector<ov::Rank>& ranks);
} // namespace ov

View File

@ -285,12 +285,10 @@ void append_spatial_shape(const TOp* op,
namespace validate {
template <class TShape>
void data_shape(const ov::op::util::ConvolutionBase* op, const TShape& data_shape) {
OPENVINO_SUPPRESS_DEPRECATED_START
NODE_VALIDATION_CHECK(op,
is_rank_compatible_any_of(data_shape.rank(), {3, 4, 5}),
ov::util::is_rank_compatible_any_of(data_shape.rank(), {3, 4, 5}),
"Expected a 3D, 4D or 5D tensor for the input. Got: ",
data_shape);
OPENVINO_SUPPRESS_DEPRECATED_END
}
template <class TShape>

View File

@ -30,12 +30,10 @@ template <class TOp, class TShape>
void attributes(const TOp* op, const TShape& data_shape, const Strides& dilations) {
const auto& data_rank = data_shape.rank();
OPENVINO_SUPPRESS_DEPRECATED_START
NODE_VALIDATION_CHECK(op,
is_rank_compatible_any_of(data_rank, {3, 4, 5}),
ov::util::is_rank_compatible_any_of(data_rank, {3, 4, 5}),
"Expected a 3D, 4D or 5D tensor for the input. Got: ",
data_shape);
OPENVINO_SUPPRESS_DEPRECATED_END
const auto& kernel = op->get_kernel();
const auto num_spatial = kernel.size();
@ -252,7 +250,7 @@ TRShape out_shape_infer(const TOp* op, const std::vector<TShape>& input_shapes,
OPENVINO_SUPPRESS_DEPRECATED_START
NODE_VALIDATION_CHECK(op,
is_rank_compatible_any_of(data_rank, {3, 4, 5}),
ov::util::is_rank_compatible_any_of(data_rank, {3, 4, 5}),
"Expected a 3D, 4D or 5D tensor for the input. Got: ",
data_shape);
OPENVINO_SUPPRESS_DEPRECATED_END

View File

@ -22,13 +22,11 @@ std::vector<TRShape> shape_infer(const util::ScatterElementsUpdateBase* op,
const auto& updates_shape = input_shapes[2];
const auto& axis_shape = input_shapes[3];
OPENVINO_SUPPRESS_DEPRECATED_START
NODE_VALIDATION_CHECK(op,
is_rank_compatible_any_of(axis_shape.rank(), {0, 1}),
ov::util::is_rank_compatible_any_of(axis_shape.rank(), {0, 1}),
"Axis input shape are required to be scalar or 1D tensor. ",
"Got: ",
axis_shape);
OPENVINO_SUPPRESS_DEPRECATED_END
const auto& data_rank = data_shape.rank();
const auto& indices_rank = indices_shape.rank();

View File

@ -40,12 +40,10 @@ std::vector<TRShape> shape_infer(const Squeeze* op,
unique_axes.reset(new std::set<int64_t>());
} else if (number_of_inputs == 2) {
const auto& axes_shape = input_shapes[1];
OPENVINO_SUPPRESS_DEPRECATED_START
NODE_VALIDATION_CHECK(op,
axes_shape.is_dynamic() || is_rank_compatible_any_of(axes_shape.rank(), {0, 1}),
axes_shape.is_dynamic() || ov::util::is_rank_compatible_any_of(axes_shape.rank(), {0, 1}),
"Second input (axes) should not be of rank higher than 1. Got: ",
axes_shape.rank().get_length());
OPENVINO_SUPPRESS_DEPRECATED_END
std::vector<int64_t> axes;
if (arg_rank.is_static() && axes_shape.is_static()) {

View File

@ -12,12 +12,10 @@ namespace v0 {
template <class TOp>
void check_unsqueeze_axes_rank(const TOp* op, const Rank& rank) {
OPENVINO_SUPPRESS_DEPRECATED_START
NODE_VALIDATION_CHECK(op,
is_rank_compatible_any_of(rank, {0, 1}),
ov::util::is_rank_compatible_any_of(rank, {0, 1}),
"Second input (axes) should not be of rank higher than 1. Got: ",
rank);
OPENVINO_SUPPRESS_DEPRECATED_END
}
template <class TShape, class TRShape = result_shape_t<TShape>>

View File

@ -11,13 +11,17 @@
#include "openvino/op/tensor_iterator.hpp"
#include "openvino/reference/loop.hpp"
#include "openvino/runtime/tensor.hpp"
#include "validation_util.hpp"
ov::op::v5::Loop::Loop(const Output<Node>& trip_count, const Output<Node>& execution_condition) : SubGraphOp() {
namespace ov {
namespace op {
namespace v5 {
Loop::Loop(const Output<Node>& trip_count, const Output<Node>& execution_condition) : SubGraphOp() {
set_argument(0, trip_count);
set_argument(1, execution_condition);
}
bool ov::op::v5::Loop::visit_attributes(AttributeVisitor& visitor) {
bool Loop::visit_attributes(AttributeVisitor& visitor) {
OV_OP_SCOPE(v5_Loop_visit_attributes);
visitor.on_attribute("body", m_bodies[0]);
visitor.on_attribute("input_descriptions", m_input_descriptions[0]);
@ -27,7 +31,7 @@ bool ov::op::v5::Loop::visit_attributes(AttributeVisitor& visitor) {
return true;
}
void ov::op::v5::Loop::validate_and_infer_types() {
void Loop::validate_and_infer_types() {
OV_OP_SCOPE(v5_Loop_validate_and_infer_types);
NODE_VALIDATION_CHECK(this, m_bodies.size() == 1, "Number of bodies for loop is greater than 1");
@ -43,23 +47,17 @@ void ov::op::v5::Loop::validate_and_infer_types() {
.at(m_special_body_ports.current_iteration_input_idx)
->get_partial_shape()
.rank();
if (cur_iter_rank.is_static()) {
NODE_VALIDATION_CHECK(this,
cur_iter_rank.compatible(1) || cur_iter_rank.compatible(0),
"Rank of CurrentIteration input must be equal to 0 or 1");
}
NODE_VALIDATION_CHECK(this,
ov::util::is_rank_compatible_any_of(cur_iter_rank, {0, 1}),
"Rank of CurrentIteration input must be equal to 0 or 1");
}
bool zero_number_of_iter = false;
const auto& loop_execution_condition = input_value(1);
const auto& loop_condition_rank = loop_execution_condition.get_partial_shape().rank();
if (loop_condition_rank.is_static()) {
NODE_VALIDATION_CHECK(this,
loop_condition_rank.compatible(1) || loop_condition_rank.compatible(0),
"Rank of ExecutionCondition input must be equal to 0 or 1");
}
OPENVINO_SUPPRESS_DEPRECATED_START
if (const auto& cond_value = ov::get_constant_from_source(loop_execution_condition)) {
OPENVINO_SUPPRESS_DEPRECATED_END
NODE_VALIDATION_CHECK(this,
ov::util::is_rank_compatible_any_of(loop_condition_rank, {0, 1}),
"Rank of ExecutionCondition input must be equal to 0 or 1");
if (const auto& cond_value = ov::util::get_constant_from_source(loop_execution_condition)) {
auto val = cond_value->cast_vector<bool>();
NODE_VALIDATION_CHECK(this,
val.size() == 1,
@ -78,14 +76,10 @@ void ov::op::v5::Loop::validate_and_infer_types() {
const auto& body_execution_condition =
m_bodies[0]->get_results().at(m_special_body_ports.body_condition_output_idx)->input_value(0);
const auto& body_condition_rank = body_execution_condition.get_partial_shape().rank();
if (body_condition_rank.is_static()) {
NODE_VALIDATION_CHECK(this,
body_condition_rank.compatible(0) || body_condition_rank.compatible(1),
"Rank of BodyExecutionCondition output must be equal to 0 or 1");
}
OPENVINO_SUPPRESS_DEPRECATED_START
if (const auto& cond_value = get_constant_from_source(body_execution_condition)) {
OPENVINO_SUPPRESS_DEPRECATED_END
NODE_VALIDATION_CHECK(this,
ov::util::is_rank_compatible_any_of(body_condition_rank, {0, 1}),
"Rank of BodyExecutionCondition output must be equal to 0 or 1");
if (const auto& cond_value = ov::util::get_constant_from_source(body_execution_condition)) {
auto val = cond_value->cast_vector<bool>();
NODE_VALIDATION_CHECK(this,
val.size() == 1,
@ -96,14 +90,12 @@ void ov::op::v5::Loop::validate_and_infer_types() {
} else {
m_num_iterations = 1; // condition_always_false, do_while mode
}
} else if (const auto& cond_param = std::dynamic_pointer_cast<const ov::op::v0::Parameter>(
body_execution_condition.get_node_shared_ptr())) {
} else if (const auto& cond_param =
std::dynamic_pointer_cast<const op::v0::Parameter>(body_execution_condition.get_node_shared_ptr())) {
// Const(true or false) -> Loop (body: Parameter -> execution_condition output)
for (const auto& desc : get_input_descriptions()) {
if (m_bodies[0]->get_parameters().at(desc->m_body_parameter_index) == cond_param) {
OPENVINO_SUPPRESS_DEPRECATED_START
if (const auto& cond_value = get_constant_from_source(input_value(desc->m_input_index))) {
OPENVINO_SUPPRESS_DEPRECATED_END
if (const auto& cond_value = ov::util::get_constant_from_source(input_value(desc->m_input_index))) {
auto val = cond_value->cast_vector<bool>();
NODE_VALIDATION_CHECK(this,
val.size() == 1,
@ -121,14 +113,10 @@ void ov::op::v5::Loop::validate_and_infer_types() {
const auto& trip_count = input_value(0);
const auto& trip_count_rank = trip_count.get_partial_shape().rank();
if (trip_count_rank.is_static()) {
NODE_VALIDATION_CHECK(this,
trip_count_rank.compatible(1) || trip_count_rank.compatible(0),
"Rank of TripCount input must be equal to 0 or 1");
}
OPENVINO_SUPPRESS_DEPRECATED_START
if (const auto& trip_count_val = get_constant_from_source(trip_count)) {
OPENVINO_SUPPRESS_DEPRECATED_END
NODE_VALIDATION_CHECK(this,
ov::util::is_rank_compatible_any_of(trip_count_rank, {0, 1}),
"Rank of TripCount input must be equal to 0 or 1");
if (const auto& trip_count_val = ov::util::get_constant_from_source(trip_count)) {
auto val = trip_count_val->cast_vector<int64_t>();
NODE_VALIDATION_CHECK(this,
val.size() == 1,
@ -163,22 +151,22 @@ void ov::op::v5::Loop::validate_and_infer_types() {
for (const auto& input_description : m_input_descriptions[0]) {
auto index = input_description->m_input_index;
if (auto slice_input_description = ov::as_type_ptr<SliceInputDescription>(input_description)) {
if (auto slice_input_description = as_type_ptr<SliceInputDescription>(input_description)) {
auto body_parameter = m_bodies[0]->get_parameters().at(slice_input_description->m_body_parameter_index);
const auto& input_partial_shape = inputs().at(index).get_source_output().get_partial_shape();
const auto& input_type = inputs().at(index).get_source_output().get_element_type();
body_parameter->set_element_type(input_type);
if (input_partial_shape.rank().is_dynamic()) {
body_parameter->set_partial_shape(ov::PartialShape::dynamic());
body_parameter->set_partial_shape(PartialShape::dynamic());
} else {
auto out_shape = input_partial_shape;
OPENVINO_SUPPRESS_DEPRECATED_START
const auto axis = ov::normalize_axis(this, slice_input_description->m_axis, input_partial_shape.rank());
const auto axis = normalize_axis(this, slice_input_description->m_axis, input_partial_shape.rank());
OPENVINO_SUPPRESS_DEPRECATED_END
out_shape[axis] = slice_input_description->m_part_size;
body_parameter->set_partial_shape(out_shape);
}
} else if (auto merged_input_description = ov::as_type_ptr<MergedInputDescription>(input_description)) {
} else if (auto merged_input_description = as_type_ptr<MergedInputDescription>(input_description)) {
auto body_value = m_bodies[0]->get_results().at(merged_input_description->m_body_value_index);
auto body_parameter = m_bodies[0]->get_parameters().at(merged_input_description->m_body_parameter_index);
@ -190,7 +178,7 @@ void ov::op::v5::Loop::validate_and_infer_types() {
body_parameter->set_element_type(input_type);
back_edges[merged_input_description->m_body_value_index] = merged_input_description->m_body_parameter_index;
} else if (auto invariant_input_description =
ov::as_type_ptr<ov::op::v0::TensorIterator::InvariantInputDescription>(input_description)) {
as_type_ptr<op::v0::TensorIterator::InvariantInputDescription>(input_description)) {
auto body_parameter = m_bodies[0]->get_parameters().at(invariant_input_description->m_body_parameter_index);
auto input_partial_shape = input(index).get_partial_shape();
@ -214,10 +202,10 @@ void ov::op::v5::Loop::validate_and_infer_types() {
auto body_value = m_bodies[0]->get_results().at(output_description->m_body_value_index)->input_value(0);
if (auto body_output_description =
ov::as_type_ptr<v0::TensorIterator::BodyOutputDescription>(output_description)) {
as_type_ptr<v0::TensorIterator::BodyOutputDescription>(output_description)) {
if (!back_edges.count(output_description->m_body_value_index))
continue;
const ov::PartialShape& body_value_shape = body_value.get_partial_shape();
const auto& body_value_shape = body_value.get_partial_shape();
auto input_param =
m_bodies[0]->get_parameters().at(back_edges[output_description->m_body_value_index]);
const auto& input_param_ps = input_param->get_partial_shape();
@ -232,7 +220,7 @@ void ov::op::v5::Loop::validate_and_infer_types() {
if (input_param_ps.rank().is_static()) {
const auto body_rank_len = body_value_shape.rank().get_length();
const auto input_rank_len = input_param_ps.rank().get_length();
ov::PartialShape new_ps;
PartialShape new_ps;
bool shape_changed = false;
if (body_rank_len == input_rank_len) {
new_ps = body_value_shape;
@ -243,7 +231,7 @@ void ov::op::v5::Loop::validate_and_infer_types() {
}
}
} else {
new_ps = ov::PartialShape::dynamic();
new_ps = PartialShape::dynamic();
shape_changed = true;
}
// reset sub model input shape
@ -277,18 +265,18 @@ void ov::op::v5::Loop::validate_and_infer_types() {
auto body_value = m_bodies[0]->get_results().at(output_description->m_body_value_index)->input_value(0);
if (auto concat_output_description =
ov::as_type_ptr<v0::TensorIterator::ConcatOutputDescription>(output_description)) {
as_type_ptr<v0::TensorIterator::ConcatOutputDescription>(output_description)) {
const auto& body_value_partial_shape = body_value.get_partial_shape();
auto out_shape = body_value_partial_shape;
if (zero_number_of_iter) {
out_shape = ov::PartialShape{0};
out_shape = PartialShape{0};
} else if (out_shape.rank().is_static()) {
OPENVINO_SUPPRESS_DEPRECATED_START
const auto axis = ov::normalize_axis(this, concat_output_description->m_axis, out_shape.rank());
const auto axis = normalize_axis(this, concat_output_description->m_axis, out_shape.rank());
OPENVINO_SUPPRESS_DEPRECATED_END
const auto rank = out_shape.rank().get_length();
if (rank == 0) {
out_shape = ov::PartialShape{1};
out_shape = PartialShape{1};
}
if (out_shape[axis].is_static() && m_num_iterations != -1) {
@ -301,8 +289,8 @@ void ov::op::v5::Loop::validate_and_infer_types() {
}
else if (auto body_output_description =
ov::as_type_ptr<v0::TensorIterator::BodyOutputDescription>(output_description)) {
const ov::PartialShape& body_value_shape = body_value.get_partial_shape();
as_type_ptr<v0::TensorIterator::BodyOutputDescription>(output_description)) {
const auto& body_value_shape = body_value.get_partial_shape();
if (body_value_shape.is_dynamic()) {
set_output_type(index, body_value.get_element_type(), body_value_shape);
} else {
@ -320,10 +308,10 @@ void ov::op::v5::Loop::validate_and_infer_types() {
"Number of outputs must be the same as number of output descriptions");
}
std::shared_ptr<ov::Node> ov::op::v5::Loop::clone_with_new_inputs(const OutputVector& new_args) const {
std::shared_ptr<Node> Loop::clone_with_new_inputs(const OutputVector& new_args) const {
OV_OP_SCOPE(v5_Loop_clone_with_new_inputs);
check_new_args_count(this, new_args);
auto op = std::make_shared<op::v5::Loop>();
auto op = std::make_shared<Loop>();
OPENVINO_ASSERT(op.get(),
op != nullptr,
"Cannot clone ",
@ -334,12 +322,12 @@ std::shared_ptr<ov::Node> ov::op::v5::Loop::clone_with_new_inputs(const OutputVe
return op;
}
ov::Output<ov::Node> ov::op::v5::Loop::get_concatenated_slices(const Output<Node>& value,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis) {
Output<Node> Loop::get_concatenated_slices(const Output<Node>& value,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis) {
OPENVINO_ASSERT(start == 0 && stride == 1 && part_size == 1 && end == -1,
"Invalid start, stride, part_size, or end attribute values in Loop op. "
"Supported values for start {0}, for stride and part_size {1}, for end "
@ -347,30 +335,29 @@ ov::Output<ov::Node> ov::op::v5::Loop::get_concatenated_slices(const Output<Node
return SubGraphOp::get_concatenated_slices(value, start, stride, part_size, end, axis);
}
bool ov::op::v5::Loop::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inputs) const {
bool Loop::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
OV_OP_SCOPE(v5_Loop_evaluate);
ov::reference::loop(m_bodies[0],
m_output_descriptions[0],
m_input_descriptions[0],
m_special_body_ports,
outputs,
inputs);
reference::loop(m_bodies[0],
m_output_descriptions[0],
m_input_descriptions[0],
m_special_body_ports,
outputs,
inputs);
return true;
}
bool ov::op::v5::Loop::has_evaluate() const {
bool Loop::has_evaluate() const {
OV_OP_SCOPE(v5_Loop_has_evaluate);
switch (get_input_element_type(0)) {
case ov::element::i32:
case ov::element::i64:
case element::i32:
case element::i64:
return true;
default:
break;
return false;
}
return false;
}
void ov::op::v5::Loop::clone_to(op::v5::Loop& dst, const OutputVector& new_args) const {
void Loop::clone_to(Loop& dst, const OutputVector& new_args) const {
dst.set_arguments(new_args);
dst.set_output_size(m_output_descriptions.size());
@ -388,6 +375,9 @@ void ov::op::v5::Loop::clone_to(op::v5::Loop& dst, const OutputVector& new_args)
dst.validate_and_infer_types();
}
ov::op::v5::Loop::Loop(const op::v5::Loop& other) : SubGraphOp() {
Loop::Loop(const op::v5::Loop& other) : SubGraphOp() {
other.clone_to(*this, other.input_values());
}
} // namespace v5
} // namespace op
} // namespace ov

View File

@ -1164,12 +1164,6 @@ std::vector<ov::PartialShape> ov::get_node_input_partial_shapes(const ov::Node&
return out;
}
bool ov::is_rank_compatible_any_of(const ov::Rank& rank, const std::vector<Rank>& ranks) {
return std::any_of(ranks.cbegin(), ranks.cend(), [&rank](const Rank& r) {
return rank.compatible(r);
});
}
bool ov::util::are_unique(const std::vector<int64_t>& data) {
return std::unordered_set<int64_t>(data.begin(), data.cend()).size() == data.size();
}
@ -1442,5 +1436,11 @@ std::vector<PartialShape> get_tensors_partial_shapes(const TensorVector& tensors
}
return shapes;
}
bool is_rank_compatible_any_of(const Rank& r, std::initializer_list<Rank> others) {
return std::any_of(others.begin(), others.end(), [&r](const Rank& other) {
return r.compatible(other);
});
}
} // namespace util
} // namespace ov