Commit
•
d3f2320
1
Parent(s):
7c79790
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,165 @@
|
|
1 |
-
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
- zh
|
5 |
+
license: apache-2.0
|
6 |
+
tags:
|
7 |
+
- vision
|
8 |
+
- image-text-to-text
|
9 |
+
datasets:
|
10 |
+
- lmms-lab/LLaVA-OneVision-Data
|
11 |
+
pipeline_tag: image-text-to-text
|
12 |
+
inference: false
|
13 |
+
arxiv: 2408.03326
|
14 |
+
---
|
15 |
+
# LLaVA-Onevision Model Card
|
16 |
+
|
17 |
+
![image/png](llava_onevision_arch.png)
|
18 |
+
|
19 |
+
Below is the model card of 72B LLaVA-Onevision model which is copied from the original LLaVA-Onevision model card that you can find [here](https://huggingface.co/lmms-lab/llava-onevision-qwen2-72b-si).
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
## Model details
|
24 |
+
|
25 |
+
**Model type:**
|
26 |
+
LLaVA-Onevision is an open-source multimodal LLM trained by fine-tuning Qwen2 on GPT-generated multimodal instruction-following data.
|
27 |
+
LLaVA-OneVision is the first single model that can simultaneously push the performance boundaries of open LMMs in three important computer
|
28 |
+
vision scenarios: single-image, multi-image, and video scenarios. Importantly, the design of LLaVA-OneVision allows strong transfer learning
|
29 |
+
across different modalities/scenarios, yielding new emerging capabilities. In particular, strong video understanding and cross-scenario
|
30 |
+
capabilities are demonstrated through task transfer from images to videos.
|
31 |
+
|
32 |
+
**Model date:**
|
33 |
+
LLaVA-Onevision-72b-si was added in August 2024.
|
34 |
+
|
35 |
+
**Paper or resources for more information:**
|
36 |
+
https://llava-vl.github.io/
|
37 |
+
|
38 |
+
- **Architecture:** SO400M + Qwen2
|
39 |
+
- **Pretraining Stage:** LCS-558K, 1 epoch, projector
|
40 |
+
- **Mid Stage:** A mixture of 4.7M high-quality synthetic data, 1 epoch, full model
|
41 |
+
- **Final-Image Stage:** A mixture of 3.6M single-image data, 1 epoch, full model
|
42 |
+
- **OneVision Stage:** A mixture of 1.6M single-image/multi-image/video data, 1 epoch, full model
|
43 |
+
- **Precision:** bfloat16
|
44 |
+
|
45 |
+
|
46 |
+
## How to use the model
|
47 |
+
|
48 |
+
First, make sure to have `transformers` installed from source or `transformers >= 4.45.0`.
|
49 |
+
The model supports multi-image and multi-prompt generation. Meaning that you can pass multiple images in your prompt. Make sure also to follow the correct prompt template by applyong chat template:
|
50 |
+
|
51 |
+
### Using `pipeline`:
|
52 |
+
|
53 |
+
Below we used [`"llava-hf/llava-onevision-qwen2-72b-si-hf"`](https://huggingface.co/llava-hf/llava-onevision-qwen2-72b-si-hf) checkpoint.
|
54 |
+
|
55 |
+
```python
|
56 |
+
from transformers import pipeline
|
57 |
+
from PIL import Image
|
58 |
+
import requests
|
59 |
+
|
60 |
+
model_id = "llava-hf/llava-onevision-qwen2-72b-si-hf"
|
61 |
+
pipe = pipeline("image-to-text", model=model_id)
|
62 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
|
63 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
64 |
+
|
65 |
+
# Define a chat history and use `apply_chat_template` to get correctly formatted prompt
|
66 |
+
# Each value in "content" has to be a list of dicts with types ("text", "image")
|
67 |
+
conversation = [
|
68 |
+
{
|
69 |
+
|
70 |
+
"role": "user",
|
71 |
+
"content": [
|
72 |
+
{"type": "text", "text": "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"},
|
73 |
+
{"type": "image"},
|
74 |
+
],
|
75 |
+
},
|
76 |
+
]
|
77 |
+
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
|
78 |
+
|
79 |
+
outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
|
80 |
+
print(outputs)
|
81 |
+
>>> {"generated_text": "user\n\nWhat does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud\nassistant\nLava"}
|
82 |
+
```
|
83 |
+
|
84 |
+
### Using pure `transformers`:
|
85 |
+
|
86 |
+
Below is an example script to run generation in `float16` precision on a GPU device:
|
87 |
+
|
88 |
+
```python
|
89 |
+
import requests
|
90 |
+
from PIL import Image
|
91 |
+
|
92 |
+
import torch
|
93 |
+
from transformers import AutoProcessor, LlavaNextForConditionalGeneration
|
94 |
+
|
95 |
+
model_id = "llava-hf/llava-onevision-qwen2-72b-si-hf"
|
96 |
+
model = LlavaNextForConditionalGeneration.from_pretrained(
|
97 |
+
model_id,
|
98 |
+
torch_dtype=torch.float16,
|
99 |
+
low_cpu_mem_usage=True,
|
100 |
+
).to(0)
|
101 |
+
|
102 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
103 |
+
|
104 |
+
# Define a chat history and use `apply_chat_template` to get correctly formatted prompt
|
105 |
+
# Each value in "content" has to be a list of dicts with types ("text", "image")
|
106 |
+
conversation = [
|
107 |
+
{
|
108 |
+
|
109 |
+
"role": "user",
|
110 |
+
"content": [
|
111 |
+
{"type": "text", "text": "What are these?"},
|
112 |
+
{"type": "image"},
|
113 |
+
],
|
114 |
+
},
|
115 |
+
]
|
116 |
+
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
|
117 |
+
|
118 |
+
image_file = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
119 |
+
raw_image = Image.open(requests.get(image_file, stream=True).raw)
|
120 |
+
inputs = processor(prompt, raw_image, return_tensors='pt').to(0, torch.float16)
|
121 |
+
|
122 |
+
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
|
123 |
+
print(processor.decode(output[0][2:], skip_special_tokens=True))
|
124 |
+
```
|
125 |
+
|
126 |
+
### Model optimization
|
127 |
+
|
128 |
+
#### 4-bit quantization through `bitsandbytes` library
|
129 |
+
|
130 |
+
First make sure to install `bitsandbytes`, `pip install bitsandbytes` and make sure to have access to a CUDA compatible GPU device. Simply change the snippet above with:
|
131 |
+
|
132 |
+
```diff
|
133 |
+
model = LlavaNextForConditionalGeneration.from_pretrained(
|
134 |
+
model_id,
|
135 |
+
torch_dtype=torch.float16,
|
136 |
+
low_cpu_mem_usage=True,
|
137 |
+
+ load_in_4bit=True
|
138 |
+
)
|
139 |
+
```
|
140 |
+
|
141 |
+
#### Use Flash-Attention 2 to further speed-up generation
|
142 |
+
|
143 |
+
First make sure to install `flash-attn`. Refer to the [original repository of Flash Attention](https://github.com/Dao-AILab/flash-attention) regarding that package installation. Simply change the snippet above with:
|
144 |
+
|
145 |
+
```diff
|
146 |
+
model = LlavaNextForConditionalGeneration.from_pretrained(
|
147 |
+
model_id,
|
148 |
+
torch_dtype=torch.float16,
|
149 |
+
low_cpu_mem_usage=True,
|
150 |
+
+ use_flash_attention_2=True
|
151 |
+
).to(0)
|
152 |
+
```
|
153 |
+
|
154 |
+
# Citation
|
155 |
+
```
|
156 |
+
@misc{li2024llavaonevisioneasyvisualtask,
|
157 |
+
title={LLaVA-OneVision: Easy Visual Task Transfer},
|
158 |
+
author={Bo Li and Yuanhan Zhang and Dong Guo and Renrui Zhang and Feng Li and Hao Zhang and Kaichen Zhang and Yanwei Li and Ziwei Liu and Chunyuan Li},
|
159 |
+
year={2024},
|
160 |
+
eprint={2408.03326},
|
161 |
+
archivePrefix={arXiv},
|
162 |
+
primaryClass={cs.CV},
|
163 |
+
url={https://arxiv.org/abs/2408.03326},
|
164 |
+
}
|
165 |
+
```
|