File size: 5,382 Bytes
7cb2129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
089c75f
7cb2129
 
 
 
 
 
a7e419e
7cb2129
 
 
a7e419e
7cb2129
 
a7e419e
089c75f
 
 
 
 
 
 
 
 
7cb2129
089c75f
 
7cb2129
089c75f
7cb2129
 
089c75f
 
 
 
 
 
7cb2129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
datasets:
- NeelNanda/pile-10k
---

## Model Details

This model is an int4 model with group_size 128 and symmetric quantization of [falcon3-3B]() generated by [intel/auto-round](https://github.com/intel/auto-round). Load the model  with revision `1839199` to use AutoGPTQ format

## How To Use
### INT4 Inference(CPU/HPU/CUDA)
```python
from auto_round import AutoRoundConfig  ##must import for auto_round format
from transformers import AutoModelForCausalLM, AutoTokenizer

quantized_model_dir = "OPEA/falcon3-3B-int4-sym-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
model = AutoModelForCausalLM.from_pretrained(
    quantized_model_dir,
    device_map="auto"
    ## revision="07a117c" ##AutoGPTQ format
)
text = "How many r in strawberry? The answer is "
inputs = tokenizer(text, return_tensors="pt", return_token_type_ids=False).to(model.device)
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50)[0]))
##INT4:
## How many r in strawberry? The answer is 10000000000000000000000000000000000000000000000000

##BF16:
## How many r in strawberry? The answer is 1.
## Q: How many r in strawberry?
## A: 1
## Q: How many r in strawberry?
## A: 1
## Q: How many r in strawberry?
## A: 1
## Q: How many r

text = "Which number is bigger, 9.8 or 9.11? The answer is"
##INT4:
## Which number is bigger, 9.8 or 9.11? The answer is 9.8.
## Q: Which number is bigger, 9.8 or 9.11?
## A: 9.8
## Q: Which number is bigger, 9.8 or 9.11?

##BF16:
## Which number is bigger, 9.8 or 9.11? The answer is 9.8.
## Q: Which number is bigger, 9.8 or 9.11?
## Options:
## - 9.8
## - 9.11
## Let's think step by step.

text = "Once upon a time,"
##INT4:
## Once upon a time, there was a little girl named Lily who loved to play in the garden. She would spend hours picking flowers, digging in the dirt, and watching the bees buzz around the colorful blooms. One day, while she was picking a bouquet of daisies, she

##BF16:
## Once upon a time, there was a little girl named Lily who loved to play with her toys. One day, she found a special box in her attic. The box was old and dusty, but when she opened it, she found a beautiful, shiny object inside. It

text = "There is a girl who likes adventure,"
##INT4:
## There is a girl who likes adventure, she likes to go on adventures with her friends. She likes to go on adventures with her friends because she likes to go on adventures with her friends. She likes to go on adventures with her friends because she likes to go on adventures with her friends.

##BF16:
## There is a girl who likes adventure, she likes to go on adventures with her friends. She likes to go on adventures with her friends because she likes to go on adventures with her friends. She likes to go on adventures with her friends because she likes to go on adventures with her friends.
```

### Evaluate the model

pip3 install lm-eval==0.4.5

```bash
auto-round --model "OPEA/falcon3-3B-int4-sym-inc" --eval --eval_bs 16  --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu
```

| Metric                      |  BF16  |  INT4  |
| :-------------------------- | :----: | :----: |
| Avg                         | 0.5816 | 0.5751 |
| mmlu                        | 0.5192 | 0.5127 |
| lambada_opeai               | 0.6109 | 0.6103 |
| hellaswage                  | 0.5357 | 0.5285 |
| winogrande                  | 0.6614 | 0.6638 |
| piqa                        | 0.7753 | 0.7715 |
| truthfulqa_mc1              | 0.2803 | 0.2742 |
| openbookqa                  | 0.3560 | 0.3360 |
| boolq                       | 0.8040 | 0.7884 |
| arc_easy                    | 0.7896 | 0.7845 |
| arc_challenge               | 0.4838 | 0.4812 |

### Generate the model

Here is the sample command to generate the model. 
```bash
auto-round  \
--model falcon3-3B \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 2000 \
--disable_eval \
--model_type float16 \
--format 'auto_gptq,auto_round' \
--output_dir "./tmp_autoround" 
```

## Ethical Considerations and Limitations

The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.

Therefore, before deploying any applications of the model, developers should perform safety testing.

## 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 and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }

[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)