aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWon Jeon <won.jeon@arm.com>2023-07-08 07:04:08 +0000
committerWon Jeon <won.jeon@arm.com>2023-07-11 18:00:12 +0000
commit6c93f41dcb781dde1351ecff549df2a753d5e9c6 (patch)
tree8e559480b359c78eae771c6ac5bfbc692fec7fc1
parent4053ce14aa636fc21c9a2c953cba3c212e7eddd3 (diff)
downloadreference_model-6c93f41dcb781dde1351ecff549df2a753d5e9c6.tar.gz
Fix size mismatch of placeholders for broadcast fuzzing
Signed-off-by: Won Jeon <won.jeon@arm.com> Change-Id: Ib954db4f8f2fd5008e95d5651a6e84a8f5b7161d
-rw-r--r--verif/frameworks/tensor_gen.py13
-rwxr-xr-xverif/frameworks/tosa_verif_framework_generator.py17
2 files changed, 13 insertions, 17 deletions
diff --git a/verif/frameworks/tensor_gen.py b/verif/frameworks/tensor_gen.py
index d50bc74..d0c0a0b 100644
--- a/verif/frameworks/tensor_gen.py
+++ b/verif/frameworks/tensor_gen.py
@@ -91,7 +91,7 @@ class TGen:
return tf_placeholders, tf_consts
@staticmethod
- def tgBFuzz(op, shape, dtype, rng, fuzzed=[]):
+ def tgBFuzz(op, shape, dtype, rng, for_tflite_converter=True):
# Build random tensor placeholder node args of a given shape, optionally
# fuzzing the arguments with random 1's to force broadcasting
@@ -99,22 +99,23 @@ class TGen:
assert const == 0
- fuzz_arg = rng.integers(0, pl + const)
- fuzz_idx = rng.integers(0, len(shape))
+ if not for_tflite_converter:
+ fuzz_arg = rng.integers(0, pl + const)
+ fuzz_idx = rng.integers(0, len(shape))
tf_placeholders = []
tf_consts = []
+
for i in range(pl):
- if not fuzzed and i == fuzz_arg:
+ if not for_tflite_converter and i == fuzz_arg:
# Insert the broadcast in one dimension index
s_fuzz = list(shape)
s_fuzz[fuzz_idx] = 1
s_fuzz = tuple(s_fuzz)
i_shape = s_fuzz
- # Record the fuzzed index.
- fuzzed.append(i)
else:
i_shape = shape
+
tf_placeholders.append(
("placeholder_{}".format(i), TGen.getRand(i_shape, dtype, rng))
)
diff --git a/verif/frameworks/tosa_verif_framework_generator.py b/verif/frameworks/tosa_verif_framework_generator.py
index 09a06b4..124bf6e 100755
--- a/verif/frameworks/tosa_verif_framework_generator.py
+++ b/verif/frameworks/tosa_verif_framework_generator.py
@@ -960,13 +960,10 @@ def run_unit_test(
# Get and seed a random number generator for this test
rng = np.random.default_rng(seed)
- # For broadcast fuzzing, record the fuzzed index if fuzzing is already done.
- fuzzed = []
-
# return placeholders=(str: name, np.array: value)
# consts=(str: name, np.array: value)
placeholders, consts = (
- tensor_gen_fcn(op, curr_shape, dtype, rng, fuzzed)
+ tensor_gen_fcn(op, curr_shape, dtype, rng, False)
if tensor_gen_fcn.__name__ == "tgBFuzz"
else tensor_gen_fcn(op, curr_shape, dtype, rng)
)
@@ -1122,12 +1119,10 @@ def run_unit_test(
max_val = float(qmax - qzero[idx]) * scale
else:
scale = (max_val - min_val) / float(qmax - qmin)
- zeropoint = -int(round((-min_val) / scale)) + qmin
-
- # Exit if min_val <= 0.0, in order to avoid assertion error
- # from tf.quantization.fake_quant_with_min_max_args
- if min_val > 0.0:
- return True
+ if op_name == "squared_difference":
+ zeropoint = -int(round((-min_val) / scale)) + qmin
+ else:
+ zeropoint = int(round((-min_val) / scale)) + qmin
# run through tf.fakequant first to assure quantization error aligned
fakequant_val = tf.quantization.fake_quant_with_min_max_args(
@@ -1177,7 +1172,7 @@ def run_unit_test(
def input_stats():
for i in range(0, args.num_samples):
placeholders, _ = (
- tensor_gen_fcn(op, placeholder_shapes[0], dtype, rng, fuzzed)
+ tensor_gen_fcn(op, placeholder_shapes[0], dtype, rng, True)
if tensor_gen_fcn == "tgBFuzz"
else tensor_gen_fcn(op, placeholder_shapes[0], dtype, rng)
)