Skip to content

Commit d9c2aee

Browse files
authored
[core] Deprecate undefined type and use dynamic where possible (#28766)
### Details: - Mark `ov::element::undefined` as deprecated - Use dynamic type instead of undefined ### Related PRs: - openvinotoolkit/openvino_contrib#945 - #28524 ### Tickets: - CVS-161637 --------- Signed-off-by: Pawel Raasz <pawel.raasz@intel.com> Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
1 parent 5d00273 commit d9c2aee

File tree

274 files changed

+4015
-4117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+4015
-4117
lines changed

docs/articles_en/assets/snippets/ov_dynamic_shapes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ ov_compiled_model_create_infer_request(compiled_model, &infer_request);
148148

149149
//! [ov_dynamic_shapes:set_input_tensor]
150150
ov_output_const_port_t* input_port = NULL;
151-
ov_element_type_e type = UNDEFINED;
151+
ov_element_type_e type = DYNAMIC;
152152
ov_shape_t input_shape_1;
153153
ov_tensor_t* input_tensor_1 = NULL;
154154
ov_tensor_t* output_tensor = NULL;

samples/cpp/benchmark_app/main.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ int main(int argc, char* argv[]) {
529529
if (result != config.end())
530530
device_config = result->second;
531531
size_t batchSize = FLAGS_b;
532-
ov::element::Type type = ov::element::undefined;
532+
ov::element::Type type = ov::element::dynamic;
533533
std::string topology_name = "";
534534
std::vector<benchmark_app::InputsInfo> app_inputs_info;
535535
std::string output_name;
@@ -660,14 +660,14 @@ int main(int argc, char* argv[]) {
660660
std::const_pointer_cast<const ov::Model>(model)->outputs());
661661
}
662662

663-
const auto input_precision = FLAGS_ip.empty() ? ov::element::undefined : getPrecision2(FLAGS_ip);
664-
const auto output_precision = FLAGS_op.empty() ? ov::element::undefined : getPrecision2(FLAGS_op);
663+
const auto input_precision = FLAGS_ip.empty() ? ov::element::dynamic : getPrecision2(FLAGS_ip);
664+
const auto output_precision = FLAGS_op.empty() ? ov::element::dynamic : getPrecision2(FLAGS_op);
665665

666666
const auto& inputs = model->inputs();
667667
for (size_t i = 0; i < inputs.size(); i++) {
668668
const auto& item = inputs[i];
669-
auto iop_precision = ov::element::undefined;
670-
auto type_to_set = ov::element::undefined;
669+
auto iop_precision = ov::element::dynamic;
670+
auto type_to_set = ov::element::dynamic;
671671
std::string name;
672672
try {
673673
// Some tensors might have no names, get_any_name will throw exception in that case.
@@ -676,18 +676,17 @@ int main(int argc, char* argv[]) {
676676
iop_precision = getPrecision2(user_precisions_map.at(item.get_any_name()));
677677
} catch (...) {
678678
}
679-
680-
if (iop_precision != ov::element::undefined) {
679+
if (iop_precision != ov::element::dynamic) {
681680
type_to_set = iop_precision;
682-
} else if (input_precision != ov::element::undefined) {
681+
} else if (input_precision != ov::element::dynamic) {
683682
type_to_set = input_precision;
684683
} else if (!name.empty() && app_inputs_info[0].at(name).is_image()) {
685684
// image input, set U8
686685
type_to_set = ov::element::u8;
687686
}
688687

689688
auto& in = preproc.input(item.get_any_name());
690-
if (type_to_set != ov::element::undefined) {
689+
if (type_to_set != ov::element::dynamic) {
691690
in.tensor().set_element_type(type_to_set);
692691

693692
if (!name.empty()) {
@@ -707,17 +706,16 @@ int main(int argc, char* argv[]) {
707706
const auto& outs = model->outputs();
708707
for (size_t i = 0; i < outs.size(); i++) {
709708
const auto& item = outs[i];
710-
auto iop_precision = ov::element::undefined;
709+
auto iop_precision = ov::element::dynamic;
711710
try {
712711
// Some tensors might have no names, get_any_name will throw exception in that case.
713712
// -iop option will not work for those tensors.
714713
iop_precision = getPrecision2(user_precisions_map.at(item.get_any_name()));
715714
} catch (...) {
716715
}
717-
718-
if (iop_precision != ov::element::undefined) {
716+
if (iop_precision != ov::element::dynamic) {
719717
preproc.output(i).tensor().set_element_type(iop_precision);
720-
} else if (output_precision != ov::element::undefined) {
718+
} else if (output_precision != ov::element::dynamic) {
721719
preproc.output(i).tensor().set_element_type(output_precision);
722720
}
723721
}

src/bindings/c/include/openvino/c/ov_common.h

+27-27
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,33 @@ typedef enum {
169169
* src/core/include/openvino/core/type/element_type.hpp
170170
*/
171171
typedef enum {
172-
UNDEFINED = 0U, //!< Undefined element type
173-
DYNAMIC, //!< Dynamic element type
174-
BOOLEAN, //!< boolean element type
175-
BF16, //!< bf16 element type
176-
F16, //!< f16 element type
177-
F32, //!< f32 element type
178-
F64, //!< f64 element type
179-
I4, //!< i4 element type
180-
I8, //!< i8 element type
181-
I16, //!< i16 element type
182-
I32, //!< i32 element type
183-
I64, //!< i64 element type
184-
U1, //!< binary element type
185-
U2, //!< u2 element type
186-
U3, //!< u3 element type
187-
U4, //!< u4 element type
188-
U6, //!< u6 element type
189-
U8, //!< u8 element type
190-
U16, //!< u16 element type
191-
U32, //!< u32 element type
192-
U64, //!< u64 element type
193-
NF4, //!< nf4 element type
194-
F8E4M3, //!< f8e4m3 element type
195-
F8E5M3, //!< f8e5m2 element type
196-
STRING, //!< string element type
197-
F4E2M1, //!< f4e2m1 element type
198-
F8E8M0, //!< f8e8m0 element type
172+
UNDEFINED = 0U, //!< Undefined element type
173+
DYNAMIC = UNDEFINED, //!< Dynamic element type
174+
BOOLEAN, //!< boolean element type
175+
BF16, //!< bf16 element type
176+
F16, //!< f16 element type
177+
F32, //!< f32 element type
178+
F64, //!< f64 element type
179+
I4, //!< i4 element type
180+
I8, //!< i8 element type
181+
I16, //!< i16 element type
182+
I32, //!< i32 element type
183+
I64, //!< i64 element type
184+
U1, //!< binary element type
185+
U2, //!< u2 element type
186+
U3, //!< u3 element type
187+
U4, //!< u4 element type
188+
U6, //!< u6 element type
189+
U8, //!< u8 element type
190+
U16, //!< u16 element type
191+
U32, //!< u32 element type
192+
U64, //!< u64 element type
193+
NF4, //!< nf4 element type
194+
F8E4M3, //!< f8e4m3 element type
195+
F8E5M3, //!< f8e5m2 element type
196+
STRING, //!< string element type
197+
F4E2M1, //!< f4e2m1 element type
198+
F8E8M0, //!< f8e8m0 element type
199199
} ov_element_type_e;
200200

201201
/**

src/bindings/c/src/ov_tensor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "common.h"
77

88
const std::map<ov_element_type_e, ov::element::Type> element_type_map = {
9-
{ov_element_type_e::UNDEFINED, ov::element::undefined},
9+
{ov_element_type_e::UNDEFINED, ov::element::dynamic},
1010
{ov_element_type_e::DYNAMIC, ov::element::dynamic},
1111
{ov_element_type_e::BOOLEAN, ov::element::boolean},
1212
{ov_element_type_e::BF16, ov::element::bf16},

src/bindings/python/src/openvino/frontend/tensorflow/node_decoder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def tf_type_to_ov_type(tf_type_int):
2020
try:
2121
ret_type = Type(numpy_type)
2222
except:
23-
ret_type = Type.undefined
23+
ret_type = Type.dynamic
2424
return ret_type
2525

2626

@@ -169,7 +169,7 @@ def get_attribute(self, name):
169169
return OVAny(Type.dynamic)
170170
return OVAny(tf_type_to_ov_type(variable_value.dtype))
171171
else:
172-
return OVAny(Type.undefined)
172+
return OVAny(Type.dynamic)
173173
return OVAny(tf_type_to_ov_type(type_num))
174174

175175
if name == "value":

src/bindings/python/src/pyopenvino/core/common.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ ov::Tensor tensor_from_pointer(py::array& array, const ov::Shape& shape, const o
510510
if (type_helpers::get_ov_type(array) == ov::element::string) {
511511
OPENVINO_THROW("SHARED MEMORY MODE FOR THIS TENSOR IS NOT APPLICABLE! String types can be only copied.");
512512
}
513-
514-
auto element_type = (type == ov::element::undefined) ? Common::type_helpers::get_ov_type(array) : type;
513+
auto element_type = (type == ov::element::dynamic) ? Common::type_helpers::get_ov_type(array) : type;
515514

516515
if (array_helpers::is_contiguous(array)) {
517516
return ov::Tensor(element_type, shape, const_cast<void*>(array.data(0)), {});

src/bindings/python/src/pyopenvino/core/tensor.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void regclass_Tensor(py::module m) {
4242
}),
4343
py::arg("array"),
4444
py::arg("shape"),
45-
py::arg("type") = ov::element::undefined,
45+
py::arg("type") = ov::element::dynamic,
4646
py::keep_alive<1, 2>(),
4747
R"(
4848
Another Tensor's special constructor.
@@ -76,7 +76,7 @@ void regclass_Tensor(py::module m) {
7676
}),
7777
py::arg("array"),
7878
py::arg("shape"),
79-
py::arg("type") = ov::element::undefined,
79+
py::arg("type") = ov::element::dynamic,
8080
py::keep_alive<1, 2>(),
8181
R"(
8282
Another Tensor's special constructor.

src/bindings/python/src/pyopenvino/graph/preprocess/pre_post_process.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void regclass_graph_PreProcessSteps(py::module m) {
9393
[](ov::preprocess::PreProcessSteps& self, ov::element::Type type = {}) {
9494
return &self.convert_element_type(type);
9595
},
96-
py::arg_v("type", ov::element::undefined, "openvino.Type.undefined"),
96+
py::arg_v("type", ov::element::dynamic, "openvino.Type.dynamic"),
9797
R"(
9898
Converts input tensor element type to specified type.
9999
Input tensor must have openvino.Type data type.
@@ -239,7 +239,7 @@ static void regclass_graph_PostProcessSteps(py::module m) {
239239
[](ov::preprocess::PostProcessSteps& self, ov::element::Type type = {}) {
240240
return &self.convert_element_type(type);
241241
},
242-
py::arg_v("type", ov::element::undefined, "openvino.Type.undefined"),
242+
py::arg_v("type", ov::element::dynamic, "openvino.Type.dynamic"),
243243
R"(
244244
Converts tensor element type to specified type.
245245
Tensor must have openvino.Type data type.

src/bindings/python/src/pyopenvino/graph/types/element_type.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void regclass_graph_Type(py::module m) {
3131
:rtype: ov.Type
3232
)");
3333

34-
type.attr("undefined") = ov::element::undefined;
34+
type.attr("undefined") = ov::element::dynamic;
3535
type.attr("dynamic") = ov::element::dynamic;
3636
type.attr("boolean") = ov::element::boolean;
3737
type.attr("f16") = ov::element::f16;

src/bindings/python/tests/test_runtime/test_type.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,17 @@ def test_basic_ovtypes(ovtype,
9292

9393
def test_undefined_ovtype():
9494
ov_type = Type.undefined
95-
assert ov_type.is_static() is True
96-
assert ov_type.is_dynamic() is False
95+
assert ov_type.is_static() is False
96+
assert ov_type.is_dynamic() is True
9797
assert ov_type.is_real() is False
98-
assert ov_type.real is False
9998
assert ov_type.is_integral() is True
100-
assert ov_type.integral is True
10199
assert ov_type.is_signed() is False
102-
assert ov_type.signed is False
103100
assert ov_type.is_quantized() is False
104-
assert ov_type.quantized is False
105-
assert ov_type.get_type_name() == "undefined"
106-
assert ov_type.type_name == "undefined"
107-
assert ov_type.get_size() == 0
101+
assert ov_type.get_type_name() == "dynamic"
108102
assert ov_type.size == 0
109-
110-
# Note: might depend on the system
111-
import sys
112-
assert ov_type.bitwidth == sys.maxsize * 2 + 1
113-
assert ov_type.get_bitwidth() == sys.maxsize * 2 + 1
103+
assert ov_type.get_size() == 0
104+
assert ov_type.bitwidth == 0
105+
assert ov_type.get_bitwidth() == 0
114106

115107

116108
def test_dynamic_ov_type():

src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace precision_set {
3232

3333
class LP_TRANSFORMATIONS_API DataPrecision {
3434
public:
35-
DataPrecision() : precision(element::undefined), min(0.f), max(0.f), hasZeroPoint(false) {}
35+
DataPrecision() : precision(element::dynamic), min(0.f), max(0.f), hasZeroPoint(false) {}
3636

3737
explicit DataPrecision(const element::Type& precision) {
3838
this->precision = precision;
@@ -48,10 +48,9 @@ class LP_TRANSFORMATIONS_API DataPrecision {
4848
hasZeroPoint(hasZeroPoint) {}
4949

5050
bool empty() const noexcept {
51-
assert(
52-
((precision == element::undefined) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint)) ||
53-
((precision != element::undefined) && (max != 0.f)));
54-
return (precision == element::undefined) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint);
51+
assert(((precision == element::dynamic) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint)) ||
52+
((precision != element::dynamic) && (max != 0.f)));
53+
return (precision == element::dynamic) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint);
5554
}
5655

5756
static bool isSupported(const element::Type& precision) {

src/common/low_precision_transformations/include/low_precision/network_helper.hpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@ class LP_TRANSFORMATIONS_API NetworkHelper {
186186

187187
static size_t getParentOutputIndex(const std::shared_ptr<ov::Node>& parent, const std::shared_ptr<ov::Node>& child);
188188

189-
static FakeQuantizeDequantizationValues createEmptyValues(
190-
const FakeQuantizeDequantization& dequantization,
191-
const element::Type& precision = element::undefined);
189+
static FakeQuantizeDequantizationValues createEmptyValues(const FakeQuantizeDequantization& dequantization,
190+
const element::Type& precision = element::dynamic);
192191

193192
static bool isZeroConst(const std::shared_ptr<Node>& node);
194193
static bool checkZeroPoint(const std::shared_ptr<Node>& node, const DataPrecision& dataPrecision = DataPrecision());
@@ -293,8 +292,13 @@ std::shared_ptr<Node> NetworkHelper::setOutDataPrecision(std::shared_ptr<Operati
293292

294293
template <typename T>
295294
std::shared_ptr<Node> make_op_pattern(const ov::NodeVector& args) {
296-
return std::make_shared<ov::pass::pattern::op::Any>(element::undefined, PartialShape{},
297-
[](std::shared_ptr<Node> n) {return !!ov::as_type_ptr<T>(n); }, args);
295+
return std::make_shared<ov::pass::pattern::op::Any>(
296+
element::dynamic,
297+
PartialShape{},
298+
[](std::shared_ptr<Node> n) {
299+
return !!ov::as_type_ptr<T>(n);
300+
},
301+
args);
298302
}
299303

300304
template <typename T, typename... Args>

src/common/low_precision_transformations/src/concat.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ bool ConcatTransformation::canBeTransformed(const std::shared_ptr<Node>& layer)
300300
if (constant == nullptr) {
301301
return true;
302302
}
303-
if (const_precision == element::undefined) {
303+
if (const_precision == element::dynamic) {
304304
const_precision = constant->get_element_type();
305305
return true;
306306
}
@@ -320,7 +320,7 @@ bool ConcatTransformation::canBeTransformed(const std::shared_ptr<Node>& layer)
320320
return false;
321321
}
322322

323-
if (precision == element::undefined) {
323+
if (precision == element::dynamic) {
324324
precision = dequantization.data.get_element_type();
325325
} else if (precision != dequantization.data.get_element_type()) {
326326
return false;

src/common/low_precision_transformations/src/fake_quantize.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ std::shared_ptr<opset1::Constant> getConstant(const std::shared_ptr<Node>& eltwi
9393

9494
bool all_precisions_equal(const std::shared_ptr<Node>& node) {
9595
const auto& inputs = node->inputs();
96-
const auto first_input_precision = inputs.empty() ? element::undefined : inputs[0].get_element_type();
96+
const auto first_input_precision = inputs.empty() ? element::dynamic : inputs[0].get_element_type();
9797
if (!inputs.empty()) {
9898
const auto first_input_precision = inputs[0].get_element_type();
9999
if (std::any_of(
@@ -109,7 +109,7 @@ bool all_precisions_equal(const std::shared_ptr<Node>& node) {
109109
const auto& outputs = node->outputs();
110110
if (!outputs.empty()) {
111111
const auto first_output_precision = outputs[0].get_element_type();
112-
if ((first_input_precision != element::undefined) && (first_input_precision != first_output_precision)) {
112+
if ((first_input_precision != element::dynamic) && (first_input_precision != first_output_precision)) {
113113
return false;
114114
}
115115

src/common/low_precision_transformations/src/fake_quantize_decomposition.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ bool FakeQuantizeDecompositionTransformation::transform(ov::pass::pattern::Match
306306

307307
const DataPrecision expectedDataPrecision = fq_decomposition::getDataPrecisionByOutputPortAndFakeQuantize(layer);
308308
// TODO: need test to compose FakeQuantize
309-
if ((expectedDataPrecision.precision == element::undefined) || (expectedDataPrecision.precision == outputPrecision)) {
309+
if ((expectedDataPrecision.precision == element::dynamic) ||
310+
(expectedDataPrecision.precision == outputPrecision)) {
310311
return rewritten;
311312
}
312313

@@ -363,7 +364,7 @@ bool FakeQuantizeDecompositionTransformation::transform(ov::pass::pattern::Match
363364

364365
// if IntervalsAlignment attribute is defined then, the attribute defines decomposition parameters,
365366
// if IntervalsAlignment attribute is not defined, then FakeQuantize operation intervals define decomposition parameters
366-
if (dataPrecision.precision == element::undefined) {
367+
if (dataPrecision.precision == element::dynamic) {
367368
element::Type precision;
368369
const auto levels = layer->get_levels();
369370
const std::vector<float> outputLowValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(3))->cast_vector<float>();

src/common/low_precision_transformations/src/layer_transformation.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ LayerTransformation::PrecisionDetails LayerTransformation::getPrecisionDetails(
268268
unsignedPrecision = !signedPrecision;
269269
}
270270

271-
element::Type resultPrecision = element::undefined;
271+
element::Type resultPrecision = element::dynamic;
272272
// if zero point exists then result precision has to be defined by client code
273273
if (!hasZeroPoint) {
274274
if (signedPrecision && (!unsignedPrecision)) {
@@ -335,8 +335,7 @@ DataPrecision LayerTransformation::getDataPrecision(
335335
printDequantizationInfo(layer);
336336
#endif
337337
PrecisionDetails precisionDetailsAtOutputIntervals = getPrecisionDetails(quantizationDetails);
338-
339-
if (precisionDetailsAtOutputIntervals.precision != element::undefined) {
338+
if (precisionDetailsAtOutputIntervals.precision != element::dynamic) {
340339
// FakeQuantize optimal precision not deined
341340
if (!requiredPrecisions.empty()) {
342341
const auto foundIt = std::find(requiredPrecisions.begin(), requiredPrecisions.end(), precisionDetailsAtOutputIntervals.precision);

src/common/low_precision_transformations/src/multiply_to_group_convolution.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool MultiplyToGroupConvolutionTransformation::transform(ov::pass::pattern::Matc
5454
dequantization = NetworkHelper::foldDequantization(multiply, inputIndex, defaultPrecisions);
5555
}
5656

57-
element::Type weightsPrecision = element::undefined;
57+
element::Type weightsPrecision = element::dynamic;
5858
if (updatePrecisions) {
5959
// try to find restrictions on weights for GroupConvolution
6060
if (restrictions.size() > 1ul) {
@@ -65,7 +65,7 @@ bool MultiplyToGroupConvolutionTransformation::transform(ov::pass::pattern::Matc
6565
}
6666

6767
// if restrictions are absent precisions attribute is used
68-
if (weightsPrecision == element::undefined) {
68+
if (weightsPrecision == element::dynamic) {
6969
const auto precisionsAttribute = getAttribute<PrecisionsAttribute>(multiply->input(inputIndex == 0ul ? 1ul : 0ul));
7070
const auto precisions = precisionsAttribute == nullptr ?
7171
defaultPrecisions :

0 commit comments

Comments
 (0)