SmolVLM2:将视频理解带到每一台设备
TL;DR:SmolVLM 现在可以观看 📺,并且具有更好的视觉理解能力
SmolVLM2 代表着我们对视频理解方式的根本性转变——从需要大量计算资源的大型模型,转向可以在任何地方运行的高效模型。我们的目标很简单:让视频理解在所有设备和用例中都可访问,从手机到服务器。
我们发布了三种大小的模型(2.2B、500M 和 256M),并从第一天起就支持 MLX(Python **和** Swift API)。所有模型和演示都可以在这个集合中找到。
想立即尝试 SmolVLM2 吗?请查看我们的交互式聊天界面,您可以通过简单直观的界面测试 SmolVLM2 2.2B 的视觉和视频理解能力。
目录
技术细节
我们推出了三款新模型,参数分别为 256M、500M 和 2.2B。2.2B 模型是视觉和视频任务的首选,而 500M 和 256M 模型代表着**有史以来发布的最轻量级视频语言模型**。
虽然它们的尺寸很小,但其内存消耗却优于任何现有模型。在 Video-MME(视频领域的权威科学基准)上,SmolVLM2 加入了 2B 范围的前沿模型家族,并且我们在更小模型领域处于领先地位。

Video-MME 作为一个综合基准脱颖而出,因为它广泛涵盖了各种视频类型、不同时长(11 秒到 1 小时)、多种数据模态(包括字幕和音频),以及涵盖 900 部视频(总时长 254 小时)的高质量专家注释。在此了解更多信息:https://video-mme.github.io/home_page.html。
SmolVLM2 2.2B:我们视觉和视频领域的新明星选手
与之前的 SmolVLM 系列相比,我们的新 2.2B 模型在解决图像数学问题、识别照片中的文本、理解复杂图表以及处理科学视觉问题方面表现更佳。这体现在模型在不同基准测试中的性能上。

在视频任务方面,2.2B 物超所值。在我们评估的各种科学基准中,我们想强调其在 Video-MME 上的表现,它超越了所有现有 2B 模型。
我们之所以能够在视频/图像性能上取得良好的平衡,得益于在 Apollo: An Exploration of Video Understanding in Large Multimodal Models 中发表的数据混合学习成果。
它的内存效率如此之高,甚至可以在免费的 Google Colab 上运行。
Python 代码
# Install transformers from `main` or from this stable branch:
!pip install git+https://github.com/huggingface/transformers@v4.49.0-SmolVLM-2
from transformers import AutoProcessor, AutoModelForImageTextToText
import torch
model_path = "HuggingFaceTB/SmolVLM2-2.2B-Instruct"
processor = AutoProcessor.from_pretrained(model_path)
model = AutoModelForImageTextToText.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
_attn_implementation="flash_attention_2"
).to("cuda")
messages = [
{
"role": "user",
"content": [
{"type": "video", "path": "path_to_video.mp4"},
{"type": "text", "text": "Describe this video in detail"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device, dtype=torch.bfloat16)
generated_ids = model.generate(**inputs, do_sample=False, max_new_tokens=64)
generated_texts = processor.batch_decode(
generated_ids,
skip_special_tokens=True,
)
print(generated_texts[0])
更小巧:认识 500M 和 256M 视频模型
迄今为止,没有人敢发布如此小巧的视频模型。
我们新的 SmolVLM2-500M-Video-Instruct 模型具有非常接近 SmolVLM 2.2B 的视频功能,但尺寸却小得多:我们以不到四分之一的参数实现了相同的视频理解能力🤯。
还有我们的小实验,SmolVLM2-256M-Video-Instruct。可以把它想象成我们的“如果”项目——如果我们能将小型模型的界限推得更远呢?从几周前 IBM 利用我们的基础 SmolVLM-256M-Instruct 模型取得的成就中汲取灵感,我们想看看视频理解能走多远。虽然它更像是一个实验性发布,但我们希望它能激发一些创意应用和专业的微调项目。
SmolVLM2 演示应用套件
为了展示我们小型视频模型的愿景,我们构建了三个实用应用程序,展示了这些模型的多功能性。
iPhone 视频理解
|
我们开发了一款 iPhone 应用程序,可完全在本地运行 SmolVLM2。通过使用我们的 500M 模型,用户可以直接在设备上分析和理解视频内容——无需云端。对使用本地运行的 AI 模型构建 iPhone 视频处理应用程序感兴趣吗?我们即将发布它——填写此表单即可与我们一起测试和构建! |
VLC 媒体播放器集成
|
我们正与 VLC 媒体播放器合作,集成 SmolVLM2,以提供智能视频片段描述和导航。这种集成允许用户语义化地搜索视频内容,根据自然语言描述直接跳转到相关部分。虽然这项工作仍在进行中,但您可以在此空间中尝试当前的播放列表生成器原型。 |
视频精彩片段生成器
|
此应用程序作为一个 Hugging Face Space 提供,它能够处理长视频(1 小时以上),并自动提取最精彩的时刻。我们已经对足球比赛和其他长时间事件进行了广泛测试,使其成为内容摘要的强大工具。在我们的演示空间中亲自尝试一下。 |
使用 Transformers 和 MLX 运行 SmolVLM2
我们从第一天起就支持使用 Transformers 和 MLX 运行 SmolVLM2。在本节中,您可以找到不同的推理方案以及视频和多图像教程。
Transformers
使用 SmolVLM2 模型进行推理最简单的方法是通过对话式 API – 应用聊天模板会自动处理所有输入。
您可以按如下方式加载模型。
# Install transformers from `main` or from this stable branch:
!pip install git+https://github.com/huggingface/transformers@v4.49.0-SmolVLM-2
from transformers import AutoProcessor, AutoModelForImageTextToText
import torch
processor = AutoProcessor.from_pretrained(model_path)
model = AutoModelForImageTextToText.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
_attn_implementation="flash_attention_2"
).to("cuda")
视频推理
您可以通过传递 {"type": "video", "path": {video_path}}
将视频传递给聊天模板。有关完整示例,请参见下文。
messages = [
{
"role": "user",
"content": [
{"type": "video", "path": "path_to_video.mp4"},
{"type": "text", "text": "Describe this video in detail"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device, dtype=torch.bfloat16)
generated_ids = model.generate(**inputs, do_sample=False, max_new_tokens=64)
generated_texts = processor.batch_decode(
generated_ids,
skip_special_tokens=True,
)
print(generated_texts[0])
多图像推理
除了视频,SmolVLM2 还支持多图像对话。您可以通过聊天模板使用相同的 API,提供每个图像的文件系统路径、URL 或 `PIL.Image` 对象。
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "What are the differences between these two images?"},
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"},
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device, dtype=torch.bfloat16)
generated_ids = model.generate(**inputs, do_sample=False, max_new_tokens=64)
generated_texts = processor.batch_decode(
generated_ids,
skip_special_tokens=True,
)
print(generated_texts[0])
使用 MLX 进行推理
要在 Apple Silicon 设备上使用 Python 运行 SmolVLM2 和 MLX,您可以使用出色的 mlx-vlm 库。首先,您需要使用以下命令从 此分支 安装 `mlx-vlm`
pip install git+https://github.com/pcuenca/mlx-vlm.git@smolvlm
然后,您可以使用以下一行代码对单个图像进行推理,该代码使用了 SmolVLM2 的未量化 500M 版本
python -m mlx_vlm.generate \
--model mlx-community/SmolVLM2-500M-Video-Instruct-mlx \
--image https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg \
--prompt "Can you describe this image?"
我们还创建了一个简单的脚本用于视频理解。您可以按如下方式使用它
python -m mlx_vlm.smolvlm_video_generate \
--model mlx-community/SmolVLM2-500M-Video-Instruct-mlx \
--system "Focus only on describing the key dramatic action or notable event occurring in this video segment. Skip general context or scene-setting details unless they are crucial to understanding the main action." \
--prompt "What is happening in this video?" \
--video /Users/pedro/Downloads/IMG_2855.mov \
--prompt "Can you describe this image?"
请注意,系统提示对于模型实现所需行为非常重要。例如,您可以使用它来描述所有场景和过渡,或者提供一个关于正在发生的事情的一句话摘要。
Swift MLX
Swift 语言也通过 mlx-swift-examples 仓库 得到支持,我们用它来构建我们的 iPhone 应用程序。
在 我们正在进行的 PR 完成并合并之前,您必须从这个分支编译项目,然后您可以在 Mac 上使用 `llm-tool` CLI,如下所示。
用于图像推理
./mlx-run --debug llm-tool \
--model mlx-community/SmolVLM2-500M-Video-Instruct-mlx \
--prompt "Can you describe this image?" \
--image https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg \
--temperature 0.7 --top-p 0.9 --max-tokens 100
还支持视频分析,以及提供系统提示。我们发现系统提示对于视频理解特别有帮助,可以使模型达到我们感兴趣的所需详细程度。这是一个视频推理示例
./mlx-run --debug llm-tool \
--model mlx-community/SmolVLM2-500M-Video-Instruct-mlx \
--system "Focus only on describing the key dramatic action or notable event occurring in this video segment. Skip general context or scene-setting details unless they are crucial to understanding the main action." \
--prompt "What is happening in this video?" \
--video /Users/pedro/Downloads/IMG_2855.mov \
--temperature 0.7 --top-p 0.9 --max-tokens 100
如果您使用 MLX 和 Swift 将 SmolVLM2 集成到您的应用程序中,我们非常乐意了解!请随时在下面的评论区给我们留言!
微调 SmolVLM2
您可以使用 transformers 🤗 微调 SmolVLM2 视频模型。为了演示目的,我们已经在 Colab 上使用 VideoFeedback 数据集中的视频-字幕对微调了 500M 变体。由于 500M 变体很小,最好应用完全微调而不是 QLoRA 或 LoRA,同时您可以尝试在 cB 变体上应用 QLoRA。您可以在此处找到微调笔记本。
引用信息
您可以按以下方式引用我们
@article{marafioti2025smolvlm,
title={SmolVLM: Redefining small and efficient multimodal models},
author={Andrés Marafioti and Orr Zohar and Miquel Farré and Merve Noyan and Elie Bakouch and Pedro Cuenca and Cyril Zakka and Loubna Ben Allal and Anton Lozhkov and Nouamane Tazi and Vaibhav Srivastav and Joshua Lochner and Hugo Larcher and Mathieu Morlon and Lewis Tunstall and Leandro von Werra and Thomas Wolf},
journal={arXiv preprint arXiv:2504.05299},
year={2025}
}
阅读更多
我们感谢 Raushan Turganbay、Arthur Zucker 和 Pablo Montalvo Leroux 为 transformers 贡献了该模型。
我们期待看到您使用 SmolVLM2 构建的所有内容!如果您想了解更多关于 SmolVLM 模型家族的信息,请随时阅读以下内容: