Skip to content
Merged
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
Prev Previous commit
Next Next commit
Fix for uint8 type in tests
  • Loading branch information
ilyag-grovety committed Apr 12, 2023
commit 32c3176bbd88559ff705f2234c27dee682a34d70
4 changes: 2 additions & 2 deletions tests/python/contrib/test_ethosu/test_codegen.py
Comment thread
lhutton1 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ def representative_dataset():
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8 if dtype == "uint8" else tf.int8
converter.inference_output_type = tf.uint8 if dtype == "uint8" else tf.int8
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8
tflite_graph = converter.convert()
tflite_model = tflite.Model.Model.GetRootAsModel(tflite_graph, 0)

Expand Down
21 changes: 13 additions & 8 deletions tests/python/contrib/test_ethosu/test_legalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ def representative_dataset():
assert tuple(func_body.args[1].checked_type.shape) == (256,)


@pytest.mark.parametrize("ifm_dtype", ["int8", "uint8"])
@pytest.mark.parametrize("dtype", ["int8", "uint8"])
@pytest.mark.parametrize(
"ifm_shape, axis, keep_dims, use_same_quantization",
[
Expand All @@ -1555,7 +1555,7 @@ def representative_dataset():
[(1, 65, 2, 1), (1, 2), True, False], # special case when h > 64
],
)
def test_mean(ifm_shape, axis, keep_dims, use_same_quantization, ifm_dtype):
def test_mean(ifm_shape, axis, keep_dims, use_same_quantization, dtype):
def create_tflite_graph():
class Model(tf.Module):
@tf.function
Expand All @@ -1578,20 +1578,20 @@ def representative_dataset():
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8 if ifm_dtype == "uint8" else tf.int8
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8
tflite_model = converter.convert()
tflite_model = tflite.Model.Model.GetRootAsModel(tflite_model, 0)

mod, _ = relay.frontend.from_tflite(
tflite_model,
shape_dict={"input": ifm_shape},
dtype_dict={"input": ifm_dtype},
dtype_dict={"input": dtype},
)
return mod

def create_relay_graph_with_same_quantization():
ifm = relay.var("input", shape=ifm_shape, dtype=ifm_dtype)
ifm = relay.var("input", shape=ifm_shape, dtype=dtype)
cast = relay.cast(ifm, dtype="int32")
mean = relay.mean(cast, axis=axis, keepdims=keep_dims)
requantize = relay.qnn.op.requantize(
Expand All @@ -1600,6 +1600,7 @@ def create_relay_graph_with_same_quantization():
input_zero_point=relay.const(0, dtype="int32"),
output_scale=relay.const(1.0, dtype="float32"),
output_zero_point=relay.const(0, dtype="int32"),
out_dtype=dtype,
)

func = relay.Function(relay.analysis.free_vars(requantize), requantize)
Expand Down Expand Up @@ -1646,14 +1647,18 @@ def calculate_expected_output_shape():
assert tuple(in_var.checked_type.shape) == ifm_shape

if use_same_quantization:
assert in_var.checked_type.dtype == ifm_dtype
assert in_var.checked_type.dtype == dtype
else:
# depthwise case's partition makes in_var's dtype equal to int8
# in_var's dtype is equal to int8 due to TFLite's requantize
assert in_var.checked_type.dtype == "int8"

# check OFM
assert tuple(out_var.checked_type.shape) == out_shape
assert out_var.checked_type.dtype == "int8"
if use_same_quantization:
assert out_var.checked_type.dtype == dtype
else:
# out_var's dtype is equal to int8 due to TFLite's requantize
assert out_var.checked_type.dtype == "int8"

# check expected legalization case
if pooling_op:
Expand Down