Skip to content

Commit

Permalink
Merge branch 'master' into kaihui/core_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
chensuyue authored Jul 29, 2024
2 parents 663921a + 50eb6fb commit 5226448
Show file tree
Hide file tree
Showing 25 changed files with 2,970 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .azure-pipelines/scripts/install_nc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
echo -e "\n Install Neural Compressor ... "
cd /neural-compressor
if [[ $1 = *"3x_pt"* ]]; then
if [[ $1 != *"3x_pt_fp8"* ]]; then
echo -e "\n Install torch CPU ... "
pip install torch==2.3.0 --index-url https://download.pytorch.org/whl/cpu
fi
python -m pip install --no-cache-dir -r requirements_pt.txt
python setup.py pt bdist_wheel
pip install --no-deps dist/neural_compressor*.whl --force-reinstall
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,29 @@ support AMD CPU, ARM CPU, and NVidia GPU through ONNX Runtime with limited testi
* [2024/07] Performance optimizations and usability improvements on [client-side](https://github.com/intel/neural-compressor/blob/master/docs/source/3x/client_quant.md).

## Installation
### Install Framework
#### Install torch for CPU
```Shell
pip install torch --index-url https://download.pytorch.org/whl/cpu
```
#### Use Docker Image with torch installed for HPU
https://docs.habana.ai/en/latest/Installation_Guide/Bare_Metal_Fresh_OS.html#bare-metal-fresh-os-single-click

#### Install torch/intel_extension_for_pytorch for Intel GPU
https://intel.github.io/intel-extension-for-pytorch/index.html#installation

#### Install torch for other platform
https://pytorch.org/get-started/locally

#### Install tensorflow
```Shell
pip install tensorflow
```

### Install from pypi
```Shell
# Install 2.X API + Framework extension API + PyTorch dependency
pip install neural-compressor[pt]
pip install neural-compressor[pt]
# Install 2.X API + Framework extension API + TensorFlow dependency
pip install neural-compressor[tf]
```
Expand Down
19 changes: 19 additions & 0 deletions docs/source/installation_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ The following prerequisites and requirements must be satisfied for a successful
> Notes:
> - If you get some build issues, please check [frequently asked questions](faq.md) at first.
### Install Framework
#### Install torch for CPU
```Shell
pip install torch --index-url https://download.pytorch.org/whl/cpu
```
#### Use Docker Image with torch installed for HPU
https://docs.habana.ai/en/latest/Installation_Guide/Bare_Metal_Fresh_OS.html#bare-metal-fresh-os-single-click

#### Install torch/intel_extension_for_pytorch for Intel GPU
https://intel.github.io/intel-extension-for-pytorch/index.html#installation

#### Install torch for other platform
https://pytorch.org/get-started/locally

#### Install tensorflow
```Shell
pip install tensorflow
```

### Install from Binary
- Install from Pypi
```Shell
Expand Down
7 changes: 7 additions & 0 deletions examples/.config/model_params_tensorflow_3x.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@
"main_script": "main.py",
"batch_size": 1000
},
"yolo_v5": {
"model_src_dir": "object_detection/yolo_v5/quantization/ptq",
"dataset_location": "/tf_dataset2/datasets/coco_yolov5/coco",
"input_model": "/tf_dataset2/models/tensorflow/yolo_v5/yolov5s.pb",
"main_script": "main.py",
"batch_size": 1
},
"faster_rcnn_resnet50": {
"model_src_dir": "object_detection/faster_rcnn_resnet50/quantization/ptq",
"dataset_location": "/tf_dataset/tensorflow/coco_val.record",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Step-by-Step
============

This document describes the step-by-step instructions for reproducing PyTorch tuning results with Intel® Neural Compressor.

# Prerequisite

## 1. Environment

We verified examples with IPEX backend on Python 3.10, recommended.

```shell
pip install -r requirements.txt
```

## 2. Install Intel-Pytorch-Extension

Please refer to [intel/intel-extension-for-pytorch(github.com)](https://github.com/intel/intel-extension-for-pytorch).

### Install IPEX CPU

> Note: GCC9 compiler is recommended
```shell
python -m pip install intel_extension_for_pytorch -f https://software.intel.com/ipex-whl-stable
```

### Install IPEX XPU
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).

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.
```bash
source {DPCPPROOT}/env/vars.sh
source {MKLROOT}/env/vars.sh
source {CCLROOT}/env/vars.sh
source {MPIROOT}/env/vars.sh
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())];"
```
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.

## 3. 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/imagenet
train val
```

# Run with CPU

> Note: All torchvision model names can be passed as long as they are included in `torchvision.models`, below are some examples.
### 1. ResNet18 With Intel PyTorch Extension

```shell
python main.py -t -a resnet18 --ipex --pretrained /path/to/imagenet
```
or
```shell
bash run_quant.sh --input_model=resnet18 --dataset_location=/path/to/imagenet
bash run_benchmark.sh --input_model=resnet18 --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false
```

### 2. ResNet50 With Intel PyTorch Extension

```shell
python main.py -t -a resnet50 --ipex --pretrained /path/to/imagenet
```
or
```shell
bash run_quant.sh --input_model=resnet50 --dataset_location=/path/to/imagenet
bash run_benchmark.sh --input_model=resnet50 --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false
```

### 3. ResNext101_32x16d With Intel PyTorch Extension

```shell
python main.py -t -a resnext101_32x16d_wsl --hub --ipex --pretrained /path/to/imagenet
```
or
```shell
bash run_quant.sh --input_model=resnext101_32x16d_wsl --dataset_location=/path/to/imagenet
bash run_benchmark.sh --input_model=resnext101_32x16d_wsl --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false
```

# Run with XPU

> Note: All torchvision model names can be passed as long as they are included in `torchvision.models`, below are some examples.
### 1. ResNet18 With Intel PyTorch Extension

```shell
python main.py -t -a resnet18 --ipex --pretrained /path/to/imagenet --xpu
```
or
```shell
bash run_quant.sh --input_model=resnet18 --dataset_location=/path/to/imagenet
bash run_benchmark.sh --input_model=resnet18 --dataset_location=/path/to/imagenet --mode=performance/accuracy --int8=true/false --xpu=true/false
```
Loading

0 comments on commit 5226448

Please sign in to comment.