
    <hD                     f    S SK Jr  S SKJr   " S S\5      r " S S\5      r " S S\5      rSS/rg	)
   )PretrainedConfig)rope_config_validationc                   V   ^  \ rS rSrSrSrSr               SU 4S jjrSrU =r	$ )Glm4vVisionConfig   aX  
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_configc                    > [         TU ]  " S0 UD6  Xl        X l        X0l        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Xl        Xl        Xl        X@l        XPl        g )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                    e/var/www/html/shao/venv/lib/python3.13/site-packages/transformers/models/glm4v/configuration_glm4v.pyr   Glm4vVisionConfig.__init__T   sj    & 	"6"
&$"&$$"4#6 .!2!2(,!2    )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )   i   siluF           r   iP     h㈵>         5  {Gz?)
__name__
__module____qualname____firstlineno____doc__
model_typebase_config_keyr   __static_attributes____classcell__r   s   @r    r   r      sN    5n J%O !#3 #3r"   r   c                      ^  \ rS rSrSrSrSrS/rSSSSSS	S
.rS/S/4SS/S/4S/S/4S.r	                 SU 4S jjr
SrU =r$ )Glm4vTextConfigz   a  
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://arxiv.org/pdf/2305.13245.pdf). 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normc                   > Xl         Xl        X l        X0l        X@l        XPl        Uc  UnX`l        Xpl        Xl        Xl	        Xl
        Xl        Xl        Xl        U R                  b,  SU R                  ;   a  U R                  S   U R                  S'   [        U S1S9  UU l        UU l        ["        TU ]H  " SSU0UD6  g )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   rO   r   r   rQ   rR   rS   r   rP   r   r   rT   rN   rU   r   rV   rW   rX   r   r   s                      r    r   Glm4vTextConfig.__init__   s    * %'>$&!2!2#6  &"5#6 $!2("$!2( (Vt7H7H-H-1->->v-FDk*t/1BC,,K-@KFKr"   )r   r   r   rW   r   r   rP   rR   rQ   rS   r   rV   rU   rT   rX   rO   )i P r+   r,   (       r)   r$   i   r-   r(   TFg     @r%   NNN)r.   r/   r0   r1   r2   r3   r4   keys_to_ignore_at_inferencebase_model_tp_planbase_model_pp_planr   r5   r6   r7   s   @r    r9   r9   z   s    Pd J#O#4"5 &/%.%.%.%2"/ &(9:#%568IJ!"_$56  %!%1L 1Lr"   r9   c                   T   ^  \ rS rSrSrSr\\S.rS/r	        SU 4S jjr
SrU =r$ )	Glm4vConfigi  a  
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	   r<   r=   c	                   > [         T
U ]  " S0 U	D6  [        U[        5      (       a  U R                  S   " S0 UD6U l        OUc  U R                  S   " 5       U l        [        U[        5      (       a  U R                  S   " S0 UD6U l        OUc  U R                  S   " S0 U	D6U l        X0l        X@l        Xpl	        Xl
        XPl        X`l        g )Nr	   r<   r   )r   r   
isinstancedictsub_configsr	   r<   rW   rX   video_start_token_idvideo_end_token_idimage_start_token_idimage_end_token_id)r   r<   r	   rW   rX   rg   rh   re   rf   r   r   s             r    r   Glm4vConfig.__init__A  s     	"6"mT**!%!1!1/!B!S]!SD"!%!1!1/!B!DDk4((#//>MMD #//>HHD,,$8!"4$8!"4r"   )rh   rg   rW   r<   rf   re   rX   r	   )NNi/O i0O i+O i,O i-O i.O )r.   r/   r0   r1   r2   r3   r   r9   rd   r\   r   r5   r6   r7   s   @r    r`   r`     sG    'R J$5oVK#4"5 #!#!5 5r"   r`   N)configuration_utilsr   modeling_rope_utilsr   r   r9   r`   __all__r   r"   r    <module>rm      sL   * 4 9^3( ^3BVL& VLrK5" K5\ +
,r"   