# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/cosmos3_edge/modular_cosmos3_edge.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_cosmos3_edge.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2026 NVIDIA Corporation and 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. from huggingface_hub.dataclasses import strict from ...configuration_utils import PreTrainedConfig from ...utils import auto_docstring @auto_docstring(checkpoint="nvidia/Cosmos3-Edge") @strict class Cosmos3EdgeTextConfig(PreTrainedConfig): r""" ```python >>> from transformers import Cosmos3EdgeTextModel, Cosmos3EdgeTextConfig >>> # Initializing a Cosmos3EdgeText cosmos3_edge_text-7b style configuration >>> configuration = Cosmos3EdgeTextConfig() >>> # Initializing a model from the cosmos3_edge_text-7b style configuration >>> model = Cosmos3EdgeTextModel(configuration) >>> # Accessing the model configuration >>> configuration = model.config ```""" model_type = "cosmos3_edge_text" keys_to_ignore_at_inference = ["past_key_values"] base_model_tp_plan = { "layers.*.self_attn.q_proj": "colwise", "layers.*.self_attn.k_proj": "colwise", "layers.*.self_attn.v_proj": "colwise", "layers.*.self_attn.o_proj": "rowwise", "layers.*.mlp.fc1": "colwise", "layers.*.mlp.fc2": "rowwise", } base_model_pp_plan = { "embed_tokens": (["input_ids"], ["inputs_embeds"]), "layers": (["hidden_states", "attention_mask"], ["hidden_states"]), "norm": (["hidden_states"], ["hidden_states"]), } vocab_size: int = 131072 hidden_size: int = 2048 intermediate_size: int = 9216 num_hidden_layers: int = 28 num_attention_heads: int = 16 num_key_value_heads: int | None = 8 hidden_act: str = "relu2" max_position_embeddings: int = 131072 initializer_range: float = 0.02 rms_norm_eps: float = 1e-5 use_cache: bool = True pad_token_id: int | None = 0 bos_token_id: int | None = 1 eos_token_id: int | list[int] | None = 11 pretraining_tp: int | None = 1 tie_word_embeddings: bool = False rope_parameters: dict | None = None attention_bias: bool = False attention_dropout: float | int = 0.0 mlp_bias: bool = False head_dim: int = 128 base_config_key = "text_config" default_theta = 100_000_000.0 ignore_keys_at_rope_validation = {"mrope_section"} def __post_init__(self, **kwargs): if self.rope_parameters is None: self.rope_parameters = { "rope_type": "default", "rope_theta": self.default_theta, "mrope_section": [24, 20, 20], } if self.head_dim is None: self.head_dim = self.hidden_size // self.num_attention_heads if self.num_key_value_heads is None: self.num_key_value_heads = self.num_attention_heads super().__post_init__(**kwargs) def validate_architecture(self): """Part of `@strict`-powered validation. Validates the architecture of the config.""" if self.hidden_size % self.num_attention_heads != 0: raise ValueError( f"The hidden size ({self.hidden_size}) is not a multiple of the number of attention " f"heads ({self.num_attention_heads})." ) rope_type = self.rope_parameters["rope_type"] if rope_type != "default": raise ValueError(f"Cosmos3 Edge requires `rope_type='default'`, got {rope_type!r}.") mrope_section = self.rope_parameters["mrope_section"] if len(mrope_section) != 3 or sum(mrope_section) != self.head_dim // 2: raise ValueError( "`rope_parameters.mrope_section` must contain three sections whose sum equals half of `head_dim`, " f"got {mrope_section} for head_dim={self.head_dim}." ) @auto_docstring(checkpoint="nvidia/Cosmos3-Edge") @strict class Cosmos3EdgeVisionConfig(PreTrainedConfig): r""" num_patches (`int`, *optional*, defaults to 256): Number of patches in the learned reference positional-embedding grid. """ model_type = "cosmos3_edge_vision" base_config_key = "vision_config" hidden_size: int = 1152 intermediate_size: int = 4304 num_hidden_layers: int = 27 num_attention_heads: int = 16 num_channels: int = 3 patch_size: int | list[int] | tuple[int, int] = 16 hidden_act: str = "gelu_pytorch_tanh" layer_norm_eps: float = 1e-6 attention_dropout: float | int = 0.0 num_patches: int = 256 spatial_merge_size: int = 2 @auto_docstring(checkpoint="nvidia/Cosmos3-Edge") @strict class Cosmos3EdgeConfig(PreTrainedConfig): r""" projector_hidden_size (`int`, *optional*, defaults to 11520): Intermediate hidden size of the vision-to-language projector MLP. Example: ```python >>> from transformers import Cosmos3EdgeConfig, Cosmos3EdgeForConditionalGeneration >>> configuration = Cosmos3EdgeConfig() >>> model = Cosmos3EdgeForConditionalGeneration(configuration) ``` """ model_type = "cosmos3_edge" sub_configs = { "text_config": Cosmos3EdgeTextConfig, "vision_config": Cosmos3EdgeVisionConfig, } keys_to_ignore_at_inference = ["past_key_values"] text_config: Cosmos3EdgeTextConfig | dict | None = None vision_config: Cosmos3EdgeVisionConfig | dict | None = None projector_hidden_size: int = 11520 image_token_id: int = 19 video_token_id: int = 18 vision_start_token_id: int = 20 vision_end_token_id: int = 21 tie_word_embeddings: bool = False def __post_init__(self, **kwargs): if self.text_config is None: self.text_config = Cosmos3EdgeTextConfig() elif isinstance(self.text_config, dict): self.text_config = Cosmos3EdgeTextConfig(**self.text_config) if self.vision_config is None: self.vision_config = Cosmos3EdgeVisionConfig() elif isinstance(self.vision_config, dict): self.vision_config = Cosmos3EdgeVisionConfig(**self.vision_config) super().__post_init__(**kwargs) def validate_architecture(self): super().validate_architecture() if not isinstance(self.text_config, Cosmos3EdgeTextConfig): raise TypeError("`text_config` must be a `Cosmos3EdgeTextConfig` or a dictionary.") if not isinstance(self.vision_config, Cosmos3EdgeVisionConfig): raise TypeError("`vision_config` must be a `Cosmos3EdgeVisionConfig` or a dictionary.") __all__ = ["Cosmos3EdgeConfig", "Cosmos3EdgeTextConfig", "Cosmos3EdgeVisionConfig"]