pytorch/torch/quantization
Vasiliy Kuznetsov 182d8c375c ns for fx: add partial support for subgraphs with base_op_node (#54254)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54254

In fp16 emulation, we now have patterns such as

```
... -> dequantize -> linear -> relu -> to(torch.float16) -> ...
```

This PR adds support for
* specifying a subgraph's "base_op_node", which is the node with the op
which should be matched to related nodes. In the example above,
"base_op_node" would be the linear node, and it would be the second
node in the matched pattern.
* matching these fusion patterns and properly setting "base_op_node"
based on pattern and index
* using "base_op_node" instead of "start_node" throughout the NS
codebase wherever the intent is to match subgraphs or create names
for subgraphs.

At the end of this PR, matching unshadowed activations with an example
fp16 emulation pattern works e2e.

I'm saving the following work for future PRs (soon), mostly to keep
PR size manageable:
* adding weight matching (will require some changes to function which
extracts weights)
* adding shadowed activation matching (will require some changes to
shadow copying)
* adding input logging for these patterns (will likely require some changes as well)

Test Plan:
```
python test/test_quantization.py TestFXNumericSuiteCoreAPIs.test_linear_fp16
```

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D27158199

fbshipit-source-id: 49fc445395452fda62e3c7a243544190f9af691c
2021-03-25 22:35:36 -07:00
..
fx fx quant: fix bug with fusion patterns and disabling quantization (#54654) 2021-03-25 22:21:41 -07:00
ns ns for fx: add partial support for subgraphs with base_op_node (#54254) 2021-03-25 22:35:36 -07:00
__init__.py [quant][fix] Fix quant type classification for float_qparam qconfig (#48069) 2020-11-18 18:22:08 -08:00
_correct_bias.py Remove py2 compatible future imports (#44735) 2020-09-16 12:55:57 -07:00
_equalize.py Fix type annotation errors in torch.functional (#43446) 2020-08-26 08:27:59 -07:00
_learnable_fake_quantize.py mem-efficient learnable fake quantization (#49315) 2021-02-03 18:57:47 -08:00
_numeric_suite_fx.py compare_model_outputs_fx API implementation (#49266) 2021-02-02 10:43:25 -08:00
_numeric_suite.py ns_eager: rename Logger I/O var names to logger_cls (#51359) 2021-02-09 22:30:44 -08:00
fake_quantize.py memory efficient per-channel fq: use it everywhere, delete old version (#51265) 2021-01-28 19:42:25 -08:00
fuse_modules.py quantization: Linear + BatchNorm1d fusion (#50748) 2021-01-20 12:59:02 -08:00
fuser_method_mappings.py quantization: Linear + BatchNorm1d fusion (#50748) 2021-01-20 12:59:02 -08:00
observer.py update HistogramObserver to be scriptable (#51081) 2021-01-27 07:27:03 -08:00
qconfig.py [quant][graphmode][fx] Add reference option support for linear_static_fp16 (#52650) 2021-02-27 08:25:44 -08:00
quant_type.py [quant][graphmode][fx] custom_module support static/dynamic/weight_only quant (#46786) 2020-10-27 21:41:33 -07:00
quantization_mappings.py [quantization] Add some support for 3d operations (#50003) 2021-03-10 16:40:35 -08:00
quantize_fx.py [quant][fx] add _remove_qconfig flag to convert_fx (#53166) 2021-03-03 12:58:05 -08:00
quantize_jit.py [TorchScript] Support user defined classes as constants (#5062) 2020-11-16 20:52:02 -08:00
quantize.py [quant] Factoring out the list of no_observers (#50459) 2021-02-17 12:38:30 -08:00
stubs.py type check for torch.quantization.stubs (#46475) 2020-10-16 15:34:23 -07:00
utils.py [quant][graphmode][fx] Fix a condition check for CopyNode (#53585) 2021-03-11 09:32:20 -08:00