Skip to content

Commit 41aca67

Browse files
NeoZhangJianyuJoeOsterericlars
authored andcommitted
Update lpot2inc ONSAM-1443 (oneapi-src#784)
* ONSAM-1414 Broken Link in Headers (oneapi-src#685) * Update Makefile * Update Makefile * Update Makefile * Update DCT.hpp * Update intrin_ftz_sample.cpp * Update merge_sort.cpp * Update intrin_double_sample.cpp * Update intrin_dot_sample.cpp * Update DCT.cpp * fix deprecation notice (oneapi-src#682) * rm plus, Fixes Issue#ONSAM-1418 * Update sample.json add install flatbuffers * Update sample.json add missed package used in TF2.5 * update according to the review comment make code be better * rename lpot to inc * fix sample.json error and use full name of INC * use full name to replace INC, format sample.json Co-authored-by: JoeOster <[email protected]> Co-authored-by: ericlars <[email protected]>
1 parent 488d2c8 commit 41aca67

File tree

13 files changed

+102
-91
lines changed

13 files changed

+102
-91
lines changed

AI-and-Analytics/Getting-Started-Samples/LPOT-Sample-for-Tensorflow/README.md renamed to AI-and-Analytics/Getting-Started-Samples/INC-Sample-for-Tensorflow/README.md

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# `Intel® Low Precision Optimization Tool (Intel® LPOT)` Sample for TensorFlow*
1+
# `Intel® Neural Compressor` Sample for TensorFlow*
22

33
## Background
44
Low-precision inference can speed up inference obviously, by converting the fp32 model to int8 or bf16 model. Intel provides Intel&reg; Deep Learning Boost technology in the Second Generation Intel&reg; Xeon&reg; Scalable Processors and newer Xeon&reg;, which supports to speed up int8 and bf16 model by hardware.
55

6-
Intel&reg; Low Precision Optimization Tool (Intel LPOT) helps the user to simplify the processing to convert the fp32 model to int8/bf16.
6+
Intel&reg; Neural Compressor helps the user to simplify the processing to convert the fp32 model to int8/bf16.
77

8-
At the same time, Intel LPOT will tune the quanization method to reduce the accuracy loss, which is a big blocker for low-precision inference.
8+
At the same time, Intel&reg; Neural Compressor will tune the quanization method to reduce the accuracy loss, which is a big blocker for low-precision inference.
99

10-
Intel LPOT is released in Intel&reg; AI Analytics Toolkit and works with Intel&reg; Optimization of TensorFlow*.
10+
Intel&reg; Neural Compressor is released in Intel&reg; AI Analytics Toolkit and works with Intel&reg; Optimization of TensorFlow*.
1111

12-
Please refer to the official website for detailed info and news: [https://github.com/intel/lp-opt-tool](https://github.com/intel/lp-opt-tool)
12+
Please refer to the official website for detailed info and news: [https://github.com/intel/neural-compressor](https://github.com/intel/neural-compressor)
1313

1414
## License
1515

@@ -19,18 +19,18 @@ Code samples are licensed under the MIT license. See
1919
Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt)
2020

2121
## Purpose
22-
This sample will show a whole process to build up a CNN model to recognize handwriting number and speed up it by Intel LPOT.
22+
This sample will show a whole process to build up a CNN model to recognize handwriting number and speed up it by Intel&reg; Neural Compressor.
2323

24-
We will learn how to train a CNN model based on Keras with TensorFlow, use Intel LPOT to quantize the model and compare the performance to understand the benefit of Intel LPOT.
24+
We will learn how to train a CNN model based on Keras with TensorFlow, use Intel&reg; Neural Compressor to quantize the model and compare the performance to understand the benefit of Intel&reg; Neural Compressor.
2525

2626
## Key Implementation Details
2727

2828
- Use Keras on TensorFlow to build and train the CNN model.
2929

3030

31-
- Define function and class for Intel LPOT to quantize the CNN model.
31+
- Define function and class for Intel&reg; Neural Compressor to quantize the CNN model.
3232

33-
The Intel LPOT can run on any Intel&reg; CPU to quantize the AI model.
33+
The Intel&reg; Neural Compressor can run on any Intel&reg; CPU to quantize the AI model.
3434

3535
The quantized AI model has better inference performance than the FP32 model on Intel CPU.
3636

@@ -47,7 +47,7 @@ We will learn how to train a CNN model based on Keras with TensorFlow, use Intel
4747
| OS | Linux* Ubuntu* 18.04
4848
| Hardware | The Second Generation Intel&reg; Xeon&reg; Scalable processor family or newer
4949
| Software | Intel&reg; oneAPI AI Analytics Toolkit 2021.1 or newer
50-
| What you will learn | How to use Intel LPOT tool to quantize the AI model based on TensorFlow and speed up the inference on Intel&reg; Xeon&reg; CPU
50+
| What you will learn | How to use Intel&reg; Neural Compressor tool to quantize the AI model based on TensorFlow and speed up the inference on Intel&reg; Xeon&reg; CPU
5151
| Time to complete | 10 minutes
5252

5353
## Running Environment
@@ -127,10 +127,10 @@ conda activate tensorflow
127127
128128
```
129129

130-
### Install Intel LPOT by Local Channel
130+
### Install Intel&reg; Neural Compressor by Local Channel
131131

132132
```
133-
conda install -c ${ONEAPI_ROOT}/conda_channel numpy pyyaml scikit-learn schema lpot -y
133+
conda install -c ${ONEAPI_ROOT}/conda_channel neural-compressor -y --offline
134134
```
135135

136136
### Install Jupyter Notebook
@@ -139,12 +139,6 @@ conda install -c ${ONEAPI_ROOT}/conda_channel numpy pyyaml scikit-learn schema l
139139
python -m pip install notebook
140140
```
141141

142-
### Install Matplotlib
143-
144-
```
145-
python -m pip install matplotlib
146-
```
147-
148142
## Running the Sample <a name="running-the-sample"></a>
149143

150144
### Startup Jupyter Notebook
@@ -178,7 +172,7 @@ conda activate /opt/intel/oneapi/intelpython/latest/envs/tensorflow
178172

179173
### Open Sample Code File
180174

181-
In a web browser, open link: **http://yyy:8888/?token=146761d9317552c43e0d6b8b6b9e1108053d465f6ca32fca**. Click 'lpot_sample_tensorflow.ipynb' to start up the sample.
175+
In a web browser, open link: **http://yyy:8888/?token=146761d9317552c43e0d6b8b6b9e1108053d465f6ca32fca**. Click 'inc_sample_tensorflow.ipynb' to start up the sample.
182176

183177
### Run
184178

AI-and-Analytics/Getting-Started-Samples/LPOT-Sample-for-Tensorflow/alexnet.yaml renamed to AI-and-Analytics/Getting-Started-Samples/INC-Sample-for-Tensorflow/alexnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: 1.0
2+
13
model:
24
name: hello_world
35
framework: tensorflow # possible values are tensorflow, mxnet and pytorch

AI-and-Analytics/Getting-Started-Samples/LPOT-Sample-for-Tensorflow/lpot_quantize_model.py renamed to AI-and-Analytics/Getting-Started-Samples/INC-Sample-for-Tensorflow/inc_quantize_model.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import sys
2+
23
try:
3-
import lpot
4+
import neural_compressor as inc
5+
print("neural_compressor version {}".format(inc.__version__))
46
except:
5-
import ilit as lpot
7+
try:
8+
import lpot as inc
9+
print("LPOT version {}".format(inc.__version__))
10+
except:
11+
import ilit as inc
12+
print("iLiT version {}".format(inc.__version__))
613

7-
if lpot.__version__ == '1.2':
14+
if inc.__version__ == '1.2':
815
print("This script doesn't support LPOT 1.2, please install LPOT 1.1, 1.2.1 or newer")
916
sys.exit(1)
1017

@@ -39,7 +46,7 @@ def __iter__(self):
3946

4047
def auto_tune(input_graph_path, yaml_config, batch_size):
4148
fp32_graph = alexnet.load_pb(input_graph_path)
42-
quan = lpot.Quantization(yaml_config)
49+
quan = inc.Quantization(yaml_config)
4350
dataloader = Dataloader(batch_size)
4451

4552
q_model = quan(

AI-and-Analytics/Getting-Started-Samples/LPOT-Sample-for-Tensorflow/lpot_sample_tensorflow.ipynb renamed to AI-and-Analytics/Getting-Started-Samples/INC-Sample-for-Tensorflow/inc_sample_tensorflow.ipynb

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Intel® Low Precision Optimization Tool (LPOT) Sample for Tensorflow"
7+
"# Intel® Neural Compressor Sample for Tensorflow"
88
]
99
},
1010
{
@@ -13,17 +13,17 @@
1313
"source": [
1414
"## Agenda\n",
1515
"- Train a CNN Model Based on Keras\n",
16-
"- Quantize Keras Model by LPOT\n",
16+
"- Quantize Keras Model by Intel® Neural Compressor\n",
1717
"- Compare Quantized Model"
1818
]
1919
},
2020
{
2121
"cell_type": "markdown",
2222
"metadata": {},
2323
"source": [
24-
"### LPOT Release and Sample \n",
24+
"### Intel® Neural Compressor Release and Sample \n",
2525
"\n",
26-
"This sample code is always updated for the LPOT release in latest oneAPI release.\n",
26+
"This sample code is always updated for the Intel® Neural Compressor release in latest oneAPI release.\n",
2727
"\n",
2828
"If you want to get the sample code for old oneAPI release, please checkout the old sample code release by git tag.\n",
2929
"\n",
@@ -51,9 +51,9 @@
5151
"source": [
5252
"Import python packages and check version.\n",
5353
"\n",
54-
"Make sure the Tensorflow is **2.2** or newer, LPOT is **not 1.2** and matplotlib are installed.\n",
54+
"Make sure the Tensorflow is **2.2** or newer, Intel® Neural Compressor is **not 1.2** and matplotlib are installed.\n",
5555
"\n",
56-
"Note, LPOT has an old name **ilit**. Following script supports to old package name **ilit**."
56+
"Note, Intel® Neural Compressor has an old names: **lpot**, **ilit**. Following script supports to old package names."
5757
]
5858
},
5959
{
@@ -64,13 +64,18 @@
6464
"source": [
6565
"import tensorflow as tf\n",
6666
"print(\"Tensorflow version {}\".format(tf.__version__))\n",
67+
"tf.compat.v1.enable_eager_execution()\n",
6768
"\n",
6869
"try:\n",
69-
" import lpot\n",
70-
" print(\"LPOT version {}\".format(lpot.__version__)) \n",
70+
" import neural_compressor as inc\n",
71+
" print(\"neural_compressor version {}\".format(inc.__version__)) \n",
7172
"except:\n",
72-
" import ilit as lpot\n",
73-
" print(\"iLiT version {}\".format(lpot.__version__)) \n",
73+
" try:\n",
74+
" import lpot as inc\n",
75+
" print(\"LPOT version {}\".format(inc.__version__)) \n",
76+
" except:\n",
77+
" import ilit as inc\n",
78+
" print(\"iLiT version {}\".format(inc.__version__)) \n",
7479
"\n",
7580
"import matplotlib.pyplot as plt\n",
7681
"import numpy as np"
@@ -87,7 +92,7 @@
8792
"cell_type": "markdown",
8893
"metadata": {},
8994
"source": [
90-
"Intel Optimized TensorFlow 2.5.0 requires to set environment variable **TF_ENABLE_MKL_NATIVE_FORMAT=0** before running LPOT quantize Fp32 model or deploying the quantized model."
95+
"Intel Optimized TensorFlow 2.5.0 and later require to set environment variable **TF_ENABLE_MKL_NATIVE_FORMAT=0** before running Intel® Neural Compressor quantize Fp32 model or deploying the quantized model."
9196
]
9297
},
9398
{
@@ -219,12 +224,12 @@
219224
"cell_type": "markdown",
220225
"metadata": {},
221226
"source": [
222-
"## Quantize FP32 Model by LPOT\n",
227+
"## Quantize FP32 Model by Intel® Neural Compressor\n",
223228
"\n",
224-
"LPOT supports to quantize the model with a validation dataset for tuning.\n",
229+
"Intel® Neural Compressor supports to quantize the model with a validation dataset for tuning.\n",
225230
"Finally, it returns an frezon quantized model based on int8.\n",
226231
"\n",
227-
"We prepare a python script \"**LPOT_quantize_model.py**\" to call LPOT to finish the all quantization job.\n",
232+
"We prepare a python script \"**inc_quantize_model.py**\" to call Intel® Neural Compressor to finish the all quantization job.\n",
228233
"Following code sample is used to explain the code.\n",
229234
"\n",
230235
"### Define Dataloader\n",
@@ -286,7 +291,7 @@
286291
"source": [
287292
"### Define Yaml File\n",
288293
"\n",
289-
"We define alexnet.yaml to save the necessary parameters for LPOT.\n",
294+
"We define alexnet.yaml to save the necessary parameters for Intel® Neural Compressor.\n",
290295
"In this case, we only need to change the input/output according to the fp32 model.\n",
291296
"\n",
292297
"In this case, the input node name is '**x**'.\n",
@@ -322,7 +327,7 @@
322327
"\n",
323328
"def auto_tune(input_graph_path, yaml_config, batch_size): \n",
324329
" fp32_graph = alexnet.load_pb(input_graph_path)\n",
325-
" quan = lpot.Quantization(yaml_config)\n",
330+
" quan = inc.Quantization(yaml_config)\n",
326331
" dataloader = Dataloader(batch_size)\n",
327332
" assert(dataloader)\n",
328333
" q_model = quan(\n",
@@ -350,23 +355,25 @@
350355
"source": [
351356
"### Call Function to Quantize the Model\n",
352357
"\n",
353-
"Show the code in \"**lpot_quantize_model.py**\"."
358+
"Show the code in \"**inc_quantize_model.py**\"."
354359
]
355360
},
356361
{
357362
"cell_type": "code",
358363
"execution_count": null,
359-
"metadata": {},
364+
"metadata": {
365+
"scrolled": true
366+
},
360367
"outputs": [],
361368
"source": [
362-
"!cat lpot_quantize_model.py"
369+
"!cat inc_quantize_model.py"
363370
]
364371
},
365372
{
366373
"cell_type": "markdown",
367374
"metadata": {},
368375
"source": [
369-
"We will execute the \"**lpot_quantize_model.py**\" to show the whole process of quantizing a model."
376+
"We will execute the \"**inc_quantize_model.py**\" to show the whole process of quantizing a model."
370377
]
371378
},
372379
{
@@ -377,7 +384,7 @@
377384
},
378385
"outputs": [],
379386
"source": [
380-
"!python lpot_quantize_model.py"
387+
"!python inc_quantize_model.py"
381388
]
382389
},
383390
{
@@ -393,11 +400,11 @@
393400
"source": [
394401
"## Compare Quantized Model\n",
395402
"\n",
396-
"We prepare a script **profiling_lpot.py** to test the performance of PB model.\n",
403+
"We prepare a script **profiling_inc.py** to test the performance of PB model.\n",
397404
"\n",
398405
"There is no correct performance data if run the code by jupyter notebook. So we run the script as process.\n",
399406
"\n",
400-
"Let learn **profiling_lpot.py**. "
407+
"Let learn **profiling_inc.py**. "
401408
]
402409
},
403410
{
@@ -406,45 +413,51 @@
406413
"metadata": {},
407414
"outputs": [],
408415
"source": [
409-
"!cat profiling_lpot.py"
416+
"!cat profiling_inc.py"
410417
]
411418
},
412419
{
413420
"cell_type": "markdown",
414421
"metadata": {},
415422
"source": [
416-
"Execute the **profiling_lpot.py** with FP32 model file:"
423+
"Execute the **profiling_inc.py** with FP32 model file:"
417424
]
418425
},
419426
{
420427
"cell_type": "code",
421428
"execution_count": null,
422-
"metadata": {},
429+
"metadata": {
430+
"scrolled": true
431+
},
423432
"outputs": [],
424433
"source": [
425-
"!python profiling_lpot.py --input-graph=./fp32_frezon.pb --omp-num-threads=4 --num-inter-threads=1 --num-intra-threads=4 --index=32"
434+
"!python profiling_inc.py --input-graph=./fp32_frezon.pb --omp-num-threads=4 --num-inter-threads=1 --num-intra-threads=4 --index=32"
426435
]
427436
},
428437
{
429438
"cell_type": "markdown",
430439
"metadata": {},
431440
"source": [
432-
"Execute the **profiling_lpot.py** with int8 model file:"
441+
"Execute the **profiling_inc.py** with int8 model file:"
433442
]
434443
},
435444
{
436445
"cell_type": "code",
437446
"execution_count": null,
438-
"metadata": {},
447+
"metadata": {
448+
"scrolled": true
449+
},
439450
"outputs": [],
440451
"source": [
441-
"!python profiling_lpot.py --input-graph=./alexnet_int8_model.pb --omp-num-threads=4 --num-inter-threads=1 --num-intra-threads=4 --index=8"
452+
"!python profiling_inc.py --input-graph=./alexnet_int8_model.pb --omp-num-threads=4 --num-inter-threads=1 --num-intra-threads=4 --index=8"
442453
]
443454
},
444455
{
445456
"cell_type": "code",
446457
"execution_count": null,
447-
"metadata": {},
458+
"metadata": {
459+
"scrolled": true
460+
},
448461
"outputs": [],
449462
"source": [
450463
"!cat 32.json\n",
@@ -570,13 +583,6 @@
570583
"- FP32 to INT8.\n",
571584
"- Intel® Deep Learning Boost speed up INT8 if your CPU is the Second Generation Intel® Xeon® Scalable Processors which supports it."
572585
]
573-
},
574-
{
575-
"cell_type": "code",
576-
"execution_count": null,
577-
"metadata": {},
578-
"outputs": [],
579-
"source": []
580586
}
581587
],
582588
"metadata": {
@@ -595,7 +601,7 @@
595601
"name": "python",
596602
"nbconvert_exporter": "python",
597603
"pygments_lexer": "ipython3",
598-
"version": "3.7.11"
604+
"version": "3.9.7"
599605
}
600606
},
601607
"nbformat": 4,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"guid": "82e7612f-2810-4d12-9c75-c17fcbb946fa",
3+
"name": "Intel® Neural Compressor Tensorflow Getting Started",
4+
"categories": ["Toolkit/oneAPI AI And Analytics/AI Getting Started Samples"],
5+
"description": "This sample illustrates how to run Intel® Neural Compressor to quantize the FP32 model trained by Keras on Tensorflow to INT8 model to speed up the inference.",
6+
"languages": [{"python":{}}],
7+
"dependencies": ["tensorflow","neural-compressor"],
8+
"os": ["linux"],
9+
"builder": ["cli"],
10+
"targetDevice": ["CPU"],
11+
"ciTests": {
12+
"linux": [
13+
{
14+
"env": ["source ${ONEAPI_ROOT}/setvars.sh --force",
15+
"conda env remove -n user_tensorflow",
16+
"conda create -n user_tensorflow -c ${ONEAPI_ROOT}/conda_channel python=`python -V| awk '{print $2}'` -y",
17+
"conda activate user_tensorflow",
18+
"conda install -n user_tensorflow -c ${ONEAPI_ROOT}/conda_channel tensorflow python-flatbuffers -y",
19+
"conda install -n user_tensorflow -c ${ONEAPI_ROOT}/conda_channel neural-compressor -y --offline",
20+
"conda install -n user_tensorflow -c ${ONEAPI_ROOT}/conda_channel lpot -y --offline",
21+
"conda install -n user_tensorflow runipy notebook -y"
22+
],
23+
"id": "neural-compressor tensorflow",
24+
"steps": [
25+
"runipy inc_sample_tensorflow.ipynb"
26+
]
27+
}
28+
]
29+
}
30+
}

0 commit comments

Comments
 (0)