库名称: transformers
许可证: apache-2.0
数据集:
- HuggingFaceM4/the_cauldron
- HuggingFaceM4/Docmatix
- lmms-lab/LLaVA-OneVision-Data
- lmms-lab/M4-Instruct-Data
- HuggingFaceFV/finevideo
- MAmmoTH-VL/MAmmoTH-VL-Instruct-12M
- lmms-lab/LLaVA-Video-178K
- orrzohar/Video-STaR
- Mutonix/Vript
- TIGER-Lab/VISTA-400K
- Enxin/MovieChat-1K_train
- ShareGPT4Video/ShareGPT4Video
任务标签: 图像文本到文本
语言:
- 英语
基础模型:
- HuggingFaceTB/SmolVLM-500M-Instruct
SmolVLM2-500M-Video
SmolVLM2-500M-Video 是一款轻量级多模态模型,专为分析视频内容而设计。该模型可处理视频、图像和文本输入以生成文本输出——无论是回答关于媒体文件的问题、比较视觉内容,还是从图像中转录文本。尽管体积小巧(视频推理仅需1.8GB GPU显存),但在复杂多模态任务上表现强劲。这种高效性使其特别适合计算资源有限的设备端应用。
模型概览
- 开发团队: Hugging Face 🤗
- 模型类型: 多模态模型(图像/多图像/视频/文本)
- 支持语言(NLP): 英语
- 许可证: Apache 2.0
- 架构: 基于 Idefics3(详见技术摘要)
资源
用途
SmolVLM2 可用于多模态(视频/图像/文本)任务的推理,输入包含文本查询及视频或一个/多个图像。文本与媒体文件可任意交错排列,支持字幕生成、视觉问答、基于视觉内容的故事叙述等任务。该模型不支持图像或视频生成。
如需针对特定任务微调SmolVLM2,可参考微调教程。
评估
我们在以下科学基准测试中评估了SmolVLM2系列的性能:
模型大小 |
Video-MME |
MLVU |
MVBench |
2.2B |
52.1 |
55.2 |
46.27 |
500M |
42.2 |
47.3 |
39.73 |
256M |
33.7 |
40.6 |
32.7 |
快速开始
使用transformers加载、推理和微调SmolVLM前,请确保已安装num2words、flash-attn和最新版transformers。加载方式如下:
from transformers import AutoProcessor, AutoModelForImageTextToText
import torch
model_path = "HuggingFaceTB/SmolVLM2-500M-Video-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": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
{"type": "text", "text": "请描述这张图片?"},
]
},
]
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])
视频推理
使用视频推理前请安装decord:
messages = [
{
"role": "user",
"content": [
{"type": "video", "path": "视频路径.mp4"},
{"type": "text", "text": "详细描述这段视频"}
]
},
]
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])
多图像交错推理
通过聊天模板交错处理多组媒体与文本:
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "这两张图片有何相似之处?"},
{"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])
模型优化
滥用与超范围使用
SmolVLM不适用于高风险场景或影响个人福祉/生计的关键决策。模型可能生成看似真实但不准确的内容。滥用行为包括但不限于:
- 禁止用途:
- 对个人评分(如就业、教育、信贷)
- 关键自动化决策
- 生成不可靠事实内容
- 恶意行为:
- 垃圾信息生成
- 虚假宣传活动
- 骚扰或滥用
- 未经授权的监控
许可证
SmolVLM2基于SigLIP图像编码器和SmolLM2文本解码器构建。
我们依据Apache 2.0许可证发布SmolVLM2模型。
引用信息
引用格式:
@article{marafioti2025smolvlm,
title={SmolVLM: 重新定义轻量高效的多模态模型},
author={Andrés Marafioti等},
journal={arXiv预印本 arXiv:2504.05299},
year={2025}
}
训练数据
SmolVLM2使用来自10个数据集的330万样本进行训练,包括:LlaVa Onevision、M4-Instruct、Mammoth等。
数据模态分布
数据类型 |
占比 |
图像 |
34.4% |
文本 |
20.2% |
视频 |
33.0% |
多图像 |
12.3% |
各模态数据集细分
文本数据集
数据集 |
占比 |
llava-onevision/magpie_pro_ft3_80b_mt |
6.8% |
多图像数据集
数据集 |
占比 |
m4-instruct-data/m4_instruct_multiimage |
10.4% |
(其他数据集细分表格依此类推)