
    +iD                        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* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 dZ9 e(jt                  e;      Z< G d de/      Z= G d de      Z> G d de4      Z? G d de2      Z@ G d de5      ZA G d  d!e1      ZB G d" d#e1      ZCd$ej                  dz  d%efd&ZEd'eFd%efd(ZG G d) d*e      ZH G d+ d,e      ZI G d- d.ej                        ZK G d/ d0ej                        ZLe& G d1 d2e3             ZMd3ej                  dz  d4ej                  d5eFdz  d%ej                  fd6ZO G d7 d8eM      ZP G d9 d:eM      ZQe& G d; d<eM             ZRe& G d= d>eM             ZS G d? d@eMe      ZTe& G dA dBeM             ZUe& G dC dDeM             ZVg dEZWy)F    )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)merge_with_config_defaults)OutputRecordercapture_outputs   )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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB    )rC   super__init__use_bidirectional_attention)selfr+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   kwargs	__class__s                              g/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/transformers/models/t5gemma/modular_t5gemma.pyrG   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        rR   i   Ng      >@g      I@F)__name__
__module____qualname____doc__intstrfloatboolr   dictlistrG   __classcell__rK   s   @rL   r*   r*   A   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:- :-rM   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decoderNrf   rg   is_encoder_decoderdropout_rateclassifier_dropout_rater=   r:   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)r9   r7   r8   r4   rE   )
isinstancer^   r*   typeto_dictrC   ri   r=   rf   r6   r,   cross_attention_hidden_sizerg   getattrrF   rG   rh   getr4   rj   r:   r+   )rI   rf   rg   rh   ri   rj   r=   r:   r+   rJ   special_token_keyrK   s              rL   rG   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  %rM   )NNTrU   rU   rU   TrN   )rV   rW   rX   rY   
model_typekeys_to_ignore_at_inferencer*   sub_configsr^   r   r]   r\   rZ   rG   r`   ra   s   @rL   rc   rc      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%rM   rc   c                       e Zd Zy)T5GemmaRMSNormNrV   rW   rX   rE   rM   rL   rw   rw   /      rM   rw   c                   $     e Zd Z fdZd Z xZS )
T5GemmaMLPc                 l    t         |   |       t        j                  |j                        | _        y N)rF   rG   nnDropoutri   dropoutrI   configrK   s     rL   rG   zT5GemmaMLP.__init__4  s&     zz&"5"56rM   c                     | j                  | j                  |            | j                  |      z  }| j                  |      }| j	                  |      }|S r}   )act_fn	gate_projup_projr   	down_proj)rI   xhidden_statesr   s       rL   forwardzT5GemmaMLP.forward8  sH    DNN1$56aH]3NN=1	rM   )rV   rW   rX   rG   r   r`   ra   s   @rL   r{   r{   3  s    7rM   r{   c                       e Zd Zy)T5GemmaRotaryEmbeddingNrx   rE   rM   rL   r   r   ?  ry   rM   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}   )rF   rG   rC   	is_causalrI   r   r   rK   s      rL   rG   zT5GemmaSelfAttention.__init__D  s    +**rM   )rV   rW   rX   r*   rZ   rG   r`   ra   s   @rL   r   r   C  s    +2 +s + +rM   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)rF   rG   r?   
layer_typer   ro   
ValueErrorr~   Linearr0   r1   r<   k_projv_projr   s      rL   rG   zT5GemmaCrossAttention.__init__K  s    +O--5abbii..0J0JT]]0Zagavav
 ii..0J0JT]]0Zagavav
rM   Nr   attention_maskencoder_hidden_statesre   rJ   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.rT   r   TrU   )r   scalingr?   softcap)r   shaper1   q_projview	transpose
is_updatedrq   r   cross_attention_cacher   r   updatelayerskeysvaluesr   get_interfacer   _attn_implementationr(   trainingr=   r   rB   reshape
contiguouso_proj)rI   r   r   r   re   rJ   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                     rL   r   zT5GemmaCrossAttention.forward[  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((rM   r}   )rV   rW   rX   r*   rZ   rG   torchTensorr   r   r   tupler   r`   ra   s   @rL   r   r   J  s    
2 
s 
* )-3)||3) t+3)  %||d2	3)
 3) -.3) 
u||U\\D0%2E2LL	M3)rM   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 )NrE   dtype)r   onesr]   to)r   r   r   r   r   s       rL   
inner_maskz/bidirectional_mask_function.<locals>.inner_mask  s=    !::b

33i/033EJJ??rM   rZ   r]   )r   r   s   ` rL   bidirectional_mask_functionr     s9    
@c @S @ @c @d @
 rM   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}   rE   )r   r   r   r   r?   s       rL   r   z>sliding_window_bidirectional_mask_function.<locals>.inner_mask  s"    &/FU^=S4STTrM   r   )r?   r   s   ` rL   *sliding_window_bidirectional_mask_functionr     s9    
Uc US U Uc Ud U rM   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)rF   rG   r,   r   r   r@   attention_typer   	self_attnrw   r5   pre_self_attn_layernormpost_self_attn_layernormr{   mlppre_feedforward_layernormpost_feedforward_layernormr~   r   ri   r   r   s      rL   rG   zT5GemmaEncoderLayer.__init__  s    !--"$00;-
 (6f6H6HfNaNa'b$(6v7I7IvObOb(c%f%)78J8JPVPcPc)d&*89K9KQWQdQd*e'zz&"5"56rM   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   re   rE   )r   r   r   r   r   r   r   )rI   r   r   r   r   rJ   residual_s           rL   r   zT5GemmaEncoderLayer.forward  s     !44]C)4>> 
' 3)% 
 
q 55mD 4<<#>> 66}E/77F 4<<#>>rM   )NNN)rV   rW   rX   rY   rZ   rG   r   r   r   
LongTensorFloatTensorr   r`   ra   s   @rL   r   r     s    7# 7. IM.204|| #5<<#=>E t+	
 &&- 
u  !	"rM   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   )rF   rG   r,   r   r   r@   r   r   r   rw   r5   r   r   r{   r   r   r   r~   r   ri   r   r   
cross_attnpre_cross_attn_layernormpost_cross_attn_layernormr   s      rL   rG   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&rM   Nr   r   r   r   re   r6   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   re   r6   r   )r   r   r   re   r6   rE   )r   r   self_attention_cacher   r   r   r   r   r   r   r   )rI   r   r   r   r   re   r6   r   r   r   rJ   r   r   s                rL   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<<#>>rM   )NNNNFNNN)rV   rW   rX   rY   rZ   rG   r   r   r   r   r	   r]   r   r   r`   ra   s   @rL   r   r     s    <e# e4 IM.2046:!&26596:.||. #5<<#=>E. t+	.
 &&-. -t3. $;. ((4/.  %||d2. !&t 3. 
		.rM   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_labelsrj   c                     t         |           t        j                  |      | _        t        j
                  ||      | _        y )N)p)rF   rG   r~   r   r   r   out_proj)rI   r,   r   rj   rK   s       rL   rG   z"T5GemmaClassificationHead.__init__+  s1    zz$;<		+z:rM   r   r   c                 J    | j                  |      }| j                  |      }|S r}   )r   r   )rI   r   s     rL   r   z!T5GemmaClassificationHead.forward0  s$    ]3m4rM   )rU   )rV   rW   rX   rY   rZ   r\   rG   r   r   r   r`   ra   s   @rL   r   r   (  s<    7;C ;S ;SX ;
U\\ ell rM   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   )rF   rG   r~   r   r   )rI   r,   r+   r   rK   s       rL   rG   zT5GemmaLMHead.__init__9  s"    		+zErM   r   r   c                 (    | j                  |      }|S r}   )r   )rI   r   logitss      rL   r   zT5GemmaLMHead.forward=  s    }-rM   )F)rV   rW   rX   rY   rZ   r]   rG   r   r   r   r`   ra   s   @rL   r   r   6  s?    8FC FS F FU\\ ell rM   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   rT   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      rU   )meanstdr   RMSNorm)r   _init_weightsr   r4   rl   r   r   weightr   initnormal_hasattrr   zeros_r   r:   rK   rV   )rI   moduler  scales       rL   r  z$T5GemmaPreTrainedModel._init_weightsQ  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& 4rM   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   rT   ).r   z9self.model.config.decoder.pad_token_id has to be defined.i)	r   rg   r9   r7   r   	new_zerosr   clonemasked_fill_)rI   	input_idsdecoder_start_token_idr7   shifted_input_idss        rL   _shift_rightz#T5GemmaPreTrainedModel._shift_rightc  s     "&!4!4!A!A{{**77!)YZZ &//	@%.sCRCx%8%>%>%@#qr'"$:&!XYY 	&&'8D'@,O  rM   N)rV   rW   rX   rc   __annotations__base_model_prefixsupports_gradient_checkpointing_no_split_modulesr   r   r   r   _can_record_outputsr   no_gradr  r  rE   rM   rL   r   r   B  sx    &*#.0EF,/q[Q/q\R0lS
 U]]_' '"!rM   r   	token_idsr   r7   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   rT   devicer   )r   r   r  r   longr   r   )r  r   r7   r   s       rL   make_default_2d_attention_maskr!  ~  s     RSS#|3778L8LejjY
    #]%8%8%;<]EYEYafakak
 rM   c                        e Zd ZeedZ f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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   )rF   rG   r7   padding_idxr+   r~   	Embeddingr,   embed_tokensrw   r5   normgradient_checkpointing
ModuleListranger.   r   r   r   ri   r   r   
rotary_emb	post_initr   s      rL   rG   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_embedsrJ   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_embedsre   r   rT   r  r   r2  r   r   re   r   or_mask_function)r7  and_mask_functionfull_attentionsliding_attention      ?r   )last_hidden_staterE   )r   popr)  r   aranger   r  	unsqueezer!  r   r7   rl   r^   r&   r   r'   r   r?   tensorr,   r   r   r.  r   r.   r   r*  r   )rI   r  r   r   r2  rJ   r   self_attn_mask_mappingmask_kwargsr   
normalizerr   layer_modules                rL   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+
 	
rM   NNNN)rV   rW   rX   r   r   r  rG   r   r   r   r   r   r   r   r   r   r   r   r`   ra   s   @rL   r#  r#    s    *,
$   .2.20426A
##d*A
 t+A
 &&-	A

 ((4/A
 +,A
 
	 A
   A
rM   r#  c                   t    e Zd Z eed       eed      edZ fdZe	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 )T5GemmaDecoderrT   )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%  )rF   rG   r7   r'  r+   r~   r(  r,   r)  rw   r5   r*  r+  r,  r-  r.   r   r   r   ri   r   r   r.  r/  r   s      rL   rG   zT5GemmaDecoder.__init__  r0  r1  Nr  r   r   re   r2  r6   r   r   r   rJ   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 )Nr4  z0`encoder_hidden_states` must be given in decoderr&  r   rT   r5  r6  r9  r:  r7  r<  r   )r=  re   rE   )r   r)  r   r	   r   r   get_seq_lengthr   r?  r   r  r@  r!  r7   rl   r^   r   r&   r'   r   rA  r,   r   r   r.  r   r.   r   r*  r   )rI   r  r   r   re   r2  r6   r   r   r   rJ   past_seen_tokensrB  rC  cross_attn_mask_mappingr   rD  r   rE  s                      rL   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++!6"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++
 	
rM   )	NNNNNNNNN)rV   rW   rX   r   r   r   r   r  rG   r   r   r   r   r   r	   r   r]   r   r   r   r   r   r`   ra   s   @rL   rH  rH    s7   $%9C*+@J,$   .2.2046:26!%26596:\
##d*\
 t+\
 &&-	\

 -t3\
 ((4/\
 $;\
 ((4/\
  %||d2\
 !&t 3\
 +,\
 
:	:\
   \
rM   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.)	rF   rG   rh   r   r#  rf   rH  rg   r/  r   s     rL   rG   zT5GemmaModel.__init__i  sO     ((uvv%fnn5%fnn5rM   c                 6    | j                   j                         S r}   rf   get_input_embeddingsrI   s    rL   rT  z!T5GemmaModel.get_input_embeddingst      ||0022rM   c                 8    | j                   j                  |      S r}   rf   set_input_embeddingsrI   new_embeddingss     rL   rY  z!T5GemmaModel.set_input_embeddingsw      ||00@@rM   Nr  r   r   decoder_input_idsdecoder_attention_maskdecoder_position_idsencoder_outputsre   r2  decoder_inputs_embedsr6   r   rJ   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   r2  )	r  r   r   r2  re   r   r   r6   r   output_hidden_statesF)r=  re   decoder_hidden_statesdecoder_attentionsrI  encoder_last_hidden_stater   encoder_attentionsrE   )	rf   r=  rg   r   re   rq   r   r  rI  )rI   r  r   r   r]  r^  r_  r`  re   r2  ra  r6   r   rJ   r   decoder_outputss                   rL   r   zT5GemmaModel.forwardz  s    . "*dll #-)+	
 O !0 A A&$,, 
'1-/+"7#1)
 
 "-??+;;zz0%8 #2"?"?!335.99,==&5&G&G"1"?"?.99
 	
rM   )NNNNNNNNNNNN)rV   rW   rX   rc   rG   rT  rY  r   r   r   r   r   
BoolTensorr   r	   r   r]   r   r   r   r   r`   ra   s   @rL   rP  rP  g  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
rM   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.)rF   rG   rh   r   r#  rf   r/  r   s     rL   rG   zT5GemmaEncoderModel.__init__  s?     $$pqq%fnn5rM   c                 6    | j                   j                         S r}   rS  rU  s    rL   rT  z(T5GemmaEncoderModel.get_input_embeddings  rV  rM   c                 8    | j                   j                  |      S r}   rX  rZ  s     rL   rY  z(T5GemmaEncoderModel.set_input_embeddings  r\  rM   Nr  r   r   r2  rJ   r   c                 4     | j                   d||||d|}|S )Nrc  rE   )rf   )rI   r  r   r   r2  rJ   r`  s          rL   r   zT5GemmaEncoderModel.forward  s7     '$,, 
)%'	

 
 rM   rF  )rV   rW   rX   rc   rG   rT  rY  r   r   r   r   r   r   r   r   r   r   r`   ra   s   @rL   rl  rl    s    } 3A  .23704-1##d* ))D0 &&-	
 ||d* +, 
  rM   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)rh   rF   rG   rP  r   rg   r+   r   r,   lm_head	loss_typer/  r   s     rL   rG   z(T5GemmaForConditionalGeneration.__init__  sb    $(! !&)
 ..33$V^^%?%?Q&rM   c                 &    || j                   _        y r}   rv  r   rZ  s     rL   set_output_embeddingsz5T5GemmaForConditionalGeneration.set_output_embeddings  s     .rM   c                 .    | j                   j                  S r}   ry  rU  s    rL   get_output_embeddingsz5T5GemmaForConditionalGeneration.get_output_embeddings  s    ||$$$rM   Nr  r   r   r]  r^  r_  r`  re   r2  ra  labelsr6   r   logits_to_keeprJ   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`  re   r2  ra  r6   r   )	lossr   re   re  rf  rI  rg  r   rh  rE   )r  r   r=  rl   rZ   slicerv  get_decoderr   rA   r   tanhloss_functionr+   r   re   re  rf  rI  rg  r   rh  )rI   r  r   r   r]  r^  r_  r`  re   r2  ra  r}  r6   r   r~  rJ   ri  r   slice_indicesr   decoder_configr  s                         rL   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

 
	
rM   c                 $    | j                  |      S r}   )r  )rI   r}  s     rL   %prepare_decoder_input_ids_from_labelszET5GemmaForConditionalGeneration.prepare_decoder_input_ids_from_labels?  s      ((rM   )NNNNNNNNNNNNNr   )rV   rW   rX   _tied_weights_keys_tp_plan_pp_planrc   rG   rz  r|  r   r   r   r   r   rj  r   r	   r]   rZ   r   r   r   r   r   r   r  r`   ra   s   @rL   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 )rM   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   rh   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.
        Nrj   皙?rh   rF   rG   r   rP  r   rl  rf   r,   rg   rp   r   scorer/  rI   r   rh   r,   classifier_dropoutrK   s        rL   rG   z)T5GemmaForSequenceClassification.__init__E  s    
 )(:F%  ++$$%f-DJ,V4DJnn00$$ ..44K$V-FL.{DOOM_`
rM   c                 6    | j                   j                         S r}   r   rT  rU  s    rL   rT  z5T5GemmaForSequenceClassification.get_input_embeddings\      zz..00rM   c                 :    | j                   j                  |       y r}   r   rY  rI   values     rL   rY  z5T5GemmaForSequenceClassification.set_input_embeddings_      

''.rM   r  r   r   r]  r^  r_  r`  r2  ra  r}  rJ   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`  r2  ra  r6   r   r   r2  r   rT   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.`r5  )r   r}  pooled_logitsr   r  r   r   r  )r   rh   NotImplementedErrorrK   rV   r   r  r   r=  re  rf  r   r  r  r   r7   r   r  r   int32r?  argmaxclamploggerwarning_oncer  r   )rI   r  r   r   r]  r^  r_  r`  r2  ra  r}  rJ   outputsr=  r   r  r   
batch_sizelast_non_pad_tokennon_pad_masktoken_indicesr  r  s                          rL   r   z(T5GemmaForSequenceClassification.forwardb  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' '!	
 	
rM   r}   
NNNNNNNNNN)rV   rW   rX   rc   r]   rG   rT  rY  r   r   r   r   r   r   r   r   r   r   r   r`   ra   s   @rL   r  r  C  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
rM   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   rh   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.
        Nrj   r  r  r  s        rL   rG   z&T5GemmaForTokenClassification.__init__  s    
 )(:F%  ++$$%f-DJ,V4DJnn00$$ ..44K$V-FL.{DOOM_`
rM   c                 6    | j                   j                         S r}   r  rU  s    rL   rT  z2T5GemmaForTokenClassification.get_input_embeddings  r  rM   c                 :    | j                   j                  |       y r}   r  r  s     rL   rY  z2T5GemmaForTokenClassification.set_input_embeddings  r  rM   r  r   r   r]  r^  r_  r`  r2  ra  r}  rJ   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   rh   r  rK   rV   r   r  r   r=  re  rf  r   r  r  r  r   )rI   r  r   r   r]  r^  r_  r`  r2  ra  r}  rJ   r  r=  r   r  r   r  s                     rL   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$'!	
 	
rM   r}   r  )rV   rW   rX   rc   r]   rG   rT  rY  r   r   r   r   r   r   r   r   r   r   r   r`   ra   s   @rL   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
rM   r  )rc   r*   rr  rP  rl  r   r  r  )X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   utils.output_capturingr   r   gemma2.configuration_gemma2r    gemma2.modeling_gemma2r!   r"   r#   r$   r%   r&   r'   r(   _CHECKPOINT_FOR_DOC
get_loggerrV   r  r*   rc   rw   r{   r   r   r   r   r   rZ   r   r   r   Moduler   r   r   r   r!  r#  rH  rP  rl  rr  r  r  __all__rE   rM   rL   <module>r     s\   %    & C C 3 ) B 9  2 F &  8 E 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$&<< * \\	"[
+ [
|w
+ w
t L
) L
 L
^ !0 ! !Hd)&<o d)N I
'= I
 I
X o
$: o
 o
d	rM   