cicdatopea commited on
Commit
27d9049
·
verified ·
1 Parent(s): a121fa0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +137 -0
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 [liuhaotian/llava-v1.5-7b](https://huggingface.co/liuhaotian/llava-v1.5-7b). Load the model with revision="a121fa0" to use AutoGPTQ format.
9
+
10
+ ## How To Use
11
+
12
+ ### Requirements
13
+
14
+ 1. Clone this repository and navigate to LLaVA folder
15
+ ```shell
16
+ git clone https://github.com/haotian-liu/LLaVA.git
17
+ cd LLaVA
18
+ ```
19
+
20
+ 2. Refine LLaVA repo
21
+ ```
22
+ vi llava/model/language_model/llava_llama.py
23
+ # add 'cache_position = None,' to line 71.
24
+ ```
25
+ 3. Install Package
26
+ ```
27
+ pip install --upgrade pip # enable PEP 660 support
28
+ pip install -e .
29
+ ```
30
+
31
+ ### INT4 Inference
32
+ ```python
33
+ from auto_round import AutoRoundConfig ## must import for auto-round format
34
+ import requests
35
+ import torch
36
+ from PIL import Image
37
+ from llava.model.builder import load_pretrained_model
38
+ from llava.train.train import preprocess, preprocess_multimodal, DataCollatorForSupervisedDataset
39
+ class DataArgs:
40
+ is_multimodal = True
41
+ mm_use_im_start_end = False
42
+
43
+ quantized_model_path="OPEA/llava-v1.5-7b-int4-sym-inc"
44
+
45
+ tokenizer, model, image_processor, _ = load_pretrained_model(
46
+ quantized_model_path,
47
+ model_base=None,
48
+ model_name=quantized_model_path,
49
+ torch_dtype="auto",
50
+ device_map="auto",
51
+ ##revision="a121fa0" ##AutoGPTQ format
52
+ )
53
+ image_url = "http://images.cocodataset.org/train2017/000000116003.jpg"
54
+ messages = [{"from": "human", "value": "What is the tennis player doing in the image?\n<image>"}]
55
+
56
+ # Preparation for inference
57
+ image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
58
+ image_input = image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0].to(model.device)
59
+ input_data = preprocess_multimodal([messages], DataArgs())
60
+ inputs = preprocess(input_data, tokenizer, has_image=(image_input is not None))
61
+
62
+ output = model.generate(inputs['input_ids'].to(model.device), images=image_input.unsqueeze(0).half(), max_new_tokens=50)
63
+ print(tokenizer.batch_decode(output))
64
+
65
+ ##INT4: The tennis player is celebrating a victory, raising his arms in the air, and holding his tennis racket.
66
+
67
+ ##BF16: The tennis player is celebrating a victory, raising his arms in the air, and holding a tennis racket.
68
+
69
+ image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
70
+ messages = [{"from": "human", "value": "How many people are on the baseball field in the picture?\n<image>"}]
71
+
72
+ ##INT4: There are three people on the baseball field in the picture.
73
+
74
+ ##BF16: There are three people on the baseball field in the picture.
75
+
76
+
77
+ image_url = "http://images.cocodataset.org/train2017/000000093025.jpg"
78
+ messages = [{"from": "human", "value": "How many people and animals are there in the image?\n<image>"}]
79
+
80
+ ##INT4: There are two people and one animal in the image.
81
+
82
+ ##BF16: There are two people and one animal in the image.
83
+
84
+ ```
85
+
86
+ ## Evaluation the model
87
+ pip3 install lmms_eval. The evaluation process may encounter errors that require changing model backend or evaluation code. Detailed instructions will be provided in a future update
88
+ ```bash
89
+ auto-round-mllm --lmms --model OPEA/llava-v1.5-7b-int4-sym-inc --tasks pope,textvqa_val,scienceqa,mmbench_en --output_dir "./eval_result" --device cuda:0
90
+ ```
91
+ |Metric |16bits|Pile Calib INT4 | Llava Calib INT4 |
92
+ |:-------------------|:------|:------|:--------------|
93
+ |avg |65.40 |65.91 | 65.79 |
94
+ |MMBench_DEV_EN_V11 |64.09 |64.43 |64.43 |
95
+ |ScienceQA_VAL |64.87 |67.20 |66.80 |
96
+ |TextVQA_VAL |45.56 |45.71 |45.81 |
97
+ |POPE |87.09 |86.31 |86.12 |
98
+
99
+ ### Generate the model
100
+ Here is the sample command to reproduce the model.
101
+ ```bash
102
+ pip install auto-round
103
+ auto-round-mllm \
104
+ --model liuhaotian/llava-v1.5-7b \
105
+ --device 0 \
106
+ --group_size 128 \
107
+ --bits 4 \
108
+ --iters 1000 \
109
+ --nsample 512 \
110
+ --seqlen 2048 \
111
+ --format 'auto_gptq,auto_round' \
112
+ --output_dir "./tmp_autoround"
113
+ ```
114
+
115
+ ## Ethical Considerations and Limitations
116
+
117
+ 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.
118
+
119
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
120
+
121
+ ## Caveats and Recommendations
122
+
123
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
124
+
125
+ Here are a couple of useful links to learn more about Intel's AI software:
126
+
127
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
128
+
129
+ ## Disclaimer
130
+
131
+ 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.
132
+
133
+ ## Cite
134
+
135
+ @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} }
136
+
137
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)