Commit Graph

14 Commits

Author SHA1 Message Date
Jerry Zhang
7ddf212f33 [quant][fx] Fully align convert with the reference model design and simplify the implementation (#73863)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73863

This PR fully aligns the convert function with the design: https://github.com/pytorch/rfcs/blob/master/RFC-0019-Extending-PyTorch-Quantization-to-Custom-Backends.md
and simplifies the implementation of convert function by always produce a reference quantized model (with reference patterns) first,
and then lower the model to a quantized model that is runnable with PyTorch native backend (fbgemm/qnnpack).

This PR makes the convert.py much easier to understand than the previous implementation, and we are able to remove majority of code
in quantization_patterns.py as well (in followup PRs).

Test Plan:
```
python test/test_quantization.py TestQuantizeFx
python test/test_quantization.py TestQuantizeFxOps
python test/test_quantization.py TestFXNumericSuiteCoreAPIs
python test/test_quantization.py TestFXNumericSuiteCoreAPIsModels
```
and other internal/oss regression tests

Imported from OSS

Reviewed By: andrewor14

Differential Revision: D34778506

fbshipit-source-id: 0678b66addf736039a8749b352f6f569caca962b
(cherry picked from commit 33ec9caf23f3ab373d827117efbd9db0668b2437)
2022-03-11 17:11:30 +00:00
Vasiliy Kuznetsov
727debb18e dbr quant: enable reference module support for torch.qint32 (#73493)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73493

This PR enables basic support for reference modules in DBR quant.
For now, the support is limited to:
1. modules that have reference versions defined only (no functions)
2. torch.qint32 dtype only

Currently, the reference module logic is enabled whenever dtype is
torch.qint32. This is done because this is needed the earliest for
the first use case. A future PR will support more dtypes and also
add the `is_reference` flag to the API.

Test Plan:
```
python test/test_quantization.py TestQuantizeDBR.test_conv_int32_reference_model
```

Reviewed By: jerryzh168

Differential Revision: D34520759

Pulled By: vkuzo

fbshipit-source-id: 363db715315c5c7c20962a1818330ce288948778
(cherry picked from commit 6ccdfe2889c252211f191edc49f4147f66e803a4)
2022-03-04 17:35:31 +00:00
Jerry Zhang
5613527ef9 [quant][fx] Add lowering support for functional ops using DefaultNodeQuantizeHandler (#73120)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73120

att
This is to align our implementation with https://github.com/pytorch/rfcs/blob/master/RFC-0019-Extending-PyTorch-Quantization-to-Custom-Backends.md

Test Plan:
python test/test_quantization.py TestQuantizeFx
python test/test_quantization.py TestQuantizeFxOps

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D34354038

fbshipit-source-id: 873a867e62bd541ef236974c697fac2334bf02ea
(cherry picked from commit 3fce7cade2f057b985833659c2cb365ee4d6d9f3)
2022-02-26 19:29:58 +00:00
Jerry Zhang
ee5b8f0c64 [quant][fx] Move MatchAllNode from match_utils.py to utils.py under quantization (#73344)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73344

not user facing as of now, since we haven't advertised the backend_config_dict api,
we need this in fuser_method_mapping.py, this is to avoid circular dependency

Test Plan:
python test/test_quantization.py TestQuantizeFx

Imported from OSS

Reviewed By: VitalyFedyunin

Differential Revision: D34441778

fbshipit-source-id: 7a01c359e4b21e9e98345dc7781f735628209a20
(cherry picked from commit 758537094c5a98a17a8825b3f240c8d5acdd72b0)
2022-02-25 17:36:14 +00:00
Terry Chen
f67cf03526 [Quant] Add qint32 quantization support (#72472)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72472

Add dtype=int32 support for observer

Test Plan:
python3 test/test_quantization.py TestObserver.test_per_tensor_observers

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D34056640

fbshipit-source-id: 4fa15a7274cfbb6a7dd4e698e3989cc0c0626e7b
(cherry picked from commit bf4351de45)
2022-02-16 03:45:15 +00:00
Jerry Zhang
8b67b83c6e [quant][fx][improvement] Add lowering support for FixedQParamsOpQuantizeHandler (#72488)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72488

This is an effort to move the current implementation towards the reference quantized model design:
https://github.com/pytorch/rfcs/blob/master/RFC-0019-Extending-PyTorch-Quantization-to-Custom-Backends.md
so that we use reference model in the default fbgemm/qnnpack path

Test Plan:
python test/test_quantization.py TestQuantizeFx
python test/test_quantization.py TestQuantizeFxOps

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D34062364

fbshipit-source-id: 50c4a86644c3f5f6fb03d2a98aa7376895c0fc84
(cherry picked from commit ed8122e44d)
2022-02-11 18:13:29 +00:00
Jerry Zhang
ac0cac7724 [quant][fx][devs] Add lowering support for torch.cat (#72487)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72487

This is an effort to move the current implementation towards the reference quantized model design:
https://github.com/pytorch/rfcs/blob/master/RFC-0019-Extending-PyTorch-Quantization-to-Custom-Backends.md
so that we use reference model in the default fbgemm/qnnpack path

Test Plan:
python test/test_quantization.py TestQuantizeFx
python test/test_quantization.py TestQuantizeFxOps

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D34062366

fbshipit-source-id: 86673bead79180a7509b51bd577f328e90f24893
(cherry picked from commit de3e443384)
2022-02-09 06:09:57 +00:00
Jerry Zhang
4b69a2373f [quant][fx] Add lowering support for ops in GeneralTensorShapeOpQuantizeHandler (#72387)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72387

Also make GeneralTensorShapeOpQuantizeHandler produce reference patterns by default

Test Plan:
python test/test_quantization.py TestQuantizeFx
python test/test_quantization.py TestQuantizeFxOps

Imported from OSS

Reviewed By: albanD, terrychenism

Differential Revision: D34025005

fbshipit-source-id: 01ca62cce727bbf4579ba8fb2b8c40198f327b86
(cherry picked from commit 7f3a9ab4c5)
2022-02-09 02:10:20 +00:00
Terry Chen
e4500306c8 [Quant] Enable default reference path for CopyNodeQuantizeHandler (#71168)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71168

In this PR we want to enable the reference path by default for CopyNodeQuantizeHandler

Test Plan:
python test/test_quantization.py TestQuantizeFx
python test/test_quantization.py TestQuantizeFxOps

Imported from OSS

Reviewed By: andrewor14

Differential Revision: D33715995

fbshipit-source-id: eda44892fcea3a1cba54ac75bc020f73e1becc8c
(cherry picked from commit a2cf63f68d)
2022-01-25 23:32:11 +00:00
Vasiliy Kuznetsov
c21a540866 dbr quant: support dynamic linear (#70257)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70257

Makes dynamic quantization for linear module work in DBR quant.

Coverage for more ops and functionals will be in future PRs.

Test Plan:
```
python test/test_quantization.py -k DBR
```

Reviewed By: jerryzh168

Differential Revision: D33262300

Pulled By: vkuzo

fbshipit-source-id: c1cb0f9dd3f42216ad6ba19f4222b171ff170174
2022-01-06 13:24:55 -08:00
Vasiliy Kuznetsov
b999f87503 fx quant: move _parent_name to common utils (#69720)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69720

This function is also useful for DBR quant, moving it from FX utils
to common utils.

Test Plan:
```
python test/test_quantization.py TestQuantizeFx
python test/test_quantization.py TestQuantizeDBR
```

Reviewed By: jerryzh168

Differential Revision: D33003473

Pulled By: vkuzo

fbshipit-source-id: 20360682c69d614a645c14fc29d3ee023d6b2623
2021-12-17 05:59:46 -08:00
Jerry Zhang
e5a1ee0e5a [quant][graphmode] Refactor fusion to use the new Pattern format (#68770)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68770

Previous fusion only works for a sequnce of ops, which is not general enough for fusion patterns
that is defined by a subgraph, this PR refactors that to make it more general

Test Plan:
```
python test/test_quantization.py TestFuseFx
```

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D32602637

fbshipit-source-id: a7897c62081b9d71c67fb56e78484cf68deaacf6
2021-12-07 16:12:40 -08:00
Jerry Zhang
9cb52327a8 [quant][refactor] Move pattern type definition to ao/quantization/utils.py (#68769)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68769

att, since we want to use this type in fuser_method_mapping in later PRs

Test Plan:
no change to logic, just regression test on ci
```
python test/test_quantization.py
```

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D32602636

fbshipit-source-id: 15b95241431dfca9b1088d0920bf75705b37aa9a
2021-12-07 11:00:22 -08:00
Zafar Takhirov
02dec91212 [quant] AO migration of the torch/quantization/utils.py (phase 1) (#64919)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/64919

AO Team is migrating the existing torch.quantization into torch.ao.quantization. We are doing it one file at a time to make sure that the internal callsites are updated properly. This migrates the quantization utilities.
ghstack-source-id: 138303325

Test Plan: `buck test mode/dev //caffe2/test:quantization`

Reviewed By: jerryzh168

Differential Revision: D30899082

fbshipit-source-id: 85eb38c419e417147e71758b682cd095308dd0c9
2021-09-16 21:30:18 -07:00