|
| 1 | +Step-by-Step |
| 2 | +============ |
| 3 | + |
| 4 | +This document describes the step-by-step instructions for reproducing PyTorch tuning results with Intel® Neural Compressor. |
| 5 | + |
| 6 | +# Prerequisite |
| 7 | + |
| 8 | +## 1. Environment |
| 9 | + |
| 10 | +We verified examples with IPEX backend on Python 3.10, recommended. |
| 11 | + |
| 12 | +```shell |
| 13 | +pip install -r requirements.txt |
| 14 | +``` |
| 15 | + |
| 16 | +## 2. Install Intel-Pytorch-Extension |
| 17 | + |
| 18 | +Please refer to [intel/intel-extension-for-pytorch(github.com)](https://github.com/intel/intel-extension-for-pytorch). |
| 19 | + |
| 20 | +### Install IPEX CPU |
| 21 | + |
| 22 | + > Note: GCC9 compiler is recommended |
| 23 | +
|
| 24 | + ```shell |
| 25 | + python -m pip install intel_extension_for_pytorch -f https://software.intel.com/ipex-whl-stable |
| 26 | + ``` |
| 27 | + |
| 28 | +### Install IPEX XPU |
| 29 | +Please build an IPEX docker container according to the [official guide](https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=gpu&version=v2.1.30%2bxpu&os=linux%2fwsl2&package=docker). |
| 30 | + |
| 31 | +You can run a simple sanity test to double confirm if the correct version is installed, and if the software stack can get correct hardware information onboard your system. The command should return PyTorch and IPEX versions installed, as well as GPU card(s) information detected. |
| 32 | +```bash |
| 33 | +source {DPCPPROOT}/env/vars.sh |
| 34 | +source {MKLROOT}/env/vars.sh |
| 35 | +source {CCLROOT}/env/vars.sh |
| 36 | +source {MPIROOT}/env/vars.sh |
| 37 | +python -c "import torch; import intel_extension_for_pytorch as ipex; print(torch.__version__); print(ipex.__version__); [print(f'[{i}]: {torch.xpu.get_device_properties(i)}') for i in range(torch.xpu.device_count())];" |
| 38 | +``` |
| 39 | +Please also refer to this [tutorial](https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=gpu&version=v2.1.30%2bxpu&os=linux%2fwsl2&package=conda) to check system requirements and install dependencies. |
| 40 | + |
| 41 | +## 3. Prepare Dataset |
| 42 | + |
| 43 | +Download [ImageNet](http://www.image-net.org/) Raw image to dir: /path/to/imagenet. The dir include below folder: |
| 44 | + |
| 45 | +```bash |
| 46 | +ls /path/to/imagenet |
| 47 | +train val |
| 48 | +``` |
| 49 | + |
| 50 | +# Run with CPU |
| 51 | + |
| 52 | +> Note: All torchvision model names can be passed as long as they are included in `torchvision.models`, below are some examples. |
| 53 | +
|
| 54 | +### 1. ResNet18 With Intel PyTorch Extension |
| 55 | + |
| 56 | +```shell |
| 57 | +python main.py -t -a resnet18 --ipex --pretrained /path/to/imagenet |
| 58 | +``` |
| 59 | +or |
| 60 | +```shell |
| 61 | +bash run_quant.sh --input_model=resnet18 --dataset_location=/path/to/imagenet |
| 62 | +bash run_benchmark.sh --input_model=resnet18 --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false |
| 63 | +``` |
| 64 | + |
| 65 | +### 2. ResNet50 With Intel PyTorch Extension |
| 66 | + |
| 67 | +```shell |
| 68 | +python main.py -t -a resnet50 --ipex --pretrained /path/to/imagenet |
| 69 | +``` |
| 70 | +or |
| 71 | +```shell |
| 72 | +bash run_quant.sh --input_model=resnet50 --dataset_location=/path/to/imagenet |
| 73 | +bash run_benchmark.sh --input_model=resnet50 --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false |
| 74 | +``` |
| 75 | + |
| 76 | +### 3. ResNext101_32x16d With Intel PyTorch Extension |
| 77 | + |
| 78 | +```shell |
| 79 | +python main.py -t -a resnext101_32x16d_wsl --hub --ipex --pretrained /path/to/imagenet |
| 80 | +``` |
| 81 | +or |
| 82 | +```shell |
| 83 | +bash run_quant.sh --input_model=resnext101_32x16d_wsl --dataset_location=/path/to/imagenet |
| 84 | +bash run_benchmark.sh --input_model=resnext101_32x16d_wsl --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false |
| 85 | +``` |
| 86 | + |
| 87 | +# Run with XPU |
| 88 | + |
| 89 | +> Note: All torchvision model names can be passed as long as they are included in `torchvision.models`, below are some examples. |
| 90 | +
|
| 91 | +### 1. ResNet18 With Intel PyTorch Extension |
| 92 | + |
| 93 | +```shell |
| 94 | +python main.py -t -a resnet18 --ipex --pretrained /path/to/imagenet --xpu |
| 95 | +``` |
| 96 | +or |
| 97 | +```shell |
| 98 | +bash run_quant.sh --input_model=resnet18 --dataset_location=/path/to/imagenet |
| 99 | +bash run_benchmark.sh --input_model=resnet18 --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false --xpu=true/false |
| 100 | +``` |
0 commit comments