Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1048e9a

Browse files
MHRDYN7vasqu
andauthored
Add Videoprism (#39895)
* inference returns correct logits for base model * modular code runs correctly * large backbone model added * a rough random forward pass * converted and uploaded both lvt weights * updated lvt checkpoints, modeling code gives the correct logits for base * everything works fine with modular convertion at this point * standardization of the VideoPrismModel code * added base classes for model output holders, but signature needs to be fixed * correctly added slow videoprism tokenizer using modular on top of t5 tokenizer * temporal interpolation works fine but F.interpolate does not give the exact values of jax.image.resize * added fast tokenizer based on t5 * refactored code for VideoPrismModel runs fine on initialised weights * converted lvt base weights, but model outsputs are not correct after refactor * perdimscale fixed and lvt base weights updated, inference works correctly * refactored perdimscale + sinusoidal posemb to get correct lvt logits * fixed VideoPrismTokenizerFast from convert_slow_tokenizer.py * borrowed l2norm from qwen3_next using copied from * modular VideoPrismVideoProcessor * added VideoPrismForVideoClassification * spatial and temporal interpolation fixed to follow jax implementation exactly * both models working again * refactor part 1: separate configs + 4 encoders * refactor part 2: softcap, per_dim_scale, l2norm * softcap is used in all models by default * script with prints * without prints * no softcap for attn pool; successful inference for lvt base/large; updated weights uploaded * refactor part 3: new model names, auto model/config, v5 practices; everything works perfectly * tokenizer adapted to v5 and it works fine * tokenizer clean up * pretrained should not inherit from vivit; fixup * vision tests (fast+slow) * text model tests * VideoPrismClipModel tests * video + classification model tests; cleaner modular files + interpolation support in all models * processor added; interpolation test added * some changes * some more changes * [fix] update video processing imports and add vision availability check * [refactor] add support for additional kwargs in VideoPrism model forward methods * allow kwargs to flow through the clip model * docstrings added + docs comlpeted * after modular file conversion * fix try 1 * fix try 2 * tokenizer automapping * cleaner files, better docs * convert modular file * updated doc date * small fix in the video classification model * trying to move everything to gpu: attempt 1 * attempt 3: moved softplus from init to forward * refactored softplu; new tests for video classificationmodel, all passing * fix-repo * fix doc date * lecun_normal_ -> init.lecun_normal_ * date update * refactor part 1: mostly cleanup in modular file * updated all checkpoints * 34 more tests to go * 15 more tests to go * 7 to go * all passing, next classification tests * lgtm for now * all slow tests passing * docstrings 1 * docstrings 2 * docstrings 3 * docstrings 4 * last few changes in the test file * test file nits * classification test fix * nits * half job done: base models converted + failing tests for text embed class * all good now * doc updated * post config attribute pr: modular files converted again, a few issues left * fix repo * strict * kept projection_size in text config * removed projection_size completely from post_init as well * is_causal and misc * correct logits for video model test inserted * added cuda logits in test file * refactor 1 * refactor 2 * refactor 3 * correct cuda logits + eager logits for classification model * the main file which was not added to prev commit * vit refactor incorporated + weights updated * converted the classification weights + test improvements:1 * nits * nits * pooler_output_size issue fixed; all tests passing * today's date * vivit restored, nits * nits * fix linter * doc * new date * new tests for tokenizer/processor * misc. refactor part 1 * misc. refactor part 2 * misc. refactor part 3 * nits * date * fa layernorm fix + new tensors for tennis video in test file * cleaner tests * nits * misc. small fixes * nits * extra tensor chunks for bicubic * new atol for video model * correct image link * resolve * correct checkpoints with revisions --------- Co-authored-by: vasqu <[email protected]>
1 parent a6f8ab7 commit 1048e9a

20 files changed

Lines changed: 4175 additions & 0 deletions

‎docs/source/en/_toctree.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,8 @@
11811181
title: V-JEPA 2
11821182
- local: model_doc/videomae
11831183
title: VideoMAE
1184+
- local: model_doc/videoprism
1185+
title: VideoPrism
11841186
- local: model_doc/vivit
11851187
title: ViViT
11861188
title: Video models
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<!--Copyright 2026 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
*This model was published in HF papers on 2024-02-20 and contributed to Hugging Face Transformers on 2026-06-19.*
13+
14+
<div style="float: right;">
15+
<div class="flex flex-wrap space-x-1">
16+
<img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat">
17+
</div>
18+
</div>
19+
20+
# VideoPrism
21+
22+
The VideoPrism model was proposed in the paper [VideoPrism: A Foundational Visual Encoder for Video Understanding](https://huggingface.co/papers/2402.13217) by Google DeepMind ([blog post](https://research.google/blog/videoprism-a-foundational-visual-encoder-for-video-understanding/)).
23+
24+
VideoPrism is a general-purpose video encoder that tackles diverse video understanding tasks with a single frozen model. The model is pretrained on a large-scale heterogeneous corpus containing 36M high-quality video-caption pairs and 582M video clips with noisy parallel text (e.g., ASR transcripts). The pretraining approach improves upon masked autoencoding through global-local distillation of semantic video embeddings and a token shuffling scheme, enabling the model to focus primarily on the video modality while leveraging text associated with videos. VideoPrism achieves state-of-the-art performance on 31 out of 33 video understanding benchmarks across four broad task groups, from web video question answering to computer vision for science.
25+
26+
<div class="flex justify-center">
27+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/VideoPrism_Overview.jpeg" alt="drawing" width="600"/>
28+
</div>
29+
30+
You can find all original VideoPrism checkpoints under the [VideoPrism](https://huggingface.co/collections/google/videoprism) collection.
31+
32+
Notes:
33+
34+
- VideoPrism uses a factorized spatio-temporal encoder architecture, processing videos through separate spatial and temporal transformers.
35+
- The model supports video-text contrastive learning through `VideoPrismClipModel`, which combines a video encoder and a text encoder. `VideoPrismConfig` must be used with this model.
36+
- For video classification tasks, use `VideoPrismForVideoClassification` which adds a classification head on top of the video encoder. `VideoPrismVisionConfig` must be used with this model.
37+
- The vision encoder can be used standalone via `VideoPrismVisionModel` for extracting video features. `VideoPrismVisionConfig` must be used with this model.
38+
- The default input resolution is 288x288 pixels with 16 frames per video clip for the base models and 8 frames for the large models. Set interpolate_pos_encoding=True to use the models with custom resolution and frames per clip.
39+
40+
This model was contributed by [MHRDYN7](https://github.com/MHRDYN7) and reviewed by [vasqu](https://github.com/vasqu) & [zucchini-nlp](https://github.com/zucchini-nlp).
41+
The original code can be found [here](https://github.com/google-deepmind/videoprism).
42+
43+
44+
## Usage example
45+
46+
The snippet below shows how to load the VideoPrismVisionModel for feature extraction using the `AutoModel` class.
47+
48+
```py
49+
import torch
50+
from transformers import AutoModel, AutoVideoProcessor
51+
52+
processor = AutoVideoProcessor.from_pretrained("google/videoprism-base-f16r288", revision="refs/pr/4")
53+
model = AutoModel.from_pretrained(
54+
"google/videoprism-base-f16r288",
55+
revision="refs/pr/4",
56+
device_map="auto",
57+
# use "flash_attention_2" for faster inference on supported hardware
58+
# attn_implementation="flash_attention_2"
59+
)
60+
61+
video_url = "https://huggingface.co/datasets/nateraw/kinetics-mini/resolve/main/val/archery/-Qz25rXdMjE_000014_000024.mp4"
62+
63+
# when do_sample_frames=True, 16/8 frames will be sampled by default depending on the checkpoint size base/large.
64+
processed_video_inputs = processor(videos=[video_url], return_metadata=True, do_sample_frames=True)
65+
video_metadata = processed_video_inputs["video_metadata"]
66+
video_inputs = processed_video_inputs["pixel_values_videos"].to(model.device)
67+
outputs = model(video_inputs)
68+
69+
# VideoPrism encoder outputs
70+
encoder_outputs = outputs.last_hidden_state
71+
72+
```
73+
74+
75+
## VideoPrismVisionConfig
76+
77+
[[autodoc]] VideoPrismVisionConfig
78+
79+
## VideoPrismTextConfig
80+
81+
[[autodoc]] VideoPrismTextConfig
82+
83+
## VideoPrismConfig
84+
85+
[[autodoc]] VideoPrismConfig
86+
87+
## VideoPrismTokenizer
88+
89+
[[autodoc]] VideoPrismTokenizer
90+
91+
## VideoPrismProcessor
92+
93+
[[autodoc]] VideoPrismProcessor
94+
95+
## VideoPrismVisionModel
96+
97+
[[autodoc]] VideoPrismVisionModel
98+
- forward
99+
100+
## VideoPrismVideoModel
101+
102+
[[autodoc]] VideoPrismVideoModel
103+
- forward
104+
105+
## VideoPrismTextModel
106+
107+
[[autodoc]] VideoPrismTextModel
108+
- forward
109+
110+
## VideoPrismClipModel
111+
112+
[[autodoc]] VideoPrismClipModel
113+
- forward
114+
115+
## VideoPrismForVideoClassification
116+
117+
[[autodoc]] VideoPrismForVideoClassification
118+
- forward

‎src/transformers/convert_slow_tokenizer.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,11 @@ def post_processor(self):
13711371
)
13721372

13731373

1374+
class VideoPrismConverter(T5Converter):
1375+
def post_processor(self):
1376+
return None
1377+
1378+
13741379
class WhisperConverter(Converter):
13751380
def converted(self) -> Tokenizer:
13761381
vocab = self.original_tokenizer.encoder
@@ -2100,6 +2105,7 @@ def converted(self) -> Tokenizer:
21002105
"SqueezeBertTokenizer": BertConverter,
21012106
"T5Tokenizer": T5Converter,
21022107
"UdopTokenizer": UdopConverter,
2108+
"VideoPrismTokenizer": VideoPrismConverter,
21032109
"WhisperTokenizer": WhisperConverter,
21042110
"XLMRobertaTokenizer": XLMRobertaConverter,
21052111
"XLNetTokenizer": XLNetConverter,

‎src/transformers/models/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@
456456
from .video_llava import *
457457
from .videomae import *
458458
from .videomt import *
459+
from .videoprism import *
459460
from .vilt import *
460461
from .vipllava import *
461462
from .vision_encoder_decoder import *

‎src/transformers/models/auto/auto_mappings.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@
633633
("video_llava", "VideoLlavaConfig"),
634634
("videomae", "VideoMAEConfig"),
635635
("videomt", "VideomtConfig"),
636+
("videoprism", "VideoPrismConfig"),
637+
("videoprism_text_model", "VideoPrismTextConfig"),
638+
("videoprism_vision_model", "VideoPrismVisionConfig"),
636639
("vilt", "ViltConfig"),
637640
("vipllava", "VipLlavaConfig"),
638641
("vision-encoder-decoder", "VisionEncoderDecoderConfig"),
@@ -890,6 +893,8 @@
890893
("unispeech-sat", "unispeech_sat"),
891894
("uvdoc_backbone", "uvdoc"),
892895
("video_llama_3_vision", "video_llama_3"),
896+
("videoprism_text_model", "videoprism"),
897+
("videoprism_vision_model", "videoprism"),
893898
("vision-encoder-decoder", "vision_encoder_decoder"),
894899
("vision-text-dual-encoder", "vision_text_dual_encoder"),
895900
("voxtral_encoder", "voxtral"),
@@ -1088,6 +1093,7 @@
10881093
("vibevoice_asr", "VibeVoiceAsrProcessor"),
10891094
("video_llama_3", "VideoLlama3Processor"),
10901095
("video_llava", "VideoLlavaProcessor"),
1096+
("videoprism", "VideoPrismProcessor"),
10911097
("vilt", "ViltProcessor"),
10921098
("vision-text-dual-encoder", "VisionTextDualEncoderProcessor"),
10931099
("voxtral", "VoxtralProcessor"),

‎src/transformers/models/auto/modeling_auto.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
504504
("video_llama_3_vision", "VideoLlama3VisionModel"),
505505
("video_llava", "VideoLlavaModel"),
506506
("videomae", "VideoMAEModel"),
507+
("videoprism", "VideoPrismClipModel"),
508+
("videoprism_vision_model", "VideoPrismVisionModel"),
507509
("vilt", "ViltModel"),
508510
("vipllava", "VipLlavaModel"),
509511
("vision-text-dual-encoder", "VisionTextDualEncoderModel"),
@@ -866,6 +868,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
866868
("timm_backbone", "TimmBackbone"),
867869
("timm_wrapper", "TimmWrapperModel"),
868870
("videomae", "VideoMAEModel"),
871+
("videoprism_vision_model", "VideoPrismVisionModel"),
869872
("vit", "ViTModel"),
870873
("vit_mae", "ViTMAEModel"),
871874
("vit_msn", "ViTMSNModel"),
@@ -1003,6 +1006,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
10031006
[
10041007
("timesformer", "TimesformerForVideoClassification"),
10051008
("videomae", "VideoMAEForVideoClassification"),
1009+
("videoprism_vision_model", "VideoPrismForVideoClassification"),
10061010
("vivit", "VivitForVideoClassification"),
10071011
("vjepa2", "VJEPA2ForVideoClassification"),
10081012
]
@@ -1794,6 +1798,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
17941798
("metaclip_2", "MetaClip2Model"),
17951799
("siglip", "SiglipModel"),
17961800
("siglip2", "Siglip2Model"),
1801+
("videoprism", "VideoPrismClipModel"),
17971802
]
17981803
)
17991804

‎src/transformers/models/auto/tokenization_auto.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
("umt5", "TokenizersBackend" if is_tokenizers_available() else None),
322322
("unispeech", "Wav2Vec2CTCTokenizer"),
323323
("unispeech-sat", "Wav2Vec2CTCTokenizer"),
324+
("videoprism", "VideoPrismTokenizer" if is_tokenizers_available() else None),
324325
("vilt", "BertTokenizer" if is_tokenizers_available() else None),
325326
("visual_bert", "BertTokenizer" if is_tokenizers_available() else None),
326327
("vits", "VitsTokenizer"),

‎src/transformers/models/auto/video_processing_auto.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
("qwen3_5_moe", "Qwen3VLVideoProcessor"),
6565
("qwen3_omni_moe", "Qwen2VLVideoProcessor"),
6666
("qwen3_vl_moe", "Qwen3VLVideoProcessor"),
67+
("videoprism", "LlavaOnevisionVideoProcessor"),
6768
]
6869
)
6970
VIDEO_PROCESSOR_MAPPING_NAMES.update(MISSING_VIDEO_PROCESSOR_MAPPING_NAMES)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2026 The HuggingFace Team. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from typing import TYPE_CHECKING
15+
16+
from ...utils import _LazyModule
17+
from ...utils.import_utils import define_import_structure
18+
19+
20+
if TYPE_CHECKING:
21+
from .configuration_videoprism import *
22+
from .modeling_videoprism import *
23+
from .processing_videoprism import *
24+
from .tokenization_videoprism import *
25+
else:
26+
import sys
27+
28+
_file = globals()["__file__"]
29+
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)

0 commit comments

Comments
 (0)