Video-Text-to-Text
Transformers
Safetensors
English
moss_vl
feature-extraction
SFT
Video-Understanding
Image-Understanding
MOSS-VL
OpenMOSS
multimodal
video
vision-language
custom_code
Instructions to use OpenMOSS-Team/MOSS-VL-Instruct-0408 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenMOSS-Team/MOSS-VL-Instruct-0408 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("OpenMOSS-Team/MOSS-VL-Instruct-0408", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
| # coding=utf-8 | |
| # Copyright 2025 The HuggingFace Inc. team. All rights reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| """MossVL model configuration""" | |
| from transformers.configuration_utils import PretrainedConfig | |
| from transformers.modeling_rope_utils import rope_config_validation | |
| from transformers.utils import logging | |
| logger = logging.get_logger(__name__) | |
| class MossVLVisionConfig(PretrainedConfig): | |
| """ | |
| Configuration for MossVL Vision Model | |
| """ | |
| model_type = "moss_vl_vision" | |
| base_config_key = "vision_config" | |
| def __init__( | |
| self, | |
| depth=27, | |
| hidden_size=1152, | |
| hidden_act="gelu_pytorch_tanh", | |
| intermediate_size=4304, | |
| num_heads=16, | |
| in_channels=3, | |
| patch_size=16, | |
| spatial_merge_size=2, | |
| temporal_patch_size=1, | |
| out_hidden_size=3584, | |
| num_position_embeddings=2304, | |
| deepstack_visual_indexes=[8, 16, 24], | |
| initializer_range=0.02, | |
| **kwargs, | |
| ): | |
| super().__init__(**kwargs) | |
| self.depth = depth | |
| self.hidden_size = hidden_size | |
| self.hidden_act = hidden_act | |
| self.intermediate_size = intermediate_size | |
| self.num_heads = num_heads | |
| self.in_channels = in_channels | |
| self.patch_size = patch_size | |
| self.spatial_merge_size = spatial_merge_size | |
| self.temporal_patch_size = temporal_patch_size | |
| self.out_hidden_size = out_hidden_size | |
| self.num_position_embeddings = num_position_embeddings | |
| self.initializer_range = initializer_range | |
| self.deepstack_visual_indexes = deepstack_visual_indexes | |
| class MossVLTextConfig(PretrainedConfig): | |
| """ | |
| Configuration for MossVL Text Model | |
| """ | |
| model_type = "moss_vl_text" | |
| base_config_key = "text_config" | |
| default_theta = 5000000.0 | |
| ignore_keys_at_rope_validation = {"mrope_section", "mrope_interleaved"} | |
| def __init__( | |
| self, | |
| vocab_size=151936, | |
| hidden_size=4096, | |
| intermediate_size=22016, | |
| num_hidden_layers=32, | |
| num_attention_heads=32, | |
| num_key_value_heads=32, | |
| head_dim=128, | |
| hidden_act="silu", | |
| max_position_embeddings=128000, | |
| initializer_range=0.02, | |
| rms_norm_eps=1e-6, | |
| use_cache=True, | |
| tie_word_embeddings=False, | |
| rope_theta=5000000.0, | |
| rope_parameters=None, | |
| rope_scaling=None, | |
| attention_bias=False, | |
| attention_dropout=0.0, | |
| pad_token_id=None, | |
| # Cross attention specific | |
| cross_attention_layers=None, # List of layer indices to insert cross attention | |
| **kwargs, | |
| ): | |
| self.vocab_size = vocab_size | |
| self.max_position_embeddings = max_position_embeddings | |
| self.hidden_size = hidden_size | |
| self.intermediate_size = intermediate_size | |
| self.num_hidden_layers = num_hidden_layers | |
| self.num_attention_heads = num_attention_heads | |
| # for backward compatibility | |
| if num_key_value_heads is None: | |
| num_key_value_heads = num_attention_heads | |
| self.num_key_value_heads = num_key_value_heads | |
| self.head_dim = head_dim | |
| self.hidden_act = hidden_act | |
| self.initializer_range = initializer_range | |
| self.rms_norm_eps = rms_norm_eps | |
| self.use_cache = use_cache | |
| self.rope_theta = rope_theta | |
| if rope_parameters is None: | |
| if rope_scaling is not None: | |
| rope_parameters = dict(rope_scaling) | |
| else: | |
| rope_parameters = {"rope_type": "default"} | |
| else: | |
| rope_parameters = dict(rope_parameters) | |
| if "type" in rope_parameters and "rope_type" not in rope_parameters: | |
| rope_parameters["rope_type"] = rope_parameters.pop("type") | |
| rope_parameters.setdefault("rope_type", "default") | |
| rope_parameters.setdefault("rope_theta", rope_theta) | |
| self.rope_parameters = rope_parameters | |
| self.rope_scaling = rope_scaling if rope_scaling is not None else dict(rope_parameters) | |
| self.attention_bias = attention_bias | |
| self.attention_dropout = attention_dropout | |
| self.pad_token_id = pad_token_id | |
| if hasattr(self, "standardize_rope_params"): | |
| self.standardize_rope_params() | |
| if hasattr(self, "validate_rope"): | |
| self.validate_rope() | |
| else: | |
| rope_config_validation(self, ignore_keys=self.ignore_keys_at_rope_validation) | |
| self.cross_attention_layers = cross_attention_layers or [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46] | |
| super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs) | |
| class MossVLConfig(PretrainedConfig): | |
| """ | |
| Configuration for MossVL Model | |
| """ | |
| model_type = "moss_vl" | |
| sub_configs = {"vision_config": MossVLVisionConfig, "text_config": MossVLTextConfig} | |
| keys_to_ignore_at_inference = ["past_key_values"] | |
| def __init__( | |
| self, | |
| text_config=None, | |
| vision_config=None, | |
| image_token_id=151655, | |
| video_token_id=151656, | |
| vision_start_token_id=151652, | |
| vision_end_token_id=151653, | |
| vision_seq_pad_multiple=8, | |
| tie_word_embeddings=False, | |
| **kwargs, | |
| ): | |
| if isinstance(vision_config, dict): | |
| self.vision_config = self.sub_configs["vision_config"](**vision_config) | |
| elif vision_config is None: | |
| self.vision_config = self.sub_configs["vision_config"]() | |
| if isinstance(text_config, dict): | |
| self.text_config = self.sub_configs["text_config"](**text_config) | |
| elif text_config is None: | |
| self.text_config = self.sub_configs["text_config"]() | |
| self.image_token_id = image_token_id | |
| self.video_token_id = video_token_id | |
| self.vision_start_token_id = vision_start_token_id | |
| self.vision_end_token_id = vision_end_token_id | |
| self.vision_seq_pad_multiple = vision_seq_pad_multiple | |
| super().__init__(**kwargs, tie_word_embeddings=tie_word_embeddings) | |
| __all__ = ["MossVLConfig", "MossVLTextConfig"] | |