Skip to content

Conversation

mschoenb97
Copy link
Contributor

@mschoenb97 mschoenb97 commented Apr 18, 2023

New quantizer to replace quantized_bits. Summary of improvements from old version:

  • Refactoring into smaller, simpler functions, enabling more features with less code
  • Better error handling
  • Removal of unnecessary computations

@mschoenb97 mschoenb97 changed the title Updates to quantized_bits Rewrite of quantized_bits Apr 18, 2023
@google-cla
Copy link

google-cla bot commented Apr 18, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mschoenb97 mschoenb97 changed the title Rewrite of quantized_bits Introducing of quantized_linear Apr 24, 2023
@mschoenb97 mschoenb97 changed the title Introducing of quantized_linear Introducing quantized_linear Apr 24, 2023
Copy link
Contributor

@danielemoro danielemoro left a comment

Choose a reason for hiding this comment

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

This is a very impactful and important contribution to QKeras.

@vloncar
Copy link
Contributor

vloncar commented May 1, 2023

Since this deprecates quantized_bits it would be useful to also note this in the main readme and update the jupyter examples. And since it is very impactful and important please consider tagging a release after merging so that packages dependent on qkeras have a new target from which they can expect this quantizer to exist. 🙏


def test_GetScale_PerChannelScale():
# Rank1 tensors
x_r1 = tf.ones([4])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since quantized_linear is trying to incorporate binary quantizer as well, I suggest add more scale test here for per channel scales.

  1. instead of having input all as 1, consider use wider range of input values so we can test better how scale is calculated;
  2. Add test on quantizer scale during training and eval; to make sure scales don't change between two stages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a test for quantized_linear. I only made a change here because I changed the name of the _get_scale function.

However, these are still good points, and I will add tests with specific scale values to the rest of the quantized_linear tests in theqactivations_test.py file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added both (1) and (2)!

scale_r4_eps_2_ua_3 = quantizers._get_least_squares_scale(
"auto", x_r4, q_r4, elements_per_scale=2, scale_axis=3)

assert_equal(tf.shape(scale_r4_eps_none_ua_none).numpy(), [1, 1, 1, 16])
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider add assertion on some specific scale values as well. The same goes for other related tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See discussion above

@danielemoro danielemoro merged commit 5c058cf into google:master Aug 24, 2023
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.

4 participants