From 72d52fd868ccbb430431ed89b2ad09de7cf4fa02 Mon Sep 17 00:00:00 2001 From: Chang Sun Date: Thu, 30 Nov 2023 12:19:13 -0800 Subject: [PATCH] fix proxy conversionn when there are garbages connected --- src/HGQ/proxy/convert.py | 2 ++ test/test_syn_hlayers.py | 8 +++++++- test/test_syn_large.py | 3 +++ test/test_syn_small.py | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/HGQ/proxy/convert.py b/src/HGQ/proxy/convert.py index 8c84494..65492ea 100644 --- a/src/HGQ/proxy/convert.py +++ b/src/HGQ/proxy/convert.py @@ -41,6 +41,8 @@ def solve_dependencies(model: keras.Model): if node.is_input: continue layer = node.layer + if layer not in model.layers: + continue requires = list(node.parent_nodes) provides = node dependencies_list.append((layer, requires, provides)) diff --git a/test/test_syn_hlayers.py b/test/test_syn_hlayers.py index 099ff73..8445150 100644 --- a/test/test_syn_hlayers.py +++ b/test/test_syn_hlayers.py @@ -26,7 +26,13 @@ def create_model(layer: str, rnd_strategy: str, io_type: str): _inp = HQuantize()(inp) else: raise Exception(f'Please add test for {layer}') - out = eval('HGQ.layers.' + layer)(_inp) + + _layer = eval('HGQ.layers.' + layer) + if hasattr(_layer, 'bias') and _layer.bias is not None: + bias: tf.Variable = _layer.bias + bias.assign(tf.constant(np.random.uniform(-4, 4, _layer.bias.shape).astype(np.float32))) + + out = _layer(_inp) model = keras.Model(inp, out) for layer in model.layers: diff --git a/test/test_syn_large.py b/test/test_syn_large.py index d0dbd2b..3ae75a6 100644 --- a/test/test_syn_large.py +++ b/test/test_syn_large.py @@ -52,6 +52,9 @@ def create_model(rnd_strategy: str, io_type: str): if hasattr(layer, 'paq'): fbw: tf.Variable = layer.paq.fbw fbw.assign(tf.constant(np.random.uniform(2, 6, fbw.shape).astype(np.float32))) + if hasattr(layer, 'bias') and layer.bias is not None: + bias: tf.Variable = layer.bias + bias.assign(tf.constant(np.random.uniform(-4, 4, layer.bias.shape).astype(np.float32))) return horrible_model diff --git a/test/test_syn_small.py b/test/test_syn_small.py index 0c51f81..aa270cb 100644 --- a/test/test_syn_small.py +++ b/test/test_syn_small.py @@ -39,6 +39,9 @@ def create_model(rnd_strategy: str, io_type: str): if hasattr(layer, 'paq'): fbw: tf.Variable = layer.paq.fbw fbw.assign(tf.constant(np.random.uniform(2, 6, fbw.shape).astype(np.float32))) + if hasattr(layer, 'bias') and layer.bias is not None: + bias: tf.Variable = layer.bias + bias.assign(tf.constant(np.random.uniform(-4, 4, layer.bias.shape).astype(np.float32))) return model