@@ -284,6 +284,7 @@ def config_from_pytorch_model(
284
284
default_reuse_factor = 1 ,
285
285
channels_last_conversion = 'full' ,
286
286
transpose_outputs = True ,
287
+ max_precision = None ,
287
288
):
288
289
"""Create an HLS conversion config given the PyTorch model.
289
290
@@ -304,7 +305,8 @@ def config_from_pytorch_model(
304
305
will generate config keys for every layer separately, allowing for highly specific
305
306
configuration tweaks.
306
307
backend(str, optional): Name of the backend to use
307
- default_precision (str, optional): Default precision to use. Defaults to 'fixed<16,6>'.
308
+ default_precision (str, optional): Default precision to use. Defaults to 'fixed<16,6>'. Note, this must
309
+ be an explicit precision: 'auto' is not allowed.
308
310
default_reuse_factor (int, optional): Default reuse factor. Defaults to 1.
309
311
channels_last_conversion (string, optional): Configures the conversion of pytorch layers to
310
312
'channels_last' dataformate. Can be set to 'full', 'internal', or 'off'. If 'full', both the inputs
@@ -313,6 +315,8 @@ def config_from_pytorch_model(
313
315
transpose_outputs (bool, optional): Set to 'False' if the output should not be transposed from
314
316
channels_last into channels_first data format. Defaults to 'False'. If False, outputs needs
315
317
to be transposed manually.
318
+ max_precision (str or None, optional): Maximum width precision to use. Defaults to None, meaning no maximum.
319
+ Note: Only integer and fixed precisions are supported
316
320
317
321
Raises:
318
322
Exception: If PyTorch model has layers not supported by hls4ml.
@@ -324,11 +328,16 @@ def config_from_pytorch_model(
324
328
config = {}
325
329
326
330
model_config = {}
327
- model_config ['Precision' ] = default_precision
331
+ model_config ['Precision' ] = {}
332
+ model_config ['Precision' ]['default' ] = default_precision
333
+ if max_precision is not None :
334
+ model_config ['Precision' ]['maximum' ] = max_precision
328
335
model_config ['ReuseFactor' ] = default_reuse_factor
329
336
model_config ['ChannelsLastConversion' ] = channels_last_conversion
330
337
model_config ['TransposeOutputs' ] = transpose_outputs
331
338
model_config ['Strategy' ] = 'Latency'
339
+ model_config ['BramFactor' ] = 1_000_000_000
340
+ model_config ['TraceOutput' ] = False
332
341
333
342
config ['Model' ] = model_config
334
343
config ['PytorchModel' ] = model
@@ -372,7 +381,7 @@ def make_layer_config(layer):
372
381
if name .endswith ('_t' ):
373
382
name = name [:- 2 ]
374
383
if attr .default is None :
375
- precision_cfg [name ] = default_precision
384
+ precision_cfg [name ] = 'auto'
376
385
else :
377
386
precision_cfg [name ] = str (attr .default )
378
387
elif attr .name == 'reuse_factor' :
0 commit comments