Skip to content

Commit 29242c6

Browse files
jimmytweikrzeszewalexsin368ZhaoqiongZlouie-tsai
authored
Bug fixes for the 2023.1 AI Kit release (#1336)
* Intel Python Numpy Numba_dpes kNN sample (#1292) * *.py and *.ipynb files with implementation * README.md and sample.json files with documentation * License and thir party programs * Adding PyTorch Training Optimizations with AMX BF16 oneAPI sample (#1293) * add IntelPytorch Quantization code samples (#1301) * add IntelPytorch Quantization code samples * fix the spelling error in the README file * use john's README with grammar fix and title change * Rename third-party-grograms.txt to third-party-programs.txt Co-authored-by: Jimmy Wei <[email protected]> * AMX bfloat16 mixed precision learning TensorFlow Transformer sample (#1317) * [New Sample] Intel Extension for TensorFlow Getting Started (#1313) * first draft * Update README.md * remove redunant file * [New Sample] [oneDNN] Benchdnn tutorial (#1315) * New Sample: benchDNN tutorial * Update readme: new sample * Rename sample to benchdnn_tutorial * Name fix * Add files via upload (#1320) * [New Sample] oneCCL Bindings for PyTorch Getting Started (#1316) * Update README.md * [New Sample] oneCCL Bindings for PyTorch Getting Started * Update README.md * add torch-ccl version check * [New Sample] Intel Extension for PyTorch Getting Started (#1314) * add new ipex GSG notebook for dGPU * Update sample.json for expertise field * Update requirements.txt Update package versions to comply with Snyk tool * Updated title field in sample.json in TF Transformer AMX bfloat16 Mixed Precision sample to fit within character length range (#1327) * add arch checker class (#1332) * change gpu.patch to convert the code samples from cpu to gpu correctly (#1334) * Fixes for spelling in AMX bfloat16 transformer sample and printing error in python code in numpy vs numba sample (#1335) * 2023.1 ai kit itex get started example fix (#1338) * Fix the typo * Update ResNet50_Inference.ipynb * fix resnet inference demo link (#1339) --------- Co-authored-by: krzeszew <[email protected]> Co-authored-by: alexsin368 <[email protected]> Co-authored-by: ZhaoqiongZ <[email protected]> Co-authored-by: Louie Tsai <[email protected]> Co-authored-by: Orel Yehuda <[email protected]> Co-authored-by: yuning <[email protected]> Co-authored-by: Wang, Kai Lawrence <[email protected]>
1 parent 098738d commit 29242c6

File tree

10 files changed

+84
-21
lines changed

10 files changed

+84
-21
lines changed

AI-and-Analytics/Features-and-Functionality/IntelPython_Numpy_Numba_dpex_kNN/IntelPython_Numpy_Numba_dpex_kNN.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def knn_numba(X_train, y_train, X_test, k):
217217
predictions = knn_numba(X_train.values, y_train.values, X_test.values, 3)
218218
true_values = y_test.to_numpy()
219219
accuracy = np.mean(predictions == true_values)
220-
print('Numba accuracy:' + accuracy)
220+
print('Numba accuracy:', accuracy)
221221

222222

223223
# ## Numba_dpex k-NN
@@ -335,7 +335,7 @@ def knn_numba_dpex(train, train_labels, test, k, predictions, votes_to_classes_l
335335

336336
true_values = y_test.to_numpy()
337337
accuracy = np.mean(predictions_numba == true_values)
338-
print('Numba_dpex accuracy:' + accuracy)
338+
print('Numba_dpex accuracy:', accuracy)
339339

340340

341341
# In[ ]:

AI-and-Analytics/Features-and-Functionality/IntelTensorFlow_Transformer_AMX_bfloat16_MixedPrecision/IntelTensorFlow_Transformer_AMX_bfloat16_MixedPrecision.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"id": "1bdd8c5b-209e-4a7d-9d98-2b552c987039",
2121
"metadata": {},
2222
"source": [
23-
"# Tensorflow Transformer with AMX bfoat16 Mixed Precision Learning\n",
23+
"# Tensorflow Transformer with AMX bfloat16 Mixed Precision Learning\n",
2424
"\n",
2525
"In this example we will be learning Transformer block for text classification using **IMBD dataset**. And then we will modify the code to use mixed precision learning with **bfloat16**. The example based on the [Text classification with Transformer Keras code example](https://keras.io/examples/nlp/text_classification_with_transformer/).\n",
2626
"\n",

AI-and-Analytics/Features-and-Functionality/IntelTensorFlow_Transformer_AMX_bfloat16_MixedPrecision/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `TensorFlow (TF) Transformer with Intel® Advanced Matrix Extensions (Intel® AMX) bfoat16 Mixed Precision Learning`
1+
# `TensorFlow (TF) Transformer with Intel® Advanced Matrix Extensions (Intel® AMX) bfloat16 Mixed Precision Learning`
22

33
This sample code demonstrates optimizing a TensorFlow model with Intel® Advanced Matrix Extensions (Intel® AMX) using bfloat16 (Brain Floating Point) on 4th Gen Intel® Xeon® Scalable Processors (Sapphire Rapids).
44

AI-and-Analytics/Features-and-Functionality/IntelTensorFlow_Transformer_AMX_bfloat16_MixedPrecision/sample.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"guid": "60A68888-6099-414E-999B-EDC7310A01EA",
3-
"name": "TensorFlow Transformer with Advanced Matrix Extensions bfoat16 Mixed Precision Learning",
3+
"name": "TensorFlow Transformer with Advanced Matrix Extensions bfloat16 Mixed Precision Learning",
44
"categories": ["Toolkit/oneAPI AI And Analytics/AI Getting Started Samples"],
55
"description": "This sample code demonstrates optimizing a TensorFlow model with Intel® Advanced Matrix Extensions (Intel® AMX) using bfloat16 (Brain Floating Point) on Sapphire Rapids",
66
"builder": ["cli"],

AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/ResNet50_Inference.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"metadata": {},
6666
"outputs": [],
6767
"source": [
68-
"!wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/master/examples/resnet50.py"
68+
"!wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/master/examples/cpu/inference/resnet50_general_inference_script.py"
6969
]
7070
},
7171
{
@@ -111,7 +111,7 @@
111111
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
112112
"source activate pytorch\n",
113113
"echo \"########## Executing the run\"\n",
114-
"DNNL_VERBOSE=1 python resnet50.py > infer_rn50_cpu.csv\n",
114+
"DNNL_VERBOSE=1 python resnet50_general_inference_script.py > infer_rn50_cpu.csv\n",
115115
"echo \"########## Done with the run\""
116116
]
117117
},
@@ -175,7 +175,7 @@
175175
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
176176
"source activate pytorch\n",
177177
"echo \"########## Executing the run\"\n",
178-
"DNNL_VERBOSE=1 python resnet50.py > infer_rn50_gpu.csv\n",
178+
"DNNL_VERBOSE=1 python resnet50_general_inference_script_gpu.py > infer_rn50_gpu.csv\n",
179179
"echo \"########## Done with the run\""
180180
]
181181
},
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
--- resnet50.py 2023-01-24 14:40:21.570401244 +0900
2-
+++ resnet50_xpu.py 2023-01-24 14:43:31.170393594 +0900
3-
@@ -23,8 +23,8 @@
1+
diff --git a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script.py b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script_gpu.py
2+
similarity index 92%
3+
rename from AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script.py
4+
rename to AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script_gpu.py
5+
index dae594af..edd0fcb3 100644
6+
--- a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script.py
7+
+++ b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/resnet50_general_inference_script_gpu.py
8+
@@ -23,8 +23,8 @@ def main(args):
49

510
import intel_extension_for_pytorch as ipex
611

712
- model = model.to(memory_format=torch.channels_last)
813
- data = data.to(memory_format=torch.channels_last)
9-
+ model = model.to("xpu", memory_format=torch.channels_last)
10-
+ data = data.to("xpu", memory_format=torch.channels_last)
14+
+ model = model.to("xpu",memory_format=torch.channels_last)
15+
+ data = data.to("xpu",memory_format=torch.channels_last)
1116

1217
if args.dtype == 'float32':
1318
model = ipex.optimize(model, dtype=torch.float32)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
2+
index 00eb371b..a3ded045 100755
3+
--- a/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
4+
+++ b/AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_PyTorch_GettingStarted/Intel_Extension_For_PyTorch_Hello_World.py
5+
@@ -75,7 +75,7 @@ def main():
6+
3. crite: Criterion function to minimize loss
7+
'''
8+
model = TestModel()
9+
- model = model.to(memory_format=torch.channels_last)
10+
+ model = model.to("xpu", memory_format=torch.channels_last)
11+
optim = torch.optim.SGD(model.parameters(), lr=0.01)
12+
crite = nn.MSELoss(reduction='sum')
13+
14+
@@ -104,7 +104,8 @@ def main():
15+
'''
16+
model.train()
17+
for batch_index, (data, y_ans) in enumerate(trainLoader):
18+
- data = data.to(memory_format=torch.channels_last)
19+
+ data = data.to("xpu", memory_format=torch.channels_last)
20+
+ y_ans = y_ans.to("xpu", memory_format=torch.channels_last)
21+
optim.zero_grad()
22+
y = model(data)
23+
loss = crite(y, y_ans)
24+
@@ -116,7 +117,7 @@ def main():
25+
'''
26+
model.eval()
27+
for batch_index, data in enumerate(testLoader):
28+
- data = data.to(memory_format=torch.channels_last)
29+
+ data = data.to("xpu", memory_format=torch.channels_last)
30+
y = model(data)
31+
32+
if __name__ == '__main__':

AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_TensorFlow_GettingStarted/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Please follow bellow steps to setup GPU environment.
3838
3. Activate the created conda env: ```$source activate user-tensorflow-gpu ```
3939
4. Install the required packages: ```(user-tensorflow-gpu) $pip install tensorflow_hub ipykernel ```
4040
5. Deactivate conda env: ```(user-tensorflow-gpu)$conda deactivate ```
41-
6. Register the kernel to Jupyter NB: ``` $~/.conda/envs/user-tensorflowgpu/bin/python -m ipykernel install --user --name=user-tensorflow-gpu ```
41+
6. Register the kernel to Jupyter NB: ``` $~/.conda/envs/user-tensorflow-gpu/bin/python -m ipykernel install --user --name=user-tensorflow-gpu ```
4242

4343
Once users finish GPU environment setup, please do the same steps but remove "-gpu" from above steps.
4444
In the end, you will have two new conda environments which are user-tensorflow-gpu and user-tensorflow

AI-and-Analytics/Getting-Started-Samples/Intel_Extension_For_TensorFlow_GettingStarted/ResNet50_Inference.ipynb

+6-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"metadata": {},
5252
"outputs": [],
5353
"source": [
54-
"%env ONEAPI_INSTALL=~/intel/oneapi"
54+
"%env ONEAPI_INSTALL=/opt/intel/oneapi"
5555
]
5656
},
5757
{
@@ -124,7 +124,7 @@
124124
"%%writefile run.sh\n",
125125
"#!/bin/bash\n",
126126
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
127-
"source activate tensorflow-gpu\n",
127+
"source activate user-tensorflow-gpu\n",
128128
"echo \"########## Executing the run\"\n",
129129
"DNNL_VERBOSE=1 python infer_resnet50.py > infer_rn50_gpu.csv\n",
130130
"echo \"########## Done with the run\""
@@ -156,7 +156,7 @@
156156
"metadata": {},
157157
"source": [
158158
"#### Run on CPU via Intel TensorFlow\n",
159-
"Users also can run the same infer_resnet50.py on CPU with intel tensorflow or stock tensorflow."
159+
"Users also can run the same infer_resnet50.py on CPU with intel tensorflow or stock tensorflow. Please switch to the user-tensorflow jupyter kernel and execute again from prerequisites for CPU run"
160160
]
161161
},
162162
{
@@ -168,7 +168,7 @@
168168
"%%writefile run.sh\n",
169169
"#!/bin/bash\n",
170170
"source $ONEAPI_INSTALL/setvars.sh --force > /dev/null 2>&1\n",
171-
"source activate tensorflow\n",
171+
"source activate user-tensorflow\n",
172172
"echo \"########## Executing the run\"\n",
173173
"DNNL_VERBOSE=1 python infer_resnet50.py > infer_rn50_cpu.csv\n",
174174
"echo \"########## Done with the run\""
@@ -269,7 +269,7 @@
269269
"metadata": {},
270270
"outputs": [],
271271
"source": [
272-
"FdIndex=2"
272+
"FdIndex=0"
273273
]
274274
},
275275
{
@@ -325,7 +325,7 @@
325325
"metadata": {},
326326
"outputs": [],
327327
"source": [
328-
"onednn.breakdown(data,\"arch\",\"time\")"
328+
"onednn.breakdown(exec_data,\"arch\",\"time\")"
329329
]
330330
},
331331
{
@@ -382,7 +382,6 @@
382382
"metadata": {},
383383
"outputs": [],
384384
"source": [
385-
"os.chdir(initial_cwd)\n",
386385
"print('[CODE_SAMPLE_COMPLETED_SUCCESFULLY]')"
387386
]
388387
}

AI-and-Analytics/version_check.py

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@
1111
modin_found = util.find_spec("modin") is not None
1212
torchccl_found = util.find_spec("oneccl_bindings_for_pytorch") is not None
1313

14+
class arch_checker:
15+
16+
def __init__(self):
17+
cpuinfo_found = util.find_spec("cpuinfo") is not None
18+
if cpuinfo_found == False:
19+
self.arch = 'None'
20+
print("please install py-cpuinfo")
21+
return
22+
from cpuinfo import get_cpu_info
23+
info = get_cpu_info()
24+
flags = info['flags']
25+
arch_list = ['SPR', 'CPX',"ICX|CLX", "SKX", "BDW|CORE|ATOM"]
26+
isa_list = [['amx_bf16', 'amx_int8', 'amx_tile'],['avx512_bf16'],['avx512_vnni'],['avx512'],['avx2']]
27+
index = len(arch_list) - 1
28+
for flag in flags:
29+
for idx, isa_sublist in enumerate(isa_list):
30+
for isa in isa_sublist:
31+
if isa in flag:
32+
if idx < index:
33+
index = idx
34+
self.arch = arch_list[index]
35+
return
36+
1437
if tensorflow_found == True:
1538

1639
import tensorflow as tf
@@ -85,3 +108,7 @@ def get_mkl_enabled_flag():
85108
if torchccl_found == True:
86109
import oneccl_bindings_for_pytorch as torchccl
87110
print("oneCCL Bindings version {}".format(torchccl.__version__))
111+
112+
113+
checker = arch_checker()
114+
print("Arch : ", checker.arch)

0 commit comments

Comments
 (0)