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

[Deprecated API] Remove api set_element_type() in ov::descriptor::Tensor #22476

31 changes: 17 additions & 14 deletions src/common/transformations/include/ov_ops/type_relaxed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,23 @@ class OPENVINO_API TypeRelaxedBase {
for (size_t i = 0; i < node.get_input_size(); ++i) {
auto origin_input_type = get_origin_input_type(i);
if (origin_input_type != element::undefined) {
OPENVINO_SUPPRESS_DEPRECATED_START
node.get_input_tensor(i).set_tensor_type(origin_input_type, node.get_input_partial_shape(i));
OPENVINO_SUPPRESS_DEPRECATED_END
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(node.input(i).get_node())) {
parameter->set_element_type(origin_input_type);
parameter->set_partial_shape(node.get_input_partial_shape(i));
parameter->validate_and_infer_types();
}
}
}
}

void restore_input_data_types(Node& node, const element::TypeVector& old_input_types) {
// Restore original input data types
for (size_t i = 0; i < node.get_input_size(); ++i) {
OPENVINO_SUPPRESS_DEPRECATED_START
node.get_input_tensor(i).set_tensor_type(old_input_types[i], node.get_input_partial_shape(i));
OPENVINO_SUPPRESS_DEPRECATED_END
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(node.input(i).get_node())) {
parameter->set_element_type(old_input_types[i]);
parameter->set_partial_shape(node.get_input_partial_shape(i));
parameter->validate_and_infer_types();
}
}

if (m_original_output_data_types.empty()) {
Expand Down Expand Up @@ -154,16 +158,17 @@ class OPENVINO_API TypeRelaxedBase {
/// So it should be
class TemporaryReplaceOutputType {
Output<Node> m_output;
element::Type orig_type;
std::shared_ptr<ov::descriptor::Tensor> orig_tensor;

public:
/// Replace element type for a given output port by tmp_type
TemporaryReplaceOutputType(Output<Node> output, element::Type tmp_type) : m_output(output) {
// save original element type in order to restore it in the destructor
orig_type = m_output.get_element_type();
OPENVINO_SUPPRESS_DEPRECATED_START
m_output.get_tensor().set_element_type(tmp_type);
OPENVINO_SUPPRESS_DEPRECATED_END
orig_tensor = m_output.get_tensor_ptr();
auto tmp_tensor = std::make_shared<ov::descriptor::Tensor>(tmp_type,
orig_tensor->get_partial_shape(),
orig_tensor->get_names());
m_output.set_tensor_ptr(tmp_tensor);
}

/// Return the output port that was used in the constructor
Expand All @@ -173,9 +178,7 @@ class TemporaryReplaceOutputType {

/// Restores the original element type for the output
~TemporaryReplaceOutputType() {
OPENVINO_SUPPRESS_DEPRECATED_START
m_output.get_tensor().set_element_type(orig_type);
OPENVINO_SUPPRESS_DEPRECATED_END
m_output.set_tensor_ptr(orig_tensor);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ bool ov::pass::SymbolicPropagation::run_on_model(const std::shared_ptr<ov::Model
for (auto& output : op->outputs()) {
auto shape = output.get_partial_shape();
symbolic_set_up_for_shape(dt, shape);
OPENVINO_SUPPRESS_DEPRECATED_START
output.get_tensor().set_tensor_type(output.get_element_type(), shape);
OPENVINO_SUPPRESS_DEPRECATED_END
auto tmp_tensor = std::make_shared<ov::descriptor::Tensor>(output.get_element_type(),
shape,
output.get_tensor_ptr()->get_names());
for (auto& item : output.get_tensor_ptr()->get_rt_info()) {
tmp_tensor->get_rt_info()[item.first] = item.second;
}
output.set_tensor_ptr(tmp_tensor);
}
}
return true;
Expand Down
6 changes: 0 additions & 6 deletions src/core/include/openvino/core/descriptor/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ class OPENVINO_API Tensor {
void set_names(const std::unordered_set<std::string>& names);
void add_names(const std::unordered_set<std::string>& names);

OPENVINO_DEPRECATED("set_tensor_type() is deprecated. To change Tensor type please change the Parameter type")
void set_tensor_type(const element::Type& element_type, const PartialShape& pshape);
OPENVINO_DEPRECATED(
"set_element_type() is deprecated. To change Tensor element type please change the Parameter type")
void set_element_type(const element::Type& elemenet_type);

/// \brief sets lower bound value description
void set_lower_value(const ov::Tensor& value);
/// \brief sets upper bound value description
Expand Down
12 changes: 0 additions & 12 deletions src/core/src/descriptor/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ ov::descriptor::Tensor::Tensor(const element::Type& element_type,
m_name_it = m_names.cend();
}

OPENVINO_SUPPRESS_DEPRECATED_START
void ov::descriptor::Tensor::set_tensor_type(const element::Type& element_type, const PartialShape& pshape) {
set_element_type(element_type);
m_partial_shape = pshape;
m_shape_changed = true;
}

void ov::descriptor::Tensor::set_element_type(const element::Type& element_type) {
m_element_type = element_type;
}
OPENVINO_SUPPRESS_DEPRECATED_END

void ov::descriptor::Tensor::invalidate_values() {
if (ov::skip_invalidation(*this))
return;
Expand Down
10 changes: 7 additions & 3 deletions src/core/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,13 @@ void ov::Node::set_input_is_relevant_to_value(size_t i, bool relevant) {
}

void ov::Node::set_output_type(size_t i, const element::Type& element_type, const PartialShape& pshape) {
OPENVINO_SUPPRESS_DEPRECATED_START
get_output_descriptor(i).get_tensor_ptr()->set_tensor_type(element_type, pshape);
OPENVINO_SUPPRESS_DEPRECATED_END
auto tmp_tensor = std::make_shared<ov::descriptor::Tensor>(element_type,
pshape,
get_output_descriptor(i).get_tensor_ptr()->get_names());
for (auto& item : get_output_descriptor(i).get_tensor_ptr()->get_rt_info()) {
tmp_tensor->get_rt_info()[item.first] = item.second;
}
get_output_descriptor(i).set_tensor_ptr(tmp_tensor);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilya-lavrenov @vurusovs Why we need to deprecated this API? Seems like this change will take more time & more complex.

}
zhaixuejun1993 marked this conversation as resolved.
Show resolved Hide resolved

std::string ov::Node::description() const {
Expand Down
16 changes: 9 additions & 7 deletions src/core/src/op/type_relaxed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ void convert_types(std::shared_ptr<v0::Parameter>& parameter,
ov::TensorVector upper_tensor = {ov::Tensor(new_type, output.get_shape())};
bool lower_success = convert->evaluate_lower(lower_tensor);
bool upper_success = convert->evaluate_upper(upper_tensor);
auto& tensor = output.get_tensor();

if (lower_success || upper_success) {
OPENVINO_SUPPRESS_DEPRECATED_START
tensor.set_element_type(new_type); // deprecated piece
OPENVINO_SUPPRESS_DEPRECATED_END
auto tmp_tensor = std::make_shared<ov::descriptor::Tensor>(new_type,
output.get_tensor().get_partial_shape(),
output.get_tensor().get_names());
output.set_tensor_ptr(tmp_tensor);
}
auto& tensor = output.get_tensor();
if (lower_success)
tensor.set_lower_value(lower_tensor[0]);
if (upper_success)
Expand Down Expand Up @@ -114,10 +115,11 @@ void reset_input_types(const std::unordered_map<size_t, std::pair<ov::Tensor, ov
continue;
const auto& etype =
item.second.first ? item.second.first.get_element_type() : item.second.second.get_element_type();
auto tmp_tensor = std::make_shared<ov::descriptor::Tensor>(etype,
inputs[item.first].get_tensor().get_partial_shape(),
inputs[item.first].get_tensor().get_names());
inputs[item.first].set_tensor_ptr(tmp_tensor);
auto& tensor = inputs[item.first].get_tensor();
OPENVINO_SUPPRESS_DEPRECATED_START
tensor.set_element_type(etype);
OPENVINO_SUPPRESS_DEPRECATED_END
if (item.second.first)
tensor.set_lower_value(item.second.first);
if (item.second.second)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@ void MemoryLSTMCellTest::SetUp() {
auto out_hidden = tensor_iterator->get_iter_value(H_o, -1);
auto out_cell = tensor_iterator->get_iter_value(C_o, -1);

out_hidden.get_tensor().set_element_type(element_type);
out_cell.get_tensor().set_element_type(element_type);
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_hidden.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_cell.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}

auto cell_memory_write = std::make_shared<ov::op::v6::Assign>(out_cell, var_cell);
auto hidden_memory_write = std::make_shared<ov::op::v6::Assign>(out_hidden, var_hidden);
Expand Down Expand Up @@ -274,8 +280,14 @@ void MemoryLSTMCellTest::create_pure_tensor_iterator_model() {
auto out_hidden = tensor_iterator->get_iter_value(H_o, -1);
auto out_cell = tensor_iterator->get_iter_value(C_o, -1);

out_hidden.get_tensor().set_element_type(element_type);
out_cell.get_tensor().set_element_type(element_type);
Comment on lines -277 to -278
Copy link
Contributor

@vurusovs vurusovs Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itikhono was set_element_type() really required? May it be just removed from test instead of replacing?

if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_hidden.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_cell.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}

auto final_reshape_pattern =
std::make_shared<ov::op::v0::Constant>(element::i64, Shape{4}, std::vector<size_t>({1, 1, 1, hiddenSize}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ void MultipleLSTMCellTest::SetUp() {
auto out_hidden = tensor_iterator->get_iter_value(H_o, -1);
auto out_cell = tensor_iterator->get_iter_value(C_o, -1);

out_hidden.get_tensor().set_element_type(element_type);
out_cell.get_tensor().set_element_type(element_type);
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_hidden.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_cell.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}

auto cell_memory_write = std::make_shared<ov::op::v6::Assign>(out_cell, var_cell);
auto hidden_memory_write = std::make_shared<ov::op::v6::Assign>(out_hidden, var_hidden);
Expand Down Expand Up @@ -193,8 +199,14 @@ void MultipleLSTMCellTest::SetUp() {
auto out_hidden_2 = tensor_iterator_2->get_iter_value(H_o_2, -1);
auto out_cell_2 = tensor_iterator_2->get_iter_value(C_o_2, -1);

out_hidden_2.get_tensor().set_element_type(element_type);
out_cell_2.get_tensor().set_element_type(element_type);
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_hidden_2.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_cell_2.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}

auto cell_memory_2_write = std::make_shared<ov::op::v6::Assign>(out_cell_2, var_cell_2);
auto hidden_memory_2_write = std::make_shared<ov::op::v6::Assign>(out_hidden_2, var_hidden_2);
Expand Down Expand Up @@ -381,8 +393,14 @@ void MultipleLSTMCellTest::create_pure_tensor_iterator_model() {
auto out_hidden = tensor_iterator->get_iter_value(H_o, -1);
auto out_cell = tensor_iterator->get_iter_value(C_o, -1);

out_hidden.get_tensor().set_element_type(element_type);
out_cell.get_tensor().set_element_type(element_type);
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_hidden.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_cell.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
tensor_iterator->validate_and_infer_types();

auto first_reshape_pattern =
Expand Down Expand Up @@ -444,8 +462,14 @@ void MultipleLSTMCellTest::create_pure_tensor_iterator_model() {
auto out_hidden_2 = tensor_iterator_2->get_iter_value(H_o_2, -1);
auto out_cell_2 = tensor_iterator_2->get_iter_value(C_o_2, -1);

out_hidden_2.get_tensor().set_element_type(element_type);
out_cell_2.get_tensor().set_element_type(element_type);
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_hidden_2.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
if (auto parameter = dynamic_cast<ov::op::v0::Parameter*>(out_cell_2.get_node())) {
parameter->set_element_type(element_type);
parameter->validate_and_infer_types();
}
tensor_iterator_2->validate_and_infer_types();
auto final_reshape_pattern =
std::make_shared<ov::op::v0::Constant>(element::i64, Shape{4}, std::vector<size_t>({1, 1, 1, hiddenSize}));
Expand Down
Loading