OPEA
/

PyTorch
cicdatopea commited on
Commit
a41e942
1 Parent(s): c31273d

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +162 -0
README.md ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - NeelNanda/pile-10k
5
+ ---
6
+
7
+ ## Model Details
8
+
9
+ This model is an int4 model(The vision module has also been quantized) with group_size 128 and symmetric quantization of [microsoft/Phi-3.5-vision-instruct](https://huggingface.co/microsoft/Phi-3.5-vision-instruct). Load the model with revision="" to use AutoGPTQ format.
10
+ ## How To Use
11
+
12
+
13
+ ### Requirements
14
+
15
+ The current `transformers` version can be verified with: `pip list | grep transformers`.
16
+
17
+ Examples of required packages:
18
+ ```
19
+ flash_attn==2.5.8
20
+ numpy==1.24.4
21
+ Pillow==10.3.0
22
+ Requests==2.31.0
23
+ torch==2.3.0
24
+ torchvision==0.18.0
25
+ transformers==4.43.0
26
+ accelerate==0.30.0
27
+ ```
28
+
29
+
30
+ ### INT4 Inference
31
+ ```python
32
+ from auto_round import AutoRoundConfig ##must import for auto-round format
33
+ import requests
34
+ from PIL import Image
35
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
36
+
37
+ model_id = "OPEA/Phi-3.5-vision-instruct-qvision-int4-sym-inc"
38
+
39
+ model = AutoModelForCausalLM.from_pretrained(
40
+ model_id,
41
+ device_map="auto",
42
+ trust_remote_code=True,
43
+ torch_dtype="auto",
44
+ ##revision="" ##AutoGPTQ format
45
+ )
46
+ processor = AutoProcessor.from_pretrained(model_id,
47
+ trust_remote_code=True,
48
+ num_crops=4
49
+ )
50
+
51
+ image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
52
+ content = "Describe this image."
53
+ messages = [
54
+ {"role": "user",
55
+ "content": "<|image_1|>\n"+content},
56
+ ]
57
+
58
+ prompt = processor.tokenizer.apply_chat_template(
59
+ messages,
60
+ tokenize=False,
61
+ add_generation_prompt=True
62
+ )
63
+ image_inputs = Image.open(requests.get(image_url, stream=True).raw)
64
+ inputs = processor(prompt, image_inputs, return_tensors="pt").to(model.device)
65
+
66
+ generation_args = {
67
+ "max_new_tokens": 1000,
68
+ "temperature": 0.0,
69
+ "do_sample": False,
70
+ }
71
+
72
+ generate_ids = model.generate(**inputs,
73
+ eos_token_id=processor.tokenizer.eos_token_id,
74
+ **generation_args
75
+ )
76
+
77
+ # remove input tokens
78
+ generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]
79
+ response = processor.batch_decode(generate_ids,
80
+ skip_special_tokens=True,
81
+ clean_up_tokenization_spaces=False)[0]
82
+
83
+ print(response)
84
+ ##INT4:
85
+ ## The image shows a person sitting on a sandy beach with a dog. The person is wearing a plaid shirt and is holding a book, while the dog is sitting next to them, looking up at the person. The beach is near the ocean, and the sun is setting, casting a warm glow over the scene.
86
+
87
+ ##BF16:
88
+ ## The image shows a person sitting on a sandy beach with a dog. The person is wearing a plaid shirt and is holding a book, while the dog is sitting next to them, looking at the book. The beach is near the ocean, and the sun is low in the sky, suggesting it is either sunrise or sunset. The sky is clear, and the overall atmosphere is calm and serene.
89
+
90
+
91
+ image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
92
+ content = "How many people are there on the baseball field in the image?"
93
+ ##INT4:
94
+ ## There are three people on the baseball field in the image.
95
+
96
+ ##BF16:
97
+ ## There are three people on the baseball field in the image.
98
+
99
+
100
+ image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
101
+ content = "This image represents which company?"
102
+ ##INT4:
103
+ ## The image represents the company Intel, as indicated by the logo and the text 'INSIDE'.
104
+
105
+ ##BF16:
106
+ ## The image represents the company Intel, as indicated by the logo and the text 'INSIDE'.
107
+ ```
108
+
109
+
110
+ ## Evaluation the model
111
+ 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
112
+ ```bash
113
+ auto-round-mllm --eval --model OPEA/Phi-3.5-vision-instruct-qvision-int4-sym-inc --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result"
114
+ ```
115
+ |Metric |16bits|Pile Calib INT4 |
116
+ |-------------------|:------|:------|
117
+ |avg |77.64 | |
118
+ |MMBench_DEV_EN_V11 |71.83 | |
119
+ |ScienceQA_VAL |90.56 | |
120
+ |TextVQA_VAL |65.36 | |
121
+ |POPE |82.82 | |
122
+
123
+ ### Generate the model
124
+ Here is the sample command to reproduce the model.
125
+ ```bash
126
+ pip install auto-round
127
+ auto-round-mllm \
128
+ --model microsoft/Phi-3.5-vision-instruct \
129
+ --device 0 \
130
+ --group_size 128 \
131
+ --bits 4 \
132
+ --iters 200 \
133
+ --nsample 128 \
134
+ --seqlen 2048 \
135
+ --quant_nontext_module \
136
+ --format 'auto_gptq,auto_round' \
137
+ --output_dir "./tmp_autoround"
138
+ ```
139
+
140
+ ## Ethical Considerations and Limitations
141
+
142
+ 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.
143
+
144
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
145
+
146
+ ## Caveats and Recommendations
147
+
148
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
149
+
150
+ Here are a couple of useful links to learn more about Intel's AI software:
151
+
152
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
153
+
154
+ ## Disclaimer
155
+
156
+ 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.
157
+
158
+ ## Cite
159
+
160
+ @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} }
161
+
162
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)