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

Fixes: quantized_relu & unsigned profiling #405

Merged
merged 2 commits into from
Oct 7, 2021

Conversation

thesps
Copy link
Contributor

@thesps thesps commented Sep 29, 2021

Note: bugfixes targeting release branch

quantized_relu

Since this change, we assign the wrong data type to quantized_relu activations. It sets the correct type for quantized_bits, just not quantized_relu. This is what causes the tests flagged in #377 to fail.

Using the example of the hls4ml-tutorial Part3 QKeras model which uses quantized_relu(6) activations, on master branch we assign ap_fixed<6,1>. But appropriate choices would be instead ap_fixed<7,1> (signed) or ap_ufixed<6,0> (unsigned). I've chosen to go for the ap_ufixed case for the fix since it uses fewer bits.

You can see that the types we currently assign to the relu layers are wrong in the profiling:

Screenshot 2021-09-29 at 16 35 10

The model accuracy is:

  • 0.743656 QKeras on CPU (reference / target)
  • 0.743542 hls4ml on master branch
  • 0.743855 hls4ml on this PR (identical if ap_fixed<7,1> was used instead)

The synthesis results slightly prefer the ap_ufixed variation which has one fewer bit than the necessary ap_fixed option.

quantized_relu precision Accuracy Latency II LUT FF DSP BRAM18
ap_ufixed<6,0> 0.743855 9 1 33706 3037 119 4
ap_fixed<7,1> 0.743855 9 1 37523 3155 119 4

The quantized_relu tests now pass, so they are included again, resolving #377. I added a few more variations as well.

unsigned profiling

In fixing the above, I noticed that we don't display unsigned types correctly in the profiling, so I include the fix for that as well. (Separate commits in case they need to be taken separately).

Before (master):

Screenshot 2021-09-29 at 16 53 33

After (this PR):

Screenshot 2021-09-29 at 16 32 10

Copy link
Member

@jmduarte jmduarte left a comment

Choose a reason for hiding this comment

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

Thanks @thesps! This looks really good. I just have one minor comment

hls4ml/model/profiling.py Show resolved Hide resolved
@jmduarte jmduarte self-requested a review October 5, 2021 17:42
Copy link
Member

@jmduarte jmduarte left a comment

Choose a reason for hiding this comment

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

Looks good!

@thesps thesps merged commit b361265 into fastmachinelearning:release-v0.6.0 Oct 7, 2021
@thesps thesps deleted the qrelu_fix branch October 7, 2021 13:54
@thesps thesps restored the qrelu_fix branch November 5, 2021 14:10
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