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

Add support for HGQ proxy model #914

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

calad0i
Copy link
Contributor

@calad0i calad0i commented Nov 7, 2023

Requires #973 and python>=3.10 now.

Description

This PR adds support for a special layer type FixedPointQuantizer used in calad0i/HGQ/hls4ml-integration to facilitate conversion from HGQ model to hls4ml model graph. ModelGraph converted from proxy-model is meant to be bit-accurate, until fp32 (or tf32) cannot emulate the required precision during tensorflow model inference.

The layer has three major functions:

  1. When heterogeneous activation quantization is used, do value masking (with code generation). If not, the layer is removed.
  2. Overrides precision settings for other layers. All precision settings are embedded into these layers in a proxy model.
  3. Though not used in hls4ml, when fp32 can represent the required precision, the proxy model can be used to emulate hls models' output, with or without overflows with SAT or WRAP (other overflow modes not tested).

In the future, the proxy model mechanism can also be used with Qkeras models, but this part is not yet implemented.

#912 could still break bit-accuracy for pooling layer with io_stream. Temporary fix available at #917 (included), superseded by #855 when available.

New (09/01/24):

  • Rebased to current master and squashed commits for basic HGQ proxy (also supports QKeras partially) support.

  • Allowing converting any unary activation function to a LUT, ensuring bit-accuracy for all unary activation functions. Performance in resource and timing may be better or worse depending on the input data format.

TODO

If the python version for hls4ml bumps to >=3.10, we can make HGQ an optional dependency for hls4ml and re-use tests from there. We can remove the re-defining of FixedPointQuantizer in hls4ml also.

Independent of this PR, Conv2D in Quartus with 3x3 filter size with io_parallel seems to be broken at the moment, some tests are expected to fail at the moment. The cause seems to be related to the winograd implementation.

This PR dependents on #887 #906 #907 #908 #909 #911 All merged now.

Type of change

  • New feature (non-breaking change which adds functionality)

Tests

test/pytest/test_proxy_model.py

Test Configuration:

Requires models add in fastmachinelearning/example-models#11.

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.

@calad0i calad0i closed this Nov 7, 2023
@calad0i calad0i reopened this Nov 7, 2023
@calad0i calad0i changed the title [DRAFT] Add support proxy model Add support proxy model Nov 7, 2023
@calad0i calad0i force-pushed the HGQ-integration branch 2 times, most recently from 5301b4d to 97f4eb2 Compare November 9, 2023 09:20
@calad0i calad0i changed the title Add support proxy model Add support for HGQ proxy model Nov 9, 2023
@vloncar vloncar added this to the v1.0.0 milestone Nov 10, 2023
@jmitrevs jmitrevs added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Jan 31, 2024
@calad0i calad0i mentioned this pull request Feb 21, 2024
7 tasks
@calad0i calad0i force-pushed the HGQ-integration branch 2 times, most recently from c14e299 to a24bfc2 Compare February 23, 2024 02:24
@jmitrevs jmitrevs added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Mar 15, 2024
latency pooling overhaul

vivado latency pooling overhaul

vitis latency pooling overhaul, fix comment

fix boundry cond

fix syn issues

latency pooling overhaul

Fix pooling accum_t autoset & avoid global override

[pre-commit.ci] auto fixes from pre-commit hooks

better way to get inp layer name

fix for vitis / input_t fetch

torch padding fix

avoid name dup in torch api test

rm pooling precision override in favor of fastmachinelearning#855
Support UnaryLUT w/ vivado&io_parallel

hotfix

format

support vivado_stream

fix syn issue

fix syn issue2

Revert unnecessary "fix syn issue1/2"

Revert "fix syn issue2"

This reverts commit af3c347.

Revert "fix syn issue"

This reverts commit 532cb9d.

rm redundant pipeline pragma

unary lut vitis fix

unary lut vitis fix - leftover
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please test Trigger testing by creating local PR branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants