File size: 5,313 Bytes
76bf1c6
 
 
 
 
1888e1e
 
 
 
 
 
 
 
 
 
 
 
 
fdbb37d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1888e1e
 
 
 
d455069
1888e1e
 
 
 
 
 
 
 
 
 
acc1e1c
d455069
1888e1e
 
 
 
 
 
d455069
1888e1e
d455069
1888e1e
 
 
 
d455069
1888e1e
 
 
 
d455069
 
 
 
 
 
 
 
 
 
 
 
 
 
1888e1e
 
 
 
 
 
 
 
 
 
 
 
 
 
d2f5d11
1888e1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76bf1c6
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
---
license: apache-2.0
datasets:
- NeelNanda/pile-10k
---






## Model Details

This model is an int4 model with group_size 128 of [google/gemma-2b](https://huggingface.co/google/gemma-2b) generated by [intel/auto-round](https://github.com/intel/auto-round).



### Use the model
### INT4 Inference with ITREX on CPU
Install the latest [intel-extension-for-transformers](
https://github.com/intel/intel-extension-for-transformers)
```python
from intel_extension_for_transformers.transformers import AutoModelForCausalLM
from transformers import AutoTokenizer
quantized_model_dir = "Intel/gemma-2b-int4-inc"
model = AutoModelForCausalLM.from_pretrained(quantized_model_dir,
                                             device_map="auto",
                                             trust_remote_code=False,
                                             use_neural_speed=False,
                                             )
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir, use_fast=True)
print(tokenizer.decode(model.generate(**tokenizer("There is a girl who likes adventure,", return_tensors="pt").to(model.device),max_new_tokens=50)[0]))
"""
<bos>There is a girl who likes adventure, and she is a girl who likes to travel. She is a girl who likes to explore the world and see new things. She is a girl who likes to meet new people and learn about their cultures. She is a girl who likes to take risks
"""
```


### INT4 Inference with AutoGPTQ's  kernel

```python
##pip install auto-gptq 
from transformers import AutoModelForCausalLM, AutoTokenizer
quantized_model_dir = "Intel/gemma-2b-int4-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
model = AutoModelForCausalLM.from_pretrained(quantized_model_dir,
                                             device_map="auto",
                                             trust_remote_code=False,
                                             )
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir, use_fast=True)
text = "There is a girl who likes adventure,"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50)[0]))
##<bos>There is a girl who likes adventure, and she is a girl who likes to travel. She is a girl who likes to explore the world and see new things. She is a girl who likes to meet new people and learn about their cultures. She is a girl who likes to take risks
```



### Evaluate the model 

pip3 install lm-eval==0.4.2

pip install auto-gptq 

Please note that there is a discrepancy between the baseline result and the official data, which is a known issue within the official model card community.

```bash
lm_eval --model hf --model_args pretrained="Intel/gemma-2b-int4-inc",autogptq=True,gptq_use_triton=True --device cuda:0 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu --batch_size 16
```



| Metric         | BF16   | FP16   | AutoRound v0.1 | AutoRound v0.2 |
| -------------- | ------ | ------ | -------------- | -------------- |
| Avg.           | 0.5263 | 0.5277 | 0.5235         | 0.5248         |
| mmlu           | 0.3287 | 0.3287 | 0.3297         | 0.3309         |
| lambada_openai | 0.6344 | 0.6375 | 0.6307         | 0.6379         |
| hellaswag      | 0.5273 | 0.5281 | 0.5159         | 0.5184         |
| winogrande     | 0.6504 | 0.6488 | 0.6543         | 0.6575         |
| piqa           | 0.7671 | 0.7720 | 0.7612         | 0.7606         |
| truthfulqa_mc1 | 0.2203 | 0.2203 | 0.2203         | 0.2191         |
| openbookqa     | 0.2980 | 0.3020 | 0.3000         | 0.3060         |
| boolq          | 0.6927 | 0.6936 | 0.6939         | 0.6966         |
| arc_easy       | 0.7420 | 0.7403 | 0.7353         | 0.7357         |
| arc_challenge  | 0.4019 | 0.4061 | 0.3933         | 0.3857         |



Here is the sample command to reproduce the model

```bash
git clone https://github.com/intel/auto-round
cd auto-round/examples/language-modeling
pip install -r requirements.txt
python3 main.py \
--model_name  google/gemma-2b \
--device 0 \
--group_size 128 \
--bits 4 \
--iters 400 \
--model_dtype "float16" \
--deployment_device 'gpu' \
--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)
* Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)

## 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.