# WARNING: This file was automatically generated # This file was automatically generated from src/transformers/models/videochat3/modular_videochat3.py. # Do NOT edit this file manually as any edits will be overwritten by the generation of # the file from the modular. If any change should be done, please apply the change to the # modular_videochat3.py file directly. One of our CI enforces this. # WARNING: This file was automatically generated # coding=utf-8 # Copyright 2025 The VideoChat3 Team and 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. from typing import Any, Optional from transformers.configuration_utils import PretrainedConfig from transformers import CONFIG_MAPPING, AutoConfig class VideoChat3VisionConfig(PretrainedConfig): """ This is the configuration class to store the configuration of a [`VideoChat3VisionModel`]. It is used to instantiate a VideoChat3 vision encoder according to the specified arguments, defining the model architecture. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the documentation from [`PretrainedConfig`] for more information. Args: hidden_size (`int`, *optional*, defaults to 1152): Dimensionality of the encoder layers and the pooler layer. intermediate_size (`int`, *optional*, defaults to 4304): Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder. num_hidden_layers (`int`, *optional*, defaults to 27): Number of hidden layers in the Transformer encoder. num_attention_heads (`int`, *optional*, defaults to 16): Number of attention heads for each attention layer in the Transformer encoder. patch_size (`int`, *optional*, defaults to 14): The size (resolution) of each patch. merge_kernel_size (`List[int]`, *optional*, defaults to [2, 2]): The kernel size for merging patches. temporal_patch_size (`int`, *optional*, defaults to 1): The temporal patch size for video processing. temporal_merge_size (`int`, *optional*, defaults to 4): The temporal merge size for video processing. init_pos_emb_height (`int`, *optional*, defaults to 64): Initial position embedding height. init_pos_emb_width (`int`, *optional*, defaults to 64): Initial position embedding width. dtype (`str`, *optional*, defaults to "bfloat16"): The dtype of the model. """ model_type = "videochat3_vision" base_config_key = "vision_config" def __init__( self, hidden_size: int = 1152, intermediate_size: int = 4304, num_hidden_layers: int = 27, num_attention_heads: int = 16, patch_size: int = 14, merge_kernel_size: tuple[int, int] = (2, 2), temporal_patch_size: int = 1, temporal_merge_size: int = 4, init_pos_emb_height: int = 64, init_pos_emb_width: int = 64, dtype: str = "bfloat16", attn_impl: str = "flash_attention_2", **kwargs, ): # Remove torch_dtype from kwargs if present kwargs.pop("torch_dtype", None) super().__init__(**kwargs) if merge_kernel_size is None: merge_kernel_size = [2, 2] self.hidden_size = hidden_size self.intermediate_size = intermediate_size self.num_hidden_layers = num_hidden_layers self.num_attention_heads = num_attention_heads self.patch_size = patch_size self.merge_kernel_size = merge_kernel_size self.temporal_patch_size = temporal_patch_size self.temporal_merge_size = temporal_merge_size self.init_pos_emb_height = init_pos_emb_height self.init_pos_emb_width = init_pos_emb_width self.dtype = dtype self.attn_impl = attn_impl class VideoChat3Config(PretrainedConfig): """ This is the configuration class to store the configuration of a [`VideoChat3ForConditionalGeneration`]. It is used to instantiate a VideoChat3 model according to the specified arguments, defining the model architecture. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the documentation from [`PretrainedConfig`] for more information. Args: vision_config (`dict`, *optional*): Dictionary of configuration options used to initialize [`VideoChat3VisionConfig`]. text_config (`dict`, *optional*): Dictionary of configuration options used to initialize any [`PretrainedConfig`]. model_type (`str`, *optional*, defaults to `"videochat3"`): The model type. image_token_id (`int`, *optional*, defaults to 151655): The id of the image token. video_token_id (`int`, *optional*, defaults to 151656): The id of the video token. vision_start_token_id (`int`, *optional*, defaults to 151652): The id of the vision start token. vision_end_token_id (`int`, *optional*, defaults to 151653): The id of the vision end token. """ model_type = "videochat3" sub_configs = {"text_config": AutoConfig, "vision_config": VideoChat3VisionConfig} def __init__( self, vision_config: Optional[dict[str, Any]] = None, text_config: Optional[dict[str, Any]] = None, image_token_id: int = 151655, video_token_id: int = 151656, vision_start_token_id: int = 151652, vision_end_token_id: int = 151653, **kwargs, ): super().__init__(**kwargs) 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 if isinstance(vision_config, dict): self.vision_config = VideoChat3VisionConfig(**vision_config) elif isinstance(vision_config, VideoChat3VisionConfig): self.vision_config = vision_config elif vision_config is None: self.vision_config = VideoChat3VisionConfig() if isinstance(text_config, dict): text_config["model_type"] = text_config.get("model_type", "qwen2") text_config = CONFIG_MAPPING[text_config["model_type"]](**text_config) elif text_config is None: text_config = CONFIG_MAPPING["qwen2"]() self.text_config = text_config super().__init__(**kwargs)