Video-Text-to-Text
Transformers
Safetensors
English
Chinese
moss_vl
feature-extraction
SFT
Video-Understanding
Image-Understanding
MOSS-VL
OpenMOSS
multimodal
video
vision-language
custom_code
Run this model with HF Jobs
Run OpenMOSS-Team/MOSS-VL-Instruct-0708 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/OpenMOSS-Team/MOSS-VL-Instruct-0708. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/OpenMOSS-Team/MOSS-VL-Instruct-0708 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use OpenMOSS-Team/MOSS-VL-Instruct-0708 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenMOSS-Team/MOSS-VL-Instruct-0708 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenMOSS-Team/MOSS-VL-Instruct-0708", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
per-sample media budgets in processor; per-sample MRoPE position ids for batched vision inputs
Browse files22 unmodified lines23242526272829354 unmodified lines38438538638738838955 unmodified lines4454464474484494504514524534544554562 unmodified lines45946046146246346446546646746846947047147247347447547647747847948048148248322 unmodified linesfrom torchvision.transforms.v2 import functional as Ffrom PIL import Imagefrom transformers.feature_extraction_utils import BatchFeaturefrom transformers.image_utils import ImageInput, SizeDictfrom transformers.image_processing_utils_fast import group_images_by_shape, reorder_imagesfrom transformers.utils import TensorTypefrom transformers.processing_utils import (354 unmodified lines# Token ids that should always be masked in labels (e.g. <|image_pad|>)self.mask_token_ids = {self.image_token_id}def __call__(self,text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,55 unmodified lines**kwargs,)# Step 1: Process images if providedif images is not None:images_kwargs = output_kwargs["images_kwargs"].copy()images_kwargs["return_tensors"] = Noneimage_inputs = self.image_processor(images=images, **images_kwargs)image_grid_thw = image_inputs["image_grid_thw"]else:image_inputs = {}image_grid_thw = None2 unmodified linesif videos is not None:videos_kwargs = output_kwargs["videos_kwargs"].copy()videos_kwargs["return_tensors"] = Nonevideos_inputs = self.video_processor(videos=videos, **videos_kwargs)video_grid_thw = videos_inputs["video_grid_thw"]# If user has not requested video metadata, pop itif "return_metadata" not in kwargs:video_metadata = videos_inputs.pop("video_metadata")else:video_metadata = videos_inputs["video_metadata"]else:videos_inputs = {}video_grid_thw = Nonevideo_metadata = None# Step 3: Process text with placeholder replacementif text is None or (isinstance(text, str) and len(text.strip()) == 0):raise ValueError("Text input is required for MossVL processor and cannot be empty.")if not isinstance(text, list):text = [text]text = text.copy() # Copy to avoid in-place modifications# Prepare labels_spans if provided22 unmodified lines23242526272829354 unmodified lines38438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843955 unmodified lines4954964974984995005015025035045055065075085095105115125135145152 unmodified lines51851952052152252352452552652752852953053153253353453553653753822 unmodified linesfrom torchvision.transforms.v2 import functional as Ffrom PIL import Imagefrom transformers.feature_extraction_utils import BatchFeaturefrom transformers.image_utils import ImageInput, SizeDict, make_flat_list_of_imagesfrom transformers.image_processing_utils_fast import group_images_by_shape, reorder_imagesfrom transformers.utils import TensorTypefrom transformers.processing_utils import (354 unmodified lines# Token ids that should always be masked in labels (e.g. <|image_pad|>)self.mask_token_ids = {self.image_token_id}def _process_media_per_sample(self, media, texts, kind, processor, kwargs):"""Apply a complete media budget independently to each text sample.Lists within one sample still share the image/video budget (and videoframe limit). A segmented video is one source item occupying severalvideo placeholders; it must not cross text-sample boundaries."""if len(texts) == 1:return processor(**{kind: media}, **kwargs)if kind == "images":items = make_flat_list_of_images(media)widths = [1] * len(items)token = self.image_placeholderelse:items = media if isinstance(media, list) else [media]widths = [len(item["segments"]) if isinstance(item, dict) and item.get("segments") else 1for item in items]token = self.video_placeholdercounts = [text.count(token) for text in texts]if sum(counts) != sum(widths):raise ValueError(f"{kind} placeholders do not match supplied media: "f"per-sample counts={counts}, media slots={sum(widths)}")groups, offset = [], 0for count in counts:start, remaining = offset, countwhile remaining:width = widths[offset]if width > remaining:raise ValueError("A segmented video cannot cross text-sample boundaries")remaining -= widthoffset += 1groups.append(items[start:offset])# Keep media order, but never share resize/frame budgets across samples.results = [processor(**{kind: group}, **kwargs) for group in groups if group]if not results:return {}combined = {}for key in results[0]:values = [result[key] for result in results]if key == "video_metadata":combined[key] = [item for value in values for item in value]else:combined[key] = _concat_array_or_tensor(values, axis=0)return combineddef __call__(self,text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,55 unmodified lines**kwargs,)# Establish sample boundaries before media preprocessing: each sample# receives its own complete image budget and video budget.if text is None or (isinstance(text, str) and not text.strip()):raise ValueError("Text input is required for MossVL processor and cannot be empty.")if not isinstance(text, list):text = [text]# Step 1: Process images if providedif images is not None:images_kwargs = output_kwargs["images_kwargs"].copy()images_kwargs["return_tensors"] = Noneimage_inputs = self._process_media_per_sample(images, text, "images", self.image_processor, images_kwargs)image_grid_thw = image_inputs.get("image_grid_thw")else:image_inputs = {}image_grid_thw = None2 unmodified linesif videos is not None:videos_kwargs = output_kwargs["videos_kwargs"].copy()videos_kwargs["return_tensors"] = Nonevideos_inputs = self._process_media_per_sample(videos, text, "videos", self.video_processor, videos_kwargs)video_grid_thw = videos_inputs.get("video_grid_thw")# If user has not requested video metadata, pop itif "return_metadata" not in kwargs:video_metadata = videos_inputs.pop("video_metadata", [])else:video_metadata = videos_inputs.get("video_metadata", [])else:videos_inputs = {}video_grid_thw = Nonevideo_metadata = None# Step 3: Process text with placeholder replacementtext = text.copy() # Copy to avoid in-place modifications# Prepare labels_spans if provided
processing_moss_vl.py+68-13