Per-channel baseline#26516
Per-channel baseline#26516raghuramank100 wants to merge 19 commits intogh/raghuramank100/26/basefrom
Conversation
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Pull Request resolved: #26516 ghstack-source-id: 90471845 Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/)
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Pull Request resolved: #26516 ghstack-source-id: 90517083 Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/)
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
test/test_quantized_models.py
Outdated
| def test_float_quant_compare_per_channel(self): | ||
| # Test for per-channel Quant | ||
| torch.manual_seed(67) | ||
| myModel = ModelMultipleOps().to(torch.float32) |
There was a problem hiding this comment.
nit: can you use '_' naming e.g. 'my_model', or maybe just 'model'? so that we have a consistent naming?
torch/nn/quantized/modules/conv.py
Outdated
| # regular QTensor form for serialization. Packed weights should not live | ||
| # outside the process in which they were created, rather they should be derived | ||
| # from the QTensor weight. | ||
|
|
torch/nn/quantized/modules/conv.py
Outdated
| act_scale, act_zp = activation_observer.calculate_qparams() | ||
| assert weight_observer.dtype == torch.qint8, 'Weight observer must have a dtype of qint8' | ||
| wt_scale, wt_zp = weight_observer.calculate_qparams() | ||
| if weight_observer.qscheme in set([torch.per_tensor_symmetric, torch.per_tensor_affine]): |
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Pull Request resolved: #26516 ghstack-source-id: 90895960 Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/)
torch/nn/quantized/modules/utils.py
Outdated
|
|
||
| def _quantize_weight(float_wt, observer): | ||
| wt_scale, wt_zp = observer.calculate_qparams() | ||
| if observer.qscheme in {torch.per_tensor_symmetric, torch.per_tensor_affine}: |
There was a problem hiding this comment.
nit: this can be a list
| @@ -4,26 +4,47 @@ | |||
| from common_quantization import QuantizationTestCase, ModelMultipleOps | |||
There was a problem hiding this comment.
why is this not in test_quantization.py?
There was a problem hiding this comment.
this looks like an integration test
There was a problem hiding this comment.
Let's chat. test_quantized_models covers tests at a higher level: more complex models and comparison of float with quantized numerics at the model level. I think its better to have it as a separate file as test_quantization is really large already
jerryzh168
left a comment
There was a problem hiding this comment.
maybe remove test_quantized_model.py and move the code to test_quantization.py? could be in another PR
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Pull Request resolved: #26516 ghstack-source-id: 90926724 Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/)
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
Pull Request resolved: #26516 ghstack-source-id: 90966545 Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/)
Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/) [ghstack-poisoned]
|
This pull request has been merged in 2ccbdb7. |
Summary: Pull Request resolved: #26516 ghstack-source-id: 90982010 Test Plan: Integrate per-channel support into conv and linear modules. The following tests pass: buck test caffe2/test:quantized -- 'test_linear_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_conv_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_float_quant_compare_per_channel \(test_quantized_models\.ModelNumerics\)' --print-passing-details Differential Revision: D17342622 fbshipit-source-id: f0d618928e3d9348672c589a6b7a47049c372a2e
Summary: Pull Request resolved: #26516 ghstack-source-id: 90982010 Test Plan: Integrate per-channel support into conv and linear modules. The following tests pass: buck test caffe2/test:quantized -- 'test_linear_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_conv_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_float_quant_compare_per_channel \(test_quantized_models\.ModelNumerics\)' --print-passing-details Differential Revision: D17342622 fbshipit-source-id: f0d618928e3d9348672c589a6b7a47049c372a2e
Summary: Pull Request resolved: #26516 ghstack-source-id: 90982010 Test Plan: Integrate per-channel support into conv and linear modules. The following tests pass: buck test caffe2/test:quantized -- 'test_linear_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_conv_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_float_quant_compare_per_channel \(test_quantized_models\.ModelNumerics\)' --print-passing-details Differential Revision: D17342622 fbshipit-source-id: f0d618928e3d9348672c589a6b7a47049c372a2e
Summary: Pull Request resolved: #26516 ghstack-source-id: 90982010 Test Plan: Integrate per-channel support into conv and linear modules. The following tests pass: buck test caffe2/test:quantized -- 'test_linear_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_conv_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_float_quant_compare_per_channel \(test_quantized_models\.ModelNumerics\)' --print-passing-details Differential Revision: D17342622 fbshipit-source-id: f0d618928e3d9348672c589a6b7a47049c372a2e
Summary: Pull Request resolved: #26516 ghstack-source-id: 90982010 Test Plan: Integrate per-channel support into conv and linear modules. The following tests pass: buck test caffe2/test:quantized -- 'test_linear_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_conv_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_float_quant_compare_per_channel \(test_quantized_models\.ModelNumerics\)' --print-passing-details Differential Revision: D17342622 fbshipit-source-id: f0d618928e3d9348672c589a6b7a47049c372a2e
Summary: Pull Request resolved: pytorch#26516 ghstack-source-id: 90982010 Test Plan: Integrate per-channel support into conv and linear modules. The following tests pass: buck test caffe2/test:quantized -- 'test_linear_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_conv_api \(test_quantized_nn_mods\.ModuleAPITest\)' --print-passing-details buck test caffe2/test:quantized -- 'test_float_quant_compare_per_channel \(test_quantized_models\.ModelNumerics\)' --print-passing-details Differential Revision: D17342622 fbshipit-source-id: f0d618928e3d9348672c589a6b7a47049c372a2e
Pull Request resolved: pytorch/pytorch#26516 ghstack-source-id: 90704045 Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/)
Pull Request resolved: pytorch/pytorch#26516 ghstack-source-id: 90988292 Differential Revision: [D17342622](https://our.internmc.facebook.com/intern/diff/D17342622/)
Stack from ghstack:
Differential Revision: D17342622