Skip to content

Commit 0da90a6

Browse files
jerryzh168Svetlana Karslioglu
and
Svetlana Karslioglu
authored
[quant][pt2e][tutorials] Some fixes to pt2e quant docs (#2513)
* [quant][pt2e][tutorials] Some fixes to pt2e quant docs --------- Co-authored-by: Svetlana Karslioglu <svekars@fb.com>
1 parent 1801fc3 commit 0da90a6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

prototype_source/pt2e_quant_ptq_static.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,13 @@ For post training quantization, we'll need to set model to the eval mode.
302302
``Quantizer`` is backend specific, and each ``Quantizer`` will provide their own way to allow users to configure their model. Just as an example, here is the different configuration APIs supported by XNNPackQuantizer:
303303

304304
.. code:: python
305+
305306
quantizer.set_global(qconfig_opt) # qconfig_opt is an optional qconfig, either a valid qconfig or None
306307
.set_object_type(torch.nn.Conv2d, qconfig_opt) # can be a module type
307308
.set_object_type(torch.nn.functional.linear, qconfig_opt) # or torch functional op
308309
.set_module_name("foo.bar", qconfig_opt)
309310
310-
We have another `tutorial <https://pytorch.org/tutorials/prototype/quantization_in_pytorch_2_0_export_tutorial.html>`_ that talks about how to write a new ``Quantizer``.
311+
We have another `tutorial <https://pytorch.org/tutorials/prototype/pt2e_quantizer.html>`_ that talks about how to write a new ``Quantizer``.
311312

312313
6. Prepare the Model for Post Training Static Quantization
313314
----------------------------------------------------------
@@ -396,6 +397,7 @@ quantization you are using to learn more about how you can have more control ove
396397
We'll show how to save and load the quantized model.
397398

398399
.. code:: python
400+
399401
# 1. Save state_dict
400402
pt2e_quantized_model_file_path = saved_model_dir + "resnet18_pt2e_quantized.pth"
401403
torch.save(quantized_model.state_dict(), pt2e_quantized_model_file_path)
@@ -434,6 +436,7 @@ We'll show how to save and load the quantized model.
434436
435437
11. Debugging Quantized Model
436438
----------------------------
439+
437440
We have `Numeric Suite <https://pytorch.org/docs/stable/quantization-accuracy-debugging.html#numerical-debugging-tooling-prototype>`_ that can help with debugging in eager mode and FX graph mode. The new version of Numeric Suite working with PyTorch 2.0 Export models is still in development.
438441

439442
12. Lowering and Performance Evaluation

prototype_source/pt2e_quantizer.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ Prerequisites:
1010

1111
Required:
1212
- `Torchdynamo concepts in PyTorch <https://pytorch.org/docs/stable/dynamo/index.html>`__
13+
1314
- `Quantization concepts in PyTorch <https://pytorch.org/docs/master/quantization.html#quantization-api-summary>`__
15+
1416
- `(prototype) PyTorch 2.0 Export Post Training Static Quantization <https://pytorch.org/tutorials/prototype/pt2e_quant_ptq_static.html>`__
1517

1618
Optional:
1719
- `FX Graph Mode post training static quantization <https://pytorch.org/tutorials/prototype/fx_graph_mode_ptq_static.html>`__
20+
1821
- `BackendConfig in PyTorch Quantization FX Graph Mode <https://pytorch.org/tutorials/prototype/backend_config_tutorial.html?highlight=backend>`__
22+
1923
- `QConfig and QConfigMapping in PyTorch Quantization FX Graph Mode <https://pytorch.org/tutorials/prototype/backend_config_tutorial.html#set-up-qconfigmapping-that-satisfies-the-backend-constraints>`__
2024

2125
Introduction
@@ -25,12 +29,12 @@ Introduction
2529
(1). What is supported quantized operator or patterns in the backend
2630
(2). How can users express the way they want their floating point model to be quantized, for example, quantized the whole model to be int8 symmetric quantization, or quantize only linear layers etc.
2731

28-
Please see `here <https://pytorch.org/tutorials/prototype/pt2e_quant_ptq_static.html>`__ For motivations for ``Quantizer``.
32+
Please see `here <https://pytorch.org/tutorials/prototype/pt2e_quant_ptq_static.html#motivation-of-pytorch-2-0-export-quantization>`__ For motivations for the new API and ``Quantizer``.
2933

3034
An existing quantizer object defined for ``XNNPACK`` is in
3135
`QNNPackQuantizer <https://github.com/pytorch/pytorch/blob/main/torch/ao/quantization/pt2e/quantizer/xnnpack_quantizer.py>`__
3236

33-
Annotation API:
37+
Annotation API
3438
^^^^^^^^^^^^^^^^^^^
3539

3640
``Quantizer`` uses annotation API to convey quantization intent for different operators/patterns.
@@ -269,4 +273,4 @@ Conclusion
269273
With this tutorial, we introduce the new quantization path in PyTorch 2.0. Users can learn about
270274
how to define a ``BackendQuantizer`` with the ``QuantizationAnnotation API`` and integrate it into the quantization 2.0 flow.
271275
Examples of ``QuantizationSpec``, ``SharedQuantizationSpec``, ``FixedQParamsQuantizationSpec``, and ``DerivedQuantizationSpec``
272-
are given for specific annotation use case. This is a prerequisite to be able to quantize a model in PyTorch 2.0 Export Quantization flow. Please follow `this tutorial <https://pytorch.org/tutorials/prototype/pt2e_quant_ptq_static.html>`_ to actually quantize a model.
276+
are given for specific annotation use case. This is a prerequisite to be able to quantize a model in PyTorch 2.0 Export Quantization flow. You can use `XNNPACKQuantizer <https://github.com/pytorch/pytorch/blob/main/torch/ao/quantization/quantizer/xnnpack_quantizer.py>`_ as an example to start implementing your own ``Quantizer``. After that please follow `this tutorial <https://pytorch.org/tutorials/prototype/pt2e_quant_ptq_static.html>`_ to actually quantize your model.

0 commit comments

Comments
 (0)