o
    ¾e¦i‚;  ã                   @   s`   d Z ddlmZ ddlmZ e e¡ZG dd„ deƒZG dd„ deƒZ	G dd	„ d	eƒZ
d	gZd
S )zMllama model configurationé   )ÚPreTrainedConfig)Úloggingc                       s¬   e Zd ZdZdZdZ								
								d&dedededededededededededede	e dB de	e	e  dB d ef‡ fd!d"„Z
ed#efd$d%„ƒZ‡  ZS )'ÚMllamaVisionConfiga+  
    This is the configuration class to store the configuration of a [`MllamaVisionModel`]. It is used to instantiate an
    Mllama vision 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 Mllama-11B.

    e.g. [meta-llama/Llama-3.2-11B-Vision](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision)

    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 1280):
            Dimensionality of the encoder layers and the pooler layer.
        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"selu"` and `"gelu_new"` `"quick_gelu"` are supported.
        num_hidden_layers (`int`, *optional*, defaults to 32):
            Number of hidden layers in the Transformer encoder.
        num_global_layers (`int`, *optional*, defaults to 8):
            Number of global layers in the Transformer encoder.
            Vision model has a second transformer encoder, called global.
        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):
            Number of channels in the input image.
        intermediate_size (`int`, *optional*, defaults to 5120):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
        vision_output_dim (`int`, *optional*, defaults to 7680):
            Dimensionality of the vision model output. Includes output of transformer
            encoder with intermediate layers and global transformer encoder.
        image_size (`int`, *optional*, defaults to 448):
            The size (resolution) of each image *tile*.
        patch_size (`int`, *optional*, defaults to 14):
            The size (resolution) of each patch.
        norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the layer normalization layers.
        max_num_tiles (`int`, *optional*, defaults to 4):
            Maximum number of tiles for image splitting.
        intermediate_layers_indices (`list[int]`, *optional*, defaults to [3, 7, 15, 23, 30]):
            Indices of intermediate layers of transformer encoder from which to extract and output features.
            These output features are concatenated with final hidden state of transformer encoder.
        supported_aspect_ratios (`list[list[int]]`, *optional*):
            List of supported aspect ratios for image splitting. If not specified, the default supported aspect ratios
            are [[1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [3, 1], [4, 1]] for `max_num_tiles=4`.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.

    Example:

    ```python
    >>> from transformers import MllamaVisionConfig, MllamaVisionModel

    >>> # Initializing a Llama config
    >>> config = MllamaVisionConfig()

    >>> # Initializing a vision model from the mllama-11b style configuration
    >>> model = MllamaVisionModel(config)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úmllama_vision_modelÚvision_configé   Úgelué    é   é   r   é   é   éÀ  é   çñhãˆµøä>é   Nç{®Gáz”?Úhidden_sizeÚ
hidden_actÚnum_hidden_layersÚnum_global_layersÚnum_attention_headsÚnum_channelsÚintermediate_sizeÚvision_output_dimÚ
image_sizeÚ
patch_sizeÚnorm_epsÚmax_num_tilesÚintermediate_layers_indicesÚsupported_aspect_ratiosÚinitializer_rangec              	      sÌ   |d u r&|dkrt dƒ‚ddgddgddgddgddgddgddgddgg}|d u r.g d¢}|| _|| _|| _|| _|| _|	| _|| _|
| _|| _	|| _
|| _|| _|| _|| _|| _tƒ jdi |¤Ž d S )Nr   z;max_num_tiles must be 4 for default supported aspect ratiosé   é   r   )r   é   é   é   é   © )Ú
ValueErrorr   r   r   r   r   r   r   r   r   r   r   r   Úattention_headsr    r!   ÚsuperÚ__init__)Úselfr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   Úkwargs©Ú	__class__r(   úm/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/transformers/models/mllama/configuration_mllama.pyr,   X   s,   4zMllamaVisionConfig.__init__Úreturnc                 C   s
   t | jƒS )N)Úlenr    )r-   r(   r(   r1   Úmax_aspect_ratio_id„   s   
z&MllamaVisionConfig.max_aspect_ratio_id)r   r   r	   r
   r   r   r   r   r   r   r   r   NNr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
model_typeÚbase_config_keyÚintÚstrÚfloatÚlistr,   Úpropertyr4   Ú__classcell__r(   r(   r/   r1   r      sh    >ðþýüûúùø	÷
öõôó
òñð,r   c                &       s¬   e Zd ZdZdZdZdZ							
												d*dededededededede	dB de
ded e
d!ed"ed#ee dB d$e
d%ed&ed'edB f$‡ fd(d)„Z‡  ZS )+ÚMllamaTextConfigaV  
    This is the configuration class to store the configuration of a [`MllamaTextModel`]. It is used to instantiate an
    Mllama text 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 Mllama-11B.

    e.g. [meta-llama/Llama-3.2-11B-Vision](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision)

    Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PreTrainedConfig`] for more information.

    Args:
        vocab_size (`int`, *optional*, defaults to 128256):
            Vocabulary size of the Mllama text model. Defines the maximum number of different tokens that can be represented
            by the `inputs_ids` passed when calling [`MllamaTextModel`].
        hidden_size (`int`, *optional*, defaults to 4096):
            Dimensionality of the embeddings and hidden states.
        hidden_act (`str` or `Callable`, *optional*, defaults to `"silu"`):
            The non-linear activation function (function or string) in the encoder and pooler.
        num_hidden_layers (`int`, *optional*, defaults to 40):
            Number of hidden layers in the Transformer encoder.
        num_attention_heads (`int`, *optional*, defaults to 32):
            Number of attention heads for each attention layer in the Transformer encoder.
        num_key_value_heads (`int`, *optional*, defaults to 8):
            This is the number of key_value heads that should be used to implement Grouped Query Attention. If not
            specified, will default to `num_attention_heads`.
        intermediate_size (`int`, *optional*, defaults to 14336):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
        rope_parameters (`RopeParameters`, *optional*):
            Dictionary containing the configuration parameters for the RoPE embeddings. The dictionary should contain
            a value for `rope_theta` and optionally parameters used for scaling in case you want to use RoPE
            with longer `max_position_embeddings`.
        rms_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the rms normalization layers.
        max_position_embeddings (`int`, *optional*, defaults to 131072):
            The maximum sequence length that this model might ever be used with.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether to tie weight embeddings
        cross_attention_layers (`list[int]`, *optional*):
            Indices of the cross attention layers. If not specified, will default to [3, 8, 13, 18, 23, 28, 33, 38].
        dropout (`float`, *optional*, defaults to 0):
            The dropout probability for self- and cross-attention layers.
        bos_token_id (`int`, *optional*, defaults to 128000):
            The id of the beginning of sentence token.
        eos_token_id (`int`, *optional*, defaults to 128001):
            The id of the end of sentence token.
        pad_token_id (`int`, *optional*, defaults to 128004):
            The id of the padding token.

    Example:

    ```python
    >>> from transformers import MllamaTextModel, MllamaTextConfig

    >>> # Initializing a Mllama text config
    >>> config = MllamaTextConfig()

    >>> # Initializing a model from the Mllama text configuration
    >>> model = MllamaTextModel(config)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```Úmllama_text_modelÚtext_configg    €„Aé õ é   Úsilué(   r	   r
   é 8  Nr   é   r   TFé    é ô éô éô Ú
vocab_sizer   r   r   r   Únum_key_value_headsr   Úrope_parametersÚrms_norm_epsÚmax_position_embeddingsr!   Ú	use_cacheÚtie_word_embeddingsÚcross_attention_layersÚdropoutÚbos_token_idÚeos_token_idÚpad_token_idc                    s’   |d u rg d¢}|| _ || _|| _|| _|| _|| _|| _|| _|	| _|| _	|| _
|| _|
| _|| _|| _|| _|| _|| _tƒ jdi |¤Ž d S )N)r   r
   é   é   r&   é   é!   é&   r(   )rN   r   rU   r   r   rO   r!   rS   rQ   r   rV   r   rR   rP   rT   rY   rW   rX   r+   r,   )r-   rN   r   r   r   r   rO   r   rP   rQ   rR   r!   rS   rT   rU   rV   rW   rX   rY   r.   r/   r(   r1   r,   Ñ   s*   zMllamaTextConfig.__init__)rD   rE   rF   rG   r	   r
   rH   Nr   rI   r   TFNrJ   rK   rL   rM   )r5   r6   r7   r8   r9   r:   Údefault_thetar;   r<   Údictr=   Úboolr>   r,   r@   r(   r(   r/   r1   rA   ‰   sx    Cíþýüûúùø	÷
öõôóò
ñðïîírA   c                       s>   e Zd ZdZdZddiZeedœZ			d
‡ fdd	„	Z	‡  Z
S )ÚMllamaConfigaÍ  
    This is the configuration class to store the configuration of a [`MllamaForConditionalGeneration`]. It is used to instantiate an
    Mllama 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 Mllama-9B.

    e.g. [meta-llama/Llama-3.2-11B-Vision](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision)

    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 (`Union[AutoConfig, dict]`, *optional*, defaults to `MllamaVisionConfig`):
            The config object or dictionary of the vision backbone.
        text_config (`Union[AutoConfig, dict]`, *optional*, defaults to `MllamaTextConfig`):
            The config object or dictionary of the text backbone.
        image_token_index (`int`, *optional*, defaults to 128256):
            The image token index to encode the image prompt.

    Example:

    ```python
    >>> from transformers import MllamaForConditionalGeneration, MllamaConfig, MllamaVisionConfig, MllamaTextConfig

    >>> # Initializing a CLIP-vision config
    >>> vision_config = MllamaVisionConfig()

    >>> # Initializing a Llama config
    >>> text_config = MllamaTextConfig()

    >>> # Initializing a mllama-11b style configuration
    >>> configuration = MllamaConfig(vision_config, text_config)

    >>> # Initializing a model from the mllama-11b style configuration
    >>> model = MllamaForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```ÚmllamaÚimage_token_idÚimage_token_index)rC   r   NrD   c                    s¬   |d u rt ƒ | _t d¡ nt|tƒrt di |¤Ž| _nt|t ƒr$|| _|| _|d u r5tƒ | _t d¡ nt|tƒrCtdi |¤Ž| _nt|tƒrK|| _t	ƒ j
di |¤Ž d S )Nz9vision_config is None, using default mllama vision configz5text_config is None, using default mllama text configr(   )r   r   ÚloggerÚinfoÚ
isinstancer`   re   rA   rC   r+   r,   )r-   r   rC   re   r.   r/   r(   r1   r,   .  s    



zMllamaConfig.__init__)NNrD   )r5   r6   r7   r8   r9   Úattribute_maprA   r   Úsub_configsr,   r@   r(   r(   r/   r1   rb      s    'ÿ
ürb   N)r8   Úconfiguration_utilsr   Úutilsr   Ú
get_loggerr5   rf   r   rA   rb   Ú__all__r(   r(   r(   r1   Ú<module>   s   
sw
J