diff --git a/python/sglang/srt/models/internvl.py b/python/sglang/srt/models/internvl.py index ef17d6008..a7897cf92 100644 --- a/python/sglang/srt/models/internvl.py +++ b/python/sglang/srt/models/internvl.py @@ -539,6 +539,7 @@ class InternVLChatModel(nn.Module): self.external_mm_data_embedding_funcs = { Modality.IMAGE: self.get_image_feature, + Modality.VIDEO: self.get_video_feature, } self.model = self.language_model.model @@ -594,6 +595,13 @@ class InternVLChatModel(nn.Module): image_features = self.extract_feature(pixel_values) return image_features + def get_video_feature(self, items: List[MultimodalDataItem]): + # items: each item corresponds to one video (recommended) + # item.feature shape: [num_frames, 3, 448, 448] (or [num_tiles, 3, 448, 448]) + pixel_values = torch.cat([item.feature for item in items], dim=0) + video_features = self.extract_feature(pixel_values) + return video_features + @torch.no_grad() def forward( self, diff --git a/python/sglang/srt/multimodal/processors/internvl.py b/python/sglang/srt/multimodal/processors/internvl.py index 7c707f908..1349fd6dc 100644 --- a/python/sglang/srt/multimodal/processors/internvl.py +++ b/python/sglang/srt/multimodal/processors/internvl.py @@ -1,6 +1,8 @@ # Adapted from https://huggingface.co/OpenGVLab/InternVL2-4B/blob/main/modeling_intern_vit.py +import logging from functools import lru_cache +from typing import List import numpy as np import torch @@ -15,26 +17,44 @@ from sglang.srt.multimodal.processors.base_processor import ( MultimodalSpecialTokens, ) +logger = logging.getLogger(__name__) -class InternVLImageProcessor(BaseMultimodalProcessor): + +class InternVLProcessor(BaseMultimodalProcessor): models = [InternVLChatModel, InternS1ForConditionalGeneration] IMAGENET_MEAN = [0.485, 0.456, 0.406] IMAGENET_STD = [0.229, 0.224, 0.225] + DEFAULT_VIDEO_NUM_FRAMES = 32 + VIDEO_MAX_NUM = 1 + VIDEO_USE_THUMBNAIL = False + + CONTEXT_FALLBACK = 40960 + CONTEXT_RESERVED = 256 + + # OpenAI multimodal placeholder tokens + IMAGE_PLACEHOLDER_TOKEN = "" + VIDEO_PLACEHOLDER_TOKEN = "