Ë
    T^(hÑÄ ã                   ó  — d Z ddlZddlZddlZddlZddlmZmZmZm	Z	 ddl
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mZmZ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!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7  e.«       rddl8m9Z9 ddl:m;Z;  e1jx                  e=«      Z>dZ?dZ@d„ ZAdZBdZC G d„ dejˆ                  «      ZE	 ddlFmGZG eGZEe>j‘                  d«        e&j˜                  eE«        G d„ dejˆ                  «      ZM G d „ d!ejˆ                  «      ZN G d"„ d#ejˆ                  «      ZO G d$„ d%ejˆ                  «      ZP G d&„ d'ejˆ                  «      ZQ G d(„ d)ejˆ                  «      ZR G d*„ d+ejˆ                  «      ZS G d,„ d-ejˆ                  «      ZT G d.„ d/e$«      ZU G d0„ d1eU«      ZVd2ZWd3ZXd4ZYd5ZZ e,d6eW«       G d7„ d8eU«      «       Z[ e,d9eW«       G d:„ d;eUe«      «       Z\ e,d<eW«       G d=„ d>eU«      «       Z] e,d?eW«       G d@„ dAeU«      «       Z^ e,dBeW«       G dC„ dDeU«      «       Z_ e,dEeW«       G dF„ dGeU«      «       Z`g dH¢Zay# eI$ r Y �ŒpeJ$ r e>j—                  d«       Y �Œˆw xY w)IzPyTorch T5 model.é    N)ÚListÚOptionalÚTupleÚUnion)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )ÚACT2FN)ÚCacheÚDynamicCacheÚEncoderDecoderCacheÚStaticCache)ÚGenerationMixin)ÚAttentionMaskConverter)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚSeq2SeqLMOutputÚSeq2SeqModelOutputÚ#Seq2SeqQuestionAnsweringModelOutputÚSeq2SeqSequenceClassifierOutputÚTokenClassifierOutput)ÚPreTrainedModel)ÚALL_LAYERNORM_LAYERSÚ find_pruneable_heads_and_indicesÚprune_linear_layer)	ÚDUMMY_INPUTSÚ
DUMMY_MASKÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚis_torch_flex_attn_availableÚis_torch_fx_proxyÚis_torchdynamo_compilingÚloggingÚreplace_return_docstrings)Úassert_device_mapÚget_device_mapé   )ÚT5Config)Ú	BlockMask)Úmake_flex_block_causal_maskr*   zgoogle-t5/t5-smallc           	      óª	  — 	 ddl }ddl}ddl}t        j                  j                  |«      }t        j                  d|› �«       |j                  j                  |«      }g }i }	|D ]R  \  }
}t        j                  d|
› d|› �«       |j                  j                  ||
«      }|j                  |
«       ||	|
<   ŒT |D �]E  }|j                  d«      }
t        d„ |
D «       «      r:t        j                  d	dj!                  |
«      › �«       |	j#                  |d«       Œad
|
d   v r:t        j                  d	dj!                  |
«      › �«       |	j#                  |d«       Œ¢| }|	|   }|
D �]¨  }|j%                  d|«      r|j                  d|«      }n|g}|d   dv rt'        |d«      }�nE|d   dk(  rt'        |d«      }|d   }�n*|d   dk(  rt'        |d«      }|d   }�n|d   dk(  rt'        |d«      }|d   }nõ|d   dk(  r2t)        |d«      rt'        |d«      }nÔt)        |d«      rÈt'        |d«      }n»|d   dk(  rt'        |d«      }n¦|d   dk(  s|d   dk(  rt'        |d«      }n‰|d   dk(  rt'        |d«      }nt|d   dk(  r
|
d   d k(  r�Œ$|d   d k(  rt'        |d!«      }nM|d   d"k(  r5t+        |«      dkD  r'|d   j-                  «       rt'        |d#|d   › �«      }�Œv	 t'        ||d   «      }t+        |«      dk\  s�Œ–t1        |d   «      }||   }�Œ« d   dvrt'        |d«      }|d   d$k7  r6t        j                  d%|j2                  › d&|
› �«       |j5                  |«      }	 |j2                  |j2                  k7  r&t7        d'|j2                  › d(|j2                  › d)�«      ‚	 t        j                  d*|
› �«       t=        j>                  |jA                  |jB                  «      «      |_"        |	j#                  |d«       �ŒH t        j                  d+d,j!                  |	jG                  «       «      › d-�«       | S # t        $ r t        j                  d«       ‚ w xY w# t.        $ r+ t        j                  d	dj!                  |
«      › �«       Y �Œ,w xY w# t8        $ r1}|xj:                  |j2                  |j2                  fz  c_        ‚ d}~ww xY w).z'Load tf checkpoints in a pytorch model.r   Nz™Loading a TensorFlow model in PyTorch, requires TensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions.z&Converting TensorFlow checkpoint from zLoading TF weight z with shape ú/c              3   ó$   K  — | ]  }|d v –— Œ
 y­w))Úadam_vÚadam_mÚAdamWeightDecayOptimizerÚAdamWeightDecayOptimizer_1Úglobal_stepN© )Ú.0Úns     ú`/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/t5/modeling_t5.pyú	<genexpr>z(load_tf_weights_in_t5.<locals>.<genexpr>k   s   è ø€ ò 
àð ÐnÔnñ
ùó   ‚z	Skipping Ú_slot_éÿÿÿÿz[A-Za-z]+_\d+z_(\d+))ÚkernelÚscaleÚ	embeddingÚweightÚself_attentionÚlayerÚenc_dec_attentionr)   Údense_relu_denseé   Úrms_normÚ
layer_normÚfinal_layer_normr>   Úoutput_biasÚbetaÚbiasÚsquadÚ
classifierÚdecoderÚlogitsÚlm_headÚwiÚwi_r?   z"Transposing numpy weight of shape z for zPointer shape z and array shape ú mismatchedzInitialize PyTorch weight z%Weights not copied to PyTorch model: z, ú.)$ÚreÚnumpyÚ
tensorflowÚImportErrorÚloggerÚerrorÚosÚpathÚabspathÚinfoÚtrainÚlist_variablesÚload_variableÚappendÚsplitÚanyÚjoinÚpopÚ	fullmatchÚgetattrÚhasattrÚlenÚisdigitÚAttributeErrorÚintÚshapeÚ	transposeÚ
ValueErrorÚAssertionErrorÚargsÚtorchÚ
from_numpyÚastypeÚfloat32ÚdataÚkeys)ÚmodelÚconfigÚtf_checkpoint_pathrU   ÚnpÚtfÚtf_pathÚ	init_varsÚnamesÚ
tf_weightsÚnamern   ÚarrayÚtxt_nameÚpointerÚm_nameÚscope_namesÚnumÚes                      r8   Úload_tf_weights_in_t5rŠ   N   sã  € ð
ÛãÛô �g‰g�o‰oÐ0Ó1€GÜ
‡K�KÐ8¸¸	ÐBÔCà—‘×'Ñ'¨Ó0€IØ€EØ€JØ ò !‰ˆˆeÜ�‰Ð(¨¨¨l¸5¸'ÐBÔCØ—‘×&Ñ& w°Ó5ˆØ�‰�TÔØ ˆ
�4Òð	!ð ó J'ˆØ�~‰~˜cÓ"ˆô ñ 
àô
ô 
ô �K‰K˜) C§H¡H¨T£NÐ#3Ð4Ô5Ø�N‰N˜8 TÔ*ØØ�t˜B‘xÑÜ�K‰K˜) C§H¡H¨T£NÐ#3Ð4Ô5Ø�N‰N˜8 TÔ*ØØˆØ˜8Ñ$ˆàó *	'ˆFØ�|‰|Ð,¨fÔ5Ø Ÿh™h y°&Ó9‘à%˜h�Ø˜1‰~Ð!AÑAÜ! '¨8Ó4’Ø˜Q‘Ð#3Ò3Ü! '¨7Ó3�Ø! !™*’Ø˜Q‘Ð#6Ò6Ü! '¨7Ó3�Ø! !™*’Ø˜Q‘Ð#5Ò5Ü! '¨7Ó3�Ø! !™*‘Ø˜Q‘ :Ò-Ü˜7 LÔ1Ü% g¨|Ó<‘GÜ˜WÐ&8Ô9Ü% gÐ/AÓB‘GØ˜Q‘ 7Ò*Ü! '¨8Ó4‘Ø˜Q‘ =Ò0°KÀ±NÀfÒ4LÜ! '¨6Ó2‘Ø˜Q‘ 7Ò*Ü! '¨<Ó8‘Ø˜Q‘ 9Ò,°°a±¸HÒ1DÙØ˜Q‘ 8Ò+Ü! '¨9Ó5‘Ø˜Q‘ 4Ò'¬C°Ó,<¸qÒ,@À[ÐQRÁ^×E[ÑE[ÔE]Ü! '¨S°¸Q±Ð0@Ð+AÓB�ÙðÜ% g¨{¸1©~Ó>�Gô �;Ó 1Ô$Ü˜+ a™.Ó)�Ø! #™,’ðU*	'ðV �q‰>Ð!AÑAÜ˜g xÓ0ˆGØ�q‰>˜[Ò(Ü�K‰KÐ<¸U¿[¹[¸MÈÈtÈfÐUÔVØ—L‘L Ó'ˆEð	Ø�}‰} §¡Ò+Ü  >°'·-±-°Ð@QÐRW×R]ÑR]ÐQ^Ð^iÐ!jÓkÐkð ,ô
 	�‰Ð0°°Ð7Ô8Ü×'Ñ'¨¯©°R·Z±ZÓ(@ÓAˆŒØ�‰�x Ö&ðUJ'ôX ‡K�KÐ7¸¿	¹	À*Ç/Á/ÓBSÓ8TÐ7UÐUVÐWÔXØ€Løô ò Ü�‰ðQô	
ð 	ðûôR &ò Ü—K‘K )¨C¯H©H°T«NÐ+;Ð <Ô=Úðûô ò 	Ø�FŠF�w—}‘} e§k¡kÐ2Ñ2�FØûð	ús5   ‚P> ËQ!Í&?RÐ> QÑ!0RÒRÒ	SÒ!,SÓSaR  
    This is an experimental feature and is a subject to change at a moment's notice.

    Uses a device map to distribute attention modules of the model across several devices. If no device map is given,
    it will evenly distribute blocks across all devices.

    Args:
        device_map (`Dict[int, list]`, *optional*):
            A dictionary that maps attention modules to devices. Note that the embedding module and LMHead are always
            automatically mapped to the first device (for esoteric reasons). That means that the first device should
            have fewer attention modules mapped to it than other devices. For reference, the t5 models have the
            following number of attention modules:

                - google-t5/t5-small: 6
                - google-t5/t5-base: 12
                - google-t5/t5-large: 24
                - google-t5/t5-3b: 24
                - google-t5/t5-11b: 24

    Example:

    ```python
    # Here is an example of a device map on a machine with 4 GPUs using google-t5/t5-3b, which has a total of 24 attention modules:
    model = T5ForConditionalGeneration.from_pretrained("google-t5/t5-3b")
    device_map = {
        0: [0, 1, 2],
        1: [3, 4, 5, 6, 7, 8, 9],
        2: [10, 11, 12, 13, 14, 15, 16],
        3: [17, 18, 19, 20, 21, 22, 23],
    }
    model.parallelize(device_map)
    ```
a4  
    Moves the model to cpu from a model parallel state.

    Example:

    ```python
    # On a 4 GPU machine with google-t5/t5-3b:
    model = T5ForConditionalGeneration.from_pretrained("google-t5/t5-3b")
    device_map = {
        0: [0, 1, 2],
        1: [3, 4, 5, 6, 7, 8, 9],
        2: [10, 11, 12, 13, 14, 15, 16],
        3: [17, 18, 19, 20, 21, 22, 23],
    }
    model.parallelize(device_map)  # Splits the model across several devices
    model.deparallelize()  # Put the model back on cpu and cleans memory by calling torch.cuda.empty_cache()
    ```
c                   ó&   ‡ — e Zd Zdˆ fd„	Zd„ Zˆ xZS )ÚT5LayerNormc                 óŠ   •— t         ‰| �  «        t        j                  t	        j
                  |«      «      | _        || _        y)zc
        Construct a layernorm module in the T5 style. No bias and no subtraction of mean.
        N)ÚsuperÚ__init__r   Ú	Parameterrs   Úonesr@   Úvariance_epsilon)ÚselfÚhidden_sizeÚepsÚ	__class__s      €r8   r�   zT5LayerNorm.__init__ò   s1   ø€ ô 	‰ÑÔÜ—l‘l¤5§:¡:¨kÓ#:Ó;ˆŒØ #ˆÕó    c                 óž  — |j                  t        j                  «      j                  d«      j	                  dd¬«      }|t        j
                  || j                  z   «      z  }| j                  j                  t        j                  t        j                  fv r%|j                  | j                  j                  «      }| j                  |z  S )NrE   r<   T)Úkeepdim)Útors   rv   ÚpowÚmeanÚrsqrtr’   r@   ÚdtypeÚfloat16Úbfloat16)r“   Úhidden_statesÚvariances      r8   ÚforwardzT5LayerNorm.forwardú   s›   € ð !×#Ñ#¤E§M¡MÓ2×6Ñ6°qÓ9×>Ñ>¸rÈ4Ð>ÓPˆØ%¬¯©°H¸t×?TÑ?TÑ4TÓ(UÑUˆð �;‰;×Ñ¤§¡´·±Ð ?Ñ?Ø)×,Ñ,¨T¯[©[×->Ñ->Ó?ˆMà�{‰{˜]Ñ*Ð*r—   )g�íµ ÷Æ°>)Ú__name__Ú
__module__Ú__qualname__r�   r£   Ú__classcell__©r–   s   @r8   rŒ   rŒ   ñ   s   ø„ õ$ö+r—   rŒ   )ÚFusedRMSNormzODiscovered apex.normalization.FusedRMSNorm - will use it instead of T5LayerNormzBdiscovered apex but it failed to load, falling back to T5LayerNormc                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )ÚT5DenseActDenserz   c                 ó^  •— t         ‰| �  «        t        j                  |j                  |j
                  d¬«      | _        t        j                  |j
                  |j                  d¬«      | _        t        j                  |j                  «      | _
        t        |j                     | _        y ©NF©rK   )rŽ   r�   r   ÚLinearÚd_modelÚd_ffrQ   ÚwoÚDropoutÚdropout_rateÚdropoutr   Údense_act_fnÚact©r“   rz   r–   s     €r8   r�   zT5DenseActDense.__init__  sn   ø€ Ü‰ÑÔÜ—)‘)˜FŸN™N¨F¯K©K¸eÔDˆŒÜ—)‘)˜FŸK™K¨¯©¸eÔDˆŒÜ—z‘z &×"5Ñ"5Ó6ˆŒÜ˜&×-Ñ-Ñ.ˆ�r—   c                 ó  — | j                  |«      }| j                  |«      }| j                  |«      }t        | j                  j
                  t        j                  «      r�|j                  | j                  j
                  j                  k7  r`| j                  j
                  j                  t        j                  k7  r/|j                  | j                  j
                  j                  «      }| j	                  |«      }|S ©N)rQ   r·   rµ   Ú
isinstancer²   r@   rs   ÚTensorrž   Úint8rš   ©r“   r¡   s     r8   r£   zT5DenseActDense.forward"  sª   € ØŸ™ Ó.ˆØŸ™ Ó/ˆØŸ™ ]Ó3ˆä�t—w‘w—~‘~¤u§|¡|Ô4Ø×#Ñ# t§w¡w§~¡~×';Ñ';Ò;Ø—‘—‘×$Ñ$¬¯
©
Ò2à)×,Ñ,¨T¯W©W¯^©^×-AÑ-AÓBˆMØŸ™ Ó.ˆØÐr—   ©r¤   r¥   r¦   r*   r�   r£   r§   r¨   s   @r8   r«   r«     s   ø„ ð/˜xõ /ör—   r«   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )ÚT5DenseGatedActDenserz   c                 óÀ  •— t         ‰| �  «        t        j                  |j                  |j
                  d¬«      | _        t        j                  |j                  |j
                  d¬«      | _        t        j                  |j
                  |j                  d¬«      | _        t        j                  |j                  «      | _        t        |j                     | _        y r­   )rŽ   r�   r   r¯   r°   r±   Úwi_0Úwi_1r²   r³   r´   rµ   r   r¶   r·   r¸   s     €r8   r�   zT5DenseGatedActDense.__init__1  sŠ   ø€ Ü‰ÑÔÜ—I‘I˜fŸn™n¨f¯k©kÀÔFˆŒ	Ü—I‘I˜fŸn™n¨f¯k©kÀÔFˆŒ	Ü—)‘)˜FŸK™K¨¯©¸eÔDˆŒÜ—z‘z &×"5Ñ"5Ó6ˆŒÜ˜&×-Ñ-Ñ.ˆ�r—   c                 ó,  — | j                  | j                  |«      «      }| j                  |«      }||z  }| j                  |«      }t	        | j
                  j                  t        j                  «      r�|j                  | j
                  j                  j                  k7  r`| j
                  j                  j                  t        j                  k7  r/|j                  | j
                  j                  j                  «      }| j                  |«      }|S rº   )r·   rÃ   rÄ   rµ   r»   r²   r@   rs   r¼   rž   r½   rš   )r“   r¡   Úhidden_geluÚhidden_linears       r8   r£   zT5DenseGatedActDense.forward9  s¿   € Ø—h‘h˜tŸy™y¨Ó7Ó8ˆØŸ	™	 -Ó0ˆØ# mÑ3ˆØŸ™ ]Ó3ˆô �t—w‘w—~‘~¤u§|¡|Ô4Ø×#Ñ# t§w¡w§~¡~×';Ñ';Ò;Ø—‘—‘×$Ñ$¬¯
©
Ò2à)×,Ñ,¨T¯W©W¯^©^×-AÑ-AÓBˆMàŸ™ Ó.ˆØÐr—   r¿   r¨   s   @r8   rÁ   rÁ   0  s   ø„ ð/˜xõ /ör—   rÁ   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )Ú	T5LayerFFrz   c                 ó  •— t         ‰| �  «        |j                  rt        |«      | _        nt        |«      | _        t        |j                  |j                  ¬«      | _	        t        j                  |j                  «      | _        y )N©r•   )rŽ   r�   Úis_gated_actrÁ   ÚDenseReluDenser«   rŒ   r°   Úlayer_norm_epsilonrG   r   r³   r´   rµ   r¸   s     €r8   r�   zT5LayerFF.__init__N  s_   ø€ Ü‰ÑÔØ×ÒÜ"6°vÓ">ˆDÕä"1°&Ó"9ˆDÔä% f§n¡n¸&×:SÑ:SÔTˆŒÜ—z‘z &×"5Ñ"5Ó6ˆ�r—   c                 ór   — | j                  |«      }| j                  |«      }|| j                  |«      z   }|S rº   )rG   rÍ   rµ   )r“   r¡   Úforwarded_statess      r8   r£   zT5LayerFF.forwardX  s=   € ØŸ?™?¨=Ó9ÐØ×.Ñ.Ð/?Ó@ÐØ%¨¯©Ð5EÓ(FÑFˆØÐr—   r¿   r¨   s   @r8   rÉ   rÉ   M  s   ø„ ð7˜xõ 7ör—   rÉ   c                   ón   ‡ — e Zd Z	 	 ddedee   fˆ fd„Zd„ Zed	d„«       Z	d
d„Z
	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )ÚT5Attentionrz   Ú	layer_idxc                 ó  •— t         ‰| �  «        |j                  | _        || _        |j                  | _        |j
                  | _        |j                  | _        |j                  | _        |j                  | _
        |j                  | _        | j                  | j                  z  | _        || _        |€9| j                  r-t        j!                  d| j"                  j$                  › d�«       t'        j(                  | j                  | j                  d¬«      | _        t'        j(                  | j                  | j                  d¬«      | _        t'        j(                  | j                  | j                  d¬«      | _        t'        j(                  | j                  | j                  d¬«      | _        | j                  r/t'        j2                  | j                  | j                  «      | _        t7        «       | _        d| _        y )NzInstantiating a decoder z³ without passing `layer_idx` is not recommended and will to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` when creating this class.Fr®   )rŽ   r�   Ú
is_decoderÚhas_relative_attention_biasÚrelative_attention_num_bucketsÚrelative_attention_max_distancer°   Úd_kvÚkey_value_proj_dimÚ	num_headsÚn_headsr´   rµ   Ú	inner_dimrÓ   rY   Úwarning_oncer–   r¤   r   r¯   ÚqÚkÚvÚoÚ	EmbeddingÚrelative_attention_biasÚsetÚpruned_headsÚgradient_checkpointing©r“   rz   rÖ   rÓ   r–   s       €r8   r�   zT5Attention.__init__`  ss  ø€ ô 	‰ÑÔØ ×+Ñ+ˆŒØ+FˆÔ(Ø.4×.SÑ.SˆÔ+Ø/5×/UÑ/UˆÔ,Ø—~‘~ˆŒØ"(§+¡+ˆÔØ×'Ñ'ˆŒØ×*Ñ*ˆŒØŸ™¨×(?Ñ(?Ñ?ˆŒØ"ˆŒØÐ §¢Ü×ÑØ*¨4¯>©>×+BÑ+BÐ*Cð D,ð ,ôô —‘˜4Ÿ<™<¨¯©¸eÔDˆŒÜ—‘˜4Ÿ<™<¨¯©¸eÔDˆŒÜ—‘˜4Ÿ<™<¨¯©¸eÔDˆŒÜ—‘˜4Ÿ>™>¨4¯<©<¸eÔDˆŒà×+Ò+Ü+-¯<©<¸×8[Ñ8[Ð]a×]iÑ]iÓ+jˆDÔ(Ü›EˆÔØ&+ˆÕ#r—   c                 ó  — t        |«      dk(  ry t        || j                  | j                  | j                  «      \  }}t        | j                  |«      | _        t        | j                  |«      | _        t        | j                  |«      | _        t        | j                  |d¬«      | _	        | j                  t        |«      z
  | _        | j                  | j                  z  | _
        | j                  j                  |«      | _        y )Nr   r)   ©Údim)rj   r   rÜ   rÚ   ræ   r   rß   rà   rá   râ   rÝ   Úunion)r“   ÚheadsÚindexs      r8   Úprune_headszT5Attention.prune_headsƒ  sÆ   € Üˆu‹:˜Š?ØÜ7Ø�4—<‘< ×!8Ñ!8¸$×:KÑ:Kó
‰ˆˆuô $ D§F¡F¨EÓ2ˆŒÜ# D§F¡F¨EÓ2ˆŒÜ# D§F¡F¨EÓ2ˆŒÜ# D§F¡F¨E°qÔ9ˆŒà—|‘|¤c¨%£jÑ0ˆŒØ×0Ñ0°4·<±<Ñ?ˆŒØ ×-Ñ-×3Ñ3°EÓ:ˆÕr—   c                 óT  — d}|rC|dz  }|| dkD  j                  t        j                  «      |z  z  }t        j                  | «      } n*t        j                  | t        j
                  | «      «       } |dz  }| |k  }|t        j                  | j                  «       |z  «      t        j                  ||z  «      z  ||z
  z  j                  t        j                  «      z   }t        j                  |t        j                  ||dz
  «      «      }|t        j                  || |«      z  }|S )aÒ  
        Adapted from Mesh Tensorflow:
        https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593

        Translate relative position to a bucket number for relative attention. The relative position is defined as
        memory_position - query_position, i.e. the distance in tokens from the attending position to the attended-to
        position. If bidirectional=False, then positive relative positions are invalid. We use smaller buckets for
        small absolute relative_position and larger buckets for larger absolute relative_positions. All relative
        positions >=max_distance map to the same bucket. All relative positions <=-max_distance map to the same bucket.
        This should allow for more graceful generalization to longer sequences than the model has been trained on

        Args:
            relative_position: an int32 Tensor
            bidirectional: a boolean - whether the attention is bidirectional
            num_buckets: an integer
            max_distance: an integer

        Returns:
            a Tensor with the same shape as relative_position, containing int32 values in the range [0, num_buckets)
        r   rE   r)   )rš   rs   ÚlongÚabsÚminÚ
zeros_likeÚlogÚfloatÚmathÚ	full_likeÚwhere)Úrelative_positionÚbidirectionalÚnum_bucketsÚmax_distanceÚrelative_bucketsÚ	max_exactÚis_smallÚrelative_position_if_larges           r8   Ú_relative_position_bucketz%T5Attention._relative_position_bucket“  s(  € ð, ÐÙØ˜AÑˆKØÐ!2°QÑ!6× :Ñ :¼5¿:¹:Ó FÈÑ TÑTÐÜ %§	¡	Ð*;Ó <Ñä!&§¡Ð+<¼e×>NÑ>NÐO`Ó>aÓ!bÐ bÐð   1Ñ$ˆ	Ø$ yÑ0ˆð &/Ü�I‰IÐ'×-Ñ-Ó/°)Ñ;Ó<Ü�h‰h�| iÑ/Ó0ñ1à˜YÑ&ñ(÷ ‰"ŒU�Z‰Z‹.ñ	&Ð"ô
 &+§Y¡YØ&¬¯©Ð8RÐT_ÐbcÑTcÓ(dó&
Ð"ð 	œEŸK™K¨Ð2CÐE_Ó`Ñ`ÐØÐr—   c                 ó  — |€ | j                   j                  j                  }|€.t        j                  |t        j
                  |¬«      dd…df   }n|dd…df   j                  |«      }t        j                  |t        j
                  |¬«      ddd…f   }||z
  }| j                  || j                   | j                  | j                  ¬«      }| j                  |«      }	|	j                  g d¢«      j                  d«      }	|	S )z%Compute binned relative position biasN)rž   Údevice)rû   rü   rý   )rE   r   r)   r   )rä   r@   r  rs   Úarangerñ   rš   r  rÕ   r×   rØ   ÚpermuteÚ	unsqueeze)
r“   Úquery_lengthÚ
key_lengthr  Úcache_positionÚcontext_positionÚmemory_positionrú   Úrelative_position_bucketÚvaluess
             r8   Úcompute_biaszT5Attention.compute_biasÃ  s÷   € àˆ>Ø×1Ñ1×8Ñ8×?Ñ?ˆFØÐ!Ü$Ÿ|™|¨LÄÇ
Á
ÐSYÔZÒ[\Ð^bÐ[bÑcÑà-ªa°¨gÑ6×9Ñ9¸&ÓAÐÜŸ,™, z¼¿¹ÈFÔSÐTXÒZ[ÐT[Ñ\ˆØ+Ð.>Ñ>ÐØ#'×#AÑ#AØØ#Ÿ™Ð.Ø×;Ñ;Ø×=Ñ=ð	 $Bó $
Ð ð ×-Ñ-Ð.FÓGˆØ—‘¢	Ó*×4Ñ4°QÓ7ˆØˆr—   c                 ó  — |j                   dd \  }}|du}| j                  |«      }|j                  |d| j                  | j                  «      j                  dd«      }|�@|j                  j                  | j                  «      }|r|j                  }n|j                  }|r|n|}|r7|�5r3j                  | j                     }|j                  | j                     }nØ| j                  |«      }| j                  |«      }|j                  |d| j                  | j                  «      j                  dd«      }|j                  |d| j                  | j                  «      j                  dd«      }|�D|s|
nd}
j                  ||| j                  d|
i«      \  }}|rd|j                  | j                  <   t!        j"                  ||j                  dd«      «      }|€×|j                   d   }|�|n|
d   dz   }| j$                  sZt!        j&                  d| j                  ||f|j(                  |j*                  ¬	«      }| j,                  rE| j.                  r9d|_        n1| j3                  |||j(                  |
¬
«      }|dd…dd…| d…dd…f   }|�#|dd…dd…dd…d|j                   d   …f   }||z   }| j4                  rRt!        j6                  |j                   d   «      }d|t9        | j4                  «      <   |dd…|j;                  «       f   }n|}||z  }t<        j>                  jA                  |jC                  «       d¬«      jE                  |«      }t<        j>                  jG                  || jF                  | j.                  ¬«      }|�||z  }t!        j"                  ||«      }|j                  dd«      jI                  «       }|j                  |d| jJ                  «      }| jM                  |«      }|||f}|	r||fz   }|S )z€
        Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
        NrE   r<   r)   r
  Tr   éþÿÿÿ©r  rž   )r  r
  r   rê   )ÚpÚtraining)'rn   rß   ÚviewrÜ   rÚ   ro   Ú
is_updatedÚgetrÓ   Úcross_attention_cacheÚself_attention_cacheÚ	key_cacheÚvalue_cacherà   rá   Úupdaters   ÚmatmulrÖ   Úzerosr  rž   rç   r  Úrequires_gradr  ræ   r‘   ÚlistÚboolr   Ú
functionalÚsoftmaxrö   Útype_asrµ   Ú
contiguousrÝ   râ   )r“   r¡   ÚmaskÚkey_value_statesÚposition_biasÚpast_key_valueÚlayer_head_maskr  Ú	use_cacheÚoutput_attentionsr
  Ú
batch_sizeÚ
seq_lengthÚis_cross_attentionÚquery_statesr  Úcurr_past_key_valueÚcurrent_statesÚ
key_statesÚvalue_statesÚscoresr	  Úreal_seq_lengthÚcausal_maskÚposition_bias_maskedÚattn_weightsÚattn_outputÚoutputss                               r8   r£   zT5Attention.forward×  sã  € ð$ "/×!4Ñ!4°R°aÐ!8Ñˆ
�Jð .°TÐ9Ðà—v‘v˜mÓ,ˆØ#×(Ñ(¨°R¸¿¹Àt×G^ÑG^Ó_×iÑiÐjkÐmnÓoˆàÐ%Ø'×2Ñ2×6Ñ6°t·~±~ÓFˆJÙ!à&4×&JÑ&JÑ#à&4×&IÑ&IÐ#á-?Ñ)À]ˆÙ .Ð"<Áà,×6Ñ6°t·~±~ÑFˆJØ.×:Ñ:¸4¿>¹>ÑJ‰LàŸ™ Ó/ˆJØŸ6™6 .Ó1ˆLØ#Ÿ™¨°R¸¿¹Àt×G^ÑG^Ó_×iÑiÐjkÐmnÓoˆJØ'×,Ñ,¨Z¸¸T¿\¹\È4×KbÑKbÓc×mÑmÐnoÐqrÓsˆLàÐ)á7I¡Èt�Ø+>×+EÑ+EØ ¨d¯n©nÐ?OÐQ_Ð>`ó,Ñ(�
˜Lñ &Ø@D�N×-Ñ-¨d¯n©nÑ=ô —‘˜l¨J×,@Ñ,@ÀÀAÓ,FÓGˆàÐ Ø#×)Ñ)¨"Ñ-ˆJà.:Ð.F™lÈNÐ[]ÑL^ÐabÑLbˆOØ×3Ò3Ü %§¡Ø˜Ÿ™ j°*Ð=ÀfÇmÁmÐ[a×[gÑ[gô!�ð ×.Ò.°4·=²=Ø26�MÕ/à $× 1Ñ 1Ø# Z¸¿¹ÐVdð !2ó !�ð !.ªa²°Z°K±LÂ!Ð.CÑ D�àÐØ"¢1¢aªÐ,B¨j×.>Ñ.>¸rÑ.BÐ,BÐ#BÑC�Ø -°Ñ ;�à×ÒÜ—:‘:˜m×1Ñ1°!Ñ4Ó5ˆDØ,-ˆD”�d×'Ñ'Ó(Ñ)Ø#0²°D·I±I³K°Ñ#@Ñ à#0Ð àÐ&Ñ&ˆô —}‘}×,Ñ,¨V¯\©\«^ÀÐ,ÓD×LÑLÈVÓTˆÜ—}‘}×,Ñ,¨\¸T¿\¹\ÐTX×TaÑTaÐ,Óbˆð Ð&Ø'¨/Ñ9ˆLä—l‘l <°Ó>ˆà!×+Ñ+¨A¨qÓ1×<Ñ<Ó>ˆØ!×&Ñ& z°2°t·~±~ÓFˆØ—f‘f˜[Ó)ˆà °Ð>ˆáØ  Ñ/ˆGØˆr—   ©FN)Té    é€   )NN)	NNNNNNFFN)r¤   r¥   r¦   r*   r   rm   r�   rï   Ústaticmethodr  r  r£   r§   r¨   s   @r8   rÒ   rÒ   _  si   ø„ ð %*Ø#'ñ	!,àð!,ð ˜C‘=õ	!,òF;ð  ò- ó ð- ó^ð. ØØØØØØØØ÷ir—   rÒ   c                   óB   ‡ — e Zd Zddee   fˆ fd„Z	 	 	 	 	 	 	 dd„Zˆ xZS )ÚT5LayerSelfAttentionrÓ   c                 óÜ   •— t         ‰| �  «        t        |||¬«      | _        t	        |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        y )N©rÖ   rÓ   rË   )rŽ   r�   rÒ   ÚSelfAttentionrŒ   r°   rÎ   rG   r   r³   r´   rµ   rè   s       €r8   r�   zT5LayerSelfAttention.__init__D  sT   ø€ Ü‰ÑÔÜ(ØÐ0KÐW`ô
ˆÔô & f§n¡n¸&×:SÑ:SÔTˆŒÜ—z‘z &×"5Ñ"5Ó6ˆ�r—   c	           
      óš   — | j                  |«      }	| j                  |	|||||||¬«      }
|| j                  |
d   «      z   }|f|
dd  z   }|S )N)r&  r(  r*  r)  r+  r,  r
  r   r)   )rG   rD  rµ   )r“   r¡   Úattention_maskr(  r*  r)  r+  r,  r
  Únormed_hidden_statesÚattention_outputr;  s               r8   r£   zT5LayerSelfAttention.forwardL  sv   € ð  $Ÿ™¨}Ó=ÐØ×-Ñ-Ø ØØ'Ø+Ø)ØØ/Ø)ð .ó 	
Ðð &¨¯©Ð5EÀaÑ5HÓ(IÑIˆØ Ð"Ð%5°a°bÐ%9Ñ9ˆØˆr—   r<  )NNNNFFN©r¤   r¥   r¦   r   rm   r�   r£   r§   r¨   s   @r8   rA  rA  C  s0   ø„ ñ7ÈXÐVYÉ]õ 7ð ØØØØØØ÷r—   rA  c                   óD   ‡ — e Zd Zddee   fˆ fd„Z	 	 	 	 	 	 	 	 dd„Zˆ xZS )ÚT5LayerCrossAttentionrÓ   c                 óÜ   •— t         ‰| �  «        t        |d|¬«      | _        t	        |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        y )NFrC  rË   )rŽ   r�   rÒ   ÚEncDecAttentionrŒ   r°   rÎ   rG   r   r³   r´   rµ   )r“   rz   rÓ   r–   s      €r8   r�   zT5LayerCrossAttention.__init__h  sN   ø€ Ü‰ÑÔÜ*¨6ÈuÐ`iÔjˆÔÜ% f§n¡n¸&×:SÑ:SÔTˆŒÜ—z‘z &×"5Ñ"5Ó6ˆ�r—   c                 óž   — | j                  |«      }| j                  |||||||||	|
¬«
      }|| j                  |d   «      z   }|f|dd  z   }|S )N)	r&  r'  r(  r*  r)  r+  r  r,  r
  r   r)   )rG   rM  rµ   )r“   r¡   r'  rF  r(  r*  r)  r+  r  r,  r
  rG  rH  Úlayer_outputr;  s                  r8   r£   zT5LayerCrossAttention.forwardn  s{   € ð  $Ÿ™¨}Ó=ÐØ×/Ñ/Ø ØØ-Ø'Ø+Ø)ØØ%Ø/Ø)ð 0ó 
Ðð % t§|¡|Ð4DÀQÑ4GÓ'HÑHˆØ�/Ð$4°Q°RÐ$8Ñ8ˆØˆr—   rº   )NNNNFNFNrI  r¨   s   @r8   rK  rK  g  s2   ø„ ñ7¨(°3©-õ 7ð ØØØØØØØ÷r—   rK  c                   óL   ‡ — e Zd Zddee   fˆ fd„Z	 	 	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )ÚT5BlockrÓ   c                 óp  •— t         ‰| �  «        |j                  | _        t        j                  «       | _        | j
                  j                  t        |||¬«      «       | j                  r&| j
                  j                  t        ||¬«      «       | j
                  j                  t        |«      «       y )NrC  )rÓ   )
rŽ   r�   rÕ   r   Ú
ModuleListrB   rb   rA  rK  rÉ   rè   s       €r8   r�   zT5Block.__init__Ž  s‚   ø€ Ü‰ÑÔØ ×+Ñ+ˆŒÜ—]‘]“_ˆŒ
Ø�
‰
×ÑÜ  ÐE`ÐluÔvô	
ð �?Š?Ø�J‰J×ÑÔ3°FÀiÔPÔQà�
‰
×Ñœ) FÓ+Õ,r—   c                 ó¸  —  | j                   d   |||||	|
||¬«      }|d d \  }}	|dd  }|j                  t        j                  k(  r¢t        j                  t        j
                  |«      j                  «       t        j                  |j                  «      j                  dz
  t        j                  |j                  «      j                  «      }t        j                  || |¬«      }| j                  xr |d u}|ró | j                   d   ||||||	|d   dz   |
|¬«	      }|d d \  }}	|j                  t        j                  k(  r¢t        j                  t        j
                  |«      j                  «       t        j                  |j                  «      j                  dz
  t        j                  |j                  «      j                  «      }t        j                  || |¬«      }||dd  z   } | j                   d   |«      }|j                  t        j                  k(  r¢t        j                  t        j
                  |«      j                  «       t        j                  |j                  «      j                  dz
  t        j                  |j                  «      j                  «      }t        j                  || |¬«      }|f}|
r||	fz   |z   }|S ||z   }|S )	Nr   )rF  r(  r*  r)  r+  r,  r
  rE   iè  )ró   Úmaxr)   r<   )r'  rF  r(  r*  r)  r  r+  r,  )rB   rž   rs   rŸ   rù   Úisinfrd   ÚfinforU  ÚclamprÕ   )r“   r¡   rF  r(  Úencoder_hidden_statesÚencoder_attention_maskÚencoder_decoder_position_biasr*  Úcross_attn_layer_head_maskr)  r+  r,  Úreturn_dictr
  Úself_attention_outputsÚattention_outputsÚclamp_valueÚdo_cross_attentionÚcross_attention_outputsr;  s                       r8   r£   zT5Block.forwardš  s   € ð  "/ §¡¨A¡ØØ)Ø'Ø+Ø)ØØ/Ø)ô	"
Ðð )?¸rÀÐ(BÑ%ˆ�~Ø2°1°2Ð6Ðð ×Ñ¤%§-¡-Ò/ÜŸ+™+Ü—‘˜MÓ*×.Ñ.Ó0Ü—‘˜M×/Ñ/Ó0×4Ñ4°tÑ;Ü—‘˜M×/Ñ/Ó0×4Ñ4óˆKô
 "ŸK™K¨¸K¸<È[ÔYˆMà!Ÿ_™_ÒRÐ1FÈdÐ1RÐÙØ&3 d§j¡j°¡mØØ!6Ø5Ø;Ø :Ø-Ø+¨BÑ/°!Ñ3Ø#Ø"3ô
'Ð#ð -DÀBÀQÐ,GÑ)ˆM˜>ð ×"Ñ"¤e§m¡mÒ3Ü#Ÿk™kÜ—K‘K Ó.×2Ñ2Ó4Ü—K‘K × 3Ñ 3Ó4×8Ñ8¸4Ñ?Ü—K‘K × 3Ñ 3Ó4×8Ñ8ó�ô
 !&§¡¨MÀ¸|ÐQ\Ô ]�ð !2Ð4KÈAÈBÐ4OÑ OÐð '˜Ÿ
™
 2™ }Ó5ˆð ×Ñ¤%§-¡-Ò/ÜŸ+™+Ü—‘˜MÓ*×.Ñ.Ó0Ü—‘˜M×/Ñ/Ó0×4Ñ4°tÑ;Ü—‘˜M×/Ñ/Ó0×4Ñ4óˆKô
 "ŸK™K¨¸K¸<È[ÔYˆMà Ð"ˆáØ Ð 1Ñ1Ð4EÑEˆGð ˆð Ð 1Ñ1ˆGàˆr—   r<  )NNNNNNNNFFTNrI  r¨   s   @r8   rQ  rQ  �  s@   ø„ ñ
-ÈXÐVYÉ]õ 
-ð ØØ"Ø#Ø&*ØØ#'ØØØØØ÷Tr—   rQ  c                   ó`   ‡ — e Zd ZdZdefˆ fd„Zdej                  dej                  fd„Zˆ xZ	S )ÚT5ClassificationHeadz-Head for sentence-level classification tasks.rz   c                 ó(  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  |j                  ¬«      | _        t        j                  |j                  |j                  «      | _
        y )N)r  )rŽ   r�   r   r¯   r°   Údenser³   Úclassifier_dropoutrµ   Ú
num_labelsÚout_projr¸   s     €r8   r�   zT5ClassificationHead.__init__ô  sZ   ø€ Ü‰ÑÔÜ—Y‘Y˜vŸ~™~¨v¯~©~Ó>ˆŒ
Ü—z‘z F×$=Ñ$=Ô>ˆŒÜŸ	™	 &§.¡.°&×2CÑ2CÓDˆ�r—   r¡   Úreturnc                 ó¸   — | j                  |«      }| j                  |«      }t        j                  |«      }| j                  |«      }| j	                  |«      }|S rº   )rµ   rf  rs   Útanhri  r¾   s     r8   r£   zT5ClassificationHead.forwardú  sN   € ØŸ™ ]Ó3ˆØŸ
™
 =Ó1ˆÜŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ mÓ4ˆØÐr—   )
r¤   r¥   r¦   Ú__doc__r*   r�   rs   r¼   r£   r§   r¨   s   @r8   rd  rd  ñ  s/   ø„ Ù7ðE˜xõ Eð U§\¡\ð °e·l±l÷ r—   rd  c                   óX   — e Zd ZdZeZeZdZdZ	dZ
dZdZdZdgZdgZed„ «       Zd„ Zd	„ Zy
)ÚT5PreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚtransformerTFrQ  r²   c                 óv   — t        j                  t        «      }t        j                  t        «      }|||dœ}|S )N)Údecoder_input_idsÚ	input_idsÚdecoder_attention_mask)rs   Útensorr   r   )r“   rs  Ú
input_maskÚdummy_inputss       r8   rw  zT5PreTrainedModel.dummy_inputs  s6   € ä—L‘L¤Ó.ˆ	Ü—\‘\¤*Ó-ˆ
à!*Ø"Ø&0ñ
ˆð
 Ðr—   c                 óx  — | j                   j                  }t        |t        «      r)|j                  j
                  j                  |dz  «       y	t        |t        t        t        t        f«      �r|j                  j                  j
                  j                  d|dz  ¬«       t        |d«      rJ| j                   j                  s4|j                  j                  j
                  j                  d|dz  ¬«       t        |d«      rz|j                   j                  j
                  j                  d|| j                   j"                  dz  z  ¬«       |j                   j$                  j
                  j'                  «        y	y	t        |t(        «      rpt        |d«      rc|j*                  j                  j
                  j                  d|dz  ¬«       |j*                  j$                  j
                  j'                  «        y	y	t        |t,        «      �rM|j.                  j                  j
                  j                  d|| j                   j"                  dz  z  ¬«       t        |j.                  d«      rD|j.                  j$                  �.|j.                  j$                  j
                  j'                  «        |j0                  j                  j
                  j                  d|| j                   j"                  dz  z  ¬«       t        |j0                  d«      rF|j0                  j$                  �/|j0                  j$                  j
                  j'                  «        y	y	y	t        |t2        «      �rM|j4                  j                  j
                  j                  d|| j                   j"                  dz  z  ¬«       t        |j4                  d«      rD|j4                  j$                  �.|j4                  j$                  j
                  j'                  «        |j6                  j                  j
                  j                  d|| j                   j8                  dz  z  ¬«       t        |j6                  d«      rF|j6                  j$                  �/|j6                  j$                  j
                  j'                  «        y	y	y	t        |t:        «      �rò|j<                  j                  j
                  j                  d|| j                   j"                  dz  z  ¬«       t        |j<                  d«      rD|j<                  j$                  �.|j<                  j$                  j
                  j'                  «        |j>                  j                  j
                  j                  d|| j                   j"                  dz  z  ¬«       t        |j>                  d«      rD|j>                  j$                  �.|j>                  j$                  j
                  j'                  «        |j6                  j                  j
                  j                  d|| j                   j8                  dz  z  ¬«       t        |j6                  d«      rF|j6                  j$                  �/|j6                  j$                  j
                  j'                  «        y	y	y	t        |t@        «      �ri| j                   j"                  }| j                   jB                  }| j                   jD                  }|jF                  j                  j
                  j                  d|||z  dz  z  ¬«       |jH                  j                  j
                  j                  d||dz  z  ¬«       |jJ                  j                  j
                  j                  d||dz  z  ¬«       |jL                  j                  j
                  j                  d|||z  dz  z  ¬«       |jN                  r8|jP                  j                  j
                  j                  d||dz  z  ¬«       y	y	y	)
zInitialize the weightsç      ð?ç        )rœ   ÚstdrP   Ú
qa_outputsç      à¿rM   rK   N))rz   Úinitializer_factorr»   rŒ   r@   rw   Úfill_ÚT5ModelÚT5ForConditionalGenerationÚT5EncoderModelÚT5ForQuestionAnsweringÚsharedÚnormal_ri   Útie_word_embeddingsrP   r|  r°   rK   Úzero_ÚT5ForTokenClassificationrM   rd  rf  ri  r«   rQ   r²   r±   rÁ   rÃ   rÄ   rÒ   rÙ   rÛ   rß   rà   rá   râ   rÖ   rä   )r“   ÚmoduleÚfactorr°   rÚ   rÜ   s         r8   Ú_init_weightszT5PreTrainedModel._init_weights  s  € à—‘×/Ñ/ˆÜ�fœkÔ*Ø�M‰M×Ñ×$Ñ$ V¨c¡\Õ2ÜØÜÔ0´.ÔBXÐYõ
ð �M‰M× Ñ ×%Ñ%×-Ñ-°3¸FÀS¹LÐ-ÔIÜ�v˜yÔ)°$·+±+×2QÒ2QØ—‘×%Ñ%×*Ñ*×2Ñ2¸ÀÈ#ÁÐ2ÔNÜ�v˜|Ô,Ø×!Ñ!×(Ñ(×-Ñ-×5Ñ5¸3ÀFÈtÏ{É{×ObÑObÐgkÑNkÑDlÐ5ÔmØ×!Ñ!×&Ñ&×+Ñ+×1Ñ1Õ3ð -ô ˜Ô 8Ô9Ü�v˜|Ô,Ø×!Ñ!×(Ñ(×-Ñ-×5Ñ5¸3ÀFÈSÁLÐ5ÔQØ×!Ñ!×&Ñ&×+Ñ+×1Ñ1Õ3ð -ô ˜Ô 4Õ5Ø�L‰L×Ñ×$Ñ$×,Ñ,°#¸6ÀdÇkÁk×FYÑFYÐ^bÑEbÑ;cÐ,ÔdÜ�v—|‘| VÔ,°·±×1BÑ1BÐ1NØ—‘×!Ñ!×&Ñ&×,Ñ,Ô.Ø�O‰O×"Ñ"×'Ñ'×/Ñ/°S¸fÈÏÉ×I\ÑI\ÐaeÑHeÑ>fÐ/ÔgÜ�v—‘¨Ô/°F·O±O×4HÑ4HÐ4TØ—‘×$Ñ$×)Ñ)×/Ñ/Õ1ð 5UÐ/ä˜¤Õ0ð �I‰I×Ñ×!Ñ!×)Ñ)¨s¸À4Ç;Á;×CVÑCVÐ[_ÑB_Ñ8`Ð)ÔaÜ�v—y‘y &Ô)¨f¯i©i¯n©nÐ.HØ—	‘	—‘×#Ñ#×)Ñ)Ô+Ø�I‰I×Ñ×!Ñ!×)Ñ)¨s¸À4Ç;Á;×CSÑCSÐX\ÑB\Ñ8]Ð)Ô^Ü�v—y‘y &Ô)¨f¯i©i¯n©nÐ.HØ—	‘	—‘×#Ñ#×)Ñ)Õ+ð /IÐ)ä˜Ô 4Õ5Ø�K‰K×Ñ×#Ñ#×+Ñ+°¸&ÀTÇ[Á[×EXÑEXÐ]aÑDaÑ:bÐ+ÔcÜ�v—{‘{ FÔ+°·±×0@Ñ0@Ð0LØ—‘× Ñ ×%Ñ%×+Ñ+Ô-Ø�K‰K×Ñ×#Ñ#×+Ñ+°¸&ÀTÇ[Á[×EXÑEXÐ]aÑDaÑ:bÐ+ÔcÜ�v—{‘{ FÔ+°·±×0@Ñ0@Ð0LØ—‘× Ñ ×%Ñ%×+Ñ+Ô-Ø�I‰I×Ñ×!Ñ!×)Ñ)¨s¸À4Ç;Á;×CSÑCSÐX\ÑB\Ñ8]Ð)Ô^Ü�v—y‘y &Ô)¨f¯i©i¯n©nÐ.HØ—	‘	—‘×#Ñ#×)Ñ)Õ+ð /IÐ)ä˜¤Õ,ð —k‘k×)Ñ)ˆGØ!%§¡×!1Ñ!1ÐØ—k‘k×+Ñ+ˆGØ�H‰H�O‰O× Ñ ×(Ñ(¨c°vÀ'ÐL^ÑB^ÐcgÑAgÑ7hÐ(ÔiØ�H‰H�O‰O× Ñ ×(Ñ(¨c°vÀÈ$ÁÑ7OÐ(ÔPØ�H‰H�O‰O× Ñ ×(Ñ(¨c°vÀÈ$ÁÑ7OÐ(ÔPØ�H‰H�O‰O× Ñ ×(Ñ(¨c°vÀ'ÐL^ÑB^ÐcgÑAgÑ7hÐ(ÔiØ×1Ò1Ø×.Ñ.×5Ñ5×:Ñ:×BÑBÈÐQWÐ\cÐhlÑ[lÑQmÐBÕnð 2ð -r—   c                 óÜ  — | j                   j                  }| j                   j                  }|€t        d«      ‚t	        |«      rGt        j                  |j                  d d dz   |«      }t        j                  ||dd d…f   gd¬«      }n>|j                  |j                  «      }|dd d…f   j                  «       |ddd …f<   ||d<   |€t        d«      ‚|j                  |d	k(  |«       |S )
NzŠself.model.config.decoder_start_token_id has to be defined. In T5 it is usually set to the pad_token_id. See T5 docs for more information.r<   )r)   .rê   r)   ).r   z1self.model.config.pad_token_id has to be defined.éœÿÿÿ)rz   Údecoder_start_token_idÚpad_token_idrp   r#   rs   Úfullrn   ÚcatÚ	new_zerosÚcloneÚmasked_fill_)r“   rs  rŽ  r�  Úshifted_input_idss        r8   Ú_shift_rightzT5PreTrainedModel._shift_right\  sÿ   € Ø!%§¡×!CÑ!CÐØ—{‘{×/Ñ/ˆà!Ð)Üð4óð ô ˜YÔ'ä %§
¡
¨9¯?©?¸3¸BÐ+?À$Ñ+FÐH^Ó _ÐÜ %§	¡	Ð+<¸iÈÈSÈbÈSÈÑ>QÐ*RÐXZÔ [Ñà )× 3Ñ 3°I·O±OÓ DÐØ)2°3¸¸¸°8Ñ)<×)BÑ)BÓ)DÐ˜c 1¡2˜gÑ&Ø(>Ð˜fÑ%àÐÜÐPÓQÐQà×&Ñ&Ð'8¸DÑ'@À,ÔOà Ð r—   N)r¤   r¥   r¦   rm  r*   Úconfig_classrŠ   Úload_tf_weightsÚbase_model_prefixÚis_parallelizableÚsupports_gradient_checkpointingÚ_supports_quantized_cacheÚ_supports_static_cacheÚ_supports_cache_classÚ_no_split_modulesÚ_keep_in_fp32_modulesÚpropertyrw  r‹  r–  r5   r—   r8   ro  ro    se   „ ñð
 €LØ+€OØ%ÐØÐØ&*Ð#Ø %ÐØ!ÐØ ÐØ"˜ÐØ!˜FÐàñó ðò;oóz!r—   ro  c                   ób  ‡ — e Zd Zdˆ fd„	Z ee«      dd„«       Z ee«      d„ «       Zd„ Z	d„ Z
	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 ddej                  dej                  d	ej                  d
edef
d„Zedej                  dededej&                  dej(                  d	ej                  defd„«       Zˆ xZS )ÚT5Stackc                 óâ  •— t         ‰| �  |«       || _        |j                  | _        t	        j
                  t        |j                  «      D �cg c]  }t        |t        |dk(  «      |¬«      ‘Œ c}«      | _
        t        |j                  |j                  ¬«      | _        t	        j                  |j                   «      | _        | j%                  «        d| _        d | _        d| _        y c c}w )Nr   rC  rË   F)rŽ   r�   Úembed_tokensrÕ   r   rS  ÚrangeÚ
num_layersrQ  r!  ÚblockrŒ   r°   rÎ   rH   r³   r´   rµ   Ú	post_initÚmodel_parallelÚ
device_maprç   )r“   rz   r¥  Úir–   s       €r8   r�   zT5Stack.__init__y  s¼   ø€ Ü‰Ñ˜Ô à(ˆÔØ ×+Ñ+ˆŒä—]‘]Ü]bÐci×ctÑctÓ]uÖvÐXYŒW�V¼¸aÀ1¹f»ÐQRÖSÒvó
ˆŒ
ô !,¨F¯N©NÀ×@YÑ@YÔ ZˆÔÜ—z‘z &×"5Ñ"5Ó6ˆŒð 	�‰Ôà#ˆÔØˆŒØ&+ˆÕ#ùò ws   Á!C,c                 óª  — t        j                  dt        «       |€Dt        t	        | j
                  «      t        t        j                  j                  «       «      «      n|| _
        t        | j                  t	        | j
                  «      «       d| _        d| j                  j                  «       v rdn.dt        t        | j                  j                  «       «      «      z   | _        dt        t#        | j                  j                  «       «      «      z   | _        | j                  j'                  «       D ]E  \  }}|D ];  }dt        |«      z   }| j
                  |   j)                  |«      | j
                  |<   Œ= ŒG | j*                  j)                  | j                   «      | _        | j,                  j)                  | j$                  «      | _        y )Na<  `T5Stack.parallelize` is deprecated and will be removed in v5 of Transformers, you should load your model with `device_map='balanced'` in the call to `from_pretrained`. You can also provide your own `device_map` but it needs to be a dictionary module_name to device, so for instance {'block.0': 0, 'block.1': 1, ...}TÚcpuúcuda:)ÚwarningsÚwarnÚFutureWarningr(   rj   r¨  r¦  rs   ÚcudaÚdevice_countr«  r'   rª  rx   Ústrró   Úfirst_devicerU  Úlast_deviceÚitemsrš   r¥  rH   )r“   r«  rà   rá   rB   Úcuda_devices         r8   ÚparallelizezT5Stack.parallelizeŒ  su  € ä�‰ð"ô ô	
ð R\ÐQcŒNœ3˜tŸz™z›?¬E´%·*±*×2IÑ2IÓ2KÓ,LÔMÐisð 	Œô 	˜$Ÿ/™/¬3¨t¯z©z«?Ô;Ø"ˆÔØ%*¨d¯o©o×.BÑ.BÓ.DÑ%D™EÈ'ÔTWÔX[Ð\`×\kÑ\k×\pÑ\pÓ\rÓXsÓTtÑJtˆÔØ"¤S¬¨T¯_©_×-AÑ-AÓ-CÓ)DÓ%EÑEˆÔà—O‘O×)Ñ)Ó+ò 	F‰DˆAˆqØò F�Ø%¬¨A«Ñ.�Ø$(§J¡J¨uÑ$5×$8Ñ$8¸Ó$E�—
‘
˜5Ò!ñFð	Fð !×-Ñ-×0Ñ0°×1BÑ1BÓCˆÔà $× 5Ñ 5× 8Ñ 8¸×9IÑ9IÓ JˆÕr—   c                 óÈ  — t        j                  dt        «       d| _        d | _        d| _        d| _        t        t        | j                  «      «      D ]-  }| j                  |   j                  d«      | j                  |<   Œ/ | j                  j                  d«      | _        | j                  j                  d«      | _        t        j                  j                  «        y )Nú\Like `parallelize`, `deparallelize` is deprecated and will be removed in v5 of Transformers.Fr®  )r°  r±  r²  rª  r«  r¶  r·  r¦  rj   r¨  rš   r¥  rH   rs   r³  Úempty_cache)r“   r¬  s     r8   ÚdeparallelizezT5Stack.deparallelize¨  s³   € ä�‰ØjÜô	
ð $ˆÔØˆŒØ!ˆÔØ ˆÔÜ”s˜4Ÿ:™:“Ó'ò 	4ˆAØ ŸJ™J q™M×,Ñ,¨UÓ3ˆD�J‰J�qŠMð	4à ×-Ñ-×0Ñ0°Ó7ˆÔØ $× 5Ñ 5× 8Ñ 8¸Ó ?ˆÔÜ�
‰
×ÑÕ r—   c                 ó   — | j                   S rº   ©r¥  ©r“   s    r8   Úget_input_embeddingszT5Stack.get_input_embeddings¸  s   € Ø× Ñ Ð r—   c                 ó   — || _         y rº   rÀ  ©r“   Únew_embeddingss     r8   Úset_input_embeddingszT5Stack.set_input_embeddings»  s
   € Ø*ˆÕr—   c                 óz  — | j                   rSt        j                  j                  | j                  «       | j
                  j                  | j                  «      | _        |	�|	n| j                  j                  }	|
�|
n| j                  j                  }
|�|n| j                  j                  }|�|n| j                  j                  }|�$|�"| j                  rdnd}t        d|› d|› d�«      ‚|�&|j                  «       }|j                  d|d   «      }n8|�|j                  «       d d }n"| j                  rdnd}t        d|› d|› d	�«      ‚| j                   r%| j"                  r|	rt$        j'                  d
«       d}	|€(| j
                  €t        d«      ‚| j                  |«      }|\  }}|	du r| j                  st        d| › d�«      ‚d}d}| j                  r—|	s|�“t)        |t*        «      r't)        |t,        «      sd}t-        |t/        «       «      }njt)        |t,        «      s-d}t$        j'                  d«       t-        j0                  |«      }n-|€+t-        t/        «       t/        «       «      }n| j                  sd }|�|j3                  «       nd}|€%t        j4                  |||z   |j6                  ¬«      }|€1t9        «       s'||z   }t        j:                  |||j6                  ¬«      }| j                  j                  r$| j=                  ||||�|j>                  nd |
«      }n]|�Y|d d …d d d d …f   }|j                  |j@                  ¬«      }d|z
  t        jB                  |j@                  «      jD                  z  }nd }| j                  r^|�\|j                  «       \  }}}||f}|€0t        j:                  ||j6                  t        jF                  ¬«      }| jI                  |«      }nd }| jK                  || j                  jL                  «      }| jK                  || j                  jL                  «      }|rdnd }|
rdnd }|
r| j                  rdnd }d }d } | jO                  |«      }!tQ        | jR                  «      D �]9  \  }"}#||"   }$||"   }%| j                   rôt        j                  j                  |!j6                  «       |�|j                  |!j6                  «      }|�|j                  |!j6                  «      }|�|j                  |!j6                  «      }|�|j                  |!j6                  «      }| �| j                  |!j6                  «      } |$�|$j                  |!j6                  «      }$|%�|%j                  |!j6                  «      }%|r||!fz   }| j                   r5| j"                  r)| jU                  |#jV                  |!||||| |$|%d |	|
||«      }&n |#|!||||| |$|%||	|
||¬«      }&|	du r|&d d dz   |&dd  z   }&|&d d \  }!}'|&d   }| j                  r|�	|&|
rdnd   } |
r||&d   fz   }| j                  r	||&d   fz   }| j                   s�ŒÓ| jX                  j[                  «       D ]J  \  }(})|"|)d   k(  sŒdt]        |(«      z   | j^                  k7  sŒ+|!j                  dt]        |(dz   «      z   «      }!ŒL �Œ< | ja                  |!«      }!| jO                  |!«      }!|r||!fz   }|	r'nd }*|r|j>                  }*|r|jc                  «       }*|ste        d„ |!|*|||fD «       «      S tg        |!|*|||¬ «      S )!NÚdecoder_Ú zYou cannot specify both zinput_ids and zinputs_embeds at the same timer<   zYou have to specify either zinput_ids or Úinputs_embedszZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Fz<You have to initialize the model with valid token embeddingsTz)`use_cache` can only be set to `True` if z is used as a decoderzìPassing a tuple of `past_key_values` is deprecated and will be removed in Transformers v4.48.0. You should pass an instance of `EncoderDecoderCache` instead, e.g. `past_key_values=EncoderDecoderCache.from_legacy_cache(past_key_values)`.r   ©r  )rž   ry  r  r5   )rF  r(  rY  rZ  r[  r*  r\  r)  r+  r,  r]  r
  r)   rº   rE   é   r   é   r¯  c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wrº   r5   )r6   rá   s     r8   r9   z"T5Stack.forward.<locals>.<genexpr>¢  s   è ø€ ò 
àð �=ô ñ
ùr:   )Úlast_hidden_stateÚpast_key_valuesr¡   Ú
attentionsÚcross_attentions)4rª  rs   r³  Ú
set_devicer¶  r¥  rš   rz   r+  r,  Úoutput_hidden_statesÚuse_return_dictrÕ   rp   Úsizer  rç   r  rY   rÞ   r»   r   r   r   Úfrom_legacy_cacheÚget_seq_lengthr  r  r$   r‘   Ú_update_causal_maskr  rž   rW  ró   rñ   Úinvert_attention_maskÚget_head_maskr§  rµ   Ú	enumerater¨  Ú_gradient_checkpointing_funcr£   r«  r¸  rµ  r·  rH   Úto_legacy_cacheÚtupler   )+r“   rs  rF  rY  rZ  rÊ  Ú	head_maskÚcross_attn_head_maskrÐ  r+  r,  rÔ  r]  r
  Úerr_msg_prefixÚinput_shaper-  r.  Úreturn_legacy_cacheÚreturn_self_attention_cacheÚpast_key_values_lengthÚmask_seq_lengthr7  Úencoder_batch_sizeÚencoder_sequence_lengthÚ_Úencoder_hidden_shapeÚencoder_extended_attention_maskÚall_hidden_statesÚall_attentionsÚall_cross_attentionsr(  r[  r¡   r¬  Úlayer_moduler*  r\  Úlayer_outputsÚnext_decoder_cacherà   rá   Ú
next_caches+                                              r8   r£   zT5Stack.forward¾  s¾  € ð" ×ÒÜ�J‰J×!Ñ! $×"3Ñ"3Ô4Ø $× 1Ñ 1× 4Ñ 4°T×5FÑ5FÓ GˆDÔØ!*Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø1BÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ  ]Ð%>Ø+/¯?ª?™ZÀˆNÜØ*¨>Ð*:¸.ÈÐHXÐXvÐwóð ð Ð"Ø#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;‰IØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰Kà+/¯?ª?™ZÀˆNÜÐ:¸>Ð:JÈ-ÐXfÐWgÐgtÐuÓvÐvà×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øpôð "�	àÐ Ø× Ñ Ð(Ü Ð!_Ó`Ð`Ø ×-Ñ-¨iÓ8ˆMà!,Ñˆ
�Jà˜ÑØ—?’?Ü Ð#LÈTÈFÐRgÐ!hÓiÐið $ÐØ&+Ð#Ø�?Š?¡	¨_Ð-HÜ˜/¬5Ô1¼*À_ÔViÔ:jØ.2Ð+Ü"5°oÄ|Ã~Ó"V‘Ü Ô1DÔEØ&*Ð#Ü×#Ñ#ð`ôô
 #6×"GÑ"GÈÓ"X‘Ø Ð(Ü"5´l³nÄlÃnÓ"U‘Ø—’ð #ˆOàETÐE` ×!?Ñ!?Ô!AÐfgÐØÐ!Ü"Ÿ\™\Ø&Ð(>ÀÑ(KÐTa×ThÑThôˆNð Ð!Ô*BÔ*Dà4°zÑAˆOÜ"ŸZ™Z¨
°OÈM×L`ÑL`ÔaˆNà�;‰;×!Ò!Ø×2Ñ2ØØØØ8GÐ8S�×4Ò4ÐY]Ø!ó‰Kð Ð'Ø(ª¨D°$ºÐ)9Ñ:ˆKØ%Ÿ.™.¨}×/BÑ/B˜.ÓCˆKØ Ñ,´·±¸M×<OÑ<OÓ0P×0TÑ0TÑT‰KàˆKð �?Š?Ð4Ð@Ø=R×=WÑ=WÓ=YÑ:ÐÐ 7¸Ø$6Ð8OÐ#PÐ Ø%Ð-Ü).¯©Ø(°×1EÑ1EÌUÏZÉZô*Ð&ð /3×.HÑ.HÐI_Ó.`Ñ+à.2Ð+ð ×&Ñ& y°$·+±+×2HÑ2HÓIˆ	Ø#×1Ñ1Ð2FÈÏÉ×H^ÑH^Ó_ÐÙ"6™B¸DÐÙ0™°dˆÙ&7¸D¿OºO™rÐRVÐØˆØ(,Ð%àŸ™ ]Ó3ˆä(¨¯©Ó4ó Q	O‰OˆAˆ|Ø'¨™lˆOØ)=¸aÑ)@Ð&à×"Ò"Ü—
‘
×%Ñ% m×&:Ñ&:Ô;àÐ*Ø"-§.¡.°×1EÑ1EÓ"F�KØ Ð,Ø$1×$4Ñ$4°]×5IÑ5IÓ$J�MØ(Ð4Ø,A×,DÑ,DÀ]×EYÑEYÓ,ZÐ)Ø2Ð>Ø6U×6XÑ6XÐYf×YmÑYmÓ6nÐ3Ø0Ð<Ø4Q×4TÑ4TÐUb×UiÑUiÓ4jÐ1Ø"Ð.Ø&5×&8Ñ&8¸×9MÑ9MÓ&N�OØ-Ð9Ø1K×1NÑ1NÈ}×OcÑOcÓ1dÐ.Ù#Ø$5¸Ð8HÑ$HÐ!à×*Ò*¨t¯}ª}Ø $× AÑ AØ ×(Ñ(Ø!ØØ!Ø)Ø3Ø1Ø#Ø.ØØØ%ØØ"ó!‘ñ" !-Ø!Ø#.Ø"/Ø*?Ø+JØ2OØ$3Ø/IØ#2Ø'Ø&7Ø +Ø#1ô!�ð$ ˜EÑ!Ø -¨b¨qÐ 1°GÑ ;¸mÈAÈBÐ>OÑ O�à0=¸b¸qÐ0AÑ-ˆMÐ-ð
 *¨!Ñ,ˆMØ�ŠÐ#8Ð#DØ0=ÑCT¹aÐZ[Ñ0\Ð-á Ø!/°=ÀÑ3CÐ2EÑ!E�Ø—?’?Ø+?À=ÐQRÑCSÐBUÑ+UÐ(ð ×"Ô"Ø ŸO™O×1Ñ1Ó3ò O‘D�A�qØ˜A˜b™E“z g´°A³Ñ&6¸$×:JÑ:JÓ&JØ(5×(8Ñ(8¸Ä3ÀqÈ1ÁuÃ:Ñ9MÓ(N™òOð_Q	Oðf ×-Ñ-¨mÓ<ˆØŸ™ ]Ó3ˆñ  Ø 1°]Ð4DÑ DÐá+4Ñ'¸$ˆ
Ù&Ø(×=Ñ=ˆJÙØ(×8Ñ8Ó:ˆJáÜñ 
ð "ØØ%Ø"Ø(ðô
ó 
ð 
ô 9Ø+Ø&Ø+Ø%Ø1ô
ð 	
r—   rF  Úinput_tensorr
  rÐ  r,  c           
      óÆ  — | j                   j                  dk(  r|�|dk(  j                  «       r|S y | j                   j                  dk(  r7t        |t        j
                  «      rt        |«      }t        |t        «      r|S |�|j                  «       nd}t        |t        «      }| j                   j                  dk(  r(|s&|s$t        j                  |||| j                  ¬«      ry |j                  |j                  }	}|j                  d   }
|r|j!                  «       }n1t        |t        j
                  «      r|j                  d   n||
z   dz   }| j#                  ||
|||	||j                  d   ¬	«      }| j                   j                  dk(  rQ|�O|j                  j$                  d
v r7|s5t	        j&                  |«      j(                  }t        j*                  ||«      }|S )NÚflash_attention_2rz  Úflex_attentionr   Úsdpa)rÊ  ræ  Úis_trainingr)   r<   )Úsequence_lengthÚtarget_lengthrž   r  r
  r-  )r³  Úxpu)rz   Ú_attn_implementationrd   r»   rs   r¼   r,   r+   rØ  r   r   Ú_ignore_causal_mask_sdpar  rž   r  rn   Úget_max_cache_shapeÚ5_prepare_4d_causal_attention_mask_with_cache_positionÚtyperW  ró   Ú_unmask_unattended)r“   rF  rô  r
  rÐ  r,  Úpast_seen_tokensÚusing_static_cacherž   r  rú  rû  r7  Ú	min_dtypes                 r8   rÙ  zT5Stack._update_causal_mask¶  sÖ  € ð �;‰;×+Ñ+Ð/BÒBØÐ)¨~ÀÑ/D×.IÑ.IÔ.KØ%Ð%ØØ�;‰;×+Ñ+Ð/?Ò?Ü˜.¬%¯,©,Ô7Ü!<¸^Ó!L�Ü˜.¬)Ô4Ø%Ð%ð
 @OÐ?Z˜?×9Ñ9Ô;Ð`aÐÜ'¨¼ÓEÐð �;‰;×+Ñ+¨vÒ5Ñ>PÑYjÜ%×>Ñ>ØØ*Ø'7Ø ŸM™Mõ	ð à$×*Ñ*¨L×,?Ñ,?ˆvˆØ&×,Ñ,¨QÑ/ˆÙØ+×?Ñ?ÓA‰Mô ˜n¬e¯l©lÔ;ð ×$Ñ$ RÒ(à%¨Ñ7¸!Ñ;ð ð ×PÑPØØ+Ø'ØØØ)Ø#×)Ñ)¨!Ñ,ð Qó 
ˆð �K‰K×,Ñ,°Ò6ØÐ*Ø×%Ñ%×*Ñ*¨oÑ=Ù%ô
 Ÿ™ EÓ*×.Ñ.ˆIÜ0×CÑCÀKÐQZÓ[ˆKàÐr—   rú  rû  rž   r  r-  c                 ó˜  — | �| j                  «       dk(  r| }|S t        j                  |«      j                  }	t        j                  ||f|	||¬«      }|dk7  rt        j
                  |d¬«      }|t        j                  ||¬«      |j                  dd«      kD  z  }|dddd…dd…f   j                  |ddd«      }| �Œ|j                  «       }| j                  d   }
|dd…dd…dd…d|
…f   | dd…dddd…f   j                  |j                  «      z   }|dk(  }|dd…dd…dd…d|
…f   j                  ||	«      |dd…dd…dd…d|
…f<   |S )	a°  
        Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
        `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.

        Args:
            attention_mask (`torch.Tensor`):
                A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape
                `(batch_size, 1, query_length, key_value_length)`.
            sequence_length (`int`):
                The sequence length being processed.
            target_length (`int`):
                The target length: when generating with static cache, the mask should be as long as the static cache,
                to account for the 0 padding, the part of the cache that is not filled yet.
            dtype (`torch.dtype`):
                The dtype to use for the 4D attention mask.
            device (`torch.device`):
                The device to place the 4D attention mask on.
            cache_position (`torch.Tensor`):
                Indices depicting the position of the input sequence tokens in the sequence.
            batch_size (`torch.Tensor`):
                Batch size.
        NrÌ  )Ú
fill_valuerž   r  r)   )ÚdiagonalrË  r<   r   )rë   rs   rW  ró   r�  Útriur  ÚreshapeÚexpandr“  rn   rš   r  Úmasked_fill)rF  rú  rû  rž   r  r
  r-  Úkwargsr7  r  Úmask_lengthÚpadding_masks               r8   r   z=T5Stack._prepare_4d_causal_attention_mask_with_cache_positionü  sy  € ðD Ð%¨.×*<Ñ*<Ó*>À!Ò*Cà(ˆKð* Ðô' Ÿ™ EÓ*×.Ñ.ˆIÜŸ*™*Ø  -Ð0¸YÈeÐ\bôˆKð  !Ò#Ü#Ÿj™j¨¸qÔA�Øœ5Ÿ<™<¨¸fÔEÈ×H^ÑH^Ð_aÐcdÓHeÑeÑeˆKØ% d¨D²!²QÐ&6Ñ7×>Ñ>¸zÈ1ÈbÐRTÓUˆKØÐ)Ø)×/Ñ/Ó1�Ø,×2Ñ2°2Ñ6�Ø*ª1ªa²°L°[°LÐ+@ÑAÀNÒSTÐVZÐ\`ÒbcÐScÑDd×DgÑDgØ×&Ñ&óEñ  �ð  ,¨qÑ0�Ø5@ÂÂAÂqÈ,È;È,ÐAVÑ5W×5cÑ5cØ  )ó6�šAšq¢! \ k \Ð1Ñ2ð Ðr—   rº   )NNNNNNNNNNNNN)F)r¤   r¥   r¦   r�   r    ÚPARALLELIZE_DOCSTRINGrº  ÚDEPARALLELIZE_DOCSTRINGr¾  rÂ  rÆ  r£   rs   r¼   r   r!  rÙ  r?  rm   rž   r  r   r§   r¨   s   @r8   r£  r£  x  s+  ø„ õ,ñ& Ð/Ó0òKó 1ðKñ6 Ð1Ó2ñ!ó 3ð!ò!ò+ð
 ØØ"Ø#ØØØ!ØØØØ!ØØóu
ð| #(ñDàŸ™ðDð —l‘lðDð Ÿ™ð	Dð
 ðDð  óDðL ð7ØŸ™ð7àð7ð ð7ð �{‰{ð	7ð
 —‘ð7ð Ÿ™ð7ð ò7ó ô7r—   r£  a½  

    The T5 model was proposed in [Exploring the Limits of Transfer Learning with a Unified Text-to-Text
    Transformer](https://arxiv.org/abs/1910.10683) by Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan
    Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J. Liu. It's an encoder decoder transformer pre-trained in a
    text-to-text denoising generative setting.

    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`T5Config`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
ay  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
            should be able to pad the inputs on both the right and the left.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for detail.

            [What are input IDs?](../glossary#input-ids)

            To know more on how to prepare `input_ids` for pretraining take a look a [T5 Training](./t5#training).
        attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are decoder input IDs?](../glossary#decoder-input-ids)

            T5 uses the `pad_token_id` as the starting token for `decoder_input_ids` generation. If `past_key_values`
            is used, optionally only the last `decoder_input_ids` have to be input (see `past_key_values`).

            To know more on how to prepare `decoder_input_ids` for pretraining take a look at [T5
            Training](./t5#training).
        decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.
        head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
            Mask to nullify selected heads of the self-attention modules in the encoder. Mask values selected in `[0,
            1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        decoder_head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
            Mask to nullify selected heads of the self-attention modules in the decoder. Mask values selected in `[0,
            1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        cross_attn_head_mask (`torch.Tensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
                Mask to nullify selected heads of the cross-attention modules in the decoder. Mask values selected in
                `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*):
            Tuple consists of (`last_hidden_state`, `optional`: *hidden_states*, `optional`: *attentions*)
            `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)` is a sequence of hidden states at
            the output of the last layer of the encoder. Used in the cross-attention of the decoder.
        past_key_values (`tuple(tuple(torch.FloatTensor))` of length `config.n_layers` with each tuple having 4 tensors of shape `(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`):
            Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.

            If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
            don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_ids` of shape `(batch_size, sequence_length)`.
        inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        decoder_inputs_embeds (`torch.FloatTensor` of shape `(batch_size, target_sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `decoder_input_ids` you can choose to directly pass an embedded
            representation. If `past_key_values` is used, optionally only the last `decoder_inputs_embeds` have to be
            input (see `past_key_values`). This is useful if you want more control over how to convert
            `decoder_input_ids` indices into associated vectors than the model's internal embedding lookup matrix.

            If `decoder_input_ids` and `decoder_inputs_embeds` are both unset, `decoder_inputs_embeds` takes the value
            of `inputs_embeds`.

        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).

        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
            Indices depicting the position of the input sequence tokens in the sequence. It is used to update the
            cache in the correct position and to infer the complete sequence length.
aŒ  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
            should be able to pad the inputs on both the right and the left.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for detail.

            To know more on how to prepare `input_ids` for pretraining take a look a [T5 Training](./t5#training).
        attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
            Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
a_  
The input argument `head_mask` was split into two arguments `head_mask` and `decoder_head_mask`. Currently,
`decoder_head_mask` is set to copy `head_mask`, but this feature is deprecated and will be removed in future versions.
If you do not want to use any `decoder_head_mask` now, please set `decoder_head_mask = torch.ones(num_layers,
num_heads)`.
z\The bare T5 Model transformer outputting raw hidden-states without any specific head on top.c            '       óº  ‡ — e Zd ZdgZddgZdefˆ fd„Z ee«      d!d„«       Z	 ee
«      d„ «       Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Z ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"deej2                     deej4                     deej2                     deej6                     deej4                     deej4                     deej8                     deeeej4                           deeeej4                           deej8                     deej8                     dee   dee   dee   dee   deej2                     deeej4                     ef   f"d „«       «       Z ˆ xZ!S )#r€  úFdecoder.block.0.layer.1.EncDecAttention.relative_attention_bias.weightúencoder.embed_tokens.weightúdecoder.embed_tokens.weightrz   c                 óæ  •— t         ‰| �  |«       t        j                  |j                  |j
                  «      | _        t        j                  |«      }d|_	        d|_
        d|_        t        || j                  «      | _        t        j                  |«      }d|_	        d|_        |j                  |_        t        || j                  «      | _        | j#                  «        d| _        d | _        y ©NFT)rŽ   r�   r   rã   Ú
vocab_sizer°   r„  ÚcopyÚdeepcopyrÕ   r+  Úis_encoder_decoderr£  ÚencoderÚnum_decoder_layersr§  rN   r©  rª  r«  ©r“   rz   Úencoder_configÚdecoder_configr–   s       €r8   r�   zT5Model.__init__å  s¿   ø€ Ü‰Ñ˜Ô Ü—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ$)ˆÔ!Ø#(ˆÔ Ø,1ˆÔ)Ü˜~¨t¯{©{Ó;ˆŒäŸ™ vÓ.ˆØ$(ˆÔ!Ø,1ˆÔ)Ø$*×$=Ñ$=ˆÔ!Ü˜~¨t¯{©{Ó;ˆŒð 	�‰Ôð $ˆÔØˆ�r—   c                 óî  — t        j                  dt        «       |€Nt        t	        | j
                  j                  «      t        t        j                  j                  «       «      «      n|| _        t        | j                  t	        | j
                  j                  «      «       | j
                  j                  | j                  «       | j                  j                  | j                  «       d| _        y )NaL  `T5Model.parallelize` is deprecated and will be removed in v5 of Transformers, you should load your model with `device_map='balanced'` in the call to `from_pretrained`. You can also provide your own `device_map` but it needs to be a dictionary module_name to device, so for instance {'encoder.block.0': 0, 'encoder.block.1': 1, ...}T)r°  r±  r²  r(   rj   r  r¨  r¦  rs   r³  r´  r«  r'   rº  rN   rª  ©r“   r«  s     r8   rº  zT5Model.parallelizeü  sª   € ä�‰ð-ô ô	
ð Ð!ô œ3˜tŸ|™|×1Ñ1Ó2´E¼%¿*¹*×:QÑ:QÓ:SÓ4TÔUàð 	Œô
 	˜$Ÿ/™/¬3¨t¯|©|×/AÑ/AÓ+BÔCØ�‰× Ñ  §¡Ô1Ø�‰× Ñ  §¡Ô1Ø"ˆÕr—   c                 óx  — t        j                  dt        «       | j                  j	                  «        | j
                  j	                  «        | j                  j                  d«      | _        | j
                  j                  d«      | _        d| _        d | _        t        j                  j                  «        y ©Nr¼  r®  F)r°  r±  r²  r  r¾  rN   rš   rª  r«  rs   r³  r½  rÁ  s    r8   r¾  zT5Model.deparallelize  s}   € ä�‰ØjÜô	
ð 	�‰×"Ñ"Ô$Ø�‰×"Ñ"Ô$Ø—|‘|—‘ uÓ-ˆŒØ—|‘|—‘ uÓ-ˆŒØ#ˆÔØˆŒÜ�
‰
×ÑÕ r—   c                 ó   — | j                   S rº   ©r„  rÁ  s    r8   rÂ  zT5Model.get_input_embeddings  ó   € Ø�{‰{Ðr—   c                 ó~   — || _         | j                  j                  |«       | j                  j                  |«       y rº   ©r„  r  rÆ  rN   rÄ  s     r8   rÆ  zT5Model.set_input_embeddings   ó-   € Ø$ˆŒØ�‰×)Ñ)¨.Ô9Ø�‰×)Ñ)¨.Õ9r—   c                 óò   — | j                   j                  ra| j                  | j                  j                  | j
                  «       | j                  | j                  j                  | j
                  «       y y rº   ©rz   r†  Ú_tie_or_clone_weightsr  r¥  r„  rN   rÁ  s    r8   Ú_tie_weightszT5Model._tie_weights%  óP   € Ø�;‰;×*Ò*Ø×&Ñ& t§|¡|×'@Ñ'@À$Ç+Á+ÔNØ×&Ñ& t§|¡|×'@Ñ'@À$Ç+Á+ÕNð +r—   c                 ó   — | j                   S rº   ©r  rÁ  s    r8   Úget_encoderzT5Model.get_encoder*  ó   € Ø�|‰|Ðr—   c                 ó   — | j                   S rº   ©rN   rÁ  s    r8   Úget_decoderzT5Model.get_decoder-  r3  r—   c                 ó˜   — |j                  «       D ]7  \  }}| j                  j                  |   j                  j	                  |«       Œ9 y)ú�
        Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer} See base
        class PreTrainedModel
        N)r¸  r  rB   Ú	attentionrï   ©r“   Úheads_to_prunerB   rí   s       r8   Ú_prune_headszT5Model._prune_heads0  sE   € ð
 +×0Ñ0Ó2ò 	C‰LˆE�5Ø�L‰L×Ñ˜uÑ%×/Ñ/×;Ñ;¸EÕBñ	Cr—   ©Úoutput_typer—  rs  rF  rr  rt  rà  Údecoder_head_maskrá  Úencoder_outputsrÐ  rÊ  Údecoder_inputs_embedsr+  r,  rÔ  r]  r
  rj  c                 ó   — |�|n| j                   j                  }|�|n| j                   j                  }|�O|€M| j                   j                  | j                   j                  k(  r t        j                  t        t        «       |}|€| j                  |||
||||¬«      }nI|rGt        |t        «      s7t        |d   t        |«      dkD  r|d   ndt        |«      dkD  r|d   nd¬«      }|d   }| j                  rÍt        j                  j!                  | j"                  j$                  «       |j'                  | j"                  j$                  «      }|�%|j'                  | j"                  j$                  «      }|�%|j'                  | j"                  j$                  «      }|�%|j'                  | j"                  j$                  «      }| j#                  ||||	|||||||||¬«      }|s||z   S t)        |j*                  |j,                  |j.                  |j0                  |j2                  |j*                  |j.                  |j0                  ¬«      S )	aö  
        Returns:

        Example:

        ```python
        >>> from transformers import AutoTokenizer, T5Model

        >>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
        >>> model = T5Model.from_pretrained("google-t5/t5-small")

        >>> input_ids = tokenizer(
        ...     "Studies have been shown that owning a dog is good for you", return_tensors="pt"
        ... ).input_ids  # Batch size 1
        >>> decoder_input_ids = tokenizer("Studies show that", return_tensors="pt").input_ids  # Batch size 1

        >>> # preprocess: Prepend decoder_input_ids with start token which is pad token for T5Model.
        >>> # This is not needed for torch's T5ForConditionalGeneration as it does this internally using labels arg.
        >>> decoder_input_ids = model._shift_right(decoder_input_ids)

        >>> # forward pass
        >>> outputs = model(input_ids=input_ids, decoder_input_ids=decoder_input_ids)
        >>> last_hidden_states = outputs.last_hidden_state
        ```N©rs  rF  rÊ  rà  r,  rÔ  r]  r   r)   rE   ©rÏ  r¡   rÑ  ©rs  rF  rÊ  rÐ  rY  rZ  rà  rá  r+  r,  rÔ  r]  r
  )rÏ  rÐ  Údecoder_hidden_statesÚdecoder_attentionsrÒ  Úencoder_last_hidden_staterY  Úencoder_attentions)rz   r+  rÕ  r§  r  r°  r±  Ú_T5Model__HEAD_MASK_WARNING_MSGr²  r  r»   r   rj   rª  rs   r³  rÓ  rN   r¶  rš   r   rÏ  rÐ  r¡   rÑ  rÒ  )r“   rs  rF  rr  rt  rà  r?  rá  r@  rÐ  rÊ  rA  r+  r,  rÔ  r]  r
  r¡   Údecoder_outputss                      r8   r£   zT5Model.forward8  s=  € ðZ "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð Ð%6Ð%>Ø�{‰{×%Ñ%¨¯©×)GÑ)GÒGÜ—‘Ô5´}ÔEØ$-Ð!ð Ð"Ø"Ÿl™lØ#Ø-Ø+Ø#Ø"3Ø%9Ø'ð +ó ‰Oñ ¤¨O¼_Ô!MÜ-Ø"1°!Ñ"4Ü47¸Ó4HÈ1Ò4L˜o¨aÒ0ÐRVÜ14°_Ó1EÈÒ1I˜?¨1Ò-ÈtôˆOð (¨Ñ*ˆð ×ÒÜ�J‰J×!Ñ! $§,¡,×";Ñ";Ô<Ø)×,Ñ,¨T¯\©\×-FÑ-FÓGˆMØ Ð,Ø$5×$8Ñ$8¸¿¹×9RÑ9RÓ$SÐ!ØÐ)Ø!/×!2Ñ!2°4·<±<×3LÑ3LÓ!M�Ø%Ð1Ø)?×)BÑ)BÀ4Ç<Á<×C\ÑC\Ó)]Ð&ð Ÿ,™,Ø'Ø1Ø/Ø+Ø"/Ø#1Ø'Ø!5ØØ/Ø!5Ø#Ø)ð 'ó 
ˆñ  Ø" _Ñ4Ð4ä!Ø-×?Ñ?Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô	
ð 		
r—   rº   ©NNNNNNNNNNNNNNNN)"r¤   r¥   r¦   Ú"_keys_to_ignore_on_load_unexpectedÚ_tied_weights_keysr*   r�   r    r  rº  r  r¾  rÂ  rÆ  r.  r2  r6  r<  r!   ÚT5_INPUTS_DOCSTRINGr&   r   Ú_CONFIG_FOR_DOCr   rs   Ú
LongTensorÚFloatTensorÚ
BoolTensorr¼   r   r!  r   r£   r§   r¨   s   @r8   r€  r€  Û  sP  ø„ ð 	Qð*Ð&ð 8Ð9VÐWÐð˜xõ ñ. Ð/Ó0ò#ó 1ð#ñ$ Ð1Ó2ñ!ó 3ð!òò:ò
Oò
òòCñ +Ð+>Ó?ÙÐ+=ÈOÔ\ð 15Ø6:Ø8<Ø=AØ15Ø9=Ø7;ØEIØEIØ04Ø8<Ø$(Ø,0Ø/3Ø&*Ø59ñ#p
à˜E×,Ñ,Ñ-ðp
ð ! ×!2Ñ!2Ñ3ðp
ð $ E×$4Ñ$4Ñ5ð	p
ð
 !)¨×)9Ñ)9Ñ :ðp
ð ˜E×-Ñ-Ñ.ðp
ð $ E×$5Ñ$5Ñ6ðp
ð ' u§|¡|Ñ4ðp
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðp
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðp
ð   §¡Ñ-ðp
ð  (¨¯©Ñ5ðp
ð ˜D‘>ðp
ð $ D™>ðp
ð ' t™nðp
ð  ˜d‘^ð!p
ð" ! ×!1Ñ!1Ñ2ð#p
ð$ 
ˆu�U×&Ñ&Ñ'Ð);Ð;Ñ	<ò%p
ó ]ó @ôp
r—   r€  z0T5 Model with a `language modeling` head on top.c            )       ó  ‡ — e Zd ZdgZg d¢Zdefˆ fd„Z ee«      d$d„«       Z	 ee
«      d„ «       Zd„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Z ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d%deej4                     deej6                     deej4                     deej8                     deej6                     deej6                     deej:                     deeeej:                           deeeej:                           deej6                     deej6                     deej4                     dee   dee   dee   dee   deej4                     d e eej6                     ef   f$d!„«       «       Z!dej:                  fd"„Z"d#„ Z#ˆ xZ$S )&r�  r  )r  r  zlm_head.weightrz   c                 ój  •— t         ‰| �  |«       |j                  | _        t	        j
                  |j                  |j                  «      | _        t        j                  |«      }d|_
        d|_        d|_        t        || j                  «      | _        t        j                  |«      }d|_
        d|_        |j                  |_        t        || j                  «      | _        t	        j$                  |j                  |j                  d¬«      | _        | j)                  «        d| _        d | _        y )NFTr®   )rŽ   r�   r°   Ú	model_dimr   rã   r  r„  r  r  rÕ   r+  r  r£  r  r  r§  rN   r¯   rP   r©  rª  r«  r  s       €r8   r�   z#T5ForConditionalGeneration.__init__´  sè   ø€ Ü‰Ñ˜Ô ØŸ™ˆŒä—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ$)ˆÔ!Ø#(ˆÔ Ø,1ˆÔ)Ü˜~¨t¯{©{Ó;ˆŒäŸ™ vÓ.ˆØ$(ˆÔ!Ø,1ˆÔ)Ø$*×$=Ñ$=ˆÔ!Ü˜~¨t¯{©{Ó;ˆŒä—y‘y §¡°×1BÑ1BÈÔOˆŒð 	�‰Ôð $ˆÔØˆ�r—   c                 óV  — t        j                  dt        «       |€Nt        t	        | j
                  j                  «      t        t        j                  j                  «       «      «      n|| _        t        | j                  t	        | j
                  j                  «      «       | j
                  j                  | j                  «       | j                  j                  | j                  «       | j                  j!                  | j                  j"                  «      | _        d| _        y )Na_  `T5ForConditionalGeneration.parallelize` is deprecated and will be removed in v5 of Transformers, you should load your model with `device_map='balanced'` in the call to `from_pretrained`. You can also provide your own `device_map` but it needs to be a dictionary module_name to device, so for instance {'encoder.block.0': 0, 'encoder.block.1': 1, ...}T)r°  r±  r²  r(   rj   r  r¨  r¦  rs   r³  r´  r«  r'   rº  rN   rP   rš   r¶  rª  r"  s     r8   rº  z&T5ForConditionalGeneration.parallelizeÏ  sÉ   € ä�‰ðAô ô	
ð Ð!ô œ3˜tŸ|™|×1Ñ1Ó2´E¼%¿*¹*×:QÑ:QÓ:SÓ4TÔUàð 	Œô
 	˜$Ÿ/™/¬3¨t¯|©|×/AÑ/AÓ+BÔCØ�‰× Ñ  §¡Ô1Ø�‰× Ñ  §¡Ô1Ø—|‘|—‘ t§|¡|×'@Ñ'@ÓAˆŒØ"ˆÕr—   c                 ó¸  — t        j                  dt        «       | j                  j	                  «        | j
                  j	                  «        | j                  j                  d«      | _        | j
                  j                  d«      | _        | j                  j                  d«      | _        d| _        d | _	        t        j                  j                  «        y r$  )r°  r±  r²  r  r¾  rN   rš   rP   rª  r«  rs   r³  r½  rÁ  s    r8   r¾  z(T5ForConditionalGeneration.deparallelizeã  s‘   € ä�‰ØjÜô	
ð 	�‰×"Ñ"Ô$Ø�‰×"Ñ"Ô$Ø—|‘|—‘ uÓ-ˆŒØ—|‘|—‘ uÓ-ˆŒØ—|‘|—‘ uÓ-ˆŒØ#ˆÔØˆŒÜ�
‰
×ÑÕ r—   c                 ó   — | j                   S rº   r&  rÁ  s    r8   rÂ  z/T5ForConditionalGeneration.get_input_embeddingsò  r'  r—   c                 ó~   — || _         | j                  j                  |«       | j                  j                  |«       y rº   r)  rÄ  s     r8   rÆ  z/T5ForConditionalGeneration.set_input_embeddingsõ  r*  r—   c                 óò   — | j                   j                  ra| j                  | j                  j                  | j
                  «       | j                  | j                  j                  | j
                  «       y y rº   r,  rÁ  s    r8   r.  z'T5ForConditionalGeneration._tie_weightsú  r/  r—   c                 ó   — || _         y rº   ©rP   rÄ  s     r8   Úset_output_embeddingsz0T5ForConditionalGeneration.set_output_embeddingsÿ  s	   € Ø%ˆ�r—   c                 ó   — | j                   S rº   r]  rÁ  s    r8   Úget_output_embeddingsz0T5ForConditionalGeneration.get_output_embeddings  r3  r—   c                 ó   — | j                   S rº   r1  rÁ  s    r8   r2  z&T5ForConditionalGeneration.get_encoder  r3  r—   c                 ó   — | j                   S rº   r5  rÁ  s    r8   r6  z&T5ForConditionalGeneration.get_decoder  r3  r—   r=  rs  rF  rr  rt  rà  r?  rá  r@  rÐ  rÊ  rA  Úlabelsr+  r,  rÔ  r]  r
  rj  c                 óà  — |�|n| j                   j                  }|�|n| j                   j                  }|�O|€M| j                   j                  | j                   j                  k(  r t        j                  t        t        «       |}|€| j                  |||
||||¬«      }nI|rGt        |t        «      s7t        |d   t        |«      dkD  r|d   ndt        |«      dkD  r|d   nd¬«      }|d   }| j                  r3t        j                  j!                  | j"                  j$                  «       |�|€|€| j'                  |«      }| j                  rÍt        j                  j!                  | j"                  j$                  «       |j)                  | j"                  j$                  «      }|�%|j)                  | j"                  j$                  «      }|�%|j)                  | j"                  j$                  «      }|�%|j)                  | j"                  j$                  «      }| j#                  ||||	|||||||||¬«      }|d   }| j                  r–t        j                  j!                  | j                  j$                  «       | j*                  j)                  | j                  j$                  «      | _        |j)                  | j*                  j,                  j.                  «      }| j                   j0                  r|| j2                  dz  z  }| j+                  |«      }d}|�^t5        d	¬
«      }|j)                  |j.                  «      } ||j7                  d|j9                  d«      «      |j7                  d«      «      }|s|f|dd z   |z   }|�|f|z   S |S t;        |||j<                  |j>                  |j@                  |jB                  |jD                  |j>                  |j@                  ¬«	      S )a¢  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[-100, 0, ...,
            config.vocab_size - 1]`. All labels set to `-100` are ignored (masked), the loss is only computed for
            labels in `[0, ..., config.vocab_size]`

        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, T5ForConditionalGeneration

        >>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
        >>> model = T5ForConditionalGeneration.from_pretrained("google-t5/t5-small")

        >>> # training
        >>> input_ids = tokenizer("The <extra_id_0> walks in <extra_id_1> park", return_tensors="pt").input_ids
        >>> labels = tokenizer("<extra_id_0> cute dog <extra_id_1> the <extra_id_2>", return_tensors="pt").input_ids
        >>> outputs = model(input_ids=input_ids, labels=labels)
        >>> loss = outputs.loss
        >>> logits = outputs.logits

        >>> # inference
        >>> input_ids = tokenizer(
        ...     "summarize: studies have shown that owning a dog is good for you", return_tensors="pt"
        ... ).input_ids  # Batch size 1
        >>> outputs = model.generate(input_ids)
        >>> print(tokenizer.decode(outputs[0], skip_special_tokens=True))
        >>> # studies have shown that owning a dog is good for you.
        ```NrC  r   r)   rE   rD  rE  r}  r�  ©Úignore_indexr<   ©	ÚlossrO   rÐ  rF  rG  rÒ  rH  rY  rI  )#rz   r+  rÕ  r§  r  r°  r±  Ú2_T5ForConditionalGeneration__HEAD_MASK_WARNING_MSGr²  r  r»   r   rj   rª  rs   r³  rÓ  rN   r¶  r–  rš   rP   r@   r  r†  rV  r	   r  rÖ  r   rÐ  r¡   rÑ  rÒ  rÏ  )r“   rs  rF  rr  rt  rà  r?  rá  r@  rÐ  rÊ  rA  rc  r+  r,  rÔ  r]  r
  r¡   rK  Úsequence_outputÚ	lm_logitsrh  Úloss_fctÚoutputs                            r8   r£   z"T5ForConditionalGeneration.forward  s™  € ðj "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð Ð%6Ð%>Ø�{‰{×%Ñ%¨¯©×)GÑ)GÒGÜ—‘Ô5´}ÔEØ$-Ð!ð Ð"à"Ÿl™lØ#Ø-Ø+Ø#Ø"3Ø%9Ø'ð +ó ‰Oñ ¤¨O¼_Ô!MÜ-Ø"1°!Ñ"4Ü47¸Ó4HÈ1Ò4L˜o¨aÒ0ÐRVÜ14°_Ó1EÈÒ1I˜?¨1Ò-ÈtôˆOð (¨Ñ*ˆà×ÒÜ�J‰J×!Ñ! $§,¡,×";Ñ";Ô<àÐÐ"3Ð";Ð@UÐ@]à $× 1Ñ 1°&Ó 9Ðð ×ÒÜ�J‰J×!Ñ! $§,¡,×";Ñ";Ô<Ø)×,Ñ,¨T¯\©\×-FÑ-FÓGˆMØ Ð,Ø$5×$8Ñ$8¸¿¹×9RÑ9RÓ$SÐ!ØÐ)Ø!/×!2Ñ!2°4·<±<×3LÑ3LÓ!M�Ø%Ð1Ø)?×)BÑ)BÀ4Ç<Á<×C\ÑC\Ó)]Ð&ð Ÿ,™,Ø'Ø1Ø/Ø+Ø"/Ø#1Ø'Ø!5ØØ/Ø!5Ø#Ø)ð 'ó 
ˆð  *¨!Ñ,ˆð ×ÒÜ�J‰J×!Ñ! $§,¡,×";Ñ";Ô<ØŸ<™<Ÿ?™?¨4¯<©<×+DÑ+DÓEˆDŒLØ-×0Ñ0°·±×1DÑ1D×1KÑ1KÓLˆOà�;‰;×*Ò*ð .°·±ÀÑ1EÑFˆOà—L‘L Ó1ˆ	àˆØÐÜ'°TÔ:ˆHà—Y‘Y˜y×/Ñ/Ó0ˆFÙ˜IŸN™N¨2¨y¯~©~¸bÓ/AÓBÀFÇKÁKÐPRÃOÓTˆDñ Ø�\ O°A°BÐ$7Ñ7¸/ÑIˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEäØØØ+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô

ð 
	
r—   c                 ó$   — | j                  |«      S rº   )r–  )r“   rc  s     r8   Ú%prepare_decoder_input_ids_from_labelsz@T5ForConditionalGeneration.prepare_decoder_input_ids_from_labels¨  s   € Ø× Ñ  Ó(Ð(r—   c           	      óÒ  — |€t         j                  d«       |S d}|D ]Æ  }d}|D ]1  }||j                  d|j                  |j                  «      «      fz   }Œ3 |d   j
                  |d   j
                  k7  r,t        d|d   j
                  › d|d   j
                  › d�«      ‚t        |«      t        |«      k7  r$t        dt        |«      › dt        |«      › d�«      ‚||fz   }ŒÈ |S )	NzHYou might want to consider setting `use_cache=True` to speed up decodingr5   r   z%reordered_layer_past_states[0] shape z  and layer_past_states[0] shape rS   z&length of reordered_layer_past_states z! and length of layer_past_states )rY   ÚwarningÚindex_selectrš   r  rn   rp   rj   )r“   rÐ  Úbeam_idxÚreordered_decoder_pastÚlayer_past_statesÚreordered_layer_past_statesÚlayer_past_states          r8   Ú_reorder_cachez)T5ForConditionalGeneration._reorder_cache«  su  € ð Ð"Ü�N‰NÐeÔfØ"Ð"à!#ÐØ!0ò 	]Ðð +-Ð'Ø$5ò Ð à.IØ$×1Ñ1°!°X·[±[ÐAQ×AXÑAXÓ5YÓZðMñ /Ñ+ðð +¨1Ñ-×3Ñ3Ð7HÈÑ7K×7QÑ7QÒQÜ Ø;Ð<WÐXYÑ<Z×<`Ñ<`Ð;að  bBð  CTð  UVñ  CW÷  C]ñ  C]ð  B^ð  ^ið  jóð ô Ð.Ó/´3Ð7HÓ3IÒIÜ Ø<¼SÐA\Ó=]Ð<^Ð^ô  ADð  EVó  AWð  @Xð  Xcð  dóð ð &<Ð?ZÐ>\Ñ%\Ñ"ð'	]ð( &Ð%r—   rº   )NNNNNNNNNNNNNNNNN)%r¤   r¥   r¦   rM  rN  r*   r�   r    r  rº  r  r¾  rÂ  rÆ  r.  r^  r`  r2  r6  r!   rO  r&   r   rP  r   rs   rQ  rR  rS  r¼   r   r!  r   r£   ro  rx  r§   r¨   s   @r8   r�  r�  ­  s|  ø„ ð 	Qð*Ð&ò jÐð˜xõ ñ6 Ð/Ó0ò#ó 1ð#ñ& Ð1Ó2ñ!ó 3ð!òò:ò
Oò
&òòòñ +Ð+>Ó?Ù¨?ÈÔYð 15Ø6:Ø8<Ø=AØ15Ø9=Ø7;Ø@DØ@DØ59Ø=AØ-1Ø$(Ø,0Ø/3Ø&*Ø59ñ%Y
à˜E×,Ñ,Ñ-ðY
ð ! ×!2Ñ!2Ñ3ðY
ð $ E×$4Ñ$4Ñ5ð	Y
ð
 !)¨×)9Ñ)9Ñ :ðY
ð ˜E×-Ñ-Ñ.ðY
ð $ E×$5Ñ$5Ñ6ðY
ð ' u§|¡|Ñ4ðY
ð " %¨¨e¯l©lÑ(;Ñ"<Ñ=ðY
ð " %¨¨e¯l©lÑ(;Ñ"<Ñ=ðY
ð   × 1Ñ 1Ñ2ðY
ð  (¨×(9Ñ(9Ñ:ðY
ð ˜×)Ñ)Ñ*ðY
ð ˜D‘>ðY
ð $ D™>ðY
ð  ' t™nð!Y
ð" ˜d‘^ð#Y
ð$ ! ×!1Ñ!1Ñ2ð%Y
ð& 
ˆu�U×&Ñ&Ñ'¨Ð8Ñ	9ò'Y
ó Zó @ðY
ðv)¸E¿L¹Ló )ö&r—   r�  zfThe bare T5 Model transformer outputting encoder's raw hidden-states without any specific head on top.c                   óŽ  ‡ — e Zd ZdgZdgZdefˆ fd„Z ee«      dd„«       Z	 ee
«      d„ «       Zd„ Zd„ Zd	„ Zd
„ Zd„ Z ee«       eee¬«      	 	 	 	 	 	 	 ddeej0                     deej2                     deej2                     deej2                     dee   dee   dee   deeej2                     ef   fd„«       «       Zˆ xZS )r‚  r  rN   rz   c                 ó:  •— t         ‰| �  |«       t        j                  |j                  |j
                  «      | _        t        j                  |«      }d|_	        d|_
        t        || j                  «      | _        | j                  «        d| _        d | _        y ©NF)rŽ   r�   r   rã   r  r°   r„  r  r  r+  r  r£  r  r©  rª  r«  )r“   rz   r  r–   s      €r8   r�   zT5EncoderModel.__init__Ò  sy   ø€ Ü‰Ñ˜Ô Ü—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ#(ˆÔ Ø,1ˆÔ)Ü˜~¨t¯{©{Ó;ˆŒð 	�‰Ôð $ˆÔØˆ�r—   c                 ó¤  — t        j                  dt        «       |€Nt        t	        | j
                  j                  «      t        t        j                  j                  «       «      «      n|| _        t        | j                  t	        | j
                  j                  «      «       | j
                  j                  | j                  «       d| _        y )NaC  `T5EncoderModel.parallelize` is deprecated and will be removed in v5 of Transformers, you should load your model with `device_map='balanced'` in the call to `from_pretrained`. You can also provide your own `device_map` but it needs to be a dictionary module_name to device, so for instance {'block.0': 0, 'block.1': 1, ...}T)r°  r±  r²  r(   rj   r  r¨  r¦  rs   r³  r´  r«  r'   rº  rª  r"  s     r8   rº  zT5EncoderModel.parallelizeâ  s”   € ä�‰ð"ô ô	
ð Ð!ô œ3˜tŸ|™|×1Ñ1Ó2´E¼%¿*¹*×:QÑ:QÓ:SÓ4TÔUàð 	Œô
 	˜$Ÿ/™/¬3¨t¯|©|×/AÑ/AÓ+BÔCØ�‰× Ñ  §¡Ô1Ø"ˆÕr—   c                 ó  — t        j                  dt        «       | j                  j	                  «        | j                  j                  d«      | _        d| _        d | _        t        j                  j                  «        y r$  )r°  r±  r²  r  r¾  rš   rª  r«  rs   r³  r½  rÁ  s    r8   r¾  zT5EncoderModel.deparallelizeô  sY   € ä�‰ØjÜô	
ð 	�‰×"Ñ"Ô$Ø—|‘|—‘ uÓ-ˆŒØ#ˆÔØˆŒÜ�
‰
×ÑÕ r—   c                 ó   — | j                   S rº   r&  rÁ  s    r8   rÂ  z#T5EncoderModel.get_input_embeddings   r'  r—   c                 óH   — || _         | j                  j                  |«       y rº   )r„  r  rÆ  rÄ  s     r8   rÆ  z#T5EncoderModel.set_input_embeddings  s   € Ø$ˆŒØ�‰×)Ñ)¨.Õ9r—   c                 ó’   — | j                   j                  r1| j                  | j                  j                  | j
                  «       y y rº   )rz   r†  r-  r  r¥  r„  rÁ  s    r8   r.  zT5EncoderModel._tie_weights  s2   € Ø�;‰;×*Ò*Ø×&Ñ& t§|¡|×'@Ñ'@À$Ç+Á+ÕNð +r—   c                 ó   — | j                   S rº   r1  rÁ  s    r8   r2  zT5EncoderModel.get_encoder  r3  r—   c                 ó²   — |j                  «       D ]D  \  }}| j                  j                  |   j                  d   j                  j                  |«       ŒF y)r8  r   N)r¸  r  r¨  rB   rD  rï   r:  s       r8   r<  zT5EncoderModel._prune_heads  sP   € ð
 +×0Ñ0Ó2ò 	P‰LˆE�5Ø�L‰L×Ñ˜uÑ%×+Ñ+¨AÑ.×<Ñ<×HÑHÈÕOñ	Pr—   r=  rs  rF  rà  rÊ  r,  rÔ  r]  rj  c           	      ój   — |�|n| j                   j                  }| j                  |||||||¬«      }|S )a3  
        Returns:

        Example:

        ```python
        >>> from transformers import AutoTokenizer, T5EncoderModel

        >>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
        >>> model = T5EncoderModel.from_pretrained("google-t5/t5-small")
        >>> input_ids = tokenizer(
        ...     "Studies have been shown that owning a dog is good for you", return_tensors="pt"
        ... ).input_ids  # Batch size 1
        >>> outputs = model(input_ids=input_ids)
        >>> last_hidden_states = outputs.last_hidden_state
        ```rC  )rz   rÕ  r  )	r“   rs  rF  rà  rÊ  r,  rÔ  r]  r@  s	            r8   r£   zT5EncoderModel.forward  sJ   € ð8 &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàŸ,™,ØØ)Ø'ØØ/Ø!5Ø#ð 'ó 
ˆð Ðr—   rº   )NNNNNNN)r¤   r¥   r¦   rN  rM  r*   r�   r    r  rº  r  r¾  rÂ  rÆ  r.  r2  r<  r!   ÚT5_ENCODER_INPUTS_DOCSTRINGr&   r   rP  r   rs   rQ  rR  r!  r   r   r£   r§   r¨   s   @r8   r‚  r‚  Ê  sN  ø„ ð
 8Ð8ÐØ*4¨Ð&ð˜xõ ñ  Ð/Ó0ò#ó 1ð#ñ" Ð1Ó2ñ	!ó 3ð	!òò:òOòòPñ +Ð+FÓGÙ¨?ÈÔYð 15Ø6:Ø15Ø59Ø,0Ø/3Ø&*ñ&à˜E×,Ñ,Ñ-ð&ð ! ×!2Ñ!2Ñ3ð&ð ˜E×-Ñ-Ñ.ð	&ð
   × 1Ñ 1Ñ2ð&ð $ D™>ð&ð ' t™nð&ð ˜d‘^ð&ð 
ˆu�U×&Ñ&Ñ'¨Ð8Ñ	9ò&ó Zó Hô&r—   r‚  zƒ
    T5 model with a sequence classification/head on top (a linear layer on top of the pooled output) e.g. for GLUE
    tasks.
    c            %       ó  ‡ — e Zd ZdgZddgZdefˆ fd„Z ee«       e	e
e¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     d	eej                     d
eej                     deej                     deej                     deej                     deeej"                        deej"                     deej"                     deej                     dee   dee   dee   dee   deee
f   f d„«       «       Zˆ xZS )ÚT5ForSequenceClassificationr  r  r  rz   c                 ó’   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        | j                  «        d| _        y r{  )rŽ   r�   r€  rp  rd  Úclassification_headr©  rª  r¸   s     €r8   r�   z$T5ForSequenceClassification.__init__L  s=   ø€ Ü‰Ñ˜Ô Ü" 6›?ˆÔÜ#7¸Ó#?ˆÔ ð 	�‰Ôà#ˆÕr—   r=  rs  rF  rr  rt  rà  r?  rá  r@  rÊ  rA  rc  r+  r,  rÔ  r]  rj  c                 ó  — |�|n| j                   j                  }|�d}|€$|	�"t        d| j                  j                  › �«      ‚|€ |
€|€t        d«      ‚| j                  |«      }| j                  |||||||||	|
||||¬«      }|d   }|j                  | j                   j                  «      j                  |j                  «      }t        t        j                  |j                  d«      «      «      dkD  rt        d«      ‚|j                   \  }}}||dd…f   j#                  |d	|«      dd…d	dd…f   }| j%                  |«      }d}|��Ê|j                  |j                  «      }| j                   j&                  €¡| j                   j(                  dk(  rd
| j                   _        nv| j                   j(                  dkD  rL|j*                  t        j,                  k(  s|j*                  t        j.                  k(  rd| j                   _        nd| j                   _        | j                   j&                  d
k(  rSt1        «       }| j                   j(                  dk(  r& ||j3                  «       |j3                  «       «      }n– |||«      }nŒ| j                   j&                  dk(  rGt5        «       } ||j#                  d	| j                   j(                  «      |j#                  d	«      «      }n,| j                   j&                  dk(  rt7        «       } |||«      }|s|f|dd z   }|�|f|z   S |S t9        |||j:                  |j<                  |j>                  |j@                  |jB                  |jD                  |jF                  ¬«	      S )aD  
        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 classification loss is computed (Cross-Entropy).
        Returns:
        NFz8Passing input embeddings is currently not supported for ú°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`.)rF  rr  rt  rà  r?  rá  r@  rÊ  rA  r+  r,  rÔ  r]  r   r)   z7All examples must have the same number of <eos> tokens.r<   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationrg  )$rz   rÕ  ÚNotImplementedErrorr–   r¤   rp   r–  rp  ÚeqÚeos_token_idrš   r  rj   rs   Úunique_consecutiveÚsumrn   r  rˆ  Úproblem_typerh  rž   rñ   rm   r
   Úsqueezer	   r   r   rÐ  rF  rG  rÒ  rH  rY  rI  )r“   rs  rF  rr  rt  rà  r?  rá  r@  rÊ  rA  rc  r+  r,  rÔ  r]  r;  rj  Úeos_maskr-  rê  r”   Úsentence_representationrO   rh  rl  rm  s                              r8   r£   z#T5ForSequenceClassification.forwardV  sQ  € ð4 &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆØÐØˆIàÐ Ð!:Ü%ØJÈ4Ï>É>×KbÑKbÐJcÐdóð ð Ð$Ð)>Ð)FØÐ Ü ðUóð ð
 !%× 1Ñ 1°)Ó <Ðà×"Ñ"ØØ)Ø/Ø#9ØØ/Ø!5Ø+Ø'Ø"7ØØ/Ø!5Ø#ð #ó 
ˆð  " !™*ˆà—<‘< §¡× 8Ñ 8Ó9×<Ñ<¸_×=SÑ=SÓTˆäŒu×'Ñ'¨¯©°Q«Ó8Ó9¸AÒ=ÜÐVÓWÐWØ%4×%:Ñ%:Ñ"ˆ
�A�{Ø"1°(ºA°+Ñ">×"CÑ"CÀJÐPRÐT_Ó"`ÒabÐdfÒhiÐaiÑ"jÐØ×)Ñ)Ð*AÓBˆàˆØÑØ—Y‘Y˜vŸ}™}Ó-ˆFØ�{‰{×'Ñ'Ð/Ø—;‘;×)Ñ)¨QÒ.Ø/;�D—K‘KÕ,Ø—[‘[×+Ñ+¨aÒ/°V·\±\ÄUÇZÁZÒ5OÐSY×S_ÑS_Ôch×clÑclÒSlØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—;‘;×)Ñ)¨QÒ.Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# F¨FÓ3‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù §¡¨B°·±×0FÑ0FÓ GÈÏÉÐUWËÓY‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨Ó/�ÙØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä.ØØØ#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r—   )NNNNNNNNNNNNNNN)r¤   r¥   r¦   rM  rN  r*   r�   r!   rO  r&   r   rP  r   rs   rQ  r¼   r   rR  r!  r   r   r£   r§   r¨   s   @r8   r†  r†  A  sÄ  ø„ ð +sÐ)sÐ&Ø7Ð9VÐWÐð$˜xõ $ñ +Ð+>Ó?ÙÐ+JÐYhÔið 15Ø15Ø8<Ø=AØ,0Ø48Ø7;Ø=AØ59Ø=AØ-1Ø$(Ø,0Ø/3Ø&*ñ!k
à˜E×,Ñ,Ñ-ðk
ð ! §¡Ñ.ðk
ð $ E×$4Ñ$4Ñ5ð	k
ð
 !)¨×)9Ñ)9Ñ :ðk
ð ˜EŸL™LÑ)ðk
ð $ E§L¡LÑ1ðk
ð ' u§|¡|Ñ4ðk
ð " $ u×'8Ñ'8Ñ"9Ñ:ðk
ð   × 1Ñ 1Ñ2ðk
ð  (¨×(9Ñ(9Ñ:ðk
ð ˜×)Ñ)Ñ*ðk
ð ˜D‘>ðk
ð $ D™>ðk
ð ' t™nðk
ð  ˜d‘^ð!k
ð" 
ˆuÐ5Ð5Ñ	6ò#k
ó jó @ôk
r—   r†  z©
    T5 Encoder Model with a token classification head on top (a linear layer on top of the hidden-states output)
    e.g. for Named-Entity-Recognition (NER) tasks.
    c                   óP  ‡ — e Zd ZdgZdefˆ fd„Z ee«       ee	e
¬«      	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     d	eej                     d
ee   dee   dee   deeej                     e	f   fd„«       «       Zˆ xZS )rˆ  z'transformer.encoder.embed_tokens.weightrz   c                 ó,  •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  «      | _        t        j                  |j                  |j                  «      | _        | j                  «        y rº   )rŽ   r�   rh  r‚  rp  r   r³   rg  rµ   r¯   r”   rM   r©  r¸   s     €r8   r�   z!T5ForTokenClassification.__init__Ð  sj   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä)¨&Ó1ˆÔÜ—z‘z &×";Ñ";Ó<ˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr—   r=  rs  rF  rà  rÊ  rc  r,  rÔ  r]  rj  c	           	      ó   — |�|n| j                   j                  }| j                  |||||||¬«      }	|	d   }
| j                  |
«      }
| j	                  |
«      }d}|�<t        «       } ||j                  d| j                  «      |j                  d«      «      }|s||	dd f}|�|f|z   S |S t        |||	j                  |	j                  ¬«      S )zì
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
        Returns:
        N)rF  rà  rÊ  r,  rÔ  r]  r   r<   rE   )rh  rO   r¡   rÑ  )rz   rÕ  rp  rµ   rM   r	   r  rh  r   r¡   rÑ  )r“   rs  rF  rà  rÊ  rc  r,  rÔ  r]  r;  r¡   rO   rh  rl  rm  s                  r8   r£   z T5ForTokenClassification.forwardÛ  sð   € ð$ &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà×"Ñ"ØØ)ØØ'Ø/Ø!5Ø#ð #ó 
ˆð   ™
ˆØŸ™ ]Ó3ˆØ—‘ Ó/ˆàˆØÐÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDáØ˜g a¨˜mÐ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r—   )NNNNNNNN)r¤   r¥   r¦   rN  r*   r�   r!   rO  r&   r   rP  r   rs   r¼   r!  r   r   r£   r§   r¨   s   @r8   rˆ  rˆ  Æ  s  ø„ ð DÐDÐð	˜xõ 	ñ +Ð+>Ó?ÙÐ+@ÈÔ_ð -1Ø15Ø,0Ø04Ø)-Ø,0Ø/3Ø&*ñ.
à˜EŸL™LÑ)ð.
ð ! §¡Ñ.ð.
ð ˜EŸL™LÑ)ð	.
ð
   §¡Ñ-ð.
ð ˜Ÿ™Ñ&ð.
ð $ D™>ð.
ð ' t™nð.
ð ˜d‘^ð.
ð 
ˆu�U—\‘\Ñ"Ð$9Ð9Ñ	:ò.
ó `ó @ô.
r—   rˆ  zÙ
    T5 Model with a span classification head on top for extractive question-answering tasks like SQuAD (linear layers
    on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c            '       ón  ‡ — e Zd ZdgZddgZdefˆ fd„Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Z ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej&                     deej(                     deej&                     deej*                     deej(                     deej(                     deej,                     deeeej,                           deej&                     deej&                     deej(                     deej(                     dee   dee   dee   dee   deeej(                     ef   f"d„«       «       Zˆ xZS )rƒ  r  r  r  rz   c                 óz  •— t         ‰| �  |«       |j                  | _        t	        j
                  |j                  |j                  «      | _        t        j                  |«      }d|_
        d|_        d|_        t        || j                  «      | _        t        j                  |«      }d|_
        d|_        |j                  |_        t        || j                  «      | _        |j$                  | _        t	        j&                  |j(                  |j$                  «      | _        | j-                  «        d| _        y r  )rŽ   r�   r°   rV  r   rã   r  r„  r  r  rÕ   r+  r  r£  r  r  r§  rN   rh  r¯   r”   r|  r©  rª  r  s       €r8   r�   zT5ForQuestionAnswering.__init__	  sì   ø€ Ü‰Ñ˜Ô ØŸ™ˆŒä—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ$)ˆÔ!Ø#(ˆÔ Ø,1ˆÔ)Ü˜~¨t¯{©{Ó;ˆŒäŸ™ vÓ.ˆØ$(ˆÔ!Ø,1ˆÔ)Ø$*×$=Ñ$=ˆÔ!Ü˜~¨t¯{©{Ó;ˆŒà ×+Ñ+ˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Ôà#ˆÕr—   c                 ó   — | j                   S rº   r&  rÁ  s    r8   rÂ  z+T5ForQuestionAnswering.get_input_embeddings3	  r'  r—   c                 ó~   — || _         | j                  j                  |«       | j                  j                  |«       y rº   r)  rÄ  s     r8   rÆ  z+T5ForQuestionAnswering.set_input_embeddings6	  r*  r—   c                 óò   — | j                   j                  ra| j                  | j                  j                  | j
                  «       | j                  | j                  j                  | j
                  «       y y rº   r,  rÁ  s    r8   r.  z#T5ForQuestionAnswering._tie_weights;	  r/  r—   c                 ó   — | j                   S rº   r1  rÁ  s    r8   r2  z"T5ForQuestionAnswering.get_encoder@	  r3  r—   c                 ó   — | j                   S rº   r5  rÁ  s    r8   r6  z"T5ForQuestionAnswering.get_decoderC	  r3  r—   r=  rs  rF  rr  rt  rà  r?  rá  r@  Ústart_positionsÚend_positionsrÊ  rA  r+  r,  rÔ  r]  rj  c                 óf  — |�|n| j                   j                  }|�|n| j                   j                  }|	�|
�d}|€ |€|€t        d«      ‚| j	                  |«      }|�|n| j                   j                  }|�|n| j                   j                  }|�O|€M| j                   j
                  | j                   j                  k(  r t        j                  t        t        «       |}|€| j                  |||||||¬«      }nI|rGt        |t        «      s7t        |d   t        |«      dkD  r|d   ndt        |«      dkD  r|d   nd¬«      }|d   }| j                  |||d||||||||¬	«      }|d   }| j!                  |«      }|j#                  dd
¬«      \  }}|j%                  d
«      j'                  «       }|j%                  d
«      j'                  «       }d}|	�é|
�çt        |	j)                  «       «      dkD  r*|	j%                  d
«      j+                  |j,                  «      }	t        |
j)                  «       «      dkD  r*|
j%                  d
«      j+                  |j,                  «      }
|j)                  d«      }|	j/                  d|«      }	|
j/                  d|«      }
t1        |¬«      } |||	«      } |||
«      }||z   dz  }|s||f|dd z   |z   }|�|f|z   S |S t3        ||||j4                  |j6                  |j8                  |j:                  |j<                  |j6                  |j8                  ¬«
      S )a  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (*sequence_length*). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (*sequence_length*). Position outside of the sequence
            are not taken into account for computing the loss.
        Returns:
        NFrŠ  rC  r   r)   rE   rD  )rs  rF  rÊ  rÐ  rY  rZ  rà  rá  r+  r,  rÔ  r]  r<   rê   re  )
rh  Ústart_logitsÚ
end_logitsrÐ  rF  rG  rÒ  rH  rY  rI  )rz   rÕ  r+  rp   r–  r§  r  r°  r±  Ú._T5ForQuestionAnswering__HEAD_MASK_WARNING_MSGr²  r  r»   r   rj   rN   r|  rc   r”  r%  rÖ  rš   r  rX  r	   r   rÐ  r¡   rÑ  rÒ  rÏ  )r“   rs  rF  rr  rt  rà  r?  rá  r@  r¡  r¢  rÊ  rA  r+  r,  rÔ  r]  r¡   rK  rj  rO   r¤  r¥  Ú
total_lossÚignored_indexrl  Ú
start_lossÚend_lossrm  s                                r8   r£   zT5ForQuestionAnswering.forwardF	  sx  € ð@ &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆØ!*Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	ØÐ&¨=Ð+DØˆIð
 Ð$Ð)>Ð)FØÐ Ü ðUóð ð
 !%× 1Ñ 1°)Ó <Ðà!*Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð Ð%6Ð%>Ø�{‰{×%Ñ%¨¯©×)GÑ)GÒGÜ—‘Ô5´}ÔEØ$-Ð!ð Ð"Ø"Ÿl™lØ#Ø-Ø+Ø#Ø"3Ø%9Ø'ð +ó ‰Oñ ¤¨O¼_Ô!MÜ-Ø"1°!Ñ"4Ü47¸Ó4HÈ1Ò4L˜o¨aÒ0ÐRVÜ14°_Ó1EÈÒ1I˜?¨1Ò-ÈtôˆOð (¨Ñ*ˆð Ÿ,™,Ø'Ø1Ø/Ø Ø"/Ø#1Ø'Ø!5ØØ/Ø!5Ø#ð 'ó 
ˆð *¨!Ñ,ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ó#:Ñ ˆ�jØ#×+Ñ+¨BÓ/×:Ñ:Ó<ˆØ×'Ñ'¨Ó+×6Ñ6Ó8ˆ
àˆ
ØÐ&¨=Ð+Dä�?×'Ñ'Ó)Ó*¨QÒ.Ø"1×"9Ñ"9¸"Ó"=×"@Ñ"@À×ATÑATÓ"U�Ü�=×%Ñ%Ó'Ó(¨1Ò,Ø -× 5Ñ 5°bÓ 9× <Ñ <¸Z×=NÑ=NÓ O�à(×-Ñ-¨aÓ0ˆMØ-×3Ñ3°A°}ÓEˆOØ)×/Ñ/°°=ÓAˆMä'°]ÔCˆHÙ! ,°Ó@ˆJÙ 
¨MÓ:ˆHØ$ xÑ/°1Ñ4ˆJáØ" JÐ/°/À!À"Ð2EÑEÈÑWˆFØ/9Ð/E�Z�M FÑ*ÐQÈ6ÐQä2ØØ%Ø!Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô
ð 	
r—   rL  )r¤   r¥   r¦   rM  rN  r*   r�   rÂ  rÆ  r.  r2  r6  r!   rO  r&   r   rP  r   rs   rQ  rR  rS  r¼   r   r!  r   r£   r§   r¨   s   @r8   rƒ  rƒ  	  s  ø„ ð +sÐ)sÐ&Ø7Ð9VÐWÐð$˜xõ $ò4ò:ò
Oò
òñ +Ð+>Ó?ÙÐ+NÐ]lÔmð 15Ø6:Ø8<Ø=AØ15Ø9=Ø7;Ø@DØ6:Ø48Ø59Ø=AØ$(Ø,0Ø/3Ø&*ñ#C
à˜E×,Ñ,Ñ-ðC
ð ! ×!2Ñ!2Ñ3ðC
ð $ E×$4Ñ$4Ñ5ð	C
ð
 !)¨×)9Ñ)9Ñ :ðC
ð ˜E×-Ñ-Ñ.ðC
ð $ E×$5Ñ$5Ñ6ðC
ð ' u§|¡|Ñ4ðC
ð " %¨¨e¯l©lÑ(;Ñ"<Ñ=ðC
ð " %×"2Ñ"2Ñ3ðC
ð   × 0Ñ 0Ñ1ðC
ð   × 1Ñ 1Ñ2ðC
ð  (¨×(9Ñ(9Ñ:ðC
ð ˜D‘>ðC
ð $ D™>ðC
ð  ' t™nð!C
ð" ˜d‘^ð#C
ð$ 
ˆu�U×&Ñ&Ñ'Ð)LÐLÑ	Mò%C
ó nó @ôC
r—   rƒ  )r‚  r�  r€  ro  rŠ   rƒ  r†  rˆ  )brm  r  r÷   r[   r°  Útypingr   r   r   r   rs   r   Útorch.nnr   r	   r
   Úactivationsr   Úcache_utilsr   r   r   r   Ú
generationr   Úmodeling_attn_mask_utilsr   Úmodeling_outputsr   r   r   r   r   r   r   Úmodeling_utilsr   Úpytorch_utilsr   r   r   Úutilsr   r   r    r!   r"   r#   r$   r%   r&   Úutils.model_parallel_utilsr'   r(   Úconfiguration_t5r*   Ú!torch.nn.attention.flex_attentionr+   Úintegrations.flex_attentionr,   Ú
get_loggerr¤   rY   rP  Ú_CHECKPOINT_FOR_DOCrŠ   r  r  ÚModulerŒ   Úapex.normalizationr©   r^   rX   Ú	Exceptionrq  rb   r«   rÁ   rÉ   rÒ   rA  rK  rQ  rd  ro  r£  ÚT5_START_DOCSTRINGrO  r„  Ú__HEAD_MASK_WARNING_MSGr€  r�  r‚  r†  rˆ  rƒ  Ú__all__r5   r—   r8   ú<module>rÁ     sö  ðñ ã Û Û 	Û ß /Ó /ã Ý ß AÑ Aå !ß PÓ PÝ )Ý >÷÷ ñ õ .ß gÑ g÷
÷ 
õ 
÷ LÝ &ñ  Ô!Ý;åJð 
ˆ×	Ñ	˜HÓ	%€à€Ø*Ð òfð\ Ð ðBÐ ô(+�"—)‘)ô +ð2	Ý/à€Kà
‡K�KÐaÔbð Ð × Ñ ˜KÔ (ô�b—i‘iô ô,˜2Ÿ9™9ô ô:�—	‘	ô ô$a�"—)‘)ô aôH!˜2Ÿ9™9ô !ôH#˜BŸI™Iô #ôLaˆb�i‰iô aôH˜2Ÿ9™9ô ô$r!˜ô r!ôj}Ðô }ð@Ð ð*^Ð ð@#Ð ðLÐ ñ ØbØóôK
Ðó K
ó	ðK
ñ\ ÐLÐN`ÓaôY&Ð!2°Oó Y&ó bðY&ñx ØlØóôpÐ&ó pó	ðpñf ðð óô{
Ð"3ó {
óð{
ñ| ðð óô>
Ð0ó >
óð>
ñB ðð óôv
Ð.ó v
óðv
òr	�øð}E ò 	âØò 	Ø
‡N�NÐWÔXÚð	ús   ÃI ÉI?É&I?É>I?