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

Automatic type inference for param_t in Parametrised Activations #1139

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

Conversation

nghielme
Copy link
Contributor

@nghielme nghielme commented Dec 4, 2024

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

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

Tests

I run some tests related to Parametrised Activations, already present in the pytests of hls4ml.

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.

@nghielme nghielme requested a review from jmitrevs December 5, 2024 06:53
@nghielme nghielme added the please test Trigger testing by creating local PR branch label Dec 5, 2024
@nghielme
Copy link
Contributor Author

nghielme commented Dec 9, 2024

I see some tests related to oneAPI fails; it's hard to me to understand why they fail, how should I proceed?

@JanFSchulte JanFSchulte added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Dec 16, 2024
@jmitrevs
Copy link
Contributor

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.

@@ -1,4 +1,5 @@
import math
import struct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Struct is much too low level for what we are doing here. We have a python float. We should use it, not look at the bits.

inferred_types.append('param_t')
def get_man_exp(f):
f = np.abs(f)
s = struct.pack('>f', f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use calculations: based on the value, you can easily determine how many bits you need. Going to structs is hard to follow.

@jmitrevs
Copy link
Contributor

@JanFSchulte
Copy link
Contributor

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 typedef ac_fixed<16,6,true> quantizer_param_t; to a one-bit typedef ac_fixed<1,0,false> quantizer_param_t;. Vivado and the other backends seem to be able to handle it, but I'm not sure it makes sense in this case because we have negative slopes here and need it to be signed. The other backends seem to be able to deal with it. But for oneAPI, a signed variable is enforced to have at least two bits:

signed _BitInt must have a bit size of at least 2

So we need to make sure to take this into account when inferring the precision for the parameters.

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.

3 participants