LanguageBind/MoE-LLaVA-OpenChat-7B-4e
122
1---2license: apache-2.03---4 5 6<p align="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## ๐ฐ News20* **[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## ๐ฎ Highlights24 25MoE-LLaVA shows excellent performance in multi-modal learning.26 27### ๐ฅ High performance, but with fewer parameters28- 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## ๐ค Demo37 38### Gradio Web UI39 40Highly 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```bash42# use phi243deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e" 44# use qwen45deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e" 46# use stablelm47deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-StableLM-1.6B-4e" 48```49 50 51 52### CLI Inference53 54```bash55# use phi256deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e" --image-file "image.jpg"57# use qwen58deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e" --image-file "image.jpg"59# use stablelm60deepspeed --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 Zoo65 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 Installation78* Python >= 3.1079* Pytorch == 2.0.180* CUDA Version >= 11.781* **Transformers == 4.36.2**82* **Tokenizers==0.15.1**83* Install required packages:84```bash85git clone https://github.com/PKU-YuanGroup/MoE-LLaVA86cd MoE-LLaVA87conda create -n moellava python=3.10 -y88conda activate moellava89pip install --upgrade pip # enable PEP 660 support90pip install -e .91pip install -e ".[train]"92pip install flash-attn --no-build-isolation93 94# Below are optional. For Qwen model.95git clone https://github.com/Dao-AILab/flash-attention96cd flash-attention && pip install .97# Below are optional. Installing them might be slow.98# pip install csrc/layer_norm99# If the version of flash-attn is higher than 2.1.1, the following is not needed.100# pip install csrc/rotary101```102 103## ๐๏ธ Training & Validating104The training & validating instruction is in [TRAIN.md](docs/TRAIN.md) & [EVAL.md](docs/EVAL.md).105 106## ๐ก Customizing your MoE-LLaVA107The instruction is in [CUSTOM.md](docs/CUSTOM.md).108 109## ๐ Visualization110The instruction is in [VISUALIZATION.md](docs/VISUALIZATION.md).111 112## ๐ค API113**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```bash118deepspeed predict.py119```120 121```python122import torch123from moellava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN124from moellava.conversation import conv_templates, SeparatorStyle125from moellava.model.builder import load_pretrained_model126from moellava.utils import disable_torch_init127from moellava.mm_utils import tokenizer_image_token, get_model_name_from_path, KeywordsStoppingCriteria128 129def 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-4e134 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 stablelm140 conv = conv_templates[conv_mode].copy()141 roles = conv.roles142 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' + inp146 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.sep2151 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 167if __name__ == '__main__':168 main()169```170 171## ๐ Related Projects172* [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## ๐ Acknowledgement176* [LLaVA](https://github.com/haotian-liu/LLaVA) The codebase we built upon and it is an efficient large language and vision assistant.177 178## ๐ License179* 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## โ๏ธ Citation185If you find our paper and code useful in your research, please consider giving a star :star: and citation :pencil:.186 187```BibTeX188@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```BibTeX199@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 History210[](https://star-history.com/#PKU-YuanGroup/MoE-LLaVA&Date)211 212 213## ๐ค Contributors214 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>