hls4ml
hls4ml copied to clipboard
Add support for HGQ proxy model
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:
- When heterogeneous activation quantization is used, do value masking (with code generation). If not, the layer is removed.
- Overrides precision settings for other layers. All precision settings are embedded into these layers in a proxy model.
- 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 withSAT
orWRAP
(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
- [x] 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
- [x] I have read the guidelines for contributing.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [x] I have installed and run
pre-commit
on the files I edited or added. - [x] I have added tests that prove my fix is effective or that my feature works.