Skip to content

Commit 0dd372a

Browse files
authored
Merge pull request #1146 from fastmachinelearning/fix_pointwise_res_type
Don't overwrite already set accum_t, fix pointwise output resolution
2 parents cc4fbf9 + 1d0cf1e commit 0dd372a

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

example-models

hls4ml/backends/fpga/fpga_layers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ def set_thresholds(self, scale, bias, ternary_threshold=0.5):
7373
class PointwiseConv1D(Conv1D):
7474
'''Optimized Conv1D implementation for 1x1 kernels.'''
7575

76-
# Nothing to do, will pick up function and config from class name
77-
pass
76+
def initialize(self):
77+
# Do noting, values copied
78+
pass
7879

7980

8081
class PointwiseConv2D(Conv2D):
8182
'''Optimized Conv2D implementation for 1x1 kernels.'''
8283

83-
# Nothing to do, will pick up function and config from class name
84-
pass
84+
def initialize(self):
85+
# Do noting, values copied
86+
pass

hls4ml/model/layers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,12 @@ def _wrap_precision_to_type(self, name, precision):
176176
return NamedType(name=name, precision=precision)
177177

178178
def _set_accum_t(self):
179-
has_accum_t = any(a for a in self.expected_attributes if a.name == 'accum_t' and isinstance(a, TypeAttribute))
180-
if has_accum_t:
181-
accum_t = NamedType(*reversed(self.model.config.get_precision(self, 'accum')))
182-
self.set_attr('accum_t', accum_t)
179+
"""Set the accumulator, but don't overwrite an existing one"""
180+
if self.get_attr('accum_t') is None:
181+
has_accum_t = any(a for a in self.expected_attributes if a.name == 'accum_t' and isinstance(a, TypeAttribute))
182+
if has_accum_t:
183+
accum_t = NamedType(*reversed(self.model.config.get_precision(self, 'accum')))
184+
self.set_attr('accum_t', accum_t)
183185

184186
def _set_type_t(self, name):
185187
has_type_t = any(a for a in self.expected_attributes if a.name == name + '_t' and isinstance(a, TypeAttribute))

hls4ml/model/optimizer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
'convert',
6060
[
6161
'channels_last_converter',
62-
'merge_linear_activation',
6362
'seperable_to_depthwise_and_conv',
6463
'remove_transpose_before_flatten',
6564
'remove_nop_transpose',
@@ -74,6 +73,7 @@
7473
'replace_multidimensional_dense_with_conv',
7574
'enforce_proxy_model_embedded_config',
7675
'eliminate_linear_activation',
76+
'merge_linear_activation',
7777
# many of the above optimzers need to be done before this
7878
'infer_precision_types',
7979
],

0 commit comments

Comments
 (0)