
    i                        d dl mZ d dlmZ d dlZd dlmZ ddlmZ	 ddl
mZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZmZmZ ddlmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 dZ7 e(jp                  e9      Z: G d de-      Z; G d de      Z< G d de2      Z= G d de0      Z> G d de3      Z? G d d e/      Z@ G d! d"e/      ZAd#ej                  dz  d$efd%ZCd&eDd$efd'ZE G d( d)e      ZF G d* d+e      ZG G d, d-ej                        ZI G d. d/ej                        ZJe& G d0 d1e1             ZKd2ej                  dz  d3ej                  d4eDdz  d$ej                  fd5ZM G d6 d7eK      ZN G d8 d9eK      ZOe& G d: d;eK             ZPe& G d< d=eK             ZQ G d> d?eKe      ZRe& G d@ dAeK             ZSe& G dB dCeK             ZTg dDZUy)E    )Callable)AnyN   )initialization)CacheDynamicCacheEncoderDecoderCache)PreTrainedConfig)GenerationMixin)FlashAttentionKwargs)GradientCheckpointingLayer)BaseModelOutput)BaseModelOutputWithPastAndCrossAttentionsSeq2SeqLMOutputSeq2SeqModelOutputSequenceClassifierOutputTokenClassifierOutput)RopeParameters)ALL_ATTENTION_FUNCTIONSPreTrainedModel)Unpack)TransformersKwargsauto_docstringcan_return_tuplelogging)OutputRecordercheck_model_inputs   )Gemma2Config)Gemma2Attention	Gemma2MLPGemma2PreTrainedModelGemma2RMSNormGemma2RotaryEmbeddingcreate_causal_mask!create_sliding_window_causal_maskeager_attention_forwardz google/t5gemma-2b-2b-prefixlm-itc            4       h    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddedz  dedz  dedz  dedz  dedz  dedz  d	edz  d
edz  dedz  dedz  dedz  dedz  dedz  dedz  dedz  dedz  dee	eef   z  dz  dedz  dedz  dedz  dedz  de
e   dz  dedz  dedz  dedz  f2 fdZ xZS )T5GemmaModuleConfiga  
    This is the configuration class to store the configuration of a [`T5GemmaModuleModel`]. It is used to instantiate an T5GemmaModule
    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 T5GemmaModule-7B.
    e.g. [google/t5_gemma_module-7b](https://huggingface.co/google/t5_gemma_module-7b)
    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 256000):
            Vocabulary size of the T5GemmaModule model. Defines the number of different tokens that can be represented by the
            `inputs_ids` passed when calling [`T5GemmaModuleModel`]
        hidden_size (`int`, *optional*, defaults to 2304):
            Dimension of the hidden representations.
        intermediate_size (`int`, *optional*, defaults to 9216):
            Dimension of the MLP representations.
        num_hidden_layers (`int`, *optional*, defaults to 26):
            Number of hidden layers in the Transformer decoder.
        num_attention_heads (`int`, *optional*, defaults to 8):
            Number of attention heads for each attention layer in the Transformer decoder.
        num_key_value_heads (`int`, *optional*, defaults to 4):
            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, check out [this
            paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
            `num_attention_heads`.
        head_dim (`int`, *optional*, defaults to 256):
            The attention head dimension.
        hidden_activation (`str` or `function`, *optional*, defaults to `"gelu_pytorch_tanh"`):
            The non-linear activation function (function or string) in the decoder. Will default to `"gelu_pytorch_tanh"`
            if not specified. `"gelu_pytorch_tanh"` uses an approximation of the `"gelu"` activation function.
        max_position_embeddings (`int`, *optional*, defaults to 8192):
            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-06):
            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`.
        pad_token_id (`int`, *optional*, defaults to 0):
            Padding token id.
        eos_token_id (`int`, *optional*, defaults to 1):
            End of stream token id.
        bos_token_id (`int`, *optional*, defaults to 2):
            Beginning of stream token id.
        tie_word_embeddings (`bool`, *optional*, defaults to `True`):
            Whether to tie weight embeddings
        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`.
        attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
            Whether to use a bias in the query, key, value and output projection layers during self-attention.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        query_pre_attn_scalar (`float`, *optional*, defaults to 256):
            scaling factor used on the attention scores
        sliding_window (`int`, *optional*, defaults to 4096):
            in T5GemmaModule, every other layer uses sliding window attention. This is the size of the sliding window.
        layer_types (`list`, *optional*):
            Attention pattern for each layer.
        final_logit_softcapping (`float`, *optional*, defaults to 30.0):
            scaling factor when applying tanh softcapping on the logits.
        attn_logit_softcapping (`float`, *optional*, defaults to 50.0):
            scaling factor when applying tanh softcapping on the attention scores.
        is_decoder (`bool`, *optional*, defaults to `False`):
            Whether to only use the decoder in an encoder-decoder architecture, otherwise it has no effect on
            decoder-only or encoder-only architectures.

    ```python
    >>> from transformers import T5GemmaModuleModel, T5GemmaModuleConfig
    >>> # Initializing a T5GemmaModule t5_gemma_module-7b style configuration
    >>> configuration = T5GemmaModuleConfig()
    >>> # Initializing a model from the t5_gemma_module-7b style configuration
    >>> model = T5GemmaModuleModel(configuration)
    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```N
vocab_sizehidden_sizeintermediate_sizenum_hidden_layersnum_attention_headsnum_key_value_headshead_dimhidden_activationmax_position_embeddingsinitializer_rangerms_norm_eps	use_cachepad_token_ideos_token_idbos_token_idtie_word_embeddingsrope_parametersattention_biasattention_dropoutquery_pre_attn_scalarsliding_windowlayer_typesfinal_logit_softcappingattn_logit_softcapping
is_decoderc                     || _         t        |   di d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|d|d|d|d|d|d|d|| | `y )Nr*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA    )rB   super__init__use_bidirectional_attention)selfr*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   kwargs	__class__s                              u/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/transformers/models/t5gemma/modular_t5gemma.pyrF   zT5GemmaModuleConfig.__init__   s   : % 	
!	
#	
 0	
 0		

 !4	
 !4	
 	
 0	
 %<	
 0	
 &	
  	
 &	
 &	
 &	
  !4!	
" ,#	
$ *%	
& 0'	
( #8)	
* *+	
, $-	
. %</	
0 $:3	
8 ,    )  i 	  i $              gelu_pytorch_tanhi    g{Gz?gư>Tr      r   TNF        rQ   i   Ng      >@g      I@F)__name__
__module____qualname____doc__intstrfloatboolr   dictlistrF   __classcell__rJ   s   @rK   r)   r)   @   s   Ph "("&(,(**+*+"(;.2*.#'!%#$#$#$+/MQ&+*-,/%)(,04/3"'5:-$J:- 4Z:- :	:-
 ::- !4Z:- !4Z:- *:- ::- "%t:- !4<:- Dj:- $;:- Dj:- Dj:-  Dj!:-" "D[#:-$ ($sN/B*CCdJ%:-& t':-( !4<):-*  #Tz+:-, d
-:-. #Y%/:-0 "'1:-2 !&3:-4 4K5:- :-rL   r)   c                        e Zd ZdZdZdgZeedZ	 	 	 	 	 	 	 	 ddeee	e	f   z  dz  deee	e	f   z  dz  de
dz  d	edz  d
edz  dedz  de
dz  dedz  f fdZ xZS )T5GemmaConfiga  
    This is the configuration class to store the configuration of a [`T5GemmaModel`]. It is used to instantiate an T5Gemma
    model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
    defaults will yield a similar configuration to a hypothetical balanced Gemma2 encoder-decoder model.
    e.g. [google/t5gemma-2b-2b-prefixlm-it](https://huggingface.co/google/t5gemma-2b-2b-prefixlm-it)
    ```python
    >>> from transformers import T5GemmaConfig, T5GemmaModel
    >>> t5gemma_config = T5GemmaConfig.from_pretrained("google/t5gemma-2b-2b-prefixlm-it")
    >>> model = T5GemmaModel(t5gemma_config)
    ```
    Configuration objects inherit from [PreTrainedConfig] and can be used to control the model outputs. Read the
    documentation from [PreTrainedConfig] for more information.
    Args:
        encoder (`Union[T5GemmaModuleConfig, dict]`, optional, *optional*):
            Configuration for the encoder.
        decoder (`Union[T5GemmaModuleConfig, dict]`, optional, *optional*):
            Configuration for the decoder.
        is_encoder_decoder (bool, optional, *optional*, defaults to `True`):
            Whether the model is used as an encoder/decoder or not.
        dropout_rate (`float`, *optional*, defaults to 0.0):
            The ratio for all dropout layers (following T5).
        classifier_dropout_rate (`float`, *optional*, defaults to 0.0):
            The dropout ratio for classifier (following T5).
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for attention.
        tie_word_embeddings (`bool`, *optional*, defaults to `True`):
            Whether tie input and output embeddings.
        vocab_size (`int`, *optional*, defaults to 256000):
            Vocabulary size of the T5Gemma model (the same as Gemma 2).
        kwargs (additional keyword arguments, optional, *optional*):
            Will be passed to the PreTrainedConfig base class.
    t5gemmapast_key_values)encoderdecoderNre   rf   is_encoder_decoderdropout_rateclassifier_dropout_rater<   r9   r*   c	                    t        |t              rt        di |}n0|t               }n#t        |t              sJ t        |       d       t        |t              rt        di |}n(||}n#t        |t              sJ t        |       d       t        di |j	                         }t        di |j	                         }d|_        ||_        ||_        || _        d|_        d|_	        ||_        ||_        |j                  |_        || _        dD ]  }
|
|	vst        ||
      |	|
<    t        | <  di |	 || _        |	j#                  d|j$                        | _        || _        || _        || _        y )Nz is not supported.FT)r8   r6   r7   r3   rD   )
isinstancer]   r)   typeto_dictrB   rh   r<   re   r5   r+   cross_attention_hidden_sizerf   getattrrE   rF   rg   getr3   ri   r9   r*   )rH   re   rf   rg   rh   ri   r<   r9   r*   rI   special_token_keyrJ   s              rK   rF   zT5GemmaConfig.__init__   s    gt$)4G4G_)+Gg':;aWN`=aa;gt$)4G4G_Gg':;aWN`=aa;%:(9:%:(9:"+$5!! +$5!.5.A.A+!Q 	P .,3G=N,O()	P 	"6""4!',?AZAZ!['>$#6  %rL   )NNTrT   rT   rT   TrM   )rU   rV   rW   rX   
model_typekeys_to_ignore_at_inferencer)   sub_configsr]   r   r\   r[   rY   rF   r_   r`   s   @rK   rb   rb      s    B J#4"51>QRK @D?C*.%(03*-+/!'5%$tCH~5<5% %tCH~5<5% !4K	5%
 dl5% "'5% !4<5% "D[5% $J5% 5%rL   rb   c                       e Zd Zy)T5GemmaRMSNormNrU   rV   rW   rD   rL   rK   rv   rv   .      rL   rv   c                   $     e Zd Z fdZd Z xZS )
T5GemmaMLPc                 l    t         |   |       t        j                  |j                        | _        y N)rE   rF   nnDropoutrh   dropoutrH   configrJ   s     rK   rF   zT5GemmaMLP.__init__3  s&     zz&"5"56rL   c                     | j                  | j                  |            | j                  |      z  }| j                  |      }| j	                  |      }|S r|   )act_fn	gate_projup_projr   	down_proj)rH   xhidden_statesr   s       rK   forwardzT5GemmaMLP.forward7  sH    DNN1$56aH]3NN=1	rL   )rU   rV   rW   rF   r   r_   r`   s   @rK   rz   rz   2  s    7rL   rz   c                       e Zd Zy)T5GemmaRotaryEmbeddingNrw   rD   rL   rK   r   r   >  rx   rL   r   c                   (     e Zd Zdedef fdZ xZS )T5GemmaSelfAttentionr   	layer_idxc                 H    t         |   ||       |j                  | _        y r|   )rE   rF   rB   	is_causalrH   r   r   rJ   s      rK   rF   zT5GemmaSelfAttention.__init__C  s    +**rL   )rU   rV   rW   r)   rY   rF   r_   r`   s   @rK   r   r   B  s    +2 +s + +rL   r   c                        e Zd Zdedef fdZ	 ddej                  dej                  dz  dej                  dz  dedz  d	e	e
   d
eej                  ej                  dz  eej                     dz  f   fdZ xZS )T5GemmaCrossAttentionr   r   c                    t         |   ||       | `| `d| _        |j
                  t        d      t        j                  |j
                  |j                  | j                  z  |j                        | _        t        j                  |j
                  |j                  | j                  z  |j                        | _        y )NFzBCross-attention needs cross_attention_hidden_size to be specified.bias)rE   rF   r>   
layer_typer   rn   
ValueErrorr}   Linearr/   r0   r;   k_projv_projr   s      rK   rF   zT5GemmaCrossAttention.__init__J  s    +O--5abbii..0J0JT]]0Zagavav
 ii..0J0JT]]0Zagavav
rL   Nr   attention_maskencoder_hidden_statesrd   rI   returnc                    |t        d      |j                  d d }g |d| j                  }| j                  |      j	                  |      j                  dd      }|1|j                  j                  | j                        }	|j                  }
|	s|j                  d d }g |d| j                  }| j                  |      j	                  |      j                  dd      }| j                  |      j	                  |      j                  dd      }|
j                  ||| j                        \  }}d|j                  | j                  <   nF
j                  | j                     j                  }|
j                  | j                     j                  }t!        j"                  | j$                  j&                  t(              } || ||||f| j*                  r| j,                  nd| j.                  d | j0                  d|\  }} |j2                  g |d j5                         }| j7                  |      }||fS )Nz5Encoder hidden state is required for cross attention.rS   r   TrT   )r   scalingr>   softcap)r   shaper0   q_projview	transpose
is_updatedrp   r   cross_attention_cacher   r   updatelayerskeysvaluesr   get_interfacer   _attn_implementationr'   trainingr<   r   rA   reshape
contiguouso_proj)rH   r   r   r   rd   rI   input_shapehidden_shapequery_statesr   curr_past_key_valuesencoder_input_shapeencoder_hidden_shape
key_statesvalue_statesattention_interfaceattn_outputattn_weightss                     rK   r   zT5GemmaCrossAttention.forwardZ  s?    !(TUU#))#2.88b8$--8{{=166|DNNqRST&(3377GJ#2#H#H "*"7"="=cr"B#L%8#L"#Ldmm#L %:;@@AUV``abdefJ;;'<=BBCWXbbcdfghL*+?+F+FzS_aeaoao+p(
L=A**4>>:-44T^^DIIJ/66t~~FMML(?(M(MKK,,.E)
 %8%
 /3mmD**LL//%
 %
!\ *k));;;;FFHkk+.L((rL   r|   )rU   rV   rW   r)   rY   rF   torchTensorr   r   r   tupler   r_   r`   s   @rK   r   r   I  s    
2 
s 
* )-3)||3) t+3)  %||d2	3)
 3) -.3) 
u||U\\D0%2E2LL	M3)rL   r   r   r   c           
      P     dt         dt         dt         dt         dt        f
 fd}|S )z4
    This creates bidirectional attention mask.
    	batch_idxhead_idxq_idxkv_idxr   c                     %t        j                  dt         j                        S | |f   j                  t         j                        S )NrD   dtype)r   onesr\   to)r   r   r   r   r   s       rK   
inner_maskz/bidirectional_mask_function.<locals>.inner_mask  s=    !::b

33i/033EJJ??rL   rY   r\   )r   r   s   ` rK   bidirectional_mask_functionr     s9    
@c @S @ @c @d @
 rL   r>   c           
      P     dt         dt         dt         dt         dt        f
 fd}|S )zH
    This creates bidirectional attention mask with sliding window.
    r   r   r   r   r   c                 &    |z
  |k  ||z   k  z  S r|   rD   )r   r   r   r   r>   s       rK   r   z>sliding_window_bidirectional_mask_function.<locals>.inner_mask  s"    &/FU^=S4STTrL   r   )r>   r   s   ` rK   *sliding_window_bidirectional_mask_functionr     s9    
Uc US U Uc Ud U rL   c                        e Zd ZdZdef fdZ	 	 	 ddej                  deej                  ej                  f   dz  dej                  dz  dej                  dz  d	eej                  f   f
d
Z xZS )T5GemmaEncoderLayerzEncoder sub-layer.r   c                 D   t         |           |j                  | _        || _        || _        |j
                  |   | _        t        ||      | _        t        |j                  |j                        | _        t        |j                  |j                        | _        t        |      | _        t        |j                  |j                        | _        t        |j                  |j                        | _        t#        j$                  |j&                        | _        y N)r   r   eps)rE   rF   r+   r   r   r?   attention_typer   	self_attnrv   r4   pre_self_attn_layernormpost_self_attn_layernormrz   mlppre_feedforward_layernormpost_feedforward_layernormr}   r~   rh   r   r   s      rK   rF   zT5GemmaEncoderLayer.__init__  s    !--"$00;-
 (6f6H6HfNaNa'b$(6v7I7IvObOb(c%f%)78J8JPVPcPc)d&*89K9KQWQdQd*e'zz&"5"56rL   Nr   position_embeddingsr   position_idsr   c           	      >   |}| j                  |      } | j                  d||||d d|\  }}| j                  |      }|| j                  |      z   }|}| j	                  |      }| j                  |      }| j                  |      }|| j                  |      z   }|S )N)r   r   r   r   rd   rD   )r   r   r   r   r   r   r   )rH   r   r   r   r   rI   residual_s           rK   r   zT5GemmaEncoderLayer.forward  s     !44]C)4>> 
' 3)% 
 
q 55mD 4<<#>> 66}E/77F 4<<#>>rL   )NNN)rU   rV   rW   rX   rY   rF   r   r   r   
LongTensorFloatTensorr   r_   r`   s   @rK   r   r     s    7# 7. IM.204|| #5<<#=>E t+	
 &&- 
u  !	"rL   r   c                   X    e Zd ZdZdef fdZ	 	 	 	 	 	 	 	 ddej                  deej                  ej                  f   dz  dej                  dz  dej                  dz  d	e
dz  d
edz  dej                  dz  dej                  dz  dej                  dz  dej                  fdZ xZS )T5GemmaDecoderLayerz2Decoder sub-layer: an extra cross-attention layer.r   c                     t         |           |j                  | _        || _        || _        |j
                  |   | _        t        ||      | _        t        |j                  |j                        | _        t        |j                  |j                        | _        t        |      | _        t        |j                  |j                        | _        t        |j                  |j                        | _        t#        j$                  |j&                        | _        t+        ||      | _        t        |j                  |j                        | _        t        |j                  |j                        | _        y r   )rE   rF   r+   r   r   r?   r   r   r   rv   r4   r   r   rz   r   r   r   r}   r~   rh   r   r   
cross_attnpre_cross_attn_layernormpost_cross_attn_layernormr   s      rK   rF   zT5GemmaDecoderLayer.__init__  s&   !--"$00;-
 (6f6H6HfNaNa'b$(6v7I7IvObOb(c%f%)78J8JPVPcPc)d&*89K9KQWQdQd*e'zz&"5"56/vS(6v7I7IvObOb(c%)78J8JPVPcPc)d&rL   Nr   r   r   r   rd   r5   cache_positionr   encoder_attention_maskr   c
                    |}| j                  |      } | j                  d||||||j                  nd ||d|
\  }}| j                  |      }|| j	                  |      z   }|}| j                  |      } | j                  d|||	||d|
\  }}| j                  |      }|| j	                  |      z   }|}| j                  |      }| j                  |      }| j                  |      }|| j	                  |      z   }|S )N)r   r   r   r   rd   r5   r   )r   r   r   rd   r5   rD   )r   r   self_attention_cacher   r   r   r   r   r   r   r   )rH   r   r   r   r   rd   r5   r   r   r   rI   r   r   s                rK   r   zT5GemmaDecoderLayer.forward  s>    !44]C)4>> 	
' 3)%DSD_O@@ei)	
 	
q 55mD 4<<#>> 55mD*4?? 
'"71+
 
q 66}E 4<<#>> 66}E/77F 4<<#>>rL   )NNNNFNNN)rU   rV   rW   rX   rY   rF   r   r   r   r   r	   r\   r   r   r_   r`   s   @rK   r   r     s    <e# e4 IM.2046:!&26596:.||. #5<<#=>E. t+	.
 &&-. -t3. $;. ((4/.  %||d2. !&t 3. 
		.rL   r   c                   j     e Zd ZdZd	dededef fdZdej                  dej                  fdZ	 xZ
S )
T5GemmaClassificationHeadz-Head for sentence-level classification tasks.r+   
num_labelsri   c                     t         |           t        j                  |      | _        t        j
                  ||      | _        y )N)p)rE   rF   r}   r~   r   r   out_proj)rH   r+   r   ri   rJ   s       rK   rF   z"T5GemmaClassificationHead.__init__*  s1    zz$;<		+z:rL   r   r   c                 J    | j                  |      }| j                  |      }|S r|   )r   r   )rH   r   s     rK   r   z!T5GemmaClassificationHead.forward/  s$    ]3m4rL   )rT   )rU   rV   rW   rX   rY   r[   rF   r   r   r   r_   r`   s   @rK   r   r   '  s<    7;C ;S ;SX ;
U\\ ell rL   r   c                   j     e Zd ZdZd	dededef fdZdej                  dej                  fdZ	 xZ
S )
T5GemmaLMHeadz.Head for language modeling (generation) tasks.r+   r*   r   c                 \    t         |           t        j                  |||      | _        y )Nr   )rE   rF   r}   r   r   )rH   r+   r*   r   rJ   s       rK   rF   zT5GemmaLMHead.__init__8  s"    		+zErL   r   r   c                 (    | j                  |      }|S r|   )r   )rH   r   logitss      rK   r   zT5GemmaLMHead.forward<  s    }-rL   )F)rU   rV   rW   rX   rY   r\   rF   r   r   r   r_   r`   s   @rK   r   r   5  s?    8FC FS F FU\\ ell rL   r   c                       e Zd ZU eed<   dZdZddgZe e	e
dd       e	e
dd	       e	edd	      gd
Z ej                         d        Zd Zy)T5GemmaPreTrainedModelr   modelTr   r   rS   r   )index
layer_namer   )r   
attentionsc                 @   t        j                  | |       | j                  j                  }t	        |t
              r|j                  j                  j                  d   dz  }t        j                  |j                  j                  d||z         t        |j                  d      rA|j                  j                  *t        j                  |j                  j                         y y y t	        |t              rm| j                  j                  sV|j                  j                  j                  d   dz  }t        j                  |j                  j                  d||z         y y d|j                   j"                  v r t        j                  |j                         y y )Nr   g      rT   )meanstdr   RMSNorm)r   _init_weightsr   r3   rk   r   r   weightr   initnormal_hasattrr   zeros_r   r9   rJ   rU   )rH   moduler  scales       rK   r  z$T5GemmaPreTrainedModel._init_weightsP  s+    	%%dF3kk++f78OO**003t;ELL//csU{Kv/FOO4H4H4TFOO001 5U/.;;22..44Q74?V__33#3;O 3 &**333KK& 4rL   c                 `   | j                   j                  j                  }| j                   j                  j                  }|t	        d      |j                  |j                        }|dddf   j                         |dddf<   ||d<   |t	        d      |j                  |dk(  |       |S )	z
        Shifts input_ids to the right, prepends the decoder_start_token_id, and handles
        pad_token_id replacement for labels that were -100.
        This is a common preparation step for decoder inputs in sequence-to-sequence models.
        Nz:self.model.config.decoder.bos_token_id has to be defined. .r   rS   ).r   z9self.model.config.decoder.pad_token_id has to be defined.i)	r   rf   r8   r6   r   	new_zerosr   clonemasked_fill_)rH   	input_idsdecoder_start_token_idr6   shifted_input_idss        rK   _shift_rightz#T5GemmaPreTrainedModel._shift_rightb  s     "&!4!4!A!A{{**77!)YZZ &//	@%.sCRCx%8%>%>%@#qr'"$:&!XYY 	&&'8D'@,O  rL   N)rU   rV   rW   rb   __annotations__base_model_prefixsupports_gradient_checkpointing_no_split_modulesr   r   r   r   _can_record_outputsr   no_gradr  r  rD   rL   rK   r   r   A  sx    &*#.0EF,/q[Q/q\R0lS
 U]]_' '"!rL   r   	token_idsr   r6   c                    | <|t        d      | |k7  j                  |j                  t        j                        }|S t        j
                  |j                  d   |j                  d   f|j                  t        j                        }|S )z%Construct the default attention mask.z3`pad_token_id` is required for padding information.r   rS   devicer   )r   r   r  r   longr   r   )r  r   r6   r   s       rK   make_default_2d_attention_maskr   }  s     RSS#|3778L8LejjY
    #]%8%8%;<]EYEYafakak
 rL   c                        e Zd ZeedZ fdZe	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  dej                  dz  dee   d	eez  fd
       Z xZS )T5GemmaEncoder)r   r   c           	      T   t         |   |       |j                  | _        |j                  | _        t        j                  |j                  |j                  | j                        | _        t        |j                  |j                        | _        d| _        t        j                  t        |j                        D cg c]  }t!        ||       c}      | _        t        j$                  |j&                        | _        t+        |      | _        | j/                          y c c}w Nr   Fr   )rE   rF   r6   padding_idxr*   r}   	Embeddingr+   embed_tokensrv   r4   normgradient_checkpointing
ModuleListranger-   r   r   r~   rh   r   r   
rotary_emb	post_initr   s      rK   rF   zT5GemmaEncoder.__init__       !.. ++LL):):F<N<NPTP`P`a"6#5#56;N;NO	&+#mmEJ6KcKcEde	 3e
 zz&"5"560? 	 f    D%Nr  r   r   inputs_embedsrI   r   c           	         |d u |d uz  rt        d      |j                  dd        || j                  |      }t        j                  d|j
                  d   |j                        }||j                  d      }|!t        ||| j                  j                        }t        |x}t              sb| j                  |||d |d}t        di |dt        |      it        di |t!        | j                  j"                        t        |      dd	}|}	t        j$                  | j                  j&                  d
z  |	j(                        }
|	|
z  }	| j+                  |	      }	| j-                  |	|      }| j.                  d | j                  j0                   D ]  } ||	|||j2                     |fi |}	 | j5                  |	      }	| j+                  |	      }	t7        |	      S )N:You must specify exactly one of input_ids or inputs_embedsrd   r   rS   r  r   input_embedsr   r   rd   r   or_mask_function)r7  and_mask_functionfull_attentionsliding_attention      ?r   )last_hidden_staterD   )r   popr(  r   aranger   r  	unsqueezer   r   r6   rk   r]   r%   r   r&   r   r>   tensorr+   r   r   r-  r   r-   r   r)  r   )rH   r  r   r   r1  rI   r   self_attn_mask_mappingmask_kwargsr   
normalizerr   layer_modules                rK   r   zT5GemmaEncoder.forward  s    -t";<YZZ 	

$d+  --i8Ma)<)<Q)?H\H\])33A6L!;I}VZVaVaVnVnoNNB0DI++ -"0"0#' ,K #5 #!#%@%P# &G &!&%OPTP[P[PjPj%k&A.&Q&
&" &\\$++"9"93">mFYFYZ
%
2]3"oom\J KK(G$++*G*GH 	L(#&|'B'BC	
 M	 		-0]3+
 	
rL   NNNN)rU   rV   rW   r   r   r  rF   r   r   r   r   r   r   r   r   r   r   r_   r`   s   @rK   r"  r"    s    *,
$  .2.20426A
##d*A
 t+A
 &&-	A

 ((4/A
 +,A
 
	 A
 A
rL   r"  c                   j    e Zd Z eed       eed      edZ fdZe		 	 	 	 	 	 	 	 	 dde
j                  dz  de
j                  dz  de
j                  dz  d	edz  d
e
j                  dz  dedz  de
j                  dz  de
j                  dz  de
j                  dz  dee   deez  fd       Z xZS )T5GemmaDecoderrS   )r   )r   cross_attentionsr   c           	      T   t         |   |       |j                  | _        |j                  | _        t        j                  |j                  |j                  | j                        | _        t        |j                  |j                        | _        d| _        t        j                  t        |j                        D cg c]  }t!        ||       c}      | _        t        j$                  |j&                        | _        t+        |      | _        | j/                          y c c}w r$  )rE   rF   r6   r&  r*   r}   r'  r+   r(  rv   r4   r)  r*  r+  r,  r-   r   r   r~   rh   r   r   r-  r.  r   s      rK   rF   zT5GemmaDecoder.__init__  r/  r0  Nr  r   r   rd   r1  r5   r   r   r   rI   r   c
                    |d u |d uz  rt        d      |t        d      || j                  |      }| j                  s,|r*|(t        t	        | j
                        t	                     }|F||j                         nd}t        j                  |||j                  d   z   |j                        }||j                  d      }|#|!t        ||| j
                  j                        }t        |x}t              s8| j
                  |||||j                   nd |d}t#        di |t%        di |d}t        |	x}t              s-| j
                  ||	|d d d}d	t#        di |d
t'        |	      ii}|}t        j(                  | j
                  j*                  dz  |j,                        }||z  }| j/                  |      }| j1                  ||      }| j2                  d | j
                  j4                   D ]#  } |||||j6                     ||||||d	   f	i |
}% | j9                  |      }| j/                  |      }t;        ||      S )Nr3  z0`encoder_hidden_states` must be given in decoderr%  r   rS   r4  r5  r9  r:  r7  r<  r   )r=  rd   rD   )r   r(  r   r	   r   r   get_seq_lengthr   r?  r   r  r@  r   r6   rk   r]   r   r%   r&   r   rA  r+   r   r   r-  r   r-   r   r)  r   )rH   r  r   r   rd   r1  r5   r   r   r   rI   past_seen_tokensrB  rC  cross_attn_mask_mappingr   rD  r   rE  s                      rK   r   zT5GemmaDecoder.forward  s    -t";<YZZ (OPP  --i8M}}/F 2,dkk2RT`TbcO!CRC^==?de"\\ "2]5H5H5K"KTaThThN )33A6L!o&=;I}VZVaVaVnVnoNNB0DI++ -"0"0KZKf?#G#Glp ,K #5"C{"C%F%U%U&"
 5KK1TR++ 5"8"0#' $K !"4 #!#%@AW%X#'# &\\$++"9"93">mFYFYZ
%
2]3"oom\J KK(G$++*G*GH 	L(#&|'B'BC%'(89 M	 		-0]38++
 	
rL   )	NNNNNNNNN)rU   rV   rW   r   r   r   r   r  rF   r   r   r   r   r	   r   r\   r   r   r   r   r   r_   r`   s   @rK   rH  rH    s/   $%9C*+@J,$  .2.2046:26!%26596:\
##d*\
 t+\
 &&-	\

 -t3\
 ((4/\
 $;\
 ((4/\
  %||d2\
 !&t 3\
 +,\
 
:	:\
 \
rL   rH  c                       e Zd Zdef fdZd Zd Zee	 	 	 	 	 	 	 	 	 	 	 	 dde	j                  dz  de	j                  dz  de	j                  dz  d	e	j                  dz  d
e	j                  dz  de	j                  dz  dedz  dedz  de	j                  dz  de	j                  dz  dedz  de	j                  dz  dee   defd              Z xZS )T5GemmaModelr   c                     t         |   |       |j                  st        d      t	        |j
                        | _        t        |j                        | _        | j                          y )NzVT5GemmaModel only support encoder-decoder modeling. Use `T5GemmaEncoderModel` instead.)	rE   rF   rg   r   r"  re   rH  rf   r.  r   s     rK   rF   zT5GemmaModel.__init__f  sO     ((uvv%fnn5%fnn5rL   c                 6    | j                   j                         S r|   re   get_input_embeddingsrH   s    rK   rT  z!T5GemmaModel.get_input_embeddingsq      ||0022rL   c                 8    | j                   j                  |      S r|   re   set_input_embeddingsrH   new_embeddingss     rK   rY  z!T5GemmaModel.set_input_embeddingst      ||00@@rL   Nr  r   r   decoder_input_idsdecoder_attention_maskdecoder_position_idsencoder_outputsrd   r1  decoder_inputs_embedsr5   r   rI   r   c                    | | j                   d||||	d|}|j                  } | j                  d||||
|||||d	|}t        |j                  |j                  |j                  dd      r|j                  n|j                  f|j                  |j                  |j                  |j                  |j                        S )aX  
        decoder_position_ids (`torch.LongTensor` of shape `(batch_size, decoder_sequence_length)`, *optional*):
            Indices of positions of each decoder input sequence tokens in the position embeddings. Selected in the range `[0,
            config.decoder.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
        r  r   r   r1  )	r  r   r   r1  rd   r   r   r5   r   output_hidden_statesF)r=  rd   decoder_hidden_statesdecoder_attentionsrI  encoder_last_hidden_stater   encoder_attentionsrD   )	re   r=  rf   r   rd   rp   r   r   rI  )rH   r  r   r   r]  r^  r_  r`  rd   r1  ra  r5   r   rI   r   decoder_outputss                   rK   r   zT5GemmaModel.forwardw  s    . "*dll #-)+	
 O !0 A A&$,, 
'1-/+"7#1)
 
 "-??+;;zz0%8 #2"?"?!335.99,==&5&G&G"1"?"?.99
 	
rL   )NNNNNNNNNNNN)rU   rV   rW   rb   rF   rT  rY  r   r   r   r   r   
BoolTensorr   r	   r   r\   r   r   r   r   r_   r`   s   @rK   rP  rP  d  sY   	} 	3A  .2370459:>8<266:-159!%268
##d*8
 ))D08
 &&-	8

 !++d28
 !& 0 04 78
 $..58
 )4/8
 -t38
 ||d*8
  %||d28
 $;8
 ((4/8
 +,8
 
8
  8
rL   rP  c                        e Zd Zdef fdZd Zd Zee	 	 	 	 dde	j                  dz  de	j                  dz  de	j                  dz  d	e	j                  dz  d
ee   defd              Z xZS )T5GemmaEncoderModelr   c                     t         |   |       |j                  rt        d      t	        |j
                        | _        | j                          y )NzQT5GemmaEncoderModel only supports encoder-only model. Use `T5GemmaModel` instead.)rE   rF   rg   r   r"  re   r.  r   s     rK   rF   zT5GemmaEncoderModel.__init__  s?     $$pqq%fnn5rL   c                 6    | j                   j                         S r|   rS  rU  s    rK   rT  z(T5GemmaEncoderModel.get_input_embeddings  rV  rL   c                 8    | j                   j                  |      S r|   rX  rZ  s     rK   rY  z(T5GemmaEncoderModel.set_input_embeddings  r\  rL   Nr  r   r   r1  rI   r   c                 4     | j                   d||||d|}|S )Nrc  rD   )re   )rH   r  r   r   r1  rI   r`  s          rK   r   zT5GemmaEncoderModel.forward  s7     '$,, 
)%'	

 
 rL   rF  )rU   rV   rW   rb   rF   rT  rY  r   r   r   r   r   r   r   r   r   r   r_   r`   s   @rK   rl  rl    s    } 3A  .23704-1##d* ))D0 &&-	
 ||d* +, 
  rL   rl  c            $       @    e Zd ZddiZddiZddgdgfiZdef fdZd	 Zd
 Z	e
e	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dej                  dz  dedz  dedz  dej                  dz  dej                  dz  dej                  dz  dedz  dej                  dz  deej(                  z  dee   deej                     ez  f d              Zdej(                  fdZ xZS )T5GemmaForConditionalGenerationzlm_head.out_proj.weightz!model.decoder.embed_tokens.weightzlm_head.out_projcolwise_gather_outputr   r   r   c                    d|_         t        | 	  |       t        |      | _        |j
                  j                  | _        t        |j
                  j                  | j                        | _	        d| _
        | j                          y )NTForMaskedLM)rg   rE   rF   rP  r   rf   r*   r   r+   lm_head	loss_typer.  r   s     rK   rF   z(T5GemmaForConditionalGeneration.__init__  sb    $(! !&)
 ..33$V^^%?%?Q&rL   c                 &    || j                   _        y r|   rv  r   rZ  s     rK   set_output_embeddingsz5T5GemmaForConditionalGeneration.set_output_embeddings  s     .rL   c                 .    | j                   j                  S r|   ry  rU  s    rK   get_output_embeddingsz5T5GemmaForConditionalGeneration.get_output_embeddings  s    ||$$$rL   Nr  r   r   r]  r^  r_  r`  rd   r1  ra  labelsr5   r   logits_to_keeprI   r   c                    |||
| j                  |      } | j                  d|||||||||	|
||d|}|j                  }t        |t              rt        | d      n|}| j                  |dd|ddf         }| j                         j                  }|j                  3||j                  z  }t        j                  |      }||j                  z  }d}| | j                  ||| j                  fi |}t        |||j                  |j                   |j"                  |j$                  |j&                  |j(                  |j*                  	      S )a  
        decoder_position_ids (`torch.LongTensor` of shape `(batch_size, decoder_sequence_length)`, *optional*):
            Indices of positions of each decoder input sequence tokens in the position embeddings. Selected in the range `[0,
            config.decoder.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
            config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
            (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
        N)r  r   r   r]  r^  r_  r`  rd   r1  ra  r5   r   )	lossr   rd   re  rf  rI  rg  r   rh  rD   )r  r   r=  rk   rY   slicerv  get_decoderr   r@   r   tanhloss_functionr*   r   rd   re  rf  rI  rg  r   rh  )rH   r  r   r   r]  r^  r_  r`  rd   r1  ra  r}  r5   r   r~  rI   ri  r   slice_indicesr   decoder_configr  s                         rK   r   z'T5GemmaForConditionalGeneration.forward  sv   < "3";@U@] $ 1 1& 9.8djj /
)%/#9!5++'"7)/
 /
  (998B>SV8W~ot4]kmA}a,?@A))+2211=nDDDFZZ'FnDDDF%4%%ffdooPPD+;;"1"G"G.AA,==&5&O&O"1"G"G.AA

 
	
rL   c                 $    | j                  |      S r|   )r  )rH   r}  s     rK   %prepare_decoder_input_ids_from_labelszET5GemmaForConditionalGeneration.prepare_decoder_input_ids_from_labels<  s      ((rL   )NNNNNNNNNNNNNr   )rU   rV   rW   _tied_weights_keys_tp_plan_pp_planrb   rF   rz  r|  r   r   r   r   r   rj  r   r	   r\   rY   r   r   r   r   r   r   r  r_   r`   s   @rK   rr  rr    s   35XY"$;<H"o%6
$CDH	} 	/%  .2370459:>8<266:26:>*.!%26-.I
##d*I
 ))D0I
 &&-	I

 !++d2I
 !& 0 04 7I
 $..5I
 )4/I
 -t3I
 ((4/I
  %0047I
   4'I
 $;I
 ((4/I
 ell*I
  +,!I
" 
u  	!O	3#I
  I
V)ELL )rL   rr  c                       e Zd Zddededz  f fdZd Zd Zee		 	 	 	 	 	 	 	 	 	 dde
j                  dz  de
j                  dz  d	e
j                  dz  d
e
j                  dz  de
j                  dz  de
j                  dz  dedz  de
j                  dz  de
j                  dz  de
j                  dz  dee   defd              Z xZS ) T5GemmaForSequenceClassificationNr   rg   c                    |||_         t        | 	  |       |j                  | _        |j                   rt	        |      | _        nt        |      | _        |j                  j                  }|j                   r|j                  j                  }t        |dd      }t        || j                  |      | _        | j                          y)z
        is_encoder_decoder (`Optional`, *optional*):
            Whether use encoder_decoder for sequence classification. When set to False, only encoder is used.
        Nri   皙?rg   rE   rF   r   rP  r   rl  re   r+   rf   ro   r   scorer.  rH   r   rg   r+   classifier_dropoutrJ   s        rK   rF   z)T5GemmaForSequenceClassification.__init__B  s    
 )(:F%  ++$$%f-DJ,V4DJnn00$$ ..44K$V-FL.{DOOM_`
rL   c                 6    | j                   j                         S r|   r   rT  rU  s    rK   rT  z5T5GemmaForSequenceClassification.get_input_embeddingsY      zz..00rL   c                 :    | j                   j                  |       y r|   r   rY  rH   values     rK   rY  z5T5GemmaForSequenceClassification.set_input_embeddings\      

''.rL   r  r   r   r]  r^  r_  r`  r1  ra  r}  rI   r   c                    | j                   j                  r'|%|#t        d| j                  j                   d      | j                   j                  r"| |	|t        d      | j                  |      }| j                   j                  rB | j                  |f||||||||	dd	|}|j                  }|j                  }|j                  }n; | j                  |f|||d|}|j                  }|j                  }|j                  }| j                  |      }||j                  d   }n|j                  d   }| j                   j                  |d	k7  rt        d
      | j                   j                  d}n||| j                   j                  k7  j!                  |j"                  t$        j&                        }t%        j(                  |j                  d   |j"                  t$        j&                        }||z  j+                  d      }| j                   j                  r[|d	z  }t%        j,                  ||j                  d   d	z
        }n.d}t.        j1                  | j                  j                   d       |t%        j(                  ||j"                        |f   }d}|
| j3                  ||
|| j                         }t5        ||||      S )  
        decoder_position_ids (`torch.LongTensor` of shape `(batch_size, decoder_sequence_length)`, *optional*):
            Indices of positions of each decoder input sequence tokens in the position embeddings. Selected in the range `[0,
            config.decoder.n_positions - 1]`. [What are position IDs?](../glossary#position-ids)
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        N8Passing input embeddings is currently not supported for  in encoder-decoder mode.If no `decoder_input_ids` or `decoder_inputs_embeds` are passed, `input_ids` cannot be `None`. Please pass either `input_ids` or `decoder_input_ids` or `decoder_inputs_embeds`.F	r   r   r]  r^  r_  r`  r1  ra  r5   r   r   r1  r   rS   z=Cannot handle batch sizes > 1 if no padding token is defined.r   r  )maxz will not detect padding tokens in `inputs_embeds`. Results may be unexpected if using padding tokens in conjunction with `inputs_embeds.`r4  )r   r}  pooled_logitsr   r  r   r   r   )r   rg   NotImplementedErrorrJ   rU   r   r  r   r=  re  rf  r   r   r  r   r6   r   r  r   int32r?  argmaxclamploggerwarning_oncer  r   )rH   r  r   r   r]  r^  r_  r`  r1  ra  r}  rI   outputsr=  r   r   r   
batch_sizelast_non_pad_tokennon_pad_masktoken_indicesr  r  s                          rK   r   z(T5GemmaForSequenceClassification.forward_  s   2 ;;))y/@]E^%J4>>KbKbJcc|} 
 ;;))/@/HMbMj  U 
 !% 1 1) <;;))*4$**+-)"3'=%9 /+&;+ +G !( 9 9#99M 33J'1tzz(-)+	(
 (G !( 9 9#11M ++J-. "+J&,,Q/J;;##+
a\]];;##+!#"%)A)AAEEfmmUZU`U`aL!LL)<V]]Z_ZeZefM"/,">!F!Fr!J{{--"a'"%*[[1CIZI`I`acIdghIh%i"!#>>**+ ,Z Z
 u||Jv}}MOaab%%VFR_hlhshs%tD' '!	
 	
rL   r|   
NNNNNNNNNN)rU   rV   rW   rb   r\   rF   rT  rY  r   r   r   r   r   r   r   r   r   r   r   r_   r`   s   @rK   r  r  @  sN   } $+ .1/  .2.204596:8<2626:>*.i
##d*i
 t+i
 &&-	i

 !++d2i
 !&t 3i
 $..5i
 )4/i
 ((4/i
  %0047i
   4'i
 +,i
 
"i
  i
rL   r  c                       e Zd Zddededz  f fdZd Zd Zee		 	 	 	 	 	 	 	 	 	 dde
j                  dz  de
j                  dz  d	e
j                  dz  d
e
j                  dz  de
j                  dz  de
j                  dz  dedz  de
j                  dz  de
j                  dz  de
j                  dz  dee   defd              Z xZS )T5GemmaForTokenClassificationNr   rg   c                    |||_         t        | 	  |       |j                  | _        |j                   rt	        |      | _        nt        |      | _        |j                  j                  }|j                   r|j                  j                  }t        |dd      }t        || j                  |      | _        | j                          y)z
        is_encoder_decoder (`Optional`, *optional*):
            Whether use encoder_decoder for token classification. When set to False, only encoder is used.
        Nri   r  r  r  s        rK   rF   z&T5GemmaForTokenClassification.__init__  s    
 )(:F%  ++$$%f-DJ,V4DJnn00$$ ..44K$V-FL.{DOOM_`
rL   c                 6    | j                   j                         S r|   r  rU  s    rK   rT  z2T5GemmaForTokenClassification.get_input_embeddings  r  rL   c                 :    | j                   j                  |       y r|   r  r  s     rK   rY  z2T5GemmaForTokenClassification.set_input_embeddings  r  rL   r  r   r   r]  r^  r_  r`  r1  ra  r}  rI   r   c                    | j                   j                  r'|%|#t        d| j                  j                   d      | j                   j                  r"| |	|t        d      | j                  |      }| j                   j                  rB | j                  |f||||||||	dd	|}|j                  }|j                  }|j                  }n; | j                  |f|||d|}|j                  }|j                  }|j                  }| j                  |      }d}|
| j                  ||
| j                         }t        ||||      S )	r  Nr  r  r  Fr  r  r  )r   rg   r  rJ   rU   r   r  r   r=  re  rf  r   r   r  r  r   )rH   r  r   r   r]  r^  r_  r`  r1  ra  r}  rI   r  r=  r   r   r   r  s                     rK   r   z%T5GemmaForTokenClassification.forward  s   4 ;;))y/@]E^%J4>>KbKbJcc|}  ;;))/@/HMbMj  U 
 !% 1 1) <;;))*4$**+-)"3'=%9 /+&;+ +G !( 9 9#99M 33J'1tzz(-)+	(
 (G !( 9 9#11M ++J-.%%ffdkkBD$'!	
 	
rL   r|   r  )rU   rV   rW   rb   r\   rF   rT  rY  r   r   r   r   r   r   r   r   r   r   r   r_   r`   s   @rK   r  r    sN   } $+ 01/  .2.204596:8<2626:>*.N
##d*N
 t+N
 &&-	N

 !++d2N
 !&t 3N
 $..5N
 )4/N
 ((4/N
  %0047N
   4'N
 +,N
 
N
  N
rL   r  )rb   r)   rr  rP  rl  r   r  r  )Vcollections.abcr   typingr   r   torch.nnr}    r   r  cache_utilsr   r   r	   configuration_utilsr
   
generationr   modeling_flash_attention_utilsr   modeling_layersr   modeling_outputsr   r   r   r   r   r   modeling_rope_utilsr   modeling_utilsr   r   processing_utilsr   utilsr   r   r   r   utils.genericr   r   gemma2.configuration_gemma2r   gemma2.modeling_gemma2r    r!   r"   r#   r$   r%   r&   r'   _CHECKPOINT_FOR_DOC
get_loggerrU   r  r)   rb   rv   rz   r   r   r   r   r   rY   r   r   r   Moduler   r   r   r   r   r"  rH  rP  rl  rr  r  r  __all__rD   rL   rK   <module>r     sZ   %    & C C 3 ) B 9  2 F &  @ 6	 	 	 9  
		H	%M-, M-`[%$ [%|	] 		 		2 	+? +D)O D)N
t0C 
 
s x 14 1hH4 HV		 	BII 	 8!2 8! 8!v$&<< * \\	"Z
+ Z
zv
+ v
r L
) L
 L
^ !0 ! !Hd)&<o d)N I
'= I
 I
X o
$: o
 o
d	rL   