File size: 5,832 Bytes
d0c66a2
 
 
0dc7dee
 
d0c66a2
 
 
 
7270565
d0c66a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7270565
 
 
 
 
914cecc
d0c66a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
914cecc
d0c66a2
914cecc
d0c66a2
 
 
 
 
 
 
 
 
914cecc
d0c66a2
 
914cecc
d0c66a2
 
 
 
 
 
914cecc
 
d0c66a2
914cecc
 
 
d0c66a2
 
914cecc
d0c66a2
914cecc
 
d0c66a2
914cecc
 
d0c66a2
 
 
914cecc
d0c66a2
914cecc
 
d0c66a2
914cecc
 
d0c66a2
 
 
 
 
 
 
 
 
8c14a41
d0c66a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dc7dee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
datasets:
- NeelNanda/pile-10k
base_model:
- fancyfeast/llama-joycaption-alpha-two-hf-llava
---

## Model Details

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="bc917a8" to use AutoGPTQ format.

## How To Use

### Requirements
Please see the [Github](https://github.com/fpgaminer/joycaption) for more details.

### INT4 Inference
```python
from auto_round import AutoRoundConfig ## must import for auto-round format
import requests
import torch
from PIL import Image
from transformers import AutoProcessor, LlavaForConditionalGeneration


quantized_model_path="OPEA/llama-joycaption-alpha-two-hf-llava-int4-sym-inc"

# Load JoyCaption INT4 Model
processor = AutoProcessor.from_pretrained(quantized_model_path)
model = LlavaForConditionalGeneration.from_pretrained(
    quantized_model_path,
    device_map="auto",
    revision="bc917a8" ## ##AutoGPTQ format
)
model.eval()

image_url = "http://images.cocodataset.org/train2017/000000116003.jpg"
content = "Write a descriptive caption for this image in a formal tone."

# Preparation for inference
with torch.no_grad():
	image = Image.open(requests.get(image_url, stream=True).raw)
	messages = [
		{
			"role": "system",
			"content": "You are a helpful image captioner.",
		},
		{
			"role": "user",
			"content": content,
		},
	]
	prompt = processor.apply_chat_template(messages, tokenize = False, add_generation_prompt = True)
	assert isinstance(prompt, str)
	inputs = processor(text=[prompt], images=[image], return_tensors="pt").to(model.device)
	inputs['pixel_values'] = inputs['pixel_values'].to(model.dtype)
    
	# Generate the captions
	generate_ids = model.generate(
		**inputs,
		max_new_tokens=50,
		do_sample=False,
		suppress_tokens=None,
		use_cache=True,
		temperature=0.6,
		top_k=None,
		top_p=0.9,
	)[0]
    
	# Trim off the prompt
	generate_ids = generate_ids[inputs['input_ids'].shape[1]:]
    
	# Decode the caption
	caption = processor.tokenizer.decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)
	caption = caption.strip()
	print(caption)


##INT4: This black-and-white photograph captures a moment of triumph on a tennis court. The central figure is a male tennis player, mid-celebration,
## with his arms raised high in victory. He is wearing a white athletic shirt and shorts, with a


##BF16: This black-and-white photograph captures a moment of triumph on a tennis court. The central figure is a male tennis player, mid-celebration,
## with his arms raised high in victory. He is wearing a white tennis shirt and shorts, with a

image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
content = "Write a descriptive caption for this image in a formal tone."

##INT4: This is a photograph capturing a moment during a baseball game. The image is taken from a high vantage point, likely from the stands,
## looking down onto the field. The main focus is on a young girl and a man standing on the grassy

##BF16: This is a photograph capturing a moment during a baseball game. The image is taken from a high angle, looking down onto the field.
## In the foreground, there is a section of the baseball field with a reddish-brown dirt infield and a well


image_url = "http://images.cocodataset.org/train2017/000000093025.jpg"
content = "Write a descriptive caption for this image in a formal tone."

##INT4: This is a photograph capturing a serene outdoor scene on a rocky mountainous terrain under a clear blue sky with scattered white clouds.
## The central focus is on a man and a sheep. The man, positioned slightly to the right of the center, is sitting

##BF16: This photograph captures a serene mountainous landscape under a bright blue sky dotted with fluffy white clouds. In the foreground,
## a man and a woman are seated on a rocky outcrop. The man, positioned on the left, is wearing a blue jacket and

```


### Generate the model
Here is the sample command to reproduce the model.
```bash
pip install auto-round
auto-round-mllm \
--model fancyfeast/llama-joycaption-alpha-two-hf-llava \
--device 0 \
--group_size 128 \
--bits 4 \
--iters 1000 \
--nsample 512 \
--seqlen 2048 \
--template default \
--model_dtype "float16" \
--format 'auto_gptq,auto_round' \
--output_dir "./tmp_autoround"
```

## Ethical Considerations and Limitations

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.

Therefore, before deploying any applications of the model, developers should perform safety testing.

## Caveats and Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.

Here are a couple of useful links to learn more about Intel's AI software:

- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)

## Disclaimer

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.

## Cite

@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} }

[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)