Skip to content
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

Fix problem with scale being a multidimensional array. #1132

Merged
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
6 changes: 3 additions & 3 deletions hls4ml/model/optimizer/passes/quant_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def match(self, node):
scale_unit_or_po2 = (scale == np.ones_like(scale)).all()
if not scale_unit_or_po2 and _ALSO_MATCH_PO2:
# This optimization only works if all scales are the same
if np.all(scale[0] == scale):
mantissa, _ = np.frexp(scale[0])
if np.all(scale.item(0) == scale):
mantissa, _ = np.frexp(scale.item(0))
scale_unit_or_po2 = mantissa == 0.5

is_match = scale_unit_or_po2
Expand All @@ -187,7 +187,7 @@ def transform(self, model, node):
integer = bitwidth
scale = node.get_attr('scale')
if _ALSO_MATCH_PO2 and not (scale == np.ones_like(scale)).all():
_, exp = np.frexp(scale[0]) # know that np.all(scale[0] == scale) must be true
_, exp = np.frexp(scale.item(0)) # know that np.all(scale.item(0) == scale) must be true
integer = bitwidth + exp - 1

precision, quantizer = _calculate_precision_quantizer(bitwidth, integer, signed, narrow, rounding_mode)
Expand Down
Loading