-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add two export examples to validate accuracy and performance of expor…
…t API. (#563) Signed-off-by: Xin He <[email protected]> Co-authored-by: chensuyue <[email protected]>
- Loading branch information
Showing
16 changed files
with
2,013 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"pt2onnx": { | ||
"resnet18": { | ||
"model_src_dir": "image_recognition/torchvision_models/export/fx", | ||
"source_model_dataset": "/tf_dataset/pytorch/ImageNet/raw", | ||
"target_model_dataset": "/tf_dataset2/datasets/imagenet/ImagenetRaw/ImagenetRaw_small_5000", | ||
"input_model": "resnet18", | ||
"main_script": "main.py", | ||
"batch_size": 100 | ||
}, | ||
"resnet50": { | ||
"model_src_dir": "image_recognition/torchvision_models/export/fx", | ||
"source_model_dataset": "/tf_dataset/pytorch/ImageNet/raw", | ||
"target_model_dataset": "/tf_dataset2/datasets/imagenet/ImagenetRaw/ImagenetRaw_small_5000", | ||
"input_model": "resnet50", | ||
"main_script": "main.py", | ||
"batch_size": 100 | ||
}, | ||
"bert_base_MRPC": { | ||
"model_src_dir": "nlp/huggingface_models/text-classification/export/fx", | ||
"source_model_dataset": "mrpc", | ||
"target_model_dataset": "mrpc", | ||
"input_model": "/tf_dataset/pytorch/glue_data/base_weights/bert_MRPC_output", | ||
"main_script": "run_glue.py", | ||
"batch_size": 64 | ||
}, | ||
"bert_large_MRPC": { | ||
"model_src_dir": "nlp/huggingface_models/text-classification/export/fx", | ||
"source_model_dataset": "mrpc", | ||
"target_model_dataset": "mrpc", | ||
"input_model": "/tf_dataset/pytorch/glue_data/weights/bert_MRPC_output", | ||
"main_script": "run_glue.py", | ||
"batch_size": 64 | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
examples/pytorch/image_recognition/torchvision_models/export/fx/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Step-by-Step | ||
============ | ||
|
||
This document describes the step-by-step instructions for reproducing PyTorch tuning results with Intel® Neural Compressor. | ||
|
||
# Prerequisite | ||
|
||
## 1. Environment | ||
|
||
PyTorch 1.8 or higher version is needed with pytorch_fx backend. | ||
|
||
```shell | ||
cd examples/pytorch/image_recognition/torchvision_models/quantization/ptq/cpu/fx | ||
pip install -r requirements.txt | ||
``` | ||
> Note: Validated PyTorch [Version](/docs/source/installation_guide.md#validated-software-environment). | ||
## 2. Prepare Dataset | ||
|
||
Download [ImageNet](http://www.image-net.org/) Raw image to dir: /path/to/imagenet. The dir include below folder: | ||
|
||
```bash | ||
ls /path/to/pytorch-imagenet | ||
train val | ||
ls /path/to/onnx-imagenet-validation | ||
ILSVRC2012_img_val val.txt | ||
``` | ||
|
||
# Run | ||
### 1. To get the exported model: | ||
|
||
Run run_export.sh to get ONNX model from PyTorch model. | ||
```bash | ||
# export fp32 model | ||
bash run_export.sh --input_model=resnet50 --dtype=fp32 --dataset_location=/path/to/pytorch-imagenet --output_model=resnet50-fp32.onnx | ||
# export int8 model | ||
bash run_export.sh --input_model=resnet50 --dtype=int8 --quant_format=[QDQ|QLinear] --dataset_location=/path/to/pytorch-imagenet --output_model=resnet50-int8.onnx | ||
``` | ||
|
||
### 2. To get the benchmark of exported and tuned models, includes Batch_size and Throughput: | ||
Run run_benchmark.sh to benchmark the accuracy and performance of ONNX models and PyTorch model. | ||
```bash | ||
# benchmark ONNX model | ||
bash run_benchmark.sh --input_model=[resnet50-fp32.onnx|resnet50-int8.onnx] --dataset_location=/path/to/onnx-imagenet-validation --mode=[accuracy|performance] --batch_size=[16] | ||
# benchmark PyTorch model | ||
bash run_benchmark.sh --input_model=[resnet50|/path/to/saved_results] --dataset_location=/path/to/pytorch-imagenet --mode=[accuracy|performance] --int8=[true|false] --batch_size=[16] | ||
``` | ||
|
||
> Note: All torchvision model names can be passed as long as they are included in `torchvision.models`, below are some examples. |
Oops, something went wrong.