Ë
    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' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6  e-«       rddl7m8Z8 ddl9m:Z:  e0jv                  e<«      Z=dZ>dZ?dZ@dZA G d„ dej„                  «      ZC G d„ dej„                  «      ZD G d„ dej„                  «      ZE G d„ dej„                  «      ZF G d „ d!ej„                  «      ZG G d"„ d#ej„                  «      ZH G d$„ d%ej„                  «      ZI G d&„ d'ej„                  «      ZJd(„ ZK G d)„ d*ej„                  «      ZL G d+„ d,e$«      ZM G d-„ d.eM«      ZNd/ZOd0ZPd1ZQd2ZR e+d3eO«       G d4„ d5eM«      «       ZS e+d6eO«       G d7„ d8eMe«      «       ZT e+d9eO«       G d:„ d;eM«      «       ZU e+d<eO«       G d=„ d>eM«      «       ZV e+d?eO«       G d@„ dAeM«      «       ZW e+dBeO«       G dC„ dDeM«      «       ZXg dE¢ZYy)FzPyTorch mT5 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)Ú 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é   )Ú	MT5Config)Ú	BlockMask)Úmake_flex_block_causal_maskr)   z	mt5-smalla  
    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 mt5 models have the
            following number of attention modules:

                - mt5-small: 6
                - mt5-base: 12
                - mt5-large: 24
                - mt5-xl: 24
                - mt5-xxl: 24

    Example:

    ```python
    # Here is an example of a device map on a machine with 4 GPUs using mt5-xl, which has a total of 24 attention modules:
    model = MT5ForConditionalGeneration.from_pretrained("mt5-xl")
    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)
    ```
a#  
    Moves the model to cpu from a model parallel state.

    Example:

    ```python
    # On a 4 GPU machine with mt5-xl:
    model = MT5ForConditionalGeneration.from_pretrained("Mt5-xl")
    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 )ÚMT5LayerNormc                 óŠ   •— t         ‰| �  «        t        j                  t	        j
                  |«      «      | _        || _        y)zd
        Construct a layernorm module in the MT5 style. No bias and no subtraction of mean.
        N)ÚsuperÚ__init__r   Ú	ParameterÚtorchÚonesÚweightÚvariance_epsilon)ÚselfÚhidden_sizeÚepsÚ	__class__s      €úb/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/mt5/modeling_mt5.pyr0   zMT5LayerNorm.__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 )Né   éÿÿÿÿT)Úkeepdim)Útor2   Úfloat32ÚpowÚmeanÚrsqrtr5   r4   ÚdtypeÚfloat16Úbfloat16)r6   Úhidden_statesÚvariances      r:   ÚforwardzMT5LayerNorm.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__r0   rJ   Ú__classcell__©r9   s   @r:   r-   r-      s   ø„ õ$ö+r;   r-   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )ÚMT5DenseActDenseÚconfigc                 ó^  •— t         ‰| �  «        t        j                  |j                  |j
                  d¬«      | _        t        j                  |j
                  |j                  d¬«      | _        t        j                  |j                  «      | _
        t        |j                     | _        y ©NF©Úbias)r/   r0   r   ÚLinearÚd_modelÚd_ffÚwiÚwoÚDropoutÚdropout_rateÚdropoutr   Údense_act_fnÚact©r6   rR   r9   s     €r:   r0   zMT5DenseActDense.__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)rZ   r`   r^   Ú
isinstancer[   r4   r2   ÚTensorrE   Úint8r@   ©r6   rH   s     r:   rJ   zMT5DenseActDense.forward¡   sª   € ØŸ™ Ó.ˆØŸ™ Ó/ˆØŸ™ ]Ó3ˆä�t—w‘w—~‘~¤u§|¡|Ô4Ø×#Ñ# t§w¡w§~¡~×';Ñ';Ò;Ø—‘—‘×$Ñ$¬¯
©
Ò2à)×,Ñ,¨T¯W©W¯^©^×-AÑ-AÓBˆMØŸ™ Ó.ˆØÐr;   ©rK   rL   rM   r)   r0   rJ   rN   rO   s   @r:   rQ   rQ   ™   s   ø„ ð/˜yõ /ör;   rQ   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )ÚMT5DenseGatedActDenserR   c                 óÀ  •— t         ‰| �  «        t        j                  |j                  |j
                  d¬«      | _        t        j                  |j                  |j
                  d¬«      | _        t        j                  |j
                  |j                  d¬«      | _        t        j                  |j                  «      | _        t        |j                     | _        y rT   )r/   r0   r   rW   rX   rY   Úwi_0Úwi_1r[   r\   r]   r^   r   r_   r`   ra   s     €r:   r0   zMT5DenseGatedActDense.__init__±   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 rc   )r`   rl   rm   r^   rd   r[   r4   r2   re   rE   rf   r@   )r6   rH   Úhidden_geluÚhidden_linears       r:   rJ   zMT5DenseGatedActDense.forward¹   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;   rh   rO   s   @r:   rj   rj   °   s   ø„ ð/˜yõ /ör;   rj   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )Ú
MT5LayerFFrR   c                 ó  •— t         ‰| �  «        |j                  rt        |«      | _        nt        |«      | _        t        |j                  |j                  ¬«      | _	        t        j                  |j                  «      | _        y )N©r8   )r/   r0   Úis_gated_actrj   ÚDenseReluDenserQ   r-   rX   Úlayer_norm_epsilonÚ
layer_normr   r\   r]   r^   ra   s     €r:   r0   zMT5LayerFF.__init__Ï   s_   ø€ Ü‰ÑÔØ×ÒÜ"7¸Ó"?ˆDÕä"2°6Ó":ˆDÔä& v§~¡~¸6×;TÑ;TÔUˆŒÜ—z‘z &×"5Ñ"5Ó6ˆ�r;   c                 ór   — | j                  |«      }| j                  |«      }|| j                  |«      z   }|S rc   )rx   rv   r^   )r6   rH   Úforwarded_statess      r:   rJ   zMT5LayerFF.forwardÙ   s=   € ØŸ?™?¨=Ó9ÐØ×.Ñ.Ð/?Ó@ÐØ%¨¯©Ð5EÓ(FÑFˆØÐr;   rh   rO   s   @r:   rr   rr   Î   s   ø„ ð7˜yõ 7ör;   rr   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 )ÚMT5AttentionrR   Ú	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.FrU   )r/   r0   Ú
is_decoderÚhas_relative_attention_biasÚrelative_attention_num_bucketsÚrelative_attention_max_distancerX   Úd_kvÚkey_value_proj_dimÚ	num_headsÚn_headsr]   r^   Ú	inner_dimr}   ÚloggerÚwarning_oncer9   rK   r   rW   ÚqÚkÚvÚoÚ	EmbeddingÚrelative_attention_biasÚsetÚpruned_headsÚgradient_checkpointing©r6   rR   r€   r}   r9   s       €r:   r0   zMT5Attention.__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)Úlenr   r†   r„   r‘   r   rŠ   r‹   rŒ   r�   r‡   Úunion)r6   ÚheadsÚindexs      r:   Úprune_headszMT5Attention.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   r=   r(   )r@   r2   Ú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           r:   Ú_relative_position_bucketz&MT5Attention._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)rE   Údevice)r§   r¨   r©   )r=   r   r(   r   )r�   r4   r°   r2   Úaranger�   r@   r®   r   r�   r‚   ÚpermuteÚ	unsqueeze)
r6   Úquery_lengthÚ
key_lengthr°   Úcache_positionÚcontext_positionÚmemory_positionr¦   Úrelative_position_bucketÚvaluess
             r:   Úcompute_biaszMT5Attention.compute_biasE  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).
        Nr=   r>   r(   r¶   Tr   éþÿÿÿ©r°   rE   )r°   r¶   r   r•   )ÚpÚtraining)'ÚshaperŠ   Úviewr†   r„   Ú	transposeÚ
is_updatedÚgetr}   Úcross_attention_cacheÚself_attention_cacheÚ	key_cacheÚvalue_cacher‹   rŒ   Úupdater2   Úmatmulr€   Úzerosr°   rE   r’   rÀ   Úrequires_gradr»   r‘   r3   ÚlistÚboolr   Ú
functionalÚsoftmaxr¢   Útype_asr^   Ú
contiguousr‡   r�   )r6   rH   Ú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                               r:   rJ   zMT5Attention.forwardY  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)rK   rL   rM   r)   r   Úintr0   r›   Ústaticmethodr®   r»   rJ   rN   rO   s   @r:   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 )ÚMT5LayerSelfAttentionr}   c                 óÜ   •— t         ‰| �  «        t        |||¬«      | _        t	        |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        y )N©r€   r}   rt   )r/   r0   r|   ÚSelfAttentionr-   rX   rw   rx   r   r\   r]   r^   r“   s       €r:   r0   zMT5LayerSelfAttention.__init__Ç  sT   ø€ Ü‰ÑÔÜ)ØÐ0KÐW`ô
ˆÔô ' v§~¡~¸6×;TÑ;TÔUˆŒÜ—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(   )rx   ró   r^   )r6   rH   Úattention_maskrÖ   rØ   r×   rÙ   rÚ   r¶   Únormed_hidden_statesÚattention_outputré   s               r:   rJ   zMT5LayerSelfAttention.forwardÏ  sv   € ð  $Ÿ™¨}Ó=ÐØ×-Ñ-Ø ØØ'Ø+Ø)ØØ/Ø)ð .ó 	
Ðð &¨¯©Ð5EÀaÑ5HÓ(IÑIˆØ Ð"Ð%5°a°bÐ%9Ñ9ˆØˆr;   rê   )NNNNFFN©rK   rL   rM   r   rí   r0   rJ   rN   rO   s   @r:   rð   rð   Æ  s0   ø„ ñ7ÈXÐVYÉ]õ 7ð ØØØØØØ÷r;   rð   c                   óD   ‡ — e Zd Zddee   fˆ fd„Z	 	 	 	 	 	 	 	 dd„Zˆ xZS )ÚMT5LayerCrossAttentionr}   c                 óÜ   •— t         ‰| �  «        t        |d|¬«      | _        t	        |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        y )NFrò   rt   )r/   r0   r|   ÚEncDecAttentionr-   rX   rw   rx   r   r\   r]   r^   )r6   rR   r}   r9   s      €r:   r0   zMT5LayerCrossAttention.__init__ì  sO   ø€ Ü‰ÑÔÜ+¨FÐPUÐajÔkˆÔÜ& v§~¡~¸6×;TÑ;TÔUˆŒÜ—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(   )rx   rü   r^   )r6   rH   rÕ   rõ   rÖ   rØ   r×   rÙ   r´   rÚ   r¶   rö   r÷   Úlayer_outputré   s                  r:   rJ   zMT5LayerCrossAttention.forwardò  s{   € ð  $Ÿ™¨}Ó=ÐØ×/Ñ/Ø ØØ-Ø'Ø+Ø)ØØ%Ø/Ø)ð 0ó 
Ðð % t§|¡|Ð4DÀQÑ4GÓ'HÑHˆØ�/Ð$4°Q°RÐ$8Ñ8ˆØˆr;   rc   )NNNNFNFNrø   rO   s   @r:   rú   rú   ë  s2   ø„ ñ7¨(°3©-õ 7ð ØØØØØØØ÷r;   rú   c                   óL   ‡ — e Zd Zddee   fˆ fd„Z	 	 	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )ÚMT5Blockr}   c                 óp  •— t         ‰| �  «        |j                  | _        t        j                  «       | _        | j
                  j                  t        |||¬«      «       | j                  r&| j
                  j                  t        ||¬«      «       | j
                  j                  t        |«      «       y )Nrò   )r}   )
r/   r0   r   r   Ú
ModuleListÚlayerÚappendrð   rú   rr   r“   s       €r:   r0   zMT5Block.__init__  s‚   ø€ Ü‰ÑÔØ ×+Ñ+ˆŒÜ—]‘]“_ˆŒ
Ø�
‰
×ÑÜ! &ÐFaÐmvÔwô	
ð �?Š?Ø�J‰J×ÑÔ4°VÀyÔQÔRà�
‰
×Ñœ* VÓ,Õ-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   )rõ   rÖ   rØ   r×   rÙ   rÚ   r¶   r=   iè  )rŸ   Úmaxr(   r>   )rÕ   rõ   rÖ   rØ   r×   r´   rÙ   rÚ   )r  rE   r2   rF   r¥   ÚisinfÚanyÚfinfor  Úclampr   )r6   rH   rõ   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                       r:   rJ   zMT5Block.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ê   )NNNNNNNNFFTNrø   rO   s   @r:   r   r     s@   ø„ ñ
.ÈXÐVYÉ]õ 
.ð ØØ"Ø#Ø&*ØØ#'ØØØØØ÷Tr;   r   c           	      ó¢	  — 	 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 �]A  }|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                  k(  s"J d'|j2                  › d(|j2                  › d)�«       ‚	 t        j                  d*|
› �«       t;        j<                  |j?                  |j@                  «      «      |_!        |	j#                  |d«       �ŒD t        j                  d+d,j!                  |	jE                  «       «      › d-�«       | S # t        $ r t        j                  d«       ‚ w xY w# t.        $ r+ t        j                  d	dj!                  |
«      › �«       Y �Œ(w xY w# t6        $ r1}|xj8                  |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     r:   ú	<genexpr>z)load_tf_weights_in_mt5.<locals>.<genexpr>“  s   è ø€ ò 
àð ÐnÔnñ
ùó   ‚z	Skipping Ú_slot_r>   z[A-Za-z]+_\d+z_(\d+))ÚkernelÚscaleÚ	embeddingr4   Úself_attentionr  Úenc_dec_attentionr(   Údense_relu_denser=   Úrms_normrx   Úfinal_layer_normr$  Úoutput_biasÚbetarV   ÚsquadÚ
classifierÚdecoderÚlogitsÚlm_headrZ   Ú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ÚImportErrorrˆ   ÚerrorÚosÚpathÚabspathÚinfoÚtrainÚlist_variablesÚload_variabler  Úsplitr  ÚjoinÚpopÚ	fullmatchÚgetattrÚhasattrr—   ÚisdigitÚAttributeErrorrí   rÁ   rÃ   ÚAssertionErrorÚargsr2   Ú
from_numpyÚastyperA   ÚdataÚkeys)ÚmodelrR   Útf_checkpoint_pathr5  ÚnpÚtfÚtf_pathÚ	init_varsÚnamesÚ
tf_weightsÚnamerÁ   ÚarrayÚtxt_nameÚpointerÚm_nameÚscope_namesÚnumÚes                      r:   Úload_tf_weights_in_mt5r_  v  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Òð	!ð ó K'ˆØ�~‰~˜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ð	Ø—=‘= E§K¡KÒ/ð Ø  §¡ Ð/@ÀÇÁÀÈ[ÐYóÑ/ô 	�‰Ð0°°Ð7Ô8Ü×'Ñ'¨¯©°R·Z±ZÓ(@ÓAˆŒØ�‰�x Ö&ðWK'ôZ ‡K�KÐ7¸¿	¹	À*Ç/Á/ÓBSÓ8TÐ7UÐUVÐWÔXØ€LøôA ò Ü�‰ð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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 )ÚMT5ClassificationHeadz-Head for sentence-level classification tasks.rR   c                 ó(  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  |j                  ¬«      | _        t        j                  |j                  |j                  «      | _
        y )N)r¿   )r/   r0   r   rW   rX   Údenser\   Úclassifier_dropoutr^   Ú
num_labelsÚout_projra   s     €r:   r0   zMT5ClassificationHead.__init__ä  sZ   ø€ Ü‰ÑÔÜ—Y‘Y˜vŸ~™~¨v¯~©~Ó>ˆŒ
Ü—z‘z F×$=Ñ$=Ô>ˆŒÜŸ	™	 &§.¡.°&×2CÑ2CÓDˆ�r;   rH   Úreturnc                 ó¸   — | j                  |«      }| j                  |«      }t        j                  |«      }| j                  |«      }| j	                  |«      }|S rc   )r^   rc  r2   Útanhrf  rg   s     r:   rJ   zMT5ClassificationHead.forwardê  sN   € ØŸ™ ]Ó3ˆØŸ
™
 =Ó1ˆÜŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ mÓ4ˆØÐr;   )
rK   rL   rM   Ú__doc__r)   r0   r2   re   rJ   rN   rO   s   @r:   ra  ra  á  s/   ø„ Ù7ðE˜yõ Eð U§\¡\ð °e·l±l÷ r;   ra  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
)ÚMT5PreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚtransformerTFr   r[   c                 óv   — t        j                  t        «      }t        j                  t        «      }|||dœ}|S )N)Údecoder_input_idsÚ	input_idsÚdecoder_attention_mask)r2   Útensorr   r   )r6   rp  Ú
input_maskÚdummy_inputss       r:   rt  zMT5PreTrainedModel.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ç      ð?ç        )rC   Ústdr1  Ú
qa_outputsç      à¿r.  rV   N))rR   Úinitializer_factorrd   r-   r4   rM  Úfill_ÚMT5ModelÚMT5ForConditionalGenerationÚMT5EncoderModelÚMT5ForQuestionAnsweringÚsharedÚnormal_rF  Útie_word_embeddingsr1  ry  rX   rV   Úzero_ÚMT5ForTokenClassificationr.  ra  rc  rf  rQ   rZ   r[   rY   rj   rl   rm   r|   rƒ   r…   rŠ   r‹   rŒ   r�   r€   r�   )r6   ÚmoduleÚfactorrX   r„   r†   s         r:   Ú_init_weightsz MT5PreTrainedModel._init_weights  s  € à—‘×/Ñ/ˆÜ�fœlÔ+Ø�M‰M×Ñ×$Ñ$ V¨c¡\Õ2ÜØÜÔ2´OÔE\Ð]õ
ð �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ð -ô ˜Ô 9Ô:Ü�v˜|Ô,Ø×!Ñ!×(Ñ(×-Ñ-×5Ñ5¸3ÀFÈSÁLÐ5ÔQØ×!Ñ!×&Ñ&×+Ñ+×1Ñ1Õ3ð -ô ˜Ô 5Õ6Ø�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Õ1ð �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Ð)ä˜Ô 5Õ6Ø�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 MT5 it is usually set to the pad_token_id. See MT5 docs for more information.r>   )r(   .r•   r(   ).r   z1self.model.config.pad_token_id has to be defined.éœÿÿÿ)rR   Údecoder_start_token_idÚpad_token_idÚ
ValueErrorr"   r2   ÚfullrÁ   ÚcatÚ	new_zerosÚcloneÚmasked_fill_)r6   rp  r‹  rŒ  Úshifted_input_idss        r:   Ú_shift_rightzMT5PreTrainedModel._shift_rightM  sÿ   € Ø!%§¡×!CÑ!CÐØ—{‘{×/Ñ/ˆà!Ð)Üð5óð ô ˜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)rK   rL   rM   rj  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Úpropertyrt  rˆ  r”  r  r;   r:   rl  rl  ô  se   „ ñð
 €LØ,€OØ%ÐØÐØ&*Ð#Ø %ÐØ!ÐØ ÐØ#˜ÐØ!˜FÐàñó ðò;oóz!r;   rl  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 )ÚMT5Stackc                 óâ  •— 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   rò   rt   F)r/   r0   Úembed_tokensr   r   r  ÚrangeÚ
num_layersr   rÏ   Úblockr-   rX   rw   r*  r\   r]   r^   Ú	post_initÚmodel_parallelÚ
device_mapr’   )r6   rR   r£  Úir9   s       €r:   r0   zMT5Stack.__init__k  s¼   ø€ Ü‰Ñ˜Ô à(ˆÔØ ×+Ñ+ˆŒä—]‘]Ü^cÐdj×duÑduÓ^vÖwÐYZŒX�f¼$¸qÀA¹v»,ÐRSÖTÒwó
ˆŒ
ô !-¨V¯^©^À×AZÑAZÔ [ˆÔÜ—z‘z &×"5Ñ"5Ó6ˆŒð 	�‰Ôà#ˆÔØˆŒØ&+ˆÕ#ùò x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=  `MT5Stack.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'   r—   r¦  r¤  r2   ÚcudaÚdevice_countr©  r&   r¨  rN  ÚstrrŸ   Úfirst_devicer  Úlast_deviceÚitemsr@   r£  r*  )r6   r©  r‹   rŒ   r  Úcuda_devices         r:   ÚparallelizezMT5Stack.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¤  r—   r¦  r@   r£  r*  r2   r±  Úempty_cache)r6   rª  s     r:   ÚdeparallelizezMT5Stack.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 rc   ©r£  ©r6   s    r:   Úget_input_embeddingszMT5Stack.get_input_embeddingsª  s   € Ø× Ñ Ð r;   c                 ó   — || _         y rc   r¾  ©r6   Únew_embeddingss     r:   Úset_input_embeddingszMT5Stack.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°   )rE   rv  r¾   r  )rõ   rÖ   r  r  r  rØ   r  r×   rÙ   rÚ   r  r¶   r(   rc   r=   é   r   é   r­  c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wrc   r  )r  rŒ   s     r:   r   z#MT5Stack.forward.<locals>.<genexpr>”  s   è ø€ ò 
àð �=ô ñ
ùr!  )Úlast_hidden_stateÚpast_key_valuesrH   Ú
attentionsÚcross_attentions)4r¨  r2   r±  Ú
set_devicer´  r£  r@   rR   rÙ   rÚ   Úoutput_hidden_statesÚuse_return_dictr   r�  ÚsizerÂ   r’   rÀ   rˆ   r‰   rd   r   r   r   Úfrom_legacy_cacheÚget_seq_lengthr±   r°   r#   r3   Ú_update_causal_maskrÇ   rE   r	  rŸ   r�   Úinvert_attention_maskÚget_head_maskr¥  r^   Ú	enumerater¦  Ú_gradient_checkpointing_funcrJ   r©  r¶  r³  rµ  r*  Úto_legacy_cacheÚtupler   )+r6   rp  rõ   r  r  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_lengthrå   Úencoder_batch_sizeÚencoder_sequence_lengthÚ_Úencoder_hidden_shapeÚencoder_extended_attention_maskÚall_hidden_statesÚall_attentionsÚall_cross_attentionsrÖ   r  rH   rª  Úlayer_modulerØ   r  Úlayer_outputsÚnext_decoder_cacher‹   rŒ   Ú
next_caches+                                              r:   rJ   zMT5Stack.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;   rõ   Ú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_2rw  Úflex_attentionr   Úsdpa)rÈ  rä  Úis_trainingr(   r>   )Úsequence_lengthÚtarget_lengthrE   r°   r¶   rÛ   )r±  Úxpu)rR   Ú_attn_implementationr  rd   r2   re   r+   r*   rÖ  r   r   Ú_ignore_causal_mask_sdparÀ   rE   r°   rÁ   Úget_max_cache_shapeÚ5_prepare_4d_causal_attention_mask_with_cache_positionÚtyper	  rŸ   Ú_unmask_unattended)r6   rõ   rò  r¶   rÎ  rÚ   Úpast_seen_tokensÚusing_static_cacherE   r°   rø  rù  rå   Ú	min_dtypes                 r:   r×  zMT5Stack._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ù  rE   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_valuerE   r°   r(   )ÚdiagonalrÉ  r>   r   )r–   r2   r	  rŸ   rŽ  Útriur±   ÚreshapeÚexpandr‘  rÁ   r@   r°   Úmasked_fill)rõ   rø  rù  rE   r°   r¶   rÛ   Úkwargsrå   r  Úmask_lengthÚpadding_masks               r:   rþ  z>MT5Stack._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;   rc   )NNNNNNNNNNNNN)F)rK   rL   rM   r0   r   ÚPARALLELIZE_DOCSTRINGr¸  ÚDEPARALLELIZE_DOCSTRINGr¼  rÀ  rÄ  rJ   r2   re   r   rÏ   r×  rî   rí   rE   r°   rþ  rN   rO   s   @r:   r¡  r¡  j  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 MT5 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 ([`MT5Config`]): 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.
ab  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. MT5 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 [MT5 Training](./mt5#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)

            MT5 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 [MT5
            Training](./mt5#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.
a�  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. MT5 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 [MT5 Training](./mt5#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 MT5 Model transformer outputting raw hidden-states without any specific head on top.c            '       óÀ  ‡ — e Zd ZdZdZe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 ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#deej6                     deej8                     deej6                     deej:                     deej8                     deej8                     deej<                     deeeej8                           deeeej8                           deej<                     deej<                     dee    dee    dee    dee    deej6                     d e!eej8                     ef   f"d!„«       «       Z"ˆ xZ#S )$r}  aw  
    Examples:

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

    >>> model = MT5Model.from_pretrained("google/mt5-small")
    >>> tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
    >>> article = "UN Offizier sagt, dass weiter verhandelt werden muss in Syrien."
    >>> summary = "Weiter Verhandlung in Syrien."
    >>> inputs = tokenizer(article, return_tensors="pt")
    >>> labels = tokenizer(text_target=summary, return_tensors="pt")

    >>> outputs = model(input_ids=inputs["input_ids"], decoder_input_ids=labels["input_ids"])
    >>> hidden_states = outputs.last_hidden_state
    ```Úmt5úFdecoder.block.0.layer.1.EncDecAttention.relative_attention_bias.weightúencoder.embed_tokens.weightúdecoder.embed_tokens.weightrR   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/   r0   r   rŽ   Ú
vocab_sizerX   r�  ÚcopyÚdeepcopyr   rÙ   Úis_encoder_decoderr¡  ÚencoderÚnum_decoder_layersr¥  r/  r§  r¨  r©  ©r6   rR   Úencoder_configÚdecoder_configr9   s       €r:   r0   zMT5Model.__init__æ  s¿   ø€ Ü‰Ñ˜Ô Ü—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ$)ˆÔ!Ø#(ˆÔ Ø,1ˆÔ)Ü °·±Ó<ˆŒäŸ™ vÓ.ˆØ$(ˆÔ!Ø,1ˆÔ)Ø$*×$=Ñ$=ˆÔ!Ü °·±Ó<ˆŒð 	�‰Ôð $ˆÔØˆ�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'   r—   r  r¦  r¤  r2   r±  r²  r©  r&   r¸  r/  r¨  ©r6   r©  s     r:   r¸  zMT5Model.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¼  r/  r@   r¨  r©  r2   r±  r»  r¿  s    r:   r¼  zMT5Model.deparallelize  s   € ô 	�‰ØjÜô	
ð 	�‰×"Ñ"Ô$Ø�‰×"Ñ"Ô$Ø—|‘|—‘ uÓ-ˆŒØ—|‘|—‘ uÓ-ˆŒØ#ˆÔØˆŒÜ�
‰
×ÑÕ r;   c                 ó   — | j                   S rc   ©r�  r¿  s    r:   rÀ  zMT5Model.get_input_embeddings!  ó   € Ø�{‰{Ðr;   c                 ó~   — || _         | j                  j                  |«       | j                  j                  |«       y rc   ©r�  r  rÄ  r/  rÂ  s     r:   rÄ  zMT5Model.set_input_embeddings%  ó-   € Ø$ˆŒØ�‰×)Ñ)¨.Ô9Ø�‰×)Ñ)¨.Õ9r;   c                 ó   — | j                   S rc   ©r  r¿  s    r:   Úget_encoderzMT5Model.get_encoder+  ó   € Ø�|‰|Ðr;   c                 ó   — | j                   S rc   ©r/  r¿  s    r:   Úget_decoderzMT5Model.get_decoder/  r-  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  r  Ú	attentionr›   ©r6   Úheads_to_pruner  r™   s       r:   Ú_prune_headszMT5Model._prune_heads3  sE   € ð
 +×0Ñ0Ó2ò 	C‰LˆE�5Ø�L‰L×Ñ˜uÑ%×/Ñ/×;Ñ;¸EÕBñ	Cr;   ©Úoutput_typer•  rp  rõ   ro  rq  rÞ  Údecoder_head_maskrß  Úencoder_outputsrÎ  rÈ  Údecoder_inputs_embedsrÙ   rÚ   rÒ  r  r¶   rg  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, MT5Model

        >>> tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
        >>> model = MT5Model.from_pretrained("google/mt5-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 MT5Model.
        >>> # This is not needed for torch's MT5ForConditionalGeneration 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©rp  rõ   rÈ  rÞ  rÚ   rÒ  r  r   r(   r=   ©rÍ  rH   rÏ  ©rp  rõ   rÈ  rÎ  r  r  rÞ  rß  rÙ   rÚ   rÒ  r  r¶   )rÍ  rÎ  Údecoder_hidden_statesÚdecoder_attentionsrÐ  Úencoder_last_hidden_stater  Úencoder_attentions)rR   rÙ   rÓ  r¥  r  r®  r¯  Ú _MT5Model__HEAD_MASK_WARNING_MSGr°  r  rd   r   r—   r¨  r2   r±  rÑ  r/  r´  r@   r   rÍ  rÎ  rH   rÏ  rÐ  )r6   rp  rõ   ro  rq  rÞ  r9  rß  r:  rÎ  rÈ  r;  rÙ   rÚ   rÒ  r  r¶   rH   Údecoder_outputss                      r:   rJ   zMT5Model.forward;  s=  € ð\ "+Ð!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;   rc   ©NNNNNNNNNNNNNNNN)$rK   rL   rM   rj  Ú
model_typer)   r•  Ú"_keys_to_ignore_on_load_unexpectedÚ_tied_weights_keysr0   r   r  r¸  r  r¼  rÀ  rÄ  r,  r0  r6  r    ÚMT5_INPUTS_DOCSTRINGr%   r   Ú_CONFIG_FOR_DOCr   r2   Ú
LongTensorÚFloatTensorÚ
BoolTensorre   r   rÏ   r   rJ   rN   rO   s   @r:   r}  r}  Ê  sT  ø„ ñ
ð" €JØ€LØ*rÐ)sÐ&Ø7Ð9VÐWÐð˜yõ ñ. Ð/Ó0ò#ó 1ð#ñ$ Ð1Ó2ñ!ó 3ð!òò:òòò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
ó ]ó Aôp
r;   r}  z1MT5 Model with a `language modeling` head on top.c            )       ó  ‡ — e Zd ZdZdZe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 ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d&deej8                     deej:                     deej8                     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 e ej>                           deej:                     deej:                     deej8                     dee!   dee!   dee!   dee!   d eej8                     d!e"e ej:                     ef   f$d"„«       «       Z#dej>                  fd#„Z$d$„ Z%ˆ xZ&S )'r~  a  
    Examples:

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

    >>> model = MT5ForConditionalGeneration.from_pretrained("google/mt5-small")
    >>> tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
    >>> article = "UN Offizier sagt, dass weiter verhandelt werden muss in Syrien."
    >>> summary = "Weiter Verhandlung in Syrien."
    >>> inputs = tokenizer(article, text_target=summary, return_tensors="pt")

    >>> outputs = model(**inputs)
    >>> loss = outputs.loss
    ```r  r  )r  r  zlm_head.weightrR   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 )NFTrU   )r/   r0   rX   Ú	model_dimr   rŽ   r  r�  r  r  r   rÙ   r  r¡  r  r  r¥  r/  rW   r1  r§  r¨  r©  r  s       €r:   r0   z$MT5ForConditionalGeneration.__init__É  sè   ø€ Ü‰Ñ˜Ô ØŸ™ˆŒä—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ$)ˆÔ!Ø#(ˆÔ Ø,1ˆÔ)Ü °·±Ó<ˆŒäŸ™ vÓ.ˆØ$(ˆÔ!Ø,1ˆÔ)Ø$*×$=Ñ$=ˆÔ!Ü °·±Ó<ˆŒä—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'   r—   r  r¦  r¤  r2   r±  r²  r©  r&   r¸  r/  r1  r@   r´  r¨  r!  s     r:   r¸  z'MT5ForConditionalGeneration.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¼  r/  r@   r1  r¨  r©  r2   r±  r»  r¿  s    r:   r¼  z)MT5ForConditionalGeneration.deparallelizeù  s“   € ô 	�‰ØjÜô	
ð 	�‰×"Ñ"Ô$Ø�‰×"Ñ"Ô$Ø—|‘|—‘ uÓ-ˆŒØ—|‘|—‘ uÓ-ˆŒØ—|‘|—‘ uÓ-ˆŒØ#ˆÔØˆŒÜ�
‰
×ÑÕ r;   c                 ó   — | j                   S rc   r%  r¿  s    r:   rÀ  z0MT5ForConditionalGeneration.get_input_embeddings
  r&  r;   c                 ó~   — || _         | j                  j                  |«       | j                  j                  |«       y rc   r(  rÂ  s     r:   rÄ  z0MT5ForConditionalGeneration.set_input_embeddings  r)  r;   c                 ó   — || _         y rc   ©r1  rÂ  s     r:   Úset_output_embeddingsz1MT5ForConditionalGeneration.set_output_embeddings  s	   € Ø%ˆ�r;   c                 ó   — | j                   S rc   rW  r¿  s    r:   Úget_output_embeddingsz1MT5ForConditionalGeneration.get_output_embeddings  r-  r;   c                 ó   — | j                   S rc   r+  r¿  s    r:   r,  z'MT5ForConditionalGeneration.get_encoder  r-  r;   c                 ó   — | j                   S rc   r/  r¿  s    r:   r0  z'MT5ForConditionalGeneration.get_decoder   r-  r;   r7  rp  rõ   ro  rq  rÞ  r9  rß  r:  rÎ  rÈ  r;  ÚlabelsrÙ   rÚ   rÒ  r  r¶   rg  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, MT5ForConditionalGeneration

        >>> tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
        >>> model = MT5ForConditionalGeneration.from_pretrained("google/mt5-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.
        ```Nr=  r   r(   r=   r>  r?  rz  rŠ  ©Úignore_indexr>   ©	Úlossr0  rÎ  r@  rA  rÐ  rB  r  rC  )#rR   rÙ   rÓ  r¥  r  r®  r¯  Ú3_MT5ForConditionalGeneration__HEAD_MASK_WARNING_MSGr°  r  rd   r   r—   r¨  r2   r±  rÑ  r/  r´  r”  r@   r1  r4   r°   rƒ  rQ  r	   rÂ   rÔ  r   rÎ  rH   rÏ  rÐ  rÍ  )r6   rp  rõ   ro  rq  rÞ  r9  rß  r:  rÎ  rÈ  r;  r]  rÙ   rÚ   rÒ  r  r¶   rH   rE  Úsequence_outputÚ	lm_logitsrb  Úloss_fctÚoutputs                            r:   rJ   z#MT5ForConditionalGeneration.forward#  s™  € ðl "+Ð!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 rc   )r”  )r6   r]  s     r:   Ú%prepare_decoder_input_ids_from_labelszAMT5ForConditionalGeneration.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 decodingr  r   z%reordered_layer_past_states[0] shape z  and layer_past_states[0] shape r3  z&length of reordered_layer_past_states z! and length of layer_past_states )rˆ   ÚwarningÚindex_selectr@   r°   rÁ   r�  r—   )r6   rÎ  Úbeam_idxÚreordered_decoder_pastÚlayer_past_statesÚreordered_layer_past_statesÚlayer_past_states          r:   Ú_reorder_cachez*MT5ForConditionalGeneration._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;   rc   )NNNNNNNNNNNNNNNNN)'rK   rL   rM   rj  rG  r)   r•  rH  rI  r0   r   r  r¸  r  r¼  rÀ  rÄ  rX  rZ  r,  r0  r    rJ  r%   r   rK  r   r2   rL  rM  rN  re   r   rÏ   r   rJ   ri  rr  rN   rO   s   @r:   r~  r~  ±  s  ø„ ñð  €JØ€LØ*rÐ)sÐ&ÚiÐð˜yõ ñ6 Ð/Ó0ò#ó 1ð#ñ& Ð1Ó2ñ!ó 3ð!òò:ò&òòòñ +Ð+?Ó@Ù¨?ÈÔ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ó AðY
ðx)¸E¿L¹Ló )ö&r;   r~  zgThe bare MT5 Model transformer outputting encoder's raw hidden-states without any specific head on top.c                   óŽ  ‡ — e Zd ZdZdZe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 ee«       eee¬«      	 	 	 	 	 	 	 ddeej2                     deej4                     deej4                     deej4                     dee   dee   dee   deeej4                     ef   fd„«       «       Zˆ xZS )r  aÞ  
    Examples:

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

    >>> model = MT5EncoderModel.from_pretrained("google/mt5-small")
    >>> tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
    >>> article = "UN Offizier sagt, dass weiter verhandelt werden muss in Syrien."
    >>> input_ids = tokenizer(article, return_tensors="pt").input_ids
    >>> outputs = model(input_ids)
    >>> hidden_state = outputs.last_hidden_state
    ```r  r  rR   c                 ó:  •— t         ‰| �  |«       t        j                  |j                  |j
                  «      | _        t        j                  |«      }d|_	        d|_
        t        || j                  «      | _        | j                  «        d| _        d | _        y ©NF)r/   r0   r   rŽ   r  rX   r�  r  r  rÙ   r  r¡  r  r§  r¨  r©  )r6   rR   r  r9   s      €r:   r0   zMT5EncoderModel.__init__ý  sy   ø€ Ü‰Ñ˜Ô Ü—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ#(ˆÔ Ø,1ˆÔ)Ü °·±Ó<ˆŒð 	�‰Ôð $ˆÔØˆ�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'   r—   r  r¦  r¤  r2   r±  r²  r©  r&   r¸  r¨  r!  s     r:   r¸  zMT5EncoderModel.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©  r2   r±  r»  r¿  s    r:   r¼  zMT5EncoderModel.deparallelize   s[   € ô 	�‰ØjÜô	
ð 	�‰×"Ñ"Ô$Ø—|‘|—‘ uÓ-ˆŒØ#ˆÔØˆŒÜ�
‰
×ÑÕ r;   c                 ó   — | j                   S rc   r%  r¿  s    r:   rÀ  z$MT5EncoderModel.get_input_embeddings.  r&  r;   c                 óH   — || _         | j                  j                  |«       y rc   )r�  r  rÄ  rÂ  s     r:   rÄ  z$MT5EncoderModel.set_input_embeddings2  s   € Ø$ˆŒØ�‰×)Ñ)¨.Õ9r;   c                 ó   — | j                   S rc   r+  r¿  s    r:   r,  zMT5EncoderModel.get_encoder7  r-  r;   c                 ó²   — |j                  «       D ]D  \  }}| j                  j                  |   j                  d   j                  j                  |«       ŒF y)r2  r   N)r¶  r  r¦  r  ró   r›   r4  s       r:   r6  zMT5EncoderModel._prune_heads;  sP   € ð
 +×0Ñ0Ó2ò 	P‰LˆE�5Ø�L‰L×Ñ˜uÑ%×+Ñ+¨AÑ.×<Ñ<×HÑHÈÕOñ	Pr;   r7  rp  rõ   rÞ  rÈ  rÚ   rÒ  r  rg  c           	      ój   — |�|n| j                   j                  }| j                  |||||||¬«      }|S )a1  
        Returns:

        Example:

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

        >>> tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
        >>> model = MT5EncoderModel.from_pretrained("google/mt5-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
        ```r=  )rR   rÓ  r  )	r6   rp  rõ   rÞ  rÈ  rÚ   rÒ  r  r:  s	            r:   rJ   zMT5EncoderModel.forwardC  sJ   € ð: &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàŸ,™,ØØ)Ø'ØØ/Ø!5Ø#ð 'ó 
ˆð Ðr;   rc   )NNNNNNN) rK   rL   rM   rj  rG  r)   r•  rI  r0   r   r  r¸  r  r¼  rÀ  rÄ  r,  r6  r    ÚMT5_ENCODER_INPUTS_DOCSTRINGr%   r   rK  r   r2   rL  rM  rÏ   r   r   rJ   rN   rO   s   @r:   r  r  å  sO  ø„ ñ
ð €JØ€LØ7Ð8Ðð˜yõ ñ  Ð/Ó0ò#ó 1ð#ñ" Ð1Ó2ñ	!ó 3ð	!òò:ò
òPñ +Ð+GÓHÙ¨?ÈÔYð 15Ø6:Ø15Ø59Ø,0Ø/3Ø&*ñ&à˜E×,Ñ,Ñ-ð&ð ! ×!2Ñ!2Ñ3ð&ð ˜E×-Ñ-Ñ.ð	&ð
   × 1Ñ 1Ñ2ð&ð $ D™>ð&ð ' t™nð&ð ˜d‘^ð&ð 
ˆu�U×&Ñ&Ñ'¨Ð8Ñ	9ò&ó Zó Iô&r;   r  z„
    MT5 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 )ÚMT5ForSequenceClassificationr  r  r  rR   c                 ó’   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        | j                  «        d| _        y ru  )r/   r0   r}  rm  ra  Úclassification_headr§  r¨  ra   s     €r:   r0   z%MT5ForSequenceClassification.__init__{  s>   ø€ Ü‰Ñ˜Ô Ü# FÓ+ˆÔÜ#8¸Ó#@ˆÔ ð 	�‰Ôà#ˆÕr;   r7  rp  rõ   ro  rq  rÞ  r9  rß  r:  rÈ  r;  r]  rÙ   rÚ   rÒ  r  rg  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`.)rõ   ro  rq  rÞ  r9  rß  r:  rÈ  r;  rÙ   rÚ   rÒ  r  r   r(   z7All examples must have the same number of <eos> tokens.r>   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationra  )$rR   rÓ  ÚNotImplementedErrorr9   rK   r�  r”  rm  ÚeqÚeos_token_idr@   r°   r—   r2   Úunique_consecutiveÚsumrÁ   rÂ   r�  Úproblem_typere  rE   r�   rí   r
   Úsqueezer	   r   r   rÎ  r@  rA  rÐ  rB  r  rC  )r6   rp  rõ   ro  rq  rÞ  r9  rß  r:  rÈ  r;  r]  rÙ   rÚ   rÒ  r  ré   rd  Úeos_maskrÛ   rè  r7   Úsentence_representationr0  rb  rf  rg  s                              r:   rJ   z$MT5ForSequenceClassification.forward…  sQ  € ð6 &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)rK   rL   rM   rH  rI  r)   r0   r    rJ  r%   r   rK  r   r2   rL  re   r   rM  rÏ   r   r   rJ   rN   rO   s   @r:   r  r  o  sÄ  ø„ ð +sÐ)sÐ&Ø7Ð9VÐWÐð$˜yõ $ñ +Ð+?Ó@ÙÐ+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ó Aôk
r;   r  zª
    MT5 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.weightrR   c                 ó,  •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  «      | _        t        j                  |j                  |j                  «      | _        | j                  «        y rc   )r/   r0   re  r  rm  r   r\   rd  r^   rW   r7   r.  r§  ra   s     €r:   r0   z"MT5ForTokenClassification.__init__	  sj   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä*¨6Ó2ˆÔÜ—z‘z &×";Ñ";Ó<ˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr;   r7  rp  rõ   rÞ  rÈ  r]  rÚ   rÒ  r  rg  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)rõ   rÞ  rÈ  rÚ   rÒ  r  r   r>   r=   )rb  r0  rH   rÏ  )rR   rÓ  rm  r^   r.  r	   rÂ   re  r   rH   rÏ  )r6   rp  rõ   rÞ  rÈ  r]  rÚ   rÒ  r  ré   rH   r0  rb  rf  rg  s                  r:   rJ   z!MT5ForTokenClassification.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)rK   rL   rM   rI  r)   r0   r    rJ  r%   r   rK  r   r2   re   rÏ   r   r   rJ   rN   rO   s   @r:   r…  r…  ö  s  ø„ ð DÐDÐð	˜yõ 	ñ +Ð+?Ó@ÙÐ+@ÈÔ_ð -1Ø15Ø,0Ø04Ø)-Ø,0Ø/3Ø&*ñ.
à˜EŸL™LÑ)ð.
ð ! §¡Ñ.ð.
ð ˜EŸL™LÑ)ð	.
ð
   §¡Ñ-ð.
ð ˜Ÿ™Ñ&ð.
ð $ D™>ð.
ð ' t™nð.
ð ˜d‘^ð.
ð 
ˆu�U—\‘\Ñ"Ð$9Ð9Ñ	:ò.
ó `ó Aô.
r;   r…  zÚ
    MT5 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            '       óh  ‡ — 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
 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  rR   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/   r0   rX   rQ  r   rŽ   r  r�  r  r  r   rÙ   r  r¡  r  r  r¥  r/  re  rW   r7   ry  r§  r¨  r  s       €r:   r0   z MT5ForQuestionAnswering.__init__L	  sì   ø€ Ü‰Ñ˜Ô ØŸ™ˆŒä—l‘l 6×#4Ñ#4°f·n±nÓEˆŒäŸ™ vÓ.ˆØ$)ˆÔ!Ø#(ˆÔ Ø,1ˆÔ)Ü °·±Ó<ˆŒäŸ™ vÓ.ˆØ$(ˆÔ!Ø,1ˆÔ)Ø$*×$=Ñ$=ˆÔ!Ü °·±Ó<ˆŒà ×+Ñ+ˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Ôà#ˆÕr;   c                 ó   — | j                   S rc   r%  r¿  s    r:   rÀ  z,MT5ForQuestionAnswering.get_input_embeddingsg	  r&  r;   c                 ó~   — || _         | j                  j                  |«       | j                  j                  |«       y rc   r(  rÂ  s     r:   rÄ  z,MT5ForQuestionAnswering.set_input_embeddingsk	  r)  r;   c                 ó   — | j                   S rc   r+  r¿  s    r:   r,  z#MT5ForQuestionAnswering.get_encoderq	  r-  r;   c                 ó   — | j                   S rc   r/  r¿  s    r:   r0  z#MT5ForQuestionAnswering.get_decoderu	  r-  r;   r7  rp  rõ   ro  rq  rÞ  r9  rß  r:  Ústart_positionsÚend_positionsrÈ  r;  rÙ   rÚ   rÒ  r  rg  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ƒ  r=  r   r(   r=   r>  )rp  rõ   rÈ  rÎ  r  r  rÞ  rß  rÙ   rÚ   rÒ  r  r>   r•   r_  )
rb  Ústart_logitsÚ
end_logitsrÎ  r@  rA  rÐ  rB  r  rC  )rR   rÓ  rÙ   r�  r”  r¥  r  r®  r¯  Ú/_MT5ForQuestionAnswering__HEAD_MASK_WARNING_MSGr°  r  rd   r   r—   r/  ry  rA  r�  rÓ   rÔ  r@   r°   r
  r	   r   rÎ  rH   rÏ  rÐ  rÍ  )r6   rp  rõ   ro  rq  rÞ  r9  rß  r:  r™  rš  rÈ  r;  rÙ   rÚ   rÒ  r  rH   rE  rd  r0  rœ  r�  Ú
total_lossÚignored_indexrf  Ú
start_lossÚend_lossrg  s                                r:   rJ   zMT5ForQuestionAnswering.forwardx	  sx  € ðB &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;   rF  )rK   rL   rM   rH  rI  r)   r0   rÀ  rÄ  r,  r0  r    rJ  r%   r   rK  r   r2   rL  rM  rN  re   r   rÏ   r   rJ   rN   rO   s   @r:   r€  r€  @	  s  ø„ ð +sÐ)sÐ&Ø7Ð9VÐWÐð$˜yõ $ò6ò:òòñ +Ð+?Ó@ÙÐ+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ó AôC
r;   r€  )r  r~  r€  r  r…  r}  rl  r¡  )Zrj  r  r£   r:  r®  Útypingr   r   r   r   r2   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   Úutilsr   r   r   r    r!   r"   r#   r$   r%   Úutils.model_parallel_utilsr&   r'   Úconfiguration_mt5r)   Ú!torch.nn.attention.flex_attentionr*   Úintegrations.flex_attentionr+   Ú
get_loggerrK   rˆ   rK  Ú_CHECKPOINT_FOR_DOCr  r  ÚModuler-   rQ   rj   rr   r|   rð   rú   r   r_  ra  rl  r¡  ÚMT5_START_DOCSTRINGrJ  r}  Ú__HEAD_MASK_WARNING_MSGr}  r~  r  r  r…  r€  Ú__all__r  r;   r:   ú<module>r·     s™  ðñ ã Û Û 	Û ß /Ó /ã Ý ß AÑ Aå !ß PÓ PÝ )Ý >÷÷ ñ õ .ß Q÷
÷ 
õ 
÷ LÝ (ñ  Ô!Ý;åJà	ˆ×	Ñ	˜HÓ	%€à€Ø!Ð ð Ð ðBÐ ô*+�2—9‘9ô +ô4�r—y‘yô ô.˜BŸI™Iô ô<�—‘ô ô&a�2—9‘9ô aôJ!˜BŸI™Iô !ôJ#˜RŸY™Yô #ôNaˆr�y‰yô aòHgôV˜BŸI™Iô ô&r!˜ô r!ôl}Ð!ô }ð@Ð ð*[Ð ðz# Ð ðLÐ ñ ØcØóô`
Ð!ó `
ó	ð`
ñF ÐMÐObÓcôp&Ð"4°oó p&ó dðp&ñf	 ØmØóôCÐ(ó Có	ðCñL ðð óô}
Ð#5ó }
óð}
ñ@ ðð óô@
Ð 2ó @
óð@
ñF ðð óôw
Ð0ó w
óðw
òt	�r;   