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

[Quant] Add quantization 2.0 document #2354

Merged
merged 53 commits into from
Jun 9, 2023

Conversation

leslie-fang-intel
Copy link
Contributor

@leslie-fang-intel leslie-fang-intel commented May 30, 2023

Fixes #issue_2336

Description

Add the new document for Quantization 2.0 flow.

Checklist

  • The issue that is being fixed is referred in the description (see above "Fixes #ISSUE_NUMBER")
  • Only one issue is addressed in this pull request
  • Labels from the issue that this PR is fixing are added to this pull request
  • No unnessessary issues are included into this pull request.

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @ZailiWang @ZhaoqiongZ @Xia-Weiwen @sekahler2 @CaoE @zhuhaozhe @Valentine233

@leslie-fang-intel leslie-fang-intel changed the title Add quantization 2.0 document [Quant] Add quantization 2.0 document May 30, 2023
@leslie-fang-intel leslie-fang-intel marked this pull request as draft May 30, 2023 02:33
@leslie-fang-intel
Copy link
Contributor Author

@jgong5 @mingfeima @Xia-Weiwen Here is the draft of documents for Quantization 2.0.

@netlify
Copy link

netlify bot commented May 30, 2023

Deploy Preview for pytorch-tutorials-preview ready!

Name Link
🔨 Latest commit 397eaa9
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-tutorials-preview/deploys/64838aa111bee10008372c33
😎 Deploy Preview https://deploy-preview-2354--pytorch-tutorials-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
@svekars svekars added the intel label May 30, 2023
@svekars
Copy link
Contributor

svekars commented May 30, 2023

Please make sure to add a customcarditem to https://github.com/pytorch/tutorials/blob/main/prototype_source/prototype_index.rst

@leslie-fang-intel
Copy link
Contributor Author

leslie-fang-intel commented May 31, 2023

Please make sure to add a customcarditem to https://github.com/pytorch/tutorials/blob/main/prototype_source/prototype_index.rst

@svekars Thanks for the suggestion. customcarditem has been added. But I keep seeing some preCI failures, the error message is ERROR: botocore 1.12.25 has requirement urllib3<1.24,>=1.20, but you'll have urllib3 2.0.2 which is incompatible. and Error response from daemon: manifest for 308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/pytorch-linux-bionic-cuda12.1-cudnn8-py3-gcc7:2449172a5f2d2b623e0baab605db55c4105e35f5 not found: manifest unknown: Requested image not found Do you have any suggestions?

@leslie-fang-intel leslie-fang-intel marked this pull request as ready for review May 31, 2023 04:16
@svekars svekars added the docathon-h1-2023 A label for the docathon in H1 2023 label May 31, 2023
@svekars
Copy link
Contributor

svekars commented May 31, 2023

We fixed the issue and I re-kicked the build.

Copy link
Contributor

@svekars svekars left a comment

Choose a reason for hiding this comment

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

A few editorial suggestions.

prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
prototype_source/quantization_2_0_tutotial.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@svekars svekars left a comment

Choose a reason for hiding this comment

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

A few editorial suggestions.

@leslie-fang-intel
Copy link
Contributor Author

Hi @jerryzh168, the comments has been addressed. Please help to take a look again. Thanks.

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@jerryzh168
Copy link
Contributor

@kimishpatel please take a look again as well

Copy link

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

I left several comments. I feel overall this is not painting the picture of why we are doing new API and thus the motivaiton. HOwever, since I am reviewing this too late, I dont want to block this on my behalf.

@leslie-fang-intel
Copy link
Contributor Author

Hi @jerryzh168 @kimishpatel, thanks for the suggestions. The comments has been addressed. Please help to take a look again.

@leslie-fang-intel leslie-fang-intel force-pushed the leslie/add_quantization_2_doc branch 2 times, most recently from f9ee24b to 5a43584 Compare June 9, 2023 02:01
Comment on lines 43 to 45
- Currently, in ``QConfig`` we are exposing observer/fake_quant classes as an object for user to configure quantization.
This increases the things that user needs to care about, e.g. not only the ``dtype`` but also how the observation should
happen. These could potentially be hidden from user to make user interface simpler.
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit confused by this, I think the new API also has the observer setting in the QuantizationSpec. So it is also part of the new API, right?

Copy link
Contributor Author

@leslie-fang-intel leslie-fang-intel Jun 9, 2023

Choose a reason for hiding this comment

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

Thanks for the comment. In creation of QuantizationSpec, we do still need to specify the class of observer. But I think it's simpler for users to use comparing with FX Quantization Mode.

  • In FX Quantization Mode, QConfig is created with observer. User needs to learn the constructor and specify the quantization parameters for different observers in order to create a QConfig for his use case.
  • Now the general quantization parameters such as dtype, qscheme for different observers are decoupled from observer to the QuantizationSpec at user interface. Although user still need to specify observer type, It decreases what's user need to know for different observers.

@jerryzh168 I think you may help to comment more about this bullet.

Copy link
Contributor

@jerryzh168 jerryzh168 Jun 9, 2023

Choose a reason for hiding this comment

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

so in the new quantizer API, the idea is that configurability is controlled by each backend, the quantizer/annotation API is not facing common modeling user directly, it is an API for backend developers or advanced modeling users only. for common users, they will be interacting with each backend specific quantizer only, e.g. I can have a quantizer that only exposes "quantize/not quantize" option to users:

backend_quantizer = BackendQuantizer()
# BackendQuantizer is interacting with QuantizationSpec, not modeling users,
# modeling user is interacting configurations exposed by the BackendQuantizer only
backend_quantizer.enable_quantization()
model = prepare_pt2e(model, backend_quantizer)
...

see the graph in the end of motivation section: https://docs.google.com/document/d/1_jjXrdaPbkmy7Fzmo35-r1GnNKL7anYoAnqozjyY-XI/edit#heading=h.jtqauapwj95c for details

Copy link
Contributor

@jgong5 jgong5 left a comment

Choose a reason for hiding this comment

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

LGTM.

way by annotating the appropriate nodes. A backend specific quantizer inherited from base quantizer,
some methods that need to be implemented:

- `annotate method <https://github.com/pytorch/pytorch/blob/3e988316b5976df560c51c998303f56a234a6a1f/torch/ao/quantization/_pt2e/quantizer/qnnpack_quantizer.py#L269>`__
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the only method that needs to be implemented (above description says some methods)? Why create a separate bullet point for it in that case?

Copy link
Contributor Author

@leslie-fang-intel leslie-fang-intel Jun 9, 2023

Choose a reason for hiding this comment

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

Actually there are some other methods needs to be implemented. However, the detail design for the other methods are not fully set per the discussion with @jerryzh168. So we only mention annotate method here which is also the most important method. Sure, I will merge this bullet into previous paragraph for now.

@svekars svekars merged commit 0ef9a65 into pytorch:main Jun 9, 2023
14 checks passed
@leslie-fang-intel
Copy link
Contributor Author

@supriyar Thanks for the comments. I made another PR #2456 to following up your comments. Please help to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
advanced cla signed docathon-h1-2023 A label for the docathon in H1 2023 intel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💡 [REQUEST] - Write a Tutorial for PyTorch 2.0 Export Quantization Frontend (Quantizer and Annotation API)
7 participants