OPEA
/

Safetensors
cicdatopea commited on
Commit
055ca25
1 Parent(s): 2161994

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +166 -0
README.md ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - NeelNanda/pile-10k
5
+ ---
6
+ ## Model Details
7
+
8
+ This model is an int4 model with group_size 128 and symmetric quantization of [Qwen/Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct). Load the model with revision="df7f44" to use AutoGPTQ format.
9
+
10
+ ## How To Use
11
+
12
+
13
+ ### Requirements
14
+ 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:
15
+ ```
16
+ KeyError: 'qwen2_vl'
17
+ ```
18
+
19
+ ### INT4 Inference
20
+ ```python
21
+ from auto_round import AutoRoundConfig ## must import for auto-round format
22
+ import requests
23
+ from PIL import Image
24
+ from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
25
+ quantized_model_path="OPEA/Qwen2-VL-7B-Instruct-int4-sym-inc"
26
+ model = Qwen2VLForConditionalGeneration.from_pretrained(
27
+ quantized_model_path,
28
+ torch_dtype="auto",
29
+ device_map="auto",
30
+ ##revision="df7f44" ##AutoGPTQ format
31
+ )
32
+ processor = AutoProcessor.from_pretrained(quantized_model_path)
33
+ image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
34
+ messages = [
35
+ {
36
+ "role": "user",
37
+ "content": [
38
+ {
39
+ "type": "image",
40
+ "image": image_url,
41
+ },
42
+ {"type": "text", "text": "Describe this image."},
43
+ ],
44
+ }
45
+ ]
46
+
47
+ # Preparation for inference
48
+ text = processor.apply_chat_template(
49
+ messages, tokenize=False, add_generation_prompt=True
50
+ )
51
+ image_inputs = Image.open(requests.get(image_url, stream=True).raw)
52
+ inputs = processor(
53
+ text=[text],
54
+ images=image_inputs,
55
+ padding=True,
56
+ return_tensors="pt",
57
+ )
58
+ inputs = inputs.to(model.device)
59
+
60
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
61
+ generated_ids_trimmed = [
62
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
63
+ ]
64
+ output_text = processor.batch_decode(
65
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
66
+ )
67
+ print(output_text[0])
68
+
69
+ ##INT4:
70
+ ## 'The image depicts a serene beach scene with a woman and her dog. The woman is sitting on the sand, facing the ocean, and appears to be engaging in a playful interaction with her dog. The dog, which is wearing a harness, is sitting beside her and has its front paw raised, seemingly giving a high-five to the woman. The woman is smiling and seems to be enjoying the moment. The beach is relatively empty, with gentle waves in the background, and the lighting suggests it is either early morning or late afternoon, creating a warm and peaceful atmosphere.'
71
+
72
+ ##BF16:
73
+ ## "The image depicts a serene beach scene with a woman and her dog enjoying a moment together. The woman is sitting on the sandy beach, facing the ocean, and appears to be engaging in a playful activity with her dog. She is wearing a plaid shirt and dark pants, and her hair is long and dark. The dog, which is a large breed, possibly a Labrador Retriever, is sitting in front of her, wearing a harness. The dog is extending its front paw towards the woman's hand, as if it is giving her a high-five. The woman is smiling and seems to be enjoying the interaction.\n\nThe beach is"
74
+
75
+ image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
76
+ messages = [
77
+ {
78
+ "role": "user",
79
+ "content": [
80
+ {
81
+ "type": "image",
82
+ "image": image_url,
83
+ },
84
+ {"type": "text", "text": "图片中的棒球场上有多少人?"},
85
+ ],
86
+ }
87
+ ]
88
+ ##INT4:
89
+ ## 图片中的棒球场上有五个人。
90
+
91
+ ##BF16:
92
+ ## 图片中的棒球场上有三个人。
93
+
94
+ image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
95
+ messages = [
96
+ {
97
+ "role": "user",
98
+ "content": [
99
+ {
100
+ "type": "image",
101
+ "image": image_url,
102
+ },
103
+ {"type": "text", "text": "这张图片代表哪家公司?"},
104
+ ],
105
+ }
106
+ ]
107
+ ##INT4:
108
+ ## 这张图片代表英特尔公司(Intel)。英特尔是全球领先的半导体公司,主要生产中央处理器(CPU)和其他计算机硬件。
109
+
110
+ ##BF16:
111
+ ## 这张图片代表英特尔公司(Intel)。图片中的标志是英特尔的标志,标志下方的文字“Intel Inside”表明这是英特尔的宣传标志,用于表明该产品使用了英特尔的处理器或其他技术。
112
+
113
+ ```
114
+
115
+ ## Evaluation the model
116
+ pip3 install git+https://github.com/open-compass/VLMEvalKit.git@7de2dcb
117
+ ```bash
118
+ auto-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"
119
+ ```
120
+ |Metric |16bits|Pile Calib INT4 | Llava Calib INT4 |
121
+ |:-------------------|:------|:------|:------|
122
+ |avg |83.92 |83.82 |83.42 |
123
+ |MMBench_DEV_EN_V11 |80.50 |79.64 |80.42 |
124
+ |ScienceQA_VAL |84.69 |83.88 |83.26 |
125
+ |TextVQA_VAL |84.36 |84.28 |84.11 |
126
+ |POPE |86.13 |87.57 |85.89 |
127
+
128
+ ### Generate the model
129
+ Here is the sample command to reproduce the model.
130
+ ```bash
131
+ pip install auto_round
132
+ auto-round-mllm
133
+ --model Qwen/Qwen2-VL-7B-Instruct \
134
+ --device 0 \
135
+ --group_size 128 \
136
+ --bits 4 \
137
+ --iters 1000 \
138
+ --nsample 512 \
139
+ --seqlen 2048 \
140
+ --format 'auto_gptq,auto_round' \
141
+ --output_dir "./tmp_autoround"
142
+ ```
143
+
144
+ ## Ethical Considerations and Limitations
145
+
146
+ 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.
147
+
148
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
149
+
150
+ ## Caveats and Recommendations
151
+
152
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
153
+
154
+ Here are a couple of useful links to learn more about Intel's AI software:
155
+
156
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
157
+
158
+ ## Disclaimer
159
+
160
+ 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.
161
+
162
+ ## Cite
163
+
164
+ @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} }
165
+
166
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)