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

Add squeeze / unsqueeze operations to quant invariant functions in torch_handler.py #891

Open
nickfraser opened this issue Mar 1, 2024 · 4 comments
Assignees
Labels
feature New features good first issue Good for newcomers

Comments

@nickfraser
Copy link
Collaborator

No description provided.

@nickfraser nickfraser self-assigned this Mar 1, 2024
@nickfraser nickfraser added feature New features good first issue Good for newcomers labels Mar 1, 2024
@sanjay-rb
Copy link

Hi @nickfraser ,

You wanted to add squeeze / unsqueeze operations in quant_invariant_handler function right ?

@Giuseppe5
Copy link
Collaborator

Giuseppe5 commented Mar 2, 2024

When dealing with squeeze/unsqueeze, we also have to handle the shapes of scale factors and zero points.

Related to #728

@ScXfjiang
Copy link

ScXfjiang commented Apr 20, 2024

For per-channel quantization

Squeeze/Unsqueeze OP is more like Permute OP, where we can find easy ways to modify the QuantTensor to keep those OPs affine quantization invariant. In the case of Squeeze/Unsqueeze OP, all we need to do is squeeze/unsqueeze the scale and zero point tensor accordingly.

However, OPs mentioned in #728 (reshape, flatten) are non-trivial. There are no trivial ways to modify the QuantTensor to keep those OPs affine quantization invariant. Recalculation of scale and zero point is inevitable. We may need to dequantize --> reshape/flatten --> requantize to bypass this problem, at the price of precision loss.

It looks like PyTorch doesn't solve this problem either. They don’t offer a quantized version of the flatten(); instead, they simply use torch.flatten(). QUANTIZATION API REFERENCE

@ScXfjiang
Copy link

Hi @nickfraser @Giuseppe5,

A PR has been submitted to solve this issue. Your comments are highly appreciated, many thanks.

#941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New features good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants