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

Redefine symmetry as offset=-round((qmin + qmax) / 2) #3718

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

quic-kyunggeu
Copy link
Contributor

Problem Statement

Given an unsigned asymmetric quantizer, setting quantizer.symmetric = True only turns it into an unsigned symmetric quantizer.
This is problematic for three reasons

  • Blindly setting symmetric=True often results in catastrophic accuracy drop
  • It's a bit counter-intuitive that int8 qdq and uint8 qdq produces radically different outputs
  • It's vastly different from v1 behavior where the users could set symmetric=True without thinking about int8 vs. uint8

Proposal

I propose redefining symmetry as below:
offset = -round((qmin+qmax) / 2)

In a sense, this is a generalized version of the current definition of symmetry (offset = 0) because, with the new definition, floating point 0.0 will always line up with the midpoint of the integer grid -- 0 if int8, 128 if uint8.

This new definition has the following pros and cons

Pros:

  • Setting quantizer.symmetric = True/False doesn't affect the qdq simulation accuracy.
  • For most users who NEVER use unsigned symmetric, this is the most transparent solution (requires no user code change) to prevent catastrophic accuracy drop

Cons:

  • The meaning of quantizer.signed and quantizer.symmetric slightly diverges from our day-to-day usage of "signed" and "symmetric".
    Particularly, quantizer.signed = False and quantizer.symmetric = True doesn't mean what we've been conventionally referring to as "unsigned symmetry".

@quic-kyunggeu quic-kyunggeu merged commit 314cbb4 into quic:develop Jan 8, 2025
4 checks passed
@quic-kyunggeu quic-kyunggeu deleted the redefine_symmetry branch January 8, 2025 03:34
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