Skip to content

Commit d947cdb

Browse files
committed
Merge branch 'pytorch_auto' of https://github.com/JanFSchulte/hls4ml into pytorch_auto
2 parents 01d4f79 + dab7b85 commit d947cdb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

hls4ml/model/layers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def initialize(self):
357357

358358

359359
class Constant(Layer):
360-
# one could consider making this a weight attribute, but given it's transient nature, I am not sure it helps
360+
# one could consider making this a weight attribute, but given its transient nature, I am not sure it helps
361361
_expected_attributes = [
362362
Attribute('value', value_type=np.ndarray),
363363
]
@@ -371,6 +371,10 @@ def initialize(self):
371371
dims = [f'{self.name}_{i}' for i in range(len(shape))]
372372
quantizer = self.get_attr('quantizer')
373373

374+
# the graph._make_graph function sets the input node to the previous node
375+
# if it is not set. That is incorrect for Constant nodes, so remove the input node
376+
self.inputs = []
377+
374378
# Should the else clause below be None or UnspecifiedPrecisionType
375379
precision = quantizer.hls_type if quantizer is not None else UnspecifiedPrecisionType()
376380

hls4ml/utils/config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def make_layer_config(layer):
422422

423423

424424
def config_from_onnx_model(
425-
model, granularity='name', backend=None, default_precision='ap_fixed<16,6>', default_reuse_factor=1
425+
model, granularity='name', backend=None, default_precision='fixed<16,6>', default_reuse_factor=1, max_precision=None
426426
):
427427
"""Create an HLS conversion config given the ONNX model.
428428
@@ -444,6 +444,8 @@ def config_from_onnx_model(
444444
backend(str, optional): Name of the backend to use
445445
default_precision (str, optional): Default precision to use. Defaults to 'fixed<16,6>'.
446446
default_reuse_factor (int, optional): Default reuse factor. Defaults to 1.
447+
max_precision (str or None, optional): Maximum width precision to use. Defaults to None, meaning no maximum.
448+
Note: Only integer and fixed precisions are supported
447449
448450
Raises:
449451
Exception: If ONNX model has layers not supported by hls4ml.
@@ -465,9 +467,14 @@ def config_from_onnx_model(
465467
config = {}
466468

467469
model_config = {}
468-
model_config['Precision'] = default_precision
470+
model_config['Precision'] = {}
471+
model_config['Precision']['default'] = default_precision
472+
if max_precision is not None:
473+
model_config['Precision']['maximum'] = max_precision
469474
model_config['ReuseFactor'] = default_reuse_factor
470475
model_config['Strategy'] = 'Latency'
476+
model_config['BramFactor'] = 1_000_000_000
477+
model_config['TraceOutput'] = False
471478

472479
config['Model'] = model_config
473480

0 commit comments

Comments
 (0)