Views
No views yet
77e8fae to use AutoGPTQ format1from auto_round import AutoHfQuantizer ##must import for auto-round format
2import torch
3from transformers import AutoModelForCausalLM,AutoTokenizer
4quantized_model_dir = "OPEA/Llama-3.1-Nemotron-70B-Instruct-HF-int4-sym-inc"
5tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
6
7model = AutoModelForCausalLM.from_pretrained(
8 quantized_model_dir,
9 torch_dtype='auto',
10 device_map="auto",
11 ##revision="77e8fae", ##AutoGPTQ format
12)
13
14##import habana_frameworks.torch.core as htcore ## uncommnet it for HPU
15##import habana_frameworks.torch.hpu as hthpu ## uncommnet it for HPU
16##model = model.to(torch.bfloat16).to("hpu") ## uncommnet it for HPU
17
18prompt = "There is a girl who likes adventure,"
19messages = [
20 {"role": "system", "content": "You are a helpful assistant."},
21 {"role": "user", "content": prompt}
22]
23
24tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
25text = tokenizer.apply_chat_template(
26 messages,
27 tokenize=False,
28 add_generation_prompt=True
29)
30model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
31
32generated_ids = model.generate(
33 model_inputs.input_ids,
34 max_new_tokens=200, ##change this to align with the official usage
35 do_sample=False ##change this to align with the official usage
36)
37generated_ids = [
38output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
39]
40
41response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
42print(response)
43
44##prompt = "There is a girl who likes adventure,"
45
46##INT4
47"""
48Sounds 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:
49
50### Directions and Questions:
51
52#### 1. **Character Development**
53- **Goal:** Enhance the character's profile.
54- **Questions:**
55 - What is her age?
56 - What kind of adventures is she drawn to (e.g., outdoor, fantasy quests, solving mysteries, space exploration)?
57 - Are there any specific skills or traits you'd like her to have (e.g., bravery, intelligence, agility)?
58 - Does she have any fears or weaknesses that could make her adventures more challenging?
59
60#### 2. **Story Outline**
61- **Goal:** Create a basic story outline featuring this adventurous girl.
62- **Questions:**
63 - What's the setting for her adventure (e.g
64"""
65
66##BF16
67"""
68Sounds 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:
69
70### Directions and Questions:
71
72#### 1. **Fantasy Adventure**
73- **Setting:** Perhaps in a mystical realm, a futuristic world, or a historical era.
74- **Quest:** Is she on a quest for a legendary artifact, to save a kingdom, or to uncover a hidden truth?
75- **Special Abilities:** Does she possess any unique skills or magical powers that aid her in her adventures?
76
77#### 2. **Real-World Expedition**
78- **Location:** Is her adventure set in the wilderness, a foreign country, or perhaps an urban jungle?
79- **Challenge:** Is she facing a survival challenge, a cultural immersion, or a mystery to solve?
80- **Companions:** Does she embark on
81"""
82
83##prompt = "Which one is larger, 9.11 or 9.8"
84## INT4
85"""
86A simple comparison!
87
88Let's break it down:
89
90* **9.11**
91 + Whole number part: 9
92 + Decimal part: 0.11
93* **9.8**
94 + Whole number part: 9
95 + Decimal part: 0.8
96
97Since the whole number part is the same for both (9), we compare the decimal parts:
98
99* **0.11** (from 9.11) is **less than** **0.8** (from 9.8)
100
101Therefore, the answer is:
102
103**9.8 is larger than 9.11**
104"""
105
106## BF16
107"""A simple comparison!
108
109Let's break it down:
110
111* **9.11**
112 + Whole number part: 9
113 + Decimal part: 0.11
114* **9.8**
115 + Whole number part: 9
116 + Decimal part: 0.8
117
118Since the whole number part is the same for both (9), we compare the decimal parts:
119
120* **0.11** (eleven hundredths)
121* **0.8** (eight tenths, which is equivalent to 80 hundredths)
122
123**Comparison:**
1240.11 (11 hundredths) < 0.8 (80 hundredths)
125
126**Result:**
127**9.8 is larger than 9.11** """
128
129prompt = "How many r in strawberry."
130## INT4
131"""
132A simple but sweet question!
133
134Let's count the "R"s in the word "strawberry":
135
1361. S
1372. T
1383. R
1394. A
1405. W
1416. B
1427. E
1438. R
1449. R
14510. Y
146
147There are **3** "R"s in the word "strawberry".
148"""
149## BF16
150"""
151A simple but sweet question!
152
153Let's count the "R"s in "strawberry":
154
1551. S
1562. T
1573. R
1584. A
1595. W
1606. B
1617. E
1628. R
1639. R
16410. Y
165
166There are **3** "R"s in the word "strawberry".
167"""
168
169##prompt = "Once upon a time,"
170## INT4
171"""
172It 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:
173
174### 1. **The Mysterious Forest**
175- **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.
176
177### 2. **The Lost Kingdom**
178- **Story Start**: Once upon a time, beneath the waves of the ocean, there lay a lost kingdom hidden from the
179"""
180## BF16
181"""
182It 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:
183
1841. **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.
185
1862. **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.
187
1883. **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.
189
1904. **I'll Take the Lead**: If you're feeling adventurous, I can simply continue the story in a surprise direction.
191"""
192 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 |
1auto-round \
2--model nvidia/Llama-3.1-Nemotron-70B-Instruct-HF \
3--device 0 \
4--group_size 128 \
5--nsamples 512 \
6--bits 4 \
7--iter 1000 \
8--disable_eval \
9--low_gpu_mem_usage \
10--format 'auto_gptq,auto_round' \
11--output_dir "./tmp_autoround"