-
Notifications
You must be signed in to change notification settings - Fork 476
Automatic type inference for param_t
in Parametrised Activations
#1139
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
base: main
Are you sure you want to change the base?
Conversation
I see some tests related to oneAPI fails; it's hard to me to understand why they fail, how should I proceed? |
If you have a linux setup it should be pretty straightforward to install oneAPI, and then you can run the pytest. But we can wait to look at the other issues first. Maybe it will clear itself. |
Note the utility we have in hls4ml already: |
I wanted to try to install oneAPI myself, so I played with this PR a bit. The issue seems to be that the precision for the parameter of the leaky ReLU is reduced significantly, from
So we need to make sure to take this into account when inferring the precision for the parameters. |
Hey @nghielme any news on this one? |
I'll take a look soon |
Please check the logic of the precision setting. |
I added a unit test to cover the various options, so I am more confident. It did discover an error in the max setting for unsigned FixedPrecisionType, which I fixed, and am including here, though it's logically independent. |
else: | ||
# find a constant to represent the values | ||
param = node.get_attr('activ_param') | ||
precision = _get_precision_from_constant(param) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly, we are basically hard-coding the bit width of the parameter to be 8 (9 if signed) and assign the fractional and integer bits based on the value. Is that correct? Because trying to find a way to infer the needed total precision has been something that has stumped me forever when working on the brevitas stuff, but it seems that here as well the only solution is to hardcode some arbitrary value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's mainly for those where the cases above don't apply. For 0 values we just use 1 bit. For power of 2 values we use a width of 1 or 2, depending on whether is negative or not. Then comes the attempt to use Fxp
from fxpmath
, which is logically like struct
. It works well for values like 1.25
of things that can be represented exactly. In those cases, the optimizer uses the width from Fxp
. But if that produces a width larger than 8 (not including the sign bit), then the size is capped at 8, with the appropriate range being set by the integer size. Note that Fxp would otherwise attempt to use 56 bits to store 1.1
. These we cut off at 8 bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks. I think I will then implement something similar to the non-power-of-2 cases for brevitas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The optimizer can set negative integer bitwidths if it needs the precision for smaller values.
There were some weird pytest failures that I'm rerunning, but otherwise I think this can be merged now. |
Looks good to me. One small note, I think the test could be rewritten in a more
|
Tests have only the "expected" failures now, so I think this is ok. I agree with Nicolo's comment on the pytest though, so if you could integrate that before merging that would be great, Jovan. |
This small PR implement the inference of W and I parameter for a given floating point constant. It is exploited in parametrised activations
Type of change
Tests
I run some tests related to Parametrised Activations, already present in the pytests of hls4ml.
Checklist
pre-commit
on the files I edited or added.