Skip to content

Commit

Permalink
[TEST] revert support of different types
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-kochin committed Dec 14, 2023
1 parent 1d03b08 commit 8da24c4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 158 deletions.
17 changes: 15 additions & 2 deletions src/frontends/tensorflow/src/graph_iterator_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ namespace frontend {
namespace tensorflow {

bool GraphIteratorMeta::is_valid_signature(const ::tensorflow::SignatureDef& signature) const {
const std::map<::tensorflow::DataType, ov::element::Type> types{
{::tensorflow::DataType::DT_BOOL, ov::element::boolean},
{::tensorflow::DataType::DT_INT16, ov::element::i16},
{::tensorflow::DataType::DT_INT32, ov::element::i32},
{::tensorflow::DataType::DT_INT64, ov::element::i64},
{::tensorflow::DataType::DT_HALF, ov::element::f16},
{::tensorflow::DataType::DT_FLOAT, ov::element::f32},
{::tensorflow::DataType::DT_DOUBLE, ov::element::f64},
{::tensorflow::DataType::DT_UINT8, ov::element::u8},
{::tensorflow::DataType::DT_INT8, ov::element::i8},
{::tensorflow::DataType::DT_BFLOAT16, ov::element::bf16},
{::tensorflow::DataType::DT_STRING, ov::element::dynamic}};

for (const auto& it : signature.inputs()) {
if (it.second.name().empty())
if (it.second.name().empty() || types.find(it.second.dtype()) == types.end())
return false;
}
for (const auto& it : signature.outputs()) {
if (it.second.name().empty())
if (it.second.name().empty() || types.find(it.second.dtype()) == types.end())
return false;
}
return true;
Expand Down
17 changes: 15 additions & 2 deletions src/frontends/tensorflow/src/graph_iterator_saved_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ namespace frontend {
namespace tensorflow {

bool GraphIteratorSavedModel::is_valid_signature(const ::tensorflow::SignatureDef& signature) const {
const std::map<::tensorflow::DataType, ov::element::Type> types{
{::tensorflow::DataType::DT_BOOL, ov::element::boolean},
{::tensorflow::DataType::DT_INT16, ov::element::i16},
{::tensorflow::DataType::DT_INT32, ov::element::i32},
{::tensorflow::DataType::DT_INT64, ov::element::i64},
{::tensorflow::DataType::DT_HALF, ov::element::f16},
{::tensorflow::DataType::DT_FLOAT, ov::element::f32},
{::tensorflow::DataType::DT_DOUBLE, ov::element::f64},
{::tensorflow::DataType::DT_UINT8, ov::element::u8},
{::tensorflow::DataType::DT_INT8, ov::element::i8},
{::tensorflow::DataType::DT_BFLOAT16, ov::element::bf16},
{::tensorflow::DataType::DT_STRING, ov::element::dynamic}};

for (const auto& it : signature.inputs()) {
if (it.second.name().empty())
if (it.second.name().empty() || types.find(it.second.dtype()) == types.end())
return false;
}
for (const auto& it : signature.outputs()) {
if (it.second.name().empty())
if (it.second.name().empty() || types.find(it.second.dtype()) == types.end())
return false;
}
return true;
Expand Down
142 changes: 39 additions & 103 deletions src/frontends/tensorflow/src/tf_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ void extract_tensor_content(const std::string& tensor_content, Tensor* values) {
# pragma warning(disable : 4244) // possible loss of data
# pragma warning(disable : 4267) // possible loss of data
#endif
template <typename SRC_T, typename DST_T = SRC_T>
template <typename T>
void extract_compressed_tensor_content(const ::tensorflow::TensorProto& tensor_proto,
int64_t val_size,
Tensor* values) {
auto val_lastsaved = static_cast<SRC_T>(0);
auto values_data = values->data<DST_T>();
auto val_lastsaved = static_cast<T>(0);
auto values_data = values->data<T>();
for (size_t i = 0; i < values->get_size(); i++) {
if (val_size == 0) {
values_data[i] = static_cast<DST_T>(0);
values_data[i] = static_cast<T>(0);
} else if (static_cast<int64_t>(i) < val_size) {
auto val_i = static_cast<SRC_T>(0);
auto val_i = static_cast<T>(0);
switch (values->get_element_type()) {
// TODO: there are more element types to support here
case boolean:
Expand All @@ -113,34 +113,13 @@ void extract_compressed_tensor_content(const ::tensorflow::TensorProto& tensor_p
case f64:
val_i = tensor_proto.double_val()[i];
break;
case u8:
val_i = tensor_proto.int_val()[i];
break;
case u16:
val_i = tensor_proto.int_val()[i];
break;
case u64:
val_i = tensor_proto.uint64_val()[i];
break;
case i8:
val_i = tensor_proto.int_val()[i];
break;
case bf16:
val_i = bfloat16::from_bits(tensor_proto.half_val()[i]);
break;
case u32:
val_i = tensor_proto.uint32_val()[i];
break;
case i16:
val_i = tensor_proto.int_val()[i];
break;
default:
FRONT_END_THROW("Encountered unknown element type " + values->get_element_type().get_type_name());
}
values_data[i] = static_cast<DST_T>(val_i);
values_data[i] = val_i;
val_lastsaved = val_i;
} else {
values_data[i] = static_cast<DST_T>(val_lastsaved);
values_data[i] = val_lastsaved;
}
}
}
Expand Down Expand Up @@ -171,18 +150,16 @@ bool CfMarkerType::is_copyable() const {
}

Type get_ov_type(const ::tensorflow::DataType& type) {
using ::tensorflow::DataType;

static map<DataType, Type> type_map{
{DataType::DT_FLOAT, f32}, {DataType::DT_DOUBLE, f64}, {DataType::DT_INT32, i32},
{DataType::DT_UINT8, u8}, {DataType::DT_INT16, i16}, {DataType::DT_INT8, i8},
{DataType::DT_INT64, i64}, {DataType::DT_BOOL, boolean}, {DataType::DT_BFLOAT16, bf16},
{DataType::DT_UINT16, u16}, {DataType::DT_HALF, f16}, {DataType::DT_UINT32, u32},
{DataType::DT_UINT64, u64}, {DataType::DT_FLOAT_REF, f32}, {DataType::DT_DOUBLE_REF, f64},
{DataType::DT_INT32_REF, i32}, {DataType::DT_UINT8_REF, u8}, {DataType::DT_INT16_REF, i16},
{DataType::DT_INT8_REF, i8}, {DataType::DT_INT64_REF, i64}, {DataType::DT_BOOL_REF, boolean},
{DataType::DT_BFLOAT16_REF, bf16}, {DataType::DT_UINT16_REF, u16}, {DataType::DT_HALF_REF, f16},
{DataType::DT_UINT32_REF, u32}, {DataType::DT_UINT64_REF, u64}};
static const map<::tensorflow::DataType, Type> type_map{{::tensorflow::DataType::DT_BOOL, boolean},
{::tensorflow::DataType::DT_INT16, i16},
{::tensorflow::DataType::DT_INT32, i32},
{::tensorflow::DataType::DT_INT64, i64},
{::tensorflow::DataType::DT_HALF, f16},
{::tensorflow::DataType::DT_FLOAT, f32},
{::tensorflow::DataType::DT_DOUBLE, f64},
{::tensorflow::DataType::DT_UINT8, u8},
{::tensorflow::DataType::DT_INT8, i8},
{::tensorflow::DataType::DT_BFLOAT16, bf16}};

auto it = type_map.find(type);
// for all unsupported types return dynamic type
Expand Down Expand Up @@ -214,108 +191,67 @@ Any unpack_tensor_proto(const ::tensorflow::TensorProto& tensor_proto,
}
return data;
}

Tensor res(ov_type, pshape.get_shape());
auto tensor_content = tensor_proto.tensor_content();
if (!tensor_content.empty() && tensor_proto.has_tensor_shape()) {
switch (ov_type) {
case f32:
extract_tensor_content<float>(tensor_content, &res);
break;
case u8:
extract_tensor_content<uint8_t>(tensor_content, &res);
break;
case i64:
extract_tensor_content<int64_t>(tensor_content, &res);
break;
case u16:
extract_tensor_content<uint16_t>(tensor_content, &res);
case i8:
extract_tensor_content<int8_t>(tensor_content, &res);
break;
case u64:
extract_tensor_content<uint64_t>(tensor_content, &res);
case i16:
extract_tensor_content<int16_t>(tensor_content, &res);
break;
case i32:
extract_tensor_content<int32_t>(tensor_content, &res);
break;
case i8:
extract_tensor_content<int8_t>(tensor_content, &res);
case i64:
extract_tensor_content<int64_t>(tensor_content, &res);
break;
case bf16:
extract_tensor_content<bfloat16>(tensor_content, &res);
case f16:
extract_tensor_content<float16>(tensor_content, &res);
break;
case u32:
extract_tensor_content<uint32_t>(tensor_content, &res);
case f32:
extract_tensor_content<float>(tensor_content, &res);
break;
case f64:
extract_tensor_content<double>(tensor_content, &res);
break;
case i16:
extract_tensor_content<int16_t>(tensor_content, &res);
break;
case boolean:
extract_tensor_content<bool>(tensor_content, &res);
break;
case f16:
extract_tensor_content<float16>(tensor_content, &res);
case bf16:
extract_tensor_content<bfloat16>(tensor_content, &res);
break;
default:
FRONT_END_THROW("Encountered unknown element type " + ov_type.get_type_name());
}
} else {
int64_t val_size = 0;
switch (ov_type) {
case f32:
val_size = tensor_proto.float_val_size();
extract_compressed_tensor_content<float>(tensor_proto, val_size, &res);
case boolean:
val_size = tensor_proto.bool_val_size();
extract_compressed_tensor_content<bool>(tensor_proto, val_size, &res);
break;
case u8:
case i32:
val_size = tensor_proto.int_val_size();
extract_compressed_tensor_content<int32_t, uint8_t>(tensor_proto, val_size, &res);
extract_compressed_tensor_content<int32_t>(tensor_proto, val_size, &res);
break;
case i64:
val_size = tensor_proto.int64_val_size();
extract_compressed_tensor_content<int64_t>(tensor_proto, val_size, &res);
break;
case u16:
val_size = tensor_proto.int_val_size();
extract_compressed_tensor_content<uint16_t, int32_t>(tensor_proto, val_size, &res);
break;
case u64:
val_size = tensor_proto.uint64_val_size();
extract_compressed_tensor_content<uint64_t>(tensor_proto, val_size, &res);
break;
case i32:
val_size = tensor_proto.int_val_size();
extract_compressed_tensor_content<int32_t>(tensor_proto, val_size, &res);
break;
case i8:
val_size = tensor_proto.int_val_size();
extract_compressed_tensor_content<int32_t, int8_t>(tensor_proto, val_size, &res);
break;
case bf16:
case f16:
val_size = tensor_proto.half_val_size();
extract_compressed_tensor_content<int32_t, bfloat16>(tensor_proto, val_size, &res);
extract_compressed_tensor_content<float16>(tensor_proto, val_size, &res);
break;
case u32:
val_size = tensor_proto.uint32_val_size();
extract_compressed_tensor_content<uint32_t>(tensor_proto, val_size, &res);
case f32:
val_size = tensor_proto.float_val_size();
extract_compressed_tensor_content<float>(tensor_proto, val_size, &res);
break;
case f64:
val_size = tensor_proto.double_val_size();
extract_compressed_tensor_content<double>(tensor_proto, val_size, &res);
break;
case i16:
val_size = tensor_proto.int_val_size();
extract_compressed_tensor_content<int32_t, int16_t>(tensor_proto, val_size, &res);
break;
case boolean:
val_size = tensor_proto.bool_val_size();
extract_compressed_tensor_content<bool>(tensor_proto, val_size, &res);
break;
case f16:
val_size = tensor_proto.half_val_size();
extract_compressed_tensor_content<int32_t, float16>(tensor_proto, val_size, &res);
break;
default:
FRONT_END_THROW("Encountered unknown element type " + ov_type.get_type_name());
}
Expand Down
51 changes: 0 additions & 51 deletions tests/layer_tests/tensorflow_tests/test_tf_AddTypes.py

This file was deleted.

0 comments on commit 8da24c4

Please sign in to comment.