Skip to content

add max_precision to onnx parser #1113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions hls4ml/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def make_layer_config(layer):


def config_from_onnx_model(
model, granularity='name', backend=None, default_precision='ap_fixed<16,6>', default_reuse_factor=1
model, granularity='name', backend=None, default_precision='fixed<16,6>', default_reuse_factor=1, max_precision=None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why this change of removing the ap_? Should I do the same in #1112?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is backend-agnostic, so there's no reason to put ap_ or ac_. (I think the ones without a prefix follow the ap_style, though, with regard to signedness, using uint/ufixed instead of false being passed as an argument.) The right type should be produced based on the backend, since it will internally go to the FixedPrecisionType. I think all thee styles are supported, those with either prefix, or without a prefix, regardless of the backend (i.e. there's no reason to change this when you switch backends).

):
"""Create an HLS conversion config given the ONNX model.

Expand All @@ -435,6 +435,8 @@ def config_from_onnx_model(
backend(str, optional): Name of the backend to use
default_precision (str, optional): Default precision to use. Defaults to 'fixed<16,6>'.
default_reuse_factor (int, optional): Default reuse factor. Defaults to 1.
max_precision (str or None, optional): Maximum width precision to use. Defaults to None, meaning no maximum.
Note: Only integer and fixed precisions are supported

Raises:
Exception: If ONNX model has layers not supported by hls4ml.
Expand All @@ -456,9 +458,14 @@ def config_from_onnx_model(
config = {}

model_config = {}
model_config['Precision'] = default_precision
model_config['Precision'] = {}
model_config['Precision']['default'] = default_precision
if max_precision is not None:
model_config['Precision']['maximum'] = max_precision
model_config['ReuseFactor'] = default_reuse_factor
model_config['Strategy'] = 'Latency'
model_config['BramFactor'] = 1_000_000_000
model_config['TraceOutput'] = False

config['Model'] = model_config

Expand Down
Loading