Moe LLaVA StableLM 1.6B 4e
MoE-LLaVA是一種基於專家混合架構的大規模視覺語言模型,通過稀疏激活參數實現高效的多模態學習。
下載量 125
發布時間 : 1/23/2024
模型概述
該模型採用專家混合架構,專注於視覺語言理解任務,能夠在多項基準測試中達到或超越更大規模模型的性能。
模型特點
高效參數利用
僅需30億稀疏激活參數即可達到7B規模模型的性能
卓越性能
在多項視覺理解任務上達到LLaVA-1.5-7B水平,部分任務超越13B模型
高效訓練
可在8張V100顯卡上2日內完成訓練
模型能力
視覺語言理解
多模態學習
圖像分析
文本生成
使用案例
視覺理解
圖像描述生成
為輸入圖像生成準確的文字描述
在物體幻覺基準測試中表現優異
視覺問答
回答關於圖像內容的複雜問題
達到或超越更大規模模型的性能
🚀 MoE-LLaVA:面向大視覺語言模型的專家混合模型
MoE-LLaVA是一種面向大視覺語言模型的專家混合模型,在多模態學習中展現出卓越性能。它以較少的參數實現了與更大模型相當甚至更優的表現,同時提供了簡單高效的訓練方案。
🚀 快速開始
環境要求
- Python >= 3.10
- Pytorch == 2.0.1
- CUDA Version >= 11.7
- Transformers == 4.36.2
- Tokenizers==0.15.1
安裝步驟
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
運行演示
Gradio Web UI
強烈建議通過以下命令嘗試我們的Web演示,它集成了MoE-LLaVA目前支持的所有功能。我們還在Huggingface Spaces上提供了在線演示。
# 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
# 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"
✨ 主要特性
🔥 高性能,低參數
僅使用3B稀疏激活參數,MoE-LLaVA在各種視覺理解數據集上的表現與LLaVA-1.5-7B相當,甚至在對象幻覺基準測試中超越了LLaVA-1.5-13B。
🚀 簡單基線,通過稀疏路徑學習多模態交互
通過添加簡單的MoE調優階段,我們可以在8個V100 GPU上在2天內完成MoE-LLaVA的訓練。
📦 模型庫
模型 | 大語言模型 | 檢查點 | 平均得分 | 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 | 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 | 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 | 63.9 | 77.1 | 61.1 | 43.4 | 68.7 | 50.2 | 85.0 | 65.5 | 93.2 | 31.1 |
💻 使用示例
基礎用法
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()
運行代碼
deepspeed predict.py
📚 詳細文檔
訓練與驗證
自定義模型
自定義MoE-LLaVA的說明請參考CUSTOM.md。
可視化
可視化說明請參考VISUALIZATION.md。
🤖 API
我們開源了所有代碼。如果您想在本地加載模型(例如LanguageBind/MoE-LLaVA
),可以使用上述代碼片段。
🙌 相關項目
- Video-LLaVA 該框架使模型能夠有效利用統一的視覺令牌。
- LanguageBind 一個開源的五模態基於語言的檢索框架。
👍 致謝
- LLaVA 我們的代碼基於此構建,它是一個高效的大語言和視覺助手。
📄 許可證
- 本項目的大部分內容遵循Apache 2.0許可證,詳情見LICENSE文件。
- 本服務僅供研究預覽,僅用於非商業用途,需遵守LLaMA的模型許可證、OpenAI生成數據的使用條款以及ShareGPT的隱私政策。如果您發現任何潛在的違規行為,請聯繫我們。
✏️ 引用
如果您覺得我們的論文和代碼對您的研究有幫助,請考慮給我們一個⭐並引用:
@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}
}
@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}
}
✨ 星標歷史
🤝 貢獻者
📰 新聞
- [2024.01.30] 論文發佈。
- [2024.01.27] 🤗Hugging Face演示以及所有代碼和數據集現已開放!歡迎關注 👀 本倉庫以獲取最新更新。
Clip Vit Large Patch14 336
基於Vision Transformer架構的大規模視覺語言預訓練模型,支持圖像與文本的跨模態理解
文本生成圖像
Transformers

C
openai
5.9M
241
Fashion Clip
MIT
FashionCLIP是基於CLIP開發的視覺語言模型,專門針對時尚領域進行微調,能夠生成通用產品表徵。
文本生成圖像
Transformers 英語

F
patrickjohncyh
3.8M
222
Gemma 3 1b It
Gemma 3是Google推出的輕量級先進開放模型系列,基於與Gemini模型相同的研究和技術構建。該模型是多模態模型,能夠處理文本和圖像輸入並生成文本輸出。
文本生成圖像
Transformers

G
google
2.1M
347
Blip Vqa Base
Bsd-3-clause
BLIP是一個統一的視覺語言預訓練框架,擅長視覺問答任務,通過語言-圖像聯合訓練實現多模態理解與生成能力
文本生成圖像
Transformers

B
Salesforce
1.9M
154
CLIP ViT H 14 Laion2b S32b B79k
MIT
基於OpenCLIP框架在LAION-2B英文數據集上訓練的視覺-語言模型,支持零樣本圖像分類和跨模態檢索任務
文本生成圖像
Safetensors
C
laion
1.8M
368
CLIP ViT B 32 Laion2b S34b B79k
MIT
基於OpenCLIP框架在LAION-2B英語子集上訓練的視覺-語言模型,支持零樣本圖像分類和跨模態檢索
文本生成圖像
Safetensors
C
laion
1.1M
112
Pickscore V1
PickScore v1 是一個針對文本生成圖像的評分函數,可用於預測人類偏好、評估模型性能和圖像排序等任務。
文本生成圖像
Transformers

P
yuvalkirstain
1.1M
44
Owlv2 Base Patch16 Ensemble
Apache-2.0
OWLv2是一種零樣本文本條件目標檢測模型,可通過文本查詢在圖像中定位對象。
文本生成圖像
Transformers

O
google
932.80k
99
Llama 3.2 11B Vision Instruct
Llama 3.2 是 Meta 發佈的多語言多模態大型語言模型,支持圖像文本到文本的轉換任務,具備強大的跨模態理解能力。
文本生成圖像
Transformers 支持多種語言

L
meta-llama
784.19k
1,424
Owlvit Base Patch32
Apache-2.0
OWL-ViT是一個零樣本文本條件目標檢測模型,可以通過文本查詢搜索圖像中的對象,無需特定類別的訓練數據。
文本生成圖像
Transformers

O
google
764.95k
129
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98