cicdatopea commited on
Commit
d0c66a2
1 Parent(s): 3762b07

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +135 -0
README.md ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 [fancyfeast/llama-joycaption-alpha-two-hf-llava](https://huggingface.co/fancyfeast/llama-joycaption-alpha-two-hf-llava) generated by [intel/auto-round](https://github.com/intel/auto-round). Load the model with revision="" to use AutoGPTQ format.
9
+
10
+ ## How To Use
11
+
12
+ ### Requirements
13
+ Please see the [Github](https://github.com/fpgaminer/joycaption) for more details.
14
+
15
+ ### INT4 Inference
16
+ ```python
17
+ from auto_round import AutoRoundConfig ## must import for auto-round format
18
+ import requests
19
+ import torch
20
+ from PIL import Image
21
+ from transformers import AutoProcessor, LlavaForConditionalGeneration
22
+
23
+
24
+ quantized_model_path="OPEA/llama-joycaption-alpha-two-hf-llava-int4-sym-inc"
25
+
26
+ # Load JoyCaption INT4 Model
27
+ processor = AutoProcessor.from_pretrained(quantized_model_path)
28
+ llava_model = LlavaForConditionalGeneration.from_pretrained(quantized_model_path, device_map=0)
29
+ llava_model.eval()
30
+
31
+ image_url = "http://images.cocodataset.org/train2017/000000116003.jpg"
32
+ content = "Write a descriptive caption for this image in a formal tone."
33
+
34
+ # Preparation for inference
35
+ with torch.no_grad():
36
+ image = Image.open(requests.get(image_url, stream=True).raw)
37
+ messages = [
38
+ {
39
+ "role": "system",
40
+ "content": "You are a helpful image captioner.",
41
+ },
42
+ {
43
+ "role": "user",
44
+ "content": content,
45
+ },
46
+ ]
47
+ prompt = processor.apply_chat_template(messages, tokenize = False, add_generation_prompt = True)
48
+ assert isinstance(prompt, str)
49
+ inputs = processor(text=[prompt], images=[image], return_tensors="pt").to(model.device)
50
+ inputs['pixel_values'] = inputs['pixel_values'].to(model.dtype)
51
+
52
+ # Generate the captions
53
+ generate_ids = llava_model.generate(
54
+ **inputs,
55
+ max_new_tokens=50,
56
+ do_sample=False,
57
+ suppress_tokens=None,
58
+ use_cache=True,
59
+ temperature=0.6,
60
+ top_k=None,
61
+ top_p=0.9,
62
+ )[0]
63
+
64
+ # Trim off the prompt
65
+ generate_ids = generate_ids[inputs['input_ids'].shape[1]:]
66
+
67
+ # Decode the caption
68
+ caption = processor.tokenizer.decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)
69
+ caption = caption.strip()
70
+ print(caption)
71
+
72
+
73
+ ##INT4:
74
+
75
+ ##BF16:
76
+
77
+ image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
78
+ content = "How many people are on the baseball field in the picture?"
79
+
80
+ ##INT4:
81
+
82
+ ##BF16:
83
+
84
+
85
+ image_url = "http://images.cocodataset.org/train2017/000000093025.jpg"
86
+ content = "How many people and animals are there in the image?"
87
+
88
+ ##INT4:
89
+
90
+ ##BF16:
91
+
92
+ ```
93
+
94
+
95
+ ### Generate the model
96
+ Here is the sample command to reproduce the model.
97
+ ```bash
98
+ pip install auto-round
99
+ auto-round-mllm \
100
+ --model \
101
+ --device 0 \
102
+ --group_size 128 \
103
+ --bits 4 \
104
+ --iters 1000 \
105
+ --nsample 512 \
106
+ --seqlen 2048 \
107
+ --template default \
108
+ --model_dtype "float16" \
109
+ --format 'auto_gptq,auto_round' \
110
+ --output_dir "./tmp_autoround"
111
+ ```
112
+
113
+ ## Ethical Considerations and Limitations
114
+
115
+ 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.
116
+
117
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
118
+
119
+ ## Caveats and Recommendations
120
+
121
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
122
+
123
+ Here are a couple of useful links to learn more about Intel's AI software:
124
+
125
+ - Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
126
+
127
+ ## Disclaimer
128
+
129
+ 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.
130
+
131
+ ## Cite
132
+
133
+ @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} }
134
+
135
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)