Fix weight precision format string #877
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Observed in #874 but not limited to zero-integer quantizers, the generated HLS doesn't achieve bit-perfect matching with the QKeras model. This turns out to be due to the initialization of the weights from literals. We print literals with
{:#f}
(where#
is the number of digits required), but this doesn't work correctly and we should instead use{:.#f}
(with the leading.
). For example:ap_fixed<8,1>
would interpret the literal0.320312
as a value0.3125
, messing up the result. This one-liner (in fact one-character) fixes #874 (and alike).Type of change
Tests
Existing QKeras tests should suffice, we should eventually aim for a stricter agreement, ideally bit-perfect one, but that's a separate change.
Checklist
pre-commit
on the files I edited or added.