Skip to content

Commit

Permalink
Merge pull request #1146 from fastmachinelearning/fix_pointwise_res_type
Browse files Browse the repository at this point in the history
Don't overwrite already set accum_t, fix pointwise output resolution
  • Loading branch information
JanFSchulte authored Dec 14, 2024
2 parents cc4fbf9 + 1d0cf1e commit 0dd372a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example-models
10 changes: 6 additions & 4 deletions hls4ml/backends/fpga/fpga_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ def set_thresholds(self, scale, bias, ternary_threshold=0.5):
class PointwiseConv1D(Conv1D):
'''Optimized Conv1D implementation for 1x1 kernels.'''

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


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

# Nothing to do, will pick up function and config from class name
pass
def initialize(self):
# Do noting, values copied
pass
10 changes: 6 additions & 4 deletions hls4ml/model/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ def _wrap_precision_to_type(self, name, precision):
return NamedType(name=name, precision=precision)

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

def _set_type_t(self, name):
has_type_t = any(a for a in self.expected_attributes if a.name == name + '_t' and isinstance(a, TypeAttribute))
Expand Down
2 changes: 1 addition & 1 deletion hls4ml/model/optimizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
'convert',
[
'channels_last_converter',
'merge_linear_activation',
'seperable_to_depthwise_and_conv',
'remove_transpose_before_flatten',
'remove_nop_transpose',
Expand All @@ -74,6 +73,7 @@
'replace_multidimensional_dense_with_conv',
'enforce_proxy_model_embedded_config',
'eliminate_linear_activation',
'merge_linear_activation',
# many of the above optimzers need to be done before this
'infer_precision_types',
],
Expand Down

0 comments on commit 0dd372a

Please sign in to comment.