
    gY$                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	  ej
        e          Z G d	 d
e          Z G d de          ZdS )zIdefics3 model configuration    N)Union   )PretrainedConfig)logging   )CONFIG_MAPPINGc                   x     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 d fd	Zedeee	j
        f         ddfd            Z xZS )Idefics3VisionConfiga  
    This is the configuration class to store the configuration of a [`Idefics3VisionModel`]. It is used to instantiate a
    Idefics3 vision encoder according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the SigLIP checkpoint
    [google/siglip-base-patch16-224](https://huggingface.co/google/siglip-base-patch16-224) used in the Idefics3 model
    [HuggingFaceM4/Idefics3-8B-Llama3](https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3).

    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 3072):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        num_hidden_layers (`int`, *optional*, defaults to 12):
            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):
            Number of channels in the input images.
        image_size (`int`, *optional*, defaults to 224):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to 32):
            The size (resolution) of each patch.
        hidden_act (`str` or `function`, *optional*, defaults to `"gelu_pytorch_tanh"`):
            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.
        layer_norm_eps (`float`, *optional*, defaults to 1e-06):
            The epsilon used by the layer normalization layers.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        intializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation for initializing all weight matrices in the model.

    Example:

    ```python
    >>> from transformers.models.idefics3.modeling_idefics3 import Idefics3VisionTransformer
    >>> from transformers.models.idefics3.configuration_idefics3 import Idefics3VisionConfig

    >>> # Initializing a Idefics3VisionConfig with google/siglip-base-patch16-224 style configuration
    >>> configuration = Idefics3VisionConfig()

    >>> # Initializing a Idefics3VisionTransformer (with random weights) from the google/siglip-base-patch16-224 style configuration
    >>> model = Idefics3VisionTransformer(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```idefics3           r          gelu_pytorch_tanhư>        {Gz?c                      t                      j        di | || _        || _        || _        || _        || _        || _        || _        |
| _	        |	| _
        || _        || _        d S )N )super__init__hidden_sizeintermediate_sizenum_hidden_layersnum_attention_headsnum_channels
patch_size
image_sizeattention_dropoutlayer_norm_eps
hidden_actinitializer_range)selfr   r   r   r   r   r    r   r#   r"   r!   r$   kwargs	__class__s                o/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/idefics3/configuration_idefics3.pyr   zIdefics3VisionConfig.__init__Q   s}     	""6"""&!2!2#6 ($$!2,$!2    pretrained_model_name_or_pathreturnr   c                 N   |                      |            | j        |fi |\  }}|                    d          dk    r|d         }d|v rMt          | d          r=|d         | j        k    r,t
                              d|d          d| j         d            | j        |fi |S )N
model_typer   vision_configzYou are using a model of type z  to instantiate a model of type zN. This is not supported for all configurations of models and can yield errors.)_set_token_in_kwargsget_config_dictgethasattrr-   loggerwarning	from_dict)clsr*   r&   config_dicts       r(   from_pretrainedz$Idefics3VisionConfig.from_pretrainedn   s      (((1c12OZZSYZZV ??<((J66%o6K;&&73+E+E&+VbJcgjguJuJuNNr\1J r r>r r r  
 s}[33F333r)   )r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r-   r   classmethodr   strosPathLiker8   __classcell__r'   s   @r(   r
   r
      s        1 1f J &3 3 3 3 3 3: 4E#r{BR<S 4bt 4 4 4 [4 4 4 4 4r)   r
   c                   :     e Zd ZdZdZdZ	 	 	 	 	 	 	 d
 fd		Z xZS )Idefics3Configa  
    This is the configuration class to store the configuration of a [`Idefics3Model`]. It is used to instantiate a
    Idefics3 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 model of the Idefics3
    [HuggingFaceM4/Idefics3-8B-Llama3](https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3) architecture.

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

    Args:
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should cache the key/value pairs of the attention mechanism. Only
            relevant if `config.is_decoder=True`.
        image_token_id (`int`, *optional*, defaults to 128257):
            The id of the "image" token.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether or not to tie the word embeddings with the token embeddings.
        vision_config (`IdeficsVisionConfig` or `dict`, *optional*, defaults to `IdeficsVisionConfig`):
            Custom vision config or dict for the vision tower
        text_config (`PretrainedConfig` or `dict`, *optional*, defaults to `LlamaConfig`):
            Custom text config or dict for the text model
        scale_factor (`int`, *optional*, defaults to 2):
            The scale factor for the image encoder.
        pad_token_id (`int`, *optional*, defaults to 128002):
            The id of the padding token.

    Example:
    ```python
    >>> from transformers import Idefics3Model, Idefics3Config
    >>> # Initializing configuration
    >>> configuration = Idefics3Config()
    >>> # Initializing a model from the configuration
    >>> model = Idefics3Model(configuration)
    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```r   T FNr    c                 T   || _         || _        || _        |.t                      | _        t
                              d           nCt          |t                    rt          d	i || _        nt          |t                    r|| _        t          |t                    r*d|v r|d         nd|d<   t          |d                  d	i |}n4|2t
                              d           t          d         d|d          }|| _
        || _         t                      j        d	i |d|i d S )
Nz2vision_config is None, using default vision configr-   llamaz.text_config is None, using default text configgh㈵>F)rms_norm_epspad_token_idtie_word_embeddingsrK   r   )image_token_id	use_cacherK   r
   r.   r3   info
isinstancedictr   text_configscale_factorr   r   )
r%   rM   rL   rK   r.   rQ   rR   rJ   r&   r'   s
            r(   r   zIdefics3Config.__init__   sY    -"#6  !5!7!7DKKLMMMMt,, 	/!5!F!F!F!FD';<< 	/!.Dk4(( 		EQU`E`E`L(A(AfmK%(\)BCRRkRRKK KKHIII(1!)$)  K '(KK6KK7JKKKKKKr)   )TrE   FNNr   rF   )r9   r:   r;   r<   r-   is_compositionr   rA   rB   s   @r(   rD   rD      su        # #J JN !%L %L %L %L %L %L %L %L %L %Lr)   rD   )r<   r?   typingr   configuration_utilsr   utilsr   autor   
get_loggerr9   r3   r
   rD   r   r)   r(   <module>rY      s    # " 				       3 3 3 3 3 3       ! ! ! ! ! ! 
	H	%	%c4 c4 c4 c4 c4+ c4 c4 c4LNL NL NL NL NL% NL NL NL NL NLr)   