|
1 | 1 | Get Started |
2 | | -========================== |
3 | | -We follow the `PyTorch official example <https://github.com/pytorch/examples/tree/master/imagenet/>`_ to build the example of Model Quantization Benchmark for ImageNet classification task. |
4 | | - |
5 | | -Requirements |
6 | | -------------- |
| 2 | +============ |
| 3 | +This tutorial will give details about the whole work-through to do quantization with MQBench, including: |
7 | 4 |
|
8 | | -- Install PyTorch following `pytorch.org <http://pytorch.org/>`_ |
9 | | -- Install dependencies:: |
| 5 | +.. toctree:: |
| 6 | + :maxdepth: 1 |
| 7 | + :titlesonly: |
10 | 8 |
|
11 | | - pip install -r requirements.txt |
12 | | - |
13 | | -- Download the ImageNet dataset from `the official website <http://www.image-net.org/>`_ |
14 | | - |
15 | | - - Then, and move validation images to labeled subfolders, using `the following shell script <https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh/>`_ |
16 | | - |
17 | | -- Install TensorRT=7.2.1.6 from `NVIDIA <https://developer.nvidia.com/tensorrt/>`_ |
18 | | - |
19 | | -Usage |
20 | | ---------- |
21 | | - |
22 | | -- **Quantization-Aware Training:** |
23 | | - |
24 | | - - Training hyper-parameters: |
25 | | - |
26 | | - - batch size = 128 |
27 | | - - epochs = 1 |
28 | | - - lr = 1e-4 |
29 | | - - others like weight decay, momentum are kept as default. |
30 | | - |
31 | | - - ResNet18 / ResNet50 / MobileNet_v2:: |
32 | | - |
33 | | - python main.py -a [model_name] --epochs 1 --lr 1e-4 --b 128 --seed 99 --pretrained |
34 | | - |
35 | | - |
36 | | -- **Deployment** |
37 | | - We provide the example to deploy the quantized model to TensorRT. |
38 | | - |
39 | | - 1. First export the quantized model to ONNX [tensorrt_deploy_model.onnx] and dump the clip ranges [tensorrt_clip_ranges.json] for activations.:: |
40 | | - |
41 | | - python main.py -a [model_name] --resume [model_save_path] |
42 | | - |
43 | | - |
44 | | - 2. Second build the TensorRT INT8 engine and evaluate, please make sure [dataset_path] contains subfolder [val]:: |
45 | | - |
46 | | - python onnx2trt.py --onnx [tensorrt_deploy_model.onnx] --trt [model_name.trt] --clip [tensorrt_clip_ranges.json] --data [dataset_path] --evaluate |
47 | | - |
48 | | - 3. If you don’t pass in external clip ranges [tensorrt_clip_ranges.json], TenosrRT will do calibration using default algorithm IInt8EntropyCalibrator2 with 100 images. So, please make sure [dataset_path] contains subfolder [cali]:: |
49 | | - |
50 | | - python onnx2trt.py --onnx [tensorrt_deploy_model.onnx] --trt [model_name.trt] --data [dataset_path] --evaluate |
51 | | - |
52 | | -Results |
53 | | ------------ |
54 | | - |
55 | | -+-------------------+--------------------------------+------------------------------------------------------------------------------------------------------------------+ |
56 | | -| Model | accuracy\@fp32 | accuracy\@int8 | |
57 | | -| | +----------------------------------------+---------------------------------+---------------------------------------+ |
58 | | -| | | TensoRT Calibration | MQBench QAT | TensorRT SetRange | |
59 | | -+===================+================================+========================================+=================================+=======================================+ |
60 | | -| **ResNet18** | Acc\@1 69.758 Acc\@5 89.078 | Acc\@1 69.612 Acc\@5 88.980 | Acc\@1 69.912 Acc\@5 89.150 | Acc\@1 69.904 Acc\@5 89.182 | |
61 | | -+-------------------+--------------------------------+----------------------------------------+---------------------------------+---------------------------------------+ |
62 | | -| **ResNet50** | Acc\@1 76.130 Acc\@5 92.862 | Acc\@1 76.074 Acc\@5 92.892 | Acc\@1 76.114 Acc\@5 92.946 | Acc\@1 76.320 Acc\@5 93.006 | |
63 | | -+-------------------+--------------------------------+----------------------------------------+---------------------------------+---------------------------------------+ |
64 | | -| **MobileNet_v2** | Acc\@1 71.878 Acc\@5 90.286 | Acc\@1 70.700 Acc\@5 89.708 | Acc\@1 70.826 Acc\@5 89.874 | Acc\@1 70.724 Acc\@5 89.870 | |
65 | | -+-------------------+--------------------------------+----------------------------------------+---------------------------------+---------------------------------------+ |
| 9 | + setup |
| 10 | + quantization |
| 11 | + deploy |
0 commit comments