🚀 🦜VideoChat-Flash-Qwen2_5-7B-1M_res224⚡
VideoChat-Flash-Qwen2_5-7B_InternVideo2-1B基於UMT - L (300M)和Qwen2.5 - 7B - 1M構建,每幀僅使用16個token。通過使用Yarn將上下文窗口擴展到1M(Qwen2.5 - 7B - 1M的原生上下文窗口為128k),我們的模型支持輸入序列最多約50,000幀。
⚠️ 重要提示
由於訓練語料主要為英文,模型僅具備基本的中文理解能力,為確保最佳性能,建議使用英文進行交互。
[📰 博客] [📂 GitHub] [📜 技術報告] [🗨️ 聊天演示]
📈 性能表現
📦 安裝指南
首先,你需要安裝flash attention2和其他一些模塊。我們在下面提供一個簡單的安裝示例:
pip install transformers==4.40.1
pip install av
pip install imageio
pip install decord
pip install opencv-python
# 可選
pip install flash-attn --no-build-isolation
💻 使用示例
基礎用法
from transformers import AutoModel, AutoTokenizer
import torch
model_path = 'OpenGVLab/VideoChat-Flash-Qwen2_5-7B-1M_res224'
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(torch.bfloat16).cuda()
image_processor = model.get_vision_tower().image_processor
mm_llm_compress = False
if mm_llm_compress:
model.config.mm_llm_compress = True
model.config.llm_compress_type = "uniform0_attention"
model.config.llm_compress_layer_list = [4, 18]
model.config.llm_image_token_ratio_list = [1, 0.75, 0.25]
else:
model.config.mm_llm_compress = False
max_num_frames = 512
generation_config = dict(
do_sample=False,
temperature=0.0,
max_new_tokens=1024,
top_p=0.1,
num_beams=1
)
video_path = "your_video.mp4"
question1 = "Describe this video in detail."
output1, chat_history = model.chat(video_path=video_path, tokenizer=tokenizer, user_prompt=question1, return_history=True, max_num_frames=max_num_frames, generation_config=generation_config)
print(output1)
question2 = "How many people appear in the video?"
output2, chat_history = model.chat(video_path=video_path, tokenizer=tokenizer, user_prompt=question2, chat_history=chat_history, return_history=True, max_num_frames=max_num_frames, generation_config=generation_config)
print(output2)
✏️ 引用
@article{li2024videochatflash,
title={VideoChat-Flash: Hierarchical Compression for Long-Context Video Modeling},
author={Li, Xinhao and Wang, Yi and Yu, Jiashuo and Zeng, Xiangyu and Zhu, Yuhan and Huang, Haian and Gao, Jianfei and Li, Kunchang and He, Yinan and Wang, Chenting and others},
journal={arXiv preprint arXiv:2501.00574},
year={2024}
}
📄 許可證
本項目採用Apache - 2.0許可證。