Views
No views yet
revision="7cac2d1" to use AutoGPTQ format1from auto_round import AutoRoundConfig ##must import for auto-round format
2from transformers import AutoModelForCausalLM,AutoTokenizer
3quantized_model_dir = "OPEA/Qwen2.5-0.5B-Instruct-int4-inc"
4tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
5
6model = AutoModelForCausalLM.from_pretrained(
7 quantized_model_dir,
8 torch_dtype='auto',
9 device_map="auto",
10 ##revision="7cac2d1" ##AutoGPTQ format
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
23text = tokenizer.apply_chat_template(
24 messages,
25 tokenize=False,
26 add_generation_prompt=True
27)
28model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
29
30generated_ids = model.generate(
31 model_inputs.input_ids,
32 max_new_tokens=200, ##change this to align with the official usage
33 do_sample=False ##change this to align with the official usage
34)
35generated_ids = [
36output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
37]
38
39response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
40print(response)
41
42prompt = "There is a girl who likes adventure,"
43## INT4:
44"""That's great to hear! What kind of adventure does the girl like? Is there anything specific she enjoys doing or exploring?"""
45## BF16:
46"""That's great! What kind of adventure does she like?"""
47
48
49prompt = "9.11和9.8哪个数字大"
50#INT4:
51"""
52要比较9.11和9.8的大小,我们可以按照以下步骤进行:
53
541. 首先,将两个数都转换为相同的小数形式。这里我们使用小数点前的零来方便比较。
55
56 9.11 = 9.1100 (保留两位小数)
57 9.8 = 9.8000 (保留两位小数)
58
592. 现在,比较这两个小数:
60 - 第一位:9 和 9 相等。
61 - 第二位:第一位是相同的,都是1。
62 - 第三位:第一个数是1,第二个数是8,所以8 > 1。
63
64因此,9.8大于9.11。
65
66最终答案:9.8更大。
67"""
68
69##BF16:
70"""
71要比较9.11和9.8的大小,我们可以按照以下步骤进行:
72
731. **直接比较**:将两个数相减:
74 \[
75 9.11 - 9.8 = -0.69
76 \]
77
782. **理解结果**:-0.69表示的是一个负数。因为9.11比9.8小。
79
80因此,9.8比9.11大。
81"""
82
83prompt = "Once upon a time,"
84##INT4:
85"""I'm sorry, but I don't understand what you're asking me to do or what information you want me to provide. Could you please clarify your question or provide more context? I'd be happy to help if you can give me all the information you need."""
86
87##BF16:
88"""once upon a time, there was a young girl named Lily who lived in a small village nestled between two mountains. She had always been fascinated by the natural world and dreamed of exploring it further.
89
90One day, while wandering through the forest, she stumbled upon an old, mysterious book that seemed to have been written on its pages. As she read, she realized that the book contained secrets about the hidden treasures of the earth.
91
92Lily was determined to uncover these secrets and become a true explorer. She spent hours poring over the pages, trying to understand what the author was trying to tell her.
93
94Finally, after many days of research and study, Lily discovered the location of the treasure. It lay deep within the heart of the mountain range, guarded by powerful forces that only those with the right knowledge could reach.
95
96With great excitement, Lily set out on her journey to find the treasure. She traveled for weeks, crossing treacherous terrain and battling fierce beasts along the way. But even as she"""
97
98
99prompt = "请简短介绍一下阿里巴巴公司"
100##INT4:
101"""阿里巴巴集团是全球领先的电子商务和云计算服务提供商,成立于1999年。该公司总部位于中国杭州,并在多个国家和地区设有办事处和运营中心。阿里巴巴集团的业务包括在线零售、移动支付、云计算、人工智能等。阿里巴巴集团是中国最大的电子商务平台之一,也是全球最大的电商平台之一。阿里巴巴集团还拥有众多子公司和品牌,如淘宝、天猫、菜鸟网络等。阿里巴巴集团在全球范围内拥有超过20亿活跃用户,每年销售额超过3500亿美元。阿里巴巴集团致力于通过创新和智能化技术推动商业变革,为消费者提供更便捷、更个性化的购物体验。"""
102
103##BF16:
104"""阿里巴巴集团是全球最大的电子商务平台之一,成立于1999年。该公司提供包括淘宝、天猫、阿里云等在内的众多产品和服务,是中国乃至全球领先的互联网企业之一。"""auto-round --model "OPEA/Qwen2.5-0.5B-Instruct-int4-inc" --eval --eval_bs 16 --tasks leaderboard_ifeval,leaderboard_mmlu_pro,gsm8k,lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,cmmlu,ceval-valid| Metric | BF16 | INT4 |
|---|---|---|
| Avg | 0.4229 | 0.4124 |
| leaderboard_mmlu_pro 5 shots | 0.1877 | 0.1678 |
| leaderboard_ifeval inst_level_strict_acc | 0.3501 | 0.3441 |
| leaderboard_ifeval prompt_level_strict_acc | 0.2107 | 0.2218 |
| mmlu | 0.4582 | 0.4434 |
| cmmlu | 0.5033 | 0.4542 |
| ceval-valid | 0.5327 | 0.4918 |
| gsm8k 5 shots | 0.2146 | 0.2267 |
| lambada_openai | 0.4968 | 0.4692 |
| hellaswag | 0.4062 | 0.3927 |
| winogrande | 0.5541 | 0.5675 |
| piqa | 0.7051 | 0.7035 |
| truthfulqa_mc1 | 0.2693 | 0.2815 |
| openbookqa | 0.2400 | 0.2200 |
| boolq | 0.6783 | 0.6471 |
| arc_easy | 0.6566 | 0.6595 |
| arc_challenge | 0.3020 | 0.3072 |
1auto-round \
2--model Qwen/Qwen2.5-0.5B-Instruct \
3--device 0 \
4--group_size 128 \
5--nsamples 512 \
6--bits 4 \
7--iter 1000 \
8--disable_eval \
9--model_dtype "fp16" \
10--format 'auto_gptq,auto_round' \
11--output_dir "./tmp_autoround"