Views
No views yet
3ba7fab to use AutoGPTQ format.1from auto_round import AutoHfQuantizer ##must import for auto-round format
2import torch
3from transformers import AutoModelForCausalLM,AutoTokenizer
4quantized_model_dir = "OPEA/Llama-3.3-70B-Instruct-int2-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="3ba7fab", ##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##INT2:
44## That sounds exciting! What kind of adventures does she enjoy? Is she into hiking, traveling, trying new foods, or something else? Tell me more about her!
45
46##BF16:
47## That sounds like the start of an exciting story. The girl who likes adventure, let's call her Alex, is probably always looking for her next thrill. She might enjoy activities like hiking, rock climbing, or exploring new places. Perhaps she's always been drawn to the unknown and loves to challenge herself to try new things.
48
49prompt = "Which one is larger, 9.11 or 9.8"
50##INT2:
51## 9.11 is larger than 9.8.
52
53##BF16:
54## 9.11 is larger than 9.8.
55
56prompt = "How many r in strawberry."
57##INT2:
58## There are 2 R's in the word "strawberry".
59
60##BF16:
61## There are 2 R's in the word "strawberry".
62
63prompt = "Once upon a time,"
64##INT2:
65## It seems like you're starting a story! I'd love to hear more. Please go on...
66
67##BF16:
68## ...in a far-off kingdom, where the sun dipped into the horizon and painted the sky with hues of crimson and gold, there lived a young adventurer named Sophia. She had hair as black as the night and eyes as blue as the clearest summer sky. Sophia was known throughout the land for her bravery, kindness, and insatiable curiosity.
69## What would you like to happen next in the story? Would you like Sophia to:
70## A) Embark on a quest to find a legendary treasure
71## B) Encounter a mysterious stranger with a hidden agenda
72## C) Discover a magical forest filled with ancient secrets
73## D) Something entirely different (please specify)
74## Choose your response to progress the story!add_bos_token=True to align with the origin model. Please use autogptq formatlm-eval --model hf --model_args pretrained=OPEA/Llama-3.3-70B-Instruct-int2-sym-inc,add_bos_token=True --tasks leaderboard_mmlu_pro,leaderboard_ifeval,lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu,gsm8k --batch_size 16| Metric | BF16(lm-eval==0.4.5) | W2G32 With BOS | BF16(lm-eval==0.4.7 with BOS) | WO BOS |
|---|---|---|---|---|
| avg | 0.7023 | 0.6606 | ||
| leaderboard_mmlu_pro 5shot | 0.5484 | 0.4461 | 0.4384 | |
| mmlu | 0.8195 | 0.7606 | 0.8229 | 0.7142 |
| lambada_openai | 0.7528 | 0.7413 | 0.7013 | |
| hellaswag | 0.6575 | 0.6056 | 0.5576 | |
| winogrande | 0.7869 | 0.7727 | 0.7080 | |
| piqa | 0.8303 | 0.8069 | 0.7797 | |
| truthfulqa_mc1 | 0.4284 | 0.3647 | 0.3586 | |
| openbookqa | 0.3720 | 0.3540 | 0.3000 | |
| boolq | 0.8865 | 0.8716 | 0.8339 | |
| arc_easy | 0.8624 | 0.8367 | 0.8064 | |
| leaderboard_ifeval | 0.6661=(0.7110+0.6211)/2 | 0.61235=(0.6739+0.5508)/2 | (0.5959+0.4603)/2 | |
| arc_challenge | 0.6109 | 0.5580 | 0.5188 | |
| gsm8k(5shot) strict match | 0.9083 | 0.8575 |
1auto-round \
2--model meta-llama/Llama-3.3-70B-Instruct \
3--device 0 \
4--group_size 32 \
5--nsamples 1024 \
6--bits 2 \
7--iter 2000 \
8--disable_eval \
9--model_dtype "fp16" \
10--enable_norm_bias_tuning \
11--low_gpu_mem_usage \
12--format 'auto_gptq,auto_round' \
13--output_dir "./tmp_autoround"