File size: 4,175 Bytes
544a20c 7b2e446 e4d3b61 544a20c 7b2e446 bb7e659 7b2e446 bb7e659 30d209a bb7e659 7b2e446 bb7e659 7b2e446 bb7e659 7b2e446 544a20c 7b2e446 544a20c 7b2e446 544a20c 7b2e446 544a20c d04b01a 544a20c d04b01a 544a20c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
---
license: mit
datasets:
- NeelNanda/pile-10k
language:
- en
---
## Model Details
This model is an int4 model recipe with group_size 128 of [microsoft/Phi-3-mini-128k-instruct](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) generated by [intel/auto-round](https://github.com/intel/auto-round).
Inference of this model is compatible with AutoGPTQ's Kernel.
### Quantize the model
Here is the sample command to reproduce the model
```bash
pip install auto-round
auto-round
--model microsoft/Phi-3-mini-128k-instruct \
--device 0 \
--group_size 128 \
--bits 4 \
--iters 200 \
--nsamples 512 \
--seqlen 4096 \
--minmax_lr 0.01 \
--format 'auto_gptq' \
--gradient_accumulate_steps 2 \
--batch_size 4 \
--output_dir "./tmp_autoround" \
```
## How to use
### INT4 Inference with IPEX on Intel CPU
Install the latest [Intel Extension for Pytorch](https://github.com/intel/intel-extension-for-pytorch) and [Intel Neural Compressor](https://github.com/intel/neural-compressor)
```bash
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install intel_extension_for_pytorch
pip install neural_compressor_pt
```
```python
from transformers import AutoTokenizer
from neural_compressor.transformers import AutoModelForCausalLM
## note: use quantized model directory name below
model_name_or_path="./tmp_autoround/<model directory name>"
q_model = AutoModelForCausalLM.from_pretrained(model_name_or_path)
prompt = "Once upon a time, a little girl"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
print(tokenizer.decode(q_model.generate(**tokenizer(prompt, return_tensors="pt").to(q_model.device),max_new_tokens=50)[0]))
##Once upon a time, a little girl named Lily was playing in her backyard. She loved to explore and discover new things. One day, she stumbled upon a beautiful garden filled with colorful flowers andugh the garden, she noticed a
```
### INT4 Inference on Intel Gaudi Accelerator
docker image with Gaudi Software Stack is recommended. More details can be found in [Gaudi Guide](https://docs.habana.ai/en/latest/).
```python
import habana_frameworks.torch.core as htcore
from neural_compressor.torch.quantization import load
from transformers import AutoTokenizer, AutoModelForCausalLM
## note: use quantized model directory name below
model_name_or_path="./tmp_autoround/<model directory name>"
model = load(
model_name_or_path=model_name_or_path,
format="huggingface",
device="hpu"
)
prompt = "Once upon a time, a little girl"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
print(tokenizer.decode(model.generate(**tokenizer(prompt, return_tensors="pt").to("hpu"),max_new_tokens=50)[0]))
```
## Accuracy Result
| Metric <img width=200> | FP16 <img width=200> | INT4 <img width=200> |
| -------------- | ------ | ------ |
| Avg. | 0.6364 | 0.6300 |
| mmlu | 0.6215 | 0.6237 |
| lambada_openai | 0.6656 | 0.6433 |
| hellaswag | 0.5979 | 0.5859 |
| winogrande | 0.7324 | 0.7230 |
| piqa | 0.7884 | 0.7846 |
| truthfulqa_mc1 | 0.3574 | 0.3562 |
| openbookqa | 0.3900 | 0.3800 |
| boolq | 0.8572 | 0.8489 |
| arc_easy | 0.8119 | 0.8199 |
| arc_challenge | 0.5418 | 0.5350 |
## Caveats and Recommendations
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
Here are a couple of useful links to learn more about Intel's AI software:
* Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
## Disclaimer
The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
## Cite
@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round) |