
    iCD                     P   d dl mZ d dlmZ ddlmZ ddlmZmZ ddl	m
Z
  ej                  e      Z ed	      e G d
 de                    Z ed	      e G d de                    Z ed	      e G d de                    Z ed	      e G d de                    Zg dZy)    )Any)strict   )PreTrainedConfig)auto_docstringlogging   )SiglipVisionConfigzgoogle/t5gemma-2-270m-270m)
checkpointc            
            e Zd ZU dZdZdgZddd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Ze	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZee
d<   dZe	e
d<   dZee
d <   d!Zee
d"<   d#Zee
d$<   d%Ze	d&z  e
d'<   d(Ze	ee	   z  d&z  e
d)<   d*Ze	d&z  e
d+<   d#Zee
d,<   d&Zed&z  e
d-<   d.Z ee
d/<   d0Z!e	ez  d&z  e
d1<   dZ"e	e
d2<   d3Z#e	d&z  e
d4<   d&Z$ee   d&z  e
d5<   d&Z%ed&z  e
d6<   d&Z&ed&z  e
d7<   d8d9d:Z' fd;Z(d< Z)d= Z* xZ+S )>T5Gemma2TextConfigt  
    query_pre_attn_scalar (`float`, *optional*, defaults to 256):
        Scaling factor used on the attention scores
    final_logit_softcapping (`float`, *optional*):
        Scaling factor when applying tanh softcapping on the logits.
    attn_logit_softcapping (`float`, *optional*):
        Scaling factor when applying tanh softcapping on the attention scores.
    t5gemma2_textpast_key_valuescolwisereplicated_with_grad_allreducerowwise	zlayers.*.self_attn.q_projzlayers.*.self_attn.k_projzlayers.*.self_attn.v_projzlayers.*.self_attn.q_normzlayers.*.self_attn.k_normzlayers.*.self_attn.o_projzlayers.*.mlp.gate_projzlayers.*.mlp.up_projzlayers.*.mlp.down_proj	input_idsinputs_embedshidden_statesattention_maskembed_tokenslayersnorm@  
vocab_size 	  hidden_size $  intermediate_size   num_hidden_layers   num_attention_heads   num_key_value_heads   head_dimgelu_pytorch_tanhhidden_activation   max_position_embeddings{Gz?initializer_rangeư>rms_norm_epsT	use_cacher   Npad_token_id   eos_token_idr	   bos_token_idtie_word_embeddingsrope_parametersFattention_bias        attention_dropoutquery_pre_attn_scalar   sliding_windowlayer_typesfinal_logit_softcappingattn_logit_softcapping    .A     @globallocalc                     |j                  dd      }| j                  ;t        | j                        D cg c]  }t	        |dz   |z        rdnd c}| _        t        |   di | y c c}w Nsliding_window_pattern   r5   sliding_attentionfull_attention popr@   ranger$   boolsuper__post_init__selfkwargs_sliding_window_patterni	__class__s       /var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/transformers/models/t5gemma2/configuration_t5gemma2.pyrT   z T5Gemma2TextConfig.__post_init__Z   x    "(**-Eq"I# t556  (,QU6M,M'N#Tdd D
 	''    A+c                     | j                   | j                  z  dk7  r&t        d| j                    d| j                   d      yOPart of `@strict`-powered validation. Validates the architecture of the config.r   zThe hidden size (z6) is not a multiple of the number of attention heads ().Nr    r&   
ValueErrorrV   s    r[   validate_architecturez(T5Gemma2TextConfig.validate_architecturee   S    d666!;#D$4$4#5 622327  <    c                 z   |j                  dd       }ddiddid}| j                  | j                  n|| _        || j                  d   j                  |       | j                  j                  d      ddi| j                  d<   | j                  d   j	                  d|j                  d| j
                  d                | j                  j                  d      ddi| j                  d<   | j                  d   j	                  d|j                  d	| j
                  d
                | j                          |S Nrope_scaling	rope_typedefault)rL   rM   rM   
rope_thetarF   rL   rope_local_base_freqrG   rP   r9   updateget
setdefaultdefault_thetastandardize_rope_paramsrV   rW   rj   default_rope_paramss       r[   convert_rope_params_to_dictz.T5Gemma2TextConfig.convert_rope_params_to_dictm   I   zz.$7
 #.y!9*I6
 8<7K7K7Wt33]p#  !1299,G ##$45=6A95MD  !12-.99&**\43E3Eh3OP	
 ##$78@9Di8PD  !4501<<&**%;T=O=OPW=XY	

 	$$&rg   ,__name__
__module____qualname____doc__
model_typekeys_to_ignore_at_inferencebase_model_tp_planbase_model_pp_planr   int__annotations__r    r"   r$   r&   r(   r*   r,   strr.   r0   floatr2   r3   rR   r4   r6   listr7   r8   r9   dictr:   r<   r=   r?   r@   rA   rB   rs   rT   re   rw   __classcell__rZ   s   @r[   r   r   !   s    !J#4"5%.%.%.%E%E%."+ )"+
 &(9:#%568IJ!"_$56 JK!s!s    Hc0s0#*S*#u#L%It L#* +,L#S	/D(, L#*  $$#'OTD[' ND ,/sU{T)/!$3$!%NC$J%$(KcT!(,0UT\0+/EDL/*X>M	(rg   r   c                        e Zd ZU dZdZddddZeedZdZ	ee
eef   z  dz  ed	<   dZee
eef   z  dz  ed
<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed<    fdZ xZS )T5Gemma2EncoderConfigaM  
    mm_tokens_per_image (`int`, *optional*, defaults to 256):
        The number of tokens per image embedding.
    boi_token_index (`int`, *optional*, defaults to 255999):
        The begin-of-image token index to wrap the image prompt.
    eoi_token_index (`int`, *optional*, defaults to 256000):
        The end-of-image token index to wrap the image prompt.

    Example:

    ```python
    >>> from transformers import T5Gemma2EncoderForConditionalGeneration, T5Gemma2EncoderConfig, SiglipVisionConfig, T5Gemma2EncoderTextConfig

    >>> # Initializing a Siglip-like vision config
    >>> vision_config = SiglipVisionConfig()

    >>> # Initializing a T5Gemma2Encoder Text config
    >>> text_config = T5Gemma2EncoderTextConfig()

    >>> # Initializing a T5Gemma2Encoder gemma-3-4b style configuration
    >>> configuration = T5Gemma2EncoderConfig(vision_config, text_config)

    >>> # Initializing a model from the gemma-3-4b style configuration
    >>> model = T5Gemma2EncoderTextConfig(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```t5gemma2_encoderimage_token_indexboi_token_indexeoi_token_index)image_token_idboi_token_ideoi_token_id)text_configvision_configNr   r   r)   mm_tokens_per_imagei i  i   r/   r0   Tr8   c                    | j                   %t               | _         t        j                  d       n4t	        | j                   t
              rt        di | j                   | _         t	        | j                  t
              rt        di | j                  | _        n0| j                  $t               | _        t        j                  d       t        | $  di | y )NzItext_config is None, using default T5Gemma2EncoderTextConfig text config.zFvision_config is None, using default SiglipVisionConfig vision config.rN   )
r   r   loggerinfo
isinstancer   r   r
   rS   rT   )rV   rW   rZ   s     r[   rT   z#T5Gemma2EncoderConfig.__post_init__   s    #13DKKcd(($/1ED4D4DEDd(($/!3!Id6H6H!ID'!3!5DKK`a''rg   )rz   r{   r|   r}   r~   attribute_mapr   r
   sub_configsr   r   r   r   r   r   r   r   r   r   r   r0   r   r8   rR   rT   r   r   s   @r[   r   r      s    : $J-))M *+K
 ?CK#d38n4t;B@DM%S#X6=D&)t)")OS4Z)")OS4Z)$+sTz+&*ut|*'++( (rg   r   c            
            e Zd ZU dZdZdgZddd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Ze	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZe	e
d<   dZee
d<   dZe	e
d<   dZee
d <   d!Zee
d"<   d#Zee
d$<   d%Ze	d&z  e
d'<   d(Ze	ee	   z  d&z  e
d)<   d*Ze	d&z  e
d+<   d#Zee
d,<   d&Zed&z  e
d-<   d.Z ee
d/<   d0Z!e	ez  d&z  e
d1<   dZ"e	e
d2<   d3Z#e	d&z  e
d4<   d&Z$ee   d&z  e
d5<   d&Z%ed&z  e
d6<   d&Z&ed&z  e
d7<   d8d9d:Z' fd;Z(d< Z)d= Z* xZ+S )>T5Gemma2DecoderConfigr   t5gemma2_decoderr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   Tr3   r   Nr4   r5   r6   r	   r7   r8   r9   Fr:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   c                     |j                  dd      }| j                  ;t        | j                        D cg c]  }t	        |dz   |z        rdnd c}| _        t        |   di | y c c}w rI   rO   rU   s       r[   rT   z#T5Gemma2DecoderConfig.__post_init__	  r\   r]   c                     | j                   | j                  z  dk7  r&t        d| j                    d| j                   d      yr_   rb   rd   s    r[   re   z+T5Gemma2DecoderConfig.validate_architecture  rf   rg   c                 z   |j                  dd       }ddiddid}| j                  | j                  n|| _        || j                  d   j                  |       | j                  j                  d      ddi| j                  d<   | j                  d   j	                  d|j                  d| j
                  d                | j                  j                  d      ddi| j                  d<   | j                  d   j	                  d|j                  d	| j
                  d
                | j                          |S ri   ro   ru   s       r[   rw   z1T5Gemma2DecoderConfig.convert_rope_params_to_dict  rx   rg   ry   r   s   @r[   r   r      s    $J#4"5%.%.%.%E%E%."+ )"+
 &(9:#%568IJ!"_$56 JK!s!s    Hc0s0#*S*#u#L%It L#* +,L#S	/D(, L#*  $$#'OTD[' ND ,/sU{T)/!$3$!%NC$J%$(KcT!(,0UT\0+/EDL/*X>M	(rg   r   c                       e Zd ZU dZdZdgZeedZdddZ	dZ
eeeef   z  dz  ed	<   dZeeeef   z  dz  ed
<   dZeed<   dZeez  ed<   dZeez  ed<   dZeez  ed<   dZeed<   dZeed<   dZedz  ed<   dZeed<    fdZd Z xZS )T5Gemma2Configa`  
    encoder (`Union[T5Gemma2EncoderConfig, dict]`, optional, *optional*):
        Configuration for the encoder.
    decoder (`Union[T5Gemma2DecoderConfig, dict]`, optional, *optional*):
        Configuration for the decoder.
    eoi_token_index (`int`, *optional*):
        The end-of-image token index to wrap the image prompt. Will be same as
        `self.encoder.eoi_token_index`

    ```python
    >>> from transformers import T5Gemma2Config, T5Gemma2Model
    >>> t5gemma2_config = T5Gemma2Config.from_pretrained("google/t5gemma-270m-270m")
    >>> model = T5Gemma2Model(t5gemma2_config)
    ```
    t5gemma2r   )encoderdecoderr   r   )r   r   Nr   r   Tis_encoder_decoderr;   dropout_rater<   classifier_dropout_rater/   r0   i r8   c                    t        | j                  t              rt        di | j                  | _        n0| j                  $t               | _        t        j                  d       t        | j                  t              rt        di | j                  | _        n0| j                  $t               | _        t        j                  d       | j                  | j                  j                  _        | j                  | j                  j                  _
        | j                  | j                  j                  _
        | j                  | j                  _        | j                  | j                  _        | j                  | j                  _
        | j                  j                  | _        dD ]   }||vst        | j                  |      ||<   " t        | @  di | y )NzDencoder is None, using default T5Gemma2EncoderConfig encoder config.zDdecoder is None, using default T5Gemma2DecoderConfig decoder config.)r7   r4   r6   r   rN   )r   r   r   r   r   r   r   r   r   r   r<   r   r   r   getattrrS   rT   )rV   rW   special_token_keyrZ   s      r[   rT   zT5Gemma2Config.__post_init__e  sZ   dllD)0@4<<@DL\\!02DLKK^_dllD)0@4<<@DL\\!02DLKK^_040A0A  -595K5K  27;7M7M""4)-)?)?&$($5$5!)-)?)?&#||;;!_ 	U .,3DLLBS,T()	U 	''rg   c                    | j                   j                  j                  | j                  j                  k7  rDt	        d| j                   j                  j                   d| j                  j                   d      | j
                  st	        d      | j                   j                  j                  | j                  j                  k7  rDt	        d| j                   j                  j                   d| j                  j                   d      y)r`   zBImbalanced encoder-decoder is not supported in T5Gemma2: encoder (z) vs decoder (ra   z4T5Gemma2Model only support encoder-decoder modeling.zRImbalanced encoder-decoder vocabulary size is not supported in T5Gemma2: encoder (N)r   r   r    r   rc   r   r   rd   s    r[   re   z$T5Gemma2Config.validate_architecture  s    <<##//4<<3K3KK LL44@@APTP\P\PhPhOiikm 
 &&STT<<##..$,,2I2II LL44??@t||OfOfNggik  Jrg   )rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   rR   r   r   r   r<   r   r0   r   r   r8   rT   re   r   r   s   @r[   r   r   :  s      J#4"5 )(K .)M
 >BG"T#s(^3d:A=AG"T#s(^3d:A## #L%#+#%(us{(+.US[.#u#$s$"&OS4Z& $$(8rg   r   )r   r   r   r   N)typingr   huggingface_hub.dataclassesr   configuration_utilsr   utilsr   r   siglipr
   
get_loggerrz   r   r   r   r   r   __all__rN   rg   r[   <module>r      s   *  . 3 , ' 
		H	% 78e) e  9eP 78@(, @(  9@(F 78e, e  9eP 78T% T  9Tn erg   