SparseVLMs

GumpestApache-2.0活跃维护

SparseVLM 是 ICML'25 与 TPAMI'26 论文的官方实现,通过稀疏化视觉 token 来降低视觉语言模型的计算开销,提升多模态推理效率。

[ICML'25][TPAMI'26] Official implementation of paper "SparseVLM" and "SparseVLM+".

v2.0发布于 2025-12-12 02:38 UTC289star22fork同步于 2026-11-07 07:31 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/Gumpest/SparseVLMs.git
cd SparseVLMs
conda create -n SparseVLMs python=3.10 -y
conda activate SparseVLMs
pip install -e .
pip install transformers==4.37.0
pip install flash_attn==2.3.3
硬件要求按 README 说明

README 未说明具体显存要求与 GPU 型号;安装步骤包含 flash_attn,通常需要 NVIDIA GPU,但 README 未明确写出。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

按问题提示自适应稀疏化视觉 token 的 VLM 推理加速方案,含 ICML'25 与 TPAMI'26 两版

SparseVLM 是 ICML'25 与 TPAMI'26 论文的官方实现,通过稀疏化视觉 token 来降低视觉语言模型的计算开销,提升多模态推理效率。

核心能力

  • 用问题提示引导视觉 patch 选择,而非文本无关的固定剪枝
  • 通过 RETAIN_TOKN 环境变量控制保留 token 数(192/128/96/64)
  • 设置 USE_VERSION=2_0 即可一键启用 SparseVLM+ 增强模式
  • 兼容 FlashAttention 2,支持更灵活的剪枝方式
  • 提供 MME、TextVQA、ScienceQA、MMBench、GQA 评测脚本

容易踩的坑

依赖版本被锁定为 transformers==4.37.0 与 flash_attn==2.3.3,版本不符容易出错;需按 LLaVA-Evaluation 文档另行下载多模态评测数据集;RETAIN_TOKN 仅内置 192/128/96/64 四档,其他数量需改 score.py。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

1 个版本v2.0
  1. v2.0SparseVLM+最新正式版2025-12-12 · 2025-12-12 02:38 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    SparseVLM+: Visual Token Sparsification with Improved Text-Visual Attention Pattern

    Peking University, Tsinghua University IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI), 2026

    SparseVLM: Visual Token Sparsification for Efficient Vision-Language Model Inference

    Peking University, UC Berkeley, Panasonic Holdings Corporation International Conference on Machine Learning (ICML), 2025

    📜 News

    🔥 [2026/07/30] Our SparseVLM+ is accepted by TPAMI 2026!

    🔥 [2025/12/11] We released new version SparseVLM+! Bring a Stronger Performance with Improved Text-Visual Attention Pattern!

    🔥 [2025/06/04] The sparsification code for VideoLLaVA is now open source! Please check the video branch.

    🔥 [2025/05/01] Our SparseVLM is accepted by ICML 2025!

    🔥 [2025/03/06] We released SparseVLM v1.5! Higher Accuracy, Flexible Pruning Manner, and Compatibility with FlashAttention 2!

    🔥 [2024/10/15] We released SparseVLM and its Project Page! The Code is now open-source! Please check the v1.5 branch for the latest version.

    ✒️ Contents

    👀 Overview

    In vision-language models (VLMs), visual tokens usually consume a significant amount of computational overhead, despite their sparser information density compared to text tokens. To address this, existing methods extract more compact image representations by modifying the image encoder or projector. While some recent works further sparsify vision tokens during the decoding, they still ignore the guidance from the language tokens, which contradicts the multimodality paradigm. We argue that visual tokens should be sparsified adaptively based on the question prompt, as the model might focus on different parts (e.g., foreground or background) when dealing with various questions, as shown in Figure below. Unlike previous methods with text-agnostic visual sparsification (c) e.g., recent FastV, our SparseVLM (b) is guided by question prompts to select relevant visual patches.

    👨‍💻 Preparation

    1. Clone this repository and navigate to SparseVLMs folder
    git clone https://github.com/Gumpest/SparseVLMs.git
    cd SparseVLMs
    
    1. Install necessary package
    conda create -n SparseVLMs python=3.10 -y
    conda activate SparseVLMs
    pip install -e .
    pip install transformers==4.37.0
    pip install flash_attn==2.3.3
    
    1. Download Multimodal Benchmark

    Please follow the detailed instruction in LLaVA-Evaluation.

    🎯 Basic Usage

    Specifically, setting RETAIN_TOKN in the environment variables indicates the number of tokens to be retained after the SparseVLM algorithm. It supports four numbers of tokens, including 192, 128, 96, and 64. If a specific number of tokens is required, please make modifications in ./llava/model/language_model/score.py

    1. Example for evaluating MME results (retain 192 tokens):
    RETAIN_TOKN=192 bash scripts/v1_5/eval/mme.sh
    
    1. Example for evaluating TextVQA results (retain 128 tokens):
    RETAIN_TOKN=128 bash scripts/v1_5/eval/textvqa.sh
    
    1. Example for evaluating ScienceQA results (retain 96 tokens):
    RETAIN_TOKN=96 bash scripts/v1_5/eval/sqa.sh
    
    1. Example for evaluating MMBench results (default 64 tokens):
    RETAIN_TOKN=64 bash scripts/v1_5/eval/mmbench.sh
    

    🛠️ One-Click Enable SparseVLM+ (V2.0 Mode)

    You can boost the performance of SparseVLM by enabling the V2.0 mode, which can be seamlessly enabled via an environment variable without modifying the code.

    1. Example for evaluating MME results (retain 192 tokens):
    USE_VERSION=2_0 RETAIN_TOKN=192 bash scripts/v1_5/eval/mme.sh
    
    1. Example for evaluating TextVQA results (retain 128 tokens):
    USE_VERSION=2_0 RETAIN_TOKN=128 bash scripts/v1_5/eval/textvqa.sh
    
    1. Example for evaluating MMBench results (retain 96 tokens):
    USE_VERSION=2_0 RETAIN_TOKN=96 bash scripts/v1_5/eval/mmbench.sh
    
    1. Example for evaluating GQA results (retain 64 tokens):
    USE_VERSION=2_0 RETAIN_TOKN=64 bash scripts/v1_5/eval/gqa.sh
    

    License

    This project is released under the Apache 2.0 license.

    Citation

    If you use SparseVLM in your research, please cite our work by using the following BibTeX entry:

    @inproceedings{zhang2024sparsevlm,
      title={SparseVLM: Visual Token Sparsification for Efficient Vision-Language Model Inference},
      author={Zhang, Yuan and Fan, Chun-Kai and Ma, Junpeng and Zheng, Wenzhao and Huang, Tao and Cheng, Kuan and Gudovskiy, Denis and Okuno, Tomoyuki and Nakata, Yohei and Keutzer, Kurt and others},
      booktitle={International Conference on Machine Learning},
      year={2025}
    }
    
    
    @article{zhang2026sparsevlmplus,
      title={SparseVLM+: Visual Token Sparsification with Improved Text-Visual Attention Pattern},
      author={Zhang, Yuan and Ma, Junpeng and Zhang, Qizhe and Fan, Chun-Kai and Zheng, Wenzhao and Cheng, Kuan and Lu, Jiwen and Zhang, Shanghang},
      journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
      year={2026}
    }
    
    

    Acknowledgment

    We extend our gratitude to the open-source efforts of TCFormer, LLaVA, MiniGemini and VideoLLaVA.