-
Notifications
You must be signed in to change notification settings - Fork 94
[Quantizer] Unsigned Integer Tensor Support #2948
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
[Quantizer] Unsigned Integer Tensor Support #2948
Conversation
997d0b8 to
df61234
Compare
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.
Nice work. LGTM!
nntrainer/tensor/quantizer.cpp
Outdated
| val = clip(std::lround(input.getValue(b, c, h, w) / *scales), | ||
| quant_min, quant_max); | ||
|
|
||
| if (output.getDataType() == Tdatatype::UINT8 || | ||
| output.getDataType() == Tdatatype::UINT16) { | ||
| val += *zero_points; | ||
| } | ||
|
|
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.
Is it okay to add zero_point value after clipping?
I find the clip should be applied after adding the zero_point to ensure its range.
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.
Thank you for the review. min max values are the same as signed integers.
nntrainer/nntrainer/tensor/quantizer.cpp
Lines 43 to 44 in 41fd25b
| quant_max = std::pow(2, N - 1) - 1; | |
| quant_min = -std::pow(2, N - 1); |
Therefore, applying zero points after the clipping would produce the correct result.
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.
I modified it to add a zero point before clipping as we discussed offline. PTAL
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.
Thank you for the update! It looks more clear and safe! 👍
df61234 to
0c23b7c
Compare
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.
LGTM!
|
@djeong20 Could you rebase? |
0c23b7c to
71957c7
Compare
This pull request enhances the quantizer class by allowing it to perform quantization on tensors with an unsigned integer data type. It includes consideration of the zero-point during the quantization process. **Changes proposed in this PR:** - The quantizer can now quantize and dequantize unsigned integer data types. - Test cases have been added to verify quantization on unsigned integers. - Functions for copying unsigned integer data to floating-point format have also been included. **Self-evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Donghyeon Jeong <[email protected]>
71957c7 to
c4e7ad5
Compare
This pull request enhances the quantizer class by allowing it to perform quantization on tensors with an unsigned integer data type. It includes consideration of the zero-point during the quantization process.
Changes proposed in this PR:
Self-evaluation: