Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

squeeze v15 implementation #26995

Merged
merged 54 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9c8f261
squeeze v15 implementation
barnasm1 Oct 10, 2024
be046ac
use attribute name from spec
barnasm1 Oct 10, 2024
4a27b4a
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 11, 2024
8830412
squeeze v15 no common bese class
barnasm1 Oct 18, 2024
bf46e42
copy shape_infer impl for tests
barnasm1 Oct 18, 2024
bfd61ec
add tests squeeze v15
barnasm1 Oct 22, 2024
757ba2b
add visitor_single_attribute test
barnasm1 Oct 22, 2024
971cb46
clang foramt
barnasm1 Oct 22, 2024
c1942ec
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 22, 2024
0900e09
turn off Wsuggest-override for typed test
barnasm1 Oct 22, 2024
47792dd
use valid constructor
barnasm1 Oct 22, 2024
c4fa858
turn off failing tests
barnasm1 Oct 22, 2024
1ad2ad1
prevent miss use squeeze shape_infer
barnasm1 Oct 22, 2024
96bc057
clang format
barnasm1 Oct 22, 2024
acd8bff
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 23, 2024
73dd231
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 23, 2024
6727564
add util namespace
barnasm1 Oct 23, 2024
693ca67
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 24, 2024
bd12551
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 24, 2024
28fd904
review suggestions for tests
barnasm1 Oct 24, 2024
8875216
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 24, 2024
ffa47ea
fix windows tests
barnasm1 Oct 24, 2024
1cb767d
fix tests
barnasm1 Oct 24, 2024
dfbf4e8
squeeze base part1
barnasm1 Oct 24, 2024
5f9b0c5
squeeze base part2
barnasm1 Oct 25, 2024
9e9f736
squeeze base part3
barnasm1 Oct 25, 2024
b42d914
move squeeze bese to seprate file
barnasm1 Oct 25, 2024
227c470
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 26, 2024
fa4f19a
separate shape_infer implementations
barnasm1 Oct 26, 2024
31e13f2
review suggestions
barnasm1 Oct 28, 2024
8367ae7
add tests
barnasm1 Oct 28, 2024
05cfed8
code format
barnasm1 Oct 28, 2024
e41fc1a
update ctor
barnasm1 Oct 28, 2024
eb6ea44
use squeeze v15 at opset15
barnasm1 Oct 28, 2024
06f52a7
add squeeze v15 tests: smoke_Squeeze_With_Hardcoded_Refs
barnasm1 Oct 28, 2024
e7a641f
shape inference fix
barnasm1 Oct 28, 2024
6450f72
fix expected rank for dynamic axis
barnasm1 Oct 28, 2024
9646543
unused function param
barnasm1 Oct 28, 2024
9bc02b7
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 28, 2024
7f21c2c
single op graph generator for squeeze v15
barnasm1 Oct 29, 2024
1110d05
test classes names unique
barnasm1 Oct 29, 2024
011da10
add squeeze v15 to shape inference registry
barnasm1 Oct 29, 2024
2ebf0e0
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 29, 2024
0f47b7a
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 29, 2024
2a1979b
review suggestions
barnasm1 Oct 29, 2024
9a220c7
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 30, 2024
9d8b408
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 30, 2024
051dad1
restore full dynamic rank result
barnasm1 Oct 30, 2024
7c6878b
revert to_shape call
barnasm1 Oct 30, 2024
a7540e4
missing bracket
barnasm1 Oct 30, 2024
11f0637
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 30, 2024
b6cac31
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 30, 2024
b76abc2
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 30, 2024
29ba4c3
Merge branch 'master' into squeeze_v15_class
barnasm1 Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/core/include/openvino/op/squeeze.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#pragma once

#include <functional>
#include <utility>

#include "openvino/op/op.hpp"

namespace ov {
Expand Down Expand Up @@ -37,5 +40,42 @@ class OPENVINO_API Squeeze : public Op {
Output<Node> get_default_axes_input() const;
};
} // namespace v0

namespace v15 {
class OPENVINO_API Squeeze : public Op {
praasz marked this conversation as resolved.
Show resolved Hide resolved
public:
OPENVINO_OP("Squeeze", "opset15");

Squeeze();
Squeeze(const Output<Node>& data);

/// \brief Constructs a squeeze operation.
///
/// \param data Input tensor with data
/// \param axis The axis along which to squeeze the input tensor.
/// \param allow_axis_skip Shape inference result dynamic rank if selected axis has 1 in range of its dynamic
Squeeze(const Output<Node>& data, const Output<Node>& axes, const bool allow_axis_skip = false);

void validate_and_infer_types() override;
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;
bool has_evaluate() const override;
bool evaluate_lower(TensorVector& outputs) const override;
bool evaluate_upper(TensorVector& outputs) const override;
bool evaluate_symbol(TensorSymbolVector& output_symbols) const override;
bool constant_fold(OutputVector& output_values, const OutputVector& inputs_values) override;

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;

bool is_dynamic() const override;

bool visit_attributes(AttributeVisitor& visitor) override;

bool get_allow_axis_skip() const;

private:
Output<Node> get_default_axes_input() const;
praasz marked this conversation as resolved.
Show resolved Hide resolved
bool m_allow_axis_skip{};
};
} // namespace v15
} // namespace op
} // namespace ov
32 changes: 26 additions & 6 deletions src/core/shape_inference/include/squeeze_shape_inference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace ov {
namespace op {
namespace v0 {

namespace util {
/**
* \brief Do Squeeze shape inference.
*
Expand All @@ -21,10 +20,13 @@ namespace v0 {
* \param input_shapes Squeeze input shapes.
* \param ta Tensor accessor to constant data.
*/
template <class T, class TRShape = result_shape_t<T>>
std::vector<TRShape> shape_infer(const Squeeze* op,
const std::vector<T>& input_shapes,
const ITensorAccessor& ta = make_tensor_accessor()) {
template <class T,
class TRShape = result_shape_t<T>,
class Squeeze,
typename = typename std::enable_if<std::is_same<Squeeze, ov::op::v0::Squeeze>::value ||
std::is_same<Squeeze, ov::op::v15::Squeeze>::value,
bool>::type>
std::vector<TRShape> shape_infer(const Squeeze* op, const std::vector<T>& input_shapes, const ITensorAccessor& ta) {
using DimType = typename T::value_type;

const auto number_of_inputs = input_shapes.size();
Expand Down Expand Up @@ -115,6 +117,24 @@ std::vector<TRShape> shape_infer(const Squeeze* op,
}
return output_shapes;
}
} // namespace util

namespace v0 {
template <class T, class TRShape = result_shape_t<T>>
std::vector<TRShape> shape_infer(const Squeeze* op,
const std::vector<T>& input_shapes,
const ITensorAccessor& ta = make_tensor_accessor()) {
return util::shape_infer(op, input_shapes, ta);
}
} // namespace v0

namespace v15 {
template <class T, class TRShape = result_shape_t<T>>
std::vector<TRShape> shape_infer(const Squeeze* op,
const std::vector<T>& input_shapes,
const ITensorAccessor& ta = make_tensor_accessor()) {
return util::shape_infer(op, input_shapes, ta);
mlukasze marked this conversation as resolved.
Show resolved Hide resolved
}
} // namespace v15
} // namespace op
} // namespace ov
116 changes: 115 additions & 1 deletion src/core/src/op/squeeze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace ov {
namespace op {
namespace v0 {

namespace validate {
namespace {

Expand All @@ -24,6 +24,7 @@ bool axes_has_and_set_bound(const Node& op) {
} // namespace
} // namespace validate

namespace v0 {
Squeeze::Squeeze() : Op() {}

Squeeze::Squeeze(const Output<Node>& data, const Output<Node>& axes) : Op({data, axes}) {
Expand Down Expand Up @@ -125,6 +126,119 @@ bool Squeeze::constant_fold(OutputVector& output_values, const OutputVector& inp
bool Squeeze::is_dynamic() const {
return get_output_partial_shape(0).is_dynamic();
}

} // namespace v0

namespace v15 {
Squeeze::Squeeze() : Op() {}

Squeeze::Squeeze(const Output<Node>& data) : Op({data}) {
constructor_validate_and_infer_types();
}

Squeeze::Squeeze(const Output<Node>& data, const Output<Node>& axes, const bool allow_axis_skip)
: Op({data, axes}),
m_allow_axis_skip{allow_axis_skip} {
constructor_validate_and_infer_types();
}

std::shared_ptr<Node> Squeeze::clone_with_new_inputs(const OutputVector& new_args) const {
OV_OP_SCOPE(v15_Squeeze_clone_with_new_inputs);
check_new_args_count(this, new_args);

switch (new_args.size()) {
case 1:
return std::make_shared<Squeeze>(new_args[0]);
mmikolajcz marked this conversation as resolved.
Show resolved Hide resolved
case 2:
return std::make_shared<Squeeze>(new_args[0], new_args[1], m_allow_axis_skip);
default:
OPENVINO_THROW("Incorrect number of new arguments");
}
}

void Squeeze::validate_and_infer_types() {
OV_OP_SCOPE(v15_Squeeze_validate_and_infer_types);

const auto input_shapes = ov::util::get_node_input_partial_shapes(*this);
const auto output_shapes = shape_infer(this, input_shapes);

set_output_type(0, get_input_element_type(0), output_shapes[0]);
}

bool Squeeze::evaluate(TensorVector& outputs, const TensorVector& inputs) const {
OV_OP_SCOPE(v15_Squeeze_evaluate);
OPENVINO_ASSERT(outputs.size() == 1);

const auto output_shapes =
shape_infer(this, ov::util::get_tensors_partial_shapes(inputs), make_tensor_accessor(inputs));
outputs[0].set_shape(output_shapes.front().get_shape());

std::memcpy(outputs[0].data(), inputs[0].data(), outputs[0].get_byte_size());
return true;
}

bool Squeeze::has_evaluate() const {
OV_OP_SCOPE(v15_Squeeze_has_evaluate);
const auto validate_axes_type = [](const element::Type& et) -> bool {
switch (et) {
case element::i8:
case element::i16:
case element::i32:
case element::i64:
case element::u8:
case element::u16:
case element::u32:
case element::u64:
return true;
default:
return false;
}
};

return (get_input_size() < 2) || validate_axes_type(get_input_element_type(1));
}

bool Squeeze::evaluate_lower(TensorVector& output_values) const {
OV_OP_SCOPE(v15_Squeeze_evaluate_lower);
return validate::axes_has_and_set_bound(*this) && default_lower_bound_evaluator(this, output_values);
}

bool Squeeze::evaluate_upper(TensorVector& output_values) const {
OV_OP_SCOPE(v15_Squeeze_evaluate_upper);
return validate::axes_has_and_set_bound(*this) && default_upper_bound_evaluator(this, output_values);
}

bool Squeeze::evaluate_symbol(TensorSymbolVector& output_symbols) const {
return validate::axes_has_and_set_bound(*this) && ov::util::default_symbol_evaluator(this, output_symbols);
}

bool Squeeze::constant_fold(OutputVector& output_values, const OutputVector& inputs_values) {
OV_OP_SCOPE(v15_Squeeze_constant_fold);
if (get_output_partial_shape(0).is_dynamic() || is_const_fold_disabled()) {
return false;
}

if (auto data_const = std::dynamic_pointer_cast<opset1::Constant>(inputs_values[0].get_node_shared_ptr())) {
const auto& shape = get_output_shape(0);
output_values[0] = std::make_shared<v0::Constant>(*data_const, shape);
return true;
}
return false;
}

bool Squeeze::is_dynamic() const {
return get_output_partial_shape(0).is_dynamic();
}

bool Squeeze::visit_attributes(AttributeVisitor& visitor) {
OV_OP_SCOPE(v15_Squeeze_visit_attributes);
visitor.on_attribute("allow_axis_skip", m_allow_axis_skip);
return true;
}

bool Squeeze::get_allow_axis_skip() const {
return m_allow_axis_skip;
}
} // namespace v15
} // namespace op
} // namespace ov
1 change: 1 addition & 0 deletions src/core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/threading.cpp
if(SUGGEST_OVERRIDE_SUPPORTED)
set_source_files_properties(ov_tensor_test.cpp
type_prop/multiclass_nms.cpp
type_prop/squeeze.cpp
PROPERTIES COMPILE_OPTIONS -Wno-suggest-override)
endif()

Expand Down
Loading
Loading