Ë
    T^(h"" ã                   ó  — d Z ddlZddlmZmZmZ ddlmZ ddl	Z	ddl
mZ ddlZddlmZmZmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ d
dlmZmZm Z m!Z!m"Z" d
dl#m$Z$m%Z%m&Z&m'Z'm(Z( d
dl)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/  e,j`                  e1«      Z2dZ3dZ4ejj                  Z5dejl                  de7de7dejl                  fd„Z8 G d„ dejr                  «      Z: G d„ dejr                  «      Z; G d„ dejr                  «      Z< G d„ dejr                  «      Z= G d„ d ejr                  «      Z> G d!„ d"ejr                  «      Z? G d#„ d$ejr                  «      Z@ G d%„ d&ejr                  «      ZA G d'„ d(ejr                  «      ZB G d)„ d*ejr                  «      ZC G d+„ d,ejr                  «      ZDd-ZEd.ZFd/ZG G d0„ d1e%«      ZHd2ZI e*d3eI«       G d4„ d5ejr                  «      «       ZJ G d6„ d7eH«      ZK e&eKe3e"e4«       d8ZL e(eKeGeLz   «        e'eKe!e4¬9«        e*d:eI«       G d;„ d<ejr                  «      «       ZM G d=„ d>eH«      ZN e*d?eI«       G d@„ dAejr                  «      «       ZO G dB„ dCeH«      ZPdDZQ e(ePeGeQz   «        e'ePe!e4¬9«       g dE¢ZRy)FzFlax T5 model.é    N)ÚCallableÚOptionalÚTuple)Ú
FrozenDictÚfreezeÚunfreeze)Úcombine_masksÚmake_causal_mask)Úpartitioning)Údot_product_attention_weights)Úflatten_dictÚunflatten_dict)ÚPRNGKeyé   )ÚFlaxBaseModelOutputÚ-FlaxBaseModelOutputWithPastAndCrossAttentionsÚ%FlaxCausalLMOutputWithCrossAttentionsÚFlaxSeq2SeqLMOutputÚFlaxSeq2SeqModelOutput)ÚACT2FNÚFlaxPreTrainedModelÚappend_call_sample_docstringÚ append_replace_return_docstringsÚoverwrite_call_docstring)Úadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚT5Configzgoogle-t5/t5-smallr    Ú	input_idsÚpad_token_idÚdecoder_start_token_idÚreturnc                 ó  — t        j                  | «      }|j                  dd…dd…f   j                  | dd…dd…f   «      }|j                  dd…df   j                  |«      }t        j                  |dk(  ||«      }|S )z1
    Shift input ids one token to the right.
    Nr   éÿÿÿÿr   iœÿÿÿ)ÚjnpÚ
zeros_likeÚatÚsetÚwhere)r!   r"   r#   Úshifted_input_idss       úe/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/t5/modeling_flax_t5.pyÚshift_tokens_rightr.   :   sƒ   € ô Ÿ™ yÓ1ÐØ)×,Ñ,ªQ°±¨UÑ3×7Ñ7¸	Â!ÀSÀbÀSÀ&Ñ8IÓJÐØ)×,Ñ,ªQ°¨TÑ2×6Ñ6Ð7MÓNÐäŸ	™	Ð"3°tÑ";¸\ÐK\Ó]ÐØÐó    c                   óÐ   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   e
j                  j                  j                  Zedej"                  f   ed<   d„ Zd„ Zy	)
ÚFlaxT5LayerNormÚhidden_sizeÚdtypeg�íµ ÷Æ°>Úeps.Úweight_initc                 ó^   — | j                  d| j                  | j                  f«      | _        y )NÚweight)Úparamr5   r2   r7   ©Úselfs    r-   ÚsetupzFlaxT5LayerNorm.setupL   s%   € Ø—j‘j ¨4×+;Ñ+;¸d×>NÑ>NÐ=PÓQˆ�r/   c                 óÖ   — t        j                  |j                  d«      d«      j                  dd¬«      }|t        j                  || j
                  z   «      z  }| j                  |z  S )zc
        Construct a layernorm module in the T5 style; No bias and no subtraction of mean.
        Úf4é   r&   T)ÚaxisÚkeepdims)r'   ÚpowerÚastypeÚmeanÚsqrtr4   r7   )r:   Úhidden_statesÚvariances      r-   Ú__call__zFlaxT5LayerNorm.__call__O   s[   € ô
 —9‘9˜]×1Ñ1°$Ó7¸Ó;×@Ñ@ÀbÐSWÐ@ÓXˆØ%¬¯©°¸D¿H¹HÑ1DÓ(EÑEˆà�{‰{˜]Ñ*Ð*r/   N)Ú__name__Ú
__module__Ú__qualname__ÚintÚ__annotations__r'   Úfloat32r3   r4   ÚfloatÚjaxÚnnÚinitializersÚonesr5   r   ÚnpÚndarrayr;   rG   © r/   r-   r1   r1   F   sV   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø€CˆÓØ-0¯V©V×-@Ñ-@×-EÑ-E€K�˜#˜rŸz™z˜/Ñ*ÓEòRó+r/   r1   c                   ó\   — e Zd ZU eed<   ej                  Zej                  ed<   d„ Zdd„Z	y)ÚFlaxT5DenseActDenseÚconfigr3   c                 óð  — | j                   j                  | j                   j                  dz  z  }| j                   j                  | j                   j                  dz  z  }t	        j
                  | j                   j                  dt        j                  j                  j                  |«      | j                  ¬«      | _
        t	        j
                  | j                   j                  dt        j                  j                  j                  |«      | j                  ¬«      | _        t	        j                  | j                   j                  «      | _        t        | j                   j                      | _        y ©Nç      à¿F©Úuse_biasÚkernel_initr3   )rX   Úinitializer_factorÚd_modelÚd_ffrP   ÚDenserO   rQ   Únormalr3   ÚwiÚwoÚDropoutÚdropout_rateÚdropoutr   Údense_act_fnÚact©r:   Úwi_init_stdÚwo_init_stds      r-   r;   zFlaxT5DenseActDense.setup^   sú   € Ø—k‘k×4Ñ4¸¿¹×8KÑ8KÈTÑ8QÑRˆØ—k‘k×4Ñ4¸¿¹×8HÑ8HÈ$Ñ8NÑOˆä—(‘(Ø�K‰K×ÑØÜŸ™×+Ñ+×2Ñ2°;Ó?Ø—*‘*ô	
ˆŒô —(‘(Ø�K‰K×ÑØÜŸ™×+Ñ+×2Ñ2°;Ó?Ø—*‘*ô	
ˆŒô —z‘z $§+¡+×":Ñ":Ó;ˆŒÜ˜$Ÿ+™+×2Ñ2Ñ3ˆ�r/   c                 ó’   — | j                  |«      }| j                  |«      }| j                  ||¬«      }| j                  |«      }|S ©N©Údeterministic)rd   rj   rh   re   )r:   rE   rq   s      r-   rG   zFlaxT5DenseActDense.__call__q   sD   € ØŸ™ Ó.ˆØŸ™ Ó/ˆØŸ™ ]À-˜ÓPˆØŸ™ Ó.ˆØÐr/   N©T©
rH   rI   rJ   r    rL   r'   rM   r3   r;   rG   rU   r/   r-   rW   rW   Z   s$   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò4ô&r/   rW   c                   óZ   — e Zd ZU eed<   ej                  Zej                  ed<   d„ Zd„ Z	y)ÚFlaxT5DenseGatedActDenserX   r3   c                 ó¶  — | j                   j                  | j                   j                  dz  z  }| j                   j                  | j                   j                  dz  z  }t	        j
                  | j                   j                  dt        j                  j                  j                  |«      | j                  ¬«      | _
        t	        j
                  | j                   j                  dt        j                  j                  j                  |«      | j                  ¬«      | _        t	        j
                  | j                   j                  dt        j                  j                  j                  |«      | j                  ¬«      | _        t	        j                  | j                   j                  «      | _        t         | j                   j"                     | _        y rZ   )rX   r_   r`   ra   rP   rb   rO   rQ   rc   r3   Úwi_0Úwi_1re   rf   rg   rh   r   ri   rj   rk   s      r-   r;   zFlaxT5DenseGatedActDense.setup}   s;  € Ø—k‘k×4Ñ4¸¿¹×8KÑ8KÈTÑ8QÑRˆØ—k‘k×4Ñ4¸¿¹×8HÑ8HÈ$Ñ8NÑOˆä—H‘HØ�K‰K×ÑØÜŸ™×+Ñ+×2Ñ2°;Ó?Ø—*‘*ô	
ˆŒ	ô —H‘HØ�K‰K×ÑØÜŸ™×+Ñ+×2Ñ2°;Ó?Ø—*‘*ô	
ˆŒ	ô —(‘(Ø�K‰K×ÑØÜŸ™×+Ñ+×2Ñ2°;Ó?Ø—*‘*ô	
ˆŒô —z‘z $§+¡+×":Ñ":Ó;ˆŒÜ˜$Ÿ+™+×2Ñ2Ñ3ˆ�r/   c                 óº   — | j                  | j                  |«      «      }| j                  |«      }||z  }| j                  ||¬«      }| j	                  |«      }|S ro   )rj   rw   rx   rh   re   )r:   rE   rq   Úhidden_geluÚhidden_linears        r-   rG   z!FlaxT5DenseGatedActDense.__call__–   sW   € Ø—h‘h˜tŸy™y¨Ó7Ó8ˆØŸ	™	 -Ó0ˆØ# mÑ3ˆØŸ™ ]À-˜ÓPˆØŸ™ Ó.ˆØÐr/   Nrs   rU   r/   r-   ru   ru   y   s$   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò4ó2r/   ru   c                   ó\   — e Zd ZU eed<   ej                  Zej                  ed<   d„ Zdd„Z	y)ÚFlaxT5LayerFFrX   r3   c                 ó°  — | j                   j                  r't        | j                   | j                  ¬«      | _        n&t        | j                   | j                  ¬«      | _        t        | j                   j                  | j                   j                  | j                  ¬«      | _	        t        j                  | j                   j                  «      | _        y )N©r3   ©r4   r3   )rX   Úis_gated_actru   r3   ÚDenseReluDenserW   r1   r`   Úlayer_norm_epsilonÚ
layer_normrP   rf   rg   rh   r9   s    r-   r;   zFlaxT5LayerFF.setup£   s‚   € Ø�;‰;×#Ò#Ü":¸4¿;¹;ÈdÏjÉjÔ"YˆDÕä"5°d·k±kÈÏÉÔ"TˆDÔä)¨$¯+©+×*=Ñ*=À4Ç;Á;×CaÑCaÐim×isÑisÔtˆŒÜ—z‘z $§+¡+×":Ñ":Ó;ˆ�r/   c                 óz   — | j                  |«      }| j                  ||¬«      }|| j                  ||¬«      z   }|S ro   )r„   r‚   rh   )r:   rE   rq   Úforwarded_statess       r-   rG   zFlaxT5LayerFF.__call__¬   sG   € ØŸ?™?¨=Ó9ÐØ×.Ñ.Ð/?È}Ð.Ó]ÐØ%¨¯©Ð5EÐUb¨Ó(cÑcˆØÐr/   Nrr   rs   rU   r/   r-   r}   r}   Ÿ   s$   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò<ôr/   r}   c                   óÔ   — e Zd ZU eed<   dZeed<   dZeed<   ej                  Z
ej                  ed<   d„ Zedd„«       Zd„ Zd	„ Zd
„ Zej$                  d„ «       Zd„ Z	 	 	 	 	 	 	 dd„Zy)ÚFlaxT5AttentionrX   FÚhas_relative_attention_biasÚcausalr3   c                 ó*  — | j                   j                  | _        | j                   j                  | _        | j                   j                  | _        | j                   j                  | _        | j                   j                  | _        | j                   j                  | _	        | j                  | j
                  z  | _
        | j                   j                  | j                  | j
                  z  dz  z  }| j                   j                  | j                  dz  z  }| j                   j                  | j                  dz  z  }t        j                  | j                  dt        j                  j                  j!                  |«      | j"                  ¬«      | _        t        j                  | j                  dt        j                  j                  j!                  |«      | j"                  ¬«      | _        t        j                  | j                  dt        j                  j                  j!                  |«      | j"                  ¬«      | _        t        j                  | j                  dt        j                  j                  j!                  |«      | j"                  ¬«      | _        | j,                  rdt        j.                  | j                  | j                  t        j                  j                  j!                  |«      | j"                  ¬«      | _        y y )Nr[   Fr\   ©Úembedding_initr3   )rX   Úrelative_attention_num_bucketsÚrelative_attention_max_distancer`   Úd_kvÚkey_value_proj_dimÚ	num_headsÚn_headsrg   rh   Ú	inner_dimr_   rP   rb   rO   rQ   rc   r3   ÚqÚkÚvÚor‰   ÚEmbedÚrelative_attention_bias)r:   Ú
q_init_stdÚkv_init_stdÚ
o_init_stds       r-   r;   zFlaxT5Attention.setup¹   s  € Ø.2¯k©k×.XÑ.XˆÔ+Ø/3¯{©{×/ZÑ/ZˆÔ,Ø—{‘{×*Ñ*ˆŒØ"&§+¡+×"2Ñ"2ˆÔØ—{‘{×,Ñ,ˆŒØ—{‘{×/Ñ/ˆŒØŸ™¨×(?Ñ(?Ñ?ˆŒà—[‘[×3Ñ3¸¿¹È×I`ÑI`Ñ8`ÐeiÑ7iÑjˆ
Ø—k‘k×4Ñ4¸¿¹ÈÑ8LÑMˆØ—[‘[×3Ñ3°t·~±~ÀtÑ7KÑLˆ
ä—‘Ø�N‰NØÜŸ™×+Ñ+×2Ñ2°:Ó>Ø—*‘*ô	
ˆŒô —‘Ø�N‰NØÜŸ™×+Ñ+×2Ñ2°;Ó?Ø—*‘*ô	
ˆŒô —‘Ø�N‰NØÜŸ™×+Ñ+×2Ñ2°;Ó?Ø—*‘*ô	
ˆŒô —‘Ø�L‰LØÜŸ™×+Ñ+×2Ñ2°:Ó>Ø—*‘*ô	
ˆŒð ×+Ò+Ü+-¯8©8Ø×3Ñ3Ø—‘Ü"Ÿv™v×2Ñ2×9Ñ9¸+ÓFØ—j‘jô	,ˆDÕ(ð ,r/   c                 ó˜  — d}|r&|dz  }|| dkD  |z  z  }t        j                  | «      } nt        j                  | d¬«       } |dz  }| |k  }|t        j                  | |z  «      t        j                  ||z  «      z  ||z
  z  z   }t        j                  ||dz
  ¬«      }|t        j                  || |«      z  }|j                  d«      S )av  
        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
        r   r>   )Úa_maxr   Úi4)r'   ÚabsÚclipÚlogr+   rB   )Úrelative_positionÚbidirectionalÚnum_bucketsÚmax_distanceÚrelative_bucketsÚ	max_exactÚis_smallÚrelative_position_if_larges           r-   Ú_relative_position_bucketz)FlaxT5Attention._relative_position_bucketç   sì   € ð ÐÙØ˜AÑˆKØÐ!2°QÑ!6¸+Ñ EÑEÐÜ #§¡Ð(9Ó :Ñä!$§¡Ð*;À1Ô!EÐ EÐð   1Ñ$ˆ	Ø$ yÑ0ˆð &/Ü�G‰GÐ%¨	Ñ1Ó2´S·W±W¸\ÈIÑ=UÓ5VÑVÐZeÐhqÑZqÑrñ&
Ð"ô &)§X¡XÐ.HÐP[Ð^_ÑP_Ô%`Ð"àœCŸI™I hÐ0AÐC]Ó^Ñ^Ðà×&Ñ& tÓ,Ð,r/   c                 óN  — t        j                  |d¬«      dd…df   }t        j                  |d¬«      ddd…f   }||z
  }| j                  || j                   | j                  | j
                  ¬«      }| j                  |«      }|j                  d«      ddd…dd…dd…f   }|S )z%Compute binned relative position biasr    r   N)r¥   r¦   r§   )r>   r   r   )r'   Úaranger¬   rŠ   rŽ   r�   rš   Ú	transpose)r:   Úquery_lengthÚ
key_lengthÚcontext_positionÚmemory_positionr¤   Úrelative_position_bucketÚvaluess           r-   Úcompute_biaszFlaxT5Attention.compute_bias  s«   € äŸ:™: l¸$Ô?ÂÀ4ÀÑHÐÜŸ*™* Z°tÔ<¸TÂ1¸WÑEˆà+Ð.>Ñ>ÐØ#'×#AÑ#AØØ#Ÿ{™{˜?Ø×;Ñ;Ø×=Ñ=ð	 $Bó $
Ð ð ×-Ñ-Ð.FÓGˆØ×!Ñ! )Ó,¨T²1²aº¨]Ñ;ˆØˆr/   c                 óp   — |j                  |j                  d d | j                  | j                  fz   «      S ©Nr>   )ÚreshapeÚshaper“   r‘   ©r:   rE   s     r-   Ú_split_headszFlaxT5Attention._split_heads  s4   € Ø×$Ñ$ ]×%8Ñ%8¸¸!Ð%<ÀÇÁÈd×NeÑNeÐ?fÑ%fÓgÐgr/   c                 óZ   — |j                  |j                  d d | j                  fz   «      S r¸   )r¹   rº   r”   r»   s     r-   Ú_merge_headszFlaxT5Attention._merge_heads  s,   € Ø×$Ñ$ ]×%8Ñ%8¸¸!Ð%<ÀÇÁÐ?PÑ%PÓQÐQr/   c                 óR  — | j                  dd«      }| j                  ddt        j                  |j                  |j
                  «      }| j                  ddt        j                  |j                  |j
                  «      }| j                  ddd„ «      }|�r|j                  j                  �^ }	}
}}|j                  }dt        |	«      z  |ddfz   }t        j                  j                  |j                  ||«      }t        j                  j                  |j                  ||«      }||_        ||_        |j                  d   }|j                  |z   |_        t        j                  t        j                  |
«      ||z   k  t        |	«      d||
fz   «      }t        ||«      }|||fS )	a\  
        This function takes projected key, value states from a single input token and concatenates the states to cached
        states from previous steps. This function is slightly adapted from the official Flax repository:
        https://github.com/google/flax/blob/491ce18759622506588784b4fca0e4bf05f8c8cd/flax/linen/attention.py#L252
        ÚcacheÚ
cached_keyÚcached_valueÚcache_indexc                  óL   — t        j                  dt         j                  ¬«      S )Nr   r   )r'   ÚarrayÚint32rU   r/   r-   ú<lambda>z7FlaxT5Attention._concatenate_to_cache.<locals>.<lambda>-  s   € ÄCÇIÁIÈaÔWZ×W`ÑW`ÔDa€ r/   )r   r   r   )Úhas_variableÚvariabler'   Úzerosrº   r3   ÚvalueÚlenrO   ÚlaxÚdynamic_update_sliceÚbroadcast_tor®   Útupler	   )r:   ÚkeyrË   ÚqueryÚattention_maskÚis_initializedrÁ   rÂ   rÃ   Ú
batch_dimsÚ
max_lengthr’   Údepth_per_headÚ	cur_indexÚindicesÚnum_updated_cache_vectorsÚpad_masks                    r-   Ú_concatenate_to_cachez%FlaxT5Attention._concatenate_to_cache"  s|  € ð ×*Ñ*¨7°LÓAˆØ—]‘] 7¨L¼#¿)¹)ÀSÇYÁYÐPS×PYÑPYÓZˆ
Ø—}‘} W¨n¼c¿i¹iÈÏÉÐV[×VaÑVaÓbˆØ—m‘m G¨]Ñ<aÓbˆâØAK×AQÑAQ×AWÑAWÑ>ˆZ˜ Y°à#×)Ñ)ˆIØœS ›_Ñ,°	¸1¸aÐ/@Ñ@ˆGÜ—'‘'×.Ñ.¨z×/?Ñ/?ÀÀgÓNˆCÜ—G‘G×0Ñ0°×1CÑ1CÀUÈGÓTˆEØ"ˆJÔØ!&ˆLÔØ(-¯©°A©Ð%Ø +× 1Ñ 1Ð4MÑ MˆKÔô ×'Ñ'Ü—
‘
˜:Ó&¨Ð5NÑ)NÑNÜ�jÓ! QÐ(AÀ:Ð$NÑNóˆHô +¨8°^ÓDˆNØ�E˜>Ð)Ð)r/   c                 ó  — | j                   xr | j                  dd«      xr | }|j                  d   }|r|n|j                  d   }	| j                  r| j	                  |	|«      }
nG|�t        j                  |«      }
n/t        j                  d| j                  |	|f| j                  ¬«      }
|rR| j                  d   d   j                  d   }t        j                  j                  |
dd|dfd| j                  ||f«      }
|
S )NrÀ   rÁ   r   r   r   )rŠ   rÈ   rº   r‰   r¶   r'   r(   rÊ   r“   r3   Ú	variablesrO   rÍ   Údynamic_slice)r:   Ú
key_statesÚquery_statesrÓ   Ú
init_cacheÚ
seq_lengthÚcausal_attention_mask_shiftÚcache_is_filledr±   r°   Úposition_biasÚmax_decoder_lengths               r-   Ú_create_position_biasz%FlaxT5Attention._create_position_biasC  s   € ð Ÿ+™+Òg¨$×*;Ñ*;¸GÀ\Ó*RÒgÐ\fÐXfˆØ×%Ñ% aÑ(ˆ
Ù%4‘z¸,×:LÑ:LÈQÑ:Oˆà×+Ò+Ø ×-Ñ-¨l¸JÓG‰MØÐ'ÜŸN™N¨>Ó:‰MäŸI™I q¨$¯,©,¸ÀjÐ&QÐY]×YcÑYcÔdˆMñ Ø!%§¡°Ñ!8¸Ñ!F×!LÑ!LÈQÑ!OÐÜŸG™G×1Ñ1ØØ�AÐ2°AÐ6Ø�D—L‘L *Ð.@ÐAóˆMð
 Ðr/   Nc	           
      ó"  — |j                   dd \  }	}
| j                  |«      }|€| j                  |«      n| j                  |«      }|€| j                  |«      n| j                  |«      }| j	                  |«      }| j	                  |«      }| j	                  |«      }|t        j                  |j                   d   «      z  }| j                  dd«      r| j                  r| j                  d   d   nd}| j                  rÐt        |d¬	«      }| j                  dd«      rH| j                  d   d   j                   d
   }t        j                  j                  |dd|dfd
d
|
|f«      }t        j                  ||	f|j                   d
d z   «      }t        j                  t        j                  |d¬«      |j                   «      }t!        ||«      }n|�t        j                  |d¬«      }| j                  r,| j                  dd«      s|r| j#                  ||||«      \  }}}|�»t        j$                  | j&                  «      j(                  }t        j                  j+                  |dkD  t        j,                  |j                   d«      j/                  | j&                  «      t        j,                  |j                   |«      j/                  | j&                  «      «      }|€| j1                  |||||
|«      }|�||z   }d}|s | j2                  dkD  r| j5                  d«      }t7        ||||| j2                  d|| j&                  ¬«      }t        j8                  d||«      }| j;                  |«      }| j=                  |«      }||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Á   rÃ   r   Úboolr   r   )éýÿÿÿéþÿÿÿ)r?   g        rh   T)ÚbiasÚdropout_rngrg   Úbroadcast_dropoutrq   r3   z...hqk,...khd->...qhd)rº   r•   r–   r—   r¼   r'   rD   rÈ   rŠ   rÞ   r
   rO   rÍ   rß   rÏ   Úexpand_dimsr	   rÜ   Úfinfor3   ÚminÚselectÚfullrB   rè   rh   Úmake_rngr   Úeinsumr¾   r˜   )r:   rE   rÓ   Úkey_value_statesræ   Ú	use_cacheÚoutput_attentionsrq   râ   Ú
batch_sizerã   rá   rà   Úvalue_statesrä   Úcausal_attention_maskrç   Ú
mask_valuerî   Úattn_weightsÚattn_outputÚoutputss                         r-   rG   zFlaxT5Attention.__call__[  s|  € ð "/×!4Ñ!4°R°aÐ!8Ñˆ
�Jð —v‘v˜mÓ,ˆØ.>Ð.F�T—V‘V˜MÔ*ÈDÏFÉFÐScÓLdˆ
Ø0@Ð0H�t—v‘v˜mÔ,ÈdÏfÉfÐUeÓNfˆð ×(Ñ(¨Ó6ˆØ×&Ñ& zÓ2ˆ
Ø×(Ñ(¨Ó6ˆð 	œŸ™ ×!3Ñ!3°BÑ!7Ó8Ñ8ˆð 8<×7HÑ7HÈÐR^Ô7_Ðdh×doÒdoˆD�N‰N˜7Ñ# MÒ2Ðvwð 	$ð �;Š;Ü$4°^È6Ô$RÐ!ð × Ñ  ¨,Ô7Ø%)§^¡^°GÑ%<¸\Ñ%J×%PÑ%PÐQRÑ%SÐ"Ü(+¯©×(=Ñ(=Ø)Ø˜Ð6¸Ð:Ø˜˜:Ð'9Ð:ó)Ð%ô %(×$4Ñ$4Ø%¨
 }Ð7L×7RÑ7RÐSTÐSUÐ7VÑ'Vó%Ð!ô !×-Ñ-Ü—‘ °XÔ>Ð@U×@[Ñ@[óˆNô +¨>Ð;PÓQ‰NØÐ'Ü Ÿ_™_¨^À(ÔKˆNð �;Š;˜D×-Ñ-¨g°|ÔDÉ
Ø7;×7QÑ7QØ˜L¨,¸ó8Ñ4ˆJ˜ nð
 Ð%ÜŸ™ 4§:¡:Ó.×2Ñ2ˆJÜ ŸW™WŸ^™^Ø Ñ"Ü—‘˜×-Ñ-¨sÓ3×:Ñ:¸4¿:¹:ÓFÜ—‘˜×-Ñ-¨zÓ:×AÑAÀ$Ç*Á*ÓMóˆNð Ð à ×6Ñ6Ø˜L¨.¸*ÀjÐRmóˆMð Ð)Ø -°Ñ >�ð ˆÙ §¡°Ò!3ØŸ-™-¨	Ó2ˆKô 5ØØØØ#ØŸ™Ø"Ø'Ø—*‘*ô	
ˆô —j‘jÐ!8¸,ÈÓUˆð ×'Ñ'¨Ó4ˆð —f‘f˜[Ó)ˆà Ð.ˆáØ  Ñ/ˆGàˆr/   )Té    é€   )NNNFFTF)rH   rI   rJ   r    rL   r‰   rê   rŠ   r'   rM   r3   r;   Ústaticmethodr¬   r¶   r¼   r¾   rP   ÚcompactrÜ   rè   rG   rU   r/   r-   rˆ   rˆ   ³   s–   … ØÓØ(-Ð Ó-Ø€FˆDÓØ—{‘{€Eˆ3�9‰9Ó"ò,ð\ ò!-ó ð!-òFò"hòRð ‡Z�Zñ*ó ð*ò@ð6 ØØØØØØôqr/   rˆ   c                   ót   — e Zd ZU eed<   dZeed<   ej                  Z	ej                  ed<   d„ Z
	 	 	 	 	 dd„Zy)	ÚFlaxT5LayerSelfAttentionrX   Fr‰   r3   c                 óv  — t        | j                  | j                  | j                  j                  | j                  ¬«      | _        t        | j                  j                  | j                  j                  | j                  ¬«      | _	        t        j                  | j                  j                  «      | _        y )N©r‰   rŠ   r3   r€   )rˆ   rX   r‰   rŠ   r3   ÚSelfAttentionr1   r`   rƒ   r„   rP   rf   rg   rh   r9   s    r-   r;   zFlaxT5LayerSelfAttention.setupÔ  sz   € Ü,Ø�K‰KØ(,×(HÑ(HØ—;‘;×%Ñ%Ø—*‘*ô	
ˆÔô *¨$¯+©+×*=Ñ*=À4Ç;Á;×CaÑCaÐim×isÑisÔtˆŒÜ—z‘z $§+¡+×":Ñ":Ó;ˆ�r/   Nc                 óš   — | j                  |«      }| j                  ||||||¬«      }|| j                  |d   |¬«      z   }|f|dd  z   }	|	S )N©rÓ   ræ   rù   rq   râ   r   rp   r   )r„   r	  rh   )
r:   rE   rÓ   ræ   rù   rq   râ   Únormed_hidden_statesÚattention_outputr   s
             r-   rG   z!FlaxT5LayerSelfAttention.__call__Þ  su   € ð  $Ÿ™¨}Ó=ÐØ×-Ñ-Ø Ø)Ø'Ø/Ø'Ø!ð .ó 
Ðð &¨¯©Ð5EÀaÑ5HÐXe¨Ó(fÑfˆØ Ð"Ð%5°a°bÐ%9Ñ9ˆØˆr/   )NNFTF©rH   rI   rJ   r    rL   r‰   rê   r'   rM   r3   r;   rG   rU   r/   r-   r  r  Ï  s@   … ØÓØ(-Ð Ó-Ø—{‘{€Eˆ3�9‰9Ó"ò<ð ØØØØôr/   r  c                   ód   — e Zd ZU eed<   ej                  Zej                  ed<   d„ Z	 	 	 	 dd„Z	y)ÚFlaxT5LayerCrossAttentionrX   r3   c                 ó:  — t        | j                  dd| j                  ¬«      | _        t	        | j                  j
                  | j                  j                  | j                  ¬«      | _        t        j                  | j                  j                  «      | _        y )NFr  r€   )rˆ   rX   r3   ÚEncDecAttentionr1   r`   rƒ   r„   rP   rf   rg   rh   r9   s    r-   r;   zFlaxT5LayerCrossAttention.setupù  sj   € Ü.Ø�K‰K°UÀ5ÐPT×PZÑPZô 
ˆÔô *¨$¯+©+×*=Ñ*=À4Ç;Á;×CaÑCaÐim×isÑisÔtˆŒÜ—z‘z $§+¡+×":Ñ":Ó;ˆ�r/   Nc                 ó˜   — | j                  |«      }| j                  |||||¬«      }|| j                  |d   |¬«      z   }|f|dd  z   }	|	S )N)rÓ   r÷   ræ   rù   r   rp   r   )r„   r  rh   )
r:   rE   r÷   rÓ   ræ   rù   rq   r  r  r   s
             r-   rG   z"FlaxT5LayerCrossAttention.__call__   sr   € ð  $Ÿ™¨}Ó=ÐØ×/Ñ/Ø Ø)Ø-Ø'Ø/ð 0ó 
Ðð &¨¯©Ð5EÀaÑ5HÐXe¨Ó(fÑfˆØ Ð"Ð%5°a°bÐ%9Ñ9ˆØˆr/   )NNFTrs   rU   r/   r-   r  r  õ  s2   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò<ð ØØØôr/   r  c                   ó|   — e Zd ZU eed<   dZeed<   ej                  Z	ej                  ed<   d„ Z
	 	 	 	 	 	 	 	 	 dd„Zy)	ÚFlaxT5BlockrX   Fr‰   r3   c                 óÔ  — | j                   j                  | _        t        | j                   | j                  t	        d«      | j
                  ¬«      f| _        d}| j                  rD| xj                  t        | j                   t	        d«      | j
                  ¬«      fz  c_        |dz  }| xj                  t        | j                   t	        |«      | j
                  ¬«      fz  c_        y )Nr   )r‰   Únamer3   r   )r  r3   )	rX   rŠ   r  r‰   Ústrr3   Úlayerr  r}   )r:   Úfeed_forward_indexs     r-   r;   zFlaxT5Block.setup  s±   € Ø—k‘k×(Ñ(ˆŒä$Ø—‘Ø,0×,LÑ,LÜ˜“VØ—j‘jô	ð
ˆŒ
ð ÐØ�;Š;Ø�JŠJÔ4°T·[±[ÄsÈ1ÃvÐUY×U_ÑU_Ô`ÐbÑb�JØ !Ñ#Ðà�
Š
”} T§[¡[´sÐ;MÓ7NÐVZ×V`ÑV`ÔaÐcÑcŽ
r/   Nc                 ó  —  | j                   d   |||||	|
¬«      }|d   }|dd  }| j                  xr |d u}|r( | j                   d   ||||||	¬«      }|d   }||dd  z   } | j                   d   ||	¬«      }|f}||z   }|S )Nr   r  r   )r÷   rÓ   ræ   rù   rq   r&   rp   )r  rŠ   )r:   rE   rÓ   ræ   Úencoder_hidden_statesÚencoder_attention_maskÚencoder_decoder_position_biasrù   Úreturn_dictrq   râ   Úself_attention_outputsÚattention_outputsÚdo_cross_attentionÚcross_attention_outputsr   s                   r-   rG   zFlaxT5Block.__call__,  sÖ   € ð "/ §¡¨A¡ØØ)Ø'Ø/Ø'Ø!ô"
Ðð /¨qÑ1ˆØ2°1°2Ð6Ðà!Ÿ[™[ÒNÐ-BÈ$Ð-NÐÙØ&3 d§j¡j°¡mØØ!6Ø5Ø;Ø"3Ø+ô'Ð#ð 4°AÑ6ˆMð !2Ð4KÈAÈBÐ4OÑ OÐð '˜Ÿ
™
 2™ }ÀMÔRˆà Ð"ˆàÐ-Ñ-ˆð ˆr/   )	NNNNNFTTFr  rU   r/   r-   r  r    sM   … ØÓØ(-Ð Ó-Ø—{‘{€Eˆ3�9‰9Ó"òdð( ØØ"Ø#Ø&*ØØØØô0r/   r  c                   óv   — e Zd ZU eed<   eed<   ej                  Zej                  ed<   d„ Z		 	 	 	 	 	 	 	 dd„Z
y)ÚFlaxT5LayerCollectionrX   r‰   r3   c                 óf   — t        | j                  | j                  | j                  ¬«      | _        y )N)r‰   r3   )r  rX   r‰   r3   r  r9   s    r-   r;   zFlaxT5LayerCollection.setupd  s&   € Ü Ø�K‰K°T×5UÑ5UÐ]a×]gÑ]gô
ˆ�
r/   Nc
                 ó6   — | j                  |||||||||	¬«	      S )N)rÓ   ræ   r  r  r  rù   rq   râ   )r  )
r:   rE   rÓ   ræ   r  r  r  rù   rq   râ   s
             r-   rG   zFlaxT5LayerCollection.__call__i  s5   € ð �z‰zØØ)Ø'Ø"7Ø#9Ø*GØ/Ø'Ø!ð ó 

ð 
	
r/   )NNNNNFTF)rH   rI   rJ   r    rL   rê   r'   rM   r3   r;   rG   rU   r/   r-   r%  r%  _  sD   … ØÓØ!%Ó%Ø—{‘{€Eˆ3�9‰9Ó"ò
ð ØØ"Ø#Ø&*ØØØô
r/   r%  c            	       óŒ   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   d„ Z
	 	 	 	 	 	 	 	 dde	de	d	e	d
e	fd„Zy)ÚFlaxT5BlockCollectionrX   r3   FÚgradient_checkpointingc                 ó   — | j                   j                  | _        | j                  rnt        t        d¬«      }t        | j                   j                  «      D �cg c].  } || j                   |dk(  | j                  t        |«      ¬«      ‘Œ0 c}| _	        y t        | j                   j                  «      D �cg c]1  }t	        | j                   |dk(  | j                  t        |«      ¬«      ‘Œ3 c}| _	        y c c}w c c}w )N)é   é   é   )Ústatic_argnumsr   )r‰   r3   r  )
rX   rŠ   r*  Úrematr%  ÚrangeÚ
num_layersr3   r  Úblocks)r:   ÚFlaxT5CheckpointLayerÚis      r-   r;   zFlaxT5BlockCollection.setup‡  sÑ   € Ø—k‘k×(Ñ(ˆŒØ×&Ò&Ü$)Ô*?ÐPYÔ$ZÐ!ô ˜tŸ{™{×5Ñ5Ó6öð ñ &Ø—K‘KØ12°a±ØŸ*™*Ü˜Q›ö	òˆD�Kô" ˜tŸ{™{×5Ñ5Ó6öð ô &Ø—K‘KØ12°a±ØŸ*™*Ü˜Q›ö	òˆD�Kùòùòs   Á3C6Â76C;Nrù   Úoutput_hidden_statesrq   râ   c	                 óT  — |rdnd }	|rdnd }
|r| j                   rdnd }d }d }t        | j                  «      D ]`  \  }}|r|	|fz   }	 ||||||||||«	      }|d   }|d   }| j                   r|�	||rdnd   }|sŒB|
|d   fz   }
| j                   sŒX||d   fz   }Œb t        ||	|
|¬«      S )NrU   r   r   r   r>   é   ©Úlast_hidden_staterE   Ú
attentionsÚcross_attentions)rŠ   Ú	enumerater3  r   )r:   rE   rÓ   r  r  rù   r6  rq   râ   Úall_hidden_statesÚall_attentionsÚall_cross_attentionsræ   r  r5  Úlayer_moduleÚlayer_outputss                    r-   rG   zFlaxT5BlockCollection.__call__Ÿ  s  € ñ #7™B¸DÐÙ0™°dˆÙ&7¸D¿KºK™rÈdÐØˆØ(,Ð%ä(¨¯©Ó5ò 	V‰OˆAˆ|Ù#Ø$5¸Ð8HÑ$HÐ!á(ØØØØ%Ø&Ø-Ø!ØØó
ˆMð *¨!Ñ,ˆMð
 *¨!Ñ,ˆMà�{Š{Ð4Ð@Ø0=ÑCT¹aÐZ[Ñ0\Ð-â Ø!/°=ÀÑ3CÐ2EÑ!E�Ø—;“;Ø+?À=ÐQRÑCSÐBUÑ+UÑ(ð;	Vô> =Ø+Ø+Ø%Ø1ô	
ð 	
r/   )NNNNFFTF©rH   rI   rJ   r    rL   r'   rM   r3   r*  rê   r;   rG   rU   r/   r-   r)  r)  ‚  sq   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(òð4 ØØ"Ø#Ø"'Ø%*Ø"Ø ñ6
ð  ð6
ð #ð6
ð ð6
ð ô6
r/   r)  c                   ó°   — e Zd ZU eed<   ej                  ed<   ej                  Z	ej                  ed<   dZ
eed<   d„ Z	 	 	 	 	 	 	 	 	 dded	ed
ededef
d„Zy)ÚFlaxT5StackrX   Úembed_tokensr3   Fr*  c                 ó‚  — | j                   j                  | _        t        | j                   | j                  | j                  ¬«      | _        t        | j                   j                  | j                   j                  | j                  ¬«      | _	        t        j                  | j                   j                  «      | _        y )N©r3   r*  r€   )rX   rŠ   r)  r3   r*  Úblockr1   r`   rƒ   Úfinal_layer_normrP   rf   rg   rh   r9   s    r-   r;   zFlaxT5Stack.setupÞ  s~   € Ø—k‘k×(Ñ(ˆŒä*Ø�K‰K˜tŸz™zÀ$×B]ÑB]ô
ˆŒ
ô !0Ø�K‰K×Ñ T§[¡[×%CÑ%CÈ4Ï:É:ô!
ˆÔô —z‘z $§+¡+×":Ñ":Ó;ˆ�r/   Nrù   r6  r  rq   râ   c
           
      ón  — | j                  |«      }
| j                  |
|¬«      }
| j                  |
|||||||	¬«      }|d   }
| j                  |
«      }
| j                  |
|¬«      }
d }|r|j                  }||
fz   }|s|r
|
|f|dd  z   S |
f|dd  z   S t        |
||j                  |j                  ¬«      S )Nrp   )rÓ   r  r  rù   r6  rq   râ   r   r>   r   r9  )rF  rh   rI  rJ  rE   r   r;  r<  )r:   r!   rÓ   r  r  rù   r6  r  rq   râ   rE   r   r>  s                r-   rG   zFlaxT5Stack.__call__é  s  € ð ×)Ñ)¨)Ó4ˆØŸ™ ]À-˜ÓPˆà—*‘*ØØ)Ø"7Ø#9Ø/Ø!5Ø'Ø!ð ó 	
ˆð   ™
ˆà×-Ñ-¨mÓ<ˆØŸ™ ]À-˜ÓPˆð !ÐáØ '× 5Ñ 5ÐØ 1°]Ð4DÑ DÐáÙ#à!Ø%ðð ˜A˜B�Kñ ð  ð "Ð# g¨a¨b kÑ1Ð1ä<Ø+Ø+Ø×)Ñ)Ø$×5Ñ5ô	
ð 	
r/   )	NNNNFFTTF)rH   rI   rJ   r    rL   rP   r™   r'   rM   r3   r*  rê   r;   rG   rU   r/   r-   rE  rE  Ø  sˆ   … ØÓØ—(‘(ÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ò	<ð ØØ"Ø#Ø"'Ø%*Ø Ø"Ø ñ3
ð  ð3
ð #ð3
ð ð3
ð ð3
ð ô3
r/   rE  a¬  
    Args:
        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
            should be able to pad the inputs on both the right and the left.

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

            To know more on how to prepare `input_ids` for pretraining take a look a [T5 Training](./t5#training).
        attention_mask (`jnp.ndarray` 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)
        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.
a1
  
    Args:
        decoder_input_ids (`jnp.ndarray` of shape `(batch_size, target_sequence_length)`):
            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)

            For training, `decoder_input_ids` should be provided.
        encoder_outputs (`tuple(tuple(jnp.ndarray)`):
            Tuple consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*: `attentions`)
            `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) is a sequence of
            hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
        encoder_attention_mask (`jnp.ndarray` 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_attention_mask (`jnp.ndarray` 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.

            If you want to change padding behavior, you should modify to your needs. See diagram 1 in [the
            paper](https://arxiv.org/abs/1910.13461) for more information on the default strategy.
        past_key_values (`Dict[str, np.ndarray]`, *optional*, returned by `init_cache` or when passing previous `past_key_values`):
            Dictionary of pre-computed hidden-states (key and values in the attention blocks) that can be used for fast
            auto-regressive decoding. Pre-computed key and value hidden-states are of shape *[batch_size, max_length]*.
        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 (`jnp.ndarray` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
            should be able to pad the inputs on both the right and the left.

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

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

            To know more on how to prepare `input_ids` for pretraining take a look a [T5 Training](./t5#training).
        attention_mask (`jnp.ndarray` 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 (`jnp.ndarray` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary.

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

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

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

            To know more on how to prepare `decoder_input_ids` for pretraining take a look at [T5
            Training](./t5#training).
        decoder_attention_mask (`jnp.ndarray` 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.
        encoder_outputs (`tuple(tuple(jnp.ndarray)`, *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(jnp.ndarray))` 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)`.


        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.
c                   ó  ‡ — e Zd ZU dZeZdZdZej                  e
d<   ddej                  ddfd	ed
ee   dedej                  dedefˆ fd„Zd„ Zd%dej(                  j*                  d
ededefd„Z ee«      	 	 	 	 	 	 	 	 	 d&dej4                  deej4                     dej4                  deej4                     dee   dee   dee   dededefd„«       Zd„ Z ee «       e!e"e¬ «      	 	 	 	 	 	 	 d'dej4                  deej4                     dee   dee   dee   dededefd!„«       «       Z# ee$«       e!e%e¬ «      	 	 	 	 	 	 	 	 	 d&d"eej4                     deej4                     d#edee   dee   dee   dededefd$„«       «       Z&ˆ xZ'S )(ÚFlaxT5PreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚtransformerNÚmodule_class)r   r   r   TFrX   Úinput_shapeÚseedr3   Ú_do_initr*  c                 ó\   •—  | j                   d|||dœ|¤Ž}t        ‰	| �	  ||||||¬«       y )N©rX   r3   r*  )rP  rQ  r3   rR  rU   )rO  ÚsuperÚ__init__)
r:   rX   rP  rQ  r3   rR  r*  ÚkwargsÚmoduleÚ	__class__s
            €r-   rV  zFlaxT5PreTrainedModel.__init__¨  sA   ø€ ð #�×"Ñ"Ðw¨&¸ÐVlÑwÐpvÑwˆÜ‰Ñ˜ °[ÀtÐSXÐckÐÕlr/   c                 ó^   — | j                  | j                  | j                  d¬«      | _        y )NTrT  )rO  rX   r3   Ú_moduler9   s    r-   Úenable_gradient_checkpointingz3FlaxT5PreTrainedModel.enable_gradient_checkpointingµ  s*   € Ø×(Ñ(Ø—;‘;Ø—*‘*Ø#'ð )ó 
ˆ�r/   ÚrngÚparamsr$   c                 ó`  — t        j                  |d¬«      }t        j                  |«      }||g}| j                  t        fvr=t        j                  |«      }t        j                  |«      }|j                  ||g«       t        j                  j                  |«      \  }	}
|	|
dœ} | j                  j                  |g|¢­Ž d   }|�dt        t        |«      «      }t        t        |«      «      }| j                  D ]
  }||   ||<   Œ t        «       | _        t        t!        |«      «      S |S )Nr    r   )r^  rh   r^  )r'   rÊ   Ú	ones_likerO  ÚFlaxT5EncoderModuleÚextendrO   ÚrandomÚsplitrX  Úinitr   r   Ú_missing_keysr*   r   r   )r:   r]  rP  r^  r!   rÓ   ÚargsÚdecoder_input_idsÚdecoder_attention_maskÚ
params_rngrî   ÚrngsÚrandom_paramsÚmissing_keys                 r-   Úinit_weightsz"FlaxT5PreTrainedModel.init_weights¼  s'  € ä—I‘I˜k°Ô6ˆ	äŸ™ yÓ1ˆØ˜>Ð*ˆØ×ÑÔ%8Ð$9Ñ9Ü #§¡¨iÓ 8ÐÜ%(§]¡]°9Ó%=Ð"Ø�K‰KÐ*Ð,BÐCÔDä"%§*¡*×"2Ñ"2°3Ó"7Ñˆ
�KØ$°Ñ=ˆà(˜Ÿ™×(Ñ(Øð
àò
ð ñˆð
 ÐÜ(¬°-Ó)@ÓAˆMÜ!¤(¨6Ó"2Ó3ˆFØ#×1Ñ1ò A�Ø&3°KÑ&@��{Ò#ðAä!$£ˆDÔÜœ.¨Ó0Ó1Ð1à Ð r/   r!   rÓ   rh  ri  rù   r6  r  Útrainrî   c                 ó8  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|€t	        d«      ‚|€t        j                  |«      }|€t        j                  |«      }|
�d|
ini }| j                  j                  d|	xs | j                  it        j                  |d¬«      t        j                  |d¬«      t        j                  |d¬«      t        j                  |d¬«      |||| |¬«
      S )NzfMake sure to provide both `input_ids` and `decoder_input_ids`. `decoder_input_ids` is not passed here.rh   r^  r    r   )	r!   rÓ   rh  ri  rù   r6  r  rq   rk  )rX   rù   r6  r  Ú
ValueErrorr'   r`  rX  Úapplyr^  rÅ   )r:   r!   rÓ   rh  ri  rù   r6  r  ro  r^  rî   rk  s               r-   rG   zFlaxT5PreTrainedModel.__call__Ù  s#  € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆàÐ$Üðóð ð Ð!Ü Ÿ]™]¨9Ó5ˆNð "Ð)Ü%(§]¡]Ð3DÓ%EÐ"ð ,7Ð+B�	˜;Ñ'Èˆà�{‰{× Ñ Ø�vÒ, §¡Ð-Ü—i‘i 	°Ô6ÜŸ9™9 ^¸4Ô@Ü!Ÿi™iÐ(9ÀÔFÜ#&§9¡9Ð-CÈ4Ô#PØ/Ø!5Ø#Ø#˜)Øð !ó 
ð 	
r/   c                 ó  — t        j                  ||fd¬«      }t        j                  |«      }d„ }| j                  j	                  t
        j                  j                  d«      |||d   d|¬«      }t        |d   «      S )a+  
        Args:
            batch_size (`int`):
                batch_size used for fast auto-regressive decoding. Defines the batch size of the initialized cache.
            max_length (`int`):
                maximum possible length for auto-regressive decoding. Defines the sequence length of the initialized
                cache.
            encoder_outputs (`Union[FlaxBaseModelOutput, tuple(tuple(jnp.ndarray)]`):
                `encoder_outputs` consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*:
                `attentions`). `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*)
                is a sequence of hidden-states at the output of the last layer of the encoder. Used in the
                cross-attention of the decoder.
        r    r   c                 ó6   — | j                  «       } |||fi |¤ŽS ©N©Ú_get_decoder_module©rX  rh  ri  rW  Údecoder_modules        r-   Ú_decoder_forwardz:FlaxT5PreTrainedModel.init_cache.<locals>._decoder_forward  ó-   € Ø#×7Ñ7Ó9ˆNÙ!Ø!Ø&ñð ñð r/   r   T)rh  ri  r  râ   ÚmethodrÀ   )	r'   rR   r`  rX  re  rO   rc  r   r   )r:   rú   rÖ   Úencoder_outputsrh  ri  rz  Úinit_variabless           r-   râ   z FlaxT5PreTrainedModel.init_cache  s‚   € ô  ŸH™H j°*Ð%=ÀTÔJÐÜ!$§¡Ð/@Ó!AÐò	ð Ÿ™×)Ñ)Ü�J‰J×Ñ˜qÓ!Ø/Ø#9Ø"1°!Ñ"4ØØ#ð *ó 
ˆô ˜ wÑ/Ó0Ð0r/   ©Úoutput_typeÚconfig_classc	                 ó¢  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|€t	        j
                  |«      }i }	|�||	d<   d„ }
| j                  j                  d|xs | j                  it	        j                  |d¬«      t	        j                  |d¬«      |||| |	|
¬«	      S )añ  
        Returns:

        Example:

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

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

        >>> text = "My friends are cool but they eat too many carbs."
        >>> inputs = tokenizer(text, return_tensors="np")
        >>> encoder_outputs = model.encode(**inputs)
        ```rh   c                 ó6   — | j                  «       } |||fi |¤ŽS ru  )Ú_get_encoder_module)rX  r!   rÓ   rW  Úencode_modules        r-   Ú_encoder_forwardz6FlaxT5PreTrainedModel.encode.<locals>._encoder_forwardY  s"   € Ø"×6Ñ6Ó8ˆMÙ  ¨NÑE¸fÑEÐEr/   r^  r    r   )r!   rÓ   rù   r6  r  rq   rk  r|  ©
rX   rù   r6  r  r'   r`  rX  rr  r^  rÅ   )r:   r!   rÓ   rù   r6  r  ro  r^  rî   rk  r†  s              r-   ÚencodezFlaxT5PreTrainedModel.encode/  sá   € ð8 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆàÐ!Ü Ÿ]™]¨9Ó5ˆNð ˆØÐ"Ø)ˆD�‰Oò	Fð �{‰{× Ñ Ø�vÒ, §¡Ð-Ü—i‘i 	°Ô6ÜŸ9™9 ^¸4Ô@Ø/Ø!5Ø#Ø#˜)ØØ#ð !ó 

ð 
	
r/   r  Úpast_key_valuesc                 óö  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|d   }|€)|j                  dd \  }}t        j                  ||f«      }|j                  \  }}|€t        j                  ||f«      }i }|�||d<   d|
xs | j                  i}|r	||d<   dg}nd}d„ }| j                  j                  |t        j                  |d	¬
«      t        j                  |d	¬
«      |t        j                  |d	¬
«      ||||	 |||¬«      }|�|r|\  }}t        |d   «      |d<   |S |�"|s |\  }}|dd t        |d   «      fz   |dd z   }|S )a9  
        Returns:

        Example:

        ```python
        >>> from transformers import AutoTokenizer, FlaxT5ForConditionalGeneration
        >>> import jax.numpy as jnp

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

        >>> text = "My friends are cool but they eat too many carbs."
        >>> inputs = tokenizer(text, return_tensors="np")
        >>> encoder_outputs = model.encode(**inputs)

        >>> decoder_start_token_id = model.config.decoder_start_token_id
        >>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id

        >>> outputs = model.decode(decoder_input_ids, encoder_outputs)
        >>> logits = outputs.logits
        ```Nr   r>   rh   r^  rÀ   Fc                 ó6   — | j                  «       } |||fi |¤ŽS ru  rv  rx  s        r-   rz  z6FlaxT5PreTrainedModel.decode.<locals>._decoder_forward®  r{  r/   r    r   ©rh  ri  r  r  rù   r6  r  rq   rk  Úmutabler|  r‰  r   )rX   rù   r6  r  rº   r'   rR   r^  rX  rr  rÅ   r   )r:   rh  r}  r  ri  r‰  rù   r6  r  ro  r^  rî   r  rú   Úsequence_lengthrk  Úinputsr�  rz  r   Úpasts                        r-   ÚdecodezFlaxT5PreTrainedModel.decodei  sÏ  € ðL 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆà /°Ñ 2ÐØ!Ð)Ø*?×*EÑ*EÀbÀqÐ*IÑ'ˆJ˜Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"à&7×&=Ñ&=Ñ#ˆ
�OØ!Ð)Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"ð ˆØÐ"Ø)ˆD�‰Oà˜FÒ1 d§k¡kÐ2ˆñ
 Ø-ˆF�7‰OØ�i‰GàˆGò	ð —+‘+×#Ñ#ØÜ!Ÿi™iÐ(9ÀÔFÜ#&§9¡9Ð-CÈ4Ô#PØ"7Ü#&§9¡9Ð-CÈ4Ô#PØ/Ø!5Ø#Ø#˜)ØØØ#ð $ó 
ˆð  Ð&©;Ø#‰MˆG�TÜ)1°$°w±-Ó)@ˆGÐ%Ñ&ØˆNØÐ(±Ø#‰MˆG�TØ˜b˜q�k¤X¨d°7©mÓ%<Ð$>Ñ>ÀÈÈÀÑLˆGàˆr/   ru  ©	NNNNNNFNN©NNNNFNN)(rH   rI   rJ   Ú__doc__r    r�  Úbase_model_prefixrO  rP   ÚModulerL   r'   rM   r   rK   r3   rê   rV  r\  rO   rc  r   r   rn  r   ÚT5_INPUTS_DOCSTRINGrT   r   ÚdictrG   râ   r   ÚT5_ENCODE_INPUTS_DOCSTRINGr   r   rˆ  ÚT5_DECODE_INPUTS_DOCSTRINGr   r‘  Ú__classcell__)rY  s   @r-   rM  rM  ž  sõ  ø… ñð
 €LØ%ÐØ"€L�"—)‘)Ó"ð
 #)ØØŸ;™;ØØ',ñmàðmð ˜3‘Zðmð ð	mð
 �y‰yðmð ðmð !%õmò
ñ! §
¡
× 2Ñ 2ð !Àð !ÐPZð !Ðfpó !ñ: +Ð+>Ó?ð 15Ø)-Ø8<Ø,0Ø/3Ø&*ØØØ#ñ/
à—;‘;ð/
ð ! §¡Ñ-ð/
ð Ÿ;™;ð	/
ð
 !)¨¯©Ñ 5ð/
ð $ D™>ð/
ð ' t™nð/
ð ˜d‘^ð/
ð ð/
ð ð/
ð ò/
ó @ð/
òb"1ñH Ð4Ó5ÙÐ+>ÈXÔVð 15Ø,0Ø/3Ø&*ØØØ#ñ6
à—;‘;ð6
ð ! §¡Ñ-ð6
ð $ D™>ð	6
ð
 ' t™nð6
ð ˜d‘^ð6
ð ð6
ð ð6
ð ò6
ó Wó 6ð6
ñp Ð4Ó5ÙÐ+XÐgoÔpð
 9=Ø8<Ø $Ø,0Ø/3Ø&*ØØØ#ñcð !)¨¯©Ñ 5ð	cð
 !)¨¯©Ñ 5ðcð ðcð $ D™>ðcð ' t™nðcð ˜d‘^ðcð ðcð ðcð òcó qó 6ôcr/   rM  a‚	  
    The T5 model was proposed in [Exploring the Limits of Transfer Learning with a Unified Text-to-Text
    Transformer](https://arxiv.org/abs/1910.10683) by Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan
    Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J. Liu. It's an encoder decoder transformer pre-trained in a
    text-to-text denoising generative setting.

    This model inherits from [`FlaxPreTrainedModel`]. 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 Flax Linen
    [flax.nn.Module](https://flax.readthedocs.io/en/latest/_autosummary/flax.nn.module.html) subclass. Use it as a
    regular Flax Module and refer to the Flax documentation for all matter related to general usage and behavior.

    Finally, this model supports inherent JAX features such as:

    - [Just-In-Time (JIT) compilation](https://jax.readthedocs.io/en/latest/jax.html#just-in-time-compilation-jit)
    - [Automatic Differentiation](https://jax.readthedocs.io/en/latest/jax.html#automatic-differentiation)
    - [Vectorization](https://jax.readthedocs.io/en/latest/jax.html#vectorization-vmap)
    - [Parallelization](https://jax.readthedocs.io/en/latest/jax.html#parallelization-pmap)

    Parameters:
        config ([`T5Config`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~FlaxPreTrainedModel.from_pretrained`] method to load the model weights.
        dtype (`jax.numpy.dtype`, *optional*, defaults to `jax.numpy.float32`):
            The data type of the computation. Can be one of `jax.numpy.float32`, `jax.numpy.float16` (on GPUs) and
            `jax.numpy.bfloat16` (on TPUs).

            This can be used to enable mixed-precision training or half-precision inference on GPUs or TPUs. If
            specified all the computation will be performed with the given `dtype`.

            **Note that this only specifies the dtype of the computation and does not influence the dtype of model
            parameters.**

            If you wish to change the dtype of the model parameters, see [`~FlaxPreTrainedModel.to_fp16`] and
            [`~FlaxPreTrainedModel.to_bf16`].
z[The bare T5 Model transformer outputting raw hidden-stateswithout any specific head on top.c                   óŽ   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   d„ Z
d„ Zd„ Z	 	 	 	 	 	 	 	 	 dd	e	fd
„Zy)ÚFlaxT5ModulerX   r3   Fr*  c                 ó   — | j                   S ru  ©Úencoderr9   s    r-   r„  z FlaxT5Module._get_encoder_module  ó   € Ø�|‰|Ðr/   c                 ó   — | j                   S ru  ©Údecoderr9   s    r-   rw  z FlaxT5Module._get_decoder_module  r¡  r/   c                 ó¶  — t        j                  | j                  j                  | j                  j                  t
        j                   j                  j                  | j                  j                  dz  «      | j                  ¬«      | _
        t        j                  | j                  «      }d|_        t        || j                  | j                  | j                  ¬«      | _        t        j                  | j                  «      }d|_        | j                  j"                  |_        t        || j                  | j                  | j                  ¬«      | _        y )Nç      ð?rŒ   F©rF  r3   r*  T)rP   r™   rX   Ú
vocab_sizer`   rO   rQ   rc   r_   r3   ÚsharedÚcopyÚdeepcopyrŠ   rE  r*  r   Únum_decoder_layersr2  r¤  ©r:   Úencoder_configÚdecoder_configs      r-   r;   zFlaxT5Module.setup  sñ   € Ü—h‘hØ�K‰K×"Ñ"Ø�K‰K×ÑÜŸ6™6×.Ñ.×5Ñ5°d·k±k×6TÑ6TÐWZÑ6ZÓ[Ø—*‘*ô	
ˆŒô Ÿ™ t§{¡{Ó3ˆØ %ˆÔÜ"ØØŸ™Ø—*‘*Ø#'×#>Ñ#>ô	
ˆŒô Ÿ™ t§{¡{Ó3ˆØ $ˆÔØ$(§K¡K×$BÑ$BˆÔ!Ü"ØØŸ™Ø—*‘*Ø#'×#>Ñ#>ô	
ˆ�r/   Nrq   c
           
      óp  — |�|n| j                   j                  }| j                  ||||||	¬«      }| j                  |||d   |||||	¬«      }
|s|
|z   S t	        |
j
                  |
j                  |
j                  |
j                  |
j                  |j
                  |j                  |j                  ¬«      S )N©r!   rÓ   rù   r6  r  rq   r   ©r!   rÓ   r  r  rù   r6  r  rq   )r:  r‰  Údecoder_hidden_statesÚdecoder_attentionsr<  Úencoder_last_hidden_stater  Úencoder_attentions)
rX   Úuse_return_dictr   r¤  r   r:  r‰  rE   r;  r<  )r:   r!   rÓ   rh  ri  r}  rù   r6  r  rq   Údecoder_outputss              r-   rG   zFlaxT5Module.__call__#  sØ   € ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ÿ,™,ØØ)Ø/Ø!5Ø#Ø'ð 'ó 
ˆð Ÿ,™,Ø'Ø1Ø"1°!Ñ"4Ø#1Ø/Ø!5Ø#Ø'ð 'ó 	
ˆñ Ø" _Ñ4Ð4ä%Ø-×?Ñ?Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô	
ð 		
r/   ©	NNNNNNNNT©rH   rI   rJ   r    rL   r'   rM   r3   r*  rê   r„  rw  r;   rG   rU   r/   r-   r�  r�  ù  sb   … ð
 ÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(òòò
ð: ØØØ#ØØØ!ØØ"ñ0
ð ô0
r/   r�  c                   ó   — e Zd ZeZy)ÚFlaxT5ModelN)rH   rI   rJ   r�  rO  rU   r/   r-   r¼  r¼  V  s   „ Ø�Lr/   r¼  a›  
    Returns:

    Example:

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

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

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

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

    >>> # forward pass
    >>> outputs = model(input_ids=input_ids, decoder_input_ids=decoder_input_ids)
    >>> last_hidden_states = outputs.last_hidden_state
    ```
r  zfThe bare T5 Model transformer outputting encoder's raw hidden-states without any specific head on top.c                   ó€   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   d„ Z
	 	 	 	 	 	 d
de	de	fd	„Zy)ra  rX   r3   Fr*  c                 óì  — t        j                  | j                  j                  | j                  j                  t
        j                   j                  j                  | j                  j                  dz  «      | j                  ¬«      | _
        t        j                  | j                  «      }d|_        d|_        d|_        t!        || j                  | j                  | j"                  ¬«      | _        y )Nr¦  rŒ   Fr§  )rP   r™   rX   r¨  r`   rO   rQ   rc   r_   r3   r©  rª  r«  Ú
is_decoderÚis_encoder_decoderrŠ   rE  r*  r   )r:   r®  s     r-   r;   zFlaxT5EncoderModule.setup„  s­   € Ü—h‘hØ�K‰K×"Ñ"Ø�K‰K×ÑÜŸ6™6×.Ñ.×5Ñ5°d·k±k×6TÑ6TÐWZÑ6ZÓ[Ø—*‘*ô	
ˆŒô Ÿ™ t§{¡{Ó3ˆØ$)ˆÔ!Ø,1ˆÔ)Ø %ˆÔÜ"ØØŸ™Ø—*‘*Ø#'×#>Ñ#>ô	
ˆ�r/   Nr  rq   c                 ó4   — | j                  ||||||¬«      }|S )Nr±  rŸ  )r:   r!   rÓ   rù   r6  r  rq   r}  s           r-   rG   zFlaxT5EncoderModule.__call__—  s1   € ð Ÿ,™,ØØ)Ø/Ø!5Ø#Ø'ð 'ó 
ˆð Ðr/   )NNFFTTrC  rU   r/   r-   ra  ra  {  sY   … ð
 ÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ò
ð* ØØØ"Ø Ø"ñð ðð ôr/   ra  c                   óž   — e Zd ZeZ ee«      	 	 	 	 	 	 	 ddej                  de	ej                     de	e
   de	e
   de	e
   de
ded	efd
„«       Zy)ÚFlaxT5EncoderModelNr!   rÓ   rù   r6  r  ro  r^  rî   c	           
      ó˜  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|€t	        j
                  |«      }|�d|ini }	| j                  j                  d|xs | j                  it	        j                  |d¬«      t	        j                  |d¬«      |||| |	¬«      S )Nrh   r^  r    r   )r!   rÓ   rù   r6  r  rq   rk  r‡  )
r:   r!   rÓ   rù   r6  r  ro  r^  rî   rk  s
             r-   rG   zFlaxT5EncoderModel.__call__°  sÕ   € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆð Ð!Ü Ÿ]™]¨9Ó5ˆNð ,7Ð+B�	˜;Ñ'Èˆà�{‰{× Ñ Ø�vÒ, §¡Ð-Ü—i‘i 	°Ô6ÜŸ9™9 ^¸4Ô@Ø/Ø!5Ø#Ø#˜)Øð !ó 	
ð 		
r/   r“  )rH   rI   rJ   ra  rO  r   r™  r'   rT   r   rê   r˜  r   rG   rU   r/   r-   rÃ  rÃ  ­  sž   „ Ø&€Lá*Ð+EÓFð 15Ø,0Ø/3Ø&*ØØØ#ñ!
à—;‘;ð!
ð ! §¡Ñ-ð!
ð $ D™>ð	!
ð
 ' t™nð!
ð ˜d‘^ð!
ð ð!
ð ð!
ð ò!
ó Gñ!
r/   rÃ  z0T5 Model with a `language modeling` head on top.c                   óŽ   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   d„ Z
d„ Zd„ Z	 	 	 	 	 	 	 	 	 dd	e	fd
„Zy)Ú$FlaxT5ForConditionalGenerationModulerX   r3   Fr*  c                 ó   — | j                   S ru  rŸ  r9   s    r-   r„  z8FlaxT5ForConditionalGenerationModule._get_encoder_moduleÛ  r¡  r/   c                 ó   — | j                   S ru  r£  r9   s    r-   rw  z8FlaxT5ForConditionalGenerationModule._get_decoder_moduleÞ  r¡  r/   c                 óþ  — | j                   j                  | _        t        j                  | j                   j
                  | j                   j                  t        j                  j                  j                  | j                   j                  «      | j                  ¬«      | _        t        j                  | j                   «      }d|_        d|_        d|_        t#        || j                  | j                  | j$                  ¬«      | _        t        j                  | j                   «      }d|_        d|_        | j                   j(                  |_        t#        || j                  | j                  | j$                  ¬«      | _        t        j.                  | j                   j
                  dt        j                  j                  j                  | j                   j                  «      | j                  ¬«      | _        y )NrŒ   FrH  Tr\   )rX   r`   Ú	model_dimrP   r™   r¨  rO   rQ   rc   r_   r3   r©  rª  r«  rŠ   rø   rÀ  rE  r*  r   r¬  r2  r¤  rb   Úlm_headr­  s      r-   r;   z*FlaxT5ForConditionalGenerationModule.setupá  s[  € ØŸ™×,Ñ,ˆŒä—h‘hØ�K‰K×"Ñ"Ø�K‰K×ÑÜŸ6™6×.Ñ.×5Ñ5°d·k±k×6TÑ6TÓUØ—*‘*ô	
ˆŒô Ÿ™ t§{¡{Ó3ˆØ %ˆÔØ#(ˆÔ Ø,1ˆÔ)Ü"Ø˜DŸK™K¨t¯z©zÐRV×RmÑRmô
ˆŒô Ÿ™ t§{¡{Ó3ˆØ $ˆÔØ,1ˆÔ)Ø$(§K¡K×$BÑ$BˆÔ!Ü"Ø˜DŸK™K¨t¯z©zÐRV×RmÑRmô
ˆŒô —x‘xØ�K‰K×"Ñ"ØÜŸ™×+Ñ+×2Ñ2°4·;±;×3QÑ3QÓRØ—*‘*ô	
ˆ�r/   Nrq   c
           
      ó¤  — |�|n| j                   j                  }| j                  ||||||	¬«      }|d   }
| j                  |||
|||||	¬«      }|d   }| j                   j                  r|| j
                  dz  z  }| j                   j                  rG| j                  j                  d   d   }| j                  j                  dd|j                  ii|«      }n| j                  |«      }|s|f|dd  z   |z   S t        ||j                  |j                  |j                  |j                  |j                   |j                  |j                  ¬	«      S )
Nr±  r   r²  r[   r^  Ú	embeddingÚkernelr   )Úlogitsr‰  r³  r´  r<  rµ  r  r¶  )rX   r·  r   r¤  Útie_word_embeddingsrÊ  r©  rÞ   rË  rr  ÚTr   r‰  rE   r;  r<  r:  )r:   r!   rÓ   rh  ri  r}  rù   r6  r  rq   rE   r¸  Úsequence_outputÚshared_embeddingÚ	lm_logitss                  r-   rG   z-FlaxT5ForConditionalGenerationModule.__call__  sp  € ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ÿ,™,ØØ)Ø/Ø!5Ø#Ø'ð 'ó 
ˆð (¨Ñ*ˆð Ÿ,™,Ø'Ø1Ø"/Ø#1Ø/Ø!5Ø#Ø'ð 'ó 	
ˆð *¨!Ñ,ˆà�;‰;×*Ò*ð .°·±ÀÑ1EÑFˆOà�;‰;×*Ò*Ø#Ÿ{™{×4Ñ4°XÑ>¸{ÑKÐØŸ™×*Ñ*¨H°xÐAQ×ASÑASÐ6TÐ+UÐWfÓg‰IàŸ™ _Ó5ˆIáØ�< /°!°"Ð"5Ñ5¸ÑGÐGä"ØØ+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô	
ð 		
r/   r¹  rº  rU   r/   r-   rÆ  rÆ  Õ  sa   … àÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(òòò
ðF ØØØ#ØØØ!ØØ"ñ?
ð ô?
r/   rÆ  c                   ó  — e Zd ZeZ ee«       eee	¬«      	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     dede
e   de
e   de
e   d	ed
edefd„«       «       Z	 	 	 dde
ej$                     de
ej$                     fd„Zd„ Zy)ÚFlaxT5ForConditionalGenerationr  Nr  ri  r‰  rù   r6  r  ro  r^  rî   c                 óz  ‡ — |�|n‰ j                   j                  }|�|n‰ j                   j                  }|�|n‰ j                   j                  }|d   }|€)|j                  dd \  }}t        j                  ||f«      }|j                  \  }}|€t        j                  ||f«      }i }|�||d<   d|
xs ‰ j                  i}|r	||d<   dg}nd}ˆ fd„}‰ j                  j                  |t        j                  |d	¬
«      t        j                  |d	¬
«      |t        j                  |d	¬
«      ||||	 |||¬«      }|€|\  }}n|\  \  }}}|r.t        ||j                  |j                  |j                  ¬«      }n	|f|dd z   }|�|rt        d   «      |d<   |S |�|s|dd t        d   «      fz   |dd z   }|S )aD  
        Returns:

        Example:

        ```python
        >>> from transformers import AutoTokenizer, FlaxT5ForConditionalGeneration
        >>> import jax.numpy as jnp

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

        >>> text = "summarize: My friends are cool but they eat too many carbs."
        >>> inputs = tokenizer(text, return_tensors="np")
        >>> encoder_outputs = model.encode(**inputs)

        >>> decoder_start_token_id = model.config.decoder_start_token_id
        >>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id

        >>> outputs = model.decode(decoder_input_ids, encoder_outputs)
        >>> logits = outputs.logits
        ```Nr   r>   rh   r^  rÀ   Fc                 ó�  •— | j                  «       } |||fi |¤Ž}|d   }‰	j                  j                  r|‰	j                  j                  dz  z  }‰	j                  j                  rJ| j                  j
                  d   d   }| j                  j                  dd|j                  ii|«      }||fS | j                  |«      }||fS )Nr   r[   r^  rÍ  rÎ  )	rw  rX   rÐ  r`   r©  rÞ   rË  rr  rÑ  )
rX  rh  ri  rW  ry  r¸  rÒ  rÓ  rÔ  r:   s
            €r-   rz  z?FlaxT5ForConditionalGeneration.decode.<locals>._decoder_forwardŒ  sÖ   ø€ Ø#×7Ñ7Ó9ˆNÙ,Ø!Ø&ñð ñˆOð .¨aÑ0ˆOà�{‰{×.Ò.ð #2°T·[±[×5HÑ5HÈ$Ñ5NÑ"O�à�{‰{×.Ò.Ø#)§=¡=×#:Ñ#:¸8Ñ#DÀ[Ñ#QÐ Ø"ŸN™N×0Ñ0°(¸XÐGW×GYÑGYÐ<ZÐ1[Ð]lÓm�	ð ˜oÐ-Ð-ð #ŸN™N¨?Ó;�	à˜oÐ-Ð-r/   r    r   rŒ  )rÏ  rE   r;  r<  r   r‰  )rX   rù   r6  r  rº   r'   rR   r^  rX  rr  rÅ   r   rE   r;  r<  r   )r:   rh  r}  r  ri  r‰  rù   r6  r  ro  r^  rî   r  rú   rŽ  rk  r�  r�  rz  r   rÔ  r¸  r�  s   `                      r-   r‘  z%FlaxT5ForConditionalGeneration.decodeG  s  ø€ ðL 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆà /°Ñ 2ÐØ!Ð)Ø*?×*EÑ*EÀbÀqÐ*IÑ'ˆJ˜Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"à&7×&=Ñ&=Ñ#ˆ
�OØ!Ð)Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"ð ˆØÐ"Ø)ˆD�‰Oà˜FÒ1 d§k¡kÐ2ˆñ
 Ø-ˆF�7‰OØ�i‰GàˆGô	.ð. —+‘+×#Ñ#ØÜ!Ÿi™iÐ(9ÀÔFÜ#&§9¡9Ð-CÈ4Ô#PØ"7Ü#&§9¡9Ð-CÈ4Ô#PØ/Ø!5Ø#Ø#˜)ØØØ#ð $ó 
ˆð Ð"Ø)0Ñ&ˆI‘à18Ñ.Ñ(ˆY˜¨$áÜ;Ø Ø-×;Ñ;Ø*×5Ñ5Ø!0×!AÑ!Aô	‰Gð !�l _°Q°RÐ%8Ñ8ˆGð Ð&©;Ü)1°$°w±-Ó)@ˆGÐ%Ñ&ØˆNØÐ(±Ø˜b˜q�k¤X¨d°7©mÓ%<Ð$>Ñ>ÀÈÈÀÑLˆGàˆr/   rÓ   c                 óÌ   — |j                   \  }}| j                  |||«      }	t        j                  ||fd¬«      }
|�!t        j
                  j                  |
|d«      }
|	|||
dœS )Nr    r   )r   r   )r‰  r}  r  ri  )rº   râ   r'   rR   rO   rÍ   rÎ   )r:   rh  rÖ   rÓ   ri  r}  rW  rú   rã   r‰  Úextended_attention_masks              r-   Úprepare_inputs_for_generationz<FlaxT5ForConditionalGeneration.prepare_inputs_for_generationÊ  sy   € ð "3×!8Ñ!8Ñˆ
�JàŸ/™/¨*°jÀ/ÓRˆô #&§(¡(¨J¸
Ð+CÈ4Ô"PÐØ!Ð-Ü&)§g¡g×&BÑ&BØ'Ð)?Àó'Ð#ð
  /Ø.Ø&4Ø&=ñ	
ð 	
r/   c                 ó$   — |j                   |d<   |S )Nr‰  )r‰  )r:   Úmodel_outputsÚmodel_kwargss      r-   Úupdate_inputs_for_generationz;FlaxT5ForConditionalGeneration.update_inputs_for_generationç  s   € Ø*7×*GÑ*GˆÐ&Ñ'ØÐr/   r’  )NNN)rH   rI   rJ   rÆ  rO  r   rš  r   r   r    r   r'   rT   r˜  rê   r   r‘  rO   ÚArrayrÛ  rß  rU   r/   r-   rÖ  rÖ  D  s  „ Ø7€LáÐ4Ó5ÙÐ+PÐ_gÔhð
 9=Ø8<Ø $Ø,0Ø/3Ø&*ØØØ#ñð !)¨¯©Ñ 5ð	ð
 !)¨¯©Ñ 5ðð ðð $ D™>ðð ' t™nðð ˜d‘^ðð ðð ðð òó ió 6ððJ /3Ø6:Øñ
ð ! §¡Ñ+ð	
ð
 !)¨¯©Ñ 3ó
ó:r/   rÖ  a”  
    Returns:

    Example:

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

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

    >>> ARTICLE_TO_SUMMARIZE = "summarize: My friends are cool but they eat too many carbs."
    >>> inputs = tokenizer([ARTICLE_TO_SUMMARIZE], return_tensors="np")

    >>> # Generate Summary
    >>> summary_ids = model.generate(inputs["input_ids"]).sequences
    >>> print(tokenizer.decode(summary_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=False))
    ```
)rÃ  rÖ  r¼  rM  )Sr”  rª  Útypingr   r   r   Ú
flax.linenÚlinenrP   rO   Ú	jax.numpyÚnumpyr'   rS   Úflax.core.frozen_dictr   r   r   r	   r
   r   Únn_partitioningÚflax.linen.attentionr   Úflax.traverse_utilr   r   Ú
jax.randomr   Úmodeling_flax_outputsr   r   r   r   r   Úmodeling_flax_utilsr   r   r   r   r   Úutilsr   r   r   r   Úconfiguration_t5r    Ú
get_loggerrH   ÚloggerÚ_CHECKPOINT_FOR_DOCÚ_CONFIG_FOR_DOCr0  rT   rK   r.   r–  r1   rW   ru   r}   rˆ   r  r  r  r%  r)  rE  r™  rš  r—  rM  ÚT5_START_DOCSTRINGr�  r¼  ÚFLAX_T5_MODEL_DOCSTRINGra  rÃ  rÆ  rÖ  Ú(FLAX_T5_CONDITIONAL_GENERATION_DOCSTRINGÚ__all__rU   r/   r-   ú<module>r÷     sÄ  ðñ ã ß ,Ñ ,å Û 
Ý Û ß >Ñ >ß 6Ý 6Ý >ß ;Ý ÷õ ÷õ ÷ uÓ tÝ &ð 
ˆ×	Ñ	˜HÓ	%€à*Ð Ø€à×Ñ€ð	 #§+¡+ð 	¸Sð 	ÐZ]ð 	Ðbe×bmÑbmó 	ô+�b—i‘iô +ô(˜"Ÿ)™)ô ô>#˜rŸy™yô #ôL�B—I‘Iô ô(Y�b—i‘iô Yôx#˜rŸy™yô #ôL §	¡	ô ôBF�"—)‘)ô FôR 
˜BŸI™Iô  
ôFS
˜BŸI™Iô S
ôlD
�"—)‘)ô D
ðNÐ ð6'Ð ðT7Ð ôtpÐ/ô pðf	%Ð ñP ØaØóôV
�2—9‘9ó V
ó	ðV
ôr Ð'ô  ñ ˜[Ð*=Ð?UÐWfÔ gðÐ ñ6 ˜Ð&9Ð<SÑ&SÔ TÙ   Ð:MÐ\kÕ lñ ØlØóô+˜"Ÿ)™)ó +ó	ð+ô\%
Ð.ô %
ñP ÐLÐN`Óaôk
¨2¯9©9ó k
ó bðk
ô\eÐ%:ô eðP,Ð (ñ* Ø"Ð$7Ð:bÑ$bôñ !Ø"Ð0CÐRaõò
 k�r/   