LLaMA-VID: An Image is Worth 2 Tokens in Large Language Models

Yanwei Li, Chengyao Wang, Jiaya Jia

Introduction

Vision Language Models (VLMs) like LLaVA and BLIP-2 have demonstrated remarkable capabilities in understanding and describing single images. However, extending these capabilities to long-form video remains a significant challenge due to "token bloat." Standard models typically represent a single image using dozens or even hundreds of tokens. When applied to high-frame-rate video, this approach quickly exhausts the context window of Large Language Models (LLMs), making it impossible to process hour-long content without extreme temporal downsampling or loss of detail.

LLaMA-VID addresses this bottleneck by introducing a novel architecture that represents each video frame using just two specialized tokens: a context token and a content token. This drastic reduction in token count allows the model to efficiently process long videos while maintaining state-of-the-art performance across both video and image benchmarks.

Methodology: The Dual-Token Strategy

The core innovation of LLaMA-VID is its dual-token generation strategy, which summarizes a frame into two distinct embeddings before passing them to the LLM.

The LLaMA-VID architecture, highlighting the generation of context and content tokens.
  1. Context Token: This is an instruction-guided token. The model uses a text decoder to generate a query based on the user's prompt. This query interacts with visual features via a "context attention" module, extracting only the information relevant to the specific question asked. For example, if a user asks about a "red car," the context token focuses the LLM's attention on that specific object.
  2. Content Token: This token captures the general visual cues of the frame. For video, global average pooling is typically used to condense the frame into a single token. For static images where spatial detail is more critical, this can be scaled up to include more tokens.

The Pipeline

The system utilizes a pre-trained Vision Transformer (EVA-G) as the visual encoder. A text decoder produces queries based on user input, and simple linear projectors map these context and content embeddings into the word embedding space of the Vicuna LLM. This streamlined pipeline allows for high efficiency, with a total processing time of roughly 6ms per frame on an A100 GPU.

Training and Datasets

LLaMA-VID undergoes a robust three-stage training process to ensure modality alignment and instruction-following capabilities:

  • Stage 1: Modality Alignment: The model is trained on 558K image-caption pairs and 232K video-caption pairs to align visual features with text embeddings.
  • Stage 2: Instruction Tuning: This stage uses a massive collection of 625K visual QA pairs, 98K video QA pairs, and 40K text conversations to refine the model's ability to answer complex questions.
  • Stage 3: Long Video Tuning (Optional): To handle extended narratives, the authors constructed a dataset of 15K long QA pairs, including 9K movie-level conversations derived from MovieNet scripts and synopses.

Key Results and Performance

LLaMA-VID demonstrates superior performance across a wide range of benchmarks, proving that efficiency does not have to come at the cost of accuracy.

Comparative performance of LLaMA-VID on video and image-based benchmarks.
  • Video Benchmarks: LLaMA-VID (7B) achieved 69.7% accuracy on MSVD-QA and 57.7% on MSRVTT-QA, outperforming established models like BT-Adapter and Video-ChatGPT.
  • Long-Form Understanding: On the EgoSchema benchmark, which tests long-video comprehension, LLaMA-VID reached 41.2% accuracy, significantly surpassing InternVideo (31.4%).
  • Image Benchmarks: Despite its video optimization, the model outperformed LLaVA-1.5 on several image benchmarks, including GQA and VizWiz, indicating that the instruction-guided context token provides valuable detail even in static contexts.

Conclusion and Future Work

LLaMA-VID proves that "an image is worth 2 tokens" for many practical LLM applications. By focusing on instruction-guided compression, the model can support videos over three hours long (roughly 64K tokens) on standard hardware. While the current 2-token strategy is highly efficient, the authors note that it may occasionally lose fine-grained spatial details, such as small text. Future work will explore methods to maintain dense spatial information outside the primary context window and dynamic token fusion to adjust token counts based on frame complexity.

Summary updated

BibTeX
@inproceedings{li2024llama,
  author = {Yanwei Li and Chengyao Wang and Jiaya Jia},
  title = {{LLaMA-VID: An Image is Worth 2 Tokens in Large Language Models}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-72952-2\_19},
}
Figure