Skip to content

Commit 13b3e47

Browse files
authored
[TF FE] Stabilize Bitwise layer tests on all platforms and fix u16 bug (#25843)
**Details:** Fix u16 bug "Tensor data with element type u16, is not representable as pointer to i32" **Ticket:** 122716 --------- Signed-off-by: Kazantsev, Roman <roman.kazantsev@intel.com>
1 parent d2ab797 commit 13b3e47

File tree

3 files changed

+84
-15
lines changed

3 files changed

+84
-15
lines changed

src/frontends/tensorflow/src/tf_utils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Any unpack_tensor_proto(const ::tensorflow::TensorProto& tensor_proto,
297297
break;
298298
case u16:
299299
val_size = tensor_proto.int_val_size();
300-
extract_compressed_tensor_content<uint16_t, int32_t>(tensor_proto, val_size, &res);
300+
extract_compressed_tensor_content<uint16_t, uint16_t>(tensor_proto, val_size, &res);
301301
break;
302302
case u64:
303303
val_size = tensor_proto.uint64_val_size();

tests/layer_tests/tensorflow_tests/test_tf_BinaryOps.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Copyright (C) 2018-2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
import platform
5-
64
import numpy as np
5+
import platform
76
import pytest
87
from common.tf_layer_test_class import CommonTFLayerTest
98

@@ -66,15 +65,12 @@ def create_add_placeholder_const_net(self, x_shape, y_shape, op_type):
6665
'FloorMod': tf.raw_ops.FloorMod,
6766
'FloorDiv': tf.raw_ops.FloorDiv,
6867
'Xdivy': tf.raw_ops.Xdivy,
69-
'BitwiseAnd': tf.raw_ops.BitwiseAnd,
70-
'BitwiseOr': tf.raw_ops.BitwiseOr,
71-
'BitwiseXor': tf.raw_ops.BitwiseXor,
7268
}
7369

7470
input_type = np.float32
7571
if op_type in ["LogicalAnd", "LogicalOr", "LogicalXor"]:
7672
input_type = bool
77-
elif op_type in ["BitwiseAnd", "BitwiseOr", "BitwiseXor", 'Pow']:
73+
elif op_type in ['Pow']:
7874
input_type = np.int32
7975
self.input_type = input_type
8076

@@ -100,21 +96,21 @@ def create_add_placeholder_const_net(self, x_shape, y_shape, op_type):
10096
@pytest.mark.parametrize("op_type",
10197
['Add', 'AddV2', 'Sub', 'Mul', 'Div', 'RealDiv', 'SquaredDifference', 'Pow',
10298
'Maximum', 'Minimum', 'Equal', 'NotEqual', 'Mod', 'Greater', 'GreaterEqual', 'Less',
103-
'LessEqual', 'LogicalAnd', 'LogicalOr', 'FloorMod', 'FloorDiv',
104-
'Xdivy', 'BitwiseAnd', 'BitwiseOr', 'BitwiseXor', ])
99+
'LessEqual', 'LogicalAnd', 'LogicalOr', 'FloorMod', 'FloorDiv', 'Xdivy'])
105100
@pytest.mark.nightly
106101
@pytest.mark.precommit
107102
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
108103
reason='Ticket - 122716')
109104
def test_binary_op(self, x_shape, y_shape, ie_device, precision, ir_version, temp_dir, op_type,
110105
use_legacy_frontend):
111-
if use_legacy_frontend and op_type in ['BitwiseAnd', 'BitwiseOr', 'BitwiseXor', 'Xdivy']:
112-
pytest.skip("Bitwise and Xdivy ops are supported only by new TF FE.")
113-
if op_type in ['BitwiseAnd', 'BitwiseOr', 'BitwiseXor', 'Pow', 'Mod'] and ie_device == 'GPU':
114-
pytest.skip("GPU does not support Bitwise ops. For Mod and Pow it has inference mismatch")
106+
if use_legacy_frontend and op_type in ['Xdivy']:
107+
pytest.skip("Xdivy op is supported only by new TF FE.")
108+
if op_type in ['Pow', 'Mod'] and ie_device == 'GPU':
109+
pytest.skip("For Mod and Pow GPU has inference mismatch")
115110
if op_type in ['Mod', 'FloorDiv', 'FloorMod']:
116111
pytest.skip("Inference mismatch for Mod and FloorDiv")
117-
if ie_device == 'GPU' and precision == 'FP16' and op_type in ['Equal', 'NotEqual', 'Greater', 'GreaterEqual', 'Less', 'LessEqual']:
118-
pytest.skip("Accuracy mismatch on GPU")
112+
if ie_device == 'GPU' and precision == 'FP16' and op_type in ['Equal', 'NotEqual', 'Greater', 'GreaterEqual',
113+
'Less', 'LessEqual']:
114+
pytest.skip("Accuracy mismatch on GPU")
119115
self._test(*self.create_add_placeholder_const_net(x_shape=x_shape, y_shape=y_shape, op_type=op_type), ie_device,
120116
precision, ir_version, temp_dir=temp_dir, use_legacy_frontend=use_legacy_frontend)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Copyright (C) 2018-2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import numpy as np
5+
import platform
6+
import pytest
7+
import tensorflow as tf
8+
from common.tf_layer_test_class import CommonTFLayerTest
9+
10+
rng = np.random.default_rng(21097)
11+
12+
op_type_to_tf = {
13+
'BitwiseAnd': tf.raw_ops.BitwiseAnd,
14+
'BitwiseOr': tf.raw_ops.BitwiseOr,
15+
'BitwiseXor': tf.raw_ops.BitwiseXor,
16+
}
17+
18+
19+
def generate_input(x_shape, x_type):
20+
if np.issubdtype(x_type, np.signedinteger):
21+
return rng.integers(-100, 100, x_shape).astype(x_type)
22+
return rng.integers(0, 200, x_shape).astype(x_type)
23+
24+
25+
class TestBitwise(CommonTFLayerTest):
26+
def _prepare_input(self, inputs_info):
27+
inputs_data = {}
28+
29+
assert 'x:0' in inputs_info, "Test error: inputs_info must contain `x`"
30+
x_shape = inputs_info['x:0']
31+
inputs_data['x:0'] = generate_input(x_shape, self.input_type)
32+
if not self.is_y_const:
33+
assert 'y:0' in inputs_info, "Test error: inputs_info must contain `y`"
34+
y_shape = inputs_info['y:0']
35+
inputs_data['y:0'] = generate_input(y_shape, self.input_type)
36+
return inputs_data
37+
38+
def create_bitwise_net(self, x_shape, y_shape, is_y_const, input_type, op_type):
39+
self.is_y_const = is_y_const
40+
self.input_type = input_type
41+
tf.compat.v1.reset_default_graph()
42+
# Create the graph and model
43+
with tf.compat.v1.Session() as sess:
44+
x = tf.compat.v1.placeholder(input_type, x_shape, 'x')
45+
if is_y_const:
46+
constant_value = generate_input(y_shape, input_type)
47+
y = tf.constant(constant_value, dtype=input_type)
48+
else:
49+
y = tf.compat.v1.placeholder(input_type, y_shape, 'y')
50+
op_type_to_tf[op_type](x=x, y=y, name=op_type)
51+
52+
tf.compat.v1.global_variables_initializer()
53+
tf_net = sess.graph_def
54+
55+
ref_net = None
56+
57+
return tf_net, ref_net
58+
59+
@pytest.mark.parametrize('x_shape', [[4], [3, 4], [1, 2, 3, 4]])
60+
@pytest.mark.parametrize('y_shape', [[4], [2, 3, 4]])
61+
@pytest.mark.parametrize('is_y_const', [True, False])
62+
@pytest.mark.parametrize('input_type', [np.int8, np.int16, np.int32, np.int64,
63+
np.uint8, np.uint16, np.uint32, np.uint64])
64+
@pytest.mark.parametrize("op_type", ['BitwiseAnd', 'BitwiseOr', 'BitwiseXor'])
65+
@pytest.mark.precommit
66+
@pytest.mark.nightly
67+
def test_bitwise(self, x_shape, y_shape, is_y_const, input_type, op_type, ie_device, precision, ir_version,
68+
temp_dir, use_legacy_frontend):
69+
if ie_device == 'GPU':
70+
pytest.skip("148540: Bitwise ops are not supported on GPU")
71+
self._test(*self.create_bitwise_net(x_shape=x_shape, y_shape=y_shape, is_y_const=is_y_const,
72+
input_type=input_type, op_type=op_type),
73+
ie_device, precision, ir_version, temp_dir=temp_dir, use_legacy_frontend=use_legacy_frontend)

0 commit comments

Comments
 (0)