说明文档
I detect translation intent — straightforward text translation with formatting preservation. This is a writing task that requires careful translation while maintaining code blocks, links, and markdown structure intact.
Let me delegate this to a writing specialist: <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/SmolVLM2_banner.png" width="800" height="auto" alt="Image description">
SmolVLM2-256M-Video
SmolVLM2-256M-Video 是一款轻量级多模态模型,专为分析视频内容而设计。该模型可处理视频、图像和文本输入,生成文本输出,无论是回答关于媒体文件的问题、比较视觉内容,还是从图像中转录文字。尽管体积小巧,视频推理仅需 1.38GB GPU 显存。这种高效性使其特别适合需要在特定领域进行微调且计算资源有限的端侧应用场景。
模型摘要
- 开发者: Hugging Face 🤗
- 模型类型: 多模态模型(图像/多图像/视频/文本)
- 语言: 英语
- 许可证: 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-256M-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": "Can you describe this image?"},
]
},
]
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 进行视频推理,请确保已安装 decord。
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])
多图像交错推理
你可以使用聊天模板将多个媒体与文本交错排列。
import torch
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "What is the similarity 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])
模型优化
误用和超出范围的使用
SmolVLM 不适用于高风险场景或影响个人福祉或生计的关键决策过程。模型可能会生成看似事实但可能不准确的内容。误用包括但不限于:
- 禁止用途:
- 评估或打分个人(例如就业、教育、信贷)
- 关键自动化决策
- 生成不可靠的事实内容
- 恶意活动:
- 垃圾信息生成
- 虚假信息传播
- 骚扰或滥用
- 未经授权的监控
许可证
SmolVLM2 基于 SigLIP 作为图像编码器和 SmolLM2 作为文本解码器部分构建。我们在 Apache 2.0 许可证下发布 SmolVLM2 检查点。
引用信息
你可以按以下方式引用我们:
@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}
}
训练数据
SmolVLM2 使用了来自十个不同数据集的 330 万个样本进行训练:LlaVa Onevision、M4-Instruct、Mammoth、LlaVa Video 178K、FineVideo、VideoStar、VRipt、Vista-400K、MovieChat 和 ShareGPT4Video。
在以下图表中,我们概述了跨模态的样本分布以及这些样本的来源。
<!-- <center><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolvlm2_data_split.png" width="auto" height="auto" alt="Image description"> </center>
详情
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolvlm2_datadetails.png" width="auto" height="auto" alt="Image description"> -->
各模态数据分布
| 数据类型 | 占比 |
|---|---|
| 图像 | 34.4% |
| 文本 | 20.2% |
| 视频 | 33.0% |
| 多图像 | 12.3% |
各模态细粒度数据集切片
文本数据集
| 数据集 | 占比 |
|---|---|
| llava-onevision/magpie_pro_ft3_80b_mt | 6.8% |
| llava-onevision/magpie_pro_ft3_80b_tt | 6.8% |
| llava-onevision/magpie_pro_qwen2_72b_tt | 5.8% |
| llava-onevision/mathqa | 0.9% |
多图像数据集
| 数据集 | 占比 |
|---|---|
| m4-instruct-data/m4_instruct_multiimage | 10.4% |
| mammoth/multiimage-cap6 | 1.9% |
图像数据集
| 数据集 | 占比 |
|---|---|
| llava-onevision/other | 17.4% |
| llava-onevision/vision_flan | 3.9% |
| llava-onevision/mavis_math_metagen | 2.6% |
| llava-onevision/mavis_math_rule_geo | 2.5% |
| llava-onevision/sharegpt4o | 1.7% |
| llava-onevision/sharegpt4v_coco | 1.5% |
| llava-onevision/image_textualization | 1.3% |
| llava-onevision/sharegpt4v_llava | 0.9% |
| llava-onevision/mapqa | 0.9% |
| llava-onevision/qa | 0.8% |
| llava-onevision/textocr | 0.8% |
视频数据集
| 数据集 | 占比 |
|---|---|
| llava-video-178k/1-2m | 7.3% |
| llava-video-178k/2-3m | 7.0% |
| other-video/combined | 5.7% |
| llava-video-178k/hound | 4.4% |
| llava-video-178k/0-30s | 2.4% |
| video-star/starb | 2.2% |
| vista-400k/combined | 2.2% |
| vript/long | 1.0% |
| ShareGPT4Video/all | 0.8% |
HuggingFaceTB/SmolVLM2-256M-Video-Instruct
作者 HuggingFaceTB
创建时间: 2025-02-11 07:06:01+00:00
更新时间: 2025-04-08 07:25:59+00:00
在 Hugging Face 上查看