Commit graph

139 commits

Author SHA1 Message Date
Supriya Rao
7cec4b3d4a [quant][fx] add _remove_qconfig flag to convert_fx (#53166)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/53166

Context: For fx modules that consist of scriptmodules, calling
delattr(module, 'qconfig') throws an attribute error. will follow up
with a separate issue/repro to fix this problem

This PR adds a temporary flag to convert_fx API to preserve the qconfig attributes on the converted model
We will remove this flag once we reach a conclusion on calling delattr on scriptmodules

Test Plan:
python test/test_quantization.py test_preserve_qconfig

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D26771518

fbshipit-source-id: 9fd72816576856ffb4aa11f8fde08303d1df10a2
2021-03-03 12:58:05 -08:00
Jerry Zhang
46bd76fdec [quant][graphmode][fx][fp16] Add fp16 support for silu (#52865)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52865

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26672270

fbshipit-source-id: a6a6ab58c347a56f0ded612b2e0a3e2230a91d9e
2021-03-02 02:11:29 -08:00
Jerry Zhang
267aeb8a56 [quant][graphmode][fx][fp16] Add fp16 support for tanh (#52864)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52864

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26672271

fbshipit-source-id: 539017c3045a28fc95f4f9d32591c2b2d10af6c0
2021-03-02 02:11:25 -08:00
Jerry Zhang
d40b501cfc [quant][graphmode][fx][fp16] Add fp16 support for sigmoid (#52863)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52863

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26672273

fbshipit-source-id: 30d5befe2a24081ac12ac773df4d2bd26d2d0192
2021-03-02 02:11:21 -08:00
Jerry Zhang
3fb324f05b [quant][graphmode][fx][fp16] Add fp16 support for layer_norm (#52862)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52862

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26672272

fbshipit-source-id: 4cfdce986efa98db7dc58bf2a62b650e45a69ed0
2021-03-02 02:11:17 -08:00
Jerry Zhang
fc6fdade9f [quant][graphmode][fx][fp16] Add fp16 support for torch.sum (#52811)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52811

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26655619

fbshipit-source-id: 642e0de47d0da7bd1abe1e981819de33e84c32f3
2021-03-02 02:11:13 -08:00
Jerry Zhang
97c51d5d5d [quant][graphmode][fx][fp16] Add fp16 support for div (#52810)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52810

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26655620

fbshipit-source-id: e46cb895ba456e99e4433bd6037229b8248a1b28
2021-03-02 02:11:08 -08:00
Jerry Zhang
a6af93e921 [quant][graphmode][fx][fp16] Add fp16 support for sub (#52809)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52809

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26655618

fbshipit-source-id: b47966ee1b75a2f814b9019d8d16b2da2212f5da
2021-03-02 02:09:07 -08:00
Jerry Zhang
991160ebd9 [quant][graphmode][fx] Add support for fp16 bmm pattern (#52808) (#53021)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/53021

Add support for producing fp16 bmm pattern

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

Imported from OSS

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26725349

fbshipit-source-id: debee718fc33e562aff3f5664757bb52ee85f651
2021-03-01 14:45:55 -08:00
Jerry Zhang
e00e42dbab [reland][quant][graphmode][fx][test][refactor] Refactoring binary op tests to split int8 and float16 tests (#52807) (#53020)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/53020

Test Plan:
Imported from OSS

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26725351

fbshipit-source-id: 35086ab19087501e1c9fdef4f16993ee9f364d0d
2021-03-01 14:06:10 -08:00
Jerry Zhang
096bea5251 [reland][quant][graphmode][fx][fp16] Add fp16 support for {add|mul}{_relu} (#52714) (#53019)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/53019

Test Plan:
python test/test_quantization.py TestQuantizedOps.test_add
python test/test_quantization.py TestQuantizedOps.test_mul
python test/test_quantization.py TestQuantizedOps.test_add_relu
python test/test_quantization.py TestQuantizedOps.test_mul_relu

Imported from OSS

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26725350

fbshipit-source-id: 2a89f5da6a21908f454f870521d2a4549fdd291e
2021-03-01 13:19:42 -08:00
Mike Ruberry
312b297b82 Revert D26626092: [quant][graphmode][fx][fp16] Add fp16 support for {add|mul}{_relu}
Test Plan: revert-hammer

Differential Revision:
D26626092 (2962fbb03c)

Original commit changeset: 91d040efa51e

fbshipit-source-id: cc6bcc0f451d6adcd7bf7572451e6e3cd6ad59d1
2021-03-01 04:52:47 -08:00
Mike Ruberry
03693c7e4a Revert D26655617: [quant][graphmode][fx][test][refactor] Refactoring binary op tests to split int8 and float16 tests
Test Plan: revert-hammer

Differential Revision:
D26655617 (f2f7fdba05)

Original commit changeset: c36edef09f52

fbshipit-source-id: 7a43cfc9385e45f4532168d2c3d9227da2f1967f
2021-03-01 04:52:44 -08:00
Mike Ruberry
3a024a7ae2 Revert D26655616: [quant][graphmode][fx] Add support for fp16 bmm pattern
Test Plan: revert-hammer

Differential Revision:
D26655616 (2c44b256d8)

Original commit changeset: 1d0639303e5c

fbshipit-source-id: 403429c706c8a9e6a657669daf8aadf282025f83
2021-03-01 04:50:35 -08:00
Jerry Zhang
2c44b256d8 [quant][graphmode][fx] Add support for fp16 bmm pattern (#52808)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52808

Add support for producing fp16 bmm pattern

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26655616

fbshipit-source-id: 1d0639303e5ca2ca4ceae08d03ebc3b25256de57
2021-02-28 16:48:41 -08:00
Jerry Zhang
f2f7fdba05 [quant][graphmode][fx][test][refactor] Refactoring binary op tests to split int8 and float16 tests (#52807)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52807

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26655617

fbshipit-source-id: c36edef09f522fe4c8eb0a8872add80c8dae4938
2021-02-27 23:16:49 -08:00
Jerry Zhang
2962fbb03c [quant][graphmode][fx][fp16] Add fp16 support for {add|mul}{_relu} (#52714)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52714

Test Plan:
python test/test_quantization.py TestQuantizedOps.test_add
python test/test_quantization.py TestQuantizedOps.test_mul
python test/test_quantization.py TestQuantizedOps.test_add_relu
python test/test_quantization.py TestQuantizedOps.test_mul_relu

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26626092

fbshipit-source-id: 91d040efa51e9c955eb688ec16a30f0c12233958
2021-02-27 22:12:10 -08:00
Jerry Zhang
0818dbf49d [quant][refactor] Merge add and mul handler (#52651)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52651

Merging them for easier extensions to fp16 and more binary ops

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26600118

fbshipit-source-id: a1816e593cf3065afe87d2e6e44cdace13bf6aeb
2021-02-27 19:56:32 -08:00
Jerry Zhang
b685864f50 [quant][graphmode][fx] Add reference option support for linear_static_fp16 (#52650)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52650

linear_dynamic_fp16 has following dtypes for activation, weight, bias, output:
(fp32, fp16, fp32, fp32)

linear_static_fp16 has following dtypes:
(fp16, fp16, fp16, fp16)

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26599803

fbshipit-source-id: b4a8345d355125070be718a227288cc848cc8bbc
2021-02-27 08:25:44 -08:00
Jerry Zhang
177694681e [quant][graphmode][fx] Add reference option support for linear_dynamic_fp16 (#52534)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52534

Currently linear_dynamic_fp16 has a signature that's tied to fbgemm/qnnpack
We'll need to produce a pattern equivalent to linear_dynamic_fp16 to support extensions
to other backends

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26557726

fbshipit-source-id: 270c9f781f73c79416a092b7831294cabca84b0c
2021-02-26 21:12:22 -08:00
Jerry Zhang
cb6b65699f [quant][graphmode][fx] Add support for packed params in state_dict (#51639)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/51639

Test Plan: Imported from OSS

Reviewed By: z-a-f

Differential Revision: D26228185

fbshipit-source-id: 6cf8b4106fec9c6900521a2afe0de6f3d29cc896
2021-02-26 15:13:50 -08:00
Jerry Zhang
a3e693789f [qunat][graphmode][fx] Enable test for non quantized input for cat (#52414)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52414

When the input is not quantized, we'll still quantize cat as requested by the qconfig, even though
it might be slower

Test Plan: Imported from OSS

Reviewed By: supriyar

Differential Revision: D26503554

fbshipit-source-id: 29d7c136711a12c124791c10ae436b61c1407668
2021-02-19 16:56:41 -08:00
Jerry Zhang
626756ac39 [quant][graphmode][api] debug --> reference (#52179)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52179

Rename debug to reference. We'll use this to produce a reference quantized model
that can be used as a common interface between pytorch quantized model and backends.

Test Plan:
python test/test_quantization.py TestQuantizeFx

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26424656

fbshipit-source-id: a0299b023f6ba7d98f5750724c517b0ecb987b35
2021-02-19 14:20:01 -08:00
Jerry Zhang
0c0de542be [quant][graphmode][fx] Guard the supported quantization type for add/mul (#52413)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52413

TODO: We'll need to add this guard for other ops as well

(Note: this ignores all push blocking failures!)

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

Imported from OSS

Reviewed By: supriyar

Differential Revision: D26503348

fbshipit-source-id: 5aaba518742a516cc3521fd5f23f1a264d2973e2
2021-02-19 12:56:22 -08:00
Jerry Zhang
338d2eca4a [quant][graphmode][fx] Enable test for non quantized input for add/mul (#52412)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/52412

When the input is not quantized, we'll still quantize add/mul

Test Plan: Imported from OSS

Reviewed By: supriyar

Differential Revision: D26503347

fbshipit-source-id: 457b3444c50e5b49b911b04c67684f5eead78ec9
2021-02-19 11:08:27 -08:00
Jerry Zhang
fb9f89507a [quant][graphmode][fx] Fix fp16 dynamic quant for functional linear (#52369)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52369

Test Plan: Imported from OSS

Reviewed By: supriyar

Differential Revision: D26491425

fbshipit-source-id: d2c2a70bf1bc43ac2b63ac4cf9ae9c07887f12e9
2021-02-18 23:05:30 -08:00
Jerry Zhang
f38e1d2d60 [quant][graphmode][fx] Enable inception_v3 and googlenet static quant test (#51402)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/51402

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26162805

fbshipit-source-id: 28ddc66f0593d28539dd6c6d3f617541e698d3bd
2021-02-03 14:32:00 -08:00
Supriya Rao
916af892b3 [quant][fx] Update name of packed weight attributes (#51259)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51259

Store the FQN of the module that is using the packed weights (the quantized op)

In the case of fusion we update the scope mapping to store the module path of the fused node.

Test Plan:
python test/test_quantization.py test_packed_weight_fused_op

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D26117964

fbshipit-source-id: 9d929997baafb1c91063dd9786a451b0040ae461
2021-01-28 20:31:08 -08:00
Jerry Zhang
7097c0d4f3 [quant][graphmode][fx] Add support for functional conv1d and conv3d (#51155) (#51254)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51254

This PR added support for quantizing functional conv1d, conv3d,  conv1d_relu and conv3d_relu

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26116172

fbshipit-source-id: 56e7d799c11963fe59ee3a1b6eb23f52007b91dc
2021-01-28 14:32:32 -08:00
Supriya Rao
288b94a8ee [quant][fx] Make scale, zero_point buffers in the model, use FQN (for quantize_per_tensor ops) (#51171)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51171

Following up on previous PR, this PR makes scale and zero_point for quantize_per_tensor to be
registered as buffers in the module.
Currently the dtype is still stored as attr (not registered as buffer) since we can only register tensor types.

Test Plan:
python test/test_quantization.py test_qparams_buffers

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D26092964

fbshipit-source-id: a54d914db7863402f2b5a3ba2c8ce8b27c18b47b
2021-01-28 08:35:46 -08:00
Supriya Rao
4c3f59b70e [quant][fx] Make scale, zero_point buffers in the model and use FQN (for quantized ops) (#51166)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51166

Currently scale and zero_point values are stored as constant values in the graph.
This prevents these values from being updated in the graph and also does not enable saving
these values to state_dict

After this PR we store scale/zero_point values for quantized ops as buffers in the root module
and createe get_attr nodes for them in the graph.

We also use the FQN of the module where the quantized ops are present to name these attributes so
that they can be uniquely  identified and mapped to quantized ops.

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

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D26092965

fbshipit-source-id: b549b2d3dccb45c5d38415ce95a09c26f5bd590b
2021-01-28 08:35:42 -08:00
Supriya Rao
096adf4b8b [quant][fx] Scope support for call_function in QuantizationTracer (#51086)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51086

Previously we only supported getting scope for call_module and custom qconfig dict for call_module.
This PR extends the Scope class to record the scope for all node types.
For call_function qconfig if module_name is specified it takes precedence over function qconfig.

Test Plan:
python test/test_quantization.py test_qconfig_for_call_func

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D26077602

fbshipit-source-id: 99cdcdedde2280e51812db300e17d4e6d8f477d2
2021-01-28 08:32:24 -08:00
Mike Ruberry
f7e90cf311 Revert D26089965: [quant][graphmode][fx] Add support for functional conv1d and conv3d
Test Plan: revert-hammer

Differential Revision:
D26089965 (dd1a97b3ae)

Original commit changeset: 4aea507d05b7

fbshipit-source-id: f54184cafb9dd07858683489d8bd147474e7e4b3
2021-01-27 13:27:10 -08:00
Jerry Zhang
dd1a97b3ae [quant][graphmode][fx] Add support for functional conv1d and conv3d (#51155)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51155

This PR added support for quantizing functional conv1d, conv3d,  conv1d_relu and conv3d_relu

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26089965

fbshipit-source-id: 4aea507d05b744807e993f6d3711ab308fb7591b
2021-01-27 12:00:35 -08:00
Jerry Zhang
d3ec204ef2 [quant][graphmode][fx] Add functional conv2d + relu (#51079)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51079

Added support for functional conv2d + relu, will add conv1d and conv3d in future PR

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D26089964

fbshipit-source-id: 8703de17de1469f7076651c386c83fb5922a56eb
2021-01-27 11:20:55 -08:00
Jerry Zhang
afa79a4df5 [quant][graphmode][fx] cleanup linear module test case (#50976)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/50976

Test Plan: Imported from OSS

Reviewed By: supriyar

Differential Revision: D26032531

fbshipit-source-id: 9725bab8f70ac79652e7bf9f94376917438d60e0
2021-01-26 11:14:22 -08:00
Jerry Zhang
28869d5a80 [quant][graphmode][fx] Add support for quantizing functional linear + {functional relu/module relu} (#50975)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/50975

Test Plan: Imported from OSS

Reviewed By: supriyar

Differential Revision: D26032532

fbshipit-source-id: a084fb4fd711ad52b2da1c6378cbcc2b352976c6
2021-01-25 12:49:58 -08:00
Jerry Zhang
55ac7e53ae [quant][graphmode][fx] Support preserved_attributes in prepare_fx (#50306)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/50306

Test Plan: Imported from OSS

Reviewed By: supriyar

Differential Revision: D25857747

fbshipit-source-id: fac132fb36ed9cf207aea40429b5bc3f7c72c35d
2021-01-11 12:10:02 -08:00
Jerry Zhang
f10e7aad06 [quant][graphmode][fx] Scope support for call_method in QuantizationTracer (#50173)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50173

Previously we did not set the qconfig for call_method node correctly since it requires us to know
the scope (module path of the module whose forward graph contains the node) of the node. This
PR modifies the QuantizationTracer to record the scope information and build a map from call_method
Node to module path, which will be used when we construct qconfig_map

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

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D25818132

fbshipit-source-id: ee9c5830f324d24d7cf67e5cd2bf1f6e0e46add8
2021-01-11 10:43:58 -08:00
Jerry Zhang
f6f0fde841 [reland][quant][graphmode][fx] Standalone module support {input/output}_quantized_idxs (#49754) (#50058)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50058

This PR adds the support for {input/output}_quantized_idxs for standalone module.

if input_quantized_idxs = [] and output_quantized_idxs = [], the standalone module will be expecting float
input and produce float output, and will quantize the input and dequantize output internally

if input_quantized_idxs = [0] and otuput_qiuantized_idxs = [0], the standalone module will be expecting quantized
input and produce quantized output, the input will be quantized in the parent module, and output will be dequantized
in the parent module as well, this is similar to current quantized modules like nn.quantized.Conv2d

For more details, please see the test case

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

Imported from OSS

Imported from OSS

Reviewed By: vkuzo

Differential Revision: D25768910

fbshipit-source-id: 96c21a3456cf192c8f1400afa4e86273ee69197b
2021-01-05 20:27:46 -08:00
Vasiliy Kuznetsov
44c17b28c6 quant: nice error message on convtranspose with per-channel weight (#49899)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49899

Per channel weights observer in conv transpose is not supported yet.  Adding an
error message which fails instantly instead of making the user wait until after
calibration/training finishes.

Test Plan:
```
python test/test_quantization.py TestPostTrainingStatic.test_convtranspose_per_channel_fails_early
python test/test_quantization.py TestQuantizeFx.test_convtranspose_per_channel_fails_early
```

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D25717151

fbshipit-source-id: 093e5979030ec185e3e0d56c45d7ce7338bf94b6
2021-01-05 09:38:57 -08:00
Vasiliy Kuznetsov
bc4ff7ba05 fx quant: split linear test cases (#49740)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49740

1. Separates the module and functional linear test cases.
2. Combines the test case which tests for linear bias observation into
the main linear test case, as requested in
https://github.com/pytorch/pytorch/pull/49628.

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

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D25681272

fbshipit-source-id: 0ed0ebd5afb8cdb938b530f7dbfbd79798eb9318
2020-12-28 14:30:25 -08:00
Vasiliy Kuznetsov
ea558b2135 fx quant: hook up ConvTranspose{n}d (#49717)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49717

Quantization of `ConvTranpose{n}d` is supported in Eager mode. This PR
adds the support for FX graph mode.

Note: this currenlty only works in `qnnpack` because per-channel weights
are not supported by quantized conv transpose. In a future PR we should throw
an error when someone tries to quantize a ConvTranspose model with per-channel
weight observers until this is fixed.

Test Plan:
```
python test/test_quantization.py TestQuantizeFxOps.test_conv_transpose_1d
python test/test_quantization.py TestQuantizeFxOps.test_conv_transpose_2d
```

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D25674636

fbshipit-source-id: b6948156123ed55db77e6337bea10db956215ae6
2020-12-28 14:27:07 -08:00
Mike Ruberry
46cf6d332f Revert D25684692: [quant][graphmode][fx] Standalone module support {input/output}_quantized_idxs
Test Plan: revert-hammer

Differential Revision:
D25684692 (89b4899ea5)

Original commit changeset: 900360e01c0e

fbshipit-source-id: 8b65fa8fbc7b364fbddb5f23cc696cd9b7db98cd
2020-12-24 15:50:52 -08:00
Jerry Zhang
89b4899ea5 [quant][graphmode][fx] Standalone module support {input/output}_quantized_idxs (#49754)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49754

This PR adds the support for {input/output}_quantized_idxs for standalone module.

if input_quantized_idxs = [] and output_quantized_idxs = [], the standalone module will be expecting float
input and produce float output, and will quantize the input and dequantize output internally

if input_quantized_idxs = [0] and otuput_qiuantized_idxs = [0], the standalone module will be expecting quantized
input and produce quantized output, the input will be quantized in the parent module, and output will be dequantized
in the parent module as well, this is similar to current quantized modules like nn.quantized.Conv2d

For more details, please see the test case

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

Imported from OSS

Reviewed By: raghuramank100

Differential Revision: D25684692

fbshipit-source-id: 900360e01c0e35b26fe85f4a887dc1fd6f7bfb66
2020-12-23 22:36:57 -08:00
Jerry Zhang
f474ffa1a9 [quant][graphmode][fx] Change standalone module api (#49719)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49719

We find there are multiple use cases for standalone module, one use case requires standalone module
to produce a module that takes float Tensor as input and outputs a float Tensor, the other needs to
produce a modulee that takes quantized Tensor as input and outputs a quantized Tensor.

This is similar to `quantized_input_idxs` and `quantized_output_idxs` so we want to nest
prepare_custom_config_dict in the standalone module configuration, for maximum flxibility we also
include qconfig_dict for stand alone module as well in case user needs to have special qconfig_dict for
the standalone module in the future.

Changed from
```python
prepare_custom_config_dict =
{
  "standalone_module_name": ["standalone_module"],
   "standalone_module_class": [StandaloneModule]
 }
```
to
```python
prepare_custom_config_dict =
{
  "standalone_module_name": [("standalone_module", qconfig_dict1, prepare_custom_config_dict1)],
  "standalone_module_class": [(StandaloneModule, qconfig_dict2, prepare_custom_config_dict2)]
 }
```
The entries in the config are:
1. name/module_class
2. optional qconfig_dict, when it is None, we'll use {"": qconfig} where qconfig is the one from parent qconfig_dict
3. optional prepare_custom_config_dict, when it is None, we'll use default value of prepare_custom_config_dict for prepare API (None)

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

Imported from OSS

Reviewed By: raghuramank100

Differential Revision: D25675704

fbshipit-source-id: 0889f519a3e55a7a677f0e2db4db9a18d87a93d4
2020-12-22 21:58:40 -08:00
Vasiliy Kuznetsov
19f972b696 fx quant: do not observe bias on F.linear (#49628)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49628

Ensures that linear bias is not observed in a `F.linear` call. This should
be a small speedup in PTQ, and will change numerics (in a good way) for
QAT if someone is using `F.linear`.

Note: the implementation is slightly more verbose compared to conv
because bias is a keyword argument in Linear.

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

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D25653532

fbshipit-source-id: c93501bf6b55cbe4a11cfdad6f79313483133a39
2020-12-22 16:53:21 -08:00
Vasiliy Kuznetsov
c3a7591cef fx quant: do not observe bias on F.conv (#49623)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49623

(not ready for review)

Ensures that conv bias is not observed in a `F.conv{n}d` call.

Test Plan: Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D25652856

fbshipit-source-id: 884f87be1948d3e049a557d79bec3c90aec34340
2020-12-22 16:49:50 -08:00
Jerry Zhang
5cde23fdd4 [quant][graphmode][fx] Allow user to specify qconfig for call_method (#49621)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49621

This adds support to configure qconfig for a call_method, e.g. x.chunk, this will help workaround
a problem in our internal model.

TODO: since call_method is also a string and we flatten the qconfig, might need to resolve namespace conflict between
call_method and module_name
TODO: Add scope support to set the qconfig for call_method correctly with original qconfig

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D25651828

fbshipit-source-id: 82d66b121d37c8274fd481b6a2e9f9b54c5ca73d
2020-12-18 20:21:52 -08:00
Vasiliy Kuznetsov
82ac6c75af fx quant: make sure observer is inserted before a quantized output (#49420)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49420

Before: if an output was marked as quantized, it could actually not
be quantized, if the previous node was not quantized.

After: if an output was marked as quantized, it will be quantized
regardless of the quantization status of the previous node.

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

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D25566834

fbshipit-source-id: 84755a1605fd3847edd03a7887ab9f635498c05c
2020-12-16 18:53:37 -08:00