Ë
    T^(h0á ã                  ó€  — d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
 ddlZddlZddlmZ ddlmZ dd	lmZmZmZmZmZmZ dd
lmZmZmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&  e#jN                  e(«      Z)dZ*dZ+dZ,d9d„Z-d:d;d„Z.d<d=d„Z/ G d„ dej`                  jb                  «      Z2 G d„ dej`                  jf                  «      Z4 G d„ dej`                  jf                  «      Z5 G d„ dej`                  jf                  «      Z6 G d„ dej`                  jf                  «      Z7 G d„ dej`                  jf                  «      Z8 G d „ d!e«      Z9e G d"„ d#e«      «       Z:e G d$„ d%e«      «       Z;e G d&„ d'e«      «       Z<d(Z=d)Z>e G d*„ d+ej`                  jf                  «      «       Z?e G d,„ d-ej`                  jf                  «      «       Z@e G d.„ d/ej`                  jf                  «      «       ZA e!d0e=«       G d1„ d2e9«      «       ZB G d3„ d4ej`                  jf                  «      ZC e!d5e=«       G d6„ d7e9«      «       ZDg d8¢ZEy)>zTF 2.0 LED model.é    )ÚannotationsN)Ú	dataclass)ÚListÚOptionalÚTupleÚUnioné   )Úget_tf_activation)Ú+TFBaseModelOutputWithPastAndCrossAttentions)ÚTFModelInputTypeÚTFPreTrainedModelÚget_initializerÚkerasÚkeras_serializableÚunpack_inputs)Úcheck_embeddings_within_boundsÚ
shape_listÚstable_softmax)ÚModelOutputÚadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )Ú	LEDConfigzallenai/led-base-16384r   g    „×—Ác           
     óö  — t        j                  || j                  «      }t        j                  || j                  «      }t        j                  t	        | «      d   dft        j
                  || j                  «      «      }t        j                  || d d …d d…f   gd«      }t        j                  |dk(  t        j                  t	        |«      t        j
                  || j                  «      «      |«      }t         j                  j                  |t        j                  d| j                  ¬«      «      }t        j                  |g«      5  t        j                  |«      }d d d «       |S # 1 sw Y   |S xY w)Nr   r   éÿÿÿÿiœÿÿÿ©Údtype)ÚtfÚcastr    Úfillr   Úconvert_to_tensorÚconcatÚwhereÚ	debuggingÚassert_greater_equalÚconstantÚcontrol_dependenciesÚidentity)Ú	input_idsÚpad_token_idÚdecoder_start_token_idÚstart_tokensÚshifted_input_idsÚassert_gte0s         úe/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/led/modeling_tf_led.pyÚshift_tokens_rightr3   <   s8  € Ü—7‘7˜<¨¯©Ó9€LÜŸW™WÐ%;¸Y¿_¹_ÓMÐÜ—7‘7Ü	�IÓ	˜qÑ	! 1Ð%¤r×';Ñ';Ð<RÐT]×TcÑTcÓ'dó€Lô Ÿ	™	 <°º1¸c¸r¸c¸6Ñ1BÐ"CÀRÓHÐäŸ™Ø˜TÑ!Ü
�‰”
Ð,Ó-¬r×/CÑ/CÀLÐR[×RaÑRaÓ/bÓcØóÐô —,‘,×3Ñ3Ð4EÄrÇ{Á{ÐSTÐ\e×\kÑ\kÔGlÓm€Kô 
×	 Ñ	  + Ó	/ñ ;ÜŸK™KÐ(9Ó:Ð÷;ð Ð÷;ð Ðús   ÅE.Å.E8c           	     óÂ  — | d   }| d   }t        j                  ||f«      t        z  }t        j                  t	        |«      d   «      }t        j
                  |t        j                  |dz   t	        |«      d   df«      k  d|«      }|dkD  r.t        j                  t        j                  ||f«      |gd¬«      }t        j                  |dddd…dd…f   |dddf«      S )zB
    Make causal mask used for bi-directional self-attention.
    r   r   r   ç        ©ÚaxisN)
r!   ÚonesÚLARGE_NEGATIVEÚranger   r&   Úreshaper%   ÚzerosÚtile)Úinput_ids_shapeÚpast_key_values_lengthÚbszÚtgt_lenÚmaskÚ	mask_conds         r2   Ú_make_causal_maskrD   U   sÔ   € ð ˜!Ñ
€CØ˜aÑ €GÜ�7‰7�G˜WÐ%Ó&¬Ñ7€DÜ—‘œ DÓ)¨"Ñ-Ó.€Iä�8‰8�I¤§
¡
¨9°q©=¼:ÀdÓ;KÈBÑ;OÐQRÐ:SÓ TÑTÐVYÐ[_Ó`€Dà Ò!Ü�y‰yœ"Ÿ(™( GÐ-CÐ#DÓEÀtÐLÐSUÔVˆä�7‰7�4˜˜d¢A¢qÐ(Ñ)¨C°°A°q¨>Ó:Ð:ó    c                óø   — t        | «      d   }|�|n|}t        j                  d«      }t        j                  | |j                  ¬«      } t        j
                  | dd…dddd…f   dd|df«      }||z
  t        z  S )z_
    Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
    r   Ng      ð?r   )r   r!   r)   r"   r    r=   r9   )rB   rA   Úsrc_lenÚone_cstÚexpanded_masks        r2   Ú_expand_maskrJ   g   sx   € ô ˜Ó˜qÑ!€GØ Ð,‰g°'€GÜ�k‰k˜#Ó€GÜ�7‰7�4˜wŸ}™}Ô-€DÜ—G‘G˜D¢ D¨$²Ð!1Ñ2°Q¸¸7ÀAÐ4FÓG€Mà�mÑ#¤~Ñ5Ð5rE   c                  ó2   ‡ — e Zd ZdZdˆ fd„Zddˆ fd„Zˆ xZS )ÚTFLEDLearnedPositionalEmbeddingzN
    This module learns positional embeddings up to a fixed maximum size.
    c                ó(   •— t        ‰| �  ||fi |¤Ž y ©N)ÚsuperÚ__init__)ÚselfÚnum_embeddingsÚembedding_dimÚkwargsÚ	__class__s       €r2   rP   z(TFLEDLearnedPositionalEmbedding.__init__y   s   ø€ Ü‰Ñ˜¨ÑA¸&ÓArE   c                ó¬   •— |d   }t        j                  |dd¬«      }||z  }t        ‰| �  t        j                  |t         j
                  ¬«      «      S )z/Input is expected to be of size [bsz x seqlen].r   r:   )ÚdeltaÚnamer   )r!   r:   rO   Úcallr"   Úint32)rQ   Úinput_shaper?   Úseq_lenÚposition_idsrU   s        €r2   rY   z$TFLEDLearnedPositionalEmbedding.call|   sG   ø€ à˜a‘.ˆÜ—x‘x ¨q°wÔ?ˆØÐ.Ñ.ˆä‰w‰|œBŸG™G L¼¿¹ÔAÓBÐBrE   )rR   ÚintrS   r^   ©r   )r[   útf.TensorShaper?   r^   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__rP   rY   Ú__classcell__©rU   s   @r2   rL   rL   t   s   ø„ ñõB÷Cò CrE   rL   c                  ó¤   ‡ — e Zd Zˆ fd„Zdd„Z	 dd„Zd„ Zed„ «       Zd„ Z	ed„ «       Z
ed„ «       Zed	„ «       Zed
„ «       Zd„ Zd„ Zd„ Zd„ Zˆ xZS )ÚTFLEDEncoderSelfAttentionc                óø  •— t        ‰| �  di |¤Ž || _        |j                  |j                  z  dk7  r%t        d|j                  › d|j                  › �«      ‚|j                  | _        t        |j                  |j                  z  «      | _        |j                  | _	        t        j                  j                  | j                  t        |j                  «      d¬«      | _        t        j                  j                  | j                  t        |j                  «      d¬«      | _        t        j                  j                  | j                  t        |j                  «      d¬«      | _        t        j                  j                  | j                  t        |j                  «      d¬«      | _        t        j                  j                  | j                  t        |j                  «      d	¬«      | _        t        j                  j                  | j                  t        |j                  «      d
¬«      | _        t        j                  j+                  |j,                  «      | _        t        j                  j+                  |j,                  «      | _        || _        |j4                  | j2                     }|dz  dk(  sJ d| j2                  › d|› �«       ‚|dkD  sJ d| j2                  › d|› �«       ‚|dz  | _        y )Nr   zThe hidden size (z6) is not a multiple of the number of attention heads (Úquery)Úkernel_initializerrX   ÚkeyÚvalueÚquery_globalÚ
key_globalÚvalue_globalé   z`attention_window` for layer z  has to be an even value. Given z has to be positive. Given © )rO   rP   ÚconfigÚhidden_sizeÚnum_attention_headsÚ
ValueErrorÚ	num_headsr^   Úhead_dimÚ	embed_dimr   ÚlayersÚDenser   Úinitializer_rangerk   rm   rn   ro   rp   rq   ÚDropoutÚattention_probs_dropout_probÚdropoutÚglobal_dropoutÚlayer_idÚattention_windowÚone_sided_attn_window_size)rQ   rt   r‚   rT   rƒ   rU   s        €r2   rP   z"TFLEDEncoderSelfAttention.__init__‡   s   ø€ Ü‰ÑÑ"˜6Ò"ØˆŒà×Ñ × :Ñ :Ñ:¸aÒ?ÜØ# F×$6Ñ$6Ð#7ð 8Ø ×4Ñ4Ð5ð7óð ð
  ×3Ñ3ˆŒÜ˜F×.Ñ.°×1KÑ1KÑKÓLˆŒØ×+Ñ+ˆŒÜ—\‘\×'Ñ'Ø�N‰NÜ.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô
 —<‘<×%Ñ%Ø�N‰NÜ.¨v×/GÑ/GÓHØð &ó 
ˆŒô
 —\‘\×'Ñ'Ø�N‰NÜ.¨v×/GÑ/GÓHØð (ó 
ˆŒ
ô "ŸL™L×.Ñ.Ø�N‰NÜ.¨v×/GÑ/GÓHØð /ó 
ˆÔô
  Ÿ,™,×,Ñ,Ø�N‰NÜ.¨v×/GÑ/GÓHØð -ó 
ˆŒô
 "ŸL™L×.Ñ.Ø�N‰NÜ.¨v×/GÑ/GÓHØð /ó 
ˆÔô
 —|‘|×+Ñ+¨F×,OÑ,OÓPˆŒÜ#Ÿl™l×2Ñ2°6×3VÑ3VÓWˆÔØ ˆŒØ!×2Ñ2°4·=±=ÑAÐà !Ñ# qÒ(ð 	
Ø+¨D¯M©M¨?Ð:ZÐ[kÐZlÐmó	
Ð(ð   !Ò#ð 	
Ø+¨D¯M©M¨?Ð:UÐVfÐUgÐhó	
Ð#ð +;¸aÑ*?ˆÕ'rE   c                óL  — | j                   sêt        j                  d«      5  | j                  j	                  | j
                  j                  f«       d d d «       t        j                  d«      5  | j                  j	                  | j
                  j                  f«       d d d «       t        j                  d«      5  | j                  j	                  | j
                  j                  f«       d d d «       | j                   ry d| _         t        | dd «      �dt        j                  | j                  j                  «      5  | j                  j	                  d d | j
                  j                  g«       d d d «       t        | dd «      �dt        j                  | j                  j                  «      5  | j                  j	                  d d | j
                  j                  g«       d d d «       t        | dd «      �dt        j                  | j                  j                  «      5  | j                  j	                  d d | j
                  j                  g«       d d d «       t        | dd «      �dt        j                  | j                  j                  «      5  | j                  j	                  d d | j
                  j                  g«       d d d «       t        | dd «      �dt        j                  | j                  j                  «      5  | j                  j	                  d d | j
                  j                  g«       d d d «       t        | dd «      �et        j                  | j                  j                  «      5  | j                  j	                  d d | j
                  j                  g«       d d d «       y y # 1 sw Y   �ŒbxY w# 1 sw Y   �Œ!xY w# 1 sw Y   �ŒàxY w# 1 sw Y   �ŒhxY w# 1 sw Y   �ŒxY w# 1 sw Y   �Œ xY w# 1 sw Y   �Œ<xY w# 1 sw Y   Œ×xY w# 1 sw Y   y xY w)Nro   rp   rq   Trk   rm   rn   )Úbuiltr!   Ú
name_scopero   Úbuildrt   ru   rp   rq   Úgetattrrk   rX   rm   rn   ©rQ   r[   s     r2   rˆ   zTFLEDEncoderSelfAttention.buildÂ   s=  € Ø�zŠzÜ—‘˜~Ó.ñ DØ×!Ñ!×'Ñ'¨¯©×)@Ñ)@Ð(BÔC÷Dä—‘˜|Ó,ñ BØ—‘×%Ñ% t§{¡{×'>Ñ'>Ð&@ÔA÷Bä—‘˜~Ó.ñ DØ×!Ñ!×'Ñ'¨¯©×)@Ñ)@Ð(BÔC÷Dð �:Š:ØØˆŒ
Ü�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ FØ—‘—‘  d¨D¯K©K×,CÑ,CÐDÔE÷Fä�4˜ $Ó'Ð3Ü—‘˜tŸz™zŸ™Ó/ñ HØ—
‘
× Ñ  $¨¨d¯k©k×.EÑ.EÐ!FÔG÷Hä�4˜¨Ó.Ð:Ü—‘˜t×0Ñ0×5Ñ5Ó6ñ OØ×!Ñ!×'Ñ'¨¨t°T·[±[×5LÑ5LÐ(MÔN÷Oä�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ MØ—‘×%Ñ% t¨T°4·;±;×3JÑ3JÐ&KÔL÷Mä�4˜¨Ó.Ð:Ü—‘˜t×0Ñ0×5Ñ5Ó6ñ OØ×!Ñ!×'Ñ'¨¨t°T·[±[×5LÑ5LÐ(MÔN÷Oð Oð ;÷3Dñ Dú÷Bñ Bú÷Dñ Dú÷Hñ Hú÷Fñ Fú÷Hñ Hú÷Oñ Oú÷Mð Mú÷Oð Oúsk   ¢1N3Á01O Â>1OÅ3OÆ23O'È#3O4Ê3PÌ3PÍ63PÎ3N=Ï O
ÏOÏO$Ï'O1Ï4O>ÐPÐPÐP#c                óø
  — |\  }}}}}}| j                  |«      }	| j                  |«      }
| j                  |«      }t        |«      \  }}}t        j
                  j                  || j                  d| j                  › d|› �¬«       |	t        j                  j                  t	        j                  | j                  |	j                  ¬«      «      z  }	t	        j                  |	||| j                  | j                  f«      }	t	        j                  |
||| j                  | j                  f«      }
| j                  |	|
| j                   «      }|dk7  }t	        j                  ||	j                  ¬«      t"        z  }| j                  t	        j$                  t        |«      «      || j                   «      }||z  }t        j
                  j                  t        |«      ||| j                  | j                   dz  dz   gd|› d	|› d	| j                  › d	| j                   dz  dz   › d
t        |«      › �
¬«       | j'                  |«      \  }}}}|r| j)                  ||	|
||||¬«      }t+        |d¬«      }|rCt	        j,                  |dd…dd…ddf   dd| j                  | j                   dz  |z   dz   f«      }n?t	        j,                  |dd…dd…ddf   dd| j                  | j                   dz  dz   f«      }t	        j.                  |t	        j0                  t        |«      |j                  ¬«      |«      }|�ht        j
                  j                  t        |«      | j                  gd| j                  › dt        |«      › �¬«       t	        j                  |d«      |z  }| j3                  ||¬«      }t	        j                  |||| j                  | j                  f«      }|r| j5                  |||||¬«      }n| j7                  ||| j                   «      }t        j
                  j                  t        |«      ||| j                  | j                  gd¬«       t	        j                  ||||f«      }|r| j9                  |||||||||¬«	      \  }}n#t	        j0                  || j                  ||f«      }|rCt	        j,                  |dd…dd…ddf   dd| j                  | j                   dz  |z   dz   f«      }n?t	        j,                  |dd…dd…ddf   dd| j                  | j                   dz  dz   f«      }t	        j.                  |t	        j0                  t        |«      |j                  ¬«      |«      }|||f}|S )a¦  
        LongformerSelfAttention expects *len(hidden_states)* to be multiple of *attention_window*. Padding to
        *attention_window* happens in LongformerModel.forward to avoid redoing the padding on each layer.

        The *attention_mask* is changed in [`LongformerModel.forward`] from 0, 1, 2 to:

            - -10000: no attention
            - 0: local attention
            - +10000: global attention
        z&hidden_states should have embed_dim = z
, but has ©Úmessager   r   rr   r   zattn_probs should be of size (z, z), but is of size )Úattn_scoresÚquery_vectorsÚkey_vectorsÚmax_num_global_attn_indicesÚis_index_global_attn_nonzeroÚ"is_local_index_global_attn_nonzeroÚ%is_local_index_no_global_attn_nonzeror   r6   Nú/Head mask for a single layer should be of size ú	, but is )r   r   r   r   ©Útraining)Úvalue_vectorsÚ
attn_probsr‘   r’   r“   zUnexpected size)	Úattn_outputÚhidden_statesr‘   Úlayer_head_maskr“   r’   r”   Úis_index_maskedr˜   )rk   rm   rn   r   r!   r'   Úassert_equalrz   ÚmathÚsqrtr"   ry   r    r;   rx   Ú _sliding_chunks_query_key_matmulr„   r9   r8   Ú_get_global_attn_indicesÚ"_concat_with_global_key_attn_probsr   r=   r&   r<   r€   Ú(_compute_attn_output_with_global_indicesÚ'_sliding_chunks_matmul_attn_probs_valueÚ'_compute_global_attn_output_from_hidden)rQ   Úinputsr˜   rœ   Úattention_maskr�   rž   Úis_index_global_attnÚis_global_attnr�   r�   r™   Ú
batch_sizer\   rz   rŽ   Ú#remove_from_windowed_attention_maskÚ
float_maskÚdiagonal_maskr‘   r’   r“   r”   rš   Úmasked_indexr›   Úglobal_attn_probsÚmasked_global_attn_indexÚoutputss                                r2   rY   zTFLEDEncoderSelfAttention.callá   sš  € ð. ñ	
ØØØØØ Øð Ÿ
™
 =Ó1ˆØ—h‘h˜}Ó-ˆØŸ
™
 =Ó1ˆÜ)3°MÓ)BÑ&ˆ
�G˜Yä
�‰×!Ñ!ØØ�N‰NØ<¸T¿^¹^Ð<LÈJÐW`ÐVaÐbð 	"ô 	
ð 	œŸ™Ÿ™¤b§g¡g¨d¯m©mÀ=×CVÑCVÔ&WÓXÑXˆÜŸ
™
 =°:¸wÈÏÉÐX\×XeÑXeÐ2fÓgˆÜ—j‘j ¨z¸7ÀDÇNÁNÐTX×TaÑTaÐ.bÓcˆð ×;Ñ;Ø˜;¨×(GÑ(Gó
ˆð
 /=ÀÑ.AÐ+ä—W‘WÐ@È×H[ÑH[Ô\Ô_mÑmˆ
ð ×=Ñ=Ü�G‰G”J˜~Ó.Ó/ØØ×+Ñ+ó
ˆð 	�}Ñ$ˆä
�‰×!Ñ!Ü�{Ó#Ø˜ $§.¡.°$×2QÑ2QÐTUÑ2UÐXYÑ2YÐZà0°°¸B¸w¸iÀrÈ$Ï.É.ÐIYð ZØ×3Ñ3°aÑ7¸!Ñ;Ð<Ð<NÌzÐZeÓOfÐNgðið	 	"ô 	
ð ×)Ñ)Ð*>Ó?ñ	
Ø'Ø(Ø.Ø1ñ Ø×AÑAØ'Ø+Ø'Ø,GØ-IØ3UØ6[ð Bó ˆKô $ K°bÔ9ˆ
ñ ÜŸ7™7Ø¢¢1 d¨DÐ 0Ñ1Ø�A�t—~‘~ t×'FÑ'FÈÑ'JÐMhÑ'hÐklÑ'lÐmó‰Lô
 Ÿ7™7Ø¢¢1 d¨DÐ 0Ñ1Ø�A�t—~‘~ t×'FÑ'FÈÑ'JÈQÑ'NÐOóˆLô —X‘XØÜ�H‰H”Z Ó-°Z×5EÑ5EÔFØó
ˆ
ð Ð&Ü�L‰L×%Ñ%Ü˜?Ó+Ø—‘Ð àEÀtÇ~Á~ÐEWð XÜ" ?Ó3Ð4ð6ð	 &ô ô Ÿ™ O°]ÓCÀjÑPˆJð —\‘\ *°x�\Ó@ˆ
ÜŸ
™
 =°:¸wÈÏÉÐX\×XeÑXeÐ2fÓgˆñ Ø×GÑGØ+Ø%Ø,GØ-IØ3Uð Hó ‰Kð ×FÑFØ˜M¨4×+JÑ+JóˆKô 	�‰×!Ñ!Ü�{Ó# j°'¸4¿>¹>È4Ï=É=Ð%YÐctð 	"ô 	
ô —j‘j ¨z¸7ÀIÐ.NÓOˆñ Ø-1×-YÑ-YØ'Ø+Ø,GØ /Ø3UØ-IØ6[Ø /Ø!ð .Zó 
.Ñ*ˆKÑ*ô !#§¡¨*°d·n±nÐFaÐcjÐ)kÓ lÐñ Ü')§w¡wØ$¢Qª¨4°Ð%5Ñ6Ø�A�t—~‘~ t×'FÑ'FÈÑ'JÐMhÑ'hÐklÑ'lÐmó(Ñ$ô
 (*§w¡wØ$¢Qª¨4°Ð%5Ñ6Ø�A�t—~‘~ t×'FÑ'FÈÑ'JÈQÑ'NÐOó(Ð$ô —X‘XØ$Ü�H‰H”ZÐ 8Ó9À×AQÑAQÔRØó
ˆ
ð  
Ð,=Ð>ˆàˆrE   c           
     óŒ  — t        |«      \  }}}}t        j                  j                  ||dz  z  dd|dz  › d|› �¬«       t        j                  j                  t        |«      t        |«      dt        |«      › dt        |«      › �¬«       ||z  dz
  }t        j                  t        j
                  |d	«      ||z  ||f«      }t        j                  t        j
                  |d	«      ||z  ||f«      }| j                  ||«      }	| j                  ||«      }
t        j                  |	|
j                  ¬
«      }	t        j                  d|	|
«      }t        j                  ddgddgddgddgg«      }| j                  ||«      }t        j                  |dd…dd…d|…d|dz   …f   |dd…dd…|d…d|dz   …f   gd¬«      }t        j                  t        j                  ||z  d||f|j                  ¬
«      |dd…dd…|dz    d…|dz   d…f   gd¬«      }t        j                  t        j                  |d|gddg¬«      dd…dd…d|…d|…f   t        j                  ||z  d||f|j                  ¬
«      gd¬«      }t        j                  t        j                   |dz   t        j"                  ¬
«      ddd…ddf   ||z  d||f«      dk  }t        j$                  |||«      }t        j                  ||gd¬«      }t        j
                  t        j                  ||||d|z  dz   f«      d	«      }| j'                  ||«      }|S )a  
        Matrix multiplication of query and key tensors using with a sliding window attention pattern. This
        implementation splits the input into overlapping chunks of size 2w (e.g. 512 for pretrained Longformer) with an
        overlap of size window_overlap
        rr   r   z&Sequence length should be multiple of z. Given rŒ   z7Shape of query and key should be equal, but got query: z
 and key: r   ©r   rr   r   r	   r   zbcxd,bcyd->bcxyNr   r6   r	   )Úshiftr7   )r   r!   r'   rŸ   r;   Ú	transposeÚ_chunkr"   r    Úeinsumr$   Ú _pad_and_transpose_last_two_dimsr%   r<   Úrollr=   r:   Úint64r&   Ú_mask_invalid_locations)rQ   rk   rm   Úwindow_overlapr¬   r\   rx   ry   Úchunks_countÚchunked_queryÚchunked_keyÚchunked_attention_scoresÚpaddingsÚ!diagonal_chunked_attention_scoresÚdiagonal_attn_scores_up_triangÚdiagonal_attn_scores_low_triangÚ diagonal_attn_scores_first_chunkÚfirst_chunk_maskÚdiagonal_attention_scoress                      r2   r¢   z:TFLEDEncoderSelfAttention._sliding_chunks_query_key_matmul   s¾  € ô 4>¸eÓ3DÑ0ˆ
�G˜Y¨ä
�‰×!Ñ!Ø�~¨Ñ)Ñ*ØØ<¸^ÈaÑ=OÐ<PÐPXÐY`ÐXaÐbð 	"ô 	
ô
 	�‰×!Ñ!Ü�uÓÜ�s‹OàIÌ*ÐUZÓJ[ÐI\ð ]Ü˜s“OÐ$ð&ð	 	"ô 	
ð  .Ñ0°1Ñ4ˆô —
‘
Ü�L‰L˜ Ó-Ø˜)Ñ# W¨hÐ7ó
ˆô �j‰jœŸ™ c¨<Ó8¸:È	Ñ;QÐSZÐ\dÐ:eÓfˆØŸ™ E¨>Ó:ˆØ—k‘k # ~Ó6ˆô Ÿ™ °[×5FÑ5FÔGˆÜ#%§9¡9Ð->ÀÈ{Ó#[Ð ô ×'Ñ'¨!¨Q¨°!°Q°¸!¸Q¸À!ÀQÀÐ(HÓIˆØ,0×,QÑ,QÐRjÐltÓ,uÐ)ô *,¯©à1²!²Q¸¸¸ÐI]È>Ð\]ÑK]ÐI]Ð2]Ñ^Ø1²!°R±S¸.¹/ÐK_È^Ð^_ÑM_ÐK_Ð2_Ñ`ðð ô*
Ð&ô +-¯)©)ä—‘Ø )Ñ+¨Q°ÀÐOØ;×AÑAôð 2²!²Q¸.È1Ñ:LÐ8MÐPRÐ8RÐTbÐefÑTfÑThÐ2hÑiðð ô	+
Ð'ô ,.¯9©9ä—‘Ø5Ø˜nÐ-Ø˜Q˜ôò ’Q˜˜˜¨¨.¨Ð8ñ	:ô
 —‘Ø )Ñ+¨Q°ÀÐOØ;×AÑAôð
ð ô,
Ð(ô �G‰GÜ—‘˜¨Ñ)´·±Ô:¸4ÂÀDÈ$Ð;NÑOØ˜iÑ'¨¨N¸NÐKóð ñ	ð 	ô +-¯(©(ØØ,Ø+ó+
Ð'ô %'§I¡IØ,Ð.LÐMÐTVô%
Ð!ô
 %'§L¡LÜ�J‰JØ)Ø˜Y¨°°^Ñ1CÀaÑ1GÐHóð ó%
Ð!ð %)×$@Ñ$@ÐAZÐ\jÓ$kÐ!à(Ð(rE   c           	     ó’  — t        j                  t         j                  j                  t        j                  ||dz   f¬«      dd«      dg¬«      }t        j
                  dt        | «      d   |z
  gdt        | «      d   |z
  dz
  gg«      }t        j                  ||«      }|t        j                  |ddg¬«      z   }t        j                  |d d d …d d d …f   t        | «      d   dddf«      }t        d«       t        j                  | «      z  }t        j                  t         j                  j                  |d«      || «      } | S )Nr   ©Úshaper   r   r6   r	   Úinf)r!   ÚreverseÚlinalgÚ	band_partr8   r$   r   Úpadr=   ÚfloatÚ	ones_liker&   r    Úgreater)Úinput_tensorr¾   Úmask_2d_upperÚpaddingÚmask_2dÚmask_4dÚ
inf_tensors          r2   r½   z1TFLEDEncoderSelfAttention._mask_invalid_locations  s4  € ô Ÿ
™
Ü�I‰I×Ñ¤§¡¨~¸~ÐPQÑ?QÐ.RÔ SÐUWÐYZÓ[Ø�ô
ˆô ×&Ñ&Ø”˜LÓ)¨!Ñ,¨~Ñ=Ð>ÀÄJÈ|ÓD\Ð]^ÑD_ÐbpÑDpÐstÑDtÐ@uÐvó
ˆô
 —&‘&˜¨Ó0ˆð œBŸJ™J w°a¸°VÔ<Ñ<ˆô —'‘'˜' $ª¨4²Ð"2Ñ3´jÀÓ6NÈqÑ6QÐSTÐVWÐYZÐ5[Ó\ˆô ˜E“l�]¤R§\¡\°,Ó%?Ñ?ˆ
ô —x‘x¤§¡§¡°¸Ó ;¸ZÈÓVˆàÐrE   c           	     ó¶  — t        |«      \  }}}}t        j                  j                  ||dz  z  dd¬«       t        j                  j                  t        |«      dd t        |«      dd d¬«       t        j                  j                  t        |«      d   d|z  dz   d	¬«       ||z  dz
  }t        j                  t        j
                  |d
«      ||z  ||z  |d|z  dz   f«      }	t        j                  t        j
                  |d
«      ||z  ||f«      }t        j                  ddg||gddgg«      }
t        j                  ||
d¬«      }d|z  |z  }t        |«      d   |z  |z
  |z  }t        j                  j                  t        j                  |||z  df«      ||«      }t        j                  |||z  |dz   d|z  |f«      }t        j                  j                  t        |«      ||z  |dz   d|z  |gd¬«       | j                  |	«      }	t        j                  d|	|«      }t        j
                  t        j                  |||||f«      d
«      }|S )z¢
        Same as _sliding_chunks_query_key_matmul but for attn_probs and value tensors. Returned tensor will be of the
        same shape as `attn_probs`
        rr   r   z0Seq_len has to be multiple of 2 * window_overlaprŒ   Nr	   z:value and attn_probs must have same dims (except head_dim)r   z4attn_probs last dim has to be 2 * window_overlap + 1rµ   r   ©Úconstant_valuesz!Chunked value has the wrong shapezbcwd,bcdh->bcwh)r   r!   r'   rŸ   r;   r·   r$   rÑ   ÚsignalÚframeÚ_pad_and_diagonalizer¹   )rQ   rš   rn   r¾   r¬   r\   rx   ry   r¿   Úchunked_attn_probsrÃ   Úpadded_valueÚ
frame_sizeÚframe_hop_sizeÚchunked_valueÚcontexts                   r2   r¦   zATFLEDEncoderSelfAttention._sliding_chunks_matmul_attn_probs_value2  s‘  € ô 4>¸eÓ3DÑ0ˆ
�G˜Y¨ä
�‰×!Ñ!Ø�~¨Ñ)Ñ*¨AÐ7ið 	"ô 	
ô 	�‰×!Ñ!Ü�zÓ" 2 AÐ&Ü�uÓ˜b˜qÐ!ØPð 	"ô 	
ô
 	�‰×!Ñ!Ü�zÓ" 1Ñ%Ø�Ñ Ñ"ØJð 	"ô 	
ð  .Ñ0°1Ñ4ˆô  ŸZ™ZÜ�L‰L˜ \Ó2à˜YÑ&Ø˜>Ñ)ØØ�NÑ" QÑ&ð	ó
Ðô —
‘
Ü�L‰L˜ Ó-Ø˜)Ñ# W¨hÐ7ó
ˆô ×'Ñ'¨!¨Q¨°.À.Ð1QÐTUÐWXÐSYÐ(ZÓ[ˆÜ—v‘v˜e X¸rÔBˆð ˜Ñ'¨(Ñ2ˆ
Ü$ \Ó2°1Ñ5¸Ñ@À:ÑMÐR^Ñ^ˆÜŸ	™	Ÿ™Ü�J‰J�| j°9Ñ&<¸bÐ%AÓBØØó
ˆô
 Ÿ
™
ØØ˜)Ñ# \°AÑ%5°q¸>Ñ7IÈ8ÐTó
ˆô
 	�‰×!Ñ!Ü�}Ó%Ø˜)Ñ# \°AÑ%5°q¸>Ñ7IÈ8ÐTØ7ð 	"ô 	
ð "×6Ñ6Ð7IÓJÐÜ—)‘)Ð-Ð/AÀ=ÓQˆÜ—,‘,Ü�J‰J�w ¨Y¸ÀÐ JÓKØó
ˆð
 ˆrE   c                ó†   — t        j                  | |«      } t        | «      \  }}}}t        j                  | ||||f«      } | S )z)pads rows and then flips rows and columns)r!   rÑ   r   r;   )Úhidden_states_paddedrÃ   r¬   Ú
chunk_sizeÚ
seq_lengthÚ
hidden_dims         r2   rº   z:TFLEDEncoderSelfAttention._pad_and_transpose_last_two_dims{  sR   € ô  "Ÿv™vØ  (ó 
Ðô :DÐDXÓ9YÑ6ˆ
�J 
¨JÜ!Ÿz™zÐ*>ÀÈZÐYcÐeoÐ@pÓqÐà#Ð#rE   c                óF  — t        | «      \  }}}}t        j                  ddgddgddgd|dz   gg«      }t        j                  | |«      } t        j                  | ||df«      } | dd…dd…d| …f   } t        j                  | |||||z   f«      } | dd…dd…dd…dd…f   } | S )aY  
        shift every row 1 step right, converting columns into diagonals.

        Example:

        ```python
        chunked_hidden_states: [
            0.4983,
            2.6918,
            -0.0071,
            1.0492,
            -1.8348,
            0.7672,
            0.2986,
            0.0285,
            -0.7584,
            0.4206,
            -0.0405,
            0.1599,
            2.0514,
            -1.1600,
            0.5372,
            0.2629,
        ]
        window_overlap = num_rows = 4
        ```

                     (pad & diagonalize) => [ 0.4983, 2.6918, -0.0071, 1.0492, 0.0000, 0.0000, 0.0000
                       0.0000, -1.8348, 0.7672, 0.2986, 0.0285, 0.0000, 0.0000 0.0000, 0.0000, -0.7584, 0.4206,
                       -0.0405, 0.1599, 0.0000 0.0000, 0.0000, 0.0000, 2.0514, -1.1600, 0.5372, 0.2629 ]
        r   r   r   N)r   r!   r$   rÑ   r;   )Úchunked_hidden_statesÚtotal_num_headsÚ
num_chunksr¾   rë   rÃ   s         r2   rà   z.TFLEDEncoderSelfAttention._pad_and_diagonalize†  sß   € ôB CMÐMbÓBcÑ?ˆ˜ ^°ZÜ×'Ñ'¨!¨Q¨°!°Q°¸!¸Q¸À!À^ÐVWÑEWÐAXÐ(YÓZˆÜ "§¡Ø! 8ó!
Ðô !#§
¡
Ø! O°ZÀÐ#Dó!
Ðð !6ÚŠqÐ"�N�?Ð"Ð"ñ!
Ðô !#§
¡
Ø!Ø˜j¨.¸.È:Ñ:UÐVó!
Ðð !6²aººA¸sÀ¸s°lÑ CÐà$Ð$rE   c           
     óˆ  — t        | «      \  }}}d|d|z  z  z  dz
  }||z  }d|z  }t        j                  | |||z  f«      } t        j                  j	                  | ||«      }t        j
                  j                  t        |«      |||gd|||g› dt        |«      › d�¬«       t        j                  |||d|z  |f«      }|S )zBconvert into overlapping chunks. Chunk size = 2w, overlap size = wrr   r   z^Make sure chunking is correctly applied. `Chunked hidden states should have output  dimension z
, but got ú.rŒ   )r   r!   r;   rÞ   rß   r'   rŸ   )	rœ   r¾   r¬   rê   rë   Únum_output_chunksrä   rã   rí   s	            r2   r¸   z TFLEDEncoderSelfAttention._chunkº  sú   € ô .8¸Ó-FÑ*ˆ
�J 
Ø °°NÑ0BÑ!CÑDÀqÑHÐð (¨*Ñ4ˆØ˜Ñ'ˆ
ÜŸ
™
 =°:¸zÈJÑ?VÐ2WÓXˆô !#§	¡	§¡°¸zÈ>Ó ZÐä
�‰×!Ñ!ÜÐ,Ó-ØÐ*¨JÐ7ðØ Ð->Ð?Ð@À
Ì:ÐVkÓKlÐJmÐmnðpð	 	"ô 	
ô !#§
¡
Ø!ØÐ*¨A°Ñ,>À
ÐKó!
Ðð
 %Ð$rE   c                óô  — t         j                  j                  | d¬«      }t        j                  |t        j                  d«      j
                  ¬«      }t        j                  |«      }t        j                  | «      }t        j                  |«      t        j                  |d¬«      k  }t        j                  |«      }t        j                  t         j                  j                  |«      «      }||||fS )z<compute global attn indices required throughout forward passr   r6   r   r   )r!   r    Úcount_nonzeror"   r)   r    Ú
reduce_maxr&   r:   Úexpand_dimsÚlogical_not)rª   Únum_global_attn_indicesr‘   r’   Úis_local_index_global_attnr“   r”   s          r2   r£   z2TFLEDEncoderSelfAttention._get_global_attn_indicesØ  sØ   € ô #%§'¡'×"7Ñ"7Ð8LÐSTÐ"7Ó"UÐÜ"$§'¡'Ð*AÌÏÉÐUVË×I]ÑI]Ô"^Ðô ')§m¡mÐ4KÓ&LÐ#ô (*§x¡xÐ0DÓ'EÐ$ô &(§X¡XÐ.IÓ%JÌRÏ^É^Ø#¨"ôN
ñ &
Ð"ô
 .0¯X©XÐ6PÓ-QÐ*ô 13·±¼¿¹×9LÑ9LÐMgÓ9hÓ0iÐ-ð (Ø(Ø.Ø1ð	
ð 	
rE   c                óT  — t        |«      d   }t        j                  ||«      }	t        j                  ||	||| j                  | j
                  f¬«      }
t        j                  d||
«      }t        j                  |d«      }t        |«      d   ft        t        |«      dd  «      z   }t        j                  |«      dz  }t        j                  ||j                  ¬«      }t        j                  |||«      }t        j                  |d«      }t        j                  ||fd	¬
«      }|S )Nr   rË   zblhd,bshd->blhs)r   r	   r   rr   éþÿÿÿç     ˆÃÀr   )r   rr   r	   r   r   r6   )r   r!   Ú	gather_ndÚ
scatter_ndrx   ry   r¹   r·   Útupler8   r"   r    Útensor_scatter_nd_updater%   )rQ   rŽ   r�   r�   r‘   r’   r“   r”   r¬   Úglobal_key_vectorsÚkey_vectors_only_globalÚattn_probs_from_global_keyÚ attn_probs_from_global_key_transÚ
mask_shaperB   s                  r2   r¤   z<TFLEDEncoderSelfAttention._concat_with_global_key_attn_probs÷  s/  € ô   Ó,¨QÑ/ˆ
ô  Ÿ\™\¨+Ð7SÓTÐô #%§-¡-Ø.ØàØ+Ø—‘Ø—‘ð	ô	#
Ðô &(§Y¡YÐ/@À-ÐQhÓ%iÐ"ô ,.¯<©<Ð8RÐT`Ó+aÐ(Ü Ð!FÓGÈÑJÐLÌuÜÐ7Ó8¸¸Ð=óP
ñ 
ˆ
ô �w‰w�zÓ" XÑ-ˆÜ�w‰w�tÐ#C×#IÑ#IÔJˆô ,.×+FÑ+FØ,Ø1Øó,
Ð(ô &(§\¡\Ð2RÐT`Ó%aÐ"ô —i‘iÐ!;¸[Ð IÐPRÔSˆàÐrE   c                ó`  — t        |«      d   }|d d …d d …d d …d |…f   }t        j                  ||«      }t        j                  ||||| j                  | j
                  f¬«      }	t        j                  d||	«      }
|d d …d d …d d …|d …f   }| j                  ||| j                  «      }|
|z   S )Nr   rË   zblhs,bshd->blhd)	r   r!   rý   rþ   rx   ry   r¹   r¦   r„   )rQ   r™   rš   r‘   r’   r“   r¬   Úattn_probs_only_globalÚglobal_value_vectorsÚvalue_vectors_only_globalÚattn_output_only_globalÚattn_probs_without_globalÚattn_output_without_globals                r2   r¥   zBTFLEDEncoderSelfAttention._compute_attn_output_with_global_indices-  sÔ   € ô   
Ó+¨AÑ.ˆ
ð ",ªAªq²!Ð5QÐ6QÐ5QÐ,QÑ!RÐô  "Ÿ|™|¨MÐ;WÓXÐô %'§M¡MØ.Ø àØ+Ø—‘Ø—‘ð	ô	%
Ð!ô #%§)¡)Ð,=Ð?UÐWpÓ"qÐð %/ªq²!²QÐ8SÑ8TÐ/TÑ$UÐ!ð &*×%QÑ%QØ% }°d×6UÑ6Uó&
Ð"ð 'Ð)CÑCÐCrE   c
           
     óv	  — t        |«      d d \  }
}t        j                  ||«      }t        j                  |||
|| j                  f¬«      }| j                  |«      }| j                  |«      }| j                  |«      }|t        j                  j                  t        j                  | j                  |j                  ¬«      «      z  }| j                  ||
«      }| j                  ||
«      }| j                  ||
«      }t        j                  ||d¬«      }t        j                  j!                  t        |«      |
| j"                  z  ||gd|
| j"                  z  ||f› dt        |«      › d�¬	«       t        j$                  ||
| j"                  ||f«      }t        j&                  |d
«      }t        |«      d   ft)        t        |«      dd  «      z   }t        j*                  |«      dz  }t        j                  ||j                  ¬«      }t        j,                  |||«      }t        j&                  |d
«      }t        j.                  |d d …d d d d …f   dt        |«      d   ddf«      }t        j0                  |d|«      }t        j$                  ||
| j"                  z  ||f«      }t3        |d¬«      }|�°t        j                  j!                  t        |«      | j"                  gd| j"                  › dt        |«      › �¬	«       t        j$                  |d«      t        j$                  ||
| j"                  ||f«      z  }t        j$                  ||
| j"                  z  ||f«      }| j5                  ||	¬«      }t        j                  ||«      }t        j                  j!                  t        |«      |
| j"                  z  || j                  gd|
| j"                  z  || j                  f› dt        |«      › d�¬	«       t        j$                  ||
| j"                  || j                  f«      }t        j                  t        j&                  |d
«      |«      }t        j$                  |t        |«      d   df«      }t        j,                  |||«      }t        j$                  ||
| j"                  ||f«      }||fS )Nrr   rË   r   T©Útranspose_bz7global_attn_scores have the wrong size. Size should be r–   rñ   rŒ   rµ   r   rû   rü   r   r   r6   r•   ©r   r   r   r   r—   z=global_attn_output tensor has the wrong size. Size should be )r   r!   rý   rþ   rz   ro   rp   rq   r    r¡   r"   ry   r    Úreshape_and_transposeÚmatmulr'   rŸ   rx   r;   r·   rÿ   r8   r   r=   r&   r   r�   )rQ   r›   rœ   r‘   r�   r“   r’   r”   rž   r˜   r¬   r\   Úglobal_attn_hidden_statesÚ global_query_vectors_only_globalr  r  Úglobal_attn_scoresÚglobal_attn_scores_transr  Úglobal_attn_maskÚ	attn_maskÚglobal_attn_probs_floatr±   Úglobal_attn_outputÚnonzero_global_attn_outputs                            r2   r§   zATFLEDEncoderSelfAttention._compute_global_attn_output_from_hiddenV  sÜ  € ô )¨Ó7¸¸Ð;Ñˆ
�Gô %'§L¡L°Ð@\Ó$]Ð!Ü$&§M¡MØ.Ø%ØÐ:¸D¿N¹NÐKô%
Ð!ð ,0×+<Ñ+<Ð=VÓ+WÐ(Ø!Ÿ_™_¨]Ó;ÐØ#×0Ñ0°Ó?Ðð 	)¬B¯G©G¯L©LÜ�G‰G�D—M‘MÐ)I×)OÑ)OÔPó-
ñ 	
Ð(ð ,0×+EÑ+EÐFfÐhrÓ+sÐ(Ø!×7Ñ7Ð8JÈJÓWÐØ#×9Ñ9Ð:NÐPZÓ[Ðô  ŸY™YÐ'GÐI[ÐimÔnÐä
�‰×!Ñ!ÜÐ)Ó*Ø˜$Ÿ.™.Ñ(Ð*EÀwÐOðØ $§.¡.Ñ0Ð2MÈwÐWÐXð YÜÐ1Ó2Ð3°1ð6ð	 	"ô 	
ô  ŸZ™ZØØ˜Ÿ™Ð)DÀgÐNó
Ðô $&§<¡<Ð0BÀLÓ#QÐ Ü Ð!FÓGÈÑJÐLÌuÜÐ/Ó0°°Ð5óP
ñ 
ˆ
ô Ÿ7™7 :Ó.°Ñ9ÐÜŸ7™7Ð#3Ð;S×;YÑ;YÔZÐô $&×#>Ñ#>Ø$Ø1Øó$
Ð ô
  Ÿ\™\Ð*BÀLÓQÐô —G‘G˜OªA¨t°Tº1Ð,<Ñ=ÀÄ:ÐN`ÓCaÐbcÑCdÐfgÐijÐ?kÓlˆ	ÜŸX™X i°Ð;MÓNÐÜŸZ™ZØØ˜$Ÿ.™.Ñ(Ð*EÀwÐOó
Ðô #1Ð1CÈ"Ô"MÐð Ð&Ü�L‰L×%Ñ%Ü˜?Ó+Ø—‘Ð àEÀtÇ~Á~ÐEWð XÜ" ?Ó3Ð4ð6ð	 &ô ô ')§j¡j°À-Ó&PÔSU×S]ÑS]Ø'¨*°d·n±nÐFaÐcjÐ)kóTñ 'Ð#ô ')§j¡jØ'¨*°t·~±~Ñ*EÐGbÐdkÐ)ló'Ð#ð
 !×/Ñ/Ð0GÐRZÐ/Ó[Ðô  ŸY™YÐ'8Ð:NÓOÐä
�‰×!Ñ!ÜÐ)Ó*Ø˜$Ÿ.™.Ñ(Ð*EÀtÇ}Á}ÐUðØ $§.¡.Ñ0Ð2MÈtÏ}É}Ð]Ð^ð _ÜÐ1Ó2Ð3°1ð6ð	 	"ô 	
ô  ŸZ™ZØØ˜Ÿ™Ð)DÀdÇmÁmÐTó
Ðô &(§\¡\Ü�L‰LÐ+¨\Ó:Ø.ó&
Ð"ô &(§Z¡ZØ&ÜÐ:Ó;¸AÑ>ÀÐCó&
Ð"ô ×1Ñ1ØÐ5Ð7Qó
ˆô ŸJ™JØ 
¨D¯N©NÐ<WÐY`Ðaó
Ðð Ð-Ð-Ð-rE   c                óâ   — t        j                  t        j                  t        j                  ||d| j                  | j                  f«      d«      || j                  z  d| j                  f«      S )Nr   rµ   )r!   r;   r·   rx   ry   )rQ   Úvectorr¬   s      r2   r  z/TFLEDEncoderSelfAttention.reshape_and_transposeß  sZ   € Ü�z‰zÜ�L‰LÜ—
‘
˜6 J°°D·N±NÀDÇMÁMÐ#RÓSØóð ˜$Ÿ.™.Ñ(¨"¨d¯m©mÐ<ó
ð 	
rE   rN   ©F)rb   rc   rd   rP   rˆ   rY   r¢   Ústaticmethodr½   r¦   rº   rà   r¸   r£   r¤   r¥   r§   r  rf   rg   s   @r2   ri   ri   †   s©   ø„ ô9@óvOðD ó}ò~r)ðh ñó ðò:GðR ñ$ó ð$ð ñ1%ó ð1%ðf ñ%ó ð%ð: ñ
ó ð
ò<4òl'DòRG.öR
rE   ri   c                  ó.   ‡ — e Zd Zˆ fd„Zdd„Zdd„Zˆ xZS )ÚTFLEDEncoderAttentionc                óº   •— t        ‰| �  di |¤Ž t        ||d¬«      | _        t        j
                  j                  |j                  dd¬«      | _        || _	        y )NÚlongformer_self_attn)r‚   rX   TÚoutput©Úuse_biasrX   rs   )
rO   rP   ri   r#  r   r{   r|   Úd_modelÚoutput_densert   ©rQ   rt   r‚   rT   rU   s       €r2   rP   zTFLEDEncoderAttention.__init__ê  sO   ø€ Ü‰ÑÑ"˜6Ò"Ü$=¸fÈxÐ^tÔ$uˆÔ!Ü!ŸL™L×.Ñ.¨v¯~©~ÈÐS[Ð.Ó\ˆÔØˆ�rE   c                óˆ   — |\  }}}}}}| j                  ||||||g|¬«      }	| j                  |	d   |¬«      }
|
f|	dd  z   }|S )Nr—   r   r   )r#  r(  )rQ   r¨   r˜   rœ   r©   r�   rž   rª   r«   Úself_outputsÚattention_outputr³   s               r2   rY   zTFLEDEncoderAttention.callð  s   € ð ñ	
ØØØØØ Øð ×0Ñ0Ø˜N¨O¸_ÐNbÐdrÐsØð 1ó 
ˆð
  ×,Ñ,¨\¸!©_ÀxÐ,ÓPÐØ#Ð%¨°Q°RÐ(8Ñ8ˆàˆrE   c                óô  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �et        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       y y # 1 sw Y   Œ|xY w# 1 sw Y   y xY w)NTr#  r(  )
r†   r‰   r!   r‡   r#  rX   rˆ   r(  rt   r'  rŠ   s     r2   rˆ   zTFLEDEncoderAttention.build  sÔ   € Ø�:Š:ØØˆŒ
Ü�4Ð/°Ó6ÐBÜ—‘˜t×8Ñ8×=Ñ=Ó>ñ 6Ø×)Ñ)×/Ñ/°Ô5÷6ä�4˜¨Ó.Ð:Ü—‘˜t×0Ñ0×5Ñ5Ó6ñ KØ×!Ñ!×'Ñ'¨¨t°T·[±[×5HÑ5HÐ(IÔJ÷Kð Kð ;÷6ð 6ú÷Kð Kús   ÁC"Â%3C.Ã"C+Ã.C7r  rN   ©rb   rc   rd   rP   rY   rˆ   rf   rg   s   @r2   r!  r!  é  s   ø„ ôó÷(	KrE   r!  c                  óx   ‡ — e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Z	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 d
d„Zdd„Zˆ xZS )ÚTFLEDDecoderAttentionz6Multi-headed attention from "Attention Is All You Needc                óP  •— t        ‰| �  di |¤Ž || _        || _        t        j
                  j                  |«      | _        ||z  | _        | j                  |z  | j                  k(  sJ d«       ‚| j                  dz  | _	        || _
        t        j
                  j                  ||d¬«      | _        t        j
                  j                  ||d¬«      | _        t        j
                  j                  ||d¬«      | _        t        j
                  j                  ||d¬«      | _        y )	Nz(embed_dim must be divisible by num_headsg      à¿Úk_projr%  Úq_projÚv_projÚout_projrs   )rO   rP   rz   rx   r   r{   r~   r€   ry   ÚscalingÚ
is_decoderr|   r2  r3  r4  r5  )rQ   rz   rx   r€   r7  ÚbiasrT   rU   s          €r2   rP   zTFLEDDecoderAttention.__init__  sñ   ø€ ô 	‰ÑÑ"˜6Ò"Ø"ˆŒà"ˆŒÜ—|‘|×+Ñ+¨GÓ4ˆŒØ! YÑ.ˆŒØ�}‰}˜yÑ(¨D¯N©NÒ:ÐfÐ<fÓfÐ:Ø—}‘} dÑ*ˆŒØ$ˆŒä—l‘l×(Ñ(¨¸TÈÐ(ÓQˆŒÜ—l‘l×(Ñ(¨¸TÈÐ(ÓQˆŒÜ—l‘l×(Ñ(¨¸TÈÐ(ÓQˆŒÜŸ™×*Ñ*¨9¸tÈ*Ð*ÓUˆ�rE   c           	     ó†   — t        j                  t        j                  |||| j                  | j                  f«      d«      S )Nrµ   )r!   r·   r;   rx   ry   )rQ   Útensorr\   r@   s       r2   Ú_shapezTFLEDDecoderAttention._shape+  s0   € Ü�|‰|œBŸJ™J v°°W¸d¿n¹nÈdÏmÉmÐ/\Ó]Ð_kÓlÐlrE   c           
     óÈ	  — |du}t        |«      \  }}	}
| j                  |«      | j                  z  }|r|�|d   }|d   }�n
|rE| j                  | j	                  |«      d|«      }| j                  | j                  |«      d|«      }nÃ|�}| j                  | j	                  |«      d|«      }| j                  | j                  |«      d|«      }t        j                  |d   |gd¬«      }t        j                  |d   |gd¬«      }nD| j                  | j	                  |«      d|«      }| j                  | j                  |«      d|«      }| j                  r||f}|| j                  z  d| j                  f}t        j                  | j                  ||	|«      |«      }t        j                  ||«      }t        j                  ||«      }t        |«      d   }t        j                  ||d¬«      }t        j                  j                  t        |«      || j                  z  |	|gd	|| j                  z  |	|f› d
t        |«      › �¬«       |�®t        j                  j                  t        |«      |d|	|gd|d|	|f› d
t        |«      › �¬«       t        j                  ||| j                  |	|f«      t        j                  ||j                   ¬«      z   }t        j                  ||| j                  z  |	|f«      }t#        |d¬«      }|�°t        j                  j                  t        |«      | j                  gd| j                  › d
t        |«      › �¬«       t        j                  |d«      t        j                  ||| j                  |	|f«      z  }t        j                  ||| j                  z  |	|f«      }| j%                  ||¬«      }t        j                  ||«      }t        j                  j                  t        |«      || j                  z  |	| j                  gd|| j                  |	| j                  f› d
t        |«      › �¬«       t        j&                  t        j                  ||| j                  |	| j                  f«      d«      }t        j                  |||	|
f«      }| j)                  |«      }t        j                  ||| j                  |	|f«      }|||fS )z#Input shape: Batch x Time x ChannelNr   r   r   rr   r6   Tr  z$Attention weights should be of size r–   rŒ   z!Attention mask should be of size r   r•   r  r—   z `attn_output` should be of size rµ   )r   r3  r6  r;  r2  r4  r!   r%   r7  rx   ry   r;   r  r'   rŸ   r"   r    r   r€   r·   r5  )rQ   rœ   Úkey_value_statesÚpast_key_valuer©   r�   r˜   Úis_cross_attentionr@   rA   rz   Úquery_statesÚ
key_statesÚvalue_statesÚ
proj_shaperG   Úattn_weightsrš   r›   s                      r2   rY   zTFLEDDecoderAttention.call.  s£  € ð .°TÐ9ÐÜ",¨]Ó";ÑˆˆW�ið —{‘{ =Ó1°D·L±LÑ@ˆá .Ð"<à'¨Ñ*ˆJØ)¨!Ñ,ŠLÙàŸ™ T§[¡[Ð1AÓ%BÀBÈÓLˆJØŸ;™; t§{¡{Ð3CÓ'DÀbÈ#ÓN‰LØÐ'àŸ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLÜŸ™ N°1Ñ$5°zÐ#BÈÔKˆJÜŸ9™9 n°QÑ&7¸Ð%FÈQÔO‰Lð Ÿ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLà�?Š?ð )¨,Ð7ˆNà˜DŸN™NÑ*¨B°·±Ð>ˆ
Ü—z‘z $§+¡+¨l¸GÀSÓ"IÈ:ÓVˆÜ—Z‘Z 
¨JÓ7ˆ
Ü—z‘z ,°
Ó;ˆä˜ZÓ(¨Ñ+ˆÜ—y‘y ¨zÀtÔLˆä
�‰×!Ñ!Ü�|Ó$Ø�4—>‘>Ñ! 7¨GÐ4à6¸¸d¿n¹nÑ8LÈgÐW^Ð7_Ð6`ð aÜ˜|Ó,Ð-ð/ð	 	"ô 	
ð Ð%Ü�L‰L×%Ñ%Ü˜>Ó*Ø�a˜ 'Ð*à7¸¸aÀÈ'Ð8RÐ7Sð TÜ" >Ó2Ð3ð5ð	 &ô ô Ÿ:™: l°S¸$¿.¹.È'ÐSZÐ4[Ó\Ô_a×_fÑ_fØ l×&8Ñ&8ô`ñ ˆLô Ÿ:™: l°S¸4¿>¹>Ñ5IÈ7ÐT[Ð4\Ó]ˆLä% l¸Ô<ˆàÐ&Ü�L‰L×%Ñ%Ü˜?Ó+Ø—‘Ð àEÀtÇ~Á~ÐEWð XÜ" ?Ó3Ð4ð6ð	 &ô ô Ÿ:™: o°}ÓEÌÏ
É
Ø˜s D§N¡N°G¸WÐEóIñ ˆLô Ÿ:™: l°S¸4¿>¹>Ñ5IÈ7ÐT[Ð4\Ó]ˆLà—\‘\ ,¸�\ÓBˆ
ä—i‘i 
¨LÓ9ˆä
�‰×!Ñ!Ü�{Ó#Ø�4—>‘>Ñ! 7¨D¯M©MÐ:à2°C¸¿¹ÈÐRV×R_ÑR_Ð3`Ð2að bÜ˜{Ó+Ð,ð.ð	 	"ô 	
ô —l‘lÜ�J‰J�{ S¨$¯.©.¸'À4Ç=Á=Ð$QÓRÐT`ó
ˆô —j‘j ¨s°G¸YÐ.GÓHˆà—m‘m KÓ0ˆÜ"$§*¡*¨\¸CÀÇÁÐQXÐZaÐ;bÓ"cˆà˜L¨.Ð8Ð8rE   c                óÈ  — | j                   ry d| _         t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �[t        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       y y # 1 sw Y   �ŒAxY w# 1 sw Y   ŒæxY w# 1 sw Y   Œ‹xY w# 1 sw Y   y xY w)NTr2  r3  r4  r5  )r†   r‰   r!   r‡   r2  rX   rˆ   rz   r3  r4  r5  rŠ   s     r2   rˆ   zTFLEDDecoderAttention.build¦  sŠ  € Ø�:Š:ØØˆŒ
Ü�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ @Ø—‘×!Ñ! 4¨¨t¯~©~Ð">Ô?÷@ä�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ @Ø—‘×!Ñ! 4¨¨t¯~©~Ð">Ô?÷@ä�4˜ 4Ó(Ð4Ü—‘˜tŸ{™{×/Ñ/Ó0ñ @Ø—‘×!Ñ! 4¨¨t¯~©~Ð">Ô?÷@ä�4˜ TÓ*Ð6Ü—‘˜tŸ}™}×1Ñ1Ó2ñ BØ—‘×#Ñ# T¨4°·±Ð$@ÔA÷Bð Bð 7÷@ñ @ú÷@ð @ú÷@ð @ú÷Bð Bús0   Á)F3Â2)G Ä)GÆ )GÆ3F=Ç G	ÇGÇG!)r5   FT)
rz   r^   rx   r^   r€   rÒ   r7  Úboolr8  rF  )r:  ú	tf.Tensorr\   r^   r@   r^   )NNNNF)rœ   rG  r=  útf.Tensor | Noner>  úTuple[Tuple[tf.Tensor]] | Noner©   rH  r�   rH  Úreturnz"Tuple[tf.Tensor, tf.Tensor | None]rN   )	rb   rc   rd   re   rP   r;  rY   rˆ   rf   rg   s   @r2   r0  r0    s°   ø„ Ù@ð Ø ØðVàðVð ðVð ð	Vð
 ðVð õVó0mð .2Ø9=Ø+/Ø,0Øðv9à ðv9ð +ðv9ð 7ð	v9ð
 )ðv9ð *ðv9ð 
,óv9÷pBrE   r0  c                  óJ   ‡ — e Zd Zdˆ fd„Z	 d	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zˆ xZS )ÚTFLEDEncoderLayerc                ó¾  •— t        ‰| �  d	i |¤Ž |j                  | _        t	        ||d¬«      | _        t        j                  j                  dd¬«      | _	        t        j                  j                  |j                  «      | _        t        |j                  «      | _        t        j                  j                  |j                  «      | _        t        j                  j!                  |j"                  d¬«      | _        t        j                  j!                  | j                  d¬«      | _        t        j                  j                  dd¬«      | _        || _        y )
NÚ	self_attn©rX   çñhãˆµøä>Úself_attn_layer_norm©ÚepsilonrX   Úfc1Úfc2Úfinal_layer_normrs   )rO   rP   r'  rz   r!  rN  r   r{   ÚLayerNormalizationrQ  r~   r€   r
   Úactivation_functionÚactivation_fnÚactivation_dropoutr|   Úencoder_ffn_dimrT  rU  rV  rt   r)  s       €r2   rP   zTFLEDEncoderLayer.__init__¹  sù   ø€ Ü‰ÑÑ"˜6Ò"ØŸ™ˆŒÜ.¨v°xÀkÔRˆŒÜ$)§L¡L×$CÑ$CÈDÐWmÐ$CÓ$nˆÔ!Ü—|‘|×+Ñ+¨F¯N©NÓ;ˆŒÜ.¨v×/IÑ/IÓJˆÔÜ"'§,¡,×"6Ñ"6°v×7PÑ7PÓ"QˆÔÜ—<‘<×%Ñ% f×&<Ñ&<À5Ð%ÓIˆŒÜ—<‘<×%Ñ% d§n¡n¸5Ð%ÓAˆŒÜ %§¡× ?Ñ ?ÈÐSeÐ ?Ó fˆÔØˆ�rE   c           
     ó  — |}| j                  ||||||g|¬«      }	|	d   }t        j                  j                  t	        |«      t	        |«      dt	        |«      › dt	        |«      › �¬«       | j                  ||¬«      }||z   }| j                  |«      }|}| j                  | j                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }||z   }| j                  |«      }|f|	dd z   S )aÀ  
        Args:
            hidden_states (`tf.Tensor`): input to the layer of shape *(batch, seq_len, embed_dim)*
            attention_mask (`tf.Tensor`): attention mask of size
                *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
            layer_head_mask (`tf.Tensor`): mask for attention heads in a given layer of size
                *(config.encoder_attention_heads,)*.
        r—   r   z&Self attn modified the shape of query ú to rŒ   r   N)rN  r!   r'   rŸ   r   r€   rQ  rY  rT  rZ  rU  rV  )
rQ   rœ   r©   r�   rž   rª   r«   r˜   ÚresidualÚlayer_outputss
             r2   rY   zTFLEDEncoderLayer.callÆ  s3  € ð$ !ˆØŸ™Ø˜N¨O¸_ÐNbÐdrÐsØð 'ó 
ˆð
 & aÑ(ˆä
�‰×!Ñ!Ü�}Ó%Ü�xÓ Ø<¼ZÈÓ=QÐ<RÐRVÔWaÐboÓWpÐVqÐrð 	"ô 	
ð Ÿ™ ]¸X˜ÓFˆØ  =Ñ0ˆØ×1Ñ1°-Ó@ˆØ ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆØ×/Ñ/°ÈÐ/ÓQˆØŸ™ Ó/ˆØŸ™ ]¸X˜ÓFˆØ  =Ñ0ˆØ×-Ñ-¨mÓ<ˆàÐ -°°Ð"3Ñ3Ð3rE   c                óª  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �[t        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       y y # 1 sw Y   �Œ²xY w# 1 sw Y   �ŒXxY w# 1 sw Y   ŒýxY w# 1 sw Y   Œ˜xY w# 1 sw Y   y xY w)NTrN  rQ  rT  rU  rV  )r†   r‰   r!   r‡   rN  rX   rˆ   rQ  rz   rT  rU  rt   r[  rV  rŠ   s     r2   rˆ   zTFLEDEncoderLayer.buildó  sÚ  € Ø�:Š:ØØˆŒ
Ü�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ +Ø—‘×$Ñ$ TÔ*÷+ä�4Ð/°Ó6ÐBÜ—‘˜t×8Ñ8×=Ñ=Ó>ñ NØ×)Ñ)×/Ñ/°°t¸T¿^¹^Ð0LÔM÷Nä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ =Ø—‘—‘  d¨D¯N©NÐ;Ô<÷=ä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ JØ—‘—‘  d¨D¯K©K×,GÑ,GÐHÔI÷Jä�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ JØ×%Ñ%×+Ñ+¨T°4¸¿¹Ð,HÔI÷Jð Jð ?÷+ñ +ú÷Nñ Nú÷=ð =ú÷Jð Jú÷Jð Jús<   ÁHÂ%)H$Ä)H1Å33H=Ç$)I	ÈH!È$H.È1H:È=IÉ	I)rt   r   r‚   r^   r  )rœ   rG  r©   rG  r�   rG  rž   rG  rª   rG  r«   rF  rN   r.  rg   s   @r2   rL  rL  ¸  sS   ø„ õð* ð+4à ð+4ð "ð+4ð #ð	+4ð
 #ð+4ð (ð+4ð ó+4÷ZJrE   rL  c                  óZ   ‡ — e Zd Zdˆ fd„Z	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zˆ xZS )ÚTFLEDDecoderLayerc                ó°  •— t        ‰| �  di |¤Ž |j                  | _        t	        | j                  |j
                  |j                  dd¬«      | _        t        j                  j                  |j                  «      | _        t        |j                  «      | _        t        j                  j                  |j                  «      | _        t        j                  j!                  dd¬«      | _        t	        | j                  |j
                  |j                  dd¬«      | _        t        j                  j!                  dd	¬«      | _        t        j                  j)                  |j*                  d
¬«      | _        t        j                  j)                  | j                  d¬«      | _        t        j                  j!                  dd¬«      | _        || _        y )NrN  T)rz   rx   r€   rX   r7  rP  rQ  rR  Úencoder_attn)r€   rX   r7  Úencoder_attn_layer_normrT  rO  rU  rV  rs   )rO   rP   r'  rz   r0  Údecoder_attention_headsÚattention_dropoutrN  r   r{   r~   r€   r
   rX  rY  rZ  rW  rQ  rd  re  r|   Údecoder_ffn_dimrT  rU  rV  rt   ©rQ   rt   rT   rU   s      €r2   rP   zTFLEDDecoderLayer.__init__	  sa  ø€ Ü‰ÑÑ"˜6Ò"ØŸ™ˆŒÜ.Ø—n‘nØ×4Ñ4Ø×,Ñ,ØØô
ˆŒô —|‘|×+Ñ+¨F¯N©NÓ;ˆŒÜ.¨v×/IÑ/IÓJˆÔÜ"'§,¡,×"6Ñ"6°v×7PÑ7PÓ"QˆÔä$)§L¡L×$CÑ$CÈDÐWmÐ$CÓ$nˆÔ!Ü1Ø�N‰NØ×*Ñ*Ø×,Ñ,ØØô
ˆÔô (-§|¡|×'FÑ'FÈtÐZsÐ'FÓ'tˆÔ$Ü—<‘<×%Ñ% f×&<Ñ&<À5Ð%ÓIˆŒÜ—<‘<×%Ñ% d§n¡n¸5Ð%ÓAˆŒÜ %§¡× ?Ñ ?ÈÐSeÐ ?Ó fˆÔØˆ�rE   c	                ó8  — |}	|�|dd nd}
| j                  ||
||¬«      \  }}}| j                  ||¬«      }|	|z   }| j                  |«      }d}d}|�S|}	|�|dd nd}| j                  |||||¬«      \  }}}| j                  ||¬«      }|	|z   }| j	                  |«      }||z   }|}	| j                  | j                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }|	|z   }| j                  |«      }||||fS )a  
        Args:
            hidden_states (`tf.Tensor`): input to the layer of shape *(batch, seq_len, embed_dim)*
            attention_mask (`tf.Tensor`): attention mask of size
                *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
            encoder_hidden_states (`tf.Tensor`):
                cross attention input to the layer of shape *(batch, seq_len, embed_dim)*
            encoder_attention_mask (`tf.Tensor`): encoder attention mask of size
                *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
            layer_head_mask (`tf.Tensor`): mask for attention heads in a given layer of size
                *(config.encoder_attention_heads,)*.
            encoder_layer_head_mask (`tf.Tensor`): mask for encoder attention heads in a given layer of
                size *(config.encoder_attention_heads,)*.
            past_key_value (`Tuple(tf.Tensor)`): cached past key and value projection states
        Nrr   )rœ   r>  r©   r�   r—   rû   )rœ   r=  r©   r�   r>  )
rN  r€   rQ  rd  re  rY  rT  rZ  rU  rV  )rQ   rœ   r©   Úencoder_hidden_statesÚencoder_attention_maskr�   Úencoder_layer_head_maskr>  r˜   r^  Úself_attn_past_key_valueÚself_attn_weightsÚpresent_key_valueÚcross_attn_present_key_valueÚcross_attn_weightsÚcross_attn_past_key_values                   r2   rY   zTFLEDDecoderLayer.call%  s�  € ð4 !ˆð :HÐ9S >°"°1Ñ#5ÐY]Ð à>B¿n¹nØ'Ø3Ø)Ø+ð	 ?Mó ?
Ñ;ˆÐ(Ð*;ð Ÿ™ ]¸X˜ÓFˆØ  =Ñ0ˆØ×1Ñ1°-Ó@ˆð (,Ð$Ø!ÐØ Ð,Ø$ˆHð @NÐ?Y¨°r°sÑ(;Ð_cÐ%ØNR×N_ÑN_Ø+Ø!6Ø5Ø 7Ø8ð O`ó OÑKˆMÐ-Ð/Kð !ŸL™L¨À˜LÓJˆMØ$ }Ñ4ˆMØ ×8Ñ8¸ÓGˆMð !2Ð4PÑ PÐð !ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆØ×/Ñ/°ÈÐ/ÓQˆØŸ™ Ó/ˆØŸ™ ]¸X˜ÓFˆØ  =Ñ0ˆØ×-Ñ-¨mÓ<ˆð ØØØð	
ð 	
rE   c                ób  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �[t        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       y y # 1 sw Y   �ŒsxY w# 1 sw Y   �ŒxY w# 1 sw Y   �ŒÌxY w# 1 sw Y   �ŒrxY w# 1 sw Y   �ŒxY w# 1 sw Y   Œ³xY w# 1 sw Y   y xY w)	NTrN  rQ  rd  re  rT  rU  rV  )r†   r‰   r!   r‡   rN  rX   rˆ   rQ  rz   rd  re  rT  rU  rt   rh  rV  rŠ   s     r2   rˆ   zTFLEDDecoderLayer.buildu  sŠ  € Ø�:Š:ØØˆŒ
Ü�4˜ dÓ+Ð7Ü—‘˜tŸ~™~×2Ñ2Ó3ñ +Ø—‘×$Ñ$ TÔ*÷+ä�4Ð/°Ó6ÐBÜ—‘˜t×8Ñ8×=Ñ=Ó>ñ NØ×)Ñ)×/Ñ/°°t¸T¿^¹^Ð0LÔM÷Nä�4˜¨Ó.Ð:Ü—‘˜t×0Ñ0×5Ñ5Ó6ñ .Ø×!Ñ!×'Ñ'¨Ô-÷.ä�4Ð2°DÓ9ÐEÜ—‘˜t×;Ñ;×@Ñ@ÓAñ QØ×,Ñ,×2Ñ2°D¸$ÀÇÁÐ3OÔP÷Qä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ =Ø—‘—‘  d¨D¯N©NÐ;Ô<÷=ä�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ JØ—‘—‘  d¨D¯K©K×,GÑ,GÐHÔI÷Jä�4Ð+¨TÓ2Ð>Ü—‘˜t×4Ñ4×9Ñ9Ó:ñ JØ×%Ñ%×+Ñ+¨T°4¸¿¹Ð,HÔI÷Jð Jð ?÷#+ñ +ú÷Nñ Nú÷.ñ .ú÷Qñ Qú÷=ñ =ú÷Jð Jú÷Jð JúsT   ÁKÂ%)K%ÄK2Å&)K?Ç)LÈ43LÊ%)L%ËK"Ë%K/Ë2K<Ë?L	ÌLÌL"Ì%L.©rt   r   )NNNNNNF)r©   rH  rk  rH  rl  rH  r�   rH  rm  rH  r>  zTuple[tf.Tensor] | NonerJ  z?Tuple[tf.Tensor, tf.Tensor, tf.Tensor, Tuple[Tuple[tf.Tensor]]]rN   r.  rg   s   @r2   rb  rb    sz   ø„ õð> ,0Ø26Ø37Ø,0Ø48Ø26ØðN
ð )ðN
ð  0ð	N
ð
 !1ðN
ð *ðN
ð "2ðN
ð 0ðN
ð 
IóN
÷`JrE   rb  c                  ó0   ‡ — e Zd ZeZdZeˆ fd„«       Zˆ xZS )ÚTFLEDPreTrainedModelÚledc                ón   •— t         ‰| �  }t        j                  dt        j                  d¬«      |d<   |S )N)NNÚglobal_attention_maskrO  )rO   Úinput_signaturer!   Ú
TensorSpecrZ   )rQ   ÚsigrU   s     €r2   r{  z$TFLEDPreTrainedModel.input_signature”  s/   ø€ ä‰gÑ%ˆÜ')§}¡}°\Ä2Ç8Á8ÐRiÔ'jˆÐ#Ñ$Øˆ
rE   )	rb   rc   rd   r   Úconfig_classÚbase_model_prefixÚpropertyr{  rf   rg   s   @r2   rw  rw  �  s    ø„ Ø€LØÐàóó ôrE   rw  c                  óJ   — e Zd ZU dZdZded<   dZded<   dZded<   dZded<   y)	ÚTFLEDEncoderBaseModelOutputaI  
    Base class for Longformer's outputs, with potential hidden states, local and global attentions.

    Args:
        last_hidden_state (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the model.
        hidden_states (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
            `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length, x +
            attention_window + 1)`, where `x` is the number of tokens with global attention mask.

            Local attentions weights after the attention softmax, used to compute the weighted average in the
            self-attention heads. Those are the attention weights from every token in the sequence to every token with
            global attention (first `x` values) and to every token in the attention window (remaining `attention_window
            + 1` values). Note that the first `x` values refer to tokens with fixed positions in the text, but the
            remaining `attention_window + 1` values refer to tokens with relative positions: the attention weight of a
            token to itself is located at index `x + attention_window / 2` and the `attention_window / 2` preceding
            (succeeding) values are the attention weights to the `attention_window / 2` preceding (succeeding) tokens.
            If the attention window contains a token with global attention, the attention weight at the corresponding
            index is set to 0; the value should be accessed from the first `x` attention weights. If a token has global
            attention, the attention weights to all other tokens in `attentions` is set to 0, the values should be
            accessed from `global_attentions`.
        global_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length, x)`, where `x`
            is the number of tokens with global attention mask.

            Global attentions weights after the attention softmax, used to compute the weighted average in the
            self-attention heads. Those are the attention weights from every token with global attention to every token
            in the sequence.
    NúOptional[tf.Tensor]Úlast_hidden_stateúTuple[tf.Tensor, ...] | Nonerœ   Ú
attentionsÚglobal_attentions)	rb   rc   rd   re   r„  Ú__annotations__rœ   r†  r‡  rs   rE   r2   r‚  r‚  ›  s8   … ñ!ðF .2ÐÐ*Ó1Ø26€MÐ/Ó6Ø/3€JÐ,Ó3Ø6:ÐÐ3Ô:rE   r‚  c                  ó�   — e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   dZ	ded
<   dZ
ded<   dZded<   dZded<   dZded<   y)ÚTFLEDSeq2SeqModelOutputaÃ  
    Base class for model encoder's outputs that also contains : pre-computed hidden states that can speed up sequential
    decoding.

    Args:
        last_hidden_state (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the decoder of the model.

            If `past_key_values` is used only the last hidden-state of the sequences of shape `(batch_size, 1,
            hidden_size)` is output.
        past_key_values (`List[tf.Tensor]`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
            List of `tf.Tensor` of length `config.n_layers`, with each tensor of shape `(2, batch_size, num_heads,
            sequence_length, embed_size_per_head)`).

            Contains pre-computed hidden-states (key and values in the attention blocks) of the decoder that can be
            used (see `past_key_values` input) to speed up sequential decoding.
        decoder_hidden_states (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
            `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.
        decoder_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
            self-attention heads.
        cross_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights of the decoder's cross-attention layer, after the attention softmax, used to compute the
            weighted average in the cross-attention heads.
        encoder_last_hidden_state (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder of the model.
        encoder_hidden_states (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
            `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.
        encoder_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
            self-attention heads.
        encoder_global_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length, x)`, where `x`
            is the number of tokens with global attention mask.

            Global attentions weights after the attention softmax, used to compute the weighted average in the
            self-attention heads. Those are the attention weights from every token with global attention to every token
            in the sequence.
    Nrƒ  r„  úList[tf.Tensor] | NoneÚpast_key_valuesr…  Údecoder_hidden_statesÚdecoder_attentionsÚcross_attentionsrH  Úencoder_last_hidden_staterk  Úencoder_attentionsÚencoder_global_attentions)rb   rc   rd   re   r„  rˆ  rŒ  r�  rŽ  r�  r�  rk  r‘  r’  rs   rE   r2   rŠ  rŠ  Ç  su   … ñ5ðn .2ÐÐ*Ó1Ø.2€OÐ+Ó2Ø:>ÐÐ7Ó>Ø7;ÐÐ4Ó;Ø59ÐÐ2Ó9Ø26ÐÐ/Ó6Ø:>ÐÐ7Ó>Ø7;ÐÐ4Ó;Ø>BÐÐ;ÔBrE   rŠ  c                  óž   — e Zd ZU dZdZded<   dZded<   dZded<   dZd	ed
<   dZ	d	ed<   dZ
d	ed<   dZded<   dZd	ed<   dZd	ed<   dZd	ed<   y)ÚTFLEDSeq2SeqLMOutputap  
    Base class for sequence-to-sequence language models outputs.

    Args:
        loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
            Language modeling loss.
        logits (`tf.Tensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
            Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
        past_key_values (`List[tf.Tensor]`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
            List of `tf.Tensor` of length `config.n_layers`, with each tensor of shape `(2, batch_size, num_heads,
            sequence_length, embed_size_per_head)`).

            Contains pre-computed hidden-states (key and values in the attention blocks) of the decoder that can be
            used (see `past_key_values` input) to speed up sequential decoding.
        decoder_hidden_states (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
            `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.
        decoder_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
            self-attention heads.
        cross_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights of the decoder's cross-attention layer, after the attention softmax, used to compute the
            weighted average in the cross-attention heads.
        encoder_last_hidden_state (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder of the model.
        encoder_hidden_states (`tuple(tf.Tensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `tf.Tensor` (one for the output of the embeddings + one for the output of each layer) of shape
            `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.
        encoder_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
            self-attention heads.
        encoder_global_attentions (`tuple(tf.Tensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `tf.Tensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length, x)`, where `x`
            is the number of tokens with global attention mask.

            Global attentions weights after the attention softmax, used to compute the weighted average in the
            self-attention heads. Those are the attention weights from every token with global attention to every token
            in the sequence.
    NrH  Úlossrƒ  Úlogitsr‹  rŒ  r…  r�  rŽ  r�  r�  rk  r‘  r’  )rb   rc   rd   re   r•  rˆ  r–  rŒ  r�  rŽ  r�  r�  rk  r‘  r’  rs   rE   r2   r”  r”    s   … ñ3ðj "€DÐ
Ó!Ø"&€FÐÓ&Ø.2€OÐ+Ó2Ø:>ÐÐ7Ó>Ø7;ÐÐ4Ó;Ø59ÐÐ2Ó9Ø26ÐÐ/Ó6Ø:>ÐÐ7Ó>Ø7;ÐÐ4Ó;Ø>BÐÐ;ÔBrE   r”  at	  
    This model inherits from [`TFPreTrainedModel`]. 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 [keras.Model](https://www.tensorflow.org/api_docs/python/tf/keras/Model) subclass. Use it
    as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to general usage and
    behavior.

    <Tip>

    TensorFlow models and layers in `transformers` accept two formats as input:

    - having all inputs as keyword arguments (like PyTorch models), or
    - having all inputs as a list, tuple or dict in the first positional argument.

    The reason the second format is supported is that Keras methods prefer this format when passing inputs to models
    and layers. Because of this support, when using methods like `model.fit()` things should "just work" for you - just
    pass your inputs and labels in any format that `model.fit()` supports! If, however, you want to use the second
    format outside of Keras methods like `fit()` and `predict()`, such as when creating your own layers or models with
    the Keras `Functional` API, there are three possibilities you can use to gather all the input Tensors in the first
    positional argument:

    - a single Tensor with `input_ids` only and nothing else: `model(input_ids)`
    - a list of varying length with one or several input Tensors IN THE ORDER given in the docstring:
    `model([input_ids, attention_mask])` or `model([input_ids, attention_mask, token_type_ids])`
    - a dictionary with one or several input Tensors associated to the input names given in the docstring:
    `model({"input_ids": input_ids, "token_type_ids": token_type_ids})`

    Note that when creating models and layers with
    [subclassing](https://keras.io/guides/making_new_layers_and_models_via_subclassing/) then you don't need to worry
    about any of this, as you can just pass inputs like you would to any other Python function!

    </Tip>

    Args:
        config ([`LEDConfig`]): 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 [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.
aÇ  
    Args:
        input_ids (`tf.Tensor` of shape `({0})`):
            Indices of input sequence tokens in the vocabulary.

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

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`tf.Tensor` of shape `({0})`, *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 (`tf.Tensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary.

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

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

            LED uses the `eos_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`).
        decoder_attention_mask (`tf.Tensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            will be made by default and ignore pad tokens. It is not recommended to set this for most use cases.
        head_mask (`tf.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the 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 (`tf.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the 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 (`tf.Tensor`, *optional*):
            hidden states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
            of shape `(batch_size, sequence_length, hidden_size)` is a sequence of
        past_key_values (`Tuple[Tuple[tf.Tensor]]` of length `config.n_layers`)
            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)`.
        use_cache (`bool`, *optional*, defaults to `True`):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`). Set to `False` during training, `True` during generation
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail. This argument can be used only in eager mode, in graph mode the value in the
            config will be used instead.
        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. This argument can be used only in eager mode, in graph mode the value in the config will be
            used instead.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple. This argument can be used in
            eager mode, in graph mode the value will always be set to True.
        training (`bool`, *optional*, defaults to `False`):
            Whether or not to use the model in training mode (some modules like dropout modules have different
            behaviors between training and evaluation).
c                  óŠ   ‡ — e Zd ZeZ	 dd	ˆ fd„Zd„ Zd„ Ze	 	 	 	 	 	 	 	 	 d
d„«       Z	e
j                  d„ «       Zd„ Zdd„Zˆ xZS )ÚTFLEDEncoderc           	     óÔ  •— t        ‰| �  di |¤Ž || _        t        j                  j                  |j                  «      | _        |j                  dkD  rt        j                  d«       d| _
        |j                  | _        t        |j                  t        «      rO|j                  dz  dk(  sJ d«       ‚|j                  dkD  sJ d«       ‚|j                  g|j                   z  |_        nLt#        |j                  «      |j                   k(  s*J d|j                   › dt#        |j                  «      › �«       ‚|j                  | _        || _        t'        |j(                  |j*                  d	¬
«      | _        t/        |j0                  «      D �cg c]  }t3        ||d|› �¬
«      ‘Œ c}| _        t        j                  j5                  dd¬«      | _        |j*                  | _        y c c}w )Nr   ú0Layerdrop is currently disabled in TFLED models.r5   rr   z1`config.attention_window` has to be an even valuez,`config.attention_window` has to be positivezQ`len(config.attention_window)` should equal `config.num_hidden_layers`. Expected z, given Úembed_positionsrO  úlayers.rP  Úlayernorm_embeddingrR  rs   )rO   rP   rt   r   r{   r~   r€   Úencoder_layerdropÚloggerÚwarningÚ	layerdropr-   Úpadding_idxÚ
isinstancerƒ   r^   Únum_hidden_layersÚlenÚembed_tokensrL   Úmax_encoder_position_embeddingsr'  r›  r:   Úencoder_layersrL  rW  r�  rz   ©rQ   rt   r¦  rT   ÚirU   s        €r2   rP   zTFLEDEncoder.__init__Æ  s°  ø€ Ü‰ÑÑ"˜6Ò"ØˆŒÜ—|‘|×+Ñ+¨F¯N©NÓ;ˆŒØ×#Ñ# aÒ'Ü�N‰NÐMÔNØˆŒØ!×.Ñ.ˆÔä�f×-Ñ-¬sÔ3Ø×*Ñ*¨QÑ.°!Ò3ÐhÐ5hÓhÐ3Ø×*Ñ*¨QÒ.Ð^Ð0^Ó^Ð.Ø'-×'>Ñ'>Ð&?À&×BZÑBZÑ&ZˆFÕ#ä�v×.Ñ.Ó/°6×3KÑ3KÒKð ðØ"×4Ñ4Ð5°X¼cÀ&×BYÑBYÓ>ZÐ=[ð]óÐKð
 !'× 7Ñ 7ˆÔØ(ˆÔÜ>Ø×2Ñ2Ø�N‰NØ"ô 
ˆÔô
 RWÐW]×WlÑWlÓQmÖnÈAÔ(¨°¸7À1À#¸ÖGÒnˆŒÜ#(§<¡<×#BÑ#BÈ4ÐVkÐ#BÓ#lˆÔ ØŸ™ˆ�ùò os   ÆG%c                ó   — | j                   S rN   ©r¦  ©rQ   s    r2   Úget_embed_tokenszTFLEDEncoder.get_embed_tokensä  s   € Ø× Ñ Ð rE   c                ó   — || _         y rN   r¬  ©rQ   r¦  s     r2   Úset_embed_tokenszTFLEDEncoder.set_embed_tokensç  ó
   € Ø(ˆÕrE   c
                ó  — |�|�t        d«      ‚|�=t        |«      }
t        || j                  j                  «       | j                  |«      }n|�t        |«      dd }
nt        d«      ‚|€t        j                  |
d«      }|�'|t        j                  |dz   |j                  ¬«      z  }| j                  |||| j                  ¬«      \  }}}}t        |«      }
t
        j                  j                  t        j                  |t
        j                  «      d«      }t
        j                  j                  t        j                  |t
        j                  «      d«      }t
        j                  j                  |«      }| j!                  |
«      }||z   }| j#                  |«      }| j%                  ||	¬«      }|�#t'        |«      dd…d	d	dd…f   }|dd…dd…ddf   }|rd
nd}|rd
ndx}}|�gt
        j(                  j+                  t        |«      d	   t-        | j.                  «      dt-        | j.                  «      › dt        |«      d	   › d�¬«       t1        | j.                  «      D ]ž  \  }}|r| j3                  ||«      }||fz   }t5        j6                  d	d«      }|	r|| j8                  k  rŒH ||||�||   nd|||¬«      }|d	   }|sŒe|t        j:                  |d   d«      fz   }|t        j:                  |d   d«      fz   }Œ  | j3                  ||«      }|r0|d	kD  r)t=        |D �cg c]  }|dd…dd…d| …dd…f   ‘Œ c}«      n|}|r||fz   }|st=        d„ |||fD «       «      S t?        ||||¬«      S c c}w )aW  
        Args:
            input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
                provide it.

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

                [What are input IDs?](../glossary#input-ids)
            attention_mask (`tf.Tensor` 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 (`tf.Tensor` of shape `(num_layers, num_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:

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

            inputs_embeds (`tf.Tensor` 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.
        NzDYou cannot specify both input_ids and inputs_embeds at the same timer   z5You have to specify either input_ids or inputs_embedsr   r   )r,   r©   Úinputs_embedsr-   r—   r   rs   ú&The head_mask should be specified for ú layers, but it is for rñ   rŒ   )rœ   r©   r�   rž   rª   r«   rµ   rr   )r   r   r	   rr   c              3  ó&   K  — | ]	  }|€Œ|–— Œ y ­wrN   rs   ©Ú.0Úvs     r2   ú	<genexpr>z$TFLEDEncoder.call.<locals>.<genexpr>€  s   è ø€ Òe˜qÐWXÑWdœÑeùs   ‚Š)r„  rœ   r†  r‡  ) rw   r   r   r¦  Ú	input_dimr!   r#   r"   r    Ú_pad_to_window_sizer¢  r    ÚlessÚint8rÔ   Ú
reduce_anyr›  r�  r€   rJ   r'   rŸ   r¥  r{   Ú	enumerateÚcompute_hidden_statesÚrandomÚuniformr¡  r·   rÿ   r‚  )rQ   r,   r´  r©   rz  Ú	head_maskÚoutput_attentionsÚoutput_hidden_statesÚreturn_dictr˜   r[   Úpadding_lenrž   rª   r«   Ú	embed_posrœ   Úencoder_statesÚall_attentionsÚall_global_attentionsÚidxÚencoder_layerÚhidden_states_to_addÚdropout_probabilityr_  Ústates                             r2   rY   zTFLEDEncoder.callê  s»  € ðd Ð  ]Ð%>ÜÐcÓdÐdØÐ"Ü$ YÓ/ˆKÜ*¨9°d×6GÑ6G×6QÑ6QÔRØ ×-Ñ-¨iÓ8‰MØÐ&Ü$ ]Ó3°C°RÐ8‰KäÐTÓUÐUàÐ!ÜŸW™W [°!Ó4ˆNð !Ð,Ø+¬b¯g©gÐ7LÈqÑ7PÐYg×YmÑYmÔ.nÑnˆNà@D×@XÑ@XØØ)Ø'Ø×)Ñ)ð	 AYó A
Ñ=ˆ�Y °ô ! Ó0ˆäŸ'™'Ÿ,™,¤r§w¡w¨~¼r¿w¹wÓ'GÈÓKˆÜ!Ÿw™wŸ™¬r¯w©w°~ÄrÇwÁwÓ/OÐQRÓSÐÜŸ™×+Ñ+Ð,@ÓAˆà×(Ñ(¨Ó5ˆ	Ø%¨	Ñ1ˆØ×0Ñ0°Ó?ˆØŸ™ ]¸X˜ÓFˆð Ð%ä)¨.Ó9º!¸QÀÂ1¸*ÑEˆNØ+ªAªq°$¸Ð,<Ñ=ˆNá3™¸ˆÙ7H±ÈdÐRˆÐ.ð Ð Ü�L‰L×%Ñ%Ü˜9Ó% aÑ(Ü�D—K‘KÓ à<¼SÀÇÁÓ=MÐ<Nð OÜ" 9Ó-¨aÑ0Ð1°ð4ð	 &ô ô #,¨D¯K©KÓ"8ò 	pÑˆC�Ù#Ø'+×'AÑ'AÀ-ÐQ\Ó']Ð$Ø!/Ð3GÐ2IÑ!I�ä"(§.¡.°°AÓ"6ÐÙÐ0°4·>±>ÒAØá)Ø+Ø-Ø2;Ð2G 	¨#¢ÈTØ /Ø%9Ø-ôˆMð *¨!Ñ,ˆMâ à!/´2·<±<ÀÈaÑ@PÐR^Ó3_Ð2aÑ!a�ð )>ÄÇÁÈmÐ\]ÑN^Ð`lÓAmÐ@oÑ(oÑ%ð3	pð: ×2Ñ2°=À+ÓNˆñ ð  ’?ô À.ÖQ¸�ušQ¢ = [ L =²!Ð3Ó4ÒQÔRà#ð ñ  Ø+¨}Ð.>Ñ>ˆNáÜÑe ]°NÀNÐ$SÔeÓeÐeÜ*Ø+Ø(Ø%Ø3ô	
ð 	
ùò Rs   Ì,M<c                ó(   — |dkD  r|d d …d | …f   S |S )Nr   rs   )rQ   rœ   rÉ  s      r2   rÂ  z"TFLEDEncoder.compute_hidden_statesˆ  s#   € à2=À²/ˆ}šQ  +  Ð-Ñ.ÐTÀ}ÐTrE   c                óv  — t        | j                  t        «      r| j                  nt        | j                  «      }|dz  dk(  s
J d|› �«       ‚|�t	        |«      n
t	        |«      }|dd \  }}|||z  z
  |z  }	|	dkD  r!t
        j                  d|› d||	z   › d|› �«       t        j                  ddgd|	gg«      }
|�t        j                  ||
|¬«      }|�G|	dkD  rBt        j                  ||	f|«      }| j                  |«      }t        j                  ||gd	¬
«      }t        j                  ||
d¬«      }|	|||fS )zaA helper function to pad tokens and mask to work with implementation of Longformer selfattention.rr   r   z2`attention_window` should be an even value. Given Nz(Input ids are automatically padded from r]  z0 to be a multiple of `config.attention_window`: rÜ   rû   r6   F)r£  rƒ   r^   Úmaxr   rŸ  Úwarning_oncer!   r$   rÑ   r#   r¦  r%   )rQ   r,   r©   r´  r-   rƒ   r[   r¬   r\   rÉ  rÃ   Úinput_ids_paddingÚinputs_embeds_paddings                r2   r½  z TFLEDEncoder._pad_to_window_sizeŒ  sz  € ô &0°×0EÑ0EÄsÔ%KˆD×!Ò!ÔQTÐUY×UjÑUjÓQkð 	ð   !Ñ# qÒ(ÐqÐ,^Ð_oÐ^pÐ*qÓqÐ(à/8Ð/D”j Ô+Ì*ÐUbÓJcˆØ)¨"¨1˜oÑˆ
�GØ'¨'Ð4DÑ*DÑDÐHXÑXˆà˜Š?Ü×ÑØ:¸7¸)À4ÈÐR]ÑH]ÐG^ð _.Ø.>Ð-?ðAôô
 ×'Ñ'¨!¨Q¨°!°[Ð1AÐ(BÓCˆàÐ ÜŸ™˜y¨(ÀLÔQˆIàÐ$Ø˜QŠÜ$&§G¡G¨Z¸Ð,EÀ|Ó$TÐ!Ø(,×(9Ñ(9Ð:KÓ(LÐ%Ü "§	¡	¨=Ð:OÐ*PÐWYÔ Z�äŸ™ °È%ÔPˆð ØØØð	
ð 	
rE   c                ó¦  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Zt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  g«       d d d «       t        | dd «      �K| j                  D ];  }t        j                  |j
                  «      5  |j                  d «       d d d «       Œ= y y # 1 sw Y   ŒÉxY w# 1 sw Y   ŒnxY w# 1 sw Y   ŒaxY w©NTr›  r�  r{   )
r†   r‰   r!   r‡   r›  rX   rˆ   r�  rz   r{   ©rQ   r[   Úlayers      r2   rˆ   zTFLEDEncoder.build¹  s!  € Ø�:Š:ØØˆŒ
Ü�4Ð*¨DÓ1Ð=Ü—‘˜t×3Ñ3×8Ñ8Ó9ñ 1Ø×$Ñ$×*Ñ*¨4Ô0÷1ä�4Ð.°Ó5ÐAÜ—‘˜t×7Ñ7×<Ñ<Ó=ñ MØ×(Ñ(×.Ñ.°°d¸D¿N¹NÐ/KÔL÷Mä�4˜ 4Ó(Ð4ØŸ™ò &�Ü—]‘] 5§:¡:Ó.ñ &Ø—K‘K Ô%÷&ð &ñ&ð 5÷1ð 1ú÷Mð Mú÷&ð &ús$   ÁD/Â%)D;ÄEÄ/D8Ä;EÅE	rN   ©rt   r   r¦  z Optional[keras.layers.Embedding])	NNNNNNNNF)rb   rc   rd   r   r~  rP   r®  r±  r   rY   r!   ÚfunctionrÂ  r½  rˆ   rf   rg   s   @r2   r˜  r˜  »  su   ø„ à€Lðö(ò<!ò)ð ð ØØØ"ØØØ!ØØò[
ó ð[
ðz ‡[�[ñUó ðUò+
÷Z&rE   r˜  c                  ób   ‡ — e Zd ZeZ	 ddˆ fd„Zd„ Ze	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Zdd„Z	ˆ xZ
S )ÚTFLEDDecoderc                ó$  •— t        ‰| �  d
i |¤Ž || _        |j                  | _        || _        |j                  dkD  rt        j                  d«       d| _	        t        |j                  |j                  d¬«      | _        t        |j                  «      D �cg c]  }t!        |d|› �¬«      ‘Œ c}| _        t$        j"                  j'                  dd¬	«      | _        t$        j"                  j+                  |j,                  «      | _        y c c}w )Nr   rš  r5   r›  rO  rœ  rP  r�  rR  rs   )rO   rP   rt   r-   r¢  r¦  Údecoder_layerdroprŸ  r   r¡  rL   Úmax_decoder_position_embeddingsr'  r›  r:   Údecoder_layersrb  r{   r   rW  r�  r~   r€   r©  s        €r2   rP   zTFLEDDecoder.__init__Ô  sß   ø€ Ü‰ÑÑ"˜6Ò"ØˆŒØ!×.Ñ.ˆÔØ(ˆÔØ×#Ñ# aÒ'Ü�N‰NÐMÔNØˆŒÜ>Ø×2Ñ2Ø�N‰NØ"ô 
ˆÔô
 OTÐTZ×TiÑTiÓNjÖkÈÔ(¨¸À¸s°mÖDÒkˆŒÜ#(§<¡<×#BÑ#BÈ4ÐVkÐ#BÓ#lˆÔ ä—|‘|×+Ñ+¨F¯N©NÓ;ˆ�ùò ls   ÂDc                ó   — || _         y rN   r¬  r°  s     r2   r±  zTFLEDDecoder.set_embed_tokensæ  r²  rE   c           
     óö  — |�|�t        d«      ‚|�t        |«      }n|�t        |«      dd }nt        d«      ‚|�t        |d   d   «      d   nd}| j                  ||«      }|€1t        || j                  j
                  «       | j	                  |«      }|}|d   dkD  rt        ||¬«      }n.t        t        j                  |d   |d   |z   f«      |d   ¬	«      }|�|d   dkD  r|t        ||d   ¬	«      z   }|�|�t        ||d   ¬	«      }| j                  ||z   «      }| j                  ||¬
«      }d}d}d}d}|�gt        j                  j                  t        |«      d   t        | j                  «      dt        | j                  «      › dt        |«      d   › d�¬«       t!        | j                  «      D ]w  \  }}|r||fz  }t#        j$                  dd«      }|r|| j&                  k  rŒ6|�||   nd} ||||||�||   nd|�||   nd|¬«      \  }}}}|	r||fz  }|
sŒl||fz  }||fz  }Œy |r||fz  }nd}|
r|nd}|
r|nd}|	r|nd}|st)        d„ |||||fD «       «      S t+        |||||¬«      S )aM  
        Args:
            input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
                provide it. Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
                [`PreTrainedTokenizer.__call__`] for details. [What are input IDs?](../glossary#input-ids)
            attention_mask (`tf.Tensor` 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)
            encoder_hidden_states (`tf.Tensor` of shape `(batch_size, encoder_sequence_length, hidden_size)`, *optional*):
                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 (`tf.Tensor` of shape `(batch_size, encoder_sequence_length)`, *optional*):
                Mask to avoid performing cross-attention on padding tokens indices of encoder input_ids. 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 (`tf.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:

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

            encoder_head_mask (`tf.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules in encoder to avoid performing cross-attention
                on hidden heads. Mask values selected in `[0, 1]`:

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

            past_key_values (`Tuple[Tuple[tf.Tensor]]` of length `config.n_layers` with each tuple having 2 tuples each of which has 2 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 (`tf.Tensor` 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.
        NzTYou cannot specify both decoder_input_ids and decoder_inputs_embeds at the same timer   zEYou have to specify either decoder_input_ids or decoder_inputs_embedsr   rr   r   )r?   )rA   r—   rs   rµ  r¶  rñ   rŒ   )r©   rk  rl  r�   rm  r>  c              3  ó$   K  — | ]  }|�|–— Œ
 y ­wrN   rs   r¸  s     r2   r»  z$TFLEDDecoder.call.<locals>.<genexpr>Ž  s   è ø€ ò àØ�=ô ñùs   ‚)r„  rŒ  rœ   r†  r�  )rw   r   r›  r   r¦  r¼  rD   rJ   r!   r8   r�  r€   r'   rŸ   r¥  r{   rÁ  rÃ  rÄ  r¡  rÿ   r   )rQ   r,   r´  r©   rk  rl  rÅ  Úencoder_head_maskrŒ  Ú	use_cacherÆ  rÇ  rÈ  r˜   r[   r?   Ú	positionsrœ   Úcombined_attention_maskÚall_hidden_statesÚall_self_attnsÚall_cross_attentionsÚpresent_key_valuesrÎ  Údecoder_layerrÑ  r>  Úlayer_self_attnÚlayer_cross_attnrp  s                                 r2   rY   zTFLEDDecoder.callé  sW  € ðN Ð  ]Ð%>ÜÐsÓtÐtØÐ"Ü$ YÓ/‰KØÐ&Ü$ ]Ó3°C°RÐ8‰KäÐdÓeÐeàIXÐId¤¨O¸AÑ,>¸qÑ,AÓ!BÀ1Ò!EÐjkÐð ×(Ñ(¨Ð6LÓMˆ	àÐ Ü*¨9°d×6GÑ6G×6QÑ6QÔRØ ×-Ñ-¨iÓ8ˆMà%ˆð �r‰?˜QÒÜ&7¸Ð\rÔ&sÑ#ä&2Ü—‘˜ Q™¨°Q©Ð:PÑ)PÐQÓRÐ\gÐhjÑ\kô'Ð#ð Ð%¨+°b©/¸AÒ*=Ø&=ÄÈ^ÐepÐqsÑetÔ@uÑ&uÐ#à Ð,Ð1GÐ1Sä%1Ð2HÐR]Ð^`ÑRaÔ%bÐ"à×0Ñ0°ÀÑ1JÓKˆØŸ™ ]¸X˜ÓFˆð ÐØˆØ!ÐØÐð Ð Ü�L‰L×%Ñ%Ü˜9Ó% aÑ(Ü�D—K‘KÓ à<¼SÀÇÁÓ=MÐ<Nð OÜ" 9Ó-¨aÑ0Ð1°ð4ð	 &ô ô #,¨D¯K©KÓ"8ò 	<ÑˆC�á#Ø! mÐ%5Ñ5Ð!Ü"(§.¡.°°AÓ"6ÐáÐ0°4·>±>ÒAØà5DÐ5P˜_¨SÒ1ÐVZˆNáR_ØØ6Ø&;Ø'=Ø2;Ð2G 	¨#¢ÈTØBSÐB_Ð(9¸#Ò(>ÐeiØ-ôSÑOˆM˜?Ð,<Ð>Oñ Ø"Ð'8Ð&:Ñ:Ð"â Ø ?Ð"4Ñ4�Ø$Ð)9Ð(;Ñ;Ñ$ð5	<ñ8  Ø -Ð!1Ñ1Ñà $Ðá+<™À$ˆÙ7HÑ3ÈdÐá3<Ñ/À$ÐáÜñ à'Ð);Ð=NÐP^Ð`tÐuôó ð ô ?Ø"/Ø 2Ø/Ø)Ø!5ôð rE   c                óº  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �dt        j                  | j                  j
                  «      5  | j                  j                  d d | j                  j                  g«       d d d «       t        | dd «      �K| j                  D ];  }t        j                  |j
                  «      5  |j                  d «       d d d «       Œ= y y # 1 sw Y   ŒÓxY w# 1 sw Y   ŒnxY w# 1 sw Y   ŒaxY wrÚ  )r†   r‰   r!   r‡   r›  rX   rˆ   r�  rt   r'  r{   rÛ  s      r2   rˆ   zTFLEDDecoder.buildœ  s'  € Ø�:Š:ØØˆŒ
Ü�4Ð*¨DÓ1Ð=Ü—‘˜t×3Ñ3×8Ñ8Ó9ñ 1Ø×$Ñ$×*Ñ*¨4Ô0÷1ä�4Ð.°Ó5ÐAÜ—‘˜t×7Ñ7×<Ñ<Ó=ñ RØ×(Ñ(×.Ñ.°°d¸D¿K¹K×<OÑ<OÐ/PÔQ÷Rä�4˜ 4Ó(Ð4ØŸ™ò &�Ü—]‘] 5§:¡:Ó.ñ &Ø—K‘K Ô%÷&ð &ñ&ð 5÷1ð 1ú÷Rð Rú÷&ð &ús$   ÁD9Â%3EÄEÄ9EÅEÅE	rN   rÝ  )NNNNNNNNNNNNF)rb   rc   rd   r   r~  rP   r±  r   rY   rˆ   rf   rg   s   @r2   rà  rà  É  s\   ø„ à€Lðö<ò$)ð ð ØØØ"Ø#ØØØØØØ!ØØòpó ðp÷d&rE   rà  c                  ón   ‡ — e Zd ZeZdˆ fd„Zd„ Zd„ Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 dd„«       Z	d	d„Z
ˆ xZS )
ÚTFLEDMainLayerc                ó¤  •— t        ‰| �  di |¤Ž || _        t        j                  j                  |j                  |j                  t        j                  j                  | j                  j                  ¬«      d¬«      | _        d| j                  _        t        || j                  d¬«      | _        t        || j                  d¬«      | _        y )N)Ústddevz
led.shared)r¼  Ú
output_dimÚembeddings_initializerrX   ÚencoderrO  Údecoderrs   )rO   rP   rt   r   r{   Ú	EmbeddingÚ
vocab_sizer'  ÚinitializersÚTruncatedNormalÚinit_stdÚsharedÚload_weight_prefixr˜  rú  rà  rû  ri  s      €r2   rP   zTFLEDMainLayer.__init__°  sŸ   ø€ Ü‰ÑÑ"˜6Ò"ØˆŒÜ—l‘l×,Ñ,Ø×'Ñ'Ø—~‘~Ü#(×#5Ñ#5×#EÑ#EÈTÏ[É[×MaÑMaÐ#EÓ#bØð	 -ó 
ˆŒð *6ˆ�‰Ô&ä# F¨D¯K©K¸iÔHˆŒÜ# F¨D¯K©K¸iÔHˆ�rE   c                ó   — | j                   S rN   )r  r­  s    r2   Úget_input_embeddingsz#TFLEDMainLayer.get_input_embeddings¿  s   € Ø�{‰{ÐrE   c                ó~   — || _         | j                   | j                  _        | j                   | j                  _        y rN   )r  rú  r¦  rû  )rQ   Únew_embeddingss     r2   Úset_input_embeddingsz#TFLEDMainLayer.set_input_embeddingsÂ  s)   € Ø$ˆŒØ$(§K¡Kˆ�‰Ô!Ø$(§K¡Kˆ�‰Õ!rE   c                óL  — |€|€d}|€| j                  |||||
||||¬«	      }nl|rHt        |t        «      s8t        |d   t        |«      dkD  r|d   nd t        |«      dkD  r|d   nd ¬«      }n"|s t        |t        «      s|j                  «       }| j                  |||d   ||||	||||||¬«      }|s||z   S t        |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  ¬«	      S )	NF)	r,   r©   rz  rÅ  r´  rÆ  rÇ  rÈ  r˜   r   r   rr   )r„  rœ   r†  )r©   rk  rl  rÅ  rè  rŒ  r´  ré  rÆ  rÇ  rÈ  r˜   ©	r„  rŒ  r�  rŽ  r�  r�  rk  r‘  r’  )rú  r£  r‚  r¥  rÿ   Úto_tuplerû  rŠ  r„  rŒ  rœ   r†  r�  r‡  )rQ   r,   r©   Údecoder_input_idsÚdecoder_attention_maskrÅ  Údecoder_head_maskÚencoder_outputsrz  rŒ  r´  Údecoder_inputs_embedsré  rÆ  rÇ  rÈ  r˜   rT   Údecoder_outputss                      r2   rY   zTFLEDMainLayer.callÇ  s`  € ð* Ð$Ð)>Ð)FØˆIàÐ"Ø"Ÿl™lØ#Ø-Ø&;Ø#Ø+Ø"3Ø%9Ø'Ø!ð +ó 
‰Oñ ¤¨OÔ=XÔ!YÜ9Ø"1°!Ñ"4Ü47¸Ó4HÈ1Ò4L˜o¨aÒ0ÐRVÜ14°_Ó1EÈÒ1I˜?¨1Ò-Ètô‰Oñ ¤Z°ÄÔ%GØ-×6Ñ6Ó8ˆOàŸ,™,ØØ1Ø"1°!Ñ"4Ø#1Ø'Ø'Ø+Ø/ØØ/Ø!5Ø#Øð 'ó 
ˆñ  Ø" _Ñ4Ð4ä&Ø-×?Ñ?Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9Ø&5×&GÑ&Gô

ð 
	
rE   c                ó²  — | j                   ry d| _         t        j                  | j                  j                  dz   | j                  j
                  z   dz   «      5  | j                  j                  d «       d d d «       t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   Œ¿xY w# 1 sw Y   ŒqxY w# 1 sw Y   y xY w)NTú/rú  rû  )
r†   r!   r‡   r  r  rX   rˆ   r‰   rú  rû  rŠ   s     r2   rˆ   zTFLEDMainLayer.build	  s  € Ø�:Š:ØØˆŒ
ô �]‰]˜4Ÿ;™;×9Ñ9¸CÑ?À$Ç+Á+×BRÑBRÑRÐUXÑXÓYñ 	$Ø�K‰K×Ñ˜dÔ#÷	$ä�4˜ DÓ)Ð5Ü—‘˜tŸ|™|×0Ñ0Ó1ñ )Ø—‘×"Ñ" 4Ô(÷)ä�4˜ DÓ)Ð5Ü—‘˜tŸ|™|×0Ñ0Ó1ñ )Ø—‘×"Ñ" 4Ô(÷)ð )ð 6÷	$ð 	$ú÷)ð )ú÷)ð )ús$   ÁD5Â5EÄEÄ5D>ÅE
ÅEru  ©NNNNNNNNNNNNNNNF)r  z3Optional[Union[Tuple, TFLEDEncoderBaseModelOutput]]rN   )rb   rc   rd   r   r~  rP   r  r  r   rY   rˆ   rf   rg   s   @r2   rõ  rõ  ¬  sr   ø„ à€LõIòò0ð
 ð ØØØ#ØØØOSØ"ØØØ"ØØØ!ØØð#K
ð MòK
ó ðK
÷Z)rE   rõ  zQThe bare LED Model outputting raw hidden-states without any specific head on top.c                  óþ   ‡ — e Zd Zˆ fd„Zd„ Zd„ Ze eej                  d«      «       e
eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
d„«       «       «       Zd„ Zdd„Zˆ xZS )Ú
TFLEDModelc                óP   •— t        ‰| �  |g|¢­i |¤Ž t        |d¬«      | _        y )Nrx  rO  )rO   rP   rõ  rx  ©rQ   rt   r¨   rT   rU   s       €r2   rP   zTFLEDModel.__init__+	  s(   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3ä! &¨uÔ5ˆ�rE   c                ó.   — | j                   j                  S rN   ©rx  rú  r­  s    r2   Úget_encoderzTFLEDModel.get_encoder0	  ó   € Ø�x‰x×ÑÐrE   c                ó.   — | j                   j                  S rN   ©rx  rû  r­  s    r2   Úget_decoderzTFLEDModel.get_decoder3	  r  rE   zbatch_size, sequence_length)Ú
checkpointÚoutput_typer~  c                óH   — | j                  |||||||||	|
||||||¬«      }|S )N)r,   r©   r  r  r  rz  rÅ  r  rŒ  r´  r  ré  rÆ  rÇ  rÈ  r˜   )rx  )rQ   r,   r©   r  r  rÅ  r  r  rz  rŒ  r´  r  ré  rÆ  rÇ  rÈ  r˜   rT   r³   s                      r2   rY   zTFLEDModel.call6	  sN   € ð6 —(‘(ØØ)Ø/Ø#9Ø+Ø"7ØØ/Ø+Ø'Ø"7ØØ/Ø!5Ø#Øð! ó 
ˆð& ˆrE   c                óZ  — | j                   j                  r"t        j                  |j                  «      d   nd }| j                   j
                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }| j                   j
                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }t        |j                  |||||j                   |||¬«	      S )Nr   r	  )rt   ré  r!   rÿ   rŒ  rÇ  r$   r�  rÆ  rŽ  r�  rk  r‘  r’  rŠ  r„  r�  ©	rQ   r$  ÚpkvÚdec_hsÚ	dec_attnsÚcross_attnsÚenc_hsÚ	enc_attnsÚenc_g_attnss	            r2   Úserving_outputzTFLEDModel.serving_outputf	  s>  € Ø59·[±[×5JÒ5JŒb�h‰h�v×-Ñ-Ó.¨qÒ1ÐPTˆØGKÇ{Á{×GgÒGg”×%Ñ% f×&BÑ&BÔCÐmqˆØGKÇ{Á{×GdÒGd”B×(Ñ(¨×)BÑ)BÔCÐjnˆ	ØGKÇ{Á{×GdÒGd”b×*Ñ*¨6×+BÑ+BÔCÐjnˆØGKÇ{Á{×GgÒGg”×%Ñ% f×&BÑ&BÔCÐmqˆØGKÇ{Á{×GdÒGd”B×(Ñ(¨×)BÑ)BÔCÐjnˆ	ØPT×P[ÑP[×PmÒPm”b×*Ñ*¨6×+KÑ+KÔLÐswˆä&Ø$×6Ñ6ØØ"(Ø(Ø(Ø&,×&FÑ&FØ"(Ø(Ø&1ô

ð 
	
rE   c                óú   — | j                   ry d| _         t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   y xY w)NTrx  )r†   r‰   r!   r‡   rx  rX   rˆ   rŠ   s     r2   rˆ   zTFLEDModel.build{	  se   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ %Ø—‘—‘˜tÔ$÷%ð %ð 2÷%ð %ús   ÁA1Á1A:r  )"r,   úTFModelInputType | Noner©   rH  r  rH  r  rH  rÅ  rH  r  rH  r  rH  rz  rH  rŒ  rI  r´  rH  r  rH  ré  úbool | NonerÆ  r.  rÇ  r.  rÈ  r.  r˜   rF  rJ  z*Tuple[tf.Tensor] | TFLEDSeq2SeqModelOutputrN   )rb   rc   rd   rP   r  r  r   r   ÚLED_INPUTS_DOCSTRINGÚformatr   Ú_CHECKPOINT_FOR_DOCrŠ  Ú_CONFIG_FOR_DOCrY   r+  rˆ   rf   rg   s   @r2   r  r  &	  s<  ø„ ô
6ò
 ò ð Ù*Ð+?×+FÑ+FÐGdÓ+eÓfÙØ&Ø+Ø$ôð .2Ø+/Ø.2Ø37Ø&*Ø.2Ø,0Ø26Ø:>Ø*.Ø26Ø!%Ø)-Ø,0Ø#'Øð#'à*ð'ð )ð'ð ,ð	'ð
 !1ð'ð $ð'ð ,ð'ð *ð'ð  0ð'ð 8ð'ð (ð'ð  0ð'ð ð'ð 'ð'ð *ð'ð  !ð!'ð" ð#'ð& 
4ò''óó gó ð'òR
÷*%rE   r  c                  ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )Ú	BiasLayerz®
    Bias as a layer. It is used for serialization purposes: `keras.Model.save_weights` stores on a per-layer basis,
    so all weights have to be registered in a layer.
    c                ó\   •— t        ‰| �  dd|i|¤Ž | j                  ||||¬«      | _        y )NrX   ©rX   rÌ   ÚinitializerÚ	trainablers   )rO   rP   Ú
add_weightr8  )rQ   rÌ   r7  r8  rX   rT   rU   s         €r2   rP   zBiasLayer.__init__‹	  s3   ø€ Ü‰ÑÑ-˜dÐ- fÒ-ð —O‘O¨°UÈÐ_h�OÓiˆ�	rE   c                ó    — || j                   z   S rN   )r8  )rQ   Úxs     r2   rY   zBiasLayer.call’	  s   € Ø�4—9‘9‰}ÐrE   ra   rg   s   @r2   r4  r4  …	  s   ø„ ñô
jörE   r4  zKThe LED Model with a language modeling head. Can be used for summarization.c                  ó&  ‡ — e Zd ZddgZˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
e ee«       eee¬
«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       «       «       Zd„ Z	 	 	 	 	 	 dd„Zdd„Zd„ Zdd„Zˆ xZS )ÚTFLEDForConditionalGenerationzled.encoder.embed_tokens.weightzled.decoder.embed_tokens.weightc                óÀ   •— t        ‰| �  |g|¢­i |¤Ž t        |d¬«      | _        |j                  | _        t        dd|j                  gdd¬«      | _        d| _        y )Nrx  rO  Úfinal_logits_biasr   r<   Fr6  )	rO   rP   rõ  rx  ré  r4  rý  Ú
bias_layerÚsupports_xla_generationr  s       €r2   rP   z&TFLEDForConditionalGeneration.__init__ 	  sa   ø€ Ü‰Ñ˜Ð3 &Ò3¨FÒ3Ü! &¨uÔ5ˆŒØ×)Ñ)ˆŒä#Ø$¨Q°×0AÑ0AÐ,BÐPWÐchô
ˆŒð
 (-ˆÕ$rE   c                ó.   — | j                   j                  S rN   r  r­  s    r2   r  z)TFLEDForConditionalGeneration.get_decoder¬	  r  rE   c                ó.   — | j                   j                  S rN   r  r­  s    r2   r  z)TFLEDForConditionalGeneration.get_encoder¯	  r  rE   c                ó2   — d| j                   j                  iS )Nr?  )r@  r8  r­  s    r2   Úget_biasz&TFLEDForConditionalGeneration.get_bias²	  s   € Ø# T§_¡_×%9Ñ%9Ð:Ð:rE   c                ó¤   — |d   j                   d   }t        dd|gdd¬«      | _        | j                  j                  j	                  |d   «       y )Nr?  r   r   r<   Fr6  )rÌ   r4  r@  r8  Úassign)rQ   rn   rý  s      r2   Úset_biasz&TFLEDForConditionalGeneration.set_biasµ	  sR   € àÐ.Ñ/×5Ñ5°bÑ9ˆ
Ü#Ø$¨Q°
¨OÈÐ\aô
ˆŒð 	�‰×Ñ×#Ñ# EÐ*=Ñ$>Õ?rE   c                ó"   — | j                  «       S rN   )r  r­  s    r2   Úget_output_embeddingsz3TFLEDForConditionalGeneration.get_output_embeddings½	  s   € Ø×(Ñ(Ó*Ð*rE   c                ó&   — | j                  |«       y rN   )r  )rQ   rn   s     r2   Úset_output_embeddingsz3TFLEDForConditionalGeneration.set_output_embeddingsÀ	  s   € Ø×!Ñ! %Õ(rE   )r   r~  c                ór  — |�;d}|€7|€5t        || j                  j                  | j                  j                  «      }| j	                  |||||||||	|
||||||¬«      }t        j                  |d   | j                  j                  j                  d¬«      }| j                  |«      }|€dn| j                  ||«      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  |j                  |j                   |j"                  |j$                  |j&                  ¬«
      S )	aŽ  
        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, TFLEDForConditionalGeneration
        >>> import tensorflow as tf

        >>> mname = "allenai/led-base-16384"
        >>> tokenizer = AutoTokenizer.from_pretrained(mname)
        >>> TXT = "My friends are <mask> but they eat too many carbs."
        >>> model = TFLEDForConditionalGeneration.from_pretrained(mname)
        >>> batch = tokenizer([TXT], return_tensors="tf")
        >>> logits = model(inputs=batch.input_ids).logits
        >>> probs = tf.nn.softmax(logits[0])
        >>> # probs[5] is associated with the mask token
        ```NF)r©   r  r  r  rz  rÅ  r  rŒ  r´  r  ré  rÆ  rÇ  rÈ  r˜   r   Tr  r   )
r•  r–  rŒ  r�  rŽ  r�  r�  rk  r‘  r’  )r3   rt   r-   r.   rx  r!   r  r  Úweightsr@  Úhf_compute_lossr”  rŒ  r�  rŽ  r�  r�  rk  r‘  r’  )rQ   r,   r©   r  r  rÅ  r  r  rz  rŒ  r´  r  ré  rÆ  rÇ  rÈ  Úlabelsr˜   r³   Ú	lm_logitsÚmasked_lm_lossr$  s                         r2   rY   z"TFLEDForConditionalGeneration.callÃ	  s]  € ðT ÐØˆIØ Ð(Ð-BÐ-JÜ$6Ø˜DŸK™K×4Ñ4°d·k±k×6XÑ6Xó%Ð!ð —(‘(ØØ)Ø/Ø#9Ø+Ø"7ØØ/Ø+Ø'Ø"7ØØ/Ø!5Ø#Øð! ó 
ˆô$ —I‘I˜g a™j¨$¯(©(¯/©/×*AÑ*AÈtÔTˆ	Ø—O‘O IÓ.ˆ	Ø!' ™°T×5IÑ5IÈ&ÐR[Ó5\ˆáØ�\ G¨A¨B KÑ/ˆFØ3AÐ3M�^Ð%¨Ñ.ÐYÐSYÐYÜ#ØØØ#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9Ø&-×&GÑ&Gô
ð 	
rE   c                óZ  — | j                   j                  r"t        j                  |j                  «      d   nd }| j                   j
                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }| j                   j
                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }| j                   j                  rt        j                  |j                  «      nd }t        |j                  |||||j                   |||¬«	      S )Nr   )	r–  rŒ  r�  rŽ  r�  r�  rk  r‘  r’  )rt   ré  r!   rÿ   rŒ  rÇ  r$   r�  rÆ  rŽ  r�  rk  r‘  r’  r”  r–  r�  r#  s	            r2   r+  z,TFLEDForConditionalGeneration.serving_output
  s<  € Ø59·[±[×5JÒ5JŒb�h‰h�v×-Ñ-Ó.¨qÒ1ÐPTˆØGKÇ{Á{×GgÒGg”×%Ñ% f×&BÑ&BÔCÐmqˆØGKÇ{Á{×GdÒGd”B×(Ñ(¨×)BÑ)BÔCÐjnˆ	ØGKÇ{Á{×GdÒGd”b×*Ñ*¨6×+BÑ+BÔCÐjnˆØGKÇ{Á{×GgÒGg”×%Ñ% f×&BÑ&BÔCÐmqˆØGKÇ{Á{×GdÒGd”B×(Ñ(¨×)BÑ)BÔCÐjnˆ	ØPT×P[ÑP[×PmÒPm”b×*Ñ*¨6×+KÑ+KÔLÐswˆä#Ø—=‘=ØØ"(Ø(Ø(Ø&,×&FÑ&FØ"(Ø(Ø&1ô

ð 
	
rE   c           	     ó2   — |�|d d …dd …f   }d |||||||dœS )Nr   )r,   r  rŒ  r  r©   rÅ  r  ré  rs   )	rQ   r  rŒ  r©   rÅ  r  ré  r  rT   s	            r2   Úprepare_inputs_for_generationz;TFLEDForConditionalGeneration.prepare_inputs_for_generation/
  s?   € ð Ð&Ø 1²!°R±S°&Ñ 9Ðð Ø.Ø.Ø!2Ø,Ø"Ø!2Ø"ñ	
ð 		
rE   c                ól   — t        || j                  j                  | j                  j                  «      S rN   )r3   rt   r-   r.   )rQ   rP  s     r2   Ú%prepare_decoder_input_ids_from_labelszCTFLEDForConditionalGeneration.prepare_decoder_input_ids_from_labelsI
  s%   € Ü! &¨$¯+©+×*BÑ*BÀDÇKÁK×DfÑDfÓgÐgrE   c           	     ó*  — t         j                  j                  dt         j                  j                  j                  ¬«      }| j
                  j                  r—t        j                  |d«      }t        j                  || j
                  j                  «      }t        j                  t        j                  |dt        |«      d   f«      |«      }t        j                  ||«      } |||«      S  |t        j                  j                  |«      |«      }t        j                  || j
                  j                  k7  |j                   ¬«      }||z  }	t        j"                  |	«      t        j"                  |«      z  }
t        j                  |
d«      S )z(CrossEntropyLoss that ignores pad tokensT)Úfrom_logitsÚ	reduction)r   r   rr   r   )r   )r   ÚlossesÚSparseCategoricalCrossentropyÚ	ReductionÚNONErt   Útf_legacy_lossr!   r;   Ú	not_equalr-   Úboolean_maskr   ÚnnÚrelur"   r    Ú
reduce_sum)rQ   rP  r–  Úloss_fnÚmelted_labelsÚactive_lossÚreduced_logitsÚunmasked_lossÚ	loss_maskÚmasked_lossÚreduced_masked_losss              r2   rO  z-TFLEDForConditionalGeneration.hf_compute_lossL
  s(  € ä—,‘,×<Ñ<ÈÔY^×YeÑYe×YoÑYo×YtÑYtÐ<ÓuˆØ�;‰;×%Ò%ÜŸJ™J v¨uÓ5ˆMÜŸ,™, }°d·k±k×6NÑ6NÓOˆKÜŸ_™_¬R¯Z©Z¸ÀÄZÐPVÓEWÐXYÑEZÐ@[Ó-\Ð^iÓjˆNÜ—_‘_ ]°KÓ@ˆFÙ˜6 >Ó2Ð2ñ  ¤§¡§
¡
¨6Ó 2°FÓ;ˆä—G‘G˜F d§k¡k×&>Ñ&>Ñ>Àm×FYÑFYÔZˆ	Ø# iÑ/ˆÜ Ÿm™m¨KÓ8¼2¿=¹=ÈÓ;SÑSÐÜ�z‰zÐ-¨tÓ4Ð4rE   c                óÆ  — | j                   ry d| _         t        | dd «      �Mt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       t        | dd «      �Nt        j                  | j                  j
                  «      5  | j                  j                  d «       d d d «       y y # 1 sw Y   ŒexY w# 1 sw Y   y xY w)NTrx  r@  )r†   r‰   r!   r‡   rx  rX   rˆ   r@  rŠ   s     r2   rˆ   z#TFLEDForConditionalGeneration.build^
  s±   € Ø�:Š:ØØˆŒ
Ü�4˜ Ó%Ð1Ü—‘˜tŸx™xŸ}™}Ó-ñ %Ø—‘—‘˜tÔ$÷%ä�4˜ tÓ,Ð8Ü—‘˜tŸ™×3Ñ3Ó4ñ ,Ø—‘×%Ñ% dÔ+÷,ð ,ð 9÷%ð %ú÷,ð ,ús   ÁCÂ%CÃCÃC )NNNNNNNNNNNNNNNNF)$r,   r-  r©   únp.ndarray | tf.Tensor | Noner  rn  r  rn  rÅ  rn  r  rn  r  z"TFLEDEncoderBaseModelOutput | Nonerz  rn  rŒ  z1Tuple[Tuple[Union[np.ndarray, tf.Tensor]]] | Noner´  rn  r  rn  ré  r.  rÆ  r.  rÇ  r.  rÈ  r.  rP  rH  r˜   rF  rJ  z'Tuple[tf.Tensor] | TFLEDSeq2SeqLMOutput)NNNNNN)rP  rG  rN   )rb   rc   rd   Ú"_keys_to_ignore_on_load_unexpectedrP   r  r  rE  rH  rJ  rL  r   r   r/  r   r”  r2  rY   r+  rU  rW  rO  rˆ   rf   rg   s   @r2   r=  r=  –	  s–  ø„ ð 	+Ø*ð*Ð&ô

-ò ò ò;ò@ò+ò)ð Ù*Ð+?Ó@ÙÐ+?ÈoÔ^ð .2Ø8<Ø;?Ø@DØ37Ø;?Ø>BØ?CØMQØ7;Ø?CØ!%Ø)-Ø,0Ø#'Ø#'Øð%R
à*ðR
ð 6ðR
ð 9ð	R
ð
 !>ðR
ð 1ðR
ð 9ðR
ð <ðR
ð  =ðR
ð KðR
ð 5ðR
ð  =ðR
ð ðR
ð 'ðR
ð *ðR
ð  !ð!R
ð" !ð#R
ð$ ð%R
ð& 
1ò'R
ó _ó Aó ðR
òh
ð0 ØØØØØó
ó4hò5÷$	,rE   r=  )r=  r  rw  )r,   rG  r-   r^   r.   r^   r_   )r>   r`   r?   r^   rN   )rB   rG  rA   zOptional[int])Fre   Ú
__future__r   rÃ  Údataclassesr   Útypingr   r   r   r   ÚnumpyÚnpÚ
tensorflowr!   Úactivations_tfr
   Úmodeling_tf_outputsr   Úmodeling_tf_utilsr   r   r   r   r   r   Útf_utilsr   r   r   Úutilsr   r   r   r   r   r   Úconfiguration_ledr   Ú
get_loggerrb   rŸ  r1  r2  r9   r3   rD   rJ   r{   rü  rL   ÚLayerri   r!  r0  rL  rb  rw  r‚  rŠ  r”  ÚLED_START_DOCSTRINGr/  r˜  rà  rõ  r  r4  r=  Ú__all__rs   rE   r2   ú<module>r€     sƒ  ðñ å "ã Ý !ß /Ó /ã Û å /Ý N÷÷ ÷ SÑ R÷÷ õ )ð 
ˆ×	Ñ	˜HÓ	%€à.Ð Ø€ð €óô2;ô$
6ôC e§l¡l×&<Ñ&<ô Cô$`
 §¡× 2Ñ 2ô `
ôF$K˜EŸL™L×.Ñ.ô $KôNeB˜EŸL™L×.Ñ.ô eBôPMJ˜Ÿ™×*Ñ*ô MJô`EJ˜Ÿ™×*Ñ*ô EJôPÐ,ô ð ô'; +ó ';ó ð';ðT ô@C˜kó @Có ð@CðF ô?C˜;ó ?Có ð?CðD'Ð ðRAÐ ðH ôJ&�5—<‘<×%Ñ%ó J&ó ðJ&ðZ ô_&�5—<‘<×%Ñ%ó _&ó ð_&ðD ôv)�U—\‘\×'Ñ'ó v)ó ðv)ñr ØWØóôW%Ð%ó W%ó	ðW%ôv�—‘×"Ñ"ô ñ" ØQØóôM,Ð$8ó M,ó	ðM,ò` R�rE   