vllm.models.nemotron_shortcut.nvidia.vision
¶
Nemotron Shortcut vision-language model.
The vision tower is vLLM's Pixtral encoder and the projector is Mistral3's spatial merger, in front of the Nemotron Shortcut language model.
Classes:
-
NemotronShortcutMultiModalProcessor– -
NemotronShortcutProcessingInfo– -
NemotronShortcutVideoBackend–Video loader that samples frames with the NeMo RL training rule.
-
NemotronShortcutVisionModel–vLLM's Pixtral encoder, plus
video_patch_convfor video tubelets.
Functions:
-
get_video_temporal_patch_size–Return the top-level
video_temporal_patch_sizeT of the config. -
group_frames_into_tubelets–Stack T consecutive
[C, H, W]frames into[T * C, H, W]tubelets. -
loader_frame_selection–Positions in the decoded frames, and labels, of the training sample.
-
pad_to_temporal_multiple–Repeat the last item until the length is a multiple of T.
-
profile_video_num_frames–Frame count of the profiling video when T frames share one token grid.
-
select_video_frame_count–Number of decoded frames to keep for a video of tubelets of T frames.
-
training_video_frame_times–Source frame index and time label of each frame that training samples.
-
video_frame_timestamps–Return the time in seconds of each selected frame of a decoded video.
-
video_prompt_text–Build the training video prompt with one line per tubelet.
-
video_prompt_token_ids–Token IDs of the per-tubelet video prompt.
NemotronShortcutMultiModalProcessor
¶
Bases: Mistral3MultiModalProcessor
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 | |
_get_cache_missing_items(cache, mm_data_items, mm_hashes)
¶
Keep the loader metadata of the videos that miss the processor cache.
The base class rebuilds the missing items from items[idx], which
holds the frames only, and parses them again. The metadata (fps,
frames_indices) is lost there, so with T > 1 a served video (the
processor cache is on by default) would get the fallback labels
"frame i at i seconds" instead of its real timestamps. T = 1 does not
read the metadata and keeps the base behaviour.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
NemotronShortcutProcessingInfo
¶
Bases: BaseProcessingInfo
Methods:
-
get_max_video_frames–The frame cap of one video, which the memory profile uses.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
get_max_video_frames()
¶
The frame cap of one video, which the memory profile uses.
With T > 1 the cap counts the frames after the T padding, so it must be at least T; the processor never emits more frames than the cap.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
NemotronShortcutVideoBackend
¶
Bases: VideoBackend
Video loader that samples frames with the NeMo RL training rule.
For exports with video_temporal_patch_size > 1. It decodes only
the frames that training_video_frame_times picks (unique, sorted) and
adds to the metadata:
frame_timestamps: the training time label of each sampled frame;frame_source_indices: the source frame of each label (an index repeats when two labels fall in one frame);frame_temporal_patch_size: the T the count was rounded to.
The Nemotron Shortcut processor (T > 1) then uses these frames and labels as they
are. Options (--media-io-kwargs '{"video": {...}}'):
max_frames (default 64, the training video_max_num_frames),
fps (sampling rate, default 2), min_frames (default 8),
temporal_patch_size (default 2), and the decoder backend.
num_frames is not used for sampling. A video never gets more than
max_frames // T * T frames; the processor rejects a video with more
frames than the engine-level max_frames (the memory profile).
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
NemotronShortcutVisionModel
¶
Bases: PixtralHFVisionModel
vLLM's Pixtral encoder, plus video_patch_conv for video tubelets.
A tubelet stacks T frames frame-major on the channel axis.
video_patch_conv embeds it as one patch grid, and the rest of the encoder
runs as for one frame of the same size, with the same RoPE positions.
Methods:
-
encode_tubelets–Encode the tubelets of a video;
forwardencodes images.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
encode_tubelets(tubelets)
¶
Encode the tubelets of a video; forward encodes images.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
_NemotronShortcutTimedVideoDataParser
¶
Bases: MultiModalDataParser
Data parser for T > 1: video items use _TimedVideoProcessorItems.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
_TimedVideoProcessorItems
¶
Bases: VideoProcessorItems
Video items whose processor-cache key includes the loader metadata.
With T > 1 the prompt carries each frame's time, which comes from the
metadata (fps, frames_indices). The base class adds the metadata
to the key only for MediaWithBytes items, so two raw-frame inputs with
the same frames and a different fps would share cached timestamps.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
_video_metadata(videos, video_idx, video)
¶
Return the loader metadata of one video item, if the parser kept it.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
get_video_temporal_patch_size(config)
¶
Return the top-level video_temporal_patch_size T of the config.
T consecutive video frames form one tubelet, which video_patch_conv
embeds as one patch grid. A config without the field means T = 1.
The checks are the same as Megatron-Bridge
check_video_temporal_compression: T must be 1 or 2, and T > 1 needs
separate_video_embedder (default True), because images keep
vision_tower.patch_conv and tubelets use vision_tower.video_patch_conv.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
group_frames_into_tubelets(frames, temporal_patch_size)
¶
Stack T consecutive [C, H, W] frames into [T * C, H, W] tubelets.
The channels are frame-major (frame 0 RGB, then frame 1 RGB), which is the
input channel order of video_patch_conv. A frame count that is not a
multiple of T is padded with the last frame.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
loader_frame_selection(metadata, num_decoded, temporal_patch_size)
¶
Positions in the decoded frames, and labels, of the training sample.
Returns None when the metadata does not come from the nemotron_shortcut_t2
loader (no frame_timestamps). Otherwise each label's source frame
(frame_source_indices) is found in the decoded frames
(frames_indices). A source frame that failed to decode is replaced
by the last decoded frame before it (the first one if there is none);
training also repeats its last decoded frame for missing frames.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
pad_to_temporal_multiple(items, temporal_patch_size)
¶
Repeat the last item until the length is a multiple of T.
The same pad as the training encoder (Megatron-Bridge
NemotronShortcutMIMOVisionEncoder._embed_media), which repeats the last frame.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
profile_video_num_frames(seq_len, tokens_per_tubelet, max_frames, temporal_patch_size)
¶
Frame count of the profiling video when T frames share one token grid.
Each frame costs tokens_per_tubelet / T tokens. The count is a multiple
of T, at least T, and at most the tubelet count of the longest video that
the processor makes (select_video_frame_count with many decoded
frames, padded up to a multiple of T).
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
select_video_frame_count(num_decoded, max_frames, temporal_patch_size)
¶
Number of decoded frames to keep for a video of tubelets of T frames.
This is the rounding of the training frame sampling: the count is
min(num_decoded, max_frames) rounded to a multiple of T. A round up
would need more frames than the decoded count or the frame cap, so it
rounds down, but never below T. When fewer than T frames exist, all
are kept and the caller pads them by repeating the last frame (as the
Megatron-Bridge encoder does).
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
training_video_frame_times(num_source_frames, source_fps, *, max_frames=_TRAINING_VIDEO_MAX_FRAMES, sampling_fps=_TRAINING_VIDEO_FPS, min_frames=_TRAINING_VIDEO_MIN_FRAMES, temporal_patch_size=2)
¶
Source frame index and time label of each frame that training samples.
This is the training frame selection with no clip, no jitter and a
resolution-only scale aug, as the model was trained. The duration is
num_source_frames / source_fps, the value that the OpenCV decoder
reports. Training reads the duration from the sample metadata instead.
- Count N:
min(num_source_frames, max_frames)when there are fewer thanmin_framessource frames, elsemin(max(int(sampling_fps * D), min_frames), max_frames). N is then rounded to a multiple of T: up when the source and the cap allow it, else down, but never below T. - The cap counts the frames after the T padding: N is a multiple of T and
at most
max_frames // T * T, the frame count of the profiling video.max_framesalso caps the short-video branch, which is the same asmin_frames = min(min_frames, max_frames). Training (and the Megatron-LM reference sampler) requiresmax_frames >= min_framesandmax_frames % T == 0; for those settings this rule is the training rule. - Times:
t_i = (D - 1) / N * (i + 0.5)in float32, as training computes them. The prompt labels aret_iwith two decimals. - Frame:
floor(t_i * fps), the frame shown at timet_ifor a constant frame rate video that starts at 0. A video shorter than 1 s has negative times (training does the same); its frame indices are clamped to[0, num_source_frames - 1]and the labels stay negative.
Returns (source_indices, timestamps), one entry per sampled frame, in
time order. source_indices can repeat an index.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
video_frame_timestamps(frame_positions, metadata)
¶
Return the time in seconds of each selected frame of a decoded video.
frame_positions index the decoded frames. The video loader metadata maps
them to source frame indices (frames_indices) and gives the source
fps. Returns None when the metadata has no usable fps.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
video_prompt_text(frame_timestamps, temporal_patch_size, placeholder)
¶
Build the training video prompt with one line per tubelet.
This is the training prompt formula with frame_timestamps given: a
"This is a video:" header, then one line per tubelet, "Frame i sampled at
X.XX seconds and frame i+1 sampled at Y.YY seconds: {marker}" as the placeholder.
Source code in vllm/models/nemotron_shortcut/nvidia/vision.py
video_prompt_token_ids(encode, frame_timestamps, temporal_patch_size, tubelet_token_ids)
¶
Token IDs of the per-tubelet video prompt.
tubelet_token_ids holds the visual tokens of each tubelet, from the
first <img> through the closing </img>. The text between them is
encoded segment by segment, as the training tokenizer does around its
media marker.