o
    ¾e¦i%>  ã                   @   sT   d dl mZ d dlmZ G dd„ deƒZG dd„ deƒZG dd„ deƒZg d	¢Zd
S )é   )ÚPreTrainedConfig)ÚRopeParametersc                       sH   e Zd ZdZdZdZ								
								d‡ fdd„	Z‡  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:
            depth (`int`, *optional*, defaults to 24):
                Number of layers (depth) in the model.
            hidden_size (`int`, *optional*, defaults to 1536):
                Dimensionality of the encoder layers and the pooler layer.
            hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
                The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
                `"relu"`, `"selu"` and `"gelu_new"` are supported.
            attention_bias (`bool`, *optional*, defaults to `False`):
                Whether to add a bias to the queries, keys and values.
            attention_dropout (`float`, *optional*, defaults to 0.0):
                Dropout probability for attention weights.
            num_heads (`<fill_type>`, *optional*, defaults to 12): <fill_docstring>
            in_channels (`<fill_type>`, *optional*, defaults to 3): <fill_docstring>
            image_size (`int` or `list[int]`, *optional*, defaults to 336):
                The size (resolution) of each image.
            patch_size (`int`, *optional*, defaults to 14):
                The size (resolution) of each patch.
            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.
            out_hidden_size (`int`, *optional*, defaults to 4096):
                The output hidden size of the vision model.
            intermediate_size (`int`, *optional*, defaults to 13696):
                Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
            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 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Úvision_configé   é   ÚsiluFç        é   r   éP  é   çñhãˆµøä>é   é   é€5  ç{®Gáz”?c                    sp   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__r   úk/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/transformers/models/glm4v/configuration_glm4v.pyr   O   s    
zGlm4vVisionConfig.__init__)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   r   r'   r)   r      s(    3ðr   c                       s  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,de	dB de	dB de	dB de	dB d e	dB d!e	dB d"e
dB d#e	dB d$edB d%e	dB d&edB d'edB d(eee
ef B dB d)e	dB f‡ fd*d+„Z‡  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`.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        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`.
        pad_token_id (`int`, *optional*):
            The id of the padding token.


    ```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_gather_outputÚrowwise_split_input)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   Tr
   NÚ
vocab_sizer   r    Únum_hidden_layersÚnum_attention_headsÚnum_key_value_headsr   Úmax_position_embeddingsr!   r"   Ú	use_cacher$   Úrope_parametersÚpad_token_idc                    s|   || _ || _|| _|| _|| _|| _|d u r|}|| _|| _|	| _|
| _	|| _
|| _|| _|| _tƒ jdddhi|¤Ž d S )NÚignore_keys_at_rope_validationÚmrope_sectionr   )rD   rH   r   r    rE   rF   rG   r   r!   r"   rI   r$   rJ   rK   r   r   )r%   rD   r   r    rE   rF   rG   r   rH   r!   r"   rI   r$   rJ   rK   r&   r'   r   r)   r   Æ   s"   zGlm4vTextConfig.__init__)r@   r   r   rA   rB   r   r	   rC   r   r   Tr
   NN)r*   r+   r,   r-   r.   r/   Úkeys_to_ignore_at_inferenceÚbase_model_tp_planÚbase_model_pp_planÚintÚstrÚfloatÚboolr   Údictr   r0   r   r   r'   r)   r1   u   sv    >ú
	
ýñþýüûúùø	÷
öõôóòñr1   c                       sH   e Zd ZdZdZeedœZdgZ								
		d‡ fdd„	Z	‡  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.
        tie_word_embeddings (`bool`, *optional*, defaults to `False`):
            Whether the model's input and output word embeddings should be tied.

    ```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
    ```Úglm4v)r   r3   r4   Né/O é0O é+O é,O é-O é.O Fc
                    s¸   t |tƒr| jd di |¤Ž| _n|d u r| jd ƒ | _t |tƒr-| jd di |¤Ž| _n|d u r<| jd di |
¤Ž| _|| _|| _|| _|| _|| _	|| _
|	| _tƒ jdi |
¤Ž d S )Nr   r3   r   )Ú
isinstancerU   Úsub_configsr   r3   Úimage_token_idÚvideo_token_idÚvideo_start_token_idÚvideo_end_token_idÚimage_start_token_idÚimage_end_token_idÚtie_word_embeddingsr   r   )r%   r3   r   r`   ra   rd   re   rb   rc   rf   r&   r'   r   r)   r     s    

zGlm4vConfig.__init__)	NNrX   rY   rZ   r[   r\   r]   F)r*   r+   r,   r-   r.   r   r1   r_   rN   r   r0   r   r   r'   r)   rV   ï   s    +
örV   )rV   r1   r   N)Úconfiguration_utilsr   Úmodeling_rope_utilsr   r   r1   rV   Ú__all__r   r   r   r)   Ú<module>   s   ]zR