diff options
Diffstat (limited to 'verif')
-rw-r--r-- | verif/frameworks/tensor_gen.py | 13 | ||||
-rwxr-xr-x | verif/frameworks/tosa_verif_framework_generator.py | 17 |
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) ) |