Commit Graph

41 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
Andrew Or
f3c6e8f720 [Quant][fx] Add lowering for functional conv (#73708)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73708

This adds functionality to lower reference models
involving functional conv in FX.

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

Imported from OSS

Reviewed By: mruberry

Differential Revision: D34648870

fbshipit-source-id: d1c8afdb9787c36639d5ee5762ae71e7e8ab3769
(cherry picked from commit 7a28617faf4b8aad152076239927e94ed3f0169e)
2022-03-07 15:32:54 +00:00
Andrew Or
cedce3be20 [Quant][fx] Add lowering for Linear-Bn1d in QAT mode (#73509)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73509

This adds functionality to lower reference models
involving the Linear-Bn1d pattern in FX QAT mode. This follows
https://github.com/pytorch/pytorch/pull/72431 and https://github.com/pytorch/pytorch/pull/72796, which add Linear-Bn1d fusion functionality
to eager QAT mode.

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

Imported from OSS

Reviewed By: dagitses

Differential Revision: D34591251

fbshipit-source-id: 39144485f9954ee1830c8b414e724560fd7e47bf
(cherry picked from commit b97a39b4d9df00e045fab4c01eca88e562ca2c02)
2022-03-07 15:32:54 +00:00
Jerry Zhang
f5c7e5406b [quant][fx] Add lowering support for qat and fused convs (#73527)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73527

This includes:
```
torch.nn.qat.Conv2d,
torch.nn.qat.Conv3d,
torch.nn.intrinsic.qat.ConvBn1d,
torch.nn.intrinsic.qat.ConvBn2d,
torch.nn.intrinsic.qat.ConvBn3d,
torch.nn.intrinsic.qat.ConvBnReLU1d,
torch.nn.intrinsic.qat.ConvBnReLU2d,
torch.nn.intrinsic.qat.ConvBnReLU3d,
torch.nn.intrinsic.qat.ConvReLU2d,
torch.nn.intrinsic.qat.ConvReLU3d
torch.nn.intrinsic.ConvReLU1d,
torch.nn.intrinsic.ConvReLU2d,
torch.nn.intrinsic.ConvReLU3d,
```
We first produce the reference pattern and then lower the reference pattern to quantized modules

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

Imported from OSS

Reviewed By: andrewor14

Differential Revision: D34583206

fbshipit-source-id: d298114d1906ea44c071b0eee52730dadf67fd3e
(cherry picked from commit 6498af35b5aa6104cadb68ca48dff4e443bee7d6)
2022-03-04 06:29:03 +00:00
Andrew Or
b7a7cdd00a [Quant][fx] Add lowering for functional linear (#72855)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72855

This adds functionality to lower reference models
involving functional linear in FX.

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

Imported from OSS

Reviewed By: albanD

Differential Revision: D34514127

fbshipit-source-id: 7af4f37bdeda710dc7197ede9d46f66227d7932c
(cherry picked from commit a14cbc04dea4e578643c4183f0c8ea43fbdaf5c7)
2022-03-02 18:34:35 +00:00
Jerry Zhang
81437e66c1 [quant][fx] Add RNN reference module (#73386)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73386

This PR adds support for RNN reference module, following https://github.com/pytorch/rfcs/blob/master/RFC-0019-Extending-PyTorch-Quantization-to-Custom-Backends.md
This includes: RNNCell, LSTMCell, GRUCell, LSTM

Test Plan:
will be tested in the lowering flow in a separate PR

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D34469445

fbshipit-source-id: 71a13d7d056f7aaccdd98fb477c8a3a38aecc249
(cherry picked from commit 0b10f0d127515556b677eae3150f026ac8cd9acd)
2022-03-02 10:30:37 +00:00
Jerry Zhang
ad1078a21e [quant] Enable reference path by default for CopyNodeQuantizeHandler (#73233)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73233

This PR makes CopyNodeQuantizeHandler to always produce reference patterns, and we have
some custom lowering pass to rewrite the reference qunatized patterns to quantized ops

Lowering passes have been implemented previously, we just need to enable the reference path here,
and cleanup the previous code to allow list some of the ops (`check_node`)

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

Imported from OSS

Reviewed By: mrshenli

Differential Revision: D34469446

fbshipit-source-id: b9d9c5f793fbb735839199056c197ae98969cc4b
(cherry picked from commit af0cf4e79e11e7343d57e6ff7766c80e72ec60f3)
2022-03-01 01:33:30 +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
9db0e0e76e [quant][graphmode] produce reference pattern for binary ops and then rewrite to quantized op (#72953)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72953

This PR makes BinaryOpQuantizeHandler to always produce reference patterns, and we have
some custom lowering pass to rewrite the reference qunatized patterns to quantized ops
it includes rewrite for
torch.ops.quantized.add, torch.ops.quantized.mul, torch.ops.quantized.matmul

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

Imported from OSS

Reviewed By: gchanan

Differential Revision: D34292408

fbshipit-source-id: 9872a5098249bc77db15e9fb614416958e62b9b2
(cherry picked from commit dbdc61ee8b5dde2e54a34a370a3af887e5117398)
2022-02-25 17:36:14 +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
Vasiliy Kuznetsov
decc79e541 fx quant: add workflow support for torch.matmul quantization (#72444)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72444

In https://github.com/pytorch/pytorch/pull/71783 support was added for
quantized matmul.

In this PR, the FX graph mode quantization workflow support for this
operator is added, for int8 dtypes.

Test Plan:
```
python test/test_quantization.py TestQuantizeFxOps.test_qmatmul
```

Imported from OSS

Reviewed By: andrewor14

Differential Revision: D34047310

fbshipit-source-id: 781219047419ce621a4deb46ea04881818bf4209
(cherry picked from commit 7e039fa3a1)
2022-02-09 18:43:58 +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
Vasiliy Kuznetsov
d672bbd0a9 fx quant: add fusion matching for operator.add and torch.relu (#71780)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71780

Adds support for matching operator.add -> torch.relu in FX graph
mode quantization.

It would be nice to support torch.relu better in general, but
saving that for a future PR to keep PRs small.

This is useful for DBR quant because we have some test cases in DBR
quant which use add-relu, and we'd like to match them to FX.

Test Plan:
```
python test/test_quantization.py TestQuantizeFxOps.test_add_relu
python test/test_quantization.py TestQuantizeFxOps.test_mul_relu
```

Reviewed By: jerryzh168

Differential Revision: D33775096

Pulled By: vkuzo

fbshipit-source-id: 889d9b41d3758ecbbb6d7eab67f64ce3d4892d24
(cherry picked from commit c1f9f38ca1)
2022-02-07 14:00:26 +00:00
Jerry Zhang
f5c7f81548 [quant][fx][devs] Delete unused code (#72244)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72244

att

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

Imported from OSS

Reviewed By: albanD

Differential Revision: D33971544

fbshipit-source-id: a6e01d08ae9fdd479bba8abfa0941c555650f84e
(cherry picked from commit fe756cc67a)
2022-02-04 21:34:34 +00:00
Andrew Or
e118d6e59f Add lowering path for LinearReLU module (#71427)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71427

This commit adds a lowering path for the LinearReLU modules
in static quantization mode. This includes torch.nn.qat.Linear,
torch.nn.intrinsic.LinearReLU, and torch.nn.intrinsic.qat.LinearReLU.
Future commits will add support for dynamic quantization and functional
LinearReLU.

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

Imported from OSS

Reviewed By: george-qi

Differential Revision: D33694742

fbshipit-source-id: 19af11f82b1ad8ade0c307498971c29a3f776036
(cherry picked from commit b3f607de43)
2022-02-01 19:31:31 +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
c3570fd945 fx quant: preserve node stack trace throughout prepare and convert (#70757)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70757

This is an initial PR on a way to preserve stack traces throughout FX
graph mode quantization.  It preserves the stack traces for ops
for all of the quantize handlers. A future PR will add stack traces
for dtype transitions.

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

Note: the above only tests a single case. In a future PR, once we
expand coverage, we can expand the utility functions to check for stack
traces on all tests.

```
python test/test_quantization.py
TestQuantizeFx.test_stack_trace_preserved
```

Imported from OSS

Differential Revision:
D33432485
D33432485

Reviewed By: jerryzh168

Pulled By: vkuzo

fbshipit-source-id: 56c56850393132487430a850fa1def826a9c39c0
(cherry picked from commit c11155b31e)
2022-01-24 14:15:43 +00:00
Terry Chen
ce3215db70 Fix nnq.dropout in vision mobilenetv3 pretrain model (#71438)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71438

Fix issue https://github.com/pytorch/vision/issues/5198
skip observer for nn.dropout to load pretrain model

Test Plan:
python -c "import torchvision; torchvision.models.quantization.mobilenet_v3_large(pretrained=True, quantize=True)"

Imported from OSS

Reviewed By: HDCharles

Differential Revision: D33641707

fbshipit-source-id: 14ea26557c4ff3b942cf46bf06610db0b8f06b05
(cherry picked from commit 0b8b178d26)
2022-01-22 00:02:48 +00:00
Terry Chen
0cd474b2ce fix op not scriptable
Summary: Fix torch.sort, min/max, torch.numel after quantization not scriptable

Test Plan: python3 test/test_quantization.py TestQuantizeFxOps.test_general_shape_ops

Reviewed By: jerryzh168

Differential Revision: D33467184

Pulled By: terrychenism

fbshipit-source-id: 13775ab36d4007978df48c9af71d83398fce5161
2022-01-07 16:55:28 -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
Andrew Or
3e43c478a8 [Quant][fx] Lower reference conv[1-3]d module (#69228)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69228

Implement lowering logic for reference conv modules,
similar to https://github.com/pytorch/pytorch/pull/65723.
ghstack-source-id: 145058198

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

Imported from OSS

Reviewed By: anjali411

Differential Revision: D32890743

fbshipit-source-id: 04f2500628c60b0fbc84d22705164215e190aeba
2021-12-14 11:23:39 -08:00
Ha-nyung Chung
3d32a0c139 Back out "[wip][quant][graphmode] produce reference pattern for binary ops and then rewrite to quantized op" (#69713)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69713

Original commit changeset: 456086b308c4

Original Phabricator Diff: D32537714 (bd8a4a9372)

Reviewed By: jerryzh168

Differential Revision: D32976643

fbshipit-source-id: bea6bf6a2718e42c9efa48a0b0c1dc7fe3893065
2021-12-09 21:55:09 -08:00
Ben Koopman
f3983f9c47 [quant][embdding qat] Re-land Add FX support for QAT EmbeddingBag (#69334)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69334

Original PR #68121 broke with incompatible qengine for Mac OS, this PR re-introduces changes with fix

Add FX support for QAT EmbeddingBag operator, previously only eager mode support.

Test Plan:
pytest test/quantization/fx/test_quantize_fx.py  -v -k "test_qat_embeddingbag_linear"

Imported from OSS

Reviewed By: jingsh

Differential Revision: D32815153

fbshipit-source-id: 33654ce29de6e81920bf3277a75027fe403a1eb2
2021-12-08 05:57:20 -08:00
Ben Koopman
93aa3603ee [quant][embedding qat] Re-Land Support Embedding QAT via FX API (#69333)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69333

Original PR reverted due to break with incompatible qengine on Mac OS, this diff fixes that.

Support QAT workflow by using torch.fx QAT API.  e.g. `prepare_qat_fx` and `convert_fx`.

Test Plan:
`pytest test/quantization/fx/test_quantize_fx.py -v -k "test_qat_embedding_linear"`

Imported from OSS

Reviewed By: jingsh

Differential Revision: D32814827

fbshipit-source-id: f7a69d2b596f1276dc5860b397c5d5d07e5b9e16
2021-12-08 05:28:07 -08:00
Jerry Zhang
bd8a4a9372 [wip][quant][graphmode] produce reference pattern for binary ops and then rewrite to quantized op (#68229)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68229

This PR makes BinaryOpQuantizeHandler to always produce reference patterns, and we rely on
subgraph_rewriter to rewrite the reference qunatized patterns to quantized ops

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D32537714

fbshipit-source-id: 456086b308c4446840d8d37997daa6f8f8068479
2021-12-06 20:20:15 -08:00
Nikita Shulga
a0367f8980 Revert D32404517: [quant][embedding qat] Support Embedding QAT via FX API
Test Plan: revert-hammer

Differential Revision:
D32404517 (abda069ce2)

Original commit changeset: 0484df8c826b

fbshipit-source-id: 4e7d62b9ccdb84eb4d184cd0b3c9506013fd8336
2021-12-02 14:28:35 -08:00
Nikita Shulga
ec4c749024 Revert D32318435: [quant][embdding qat] Add FX support for QAT EmbeddingBag
Test Plan: revert-hammer

Differential Revision:
D32318435 (4484c04513)

Original commit changeset: 8b5d1a5d5422

fbshipit-source-id: e46d431f92a5c3f86c757695164d1eb5b0041298
2021-12-02 14:27:17 -08:00
Ben Koopman
4484c04513 [quant][embdding qat] Add FX support for QAT EmbeddingBag (#68121)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68121

Add FX support for QAT EmbeddingBag operator, previously only eager mode support.

Test Plan:
pytest test/quantization/fx/test_quantize_fx.py  -v -k "test_qat_embeddingbag_linear"

Imported from OSS

Reviewed By: supriyar

Differential Revision: D32318435

fbshipit-source-id: 8b5d1a5d5422972c49676f9e470d5fbe29dd503b
2021-12-02 09:05:07 -08:00
Ben Koopman
abda069ce2 [quant][embedding qat] Support Embedding QAT via FX API (#68296)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68296

Support QAT workflow by using torch.fx QAT API.  e.g. `prepare_qat_fx` and `convert_fx`.

Test Plan:
`pytest test/quantization/fx/test_quantize_fx.py -v -k "test_qat_embedding_linear"`

Imported from OSS

Reviewed By: jingsh, supriyar

Differential Revision: D32404517

fbshipit-source-id: 0484df8c826b823b60dfecd9def77bf8cffe0527
2021-12-02 08:42:45 -08:00
andrewor
79b67d9a4a [Quant] Refactor handling of FixedQParams operators (#68143)
Summary:
**Summary**: FixedQParams operators do not need fake quantization
in the prepare step. This commit introduces FixedQParamsObserver
and makes FixedQParamsFakeQuantize a simple wrapper around this
observer. It also removes the fake quantize logic in forward.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/68143

Test Plan:
Added two tests:
python3 test/test_quantization.py TestQuantizeFx.test_fixed_qparams_patterns
python3 test/test_quantization.py TestQuantizeFx.test_register_patterns

**Reviewers**: Jerry Zhang

**Subscribers**: Jerry Zhang, Supriya Rao

**Tasks**: T104942885

**Tags**: pytorch

Reviewed By: albanD

Differential Revision: D32484427

Pulled By: andrewor14

fbshipit-source-id: 5a048b90eb4da79074c5ceffa3c8153f8d8cd662
2021-11-23 15:26:10 -08:00
Jerry Zhang
0117ada47c [quant][graphmode][fx] Add input_idx_to_dtype and ouptut_idx_to_dtype to backend_config_dict (#67067)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/67067

Plan to gradually adding features to backend_config_dict, this PR adds support
for specifying the dtype for input and output of a given pattern

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D31849074

fbshipit-source-id: ca2fbb873176fe72e08ea79ed1bc659bf27cbd8a
2021-10-27 22:10:12 -07:00
Jerry Zhang
4ac8d06911 [quant] Remove unused print in quantization_patterns.py (#67191)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/67191

Test Plan:
sandcastle and ossci

Imported from OSS

Reviewed By: supriyar

Differential Revision: D31899784

fbshipit-source-id: 31ad63c0b2a5328fff80c38dc4e527e0399e802e
2021-10-25 15:07:18 -07:00
Jerry Zhang
a7bbf8814c [quant][graphmode][fx] Move quant-fx2trt unittests to test_quantize_fx.py (#67064)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/67064

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D31849075

fbshipit-source-id: 9c5e8aad7c88070830d853faf3106491726e77ff
2021-10-22 14:36:36 -07:00
Jerry Zhang
06e49ea088 [not4land][quant][fx][graphmode] lower reference linear module example (#65723)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65723

Example lowering reference linear module to fbgemm/qnnpack quantized linear module

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D31567461

fbshipit-source-id: 0b8fffaf8e742ec15cb07bf6a4672cf3e856db2d
2021-10-18 13:14:39 -07:00
Jerry Zhang
d777e490a5 [bc-breaking][quant][graphmode][fx] Produce reference patterns for GeneralShapeOps (#66647)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66647

Missed in the last round ,
This adds reference patterns for general shape ops like view when is_reference is True

bc-breaking:
basically disabled getitem from supporting quantized ops here, we may support it later in fbgemm

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

Imported from OSS

Reviewed By: H-Huang

Differential Revision: D31680379

fbshipit-source-id: 6a3a7128514baf6d92b1607308c40339469d0066
2021-10-18 11:09:17 -07:00
Teng Zhang
17e79bc76c remove is_reference from all is_output_quantized (#66456)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/66456

Test Plan: Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D31562633

Pulled By: rahxephon89

fbshipit-source-id: 85c73a23e90ba9c1406f4027d447fbbe4576e39a
2021-10-12 10:43:52 -07:00
Peter Bell
747a5782e3 [quant][fx] Don't assume bias is a keyword argument (#61647)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/61647

`prepare_fx` currently assumes that bias is always a positional argument to
convolutions, and only a keyword argument to other functions. This happens to work
today due to a quirk in how `__torch_function__` is handled for python
functions but shouldn't be considered stable.

Instead, we should support `bias` for both positional and keyword forms.

cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D31401360

Pulled By: albanD

fbshipit-source-id: 1e2f53d80e2176b870f326dc498e251e2386136e
2021-10-06 07:25:47 -07:00
Zafar
0d020effab [quant] Fix the parts that were missing after initial migration (#66058)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66058

After the initial migration from `torch.quantization` to `torch.ao.quantization`, some of the files did not change.
This happened because the migration was done in parallel, and some of the files were landed while the others were still in the original location.
This is the last fix in the AO migration phase 1, which completely enables the ao.quantization namespace.

Test Plan: `python test/test_quantization.py`

Reviewed By: vkuzo

Differential Revision: D31366066

Pulled By: z-a-f

fbshipit-source-id: bf4a74885be89d098df2d87e685795a2a64026c5
2021-10-05 11:45:37 -07:00
Jerry Zhang
b77c979102 [quant][fx][graphmode] Make FixedQParam ops work for dtypes other than quint8 (#65484)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65484

This PR makes sure we only use FixedQParamFakeQuantize for quint8 dtype and allows user
to use other dtypes for ops like sigmoid, this is useful for producing reference pattern for
these ops that can be used in other backends like TensorRT

Test Plan:
python test/test_quantization.py TestQuantizeFxOps

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D31120377

fbshipit-source-id: 3b529d588e2b6ff0377a89c181f6237f8f0cc2f5
2021-09-23 18:29:56 -07:00
Jerry Zhang
508845f2b5 [quant] AO migration of the torch/quantization/quantize_fx.py and torch/quantization/fx/* (#65033)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65033

1. Move the file:
```
hg mv caffe2/torch/quantization/fx caffe2/torch/ao/quantization/fx
hg mv caffe2/torch/quantization/quantize_fx.py caffe2/torch/ao/quantization/quantize_fx.py
```
2. Create new files
```
touch caffe2/torch/quantization/quantize_fx.py
touch caffe2/torch/quantization/fx/__init__.py
```
3. import things in the new files
4. add tests to test/quantization/ao_migration/test_quantization_fx.py
this is because we have some fx import in quantize_fx and fx/*.py

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

Reviewed By: vkuzo, z-a-f

Differential Revision: D30949749

fbshipit-source-id: 9e5d4d039c8a0a0820bc9040e224f0d2c26886d3
2021-09-22 09:29:15 -07:00