BAAI/Video-XL-2 已完整同步
Video-XL-2
[📰 Blog] [📂 GitHub] [📜 Tech Report(comming soon)]
How to use the model
Video-XL-2 supply two efficiency optimization strategy: chunk-based prefill and bi-level kvs decoding. You can flexibly choose them based on your needs.
TODO
- Release model weights.
- Release the inference code w/o. efficiency optimization.
- Release the inference code w. chunk-based prefill.
- Release the inference code w. chunk-based prefill & bi-level kvs decoding.
*Tips: Our inference code still under updating, you could update it by assign "--include '*.py'" in huggingface-cli to only update the inference code, avoid downloading the whole model.
0. Installing Required Packages
pip install transformers==4.43.0
pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu121
pip install decord
pip install einops
pip install opencv-python
pip install accelerate==0.30.0
pip install numpy==1.26.4
# optional
pip install flash-attn --no-build-isolation
1. Inference w/o. Efficiency Optimization
from transformers import AutoTokenizer, AutoModel, AutoConfig, BitsAndBytesConfig, AutoModelForCausalLM
import torch
# load model
model_path = '/root/Models/Video-XL-2'
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map=device,quantization_config=None, attn_implementation="sdpa", torch_dtype=torch.float16, low_cpu_mem_usage=True)
gen_kwargs = {
"do_sample": False,
"temperature": 0.01,
"top_p": 0.001,
"num_beams": 1,
"use_cache": True,
"max_new_tokens": 256
}
model.config.enable_sparse = False
# input data
video_path = "/asset/demo.mp4"
question1 = "How many people in the video? (A)3 people (B)6 people. Please only respone the letter"
# params
max_num_frames = 150
sample_fps = 1 # extract frame at 1fps
max_sample_fps = 4
with torch.inference_mode():
response = model.chat(video_path, tokenizer, question1, chat_history=None, return_history=False,max_num_frames=max_num_frames, sample_fps=sample_fps, max_sample_fps=max_sample_fps, generation_config=gen_kwargs)
print(response)
2. Inference w. Chunk-based Pre-filling
Chunk-based prefill significantly reduces memory demands and response latency by encoding video input in a streaming manner. This advantage becomes particularly noticeable with longer videos.
To enable this mode, you need to set enable_chunk_prefill to True and configure the prefill_config parameters:
chunk_prefill_mode: This defines the mode of chunk-based prefill. We currently support two modes:streaming: This mode encodes video chunks streamingly.mask: This mode achieves an equivalent effect using an attention mask. However, due to a lack of underlying optimized operators, themaskmode doesn't offer any efficiency improvements at this time. We recommend using thestreamingmode.
chunk_size: This parameter specifies the size of each chunk processed in a single forward pass. The unit forchunk_sizeis 4 frames (e.g.,chunk_size = 4means processing visual tokens from 4×4 = 16 frames at once). A largerchunk_sizewill gradually approach full attention, resulting in a higher peak memory usage.step_size: This controls the step size between chunks. A smallerstep_sizeleads to more continuous information transfer between chunks but may slightly decrease inference speed.offload: This boolean parameter determines whether to offload the key-value states (KVs) of each chun
27 个文件
浏览文件数据集版权信息
本数据集的许可证为 Apache License 2.0。如有违反相关条款,请联系 WEHUB,我们将及时处理。 查看许可证
通过 WeHub CLI 下载当前数据集快照。下列命令会固定为当前页面展示的数据版本(如果页面提供版本)。文件字节由本机直连存储下载,浏览器不会签发或保存下载链接。
前置要求
需要 Node.js 18 及以上,以及 npm(或 npx)。
1. 安装 CLI
npm install -g wehub-cli@latest
2. 下载此数据集
wehub datasets download ds_ext_3055_87a20794b8 --revision 107a6ebaf32becf8abc73b6ada9cb68a27384be1 --output ./ds_ext_3055_87a20794b8
若中断或部分失败,在同一目录重新执行同一命令即可续传。默认会校验 SHA-256。
免全局安装
npx --yes wehub-cli@latest datasets download ds_ext_3055_87a20794b8 --revision 107a6ebaf32becf8abc73b6ada9cb68a27384be1 --output ./ds_ext_3055_87a20794b8
高级选项
以下为 wehub datasets download 已支持的参数示例:
强制重新下载,不复用已校验的本地文件
wehub datasets download ds_ext_3055_87a20794b8 --revision 107a6ebaf32becf8abc73b6ada9cb68a27384be1 --output ./ds_ext_3055_87a20794b8 --overwrite
仅包含匹配路径
wehub datasets download ds_ext_3055_87a20794b8 --revision 107a6ebaf32becf8abc73b6ada9cb68a27384be1 --output ./ds_ext_3055_87a20794b8 --include "*.jsonl"
排除匹配路径
wehub datasets download ds_ext_3055_87a20794b8 --revision 107a6ebaf32becf8abc73b6ada9cb68a27384be1 --output ./ds_ext_3055_87a20794b8 --exclude "*.md"
提高并发下载数
wehub datasets download ds_ext_3055_87a20794b8 --revision 107a6ebaf32becf8abc73b6ada9cb68a27384be1 --output ./ds_ext_3055_87a20794b8 --jobs 8
完整帮助:wehub datasets download --help