Skip to content

Commit d6c0e16

Browse files
committed
model opt pass fix and avg pool fix
1 parent c5ad390 commit d6c0e16

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

hls4ml/model/optimizer/optimizer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,11 @@ def optimize_model(model, passes):
308308
optimization_done = False
309309
while not optimization_done:
310310
for opt_name, opt in optimizers.items():
311-
if isinstance(opt, ModelOptimizerPass) and opt_name not in applied_passes:
312-
res = opt.transform(model)
313-
if res:
314-
applied_passes.add(opt_name)
311+
if isinstance(opt, ModelOptimizerPass):
312+
if opt_name not in applied_passes:
313+
res = opt.transform(model)
314+
if res:
315+
applied_passes.add(opt_name)
315316
continue
316317
for node in model.graph.values():
317318
if opt.match(node):

hls4ml/model/optimizer/passes/bit_exact.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ def _(node: Pooling1D | Pooling2D | GlobalPooling1D | GlobalPooling2D):
759759
if pool_op != 'Average':
760760
return
761761
px_shape = _get_px_shape(node)
762-
i_add = int(log2(prod(px_shape)))
762+
# Used before division, also more int bits
763+
i_add = ceil(log2(prod(px_shape)))
763764
node.attributes['accum_t'].precision.width += i_add
764765
node.attributes['accum_t'].precision.integer += i_add
765766

@@ -804,7 +805,7 @@ def transform(self, model: 'ModelGraph'):
804805
if node.attributes.get('_request_kif'):
805806
del node.attributes['_request_kif']
806807

807-
return False
808+
return True
808809

809810

810811
class FixInputPrecision(OptimizerPass):
@@ -861,5 +862,3 @@ def transform(self, model, node: Layer):
861862
node.get_output_variable().type = new_type
862863
node.model.config.layer_name_precision[node.name] = str(new_type)
863864
return False
864-
node.model.config.layer_name_precision[node.name] = str(new_type)
865-
return False

0 commit comments

Comments
 (0)