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center">
|
7 |
+
<img src="https://s11.ax1x.com/2023/12/28/piqvDMV.png" width="250" style="margin-bottom: 0.2;"/>
|
8 |
+
<p>
|
9 |
+
<h2 align="center"> <a href="https://arxiv.org/abs/2401.15947">MoE-LLaVA: Mixture of Experts for Large Vision-Language Models</a></h2>
|
10 |
+
<h5 align="center"> If you like our project, please give us a star โญ on GitHub for latest update. </h2>
|
11 |
+
|
12 |
+
<h5 align="center">
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
</h5>
|
17 |
+
|
18 |
+
|
19 |
+
## ๐ฐ News
|
20 |
+
* **[2024.01.30]** The [paper](https://arxiv.org/abs/2401.15947) is released.
|
21 |
+
* **[2024.01.27]** ๐ค[Hugging Face demo](https://huggingface.co/spaces/LanguageBind/MoE-LLaVA) and **all codes & datasets** are available now! Welcome to **watch** ๐ this repository for the latest updates.
|
22 |
+
|
23 |
+
## ๐ฎ Highlights
|
24 |
+
|
25 |
+
MoE-LLaVA shows excellent performance in multi-modal learning.
|
26 |
+
|
27 |
+
### ๐ฅ High performance, but with fewer parameters
|
28 |
+
- with just **3B sparsely activated parameters**, MoE-LLaVA demonstrates performance comparable to the LLaVA-1.5-7B on various visual understanding datasets and even surpasses the LLaVA-1.5-13B in object hallucination benchmarks.
|
29 |
+
|
30 |
+
|
31 |
+
### ๐ Simple baseline, learning multi-modal interactions with sparse pathways.
|
32 |
+
- With the addition of **a simple MoE tuning stage**, we can complete the training of MoE-LLaVA on **8 V100 GPUs** within 2 days.
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
## ๐ค Demo
|
37 |
+
|
38 |
+
### Gradio Web UI
|
39 |
+
|
40 |
+
Highly recommend trying out our web demo by the following command, which incorporates all features currently supported by MoE-LLaVA. We also provide [online demo](https://huggingface.co/spaces/LanguageBind/MoE-LLaVA) in Huggingface Spaces.
|
41 |
+
```bash
|
42 |
+
# use phi2
|
43 |
+
deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e"
|
44 |
+
# use qwen
|
45 |
+
deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e"
|
46 |
+
# use stablelm
|
47 |
+
deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-StableLM-1.6B-4e"
|
48 |
+
```
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
### CLI Inference
|
53 |
+
|
54 |
+
```bash
|
55 |
+
# use phi2
|
56 |
+
deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e" --image-file "image.jpg"
|
57 |
+
# use qwen
|
58 |
+
deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e" --image-file "image.jpg"
|
59 |
+
# use stablelm
|
60 |
+
deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-StableLM-1.6B-4e" --image-file "image.jpg"
|
61 |
+
```
|
62 |
+
|
63 |
+
|
64 |
+
## ๐ณ Model Zoo
|
65 |
+
|
66 |
+
| Model | LLM | Checkpoint | Avg | VQAv2 | GQA | VizWiz | SQA | T-VQA | POPE | MM-Bench| LLaVA-Bench-Wild | MM-Vet |
|
67 |
+
|----------|-----------|-----------|---|---|---|---|---|---|---|---|---|---|
|
68 |
+
| MoE-LLaVA-1.6Bร4-Top2 | 1.6B | [LanguageBind/MoE-LLaVA-StableLM-1.6B-4e](https://huggingface.co/LanguageBind/MoE-LLaVA-StableLM-1.6B-4e) | 60.0 | 76.0 | 60.4 | 37.2 | 62.6 | 47.8 | 84.3 | 59.4 | 85.9 | 26.1 |
|
69 |
+
| MoE-LLaVA-1.8Bร4-Top2 | 1.8B | [LanguageBind/MoE-LLaVA-Qwen-1.8B-4e](https://huggingface.co/LanguageBind/MoE-LLaVA-Qwen-1.8B-4e) | 60.2 | 76.2 | 61.5 | 32.6 | 63.1 | 48.0 | 87.0 | 59.6 | 88.7 | 25.3 |
|
70 |
+
| MoE-LLaVA-2.7Bร4-Top2 | 2.7B | [LanguageBind/MoE-LLaVA-Phi2-2.7B-4e](https://huggingface.co/LanguageBind/MoE-LLaVA-Phi2-2.7B-4e) | 63.9 | 77.1 | 61.1 | 43.4 | 68.7 | 50.2 | 85.0 | 65.5 | 93.2 | 31.1 |
|
71 |
+
|
72 |
+
<!--
|
73 |
+
| LLaVA-1.5 | 7B | [liuhaotian/llava-v1.5-7b](https://huggingface.co/liuhaotian/llava-v1.5-7b) | 62.0 | 78.5 | 62.0 | 50.0 | 66.8 | 58.2 | 85.9 | 64.3 | 31.1 |
|
74 |
+
| LLaVA-1.5 | 13B | [liuhaotian/llava-v1.5-13b](https://huggingface.co/liuhaotian/llava-v1.5-13b) | 64.9 | 80.0 | 63.3 | 53.6 | 71.6 | 61.3 | 85.9 | 67.7 | 36.1 |
|
75 |
+
-->
|
76 |
+
|
77 |
+
## โ๏ธ Requirements and Installation
|
78 |
+
* Python >= 3.10
|
79 |
+
* Pytorch == 2.0.1
|
80 |
+
* CUDA Version >= 11.7
|
81 |
+
* **Transformers == 4.36.2**
|
82 |
+
* **Tokenizers==0.15.1**
|
83 |
+
* Install required packages:
|
84 |
+
```bash
|
85 |
+
git clone https://github.com/PKU-YuanGroup/MoE-LLaVA
|
86 |
+
cd MoE-LLaVA
|
87 |
+
conda create -n moellava python=3.10 -y
|
88 |
+
conda activate moellava
|
89 |
+
pip install --upgrade pip # enable PEP 660 support
|
90 |
+
pip install -e .
|
91 |
+
pip install -e ".[train]"
|
92 |
+
pip install flash-attn --no-build-isolation
|
93 |
+
|
94 |
+
# Below are optional. For Qwen model.
|
95 |
+
git clone https://github.com/Dao-AILab/flash-attention
|
96 |
+
cd flash-attention && pip install .
|
97 |
+
# Below are optional. Installing them might be slow.
|
98 |
+
# pip install csrc/layer_norm
|
99 |
+
# If the version of flash-attn is higher than 2.1.1, the following is not needed.
|
100 |
+
# pip install csrc/rotary
|
101 |
+
```
|
102 |
+
|
103 |
+
## ๐๏ธ Training & Validating
|
104 |
+
The training & validating instruction is in [TRAIN.md](docs/TRAIN.md) & [EVAL.md](docs/EVAL.md).
|
105 |
+
|
106 |
+
## ๐ก Customizing your MoE-LLaVA
|
107 |
+
The instruction is in [CUSTOM.md](docs/CUSTOM.md).
|
108 |
+
|
109 |
+
## ๐ Visualization
|
110 |
+
The instruction is in [VISUALIZATION.md](docs/VISUALIZATION.md).
|
111 |
+
|
112 |
+
## ๐ค API
|
113 |
+
**We open source all codes.** If you want to load the model (e.g. ```LanguageBind/MoE-LLaVA```) on local, you can use the following code snippets.
|
114 |
+
|
115 |
+
**Using the following command to run the code.**
|
116 |
+
|
117 |
+
```bash
|
118 |
+
deepspeed predict.py
|
119 |
+
```
|
120 |
+
|
121 |
+
```python
|
122 |
+
import torch
|
123 |
+
from moellava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
|
124 |
+
from moellava.conversation import conv_templates, SeparatorStyle
|
125 |
+
from moellava.model.builder import load_pretrained_model
|
126 |
+
from moellava.utils import disable_torch_init
|
127 |
+
from moellava.mm_utils import tokenizer_image_token, get_model_name_from_path, KeywordsStoppingCriteria
|
128 |
+
|
129 |
+
def main():
|
130 |
+
disable_torch_init()
|
131 |
+
image = 'moellava/serve/examples/extreme_ironing.jpg'
|
132 |
+
inp = 'What is unusual about this image?'
|
133 |
+
model_path = 'LanguageBind/MoE-LLaVA-Phi2-2.7B-4e' # LanguageBind/MoE-LLaVA-Qwen-1.8B-4e or LanguageBind/MoE-LLaVA-StableLM-1.6B-4e
|
134 |
+
device = 'cuda'
|
135 |
+
load_4bit, load_8bit = False, False # FIXME: Deepspeed support 4bit or 8bit?
|
136 |
+
model_name = get_model_name_from_path(model_path)
|
137 |
+
tokenizer, model, processor, context_len = load_pretrained_model(model_path, None, model_name, load_8bit, load_4bit, device=device)
|
138 |
+
image_processor = processor['image']
|
139 |
+
conv_mode = "phi" # qwen or stablelm
|
140 |
+
conv = conv_templates[conv_mode].copy()
|
141 |
+
roles = conv.roles
|
142 |
+
image_tensor = image_processor.preprocess(image, return_tensors='pt')['pixel_values'].to(model.device, dtype=torch.float16)
|
143 |
+
|
144 |
+
print(f"{roles[1]}: {inp}")
|
145 |
+
inp = DEFAULT_IMAGE_TOKEN + '\n' + inp
|
146 |
+
conv.append_message(conv.roles[0], inp)
|
147 |
+
conv.append_message(conv.roles[1], None)
|
148 |
+
prompt = conv.get_prompt()
|
149 |
+
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).cuda()
|
150 |
+
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
|
151 |
+
keywords = [stop_str]
|
152 |
+
stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
|
153 |
+
|
154 |
+
with torch.inference_mode():
|
155 |
+
output_ids = model.generate(
|
156 |
+
input_ids,
|
157 |
+
images=image_tensor,
|
158 |
+
do_sample=True,
|
159 |
+
temperature=0.2,
|
160 |
+
max_new_tokens=1024,
|
161 |
+
use_cache=True,
|
162 |
+
stopping_criteria=[stopping_criteria])
|
163 |
+
|
164 |
+
outputs = tokenizer.decode(output_ids[0, input_ids.shape[1]:], skip_special_tokens=True).strip()
|
165 |
+
print(outputs)
|
166 |
+
|
167 |
+
if __name__ == '__main__':
|
168 |
+
main()
|
169 |
+
```
|
170 |
+
|
171 |
+
## ๐ Related Projects
|
172 |
+
* [Video-LLaVA](https://github.com/PKU-YuanGroup/Video-LLaVA) This framework empowers the model to efficiently utilize the united visual tokens.
|
173 |
+
* [LanguageBind](https://github.com/PKU-YuanGroup/LanguageBind) An open source five modalities language-based retrieval framework.
|
174 |
+
|
175 |
+
## ๐ Acknowledgement
|
176 |
+
* [LLaVA](https://github.com/haotian-liu/LLaVA) The codebase we built upon and it is an efficient large language and vision assistant.
|
177 |
+
|
178 |
+
## ๐ License
|
179 |
+
* The majority of this project is released under the Apache 2.0 license as found in the [LICENSE](https://github.com/PKU-YuanGroup/MoE-LLaVA/blob/main/LICENSE) file.
|
180 |
+
* The service is a research preview intended for non-commercial use only, subject to the model [License](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md) of LLaMA, [Terms of Use](https://openai.com/policies/terms-of-use) of the data generated by OpenAI, and [Privacy Practices](https://chrome.google.com/webstore/detail/sharegpt-share-your-chatg/daiacboceoaocpibfodeljbdfacokfjb) of ShareGPT. Please contact us if you find any potential violation.
|
181 |
+
|
182 |
+
|
183 |
+
|
184 |
+
## โ๏ธ Citation
|
185 |
+
If you find our paper and code useful in your research, please consider giving a star :star: and citation :pencil:.
|
186 |
+
|
187 |
+
```BibTeX
|
188 |
+
@misc{lin2024moellava,
|
189 |
+
title={MoE-LLaVA: Mixture of Experts for Large Vision-Language Models},
|
190 |
+
author={Bin Lin and Zhenyu Tang and Yang Ye and Jiaxi Cui and Bin Zhu and Peng Jin and Junwu Zhang and Munan Ning and Li Yuan},
|
191 |
+
year={2024},
|
192 |
+
eprint={2401.15947},
|
193 |
+
archivePrefix={arXiv},
|
194 |
+
primaryClass={cs.CV}
|
195 |
+
}
|
196 |
+
```
|
197 |
+
|
198 |
+
```BibTeX
|
199 |
+
@article{lin2023video,
|
200 |
+
title={Video-LLaVA: Learning United Visual Representation by Alignment Before Projection},
|
201 |
+
author={Lin, Bin and Zhu, Bin and Ye, Yang and Ning, Munan and Jin, Peng and Yuan, Li},
|
202 |
+
journal={arXiv preprint arXiv:2311.10122},
|
203 |
+
year={2023}
|
204 |
+
}
|
205 |
+
```
|
206 |
+
|
207 |
+
|
208 |
+
|
209 |
+
## โจ Star History
|
210 |
+
[![Star History](https://api.star-history.com/svg?repos=PKU-YuanGroup/MoE-LLaVA&type=Date)](https://star-history.com/#PKU-YuanGroup/MoE-LLaVA&Date)
|
211 |
+
|
212 |
+
|
213 |
+
## ๐ค Contributors
|
214 |
+
|
215 |
+
<a href="https://github.com/PKU-YuanGroup/MoE-LLaVA/graphs/contributors">
|
216 |
+
<img src="https://contrib.rocks/image?repo=PKU-YuanGroup/MoE-LLaVA" />
|
217 |
+
</a>
|