Skip to content

Commit 0c5ffd0

Browse files
authored
Merge branch 'main' into nested_model
2 parents f426b8c + abaea98 commit 0c5ffd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+441
-472
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exclude: (^hls4ml\/templates\/(vivado|quartus)\/(ap_types|ac_types)\/|^test/pyte
22

33
repos:
44
- repo: https://github.com/psf/black
5-
rev: 22.12.0
5+
rev: 23.3.0
66
hooks:
77
- id: black
88
language_version: python3
@@ -30,18 +30,18 @@ repos:
3030
args: ["--profile", "black", --line-length=125]
3131

3232
- repo: https://github.com/asottile/pyupgrade
33-
rev: v3.3.1
33+
rev: v3.6.0
3434
hooks:
3535
- id: pyupgrade
3636
args: ["--py36-plus"]
3737

3838
- repo: https://github.com/asottile/setup-cfg-fmt
39-
rev: v2.2.0
39+
rev: v2.3.0
4040
hooks:
4141
- id: setup-cfg-fmt
4242

4343
- repo: https://github.com/pycqa/flake8
44-
rev: 5.0.4
44+
rev: 6.0.0
4545
hooks:
4646
- id: flake8
4747
exclude: docs/conf.py

contrib/kl_layer/kl_layer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def build(self, input_shape):
3434
super().build(input_shape)
3535

3636
def _merge_function(self, inputs):
37-
3837
mean = inputs[0]
3938
log_var = inputs[1]
4039

hls4ml/backends/fpga/fpga_backend.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ def product_type(self, data_T, weight_T):
391391
return product
392392

393393
def compute_conv1d_instructions(self, in_W, in_C, kernel_size=3, stride=1, pad=0):
394-
395394
# Current limitations
396395
assert pad == 0
397396

@@ -427,7 +426,6 @@ def compute_conv1d_instructions(self, in_W, in_C, kernel_size=3, stride=1, pad=0
427426
return (min_W, windows_int)
428427

429428
def compute_conv2d_instructions(self, in_H, in_W, in_C, kernel_size=3, stride=1, pad=0):
430-
431429
if isinstance(kernel_size, Iterable):
432430
kernel_height = kernel_size[0]
433431
kernel_width = kernel_size[1]

hls4ml/backends/quartus/passes/convolution_winograd.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def match(self, node):
8282
def transform(self, model, node):
8383
if isinstance(node, Conv1D):
8484
if node.get_attr('filt_width', 3) == 3:
85-
8685
# First, transpose to a format suitable for the Winograd algorithm (F, C, W)
8786
# Note, this assumes a format post-resource strategy optimizer, that is (F, W, C)
8887
# Therefore, (F, W, C) => (F, C, W)
@@ -127,7 +126,6 @@ def transform(self, model, node):
127126

128127
elif isinstance(node, Conv2D):
129128
if node.get_attr('filt_height', 3) == 3 and node.get_attr('filt_width', 3) == 3:
130-
131129
# First, transpose to a format suitable for the Winograd algorithm (F, C, H, W)
132130
# Note, this assumes a format post-resource strategy optimizer, that is (F, H, W, C)
133131
# Therefore, (F, H, W, C) => (F, C, H, W)

hls4ml/backends/quartus/quartus_backend.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ def create_initial_config(self, part='Arria10', clock_period=5, io_type='io_para
133133
return config
134134

135135
def build(self, model, synth=True, fpgasynth=False, log_level=1, cont_if_large_area=False):
136-
137136
"""
138137
Builds the project using Intel HLS compiler.
139138

hls4ml/backends/vivado/passes/convolution_templates.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
static const unsigned n_out = {n_out};
1010
static const unsigned reuse_factor = {reuse};
1111
static const unsigned strategy = nnet::{strategy};
12-
static const unsigned n_zeros = 0;
12+
static const unsigned n_zeros = {nzeros};
1313
static const unsigned multiplier_limit = DIV_ROUNDUP(n_in * n_out, reuse_factor) - n_zeros / reuse_factor;
1414
typedef {accum_t.name} accum_t;
1515
typedef {bias_t.name} bias_t;
@@ -83,6 +83,7 @@ def format(self, node):
8383
mult_params = self._default_config_params(node)
8484
mult_params['n_in'] = node.get_attr('n_chan') * node.get_attr('filt_width')
8585
mult_params['n_out'] = node.get_attr('n_filt')
86+
mult_params['nzeros'] = node.get_weights('weight').nzeros
8687
mult_params['product_type'] = get_backend('vivado').product_type(
8788
node.get_input_variable().type.precision, node.get_weights('weight').type.precision
8889
)
@@ -189,6 +190,7 @@ def format(self, node):
189190
mult_params = self._default_config_params(node)
190191
mult_params['n_in'] = node.get_attr('n_chan') * node.get_attr('filt_height') * node.get_attr('filt_width')
191192
mult_params['n_out'] = node.get_attr('n_filt')
193+
mult_params['nzeros'] = node.get_weights('weight').nzeros
192194
mult_params['product_type'] = get_backend('vivado').product_type(
193195
node.get_input_variable().type.precision, node.get_weights('weight').type.precision
194196
)
@@ -274,6 +276,7 @@ def format(self, node):
274276
mult_params['index'] = str(node.index) + '_depthwise'
275277
mult_params['n_in'] = node.get_attr('n_chan') * node.get_attr('filt_width')
276278
mult_params['n_out'] = node.get_attr('n_chan')
279+
mult_params['nzeros'] = node.get_weights('depthwise').nzeros
277280
mult_params['weight_t'] = node.get_weights('depthwise').type
278281
mult_params['product_type'] = get_backend('vivado').product_type(
279282
node.get_input_variable().type.precision, node.get_weights('depthwise').type.precision
@@ -313,6 +316,7 @@ def format(self, node):
313316
mult_params['index'] = str(node.index) + '_pointwise'
314317
mult_params['n_in'] = node.get_attr('n_chan')
315318
mult_params['n_out'] = node.get_attr('n_filt')
319+
mult_params['nzeros'] = node.get_weights('pointwise').nzeros
316320
mult_params['weight_t'] = node.get_weights('pointwise').type
317321
mult_params['product_type'] = get_backend('vivado').product_type(
318322
node.get_input_variable().type.precision, node.get_weights('pointwise').type.precision
@@ -395,6 +399,7 @@ def format(self, node):
395399
mult_params['index'] = str(node.index) + '_depthwise'
396400
mult_params['n_in'] = node.get_attr('n_chan') * node.get_attr('filt_height') * node.get_attr('filt_width')
397401
mult_params['n_out'] = node.get_attr('n_chan')
402+
mult_params['nzeros'] = node.get_weights('depthwise').nzeros
398403
mult_params['weight_t'] = node.get_weights('depthwise').type
399404
mult_params['product_type'] = get_backend('vivado').product_type(
400405
node.get_input_variable().type.precision, node.get_weights('depthwise').type.precision
@@ -438,6 +443,7 @@ def format(self, node):
438443
mult_params['index'] = str(node.index) + '_pointwise'
439444
mult_params['n_in'] = node.get_attr('n_chan')
440445
mult_params['n_out'] = node.get_attr('n_filt')
446+
mult_params['nzeros'] = node.get_weights('pointwise').nzeros
441447
mult_params['weight_t'] = node.get_weights('pointwise').type
442448
mult_params['product_type'] = get_backend('vivado').product_type(
443449
node.get_input_variable().type.precision, node.get_weights('pointwise').type.precision

hls4ml/backends/vivado/passes/recurrent_templates.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def __init__(self):
7979
self.mult2_template = recr_mult_config_template
8080

8181
def format(self, node):
82-
8382
params = self._default_config_params(node)
8483

8584
params['n_in'] = node.get_input_variable().dim_names[1]

hls4ml/backends/vivado/passes/resource_strategy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class ApplyResourceStrategy(OptimizerPass):
88
'''Transposes the weights to use the dense_resource matrix multiply routine'''
99

1010
def match(self, node):
11-
1211
node_matches = isinstance(node, (Dense, Conv1D, SeparableConv1D, Conv2D, SeparableConv2D, LSTM, GRU))
1312
is_resource_strategy = node.get_attr('strategy', '').lower() == 'resource'
1413
already_transformed = node.get_attr('_weights_transposed', False) is True

hls4ml/converters/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
warnings.warn("WARNING: ONNX converter is not enabled!", stacklevel=1)
3535
__onnx_enabled__ = False
3636

37-
try:
38-
from hls4ml.converters.tf_to_hls import tf_to_hls
39-
40-
__tensorflow_enabled__ = True
41-
except ImportError:
42-
warnings.warn("WARNING: Tensorflow converter is not enabled!", stacklevel=1)
43-
__tensorflow_enabled__ = False
44-
4537
# ----------Layer handling register----------#
4638
model_types = ['keras', 'pytorch', 'onnx']
4739

@@ -57,7 +49,6 @@
5749
# and is defined in this module (i.e., not imported)
5850
if callable(func) and hasattr(func, 'handles') and func.__module__ == lib.__name__:
5951
for layer in func.handles:
60-
6152
if model_type == 'keras':
6253
register_keras_layer_handler(layer, func)
6354
elif model_type == 'pytorch':
@@ -139,11 +130,6 @@ def convert_from_config(config):
139130
model = pytorch_to_hls(yamlConfig)
140131
else:
141132
raise Exception("PyTorch not found. Please install PyTorch.")
142-
elif 'TensorFlowModel' in yamlConfig:
143-
if __tensorflow_enabled__:
144-
model = tf_to_hls(yamlConfig)
145-
else:
146-
raise Exception("TensorFlow not found. Please install TensorFlow.")
147133
else:
148134
model = keras_to_hls(yamlConfig)
149135

hls4ml/converters/keras/convolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def parse_conv2d_layer(keras_layer, input_names, input_shapes, data_reader):
4444

4545
(layer['in_height'], layer['in_width'], layer['n_chan']) = parse_data_format(input_shapes[0], layer['data_format'])
4646

47-
if layer['class_name'] in ['Conv2D', 'QConv2D']:
47+
if layer['class_name'] in ['Conv2D', 'QConv2D', 'QConv2DBatchnorm']:
4848
layer['weight_data'] = get_weights_data(data_reader, layer['name'], 'kernel')
4949
elif layer['class_name'] in ['SeparableConv2D', 'QSeparableConv2D']:
5050
layer['depthwise_data'], layer['pointwise_data'] = get_weights_data(

0 commit comments

Comments
 (0)