Views
No views yet
1##pip install auto-round
2from transformers import AutoModelForCausalLM, AutoTokenizer
3quantized_model_dir = "Intel/phi-2-int4-inc"
4tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
5model = AutoModelForCausalLM.from_pretrained(quantized_model_dir,
6 device_map="auto",
7 trust_remote_code=True,
8 ## revision="5973e3a" ##AutoGPTQ format
9 )
10text = "There is a girl who likes adventure,"
11inputs = tokenizer(text, return_tensors="pt", return_attention_mask=False).to(model.device)
12outputs = model.generate(**inputs, max_new_tokens=50)
13text = tokenizer.batch_decode(outputs)[0]
14print(text)
15"""
16There is a girl who likes adventure,
17She loves to explore and to venture.
18She travels to faraway lands,
19And meets people from different lands.
20She learns new languages and cultures,
21And makes friends with all kinds of people.
22She is curious and brave and
23"""1import habana_frameworks.torch.core as htcore
2import habana_frameworks.torch.hpu as hthpu
3
4from auto_round import AutoRoundConfig
5from transformers import AutoModelForCausalLM,AutoTokenizer
6
7quantized_model_dir = "Intel/phi-2-int4-inc"
8tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
9model = AutoModelForCausalLM.from_pretrained(quantized_model_dir).to('hpu').to(bfloat16)
10text = "下面我来介绍一下阿里巴巴公司,"
11inputs = tokenizer(text, return_tensors="pt").to(model.device)
12print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50, do_sample=False)[0]))
13auto-round --eval --model Intel/phi-2-int4-inc --device cuda:0 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,mmlu --batch_size 16| Metric | FP16 | INT4 |
|---|---|---|
| Avg. | 0.6131 | 0.6087 |
| mmlu | 0.5334 | 0.5417 |
| lambada_openai | 0.6243 | 0.6088 |
| hellaswag | 0.5581 | 0.5520 |
| winogrande | 0.7522 | 0.7577 |
| piqa | 0.7867 | 0.7911 |
| truthfulqa_mc1 | 0.3097 | 0.2962 |
| openbookqa | 0.4040 | 0.3900 |
| boolq | 0.8346 | 0.8333 |
| arc_easy | 0.8001 | 0.7980 |
| arc_challenge | 0.5282 | 0.5179 |
1auto-round \
2--model microsoft/phi-2 \
3--device 0 \
4--group_size 128 \
5--bits 4 \
6--iters 1000 \
7--nsamples 512 \
8--format "auto_round" \
9--output_dir "./tmp_autoround" \