cicdatopea commited on
Commit
c18be77
·
verified ·
1 Parent(s): 88e7811

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +147 -0
README.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - NeelNanda/pile-10k
4
+ ---
5
+
6
+ ## Model Details
7
+
8
+ This model is an int4 model(The vision module has also been quantized) with group_size 128 and symmetric quantization of [meta-llama/Llama-3.2-11B-Vision-Instruct](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct).
9
+
10
+ ## How To Use
11
+
12
+ ### Requirements
13
+ Please use Transformers version 4.45.0 or later
14
+ AutoRound version >= 0.4.1
15
+
16
+ ### INT4 Inference
17
+ ```python
18
+ from auto_round import AutoRoundConfig ## must import for auto-round format
19
+ import requests
20
+ import torch
21
+ from PIL import Image
22
+ from transformers import MllamaForConditionalGeneration, AutoProcessor
23
+
24
+ quantized_model_path="OPEA/Llama-3.2-11B-Vision-Instruct-qvision-int4-sym-inc"
25
+
26
+ model = MllamaForConditionalGeneration.from_pretrained(
27
+ quantized_model_path,
28
+ torch_dtype="auto",
29
+ device_map="auto"
30
+ )
31
+ processor = AutoProcessor.from_pretrained(quantized_model_path)
32
+ image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
33
+ messages = [
34
+ {"role": "user", "content": [
35
+ {"type": "image"},
36
+ {"type": "text", "text": "Please write a haiku for this one, it would be: "}
37
+ ]}
38
+ ]
39
+
40
+ # Preparation for inference
41
+ image = Image.open(requests.get(image_url, stream=True).raw)
42
+ input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
43
+ inputs = processor(
44
+ image,
45
+ input_text,
46
+ add_special_tokens=False,
47
+ return_tensors="pt"
48
+ ).to(model.device)
49
+
50
+ output = model.generate(**inputs, max_new_tokens=50)
51
+ print(processor.decode(output[0]))
52
+
53
+ ##INT4:
54
+
55
+ ## A rabbit in a coat,
56
+ ## Walking down a dirt road
57
+ ## Nature's gentle charm<|eot_id|>
58
+
59
+
60
+ ##BF16:
61
+ ## Here is a haiku for the rabbit:
62
+
63
+ ## Whiskers twitching fast
64
+ ## In a coat of blue and brown
65
+ ## Hoppy little soul<|eot_id|>
66
+
67
+ image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
68
+ messages = [
69
+ {"role": "user", "content": [
70
+ {"type": "image"},
71
+ {"type": "text", "text": "How many people are on the baseball field in the picture?"}
72
+ ]}
73
+ ]
74
+ ##INT4: There are five people on the baseball field in the picture.
75
+ ##
76
+
77
+ ##BF16: There are five people on the baseball field in the picture.
78
+ ##
79
+
80
+ image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
81
+ messages = [
82
+ {"role": "user", "content": [
83
+ {"type": "image"},
84
+ {"type": "text", "text": "Which company does this picture represent?"}
85
+ ]}
86
+ ]
87
+ ##INT4: Intel.
88
+ ##
89
+
90
+ ##BF16: This image represents Intel, a multinational semiconductor corporation headquartered in Santa Clara, California.
91
+ ##
92
+
93
+ ```
94
+
95
+ ## Evaluation the model
96
+ 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.
97
+ ```bash
98
+ auto-round-mllm --eval --model OPEA/Llama-3.2-11B-Vision-Instruct-qvision-int4-sym-inc --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result"
99
+ ```
100
+ |Metric |16bits|Llava Calib INT4|
101
+ |:-------------------|:------|:------|
102
+ |avg |66.05 | |
103
+ |MMBench_DEV_EN_V11 |52.86 |50.23 |
104
+ |ScienceQA_VAL |68.86 |68.24 |
105
+ |TextVQA_VAL |54.49 | |
106
+ |POPE |88.00 | |
107
+
108
+ ### Generate the model
109
+ Here is the sample command to reproduce the model.
110
+ ```bash
111
+ pip install auto-round
112
+ auto-round-mllm \
113
+ --model meta-llama/Llama-3.2-11B-Vision-Instruct \
114
+ --device 0 \
115
+ --group_size 128 \
116
+ --bits 4 \
117
+ --iters 200 \
118
+ --nsample 128 \
119
+ --seqlen 512 \
120
+ --quant_nontext_module \
121
+ --format 'auto_round' \
122
+ --output_dir "./tmp_autoround"
123
+ ```
124
+
125
+ ## Ethical Considerations and Limitations
126
+
127
+ 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.
128
+
129
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
130
+
131
+ ## Caveats and Recommendations
132
+
133
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
134
+
135
+ Here are a couple of useful links to learn more about Intel's AI software:
136
+
137
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
138
+
139
+ ## Disclaimer
140
+
141
+ 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.
142
+
143
+ ## Cite
144
+
145
+ @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} }
146
+
147
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)