OPEA
/

Safetensors
llama
4-bit precision
intel/auto-round
File size: 10,675 Bytes
a503280
 
 
 
423db67
 
a503280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6010237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a503280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6010237
 
 
 
 
 
 
 
 
a503280
 
 
 
 
 
 
 
 
6b17813
a503280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
---
license: llama3.1
datasets:
- NeelNanda/pile-10k
base_model:
- nvidia/Llama-3.1-Nemotron-70B-Instruct-HF
---
## Model Card Details

This model is an int4 model with group_size 128 and symmetric quantization of [ nvidia/Llama-3.1-Nemotron-70B-Instruct-HF ](https://huggingface.co/nvidia/Llama-3.1-Nemotron-70B-Instruct-HF) generated by [intel/auto-round](https://github.com/intel/auto-round). Load the model  with revision `77e8fae` to use AutoGPTQ format

## Inference on CPU/HPU/CUDA

HPU: docker image with Gaudi Software Stack is recommended, please refer to following script for environment setup. More details can be found in [Gaudi Guide](https://docs.habana.ai/en/latest/Installation_Guide/Bare_Metal_Fresh_OS.html#launch-docker-image-that-was-built).

```python
from auto_round import AutoHfQuantizer ##must import for auto-round format
import torch
from transformers import AutoModelForCausalLM,AutoTokenizer
quantized_model_dir = "OPEA/Llama-3.1-Nemotron-70B-Instruct-HF-int4-sym-inc"
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)

model = AutoModelForCausalLM.from_pretrained(
    quantized_model_dir,
    torch_dtype='auto',
    device_map="auto",
    ##revision="77e8fae", ##AutoGPTQ format
)

##import habana_frameworks.torch.core as htcore ## uncommnet it for HPU
##import habana_frameworks.torch.hpu as hthpu ## uncommnet it for HPU
##model = model.to(torch.bfloat16).to("hpu") ## uncommnet it for HPU

prompt = "There is a girl who likes adventure,"
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]

tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=200,  ##change this to align with the official usage
    do_sample=False  ##change this to align with the official usage
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

##prompt = "There is a girl who likes adventure,"

##INT4
"""
Sounds like an exciting starting point! Let's build upon this. Here are a few potential directions to take this character and scenario, along with some questions to help narrow down the kind of assistance you might need. Please pick any that interest you, or feel free to add your own direction:

### Directions and Questions:

#### 1. **Character Development**
- **Goal:** Enhance the character's profile.
- **Questions:**
  - What is her age?
  - What kind of adventures is she drawn to (e.g., outdoor, fantasy quests, solving mysteries, space exploration)?
  - Are there any specific skills or traits you'd like her to have (e.g., bravery, intelligence, agility)?
  - Does she have any fears or weaknesses that could make her adventures more challenging?

#### 2. **Story Outline**
- **Goal:** Create a basic story outline featuring this adventurous girl.
- **Questions:**
  - What's the setting for her adventure (e.g
"""

##BF16 
"""
Sounds like an exciting start! Let's build upon this. Here are a few potential directions to take this character and scenario, along with some questions to help narrow down the kind of assistance you might need. Please pick any that interest you, or feel free to add your own direction:

### Directions and Questions:

#### 1. **Fantasy Adventure**
- **Setting:** Perhaps in a mystical realm, a futuristic world, or a historical era.
- **Quest:** Is she on a quest for a legendary artifact, to save a kingdom, or to uncover a hidden truth?
- **Special Abilities:** Does she possess any unique skills or magical powers that aid her in her adventures?

#### 2. **Real-World Expedition**
- **Location:** Is her adventure set in the wilderness, a foreign country, or perhaps an urban jungle?
- **Challenge:** Is she facing a survival challenge, a cultural immersion, or a mystery to solve?
- **Companions:** Does she embark on
"""

##prompt = "Which one is larger, 9.11 or 9.8"
## INT4
"""
A simple comparison!

Let's break it down:

* **9.11**
	+ Whole number part: 9
	+ Decimal part: 0.11
* **9.8**
	+ Whole number part: 9
	+ Decimal part: 0.8

Since the whole number part is the same for both (9), we compare the decimal parts:

* **0.11** (from 9.11) is **less than** **0.8** (from 9.8)

Therefore, the answer is:

**9.8 is larger than 9.11**
"""

## BF16
"""A simple comparison!

Let's break it down:

* **9.11**
	+ Whole number part: 9
	+ Decimal part: 0.11
* **9.8**
	+ Whole number part: 9
	+ Decimal part: 0.8

Since the whole number part is the same for both (9), we compare the decimal parts:

* **0.11** (eleven hundredths)
* **0.8** (eight tenths, which is equivalent to 80 hundredths)

**Comparison:**
0.11 (11 hundredths) < 0.8 (80 hundredths)

**Result:**
**9.8 is larger than 9.11** """

prompt = "How many r in strawberry."
## INT4
"""
A simple but sweet question!

Let's count the "R"s in the word "strawberry":

1. S
2. T
3. R
4. A
5. W
6. B
7. E
8. R
9. R
10. Y

There are **3** "R"s in the word "strawberry".
"""
## BF16
"""
A simple but sweet question!

Let's count the "R"s in "strawberry":

1. S
2. T
3. R
4. A
5. W
6. B
7. E
8. R
9. R
10. Y

There are **3** "R"s in the word "strawberry".
"""

##prompt = "Once upon a time,"
## INT4
"""
It seems like we're about to embark on a delightful journey into the realm of storytelling! "Once upon a time" is a classic opening phrase that invites us into a world of fantasy, adventure, or perhaps a timeless tale. Let's see where this story might go! Here are a few directions we could take, and you can choose which one sparks your interest the most, or feel free to guide the story in a completely different direction:

### 1. **The Mysterious Forest**
- **Story Start**: Once upon a time, in a land far, far away, there was a mysterious forest that appeared only under the light of a full moon. The forest was said to be inhabited by magical creatures and hidden wonders. One brave adventurer, named [**Your Choice of Name**], decided to explore its secrets.

### 2. **The Lost Kingdom**
- **Story Start**: Once upon a time, beneath the waves of the ocean, there lay a lost kingdom hidden from the
"""
## BF16 
"""
It seems like we're about to embark on a delightful adventure! "Once upon a time" is a classic opening to many a tale. Let's see where the story takes us. Here are a few ways we can proceed:

1. **You Continue the Story**: Please go ahead and add the next sentence or paragraph to our tale. I'll respond with the next part, and so on.
   
2. **Choose a Theme**: If you'd like, you can give me a theme or genre for our story (e.g., fantasy, mystery, sci-fi, romance, etc.), and I'll start adding to "Once upon a time" accordingly.

3. **Provide Story Elements**: Share some elements you'd like to see in the story (e.g., specific characters, locations, magical objects, etc.), and I'll weave them into our narrative.

4. **I'll Take the Lead**: If you're feeling adventurous, I can simply continue the story in a surprise direction.
"""

```

### Evaluate the model

pip3 install lm-eval==0.4.5

```bash
 auto-round --eval --model "OPEA/Llama-3.1-Nemotron-70B-Instruct-HF-int4-sym-inc" --eval_bs 16  --tasks leaderboard_mmlu_pro,leaderboard_ifeval,lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu,gsm8k
```

| Metric                      | BF16                     | INT4                     |
| --------------------------- | ------------------------ | ------------------------ |
| avg                         | 0.6918                   | 0.6948                   |
| leaderboard_mmlu_pro  5shot | 0.5381                   | 0.5324                   |
| leaderboard_ifeval          | 0.7146=(0.7638+0.6654)/2 | 0.7491=(0.7938+0.7043)/2 |
| lambada_openai              | 0.7520                   | 0.7535                   |
| hellaswag                   | 0.6580                   | 0.6530                   |
| winogrande                  | 0.7853                   | 0.7916                   |
| piqa                        | 0.8351                   | 0.8297                   |
| truthfulqa_mc1              | 0.4517                   | 0.4517                   |
| openbookqa                  | 0.3700                   | 0.3620                   |
| boolq                       | 0.8768                   | 0.8768                   |
| arc_easy                    | 0.8611                   | 0.8586                   |
| arc_challenge               | 0.6271                   | 0.6143                   |
| gsm8k(5shot) strict match   | 0.8317                   | 0.8643                   |

## Generate the model

Here is the sample command to reproduce the model.  We found auto-round is not stable for this model, please do NOT use  --model_dtype "fp16"

```bash
auto-round  \
--model nvidia/Llama-3.1-Nemotron-70B-Instruct-HF \
--device 0 \
--group_size 128 \
--nsamples 512 \
--bits 4 \
--iter 1000 \
--disable_eval \
--low_gpu_mem_usage \
--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)