Skip to content

Fix over-allocation of bits for quantised po2 #806

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
Jun 16, 2023

Conversation

bo3z
Copy link
Contributor

@bo3z bo3z commented Jun 12, 2023

Description

  • When using power-of-2 multiplications, the current implementation assigns too many bits
  • In Vivado, there is a limit of 65,536 bits, which will be allocated when the weights are quantised in QKeras with 17 or more bits and a power of 2
  • The multiplication can be computed in far less bits - it only requires the width of the input and weights combined, not the power of that.
  • This problem is very sneaky - it is very rare to train with QKeras with a bit-width of more than 16 - however, the alpha parameter in QKeras can often be more than 16 bits (when it is not specified by the user to be 1 - attached is a quantised jet classification model that initially found this bug - model)

Type of change

  • Bug fix (non-breaking change that fixes an issue)

Tests

  • Extend test_qkeras.py to test power of 2 multiplication with a high number and ensure the outputs match.

Checklist

  • I have read the guidelines for contributing.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have installed and run pre-commit on the files I edited or added.
  • I have added tests that prove my fix is effective or that my feature works.

@bo3z bo3z mentioned this pull request Jun 16, 2023
8 tasks
@jmitrevs jmitrevs merged commit f2d389f into fastmachinelearning:main Jun 16, 2023
calad0i pushed a commit to calad0i/hls4ml that referenced this pull request Jul 1, 2023
Fix over-allocation of bits for quantised po2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants