OPEA
/

Safetensors
qwen2_vl
2-bit
gptq
File size: 6,610 Bytes
fe8ebad
 
 
 
3cc7326
 
fe8ebad
 
 
969082d
fe8ebad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969082d
fe8ebad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969082d
fe8ebad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969082d
fe8ebad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969082d
fe8ebad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
license: apache-2.0
datasets:
- NeelNanda/pile-10k
base_model:
- Qwen/Qwen2-VL-72B-Instruct
---
## Model Details

This model is an INT2 model with group_size 128 and symmetric quantization of [Qwen/Qwen2-VL-72B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-72B-Instruct) generated by [intel/auto-round](https://github.com/intel/auto-round). Load the model with revision="eac2fb6" to use AutoGPTQ format.

## How To Use


### Requirements
The code of Qwen2-VL has been in the latest Hugging face transformers and we advise you to build from source with command `pip install git+https://github.com/huggingface/transformers`, or you might encounter the following error:
```
KeyError: 'qwen2_vl'
```

### INT2 Inference
```python
from auto_round import AutoRoundConfig ## must import for auto-round format
import requests
from PIL import Image
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
quantized_model_path="OPEA/Qwen2-VL-72B-Instruct-int2-sym-inc"
model = Qwen2VLForConditionalGeneration.from_pretrained(
    quantized_model_path,
    torch_dtype="auto",
    device_map="auto",
    ##revision="eac2fb6" ##AutoGPTQ format
)
processor = AutoProcessor.from_pretrained(quantized_model_path)
image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": image_url,
            },
            {"type": "text", "text": "Describe this image."},
        ],
    }
]

# Preparation for inference
text = processor.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)
image_inputs = Image.open(requests.get(image_url, stream=True).raw)
inputs = processor(
    text=[text],
    images=image_inputs,
    padding=True,
    return_tensors="pt",
)
inputs = inputs.to(model.device)

generated_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)
generated_ids_trimmed = [
    out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
    generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False,
)
print(output_text[0])

##INT2:
## The image shows a woman and a dog sitting on a sandy beach near the ocean. The woman is wearing a plaid shirt and has long hair, while the dog is wearing a harness with a colorful pattern. They are both sitting facing each other, with the woman holding the dog's paw in her hand. The background features the ocean waves and the sun setting or rising, creating a warm and serene atmosphere. The overall scene conveys a sense of companionship and relaxation between the woman and her dog.

##BF16:
## 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.

image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": image_url,
            },
            {"type": "text", "text": "图片中的棒球场上有多少人?"},
        ],
    }
]
##INT2:
## 图片中有三个人在棒球场上。

##BF16:
## 图片中没有描述棒球场上有多少人。

image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": image_url,
            },
            {"type": "text", "text": "这张图片代表哪家公司?"},
        ],
    }
]
##INT2:
## 这张图片代表英特尔(Intel)公司。

##BF16:
## 这张图片代表的是英特尔(Intel)公司。

```


## Evaluation the model
pip3 install git+https://github.com/open-compass/VLMEvalKit.git@7de2dcb. The evaluation process may encounter errors that require changing model backend or evaluation code. Detailed instructions will be provided in a future update.
```bash
auto-round-mllm --eval --model OPEA/Qwen2-VL-7B-Instruct-INT2-sym-inc --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result"
```
|Metric             |16bits|Pile Calib INT2  |
|:-------------------|:------|:------|
|avg                |87.80 |84.80 |
|MMBench_DEV_EN_V11 |86.76 |83.13 |
|ScienceQA_VAL      |91.65 |86.17 |
|TextVQA_VAL        |85.45 |83.10 |
|POPE               |87.32 |86.78 |



### Generate the model
Here is the sample command to reproduce the model.
```bash
pip install auto-round
auto-round-mllm
--model Qwen/Qwen2-VL-72B-Instruct \
--device 0,1 \
--group_size 64 \
--bits 2 \
--iters 2000 \
--nsample 1024 \
--low_gpu_mem_usage \
--seqlen 2048 \
--model_dtype "float16" \
--format 'auto_gptq,auto_round' \
--output_dir "./tmp_autoround"
```

## Ethical Considerations and Limitations

The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.

Therefore, before deploying any applications of the model, developers should perform safety testing.

## Caveats and Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.

Here are a couple of useful links to learn more about Intel's AI software:

- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)

## Disclaimer

The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.

## Cite

@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }

[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)