try: # transformers >= 5 from transformers.configuration_utils import PreTrainedConfig except ImportError: # transformers < 5 from transformers.configuration_utils import PretrainedConfig as PreTrainedConfig from transformers.utils import logging logger = logging.get_logger(__name__) class MageViTConfig(PreTrainedConfig): r""" This is the configuration class to store the configuration of a [`MageViTModel`]. It is used to instantiate a Mage-ViT model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of the Mage-ViT 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 1024): Dimensionality of the encoder layers and the pooler layer. intermediate_size (`int`, *optional*, defaults to 4096): Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder. num_hidden_layers (`int`, *optional*, defaults to 24): 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. num_channels (`int`, *optional*, defaults to 3): The number of input channels. image_size (`int`, *optional*, defaults to 256): The size (resolution) of each image. patch_size (`int`, *optional*, defaults to 16): The size (resolution) of each patch. hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`): The non-linear activation function (function or string) in the encoder and pooler. layer_norm_eps (`float`, *optional*, defaults to 1e-6): The epsilon used by the layer normalization layers. layer_norm_type (`str`, *optional*, defaults to `"layer_norm"`): The type of layer normalization to use. Supported values: `"layer_norm"`, `"rms_norm"`. attention_dropout (`float`, *optional*, defaults to 0.0): The dropout ratio for the attention probabilities. initializer_range (`float`, *optional*, defaults to 0.02): The standard deviation of the truncated_normal_initializer for initializing all weight matrices. rope_theta (`float`, *optional*, defaults to 10000.0): The base period of the RoPE embeddings. rope_temporal_size (`int` or `None`, *optional*, defaults to 64): Fixed temporal grid size used to build RoPE positions when a 5D video tensor is passed without explicit `patch_positions`. Set to `None` to use the actual number of frames. use_head (`bool`, *optional*, defaults to `True`): Whether to use the multi-head attention pooling head. Example: ```python >>> from configuration_mage_vit import MageViTConfig >>> from modeling_mage_vit import MageViTModel >>> # Initializing a Mage-ViT configuration >>> configuration = MageViTConfig() >>> # Initializing a model (with random weights) from the configuration >>> model = MageViTModel(configuration) >>> # Accessing the model configuration >>> configuration = model.config ``` """ model_type = "mage_vit" def __init__( self, hidden_size=1024, intermediate_size=4096, num_hidden_layers=24, num_attention_heads=16, num_channels=3, image_size=256, patch_size=16, hidden_act="gelu", layer_norm_eps=1e-6, layer_norm_type="layer_norm", attention_dropout=0.0, initializer_range=0.02, rope_theta=10000.0, rope_temporal_size=64, use_head=True, **kwargs, ): super().__init__(**kwargs) 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.num_channels = num_channels self.image_size = image_size self.patch_size = patch_size self.hidden_act = hidden_act self.layer_norm_eps = layer_norm_eps self.layer_norm_type = layer_norm_type self.attention_dropout = attention_dropout self.initializer_range = initializer_range self.rope_theta = rope_theta self.rope_temporal_size = rope_temporal_size # None=use actual frames, int=fixed size (legacy: 64) self.use_head = use_head __all__ = ["MageViTConfig"]