Skip to content

Commit f3dd1b4

Browse files
xiaolil1tye1
andauthored
Add tutorial for INT4 (#3538)
* Add tutorial for INT4 --------- Co-authored-by: Ye Ting <[email protected]>
1 parent a1f970e commit f3dd1b4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/tutorials/features/int4.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
INT4 inference [GPU] (Experimentatal)
2+
=====================================
3+
4+
## INT4 DataType
5+
6+
INT4 is 4-bit fixed point which is used to reduce memory footprint, improve the computation efficiency and save power in Deep Learning domain.
7+
8+
INT4 data type is being used in weight only quantization in current stage. It will be converted to Float16 data type for computation.
9+
10+
## INT4 Quantization
11+
12+
On GPU, offline Weight Only Quantization (WOQ) is used for INT4 data compression. WOQ calibration tool using Generative Pre-trained Transformer models Quantization (GPT-Q) algorithm is created for improving the accuracy for INT4 weight quantization.
13+
14+
## Supported running mode
15+
16+
DNN Inference is supported with INT4 data type.
17+
18+
## Supported operators
19+
20+
INT4 Linear operator and widely used linear fusion operators in Large Langugue Models like `mm_qkv_int4`, `mm_bias_int4`, `mm_silu_int4`, `mm_resmul_int4`, `mm_bias_gelu_int4`, `mm_bias_resadd_resadd_int4` are supported.
21+
22+
## INT4 usage example
23+
24+
You can use a well quantized INT4 model to perform INT4 inference directly, or use the WOQ tool to compress the high precision model to INT4 model firstly, then to execute INT4 inference with IPEX on GPU.
25+
26+
### Weight Only Quantization Tool
27+
28+
This tool is used for applying quantization to the given model using gptq method.
29+
30+
Please note that we only support HuggingFace transformers model structure at present. GPT-J-6B is a model we intensively verified.
31+
32+
```python
33+
from transformers import GPTJForCausalLM
34+
35+
model_path = ...
36+
dataset = ...
37+
model = GPTJForCausalLM.from_pretrained(model_path)
38+
model.eval()
39+
40+
ipex.quantization._gptq(model, dataset, 'quantized_weight.pt', wbits=4)
41+
```

0 commit comments

Comments
 (0)