OPEA
/

Safetensors
mllama
4-bit precision
intel/auto-round
weiweiz1 commited on
Commit
f6cece3
·
2 Parent(s): 160666a 9a9af41

Merge branch 'main' of https://huggingface.co/cicdatopea/Llama-3.2-11B-Vision-Instruct-int4-sym-inc into main

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