BAAI / Video-XL-2

huggingface.co
Total runs: 269
24-hour runs: -3
7-day runs: 4
30-day runs: 39
Model's Last Updated: June 06 2025
video-text-to-text

Introduction of Video-XL-2

Model Details of 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, the mask mode doesn't offer any efficiency improvements at this time. We recommend using the streaming mode.
  • chunk_size : This parameter specifies the size of each chunk processed in a single forward pass. The unit for chunk_size is 4 frames (e.g., chunk_size = 4 means processing visual tokens from 4×4 = 16 frames at once). A larger chunk_size will gradually approach full attention, resulting in a higher peak memory usage.
  • step_size : This controls the step size between chunks. A smaller step_size leads 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 chunk to the CPU during forwarding. While this can reduce memory usage, it will also lower the inference speed.
  • chunk_size_for_vision_tower : For longer video inputs, the vision tower can become a memory bottleneck during forwarding. To mitigate this, we also support a streaming mode for the vision tower, which is controlled by this parameter. The unit for chunk_size_for_vision_tower is 1 frames . And, the value of chunk_size_for_vision_tower must be a multiple of 4 .

* Tip: Currently, chunk-based prefill only supports the 'sdpa' attention implementation.

from transformers import AutoTokenizer, AutoModel, AutoConfig, BitsAndBytesConfig, AutoModelForCausalLM
import torch
import pdb
import argparse

torch.cuda.reset_peak_memory_stats()
# load model 
model_path = '/root/Models/Video-XL-2'
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
device = 'cuda:0' 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) # sdpa

gen_kwargs = {"do_sample": False, "temperature": 0.01, "top_p": 0.001, "num_beams": 1, "use_cache": True, "max_new_tokens": 128}

model.config.enable_chunk_prefill = True
prefill_config = {
    'chunk_prefill_mode': 'streaming',
    'chunk_size': 4,
    'step_size': 1,
    'offload': True,
    'chunk_size_for_vision_tower': 24,
}
model.config.prefill_config = prefill_config

# 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 = 1300
sample_fps = None  # uniform sampling
max_sample_fps = None

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)
    

peak_memory_allocated = torch.cuda.max_memory_allocated()
print(f"Memory Peak: {peak_memory_allocated / (1024**3):.2f} GB")
print(response)

3. Inference w. Chunk-based Pre-filling & Bi-level KVs Decoding

coming soon


✏️ Citation
@article{shu2024video,
  title={Video-XL: Extra-Long Vision Language Model for Hour-Scale Video Understanding},
  author={Shu, Yan and Zhang, Peitian and Liu, Zheng and Qin, Minghao and Zhou, Junjie and Huang, Tiejun and Zhao, Bo},
  journal={arXiv preprint arXiv:2409.14485},
  year={2024}
}

@article{liu2025video,
  title={Video-XL-Pro: Reconstructive Token Compression for Extremely Long Video Understanding},
  author={Liu, Xiangrui and Shu, Yan and Liu, Zheng and Li, Ao and Tian, Yang and Zhao, Bo},
  journal={arXiv preprint arXiv:2503.18478},
  year={2025}
}

Runs of BAAI Video-XL-2 on huggingface.co

269
Total runs
-3
24-hour runs
-2
3-day runs
4
7-day runs
39
30-day runs

More Information About Video-XL-2 huggingface.co Model

More Video-XL-2 license Visit here:

https://choosealicense.com/licenses/apache-2.0

Video-XL-2 huggingface.co

Video-XL-2 huggingface.co is an AI model on huggingface.co that provides Video-XL-2's model effect (), which can be used instantly with this BAAI Video-XL-2 model. huggingface.co supports a free trial of the Video-XL-2 model, and also provides paid use of the Video-XL-2. Support call Video-XL-2 model through api, including Node.js, Python, http.

Video-XL-2 huggingface.co Url

https://huggingface.co/BAAI/Video-XL-2

BAAI Video-XL-2 online free

Video-XL-2 huggingface.co is an online trial and call api platform, which integrates Video-XL-2's modeling effects, including api services, and provides a free online trial of Video-XL-2, you can try Video-XL-2 online for free by clicking the link below.

BAAI Video-XL-2 online free url in huggingface.co:

https://huggingface.co/BAAI/Video-XL-2

Video-XL-2 install

Video-XL-2 is an open source model from GitHub that offers a free installation service, and any user can find Video-XL-2 on GitHub to install. At the same time, huggingface.co provides the effect of Video-XL-2 install, users can directly use Video-XL-2 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

Video-XL-2 install url in huggingface.co:

https://huggingface.co/BAAI/Video-XL-2

Url of Video-XL-2

Video-XL-2 huggingface.co Url

Provider of Video-XL-2 huggingface.co

BAAI
ORGANIZATIONS

Other API from BAAI

huggingface.co

Total runs: 58.1M
Run Growth: -6.4M
Growth Rate: -11.08%
Updated:February 22 2024
huggingface.co

Total runs: 31.7M
Run Growth: -6.5M
Growth Rate: -20.47%
Updated:July 03 2024
huggingface.co

Total runs: 10.0M
Run Growth: -1.6M
Growth Rate: -15.61%
Updated:February 21 2024
huggingface.co

Total runs: 9.0M
Run Growth: -1.5M
Growth Rate: -17.17%
Updated:February 21 2024
huggingface.co

Total runs: 2.4M
Run Growth: -105.2K
Growth Rate: -4.35%
Updated:April 17 2024
huggingface.co

Total runs: 381.6K
Run Growth: -425.8K
Growth Rate: -111.58%
Updated:October 12 2023
huggingface.co

Total runs: 343.3K
Run Growth: -767.9K
Growth Rate: -223.70%
Updated:April 02 2024
huggingface.co

Total runs: 191.1K
Run Growth: -29.1K
Growth Rate: -15.21%
Updated:December 13 2023
huggingface.co

Total runs: 113.9K
Run Growth: 63.6K
Growth Rate: 55.84%
Updated:October 12 2023
huggingface.co

Total runs: 53.4K
Run Growth: 3.3K
Growth Rate: 6.26%
Updated:November 14 2023
huggingface.co

Total runs: 38.8K
Run Growth: -15.5K
Growth Rate: -39.80%
Updated:October 12 2023
huggingface.co

Total runs: 37.4K
Run Growth: -29.0K
Growth Rate: -77.38%
Updated:July 13 2026
huggingface.co

Total runs: 30.7K
Run Growth: -9.7K
Growth Rate: -31.57%
Updated:January 15 2025
huggingface.co

Total runs: 11.0K
Run Growth: -4.9K
Growth Rate: -44.23%
Updated:April 16 2025
huggingface.co

Total runs: 9.6K
Run Growth: -59.0K
Growth Rate: -613.19%
Updated:October 12 2023
huggingface.co

Total runs: 3.7K
Run Growth: -6.8K
Growth Rate: -184.86%
Updated:October 12 2023
huggingface.co

Total runs: 3.4K
Run Growth: -1.4K
Growth Rate: -42.26%
Updated:May 20 2025
huggingface.co

Total runs: 3.0K
Run Growth: -1.3K
Growth Rate: -43.67%
Updated:April 19 2024
huggingface.co

Total runs: 2.0K
Run Growth: 2.0K
Growth Rate: 100.00%
Updated:October 01 2026
huggingface.co

Total runs: 1.6K
Run Growth: -85
Growth Rate: -5.25%
Updated:April 10 2026
huggingface.co

Total runs: 1.6K
Run Growth: -351
Growth Rate: -22.17%
Updated:January 15 2025
huggingface.co

Total runs: 1.4K
Run Growth: -2.2K
Growth Rate: -151.44%
Updated:September 11 2026
huggingface.co

Total runs: 1.2K
Run Growth: -696
Growth Rate: -60.26%
Updated:April 10 2026
huggingface.co

Total runs: 1.1K
Run Growth: -1000
Growth Rate: -89.37%
Updated:December 31 2022
huggingface.co

Total runs: 1.1K
Run Growth: -724
Growth Rate: -66.85%
Updated:November 28 2024
huggingface.co

Total runs: 736
Run Growth: 721
Growth Rate: 97.96%
Updated:October 13 2025
huggingface.co

Total runs: 729
Run Growth: -22
Growth Rate: -2.89%
Updated:February 07 2024
huggingface.co

Total runs: 516
Run Growth: -11
Growth Rate: -2.13%
Updated:July 13 2026
huggingface.co

Total runs: 482
Run Growth: 268
Growth Rate: 55.60%
Updated:April 02 2024
huggingface.co

Total runs: 478
Run Growth: -343
Growth Rate: -71.76%
Updated:October 23 2024
huggingface.co

Total runs: 451
Run Growth: 28
Growth Rate: 6.21%
Updated:April 18 2023
huggingface.co

Total runs: 445
Run Growth: 38
Growth Rate: 8.54%
Updated:July 13 2026
huggingface.co

Total runs: 442
Run Growth: -331
Growth Rate: -74.89%
Updated:May 23 2025
huggingface.co

Total runs: 422
Run Growth: 158
Growth Rate: 37.44%
Updated:December 25 2025
huggingface.co

Total runs: 421
Run Growth: 41
Growth Rate: 9.74%
Updated:October 27 2023
huggingface.co

Total runs: 419
Run Growth: 86
Growth Rate: 20.53%
Updated:July 13 2026
huggingface.co

Total runs: 413
Run Growth: 128
Growth Rate: 30.84%
Updated:March 07 2024
huggingface.co

Total runs: 400
Run Growth: 53
Growth Rate: 13.25%
Updated:August 11 2026
huggingface.co

Total runs: 393
Run Growth: -9.8K
Growth Rate: -2490.33%
Updated:September 16 2026
huggingface.co

Total runs: 385
Run Growth: -649
Growth Rate: -168.57%
Updated:October 24 2024
huggingface.co

Total runs: 383
Run Growth: 10
Growth Rate: 2.61%
Updated:August 11 2026
huggingface.co

Total runs: 363
Run Growth: 152
Growth Rate: 41.87%
Updated:July 13 2026
huggingface.co

Total runs: 294
Run Growth: 46
Growth Rate: 15.65%
Updated:August 18 2026
huggingface.co

Total runs: 281
Run Growth: -50
Growth Rate: -17.79%
Updated:July 13 2026
huggingface.co

Total runs: 280
Run Growth: 64
Growth Rate: 22.86%
Updated:July 13 2026
huggingface.co

Total runs: 272
Run Growth: 84
Growth Rate: 30.88%
Updated:July 13 2026
huggingface.co

Total runs: 267
Run Growth: -203
Growth Rate: -76.03%
Updated:April 10 2026
huggingface.co

Total runs: 253
Run Growth: 97
Growth Rate: 38.34%
Updated:November 28 2023
huggingface.co

Total runs: 252
Run Growth: -47
Growth Rate: -18.65%
Updated:July 13 2026
huggingface.co

Total runs: 249
Run Growth: -62
Growth Rate: -24.90%
Updated:December 25 2025
huggingface.co

Total runs: 244
Run Growth: 67
Growth Rate: 27.46%
Updated:October 23 2024
huggingface.co

Total runs: 233
Run Growth: 68
Growth Rate: 29.18%
Updated:July 13 2026
huggingface.co

Total runs: 209
Run Growth: 70
Growth Rate: 33.49%
Updated:July 13 2026
huggingface.co

Total runs: 208
Run Growth: -17
Growth Rate: -8.17%
Updated:July 17 2026
huggingface.co

Total runs: 203
Run Growth: 42
Growth Rate: 20.69%
Updated:May 13 2024
huggingface.co

Total runs: 201
Run Growth: 25
Growth Rate: 12.44%
Updated:June 24 2024
huggingface.co

Total runs: 196
Run Growth: 37
Growth Rate: 18.88%
Updated:May 13 2024
huggingface.co

Total runs: 195
Run Growth: 44
Growth Rate: 22.56%
Updated:June 24 2024
huggingface.co

Total runs: 193
Run Growth: 48
Growth Rate: 24.87%
Updated:December 21 2023
huggingface.co

Total runs: 190
Run Growth: 36
Growth Rate: 18.95%
Updated:May 13 2024
huggingface.co

Total runs: 190
Run Growth: 37
Growth Rate: 19.47%
Updated:May 31 2024
huggingface.co

Total runs: 187
Run Growth: 40
Growth Rate: 21.39%
Updated:December 21 2023
huggingface.co

Total runs: 181
Run Growth: 21
Growth Rate: 11.60%
Updated:March 13 2026
huggingface.co

Total runs: 180
Run Growth: 37
Growth Rate: 20.44%
Updated:July 02 2024