Commit Graph

10 Commits

Author SHA1 Message Date
Ben Koopman
a58ff186e8 [quant][embedding qat] Add basic EmbeddingBag QAT fakeQuant workflow (#65443)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/65443

Test Plan: Imported from OSS

Reviewed By: dagitses, supriyar

Differential Revision: D31456445

Pulled By: b-koopman

fbshipit-source-id: 0edda6e272d9005fce65f2ba6a5e6abc831836de
2021-10-07 20:19:29 -07:00
Supriya Rao
8a974a482c [quant] Add support for quantization of Embedding{Bag} in dynamic quant APIs (#65674)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65674

Before this PR user had to use the eager mode static quantization APIs to quantize Embedding/EmbeddingBag modules.
With this PR they can use either the static or dynamic quantization APIs for Embedding quantization

The only qconfig supported for embedding quantization is float_qparams_weight_only_qconfig whcih is currently enforced in the from_float
method of the quantized Embedding/Embedding modules.

To combine embedding quantization with Linear dynamic quantization, user can use the qconfig_dict to specify different qconfig for each module type.

The prepare/convert APIs can still be used to quantize Embeddings, with the caveat that user need to ensure input to Embedding ops are FP32.

Addresses Issue #65185
ghstack-source-id: 139935419

Test Plan:
python test/test_quantization.py

Imported from OSS

Reviewed By: gchanan

Differential Revision: D31211199

fbshipit-source-id: 8c747881caee5ccbf8b93c6704b08d132049dea4
2021-10-06 23:19:38 -07:00
Supriya Rao
554a1a70c7 [quant] update embedding module to not store qweight (#50418)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50418

previously we were storing the quantized weight as a module attribute, whcih
was resulting in the weight getting stored as part of the model.
We don't need this since we already store the unpacked weights as part of the model.

Test Plan:
Before
```
Archive:  tmp.pt
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
     586  Stored      586   0% 00-00-1980 00:00 5fefdda0  tmp/extra/producer_info.json
 1588700  Stored  1588700   0% 00-00-1980 00:00 04e0da4c  tmp/data/0
   63548  Stored    63548   0% 00-00-1980 00:00 0ceb1f45  tmp/data/1
   63548  Stored    63548   0% 00-00-1980 00:00 517bc3ab  tmp/data/2
 1588700  Stored  1588700   0% 00-00-1980 00:00 dbe88c73  tmp/data/3
   63548  Stored    63548   0% 00-00-1980 00:00 d8dc47c4  tmp/data/4
   63548  Stored    63548   0% 00-00-1980 00:00 b9e0c20f  tmp/data/5
    1071  Stored     1071   0% 00-00-1980 00:00 10dc9350  tmp/data.pkl
     327  Defl:N      203  38% 00-00-1980 00:00 dfddb661  tmp/code/__torch__/___torch_mangle_0.py
     185  Stored      185   0% 00-00-1980 00:00 308f580b  tmp/code/__torch__/___torch_mangle_0.py.debug_pkl
    1730  Defl:N      515  70% 00-00-1980 00:00 aa11f799  tmp/code/__torch__/torch/nn/quantized/modules/embedding_ops.py
    1468  Defl:N      636  57% 00-00-1980 00:00 779609a6  tmp/code/__torch__/torch/nn/quantized/modules/embedding_ops.py.debug_pkl
       0  Stored        0   0% 00-00-1980 00:00 00000000  tmp/code/__torch__/torch/classes/quantized.py
       6  Stored        6   0% 00-00-1980 00:00 816d0907  tmp/code/__torch__/torch/classes/quantized.py.debug_pkl
       4  Stored        4   0% 00-00-1980 00:00 57092f6d  tmp/constants.pkl
       2  Stored        2   0% 00-00-1980 00:00 55679ed1  tmp/version
--------          -------  ---                            -------
 3436971          3434800   0%                            16 files
```
After
```
Archive:  tmp.pt
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
 1588700  Stored  1588700   0% 00-00-1980 00:00 a4da6981  tmp/data/0
   63548  Stored    63548   0% 00-00-1980 00:00 74d9b607  tmp/data/1
   63548  Stored    63548   0% 00-00-1980 00:00 e346a0c2  tmp/data/2
     952  Stored      952   0% 00-00-1980 00:00 eff8706e  tmp/data.pkl
     375  Defl:N      227  40% 00-00-1980 00:00 96c77b68  tmp/code/__torch__/quantization/test_quantize/___torch_mangle_23.py
     228  Defl:N      162  29% 00-00-1980 00:00 6a378113  tmp/code/__torch__/quantization/test_quantize/___torch_mangle_23.py.debug_pkl
    1711  Defl:N      509  70% 00-00-1980 00:00 66d8fd61  tmp/code/__torch__/torch/nn/quantized/modules/embedding_ops.py
    1473  Defl:N      634  57% 00-00-1980 00:00 beb2323b  tmp/code/__torch__/torch/nn/quantized/modules/embedding_ops.py.debug_pkl
       0  Stored        0   0% 00-00-1980 00:00 00000000  tmp/code/__torch__/torch/classes/quantized.py
       6  Stored        6   0% 00-00-1980 00:00 816d0907  tmp/code/__torch__/torch/classes/quantized.py.debug_pkl
       4  Stored        4   0% 00-00-1980 00:00 57092f6d  tmp/constants.pkl
       2  Stored        2   0% 00-00-1980 00:00 55679ed1  tmp/version
--------          -------  ---                            -------
 1720547          1718292   0%                            12 files
```

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D25879879

fbshipit-source-id: e09427a60d4c44dd1a190575e75f3ed9cde6358f
2021-01-14 10:38:06 -08:00
Richard Barnes
638086950d Clean up type annotations in torch/nn/quantized/modules (#49941)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/49941

Test Plan: Sandcastle

Reviewed By: jerryzh168

Differential Revision: D25718715

fbshipit-source-id: bbe450d937cf7ef634e003c09146e308180d1d58
2021-01-06 11:03:08 -08:00
Alex Henrie
5f2ec6293d Unused variables in neural net classes and functions (#50100)
Summary:
These unused variables were identified by [pyflakes](https://pypi.org/project/pyflakes/). They can be safely removed to simplify the code and possibly improve performance.

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

Reviewed By: ezyang

Differential Revision: D25797764

Pulled By: smessmer

fbshipit-source-id: ced341aee692f429d2dcc3a4ef5c46c8ee99cabb
2021-01-06 08:16:57 -08:00
Jerry Zhang
576fa09157 [quant][fix] Fix quant type classification for float_qparam qconfig (#48069)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/48069

also renamed float_qparam_dynamic_qconfig to float_qparam_weight_only_qconfig
It's not used in user code yet so we only need to update the tests.

Test Plan: Imported from OSS

Reviewed By: supriyar

Differential Revision: D25010175

fbshipit-source-id: caa3eaa5358a8bc5c808bf5f64e6ebff3e0b61e8
2020-11-18 18:22:08 -08:00
Supriya Rao
31888b2e77 [quant][pyper] Rename the sparse argument for embedding_bag ops (#46003)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/46003

sparse is confusing because itt is used in training for sparse gradients

Test Plan: Imported from OSS

Reviewed By: radkris-git, qizzzh

Differential Revision: D24178248

fbshipit-source-id: 0a2b595f3873d33b2ce25839b6eee31d2bfd3b0d
2020-10-08 16:15:28 -07:00
Supriya Rao
43dc7ef933 [quant] Support for 4-bit quantized EmbeddingBag module (#45865)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/45865

Test Plan:
python test/test_quantization.py TestPostTrainingStatic.test_quantized_embedding_bag
python test/test_quantization.py TestStaticQuantizedModule.test_embedding_bag_api

Imported from OSS

Reviewed By: jerryzh168

Differential Revision: D24120995

fbshipit-source-id: c55fc6b2cfd683d14d2a05be7c04f787fdf8cc79
2020-10-06 21:11:52 -07:00
Xiang Gao
20ac736200 Remove py2 compatible future imports (#44735)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/44735

Reviewed By: mruberry

Differential Revision: D23731306

Pulled By: ezyang

fbshipit-source-id: 0ba009a99e475ddbe22981be8ac636f8a1c8b02f
2020-09-16 12:55:57 -07:00
Supriya Rao
646ffd4886 [quant] Move EmbeddingBag eager quantization to static (#44217)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/44217

Move the tests to static ones as well

Test Plan:
python test/test_quantization.py TestStaticQuantizedModule.test_embedding_bag_api

Imported from OSS

Reviewed By: raghuramank100

Differential Revision: D23547386

fbshipit-source-id: 41f81c31e1613098ecf6a7eff601c7dcd4b09c76
2020-09-08 19:05:02 -07:00