five

MoE-LLaVA

收藏
魔搭社区2026-05-02 更新2024-06-08 收录
下载链接:
https://modelscope.cn/datasets/PKU-YuanLab/MoE-LLaVA
下载链接
链接失效反馈
官方服务:
资源简介:
<p align="center"> <img src="https://s11.ax1x.com/2023/12/28/piqvDMV.png" width="250" style="margin-bottom: 0.2;"/> <p> <h2 align="center"> <a href="https://arxiv.org/abs/2401.15947">MoE-LLaVA: Mixture of Experts for Large Vision-Language Models</a></h2> <h5 align="center"> If you like our project, please give us a star ⭐ on GitHub for latest update. </h2> <h5 align="center"> </h5> ## 📰 News * **[2024.01.30]** The [paper](https://arxiv.org/abs/2401.15947) is released. * **[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. ## 😮 Highlights MoE-LLaVA shows excellent performance in multi-modal learning. ### 🔥 High performance, but with fewer parameters - 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. ### 🚀 Simple baseline, learning multi-modal interactions with sparse pathways. - With the addition of **a simple MoE tuning stage**, we can complete the training of MoE-LLaVA on **8 V100 GPUs** within 2 days. ## 🤗 Demo ### Gradio Web UI 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. ```bash # use phi2 deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e" # use qwen deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e" # use stablelm deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-StableLM-1.6B-4e" ``` ### CLI Inference ```bash # use phi2 deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e" --image-file "image.jpg" # use qwen deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e" --image-file "image.jpg" # use stablelm deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-StableLM-1.6B-4e" --image-file "image.jpg" ``` ## 🐳 Model Zoo | Model | LLM | Checkpoint | Avg | VQAv2 | GQA | VizWiz | SQA | T-VQA | POPE | MM-Bench| LLaVA-Bench-Wild | MM-Vet | |----------|-----------|-----------|---|---|---|---|---|---|---|---|---|---| | 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 | | 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 | | 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 | <!-- | 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 | | 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 | --> ## ⚙️ Requirements and Installation * Python >= 3.10 * Pytorch == 2.0.1 * CUDA Version >= 11.7 * **Transformers == 4.36.2** * **Tokenizers==0.15.1** * Install required packages: ```bash git clone https://github.com/PKU-YuanGroup/MoE-LLaVA cd MoE-LLaVA conda create -n moellava python=3.10 -y conda activate moellava pip install --upgrade pip # enable PEP 660 support pip install -e . pip install -e ".[train]" pip install flash-attn --no-build-isolation # Below are optional. For Qwen model. git clone https://github.com/Dao-AILab/flash-attention cd flash-attention && pip install . # Below are optional. Installing them might be slow. # pip install csrc/layer_norm # If the version of flash-attn is higher than 2.1.1, the following is not needed. # pip install csrc/rotary ``` ## 🗝️ Training & Validating The training & validating instruction is in [TRAIN.md](docs/TRAIN.md) & [EVAL.md](docs/EVAL.md). ## 💡 Customizing your MoE-LLaVA The instruction is in [CUSTOM.md](docs/CUSTOM.md). ## 😍 Visualization The instruction is in [VISUALIZATION.md](docs/VISUALIZATION.md). ## 🤖 API **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. **Using the following command to run the code.** ```bash deepspeed predict.py ``` ```python import torch from moellava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN from moellava.conversation import conv_templates, SeparatorStyle from moellava.model.builder import load_pretrained_model from moellava.utils import disable_torch_init from moellava.mm_utils import tokenizer_image_token, get_model_name_from_path, KeywordsStoppingCriteria def main(): disable_torch_init() image = 'moellava/serve/examples/extreme_ironing.jpg' inp = 'What is unusual about this image?' model_path = 'LanguageBind/MoE-LLaVA-Phi2-2.7B-4e' # LanguageBind/MoE-LLaVA-Qwen-1.8B-4e or LanguageBind/MoE-LLaVA-StableLM-1.6B-4e device = 'cuda' load_4bit, load_8bit = False, False # FIXME: Deepspeed support 4bit or 8bit? model_name = get_model_name_from_path(model_path) tokenizer, model, processor, context_len = load_pretrained_model(model_path, None, model_name, load_8bit, load_4bit, device=device) image_processor = processor['image'] conv_mode = "phi" # qwen or stablelm conv = conv_templates[conv_mode].copy() roles = conv.roles image_tensor = image_processor.preprocess(image, return_tensors='pt')['pixel_values'].to(model.device, dtype=torch.float16) print(f"{roles[1]}: {inp}") inp = DEFAULT_IMAGE_TOKEN + '\n' + inp conv.append_message(conv.roles[0], inp) conv.append_message(conv.roles[1], None) prompt = conv.get_prompt() input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).cuda() stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2 keywords = [stop_str] stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids) with torch.inference_mode(): output_ids = model.generate( input_ids, images=image_tensor, do_sample=True, temperature=0.2, max_new_tokens=1024, use_cache=True, stopping_criteria=[stopping_criteria]) outputs = tokenizer.decode(output_ids[0, input_ids.shape[1]:], skip_special_tokens=True).strip() print(outputs) if __name__ == '__main__': main() ``` ## 🙌 Related Projects * [Video-LLaVA](https://github.com/PKU-YuanGroup/Video-LLaVA) This framework empowers the model to efficiently utilize the united visual tokens. * [LanguageBind](https://github.com/PKU-YuanGroup/LanguageBind) An open source five modalities language-based retrieval framework. ## 👍 Acknowledgement * [LLaVA](https://github.com/haotian-liu/LLaVA) The codebase we built upon and it is an efficient large language and vision assistant. ## 🔒 License * 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. * 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. ## ✏️ Citation If you find our paper and code useful in your research, please consider giving a star :star: and citation :pencil:. ```BibTeX @misc{lin2024moellava, title={MoE-LLaVA: Mixture of Experts for Large Vision-Language Models}, 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}, year={2024}, eprint={2401.15947}, archivePrefix={arXiv}, primaryClass={cs.CV} } ``` ```BibTeX @article{lin2023video, title={Video-LLaVA: Learning United Visual Representation by Alignment Before Projection}, author={Lin, Bin and Zhu, Bin and Ye, Yang and Ning, Munan and Jin, Peng and Yuan, Li}, journal={arXiv preprint arXiv:2311.10122}, year={2023} } ``` ## ✨ Star History [![Star History](https://api.star-history.com/svg?repos=PKU-YuanGroup/MoE-LLaVA&type=Date)](https://star-history.com/#PKU-YuanGroup/MoE-LLaVA&Date) ## 🤝 Contributors <a href="https://github.com/PKU-YuanGroup/MoE-LLaVA/graphs/contributors"> <img src="https://contrib.rocks/image?repo=PKU-YuanGroup/MoE-LLaVA" /> </a>

<p align="center"> <img src="https://s11.ax1x.com/2023/12/28/piqvDMV.png" width="250" style="margin-bottom: 0.2;"/> </p> <h2 align="center"> <a href="https://arxiv.org/abs/2401.15947">MoE-LLaVA:面向大视觉语言模型的混合专家(Mixture of Experts, MoE)框架</a></h2> <h5 align="center">如果您喜欢本项目,请为我们的GitHub仓库点亮Star ⭐ 以获取最新动态。</h5> ## 📰 新闻 * **[2024.01.30]** 本项目相关[论文](https://arxiv.org/abs/2401.15947)正式发布。 * **[2024.01.27]** 🤗[Hugging Face在线演示](https://huggingface.co/spaces/LanguageBind/MoE-LLaVA)及**全部代码与数据集**现已开放!欢迎关注👀本仓库以获取最新更新。 ## 😮 核心亮点 MoE-LLaVA在多模态学习任务中展现出优异的性能。 ### 🔥 高性能低参量 - 仅需**30亿稀疏激活参数**,MoE-LLaVA在各类视觉理解数据集上的性能可与LLaVA-1.5-7B媲美,甚至在物体幻觉(object hallucination)基准测试中超越了LLaVA-1.5-13B。 ### 🚀 轻量化基线,通过稀疏通路学习多模态交互 - 仅需新增**一个简易的混合专家微调阶段**,我们即可在**8张V100 GPU**上用不到2天的时间完成MoE-LLaVA的训练。 ## 🤗 演示 ### Gradio 网页演示 我们强烈推荐通过以下命令运行本地网页演示,该演示覆盖了MoE-LLaVA当前支持的全部功能。我们同时在Hugging Face Spaces上提供了[在线演示](https://huggingface.co/spaces/LanguageBind/MoE-LLaVA)。 bash # 采用Phi2模型 deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e" # 采用Qwen模型 deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e" # 采用StableLM模型 deepspeed --include localhost:0 moellava/serve/gradio_web_server.py --model-path "LanguageBind/MoE-LLaVA-StableLM-1.6B-4e" ### CLI 推理 bash # 采用Phi2模型 deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Phi2-2.7B-4e" --image-file "image.jpg" # 采用Qwen模型 deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-Qwen-1.8B-4e" --image-file "image.jpg" # 采用StableLM模型 deepspeed --include localhost:0 moellava/serve/cli.py --model-path "LanguageBind/MoE-LLaVA-StableLM-1.6B-4e" --image-file "image.jpg" ## 🐳 模型库 | 模型 | 大语言模型(Large Language Model, LLM) | 权重文件 | 平均性能 | VQAv2 | GQA | VizWiz | SQA | T-VQA | POPE | MM-Bench| LLaVA-Bench-Wild | MM-Vet | |----------|-----------|-----------|---|---|---|---|---|---|---|---|---|---| | 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 | | 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 | | 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 | ## ⚙️ 环境依赖与安装 * Python 版本 ≥ 3.10 * PyTorch 版本 == 2.0.1 * CUDA 版本 ≥ 11.7 * **Transformers 库版本 == 4.36.2** * **Tokenizers 库版本 == 0.15.1** * 安装依赖包: bash git clone https://github.com/PKU-YuanGroup/MoE-LLaVA cd MoE-LLaVA # 创建名为moellava的conda环境 conda create -n moellava python=3.10 -y conda activate moellava # 升级pip以支持PEP 660规范 pip install --upgrade pip pip install -e . pip install -e ".[train]" pip install flash-attn --no-build-isolation # 以下为可选步骤,用于支持Qwen模型 git clone https://github.com/Dao-AILab/flash-attention cd flash-attention && pip install . # 以下为可选步骤,安装可能耗时较长 # pip install csrc/layer_norm # 若flash-attn版本高于2.1.1,则无需执行以下命令 # pip install csrc/rotary ## 🗝️ 训练与验证 训练与验证的详细说明请参考[TRAIN.md](docs/TRAIN.md)与[EVAL.md](docs/EVAL.md)文档。 ## 💡 自定义MoE-LLaVA 自定义流程请参考[CUSTOM.md](docs/CUSTOM.md)文档。 ## 😍 可视化 可视化操作指南请参考[VISUALIZATION.md](docs/VISUALIZATION.md)文档。 ## 🤖 API **我们开源了全部代码。** 若您希望在本地加载该模型(例如 LanguageBind/MoE-LLaVA),可使用以下代码片段。 **可通过以下命令运行该代码。** bash deepspeed predict.py python import torch from moellava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN from moellava.conversation import conv_templates, SeparatorStyle from moellava.model.builder import load_pretrained_model from moellava.utils import disable_torch_init from moellava.mm_utils import tokenizer_image_token, get_model_name_from_path, KeywordsStoppingCriteria def main(): # 禁用PyTorch初始化冗余操作 disable_torch_init() # 示例图片路径 image = 'moellava/serve/examples/extreme_ironing.jpg' # 输入查询语句 inp = 'What is unusual about this image?' # 模型路径,支持Phi2、Qwen、StableLM三种变体 model_path = 'LanguageBind/MoE-LLaVA-Phi2-2.7B-4e' # LanguageBind/MoE-LLaVA-Qwen-1.8B-4e 或 LanguageBind/MoE-LLaVA-StableLM-1.6B-4e device = 'cuda' # 是否启用4bit/8bit量化(注:DeepSpeed暂不支持4bit/8bit量化) load_4bit, load_8bit = False, False # 获取模型名称 model_name = get_model_name_from_path(model_path) # 加载预训练模型、分词器与图像处理器 tokenizer, model, processor, context_len = load_pretrained_model(model_path, None, model_name, load_8bit, load_4bit, device=device) image_processor = processor['image'] # 对话模式,根据模型选择:phi对应Phi2,qwen对应Qwen,stablelm对应StableLM conv_mode = "phi" conv = conv_templates[conv_mode].copy() roles = conv.roles # 预处理图像张量 image_tensor = image_processor.preprocess(image, return_tensors='pt')['pixel_values'].to(model.device, dtype=torch.float16) print(f"{roles[1]}: {inp}") # 在输入前插入图像Token inp = DEFAULT_IMAGE_TOKEN + ' ' + inp conv.append_message(conv.roles[0], inp) conv.append_message(conv.roles[1], None) prompt = conv.get_prompt() # 将文本转换为模型输入的Token序列 input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).cuda() stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2 keywords = [stop_str] stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids) # 关闭梯度计算以加速推理 with torch.inference_mode(): output_ids = model.generate( input_ids, images=image_tensor, do_sample=True, temperature=0.2, max_new_tokens=1024, use_cache=True, stopping_criteria=[stopping_criteria]) # 解码生成的响应结果 outputs = tokenizer.decode(output_ids[0, input_ids.shape[1]:], skip_special_tokens=True).strip() print(outputs) if __name__ == '__main__': main() ## 🙌 相关项目 * [Video-LLaVA](https://github.com/PKU-YuanGroup/Video-LLaVA) 该框架使模型能够高效利用统一视觉表征。 * [LanguageBind](https://github.com/PKU-YuanGroup/LanguageBind) 一款开源的五模态语言检索框架。 ## 👍 致谢 * [LLaVA](https://github.com/haotian-liu/LLaVA) 本项目基于该代码库开发,LLaVA是一款高效的大语言与视觉助手。 ## 🔒 许可证 * 本项目的绝大部分代码遵循Apache 2.0许可证,详情请参考[LICENSE](https://github.com/PKU-YuanGroup/MoE-LLaVA/blob/main/LICENSE)文件。 * 本服务仅作为研究预览版本,仅供非商业用途使用,需遵循LLaMA的[模型许可证](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md)、OpenAI生成数据的[使用条款](https://openai.com/policies/terms-of-use)以及ShareGPT的[隐私政策](https://chrome.google.com/webstore/detail/sharegpt-share-your-chatg/daiacboceoaocpibfodeljbdfacokfjb)。若您发现任何潜在的侵权行为,请与我们联系。 ## ✏️ 引用 如果您的研究中用到了本项目的论文与代码,请考虑为我们点亮Star :star: 并引用我们的工作 :pencil:。 BibTeX @misc{lin2024moellava, title={MoE-LLaVA: Mixture of Experts for Large Vision-Language Models}, 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}, year={2024}, eprint={2401.15947}, archivePrefix={arXiv}, primaryClass={cs.CV} } BibTeX @article{lin2023video, title={Video-LLaVA: Learning United Visual Representation by Alignment Before Projection}, author={Lin, Bin and Zhu, Bin and Ye, Yang and Ning, Munan and Jin, Peng and Yuan, Li}, journal={arXiv preprint arXiv:2311.10122}, year={2023} } ## ✨ Star 历史 [![Star 历史曲线](https://api.star-history.com/svg?repos=PKU-YuanGroup/MoE-LLaVA&type=Date)](https://star-history.com/#PKU-YuanGroup/MoE-LLaVA&Date) ## 🤝 贡献者 <a href="https://github.com/PKU-YuanGroup/MoE-LLaVA/graphs/contributors"> <img src="https://contrib.rocks/image?repo=PKU-YuanGroup/MoE-LLaVA" /> </a>
提供机构:
maas
创建时间:
2025-06-05
5,000+
优质数据集
54 个
任务类型
进入经典数据集
二维码
社区交流群

面向社区/商业的数据集话题

二维码
科研交流群

面向高校/科研机构的开源数据集话题

数据驱动未来

携手共赢发展

商业合作