Skip to content

Commit 6ab5570

Browse files
doc and example update for ITEX support (#1360)
1 parent 74b3b38 commit 6ab5570

File tree

139 files changed

+4376
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+4376
-90
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Intel® Neural Compressor
1717
Intel® Neural Compressor, formerly known as Intel® Low Precision Optimization Tool, is an open-source Python library that runs on Intel CPUs and GPUs, which delivers unified interfaces across multiple deep-learning frameworks for popular network compression technologies such as quantization, pruning, and knowledge distillation. This tool supports automatic accuracy-driven tuning strategies to help the user quickly find out the best quantized model. It also implements different weight-pruning algorithms to generate a pruned model with predefined sparsity goal. It also supports knowledge distillation to distill the knowledge from the teacher model to the student model.
1818
Intel® Neural Compressor is a critical AI software component in the [Intel® oneAPI AI Analytics Toolkit](https://software.intel.com/content/www/us/en/develop/tools/oneapi/ai-analytics-toolkit.html).
1919

20-
> **Note:**
21-
> GPU support is under development.
2220

2321
**Visit the Intel® Neural Compressor online document website at: <https://intel.github.io/neural-compressor>.**
2422

@@ -107,6 +105,10 @@ Intel® Neural Compressor supports systems based on [Intel 64 architecture or co
107105
* Intel Xeon Scalable processor (formerly Skylake, Cascade Lake, Cooper Lake, and Icelake)
108106
* Future Intel Xeon Scalable processor (code name Sapphire Rapids)
109107

108+
Intel® Neural Compressor supports the following Intel GPUs built on Intel's Xe architecture:
109+
110+
* [Intel® Data Center GPU Flex Series](https://www.intel.com/content/www/us/en/products/docs/discrete-gpus/data-center-gpu/flex-series/overview.html)
111+
110112
### Validated Software Environment
111113

112114
* OS version: CentOS 8.4, Ubuntu 20.04

examples/tensorflow/image_recognition/SavedModel/quantization/ptq/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Step-by-Step
22
============
33

44
This document is used to enable Tensorflow SavedModel format using Intel® Neural Compressor for performance only.
5+
This example can run on Intel CPUs and GPUs.
56

67

78
## Prerequisite
@@ -17,14 +18,32 @@ pip install intel-tensorflow
1718
```
1819
> Note: Supported Tensorflow >= 2.4.0.
1920
20-
### 3. Prepare Pretrained model
21+
### 3. Install Intel Extension for Tensorflow if needed
22+
#### Tuning the model on Intel GPU(Mandatory)
23+
Intel Extension for Tensorflow is mandatory to be installed for tuning the model on Intel GPUs.
24+
25+
```shell
26+
pip install --upgrade intel-extension-for-tensorflow[gpu]
27+
```
28+
For any more details, please follow the procedure in [install-gpu-drivers](https://github.com/intel-innersource/frameworks.ai.infrastructure.intel-extension-for-tensorflow.intel-extension-for-tensorflow/blob/master/docs/install/install_for_gpu.md#install-gpu-drivers)
29+
30+
#### Tuning the model on Intel CPU(Experimental)
31+
Intel Extension for Tensorflow for Intel CPUs is experimental currently. It's not mandatory for tuning the model on Intel CPUs.
32+
33+
```shell
34+
pip install --upgrade intel-extension-for-tensorflow[cpu]
35+
```
36+
37+
### 4. Prepare Pretrained model
2138
Download the model from tensorflow-hub.
2239

2340
image recognition
2441
- [mobilenetv1](https://hub.tensorflow.google.cn/google/imagenet/mobilenet_v1_075_224/classification/5)
2542
- [mobilenetv2](https://hub.tensorflow.google.cn/google/imagenet/mobilenet_v2_035_224/classification/5)
2643
- [efficientnet_v2_b0](https://hub.tensorflow.google.cn/google/imagenet/efficientnet_v2_imagenet1k_b0/classification/2)
2744

45+
## Write Yaml config file
46+
In examples directory, there are mobilenet_v1.yaml, mobilenet_v2.yaml and efficientnet_v2_b0.yaml for tuning the model on Intel CPUs. The 'framework' in the yaml is set to 'tensorflow'. If running this example on Intel GPUs, the 'framework' should be set to 'tensorflow_itex' and the device in yaml file should be set to 'gpu'. The mobilenet_v1_itex.yaml, mobilenet_v2_itex.yaml and efficientnet_v2_b0_itex.yaml are prepared for the GPU case. We could remove most of items and only keep mandatory item for tuning. We also implement a calibration dataloader and have evaluation field for creation of evaluation function at internal neural_compressor.
2847

2948
## Run Command
3049
```shell

examples/tensorflow/image_recognition/SavedModel/quantization/ptq/efficientnet_v2_b0.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ model: # mandatory. neural_compres
1919
name: efficientnet_v2_b0
2020
framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension.
2121

22+
device: cpu # optional. default value is cpu, other value is gpu.
23+
2224
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
2325
calibration:
2426
sampling_size: 5, 10, 50, 100 # optional. default value is the size of whole dataset. used to set how many portions of calibration dataset is used. exclusive with iterations field.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#
2+
# Copyright (c) 2021 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
version: 1.0
17+
18+
model: # mandatory. neural_compressor uses this model name and framework name to decide where to save tuning history and deploy yaml.
19+
name: efficientnet_v2_b0
20+
framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension.
21+
22+
device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu].
23+
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
24+
calibration:
25+
sampling_size: 5, 10, 50, 100 # optional. default value is the size of whole dataset. used to set how many portions of calibration dataset is used. exclusive with iterations field.
26+
dataloader:
27+
dataset:
28+
ImagenetRaw:
29+
data_path: /path/to/calibration/dataset # NOTE: modify to calibration dataset location if needed
30+
image_list: /path/to/calibration/label # data file, record image_names and their labels
31+
transform:
32+
PaddedCenterCrop:
33+
size: 224
34+
crop_padding: 32
35+
Resize:
36+
size: 224
37+
interpolation: bicubic
38+
Normalize:
39+
mean: [123.675, 116.28, 103.53]
40+
std: [58.395, 57.12, 57.375]
41+
42+
evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
43+
accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
44+
metric:
45+
topk: 1 # built-in metrics are topk, map, f1, allow user to register new metric.
46+
dataloader:
47+
batch_size: 32
48+
dataset:
49+
ImagenetRaw:
50+
data_path: /path/to/evaluation/dataset # NOTE: modify to evaluation dataset location if needed
51+
image_list: /path/to/evaluation/label # data file, record image_names and their labels
52+
transform:
53+
PaddedCenterCrop:
54+
size: 224
55+
crop_padding: 32
56+
Resize:
57+
size: 224
58+
interpolation: bicubic
59+
Normalize:
60+
mean: [123.675, 116.28, 103.53]
61+
std: [58.395, 57.12, 57.375]
62+
performance: # optional. used to benchmark performance of passing model.
63+
iteration: 100
64+
configs:
65+
cores_per_instance: 4
66+
num_of_instance: 7
67+
dataloader:
68+
batch_size: 1
69+
dataset:
70+
ImagenetRaw:
71+
data_path: /path/to/evaluation/dataset # NOTE: modify to evaluation dataset location if needed
72+
image_list: /path/to/evaluation/label # data file, record image_names and their labels
73+
transform:
74+
PaddedCenterCrop:
75+
size: 224
76+
crop_padding: 32
77+
Resize:
78+
size: 224
79+
interpolation: bicubic
80+
Normalize:
81+
mean: [123.675, 116.28, 103.53]
82+
std: [58.395, 57.12, 57.375]
83+
84+
tuning:
85+
accuracy_criterion:
86+
relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%.
87+
exit_policy:
88+
timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit.
89+
random_seed: 9527 # optional. random seed for deterministic tuning.

examples/tensorflow/image_recognition/SavedModel/quantization/ptq/mobilenet_v1.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ model: # mandatory. used to specif
1717
name: mobilenet_v1
1818
framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension.
1919

20+
device: cpu # optional. default value is cpu, other value is gpu.
21+
2022
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
2123
calibration:
2224
sampling_size: 20, 50 # optional. default value is 100. used to set how many samples should be used in calibration.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# Copyright (c) 2021 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
model: # mandatory. used to specify model specific information.
17+
name: mobilenet_v1
18+
framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension.
19+
20+
device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu].
21+
22+
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
23+
calibration:
24+
sampling_size: 20, 50 # optional. default value is 100. used to set how many samples should be used in calibration.
25+
dataloader:
26+
batch_size: 10
27+
dataset:
28+
ImageRecord:
29+
root: /path/to/calibration/dataset # NOTE: modify to calibration dataset location if needed
30+
transform:
31+
BilinearImagenet:
32+
height: 224
33+
width: 224
34+
model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
35+
activation:
36+
algorithm: minmax
37+
weight:
38+
granularity: per_channel
39+
40+
evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
41+
accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
42+
metric:
43+
topk: 1 # built-in metrics are topk, map, f1, allow user to register new metric.
44+
dataloader:
45+
batch_size: 32
46+
dataset:
47+
ImageRecord:
48+
root: /path/to/evaluation/dataset # NOTE: modify to evaluation dataset location if needed
49+
transform:
50+
BilinearImagenet:
51+
height: 224
52+
width: 224
53+
performance: # optional. used to benchmark performance of passing model.
54+
iteration: 100
55+
configs:
56+
cores_per_instance: 4
57+
num_of_instance: 7
58+
dataloader:
59+
batch_size: 1
60+
dataset:
61+
ImageRecord:
62+
root: /path/to/evaluation/dataset # NOTE: modify to evaluation dataset location if needed
63+
transform:
64+
BilinearImagenet:
65+
height: 224
66+
width: 224
67+
68+
tuning:
69+
accuracy_criterion:
70+
relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%.
71+
exit_policy:
72+
timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit.
73+
random_seed: 9527 # optional. random seed for deterministic tuning.

examples/tensorflow/image_recognition/SavedModel/quantization/ptq/mobilenet_v2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ model: # mandatory. used to specif
1717
name: mobilenet_v2
1818
framework: tensorflow # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension.
1919

20+
device: cpu # optional. default value is cpu, other value is gpu.
21+
2022
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
2123
calibration:
2224
sampling_size: 20, 50 # optional. default value is 100. used to set how many samples should be used in calibration.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#
2+
# Copyright (c) 2021 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
model: # mandatory. used to specify model specific information.
17+
name: mobilenet_v2
18+
framework: tensorflow_itex # mandatory. supported values are tensorflow, tensorflow_itex, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension.
19+
20+
device: gpu # optional. set cpu if installed intel-extension-for-tensorflow[cpu], set gpu if installed intel-extension-for-tensorflow[gpu].
21+
22+
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
23+
calibration:
24+
sampling_size: 20, 50 # optional. default value is 100. used to set how many samples should be used in calibration.
25+
dataloader:
26+
batch_size: 10
27+
dataset:
28+
ImageRecord:
29+
root: /path/to/calibration/dataset # NOTE: modify to calibration dataset location if needed
30+
transform:
31+
BilinearImagenet:
32+
height: 224
33+
width: 224
34+
model_wise: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
35+
activation:
36+
algorithm: minmax
37+
weight:
38+
granularity: per_channel
39+
40+
op_wise: {
41+
'MobilenetV2/expanded_conv/depthwise/depthwise': {
42+
'activation': {'dtype': ['fp32']},
43+
},
44+
'MobilenetV2/Conv_1/Conv2D': {
45+
'activation': {'dtype': ['fp32']},
46+
}
47+
}
48+
49+
evaluation: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
50+
accuracy: # optional. required if user doesn't provide eval_func in neural_compressor.Quantization.
51+
metric:
52+
topk: 1 # built-in metrics are topk, map, f1, allow user to register new metric.
53+
dataloader:
54+
batch_size: 32
55+
dataset:
56+
ImageRecord:
57+
root: /path/to/evaluation/dataset # NOTE: modify to evaluation dataset location if needed
58+
transform:
59+
BilinearImagenet:
60+
height: 224
61+
width: 224
62+
performance: # optional. used to benchmark performance of passing model.
63+
iteration: 100
64+
configs:
65+
cores_per_instance: 4
66+
num_of_instance: 7
67+
dataloader:
68+
batch_size: 1
69+
dataset:
70+
ImageRecord:
71+
root: /path/to/evaluation/dataset # NOTE: modify to evaluation dataset location if needed
72+
transform:
73+
BilinearImagenet:
74+
height: 224
75+
width: 224
76+
77+
tuning:
78+
accuracy_criterion:
79+
relative: 0.01 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%.
80+
exit_policy:
81+
timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit.
82+
random_seed: 9527 # optional. random seed for deterministic tuning.

0 commit comments

Comments
 (0)