Views
No views yet
pip install git+https://github.com/huggingface/transformers, or you might encounter the following error:KeyError: 'qwen2_vl'1import requests
2from PIL import Image
3from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
4quantized_model_path="OPEA/Qwen2-VL-72B-Instruct-int4-sym-inc"
5model = Qwen2VLForConditionalGeneration.from_pretrained(
6 quantized_model_path,
7 torch_dtype="auto",
8 device_map="auto",
9 ##revision="e67cae7" ##AutoGPTQ format
10)
11processor = AutoProcessor.from_pretrained(quantized_model_path)
12image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
13messages = [
14 {
15 "role": "user",
16 "content": [
17 {
18 "type": "image",
19 "image": image_url,
20 },
21 {"type": "text", "text": "Describe this image."},
22 ],
23 }
24]
25
26# Preparation for inference
27text = processor.apply_chat_template(
28 messages, tokenize=False, add_generation_prompt=True
29)
30image_inputs = Image.open(requests.get(image_url, stream=True).raw)
31inputs = processor(
32 text=[text],
33 images=image_inputs,
34 padding=True,
35 return_tensors="pt",
36)
37inputs = inputs.to(model.device)
38
39generated_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)
40generated_ids_trimmed = [
41 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
42]
43output_text = processor.batch_decode(
44 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False,
45)
46print(output_text[0])
47
48##INT4:
49## The image depicts a serene beach scene at sunset. A woman is sitting on the sand, facing a large dog, likely a Labrador Retriever. The woman is wearing a plaid shirt and shorts, and she appears to be smiling as she interacts with the dog. The dog is wearing a harness and is giving the woman a paw. The sun is setting in the background, casting a warm glow over the entire scene, creating a peaceful and heartwarming atmosphere. The waves of the ocean can be seen gently rolling onto the shore behind them.
50
51##BF16:
52## The image depicts a serene beach scene at sunset. A person is sitting on the sand, facing the ocean, with their back to the camera. They are wearing a plaid shirt and shorts. Next to them, a large dog, possibly a Labrador Retriever, is sitting upright, facing the person. The dog is wearing a harness. The sun is setting in the background, casting a warm glow over the entire scene, creating a peaceful and tranquil atmosphere. The waves gently lap at the shore, adding to the calm ambiance.
53
54image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
55messages = [
56 {
57 "role": "user",
58 "content": [
59 {
60 "type": "image",
61 "image": image_url,
62 },
63 {"type": "text", "text": "图片中的棒球场上有多少人?"},
64 ],
65 }
66]
67##INT4:
68## 图片中棒球场上有三个人。
69
70##BF16:
71## 图片中没有描述棒球场上有多少人。
72
73image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
74messages = [
75 {
76 "role": "user",
77 "content": [
78 {
79 "type": "image",
80 "image": image_url,
81 },
82 {"type": "text", "text": "这张图片代表哪家公司?"},
83 ],
84 }
85]
86##INT4:
87## 这张图片代表的是Intel公司。图片中的标志是Intel Inside,这是Intel公司的标志性标语和标志。
88
89##BF16:
90## 这张图片代表的是英特尔(Intel)公司。
91auto-round-mllm --eval --model OPEA/Qwen2-VL-7B-Instruct-int4-sym-inc --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result"| Metric | 16bits | Pile Calib INT4 |
|---|---|---|
| avg | 87.80 | 87.63 |
| MMBench_DEV_EN_V11 | 86.76 | 86.30 |
| ScienceQA_VAL | 91.65 | 91.23 |
| TextVQA_VAL | 85.45 | 85.39 |
| POPE | 87.32 | 87.61 |
1pip install auto-round
2auto-round-mllm
3--model Qwen/Qwen2-VL-72B-Instruct \
4--device 0,1 \
5--group_size 128 \
6--bits 4 \
7--iters 1000 \
8--nsample 512 \
9--seqlen 2048 \
10--format 'auto_gptq,auto_round' \
11--output_dir "./tmp_autoround"