Skip to content

Conversation

@djeong20
Copy link
Contributor

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

@EunjuYang EunjuYang changed the title [Wait for #2940][Quantizer] Unsigned Integer Tensor Support [Wait for #2940][Quantizer] Unsigned Integer Tensor Support @open sesame 02/14 15:25 Feb 14, 2025
@djeong20 djeong20 force-pushed the quantizer/uint/per_tensor branch from 997d0b8 to df61234 Compare February 21, 2025 04:48
@djeong20 djeong20 changed the title [Wait for #2940][Quantizer] Unsigned Integer Tensor Support @open sesame 02/14 15:25 [Quantizer] Unsigned Integer Tensor Support Feb 21, 2025
Copy link
Contributor

@baek2sm baek2sm left a comment

Choose a reason for hiding this comment

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

Nice work. LGTM!

Comment on lines 124 to 135
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;
}

Copy link
Contributor

@EunjuYang EunjuYang Mar 4, 2025

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.

Copy link
Contributor Author

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.

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.

Copy link
Contributor Author

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

Copy link
Contributor

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! 👍

@djeong20 djeong20 force-pushed the quantizer/uint/per_tensor branch from df61234 to 0c23b7c Compare March 5, 2025 02:27
Copy link
Member

@DonghakPark DonghakPark left a comment

Choose a reason for hiding this comment

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

LGTM!

@dkjung
Copy link
Collaborator

dkjung commented Mar 7, 2025

@djeong20 Could you rebase?

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]>
@djeong20 djeong20 force-pushed the quantizer/uint/per_tensor branch from 71957c7 to c4e7ad5 Compare March 10, 2025 00:55
@jijoongmoon jijoongmoon merged commit cd0a74d into nnstreamer:main Mar 11, 2025
16 checks passed
@djeong20 djeong20 deleted the quantizer/uint/per_tensor branch March 28, 2025 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants