Views
No views yet
90c15db 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/Meta-Llama-3.1-70B-Instruct-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="90c15db", ##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##BF16
46"""That sounds exciting. What kind of adventures is she interested in? Is she more into outdoor activities like hiking, rock climbing, or exploring new places, or does she enjoy indoor adventures like solving puzzles, playing escape rooms, or reading fantasy novels?
47"""
48##INT4
49"""That sounds exciting. What kind of adventures is she interested in? Is she more into outdoor activities like hiking, camping, or exploring new places, or is she drawn to thrilling experiences like skydiving, bungee jumping, or trying new extreme sports?
50"""
51
52##prompt = "Which one is larger, 9.11 or 9.8"
53## INT4
54"""9.11 is larger than 9.8."""
55
56## BF16
57"""9.11 is larger than 9.8."""
58
59prompt = "How many r in strawberry."
60## INT4
61"""There are 2 R's in the word "strawberry""
62## BF16
63"""There are 2 R's in the word "strawberry"."""
64
65##prompt = "Once upon a time,"
66## INT4
67"""It sounds like you're starting a story. Would you like me to continue it, or would you like to tell me the rest of the story yourself?
68"""
69## BF16
70"""it seems like we're about to start a classic fairy tale. Would you like to continue the story, or would you like me to take over and spin a yarn for you?
71"""
72 auto-round --eval --model "OPEA/Meta-Llama-3.1-70B-Instruct-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.69565 | 0.6945 |
| leaderboard_mmlu_pro 5shot | 0.5309 | 0.5226 |
| leaderboard_ifeval | 0.7582=(0.8010+0.7153)/2 | 0.75725=(0.8010+0.7135)/2 |
| lambada_openai | 0.7557 | 0.7572 |
| hellaswag | 0.6516 | 0.6467 |
| winogrande | 0.7861 | 0.8098 |
| piqa | 0.8313 | 0.8243 |
| truthfulqa_mc1 | 0.4064 | 0.4027 |
| openbookqa | 0.3700 | 0.3620 |
| boolq | 0.8783 | 0.8761 |
| arc_easy | 0.8670 | 0.8590 |
| arc_challenge | 0.6237 | 0.6101 |
| gsm8k(5shot) strict match | 0.8886 | 0.9067 |
1auto-round \
2--model meta-llama/Meta-Llama-3.1-70B-Instruct \
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_round' \
11--output_dir "./tmp_autoround"