Views
No views yet
1from 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-405B-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)
12
13##import habana_frameworks.torch.core as htcore ## uncommnet it for HPU
14##import habana_frameworks.torch.hpu as hthpu ## uncommnet it for HPU
15##model = model.to(torch.bfloat16).to("hpu") ## uncommnet it for HPU
16
17prompt = "There is a girl who likes adventure,"
18messages = [
19 {"role": "system", "content": "You are a helpful assistant."},
20 {"role": "user", "content": prompt}
21]
22
23tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
24text = tokenizer.apply_chat_template(
25 messages,
26 tokenize=False,
27 add_generation_prompt=True
28)
29model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
30
31generated_ids = model.generate(
32 model_inputs.input_ids,
33 max_new_tokens=200, ##change this to align with the official usage
34 do_sample=False ##change this to align with the official usage
35)
36generated_ids = [
37output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
38]
39
40response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
41print(response)
42
43##prompt = "There is a girl who likes adventure,"
44##INT4
45"""That sounds exciting! Does she have a specific type of adventure in mind, such as traveling to new places, trying new activities, or exploring the outdoors? Or is she more of a spontaneous, "see where the day takes me" kind of person?
46"""
47
48##prompt = "Which one is larger, 9.11 or 9.8"
49## INT4
50"""9.11 is larger than 9.8."""
51
52prompt = "How many r in strawberry."
53## INT4
54"""There are 2 Rs in the word "strawberry".""
55
56##prompt = "Once upon a time,"
57## INT4
58"""
59...in a land far, far away... Would you like me to continue the story, or do you have a specific direction in mind?
60"""
61
62 auto-round --eval --model_name "OPEA/Meta-Llama-3.1-405B-Instruct-int4-sym-inc" --device 0,1,2,3 --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 | INT4 |
|---|---|
| avg | |
| leaderboard_mmlu_pro 5shot | |
| leaderboard_ifeval | |
| mmlu | 0.8551 |
| lambada_openai | |
| hellaswag | |
| winogrande | 0.8303 |
| piqa | |
| truthfulqa_mc1 | |
| openbookqa | |
| boolq | |
| arc_easy | |
| arc_challenge | 0.6451 |
| gsm8k(5shot) strict match |
torch._dynamo.config.cache_size_limit = 130 to the code, otherwise, OOM will occur on 80GB gpu device, ~800G CPU memory1auto-round \
2--model meta-llama/Llama-3.1-405B-Instruct \
3--device 0 \
4--group_size -1 \
5--batch_size 1 \
6--gradient_accumulate_steps 4 \
7--bits 4 \
8--disable_eval \
9--low_gpu_mem_usage \
10--format 'auto_round' \
11--output_dir "./tmp_autoround"