Skip to content

Commit f11c51b

Browse files
authored
Neural Coder PTQ Support on Intel GPU with IPEX Backend (#1461)
Signed-off-by: zehao-intel <zehao.huang@intel.com>
1 parent 047b657 commit f11c51b

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2023 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
transformation:
16+
location:
17+
- ["insert_below_dataloader_definition_line", "insert_below_model_definition_line"]
18+
content:
19+
- |-
20+
[+] from neural_compressor.config import PostTrainingQuantConfig
21+
[+] from neural_compressor.quantization import fit
22+
[+] MODEL_NAME = MODEL_NAME.to("xpu")
23+
[+] conf = PostTrainingQuantConfig(backend='ipex', quant_level=1, device="xpu")
24+
[+] MODEL_NAME = fit(model=MODEL_NAME, conf=conf, calib_dataloader=DATALOADER_NAME)
25+
[+] MODEL_NAME.save("./quantized_model")
26+
[+] MODEL_NAME.eval()
27+
order:
28+
- below:
29+
above:
30+
- pytorch_jit_script
31+
- pytorch_jit_script_ofi
32+
- pytorch_jit_trace
33+
- pytorch_jit_trace_ofi
34+
- pytorch_channels_last

neural_coder/docs/SupportMatrix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Supported Optimization Features
88
| PyTorch | [JIT (Just-In-Time) Script/Trace](https://pytorch.org/docs/stable/jit.html) & [optimize_for_inference](https://pytorch.org/docs/stable/generated/torch.jit.optimize_for_inference.html) | `pytorch_jit_script`, `pytorch_jit_trace`, `pytorch_jit_script_ofi`, `pytorch_jit_trace_ofi` |
99
| PyTorch | JIT with [TorchDynamo](https://github.com/pytorch/torchdynamo) | `pytorch_torchdynamo_jit_script`, `pytorch_torchdynamo_jit_trace`, `pytorch_torchdynamo_jit_script_ofi`, `pytorch_torchdynamo_jit_trace_ofi` |
1010
| PyTorch | [Intel Neural Compressor (INC) Mixed Precision](https://github.com/intel/neural-compressor/blob/master/docs/source/mixed_precision.md) | `pytorch_inc_bf16` |
11-
| PyTorch | [INC INT8 Static Quantization (FX/IPEX)](https://github.com/intel/neural-compressor/blob/master/docs/source/quantization.md#supported-feature-matrix) | `pytorch_inc_static_quant_fx`, `pytorch_inc_static_quant_ipex` |
11+
| PyTorch | [INC INT8 Static Quantization (FX/IPEX)](https://github.com/intel/neural-compressor/blob/master/docs/source/quantization.md#supported-feature-matrix) | `pytorch_inc_static_quant_fx`, `pytorch_inc_static_quant_ipex`, `pytorch_inc_static_quant_ipex_xpu` |
1212
| PyTorch | [INC INT8 Dynamic Quantization](https://github.com/intel/neural-compressor/blob/master/docs/source/quantization.md#supported-feature-matrix) | `pytorch_inc_dynamic_quant` |
1313
| PyTorch | [Intel Extension for PyTorch (FP32, BF16, INT8 Static/Dynamic Quantization)](https://github.com/intel/intel-extension-for-pytorch) | `pytorch_ipex_fp32`, `pytorch_ipex_bf16`, `pytorch_ipex_int8_static_quant`, `pytorch_ipex_int8_dynamic_quant` |
1414
| PyTorch | [Alibaba Blade-DISC](https://github.com/alibaba/BladeDISC) | `pytorch_aliblade` |

neural_coder/interface.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def enable(
118118
"pytorch_inc_dynamic_quant",
119119
"pytorch_inc_static_quant_fx",
120120
"pytorch_inc_static_quant_ipex",
121+
"pytorch_inc_static_quant_ipex_xpu",
121122
"pytorch_inc_bf16",
122123
"pytorch_inc_huggingface_optimum_static",
123124
"pytorch_inc_huggingface_optimum_dynamic",
@@ -210,6 +211,7 @@ def enable(
210211
or "pytorch_jit_trace_ofi" in features
211212
or "pytorch_inc_static_quant_fx" in features
212213
or "pytorch_inc_static_quant_ipex" in features
214+
or "pytorch_inc_static_quant_ipex_xpu" in features
213215
):
214216
features = ["pytorch_reclaim_inputs"] + features
215217

@@ -312,6 +314,7 @@ def enable(
312314
"pytorch_inc_dynamic_quant",
313315
"pytorch_inc_static_quant_fx",
314316
"pytorch_inc_static_quant_ipex",
317+
"pytorch_inc_static_quant_ipex_xpu",
315318
"pytorch_inc_huggingface_optimum_static",
316319
"pytorch_inc_huggingface_optimum_dynamic",
317320
"onnx_inc_static_quant_qlinear",
@@ -839,6 +842,7 @@ def superbench(
839842
["pytorch_inc_dynamic_quant"],
840843
["pytorch_inc_static_quant_fx"],
841844
["pytorch_inc_static_quant_ipex"],
845+
["pytorch_inc_static_quant_ipex_xpu"],
842846
["pytorch_inc_bf16"],
843847
]
844848
standalones_pool = []
@@ -857,12 +861,14 @@ def superbench(
857861
"pytorch_ipex_bf16",
858862
"pytorch_inc_static_quant_fx",
859863
"pytorch_inc_static_quant_ipex",
864+
"pytorch_inc_static_quant_ipex_xpu",
860865
"pytorch_inc_dynamic_quant",
861866
"pytorch_ipex_int8_static_quant",
862867
"pytorch_ipex_int8_dynamic_quant",
863868
]
864869
# features that can be standalone (either use alone or use with "backend"):
865870
standalones_pool = [
871+
"pytorch_ipex_xpu",
866872
"pytorch_mixed_precision_cpu",
867873
"pytorch_channels_last",
868874
]
@@ -906,6 +912,8 @@ def superbench(
906912
continue
907913
if "pytorch_inc_static_quant_ipex" in features and "pytorch_mixed_precision_cpu" in features:
908914
continue
915+
if "pytorch_inc_static_quant_ipex_xpu" in features and "pytorch_mixed_precision_cpu" in features:
916+
continue
909917
if "pytorch_inc_dynamic_quant" in features and "pytorch_mixed_precision_cpu" in features:
910918
continue
911919

@@ -960,6 +968,8 @@ def remove_if_have(list, element):
960968
features_display = "Intel INT8 (Static)"
961969
elif features == ["pytorch_inc_static_quant_ipex"]:
962970
features_display = "Intel INT8 (IPEX)"
971+
elif features == ["pytorch_inc_static_quant_ipex_xpu"]:
972+
features_display = "Intel INT8 (IPEX XPU)"
963973
elif features == ["pytorch_inc_bf16"]:
964974
features_display = "Intel BF16"
965975
elif features == []:
@@ -1047,6 +1057,8 @@ def remove_if_have(list, element):
10471057
best_optimization_display = "Intel INT8 (Static)"
10481058
elif list_optimization_set_top3[0] == ["pytorch_inc_static_quant_ipex"]:
10491059
best_optimization_display = "Intel INT8 (IPEX)"
1060+
elif list_optimization_set_top3[0] == ["pytorch_inc_static_quant_ipex_xpu"]:
1061+
best_optimization_display = "Intel INT8 (IPEX XPU)"
10501062
elif list_optimization_set_top3[0] == ["pytorch_inc_bf16"]:
10511063
best_optimization_display = "Intel BF16"
10521064
elif list_optimization_set_top3[0] == []:

neural_coder/launcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def execute(
5757
args.opt = "pytorch_inc_static_quant_fx"
5858
if args.approach == "static_ipex":
5959
args.opt = "pytorch_inc_static_quant_ipex"
60+
if args.approach == "static_ipex_xpu":
61+
args.opt = "pytorch_inc_static_quant_ipex_xpu"
6062
if args.approach == "dynamic":
6163
args.opt = "pytorch_inc_dynamic_quant"
6264
if args.approach == "auto":

0 commit comments

Comments
 (0)