Skip to content

Commit 82e3086

Browse files
committed
Merge remote-tracking branch 'gitlab/master-pt1.8'
2 parents cc3203a + 49f9eb2 commit 82e3086

Some content is hidden

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

63 files changed

+2401
-972
lines changed

README.md

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,73 @@
33
Intel Extension for PyTorch is a Python package to extend official PyTorch. It is designed to make the Out-of-Box user experience of PyTorch CPU better while achieving good performance. The extension also will be the PR(Pull-Request) buffer for the Intel PyTorch framework dev team. The PR buffer will not only contain functions, but also optimization (for example, take advantage of Intel's new hardware features).
44

55
- [Installation](#installation)
6-
- [Install PyTorch from Source](#install-pytorch-from-source)
6+
- [Install PyTorch](#install-pytorch)
77
- [Install Intel Extension for PyTorch from Source](#install-intel-extension-for-pytorch-from-source)
88
- [Getting Started](#getting-started)
99
- [Automatically Mix Precison](#automatically-mix-precision)
1010
- [BFloat16](#BFloat16)
1111
- [INT8](#int8-quantization)
12-
- [Contribution](#contribution)
12+
- [Supported Customized Operators](#supported-customized-operators)
13+
- [Supported Fusion Patterns](#supported-fusion-patterns)
14+
- [Tutorials](#tutorials)
15+
- [Joint blogs](#joint-blogs)
1316
- [License](#license)
1417

1518
## Installation
1619

17-
### Install PyTorch from Source
20+
### Install PyTorch
1821
|IPEX Version|PyTorch Version|
1922
|--|--|
23+
|[v1.8.0](https://github.com/intel/intel-extension-for-pytorch/tree/v1.8.0)|[v1.8.0](https://github.com/pytorch/pytorch/tree/v1.8.0 "v1.8.0")|
2024
|[v1.2.0](https://github.com/intel/intel-extension-for-pytorch/tree/v1.2.0)|[v1.7.0](https://github.com/pytorch/pytorch/tree/v1.7.0 "v1.7.0")|
2125
|[v1.1.0](https://github.com/intel/intel-extension-for-pytorch/tree/v1.1.0)|[v1.5.0-rc3](https://github.com/pytorch/pytorch/tree/v1.5.0-rc3 "v1.5.0-rc3")|
2226
|[v1.0.2](https://github.com/intel/intel-extension-for-pytorch/tree/v1.0.2)|[v1.5.0-rc3](https://github.com/pytorch/pytorch/tree/v1.5.0-rc3 "v1.5.0-rc3")|
2327
|[v1.0.1](https://github.com/intel/intel-extension-for-pytorch/tree/v1.0.1)|[v1.5.0-rc3](https://github.com/pytorch/pytorch/tree/v1.5.0-rc3 "v1.5.0-rc3")|
2428
|[v1.0.0](https://github.com/intel/intel-extension-for-pytorch/tree/v1.0.0)|[v1.5.0-rc3](https://github.com/pytorch/pytorch/tree/v1.5.0-rc3 "v1.5.0-rc3")|
2529

26-
Take Intel-Extension-for-Pytorch v1.2.0 as the example.
30+
Take Intel-Extension-for-Pytorch v1.8.0 as the example.
2731

28-
1. Get PyTorch v1.7.0 source(Refer to [PyTorch guide](https://github.com/pytorch/pytorch#get-the-pytorch-source) for more details)
32+
1. Install PyTorch from binary
33+
```bash
34+
conda install pytorch torchvision torchaudio cpuonly -c pytorch
35+
```
36+
37+
2. Install PyTorch from source
38+
39+
Get PyTorch v1.8.0 source(Refer to [PyTorch guide](https://github.com/pytorch/pytorch#get-the-pytorch-source) for more details)
2940
```bash
3041
git clone --recursive https://github.com/pytorch/pytorch
42+
```
43+
44+
Checkout PyTorch to the specified version
45+
```bash
3146
cd pytorch
32-
33-
# checkout source code to the specified version
34-
git checkout v1.7.0
35-
36-
# update submodules for the specified PyTorch version
37-
git submodule sync
38-
git submodule update --init --recursive
47+
git checkout v1.8.0
3948
```
4049

41-
2. Get the source code of Intel Extension for PyTorch
50+
Update submodules
4251
```bash
43-
git clone --recursive https://github.com/intel/intel-extension-for-pytorch
44-
cd intel-extension-for-pytorch
45-
46-
# if you are updating an existing checkout
4752
git submodule sync
4853
git submodule update --init --recursive
4954
```
5055

51-
3. Add an new backend for Intel Extension for PyTorch
56+
Build and install PyTorch (Refer to [PyTorch guide](https://github.com/pytorch/pytorch#install-pytorch) for more details)
5257
```bash
53-
# Apply git patch to pytorch code
54-
cd ${pytorch_directory}
55-
git apply ${intel_extension_for_pytorch_directory}/torch_patches/xpu-1.7.patch
56-
```
57-
58-
4. Build and install PyTorch (Refer to [PyTorch guide](https://github.com/pytorch/pytorch#install-pytorch) for more details)
59-
```bash
60-
cd ${pytorch_directory}
6158
python setup.py install
6259
```
6360

6461
### Install Intel Extension for PyTorch from Source
62+
63+
Get the source code of Intel Extension for PyTorch
64+
```bash
65+
git clone --recursive https://github.com/intel/intel-extension-for-pytorch
66+
cd intel-extension-for-pytorch
67+
68+
# if you are updating an existing checkout
69+
git submodule sync
70+
git submodule update --init --recursive
71+
```
72+
6573
Install dependencies
6674
```bash
6775
pip install lark-parser hypothesis
@@ -249,6 +257,39 @@ Supported Quantization Operators:
249257
- ```convolution + BatchNorm```
250258
251259
260+
261+
### Supported Customized Operators
262+
* ROIAlign
263+
* NMS
264+
* BatchScoreNMS
265+
* MLP
266+
* Interaction
267+
* FrozenBatchNorm2d
268+
269+
### Supported Fusion Patterns
270+
* Conv2D + ReLU
271+
* Conv2D + SUM
272+
* Conv2D + SUM + ReLU
273+
* Conv2D + Sigmoid
274+
* Conv2D + Sigmoid + MUL
275+
* Conv2D + HardTanh
276+
* Conv2D + ELU
277+
* Conv3D + ReLU
278+
* Conv3D + SUM
279+
* Conv3D + SUM + ReLU
280+
* Linear + ReLU
281+
* Linear + GELU
282+
* View + Transpose + Contiguous + View
283+
284+
## Tutorials
285+
* [Performance Tuning](tutorials/Performance_Tuning.md)
286+
287+
## Joint-blogs
288+
* [Intel and Facebook Accelerate PyTorch Performance with 3rd Gen Intel® Xeon® Processors and Intel® Deep Learning Boost’s new BFloat16 capability](https://www.intel.com/content/www/us/en/artificial-intelligence/posts/intel-facebook-boost-bfloat16.html)
289+
* [Accelerate PyTorch with IPEX and oneDNN using Intel BF16 Technology](https://medium.com/pytorch/accelerate-pytorch-with-ipex-and-onednn-using-intel-bf16-technology-dca5b8e6b58f)
290+
* [Scaling up BERT-like model Inference on modern CPU - Part 1 by IPEX launcher](https://huggingface.co/blog/bert-cpu-scaling-part-1)
291+
292+
252293
## Contribution
253294
254295
Please submit PR or issue to communicate with us or contribute code.

intel_pytorch_extension_py/ops/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .embeddingbag import embeddingbag
33
from .linear import *
44
from .pooling import *
5-
from .mlp import *
5+
from .mlp import *
66
from .jit import *
77
from .save import *
88
from .to import *
@@ -12,4 +12,5 @@
1212
from .lstm import *
1313
from .rnn import *
1414
from .gru import *
15+
from .layer_norm import *
1516
from .frozen_batch_norm import *
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import torch
2+
import _torch_ipex as core
3+
from typing import Optional
4+
5+
torch_layer_norm = torch.layer_norm
6+
7+
def _layer_norm(input, normalized_shape, weight, bias, eps, cudnn_enabled):
8+
if input.device.type != "xpu":
9+
return torch_layer_norm(input, normalized_shape, weight, bias, eps, cudnn_enabled)
10+
else:
11+
return torch.ops.torch_ipex.layer_norm(input, normalized_shape, weight, bias, eps)
12+
13+
torch.layer_norm = _layer_norm

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
lark-parser
2-
hypothesis
2+
hypothesis
3+
cmake>=3.13.0
4+
wheel>=0.36

scripts/cpu/common/aten_sig_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
| SIGNED_NUMBER
3434
| ESCAPED_STRING
3535
| CNAME
36+
| STR_LITERAL
3637
3738
array_list: array_val
3839
| array_val "," array_list
3940
array_val: NUMBER*
41+
| SIGNED_NUMBER*
4042
| CNAME
4143
return_type: "("* ret_param_list ")"*
4244
| "()"
@@ -72,6 +74,7 @@
7274
7375
ATEN_NS: "aten::"
7476
VEC: "[" (NUMBER)* "]"
77+
STR_LITERAL: "'" (CNAME)* "'"
7578
TENSOR_TYPE: "Tensor"
7679
W_SYM: "!"
7780
OPTIONAL_SYM: "?"
@@ -165,6 +168,7 @@ def get_all_return_params(self):
165168

166169
if __name__ == '__main__':
167170
sigs = [
171+
"aten::fft_fft2(Tensor self, int[1]? s=None, int[1] dim=[-2,-1], str? norm=None) -> Tensor",
168172
"aten::abs.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)",
169173
"aten::abs_(Tensor(a!) self) -> Tensor(a!)",
170174
"aten::angle(Tensor self) -> Tensor",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/python
2+
3+
import collections
4+
import os
5+
import re
6+
import string
7+
import sys
8+
9+
from .cpp_sig_parser import CPPSig
10+
from .utils import *
11+
12+
class NativeFunctions(object):
13+
def __init__(self, func_file_path):
14+
self._func_file_path = func_file_path
15+
self._native_sigs_str = []
16+
self._func_data = ''
17+
self._err_info = []
18+
19+
with open(self._func_file_path, 'r') as ff:
20+
self._func_data = ff.read()
21+
22+
for line in open(self._func_file_path, 'r'):
23+
m = re.match(r'TORCH_API *(.*); *', line)
24+
if not m:
25+
continue
26+
native_cpp_sig_str = m.group(1).replace('at::', '').replace('c10::', '').replace('Reduction::', '')
27+
# Remove ={xxx}
28+
native_cpp_sig_str = re.sub("\=\{.*?\}\,", ",", native_cpp_sig_str)
29+
# Remove =xxx,
30+
native_cpp_sig_str = re.sub("\=.*?\,", ",", native_cpp_sig_str)
31+
# Remove =),
32+
native_cpp_sig_str = re.sub("\=.*?\)", ")", native_cpp_sig_str)
33+
if not is_tensor_api(native_cpp_sig_str):
34+
continue
35+
self._native_sigs_str.append(native_cpp_sig_str)
36+
37+
def is_tensor_member_function(self, func_name):
38+
if self._func_data.find(' {}('.format(func_name)) >= 0:
39+
return False
40+
else:
41+
return True
42+
43+
def query(self, cpp_sig):
44+
cnt = 0
45+
cur_native_cpp_sig_str = ''
46+
ret_native_cpp_sig = None
47+
try:
48+
for native_sig_str_item in self._native_sigs_str:
49+
target_str = ' {}('.format(cpp_sig.def_name)
50+
if native_sig_str_item.find(target_str) >= 0:
51+
cur_native_cpp_sig_str = native_sig_str_item
52+
native_cpp_sig = CPPSig(cur_native_cpp_sig_str)
53+
params1 = [param.ipex_name if param.ipex_name != '' else param.name for param in native_cpp_sig.input_params]
54+
params2 = [param.ipex_name if param.ipex_name != '' else param.name for param in cpp_sig.input_params]
55+
if compare_params(params1, params2):
56+
cnt = cnt + 1
57+
ret_native_cpp_sig = native_cpp_sig
58+
except Exception as e:
59+
self._err_info.append((cur_native_cpp_sig_str, str(e)))
60+
print('[NativeFunctions] Error parsing "{}": {}'.format(cur_native_cpp_sig_str, e), file=sys.stderr)
61+
62+
if cnt == 0:
63+
raise Exception("Cannot the function:{} in Functions.h".format(cpp_sig.def_name))
64+
return ret_native_cpp_sig

scripts/cpu/common/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
'TensorList': 'at::TensorList',
99
'TensorOptions': 'c10::TensorOptions',
1010
'IntList': 'at::IntList',
11+
'List': 'c10::List',
12+
'Stream': 'c10::Stream',
1113
'IntArrayRef': 'at::IntArrayRef',
1214
'ArrayRef': 'c10::ArrayRef',
1315
'Layout': 'c10::Layout',
@@ -22,6 +24,18 @@
2224
'DimnameList': 'at::DimnameList', # Cover DimnameList and Dimname
2325
}
2426

27+
def is_tensor_api(func_name):
28+
m = re.search(r'\bTensor\b', func_name)
29+
return m is not None
30+
31+
def compare_params(params1, params2):
32+
if len(params1) != len(params2):
33+
return False
34+
35+
for param_item in params1:
36+
if param_item not in params2:
37+
return False
38+
return True
2539

2640
def add_ns(pt_string):
2741
splited_str = re.split(r'([^a-zA-Z0-9_])', pt_string)
@@ -53,6 +67,17 @@ def query_tensor_options(input_params):
5367
start_idx = -1
5468
return start_idx, end_idx
5569

70+
def is_out_func(fname):
71+
return fname.endswith("_out") or fname.endswith("_outf")
72+
73+
def reorder_params_idx(to_be_reordered_params, ref_params):
74+
new_idxs = {}
75+
assert len(to_be_reordered_params) == len(ref_params)
76+
for param in to_be_reordered_params:
77+
assert param in ref_params
78+
new_idxs[ref_params.index(param)] = to_be_reordered_params.index(param)
79+
return new_idxs
80+
5681
if __name__ == '__main__':
5782
sigs = [
5883
"aten::abs.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)",

0 commit comments

Comments
 (0)