Skip to content

Commit 5baebb4

Browse files
committed
Moving documentation of quantized models in the right place.
1 parent 4e03a0b commit 5baebb4

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

docs/source/models.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,53 @@ MNASNet
263263
.. autofunction:: mnasnet1_0
264264
.. autofunction:: mnasnet1_3
265265

266+
Quantized Models
267+
----------------
268+
269+
The following architectures provide support for INT8 quantized models. You can get
270+
a model with random weights by calling its constructor:
271+
272+
.. code:: python
273+
274+
import torchvision.models as models
275+
googlenet = models.quantization.googlenet()
276+
inception_v3 = models.quantization.inception_v3()
277+
mobilenet_v2 = models.quantization.mobilenet_v2()
278+
mobilenet_v3_large = models.quantization.mobilenet_v3_large()
279+
mobilenet_v3_small = models.quantization.mobilenet_v3_small()
280+
resnet18 = models.quantization.resnet18()
281+
resnet50 = models.quantization.resnet50()
282+
resnext101_32x8d = models.quantization.resnext101_32x8d()
283+
shufflenet_v2_x0_5 = models.quantization.shufflenet_v2_x0_5()
284+
shufflenet_v2_x1_0 = models.quantization.shufflenet_v2_x1_0()
285+
shufflenet_v2_x1_5 = models.quantization.shufflenet_v2_x1_5()
286+
shufflenet_v2_x2_0 = models.quantization.shufflenet_v2_x2_0()
287+
288+
Obtaining a pre-trained quantized model can be done with a few lines of code:
289+
290+
.. code:: python
291+
292+
import torchvision.models as models
293+
model = models.quantization.mobilenet_v2(pretrained=True, quantize=True)
294+
model.eval()
295+
# run the model with quantized inputs and weights
296+
out = model(torch.rand(1, 3, 224, 224))
297+
298+
We provide pre-trained quantized weights for the following models:
299+
300+
================================ ============= =============
301+
Model Acc@1 Acc@5
302+
================================ ============= =============
303+
MobileNet V2 71.658 90.150
304+
MobileNet V3 Large TODO TODO
305+
ShuffleNet V2 68.360 87.582
306+
ResNet 18 69.494 88.882
307+
ResNet 50 75.920 92.814
308+
ResNext 101 32x8d 78.986 94.480
309+
Inception V3 77.176 93.354
310+
GoogleNet 69.826 89.404
311+
================================ ============= =============
312+
266313

267314
Semantic Segmentation
268315
=====================

references/classification/README.md

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,6 @@ python -m torch.distributed.launch --nproc_per_node=8 --use_env train.py\
7474
```
7575

7676
## Quantized
77-
### INT8 models
78-
We add INT8 quantized models to follow the quantization support added in PyTorch 1.3.
79-
80-
Obtaining a pre-trained quantized model can be obtained with a few lines of code:
81-
```
82-
model = torchvision.models.quantization.mobilenet_v2(pretrained=True, quantize=True)
83-
model.eval()
84-
# run the model with quantized inputs and weights
85-
out = model(torch.rand(1, 3, 224, 224))
86-
```
87-
We provide pre-trained quantized weights for the following models:
88-
89-
| Model | Acc@1 | Acc@5 |
90-
|:-----------------:|:------:|:------:|
91-
| MobileNet V2 | 71.658 | 90.150 |
92-
| ShuffleNet V2: | 68.360 | 87.582 |
93-
| ResNet 18 | 69.494 | 88.882 |
94-
| ResNet 50 | 75.920 | 92.814 |
95-
| ResNext 101 32x8d | 78.986 | 94.480 |
96-
| Inception V3 | 77.176 | 93.354 |
97-
| GoogleNet | 69.826 | 89.404 |
9877

9978
### Parameters used for generating quantized models:
10079

@@ -106,6 +85,10 @@ For all post training quantized models (All quantized models except mobilenet-v2
10685
4. eval_batch_size: 128
10786
5. backend: 'fbgemm'
10887

88+
```
89+
python train_quantization.py --device='cpu' --post-training-quantize --backend='fbgemm' --model='<model_name>'
90+
```
91+
10992
For Mobilenet-v2, the model was trained with quantization aware training, the settings used are:
11093
1. num_workers: 16
11194
2. batch_size: 32
@@ -119,14 +102,17 @@ For Mobilenet-v2, the model was trained with quantization aware training, the se
119102
10. lr_step_size:30
120103
11. lr_gamma: 0.1
121104

105+
```
106+
python -m torch.distributed.launch --nproc_per_node=8 --use_env train_quantization.py --model='mobilenetv2'
107+
```
108+
122109
Training converges at about 10 epochs.
123110

124111
For post training quant, device is set to CPU. For training, the device is set to CUDA
125112

126113
### Command to evaluate quantized models using the pre-trained weights:
127-
For all quantized models:
114+
128115
```
129-
python references/classification/train_quantization.py --data-path='imagenet_full_size/' \
130-
--device='cpu' --test-only --backend='fbgemm' --model='<model_name>'
116+
python train_quantization.py --device='cpu' --test-only --backend='fbgemm' --model='<model_name>'
131117
```
132118

0 commit comments

Comments
 (0)