
     `iD                     z    d dl mZ d dlmZ  G d de          Z G d de          Z G d de          ZddgZd	S )
   )PretrainedConfig)rope_config_validationc                   J     e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z xZS )Glm4vVisionConfiga  
    This is the configuration class to store the configuration of a [`Glm4vVisionModel`]. It is used to instantiate an Glm4vVisionModel
    model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield
    a similar configuration to that of
    GLM-4.1V-9B-Thinking [THUDM/GLM-4.1V-9B-Thinking](https://huggingface.co/THUDM/GLM-4.1V-9B-Thinking).

    Args:
        hidden_size (`int`, *optional*, defaults to 1536):
            Dimensionality of the encoder layers and the pooler layer.
        depth (`int`, *optional*, defaults to 24):
            Number of layers (depth) in the model.
        attention_bias (`bool`, *optional*, defaults to `False`):
            Whether to add a bias to the queries, keys and values.
        intermediate_size (`int`, *optional*, defaults to 13696):
            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
        hidden_act (`str` or `function`, *optional*, defaults to `"selu"`):
            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
            `"relu"`, `"selu"` and `"gelu_new"` are supported.
        hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            Dropout probability for attention weights.
        projection_dropout (`float`, *optional*, defaults to 0.0):
            Dropout probability for the projection layer.
        initializer_range (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        image_size (`int` or `list[int]`, *optional*, defaults to `[336, 336]`):
            The size (resolution) of each image.
        patch_size (`int`, *optional*, defaults to `14`):
            The size (resolution) of each patch.
        num_channels (`int`, *optional*, defaults to 3):
            The number of input channels.
        out_hidden_size (`int`, *optional*, defaults to 4096):
            The output hidden size of the vision model.
        rms_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the rms normalization layers.
        spatial_merge_size (`int`, *optional*, defaults to 2):
            The size used for merging spatial dimensions.
        temporal_patch_size (`int`, *optional*, defaults to 2):
            The size used for patches along the temporal dimension.
    Example:

    ```python
    >>> from transformers import Glm4vVisionConfig, Glm4vVisionModel

    >>> # Initializing a Glm4vVisionConfig GLM-4.1V-9B style configuration
    >>> configuration = Glm4vVisionConfig()

    >>> # Initializing a model (with random weights) from the GLM-4.1V-9B configuration
    >>> model = Glm4vVisionModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```glm4vvision_config      siluF           r   P     h㈵>      5  {Gz?c                     t                      j        di | || _        || _        || _        || _        || _        || _        |	| _        || _	        || _
        || _        || _        || _        |
| _        || _        || _        d S )N )super__init__depthhidden_size
hidden_act	num_headsin_channels
image_size
patch_sizespatial_merge_sizetemporal_patch_sizeout_hidden_sizeintermediate_sizeinitializer_rangerms_norm_epsattention_biasattention_dropout)selfr   r   r   r&   r'   r   r   r   r   r%   r    r!   r"   r#   r$   kwargs	__class__s                    /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/models/glm4v/configuration_glm4v.pyr   zGlm4vVisionConfig.__init__T   s    & 	""6"""
&$"&$$"4#6 .!2!2(,!2    )r	   r
   r   Fr   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__
model_typebase_config_keyr   __classcell__r*   s   @r+   r   r      s        5 5n J%O !#3 #3 #3 #3 #3 #3 #3 #3 #3 #3r,   r   c                        e Zd ZdZdZdZdgZddddddd	Zd
gdgfddgdgfdgdgfdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z	 xZ
S ) Glm4vTextConfiga  
    This is the configuration class to store the configuration of a [`Glm4vModel`]. It is used to instantiate a
    GLM-4.1V model according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of
    GLM-4.1V-9B-Thinking [THUDM/GLM-4.1V-9B-Thinking](https://huggingface.co/THUDM/GLM-4.1V-9B-Thinking).

    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 151552):
            Vocabulary size of the Glm4v model. Defines the number of different tokens that can be represented by the
            `inputs_ids` passed when calling [`Glm4vModel`]
        hidden_size (`int`, *optional*, defaults to 4096):
            Dimension of the hidden representations.
        intermediate_size (`int`, *optional*, defaults to 13696):
            Dimension of the MLP representations.
        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 2):
            This is the number of key_value heads that should be used to implement Grouped Query Attention. If
            `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
            `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
            converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
            by meanpooling all the original heads within that group. For more details checkout [this
            paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to `32`.
        hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
            The non-linear activation function (function or string) in the decoder.
        max_position_embeddings (`int`, *optional*, defaults to 32768):
            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.
        rms_norm_eps (`float`, *optional*, defaults to 1e-05):
            The epsilon used by the rms normalization layers.
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether or not the model should return the last key/values attentions (not used by all models). Only
            relevant if `config.is_decoder=True`.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether the model's input and output word embeddings should be tied.
        rope_theta (`float`, *optional*, defaults to 10000.0):
            The base period of the RoPE embeddings.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        rope_scaling (`Dict`, *optional*):
            Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
            and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
            accordingly.
            Expected contents:
                `rope_type` (`str`):
                    The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
                    'llama3'], with 'default' being the original RoPE implementation.
                `factor` (`float`, *optional*):
                    Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
                    most scaling types, a `factor` of x will enable the model to handle sequences of length x *
                    original maximum pre-trained length.
                `original_max_position_embeddings` (`int`, *optional*):
                    Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
                    pretraining.
                `attention_factor` (`float`, *optional*):
                    Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
                    computation. If unspecified, it defaults to value recommended by the implementation, using the
                    `factor` field to infer the suggested value.
        image_token_id (`int`, *optional*):
            Token index used as placeholder for image embeddings.
        video_token_id (`int`, *optional*):
            Token index used as placeholder for video embeddings.

    ```python
    >>> from transformers import Glm4vTextModel, Glm4vConfig

    >>> # Initializing a GLM-4.1V style configuration
    >>> configuration = Glm4vConfig()

    >>> # Initializing a model from the GLM-4.1V style configuration
    >>> model = Glm4vTextModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```
glm4v_texttext_configpast_key_valuescolwiserowwisecolwise_reprowwise_rep)zlayers.*.self_attn.q_projzlayers.*.self_attn.k_projzlayers.*.self_attn.v_projzlayers.*.self_attn.o_projzlayers.*.mlp.gate_up_projzlayers.*.mlp.down_proj	input_idsinputs_embedshidden_statesattention_mask)embed_tokenslayersnorm P r   r   (       r   r      r   r   TF     @r   Nc                    || _         || _        || _        || _        || _        || _        ||}|| _        || _        |	| _        |
| _	        || _
        || _        || _        || _        | j        d| j        v r| j        d         | j        d<   t          | dh           || _        || _         t#                      j        dd|i| d S )Ntype	rope_typemrope_section)ignore_keystie_word_embeddingsr   )
vocab_sizemax_position_embeddingsr   r#   num_hidden_layersnum_attention_headsnum_key_value_headsr   r$   r%   	use_cache
rope_thetar'   rope_scalingr   image_token_idvideo_token_idr   r   )r(   rP   r   r#   rR   rS   rT   r   rQ   r$   r%   rU   rO   rV   r'   rW   rX   rY   r)   r*   s                      r+   r   zGlm4vTextConfig.__init__   s    * %'>$&!2!2#6  &"5#6 $!2("$!2( (Vt7H-H-H-1->v-FDk*t/1BCCCC,,KK-@KFKKKKKr,   )rE   r   r   rF   rG   r   r   rH   r   r   TFrI   r   NNN)r-   r.   r/   r0   r1   r2   keys_to_ignore_at_inferencebase_model_tp_planbase_model_pp_planr   r3   r4   s   @r+   r6   r6   z   s        P Pd J#O#4"5 &/%.%.%.%2"/  &(9:#%568IJ!"_$56   %!%1L 1L 1L 1L 1L 1L 1L 1L 1L 1Lr,   r6   c                   H     e Zd ZdZdZeedZdgZ	 	 	 	 	 	 	 	 d fd	Z	 xZ
S )Glm4vConfiga\  
    This is the configuration class to store the configuration of a [`Glm4vModel`]. It is used to instantiate a
    GLM-4.1V model according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of
    GLM-4.1V-9B-Thinking [THUDM/GLM-4.1V-9B-Thinking](https://huggingface.co/THUDM/GLM-4.1V-9B-Thinking).

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


    Args:
        text_config (`Union[PreTrainedConfig, dict]`, *optional*, defaults to `Glm4vTextConfig`):
            The config object or dictionary of the text backbone.
        vision_config (`Union[PreTrainedConfig, dict]`,  *optional*, defaults to `Glm4vVisionConfig`):
            The config object or dictionary of the vision backbone.
        image_token_id (`int`, *optional*, defaults to 151343):
            The image token index to encode the image prompt.
        video_token_id (`int`, *optional*, defaults to 151344):
            The video token index to encode the image prompt.
        image_start_token_id (`int`, *optional*, defaults to 151339):
            The image start token index to encode the start of image.
        image_end_token_id (`int`, *optional*, defaults to 151340):
            The image end token index to encode the end of image.
        video_start_token_id (`int`, *optional*, defaults to 151341):
            The video start token index to encode the start of video.
        video_end_token_id (`int`, *optional*, defaults to 151342):
            The video end token index to encode the end of video.

    ```python
    >>> from transformers import Glm4vForConditionalGeneration, Glm4vConfig

    >>> # Initializing a GLM-4.1V style configuration
    >>> configuration = Glm4vConfig()

    >>> # Initializing a model from the GLM-4.1V style configuration
    >>> model = Glm4vForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```r   )r   r8   r9   N/O 0O +O ,O -O .O c	                    t          |t                    r | j        d         di || _        n| | j        d                     | _        t          |t                    r | j        d         di || _        n| | j        d         di |	| _        || _        || _        || _        || _        || _	        || _
         t                      j        di |	 d S )Nr   r8   r   )
isinstancedictsub_configsr   r8   rX   rY   video_start_token_idvideo_end_token_idimage_start_token_idimage_end_token_idr   r   )r(   r8   r   rX   rY   rk   rl   ri   rj   r)   r*   s             r+   r   zGlm4vConfig.__init__A  s    mT** 	E!B!1/!B!S!S]!S!SD"!B!1/!B!D!DDk4(( 	I>t/>MMMMD >t/>HHHHD,,$8!"4$8!"4""6"""""r,   )NNr_   r`   ra   rb   rc   rd   )r-   r.   r/   r0   r1   r   r6   rh   rZ   r   r3   r4   s   @r+   r^   r^     s        ' 'R J$5oVVK#4"5 #!#!# # # # # # # # # #r,   r^   N)configuration_utilsr   modeling_rope_utilsr   r   r6   r^   __all__r   r,   r+   <module>rp      s   * 4 3 3 3 3 3 9 9 9 9 9 9^3 ^3 ^3 ^3 ^3( ^3 ^3 ^3BVL VL VL VL VL& VL VL VLrK# K# K# K# K#" K# K# K#\ +
,r,   