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

[core] Deprecate undefined type and use dynamic where possible #28766

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
22 changes: 11 additions & 11 deletions samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ int main(int argc, char* argv[]) {
if (result != config.end())
device_config = result->second;
size_t batchSize = FLAGS_b;
ov::element::Type type = ov::element::undefined;
ov::element::Type type = ov::element::dynamic;
std::string topology_name = "";
std::vector<benchmark_app::InputsInfo> app_inputs_info;
std::string output_name;
Expand Down Expand Up @@ -660,14 +660,14 @@ int main(int argc, char* argv[]) {
std::const_pointer_cast<const ov::Model>(model)->outputs());
}

const auto input_precision = FLAGS_ip.empty() ? ov::element::undefined : getPrecision2(FLAGS_ip);
const auto output_precision = FLAGS_op.empty() ? ov::element::undefined : getPrecision2(FLAGS_op);
const auto input_precision = FLAGS_ip.empty() ? ov::element::dynamic : getPrecision2(FLAGS_ip);
const auto output_precision = FLAGS_op.empty() ? ov::element::dynamic : getPrecision2(FLAGS_op);

const auto& inputs = model->inputs();
for (size_t i = 0; i < inputs.size(); i++) {
const auto& item = inputs[i];
auto iop_precision = ov::element::undefined;
auto type_to_set = ov::element::undefined;
auto iop_precision = ov::element::dynamic;
auto type_to_set = ov::element::dynamic;
std::string name;
try {
// Some tensors might have no names, get_any_name will throw exception in that case.
Expand All @@ -677,17 +677,17 @@ int main(int argc, char* argv[]) {
} catch (...) {
}

if (iop_precision != ov::element::undefined) {
if (iop_precision != ov::element::dynamic) {
type_to_set = iop_precision;
} else if (input_precision != ov::element::undefined) {
} else if (input_precision != ov::element::dynamic) {
type_to_set = input_precision;
} else if (!name.empty() && app_inputs_info[0].at(name).is_image()) {
// image input, set U8
type_to_set = ov::element::u8;
}

auto& in = preproc.input(item.get_any_name());
if (type_to_set != ov::element::undefined) {
if (type_to_set != ov::element::dynamic) {
in.tensor().set_element_type(type_to_set);

if (!name.empty()) {
Expand All @@ -707,17 +707,17 @@ int main(int argc, char* argv[]) {
const auto& outs = model->outputs();
for (size_t i = 0; i < outs.size(); i++) {
const auto& item = outs[i];
auto iop_precision = ov::element::undefined;
auto iop_precision = ov::element::dynamic;
try {
// Some tensors might have no names, get_any_name will throw exception in that case.
// -iop option will not work for those tensors.
iop_precision = getPrecision2(user_precisions_map.at(item.get_any_name()));
} catch (...) {
}

if (iop_precision != ov::element::undefined) {
if (iop_precision != ov::element::dynamic) {
preproc.output(i).tensor().set_element_type(iop_precision);
} else if (output_precision != ov::element::undefined) {
} else if (output_precision != ov::element::dynamic) {
preproc.output(i).tensor().set_element_type(output_precision);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/c/src/ov_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "common.h"

const std::map<ov_element_type_e, ov::element::Type> element_type_map = {
{ov_element_type_e::UNDEFINED, ov::element::undefined},
{ov_element_type_e::UNDEFINED, ov::element::dynamic},
{ov_element_type_e::DYNAMIC, ov::element::dynamic},
{ov_element_type_e::BOOLEAN, ov::element::boolean},
{ov_element_type_e::BF16, ov::element::bf16},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def tf_type_to_ov_type(tf_type_int):
try:
ret_type = Type(numpy_type)
except:
ret_type = Type.undefined
ret_type = Type.dynamic
return ret_type


Expand Down Expand Up @@ -169,7 +169,7 @@ def get_attribute(self, name):
return OVAny(Type.dynamic)
return OVAny(tf_type_to_ov_type(variable_value.dtype))
else:
return OVAny(Type.undefined)
return OVAny(Type.dynamic)
return OVAny(tf_type_to_ov_type(type_num))

if name == "value":
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/python/src/pyopenvino/core/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void regclass_Tensor(py::module m) {
}),
py::arg("array"),
py::arg("shape"),
py::arg("type") = ov::element::undefined,
py::arg("type") = ov::element::dynamic,
py::keep_alive<1, 2>(),
R"(
Another Tensor's special constructor.
Expand Down Expand Up @@ -76,7 +76,7 @@ void regclass_Tensor(py::module m) {
}),
py::arg("array"),
py::arg("shape"),
py::arg("type") = ov::element::undefined,
py::arg("type") = ov::element::dynamic,
py::keep_alive<1, 2>(),
R"(
Another Tensor's special constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void regclass_graph_PreProcessSteps(py::module m) {
[](ov::preprocess::PreProcessSteps& self, ov::element::Type type = {}) {
return &self.convert_element_type(type);
},
py::arg_v("type", ov::element::undefined, "openvino.Type.undefined"),
py::arg_v("type", ov::element::dynamic, "openvino.Type.dynamic"),
R"(
Converts input tensor element type to specified type.
Input tensor must have openvino.Type data type.
Expand Down Expand Up @@ -239,7 +239,7 @@ static void regclass_graph_PostProcessSteps(py::module m) {
[](ov::preprocess::PostProcessSteps& self, ov::element::Type type = {}) {
return &self.convert_element_type(type);
},
py::arg_v("type", ov::element::undefined, "openvino.Type.undefined"),
py::arg_v("type", ov::element::dynamic, "openvino.Type.dynamic"),
R"(
Converts tensor element type to specified type.
Tensor must have openvino.Type data type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void regclass_graph_Type(py::module m) {
:rtype: ov.Type
)");

type.attr("undefined") = ov::element::undefined;
type.attr("undefined") = ov::element::dynamic;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you check that deprecation warning is also thrown for Python API?

type.attr("dynamic") = ov::element::dynamic;
type.attr("boolean") = ov::element::boolean;
type.attr("f16") = ov::element::f16;
Expand Down
20 changes: 6 additions & 14 deletions src/bindings/python/tests/test_runtime/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,17 @@ def test_basic_ovtypes(ovtype,

def test_undefined_ovtype():
ov_type = Type.undefined
assert ov_type.is_static() is True
assert ov_type.is_dynamic() is False
assert ov_type.is_static() is False
assert ov_type.is_dynamic() is True
assert ov_type.is_real() is False
assert ov_type.real is False
assert ov_type.is_integral() is True
assert ov_type.integral is True
assert ov_type.is_signed() is False
assert ov_type.signed is False
assert ov_type.is_quantized() is False
assert ov_type.quantized is False
assert ov_type.get_type_name() == "undefined"
assert ov_type.type_name == "undefined"
assert ov_type.get_size() == 0
assert ov_type.get_type_name() == "dynamic"
assert ov_type.size == 0

# Note: might depend on the system
import sys
assert ov_type.bitwidth == sys.maxsize * 2 + 1
assert ov_type.get_bitwidth() == sys.maxsize * 2 + 1
assert ov_type.get_size() == 0
assert ov_type.bitwidth == 0
assert ov_type.get_bitwidth() == 0


def test_dynamic_ov_type():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace precision_set {

class LP_TRANSFORMATIONS_API DataPrecision {
public:
DataPrecision() : precision(element::undefined), min(0.f), max(0.f), hasZeroPoint(false) {}
DataPrecision() : precision(element::dynamic), min(0.f), max(0.f), hasZeroPoint(false) {}

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

bool empty() const noexcept {
assert(
((precision == element::undefined) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint)) ||
((precision != element::undefined) && (max != 0.f)));
return (precision == element::undefined) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint);
assert(((precision == element::dynamic) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint)) ||
((precision != element::dynamic) && (max != 0.f)));
return (precision == element::dynamic) && (min == 0.f) && (max == 0.f) && (!hasZeroPoint);
}

static bool isSupported(const element::Type& precision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ class LP_TRANSFORMATIONS_API NetworkHelper {

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

static FakeQuantizeDequantizationValues createEmptyValues(
const FakeQuantizeDequantization& dequantization,
const element::Type& precision = element::undefined);
static FakeQuantizeDequantizationValues createEmptyValues(const FakeQuantizeDequantization& dequantization,
const element::Type& precision = element::dynamic);

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

template <typename T>
std::shared_ptr<Node> make_op_pattern(const ov::NodeVector& args) {
return std::make_shared<ov::pass::pattern::op::Any>(element::undefined, PartialShape{},
[](std::shared_ptr<Node> n) {return !!ov::as_type_ptr<T>(n); }, args);
return std::make_shared<ov::pass::pattern::op::Any>(
element::dynamic,
PartialShape{},
[](std::shared_ptr<Node> n) {
return !!ov::as_type_ptr<T>(n);
},
args);
}

template <typename T, typename... Args>
Expand Down
4 changes: 2 additions & 2 deletions src/common/low_precision_transformations/src/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ bool ConcatTransformation::canBeTransformed(const std::shared_ptr<Node>& layer)
if (constant == nullptr) {
return true;
}
if (const_precision == element::undefined) {
if (const_precision == element::dynamic) {
const_precision = constant->get_element_type();
return true;
}
Expand All @@ -320,7 +320,7 @@ bool ConcatTransformation::canBeTransformed(const std::shared_ptr<Node>& layer)
return false;
}

if (precision == element::undefined) {
if (precision == element::dynamic) {
precision = dequantization.data.get_element_type();
} else if (precision != dequantization.data.get_element_type()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ std::shared_ptr<opset1::Constant> getConstant(const std::shared_ptr<Node>& eltwi

bool all_precisions_equal(const std::shared_ptr<Node>& node) {
const auto& inputs = node->inputs();
const auto first_input_precision = inputs.empty() ? element::undefined : inputs[0].get_element_type();
const auto first_input_precision = inputs.empty() ? element::dynamic : inputs[0].get_element_type();
if (!inputs.empty()) {
const auto first_input_precision = inputs[0].get_element_type();
if (std::any_of(
Expand All @@ -109,7 +109,7 @@ bool all_precisions_equal(const std::shared_ptr<Node>& node) {
const auto& outputs = node->outputs();
if (!outputs.empty()) {
const auto first_output_precision = outputs[0].get_element_type();
if ((first_input_precision != element::undefined) && (first_input_precision != first_output_precision)) {
if ((first_input_precision != element::dynamic) && (first_input_precision != first_output_precision)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ bool FakeQuantizeDecompositionTransformation::transform(ov::pass::pattern::Match

const DataPrecision expectedDataPrecision = fq_decomposition::getDataPrecisionByOutputPortAndFakeQuantize(layer);
// TODO: need test to compose FakeQuantize
if ((expectedDataPrecision.precision == element::undefined) || (expectedDataPrecision.precision == outputPrecision)) {
if ((expectedDataPrecision.precision == element::dynamic) ||
(expectedDataPrecision.precision == outputPrecision)) {
return rewritten;
}

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

// if IntervalsAlignment attribute is defined then, the attribute defines decomposition parameters,
// if IntervalsAlignment attribute is not defined, then FakeQuantize operation intervals define decomposition parameters
if (dataPrecision.precision == element::undefined) {
if (dataPrecision.precision == element::dynamic) {
element::Type precision;
const auto levels = layer->get_levels();
const std::vector<float> outputLowValues = ov::as_type_ptr<opset1::Constant>(layer->get_input_node_shared_ptr(3))->cast_vector<float>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ LayerTransformation::PrecisionDetails LayerTransformation::getPrecisionDetails(
unsignedPrecision = !signedPrecision;
}

element::Type resultPrecision = element::undefined;
element::Type resultPrecision = element::dynamic;
// if zero point exists then result precision has to be defined by client code
if (!hasZeroPoint) {
if (signedPrecision && (!unsignedPrecision)) {
Expand Down Expand Up @@ -336,7 +336,7 @@ DataPrecision LayerTransformation::getDataPrecision(
#endif
PrecisionDetails precisionDetailsAtOutputIntervals = getPrecisionDetails(quantizationDetails);

if (precisionDetailsAtOutputIntervals.precision != element::undefined) {
if (precisionDetailsAtOutputIntervals.precision != element::dynamic) {
// FakeQuantize optimal precision not deined
if (!requiredPrecisions.empty()) {
const auto foundIt = std::find(requiredPrecisions.begin(), requiredPrecisions.end(), precisionDetailsAtOutputIntervals.precision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool MultiplyToGroupConvolutionTransformation::transform(ov::pass::pattern::Matc
dequantization = NetworkHelper::foldDequantization(multiply, inputIndex, defaultPrecisions);
}

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

// if restrictions are absent precisions attribute is used
if (weightsPrecision == element::undefined) {
if (weightsPrecision == element::dynamic) {
const auto precisionsAttribute = getAttribute<PrecisionsAttribute>(multiply->input(inputIndex == 0ul ? 1ul : 0ul));
const auto precisions = precisionsAttribute == nullptr ?
defaultPrecisions :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ std::shared_ptr<ov::opset1::Constant> NetworkHelper::normalizeDequantizationShap
}

FakeQuantizeDequantizationValues NetworkHelper::createEmptyValues(const FakeQuantizeDequantization& dequantization, const element::Type& prc) {
const auto precision = prc == element::undefined ? dequantization.getPrecision() : prc;
const auto precision = prc == element::dynamic ? dequantization.getPrecision() : prc;
const std::shared_ptr<Node> multiplyConstant = dequantization.multiply ?
dequantization.multiplyConstant->get_element_type() != precision ?
foldConvert(dequantization.multiplyConstant->output(0), precision) :
Expand Down Expand Up @@ -1897,4 +1897,4 @@ bool NetworkHelper::checkConstantNotInf(const std::shared_ptr<Node> constant_nod
}
} // namespace low_precision
} // namespace pass
} // namespace ov
} // namespace ov
17 changes: 12 additions & 5 deletions src/common/low_precision_transformations/src/recurrent_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@ bool isSupportedForPerChannelQuantization(const std::shared_ptr<Node>& node) {
std::vector<std::pair<size_t, element::Type>> get_supported_precisions(std::shared_ptr<ov::Node> lstm) {
// pair fields:
// 0 - input number,
// 1 - input type, `element::undefined` - any precision
// 1 - input type, `element::dynamic` - any precision
if (is_type<ov::opset5::LSTMSequence>(lstm)) {
return std::vector<std::pair<size_t, element::Type>>{ {0, element::u8}, { 1, element::u8 }, { 4, element::undefined }, { 5, element::undefined } };
return std::vector<std::pair<size_t, element::Type>>{{0, element::u8},
{1, element::u8},
{4, element::dynamic},
{5, element::dynamic}};
} else if (is_type<ov::opset5::GRUSequence>(lstm)) {
return std::vector<std::pair<size_t, element::Type>>{ {0, element::u8}, { 1, element::u8 }, { 3, element::undefined }, { 4, element::undefined } };
return std::vector<std::pair<size_t, element::Type>>{{0, element::u8},
{1, element::u8},
{3, element::dynamic},
{4, element::dynamic}};
}

OPENVINO_THROW("unsupported operation type: ", lstm->get_type_name());
Expand Down Expand Up @@ -163,7 +169,8 @@ bool RecurrentCellTransformation::transform(ov::pass::pattern::Matcher& m) {
defaultPrecisions :
precisionsAttribute.as<PrecisionsAttribute>().value();
const auto& dataPrecision = getDataPrecision(fq, quantizationDetails, precisions);
if (dataPrecision.empty() || ((input.second != element::undefined) && (dataPrecision.precision != input.second))) {
if (dataPrecision.empty() ||
((input.second != element::dynamic) && (dataPrecision.precision != input.second))) {
return false;
}

Expand Down Expand Up @@ -257,7 +264,7 @@ bool RecurrentCellTransformation::canBeTransformed(const std::shared_ptr<Node>&
if (dequantization.empty()) {
continue;
}
if ((index.second != element::undefined) && (dequantization.data.get_element_type() != index.second)) {
if ((index.second != element::dynamic) && (dequantization.data.get_element_type() != index.second)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ov::Any IntervalsAlignmentAttribute::create(
outputLowValues,
outputHighValues);

if (preferablePrecision.precision != element::undefined) {
if (preferablePrecision.precision != element::dynamic) {
attribute.value().preferablePrecisions.insert(preferablePrecision.precision);
}

Expand Down
Loading
Loading