Ë
    S^(hA” ã                   óH  — d Z ddlZddlZddlZddlmZmZmZmZ ddl	Z	ddl
Z	ddl	mZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZ dd
lmZmZ ddlmZmZmZm Z m!Z!m"Z"m#Z# 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.  e«       rddlm/Z/  e+j`                  e1«      Z2dZ3dZ4g d¢Z5dZ6dZ7dZ8dZ9dZ:dZ;de	jx                  de=de=fd„Z> G d„ dej~                  «      Z@ G d „ d!ej~                  «      ZA G d"„ d#ej„                  «      ZC G d$„ d%eC«      ZD G d&„ d'eC«      ZEeCeEeDd(œZF G d)„ d*ej„                  «      ZG G d+„ d,ej„                  «      ZH G d-„ d.ej„                  «      ZI G d/„ d0e%«      ZJ G d1„ d2eJ«      ZK G d3„ d4eJ«      ZLd5ZMd6ZNd7ZO G d8„ d9eJ«      ZP G d:„ d;eJ«      ZQ e)d<eM«       G d=„ d>eJ«      «       ZR e)d?eM«       G d@„ dAeJe«      «       ZS e)dBeM«       G dC„ dDeJ«      «       ZT e)dEeM«       G dF„ dGeJ«      «       ZU G dH„ dIeJ«      ZV e)dJeM«       G dK„ dLeJe«      «       ZWg dM¢ZXy)NzPyTorch BART model.é    N)ÚListÚOptionalÚTupleÚUnion)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )ÚACT2FN)ÚGenerationMixin)Ú_prepare_4d_attention_maskÚ#_prepare_4d_attention_mask_for_sdpaÚ!_prepare_4d_causal_attention_maskÚ*_prepare_4d_causal_attention_mask_for_sdpa)Ú!flash_attn_supports_top_left_maskÚis_flash_attn_available)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚ!CausalLMOutputWithCrossAttentionsÚSeq2SeqLMOutputÚSeq2SeqModelOutputÚ#Seq2SeqQuestionAnsweringModelOutputÚSeq2SeqSequenceClassifierOutput)ÚPreTrainedModel)Úadd_code_sample_docstringsÚadd_end_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )Ú
BartConfig)Ú_flash_attention_forwardzfacebook/bart-baser#   )r"   é   i   zvalhalla/bart-large-sst2ç        z
'POSITIVE'z%valhalla/bart-large-finetuned-squadv1gáz®Gáâ?z' nice puppet'Ú	input_idsÚpad_token_idÚdecoder_start_token_idc                 óÖ   — | j                  | j                  «      }| dd…dd…f   j                  «       |dd…dd…f<   ||dd…df<   |€t        d«      ‚|j	                  |dk(  |«       |S )z1
    Shift input ids one token to the right.
    Néÿÿÿÿr"   r   z1self.model.config.pad_token_id has to be defined.iœÿÿÿ)Ú	new_zerosÚshapeÚcloneÚ
ValueErrorÚmasked_fill_)r'   r(   r)   Úshifted_input_idss       úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/bart/modeling_bart.pyÚshift_tokens_rightr3   P   s}   € ð "×+Ñ+¨I¯O©OÓ<ÐØ(ª¨C¨R¨C¨Ñ0×6Ñ6Ó8Ð’a˜™�eÑØ4Ð’a˜�dÑàÐÜÐLÓMÐMà×"Ñ"Ð#4¸Ñ#<¸lÔKàÐó    c                   óV   ‡ — e Zd ZdZdedefˆ fd„Zddej                  defˆ fd„Zˆ xZ	S )	ÚBartLearnedPositionalEmbeddingzN
    This module learns positional embeddings up to a fixed maximum size.
    Únum_embeddingsÚembedding_dimc                 óN   •— d| _         t        ‰| �	  || j                   z   |«       y ©Né   )ÚoffsetÚsuperÚ__init__)Úselfr7   r8   Ú	__class__s      €r2   r>   z'BartLearnedPositionalEmbedding.__init__e   s$   ø€ ð ˆŒÜ‰Ñ˜¨$¯+©+Ñ5°}ÕEr4   r'   Úpast_key_values_lengthc                 óü   •— |j                   dd \  }}t        j                  |||z   t        j                  | j                  j
                  ¬«      j                  |d«      }t        ‰| �!  || j                  z   «      S )z3`input_ids' shape is expected to be [bsz x seqlen].Nr;   )ÚdtypeÚdevicer+   )
r-   ÚtorchÚarangeÚlongÚweightrD   Úexpandr=   Úforwardr<   )r?   r'   rA   ÚbszÚseq_lenÚ	positionsr@   s         €r2   rJ   z&BartLearnedPositionalEmbedding.forwardk   so   ø€ ð !—‘ r¨Ð*‰ˆˆWÜ—L‘LØ"Ð$:¸WÑ$DÌEÏJÉJÐ_c×_jÑ_j×_qÑ_qô
ç
‰&��b‹/ð 	ô ‰w‰˜y¨4¯;©;Ñ6Ó7Ð7r4   )r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr>   rE   ÚTensorrJ   Ú__classcell__©r@   s   @r2   r6   r6   `   s:   ø„ ñðF sð F¸3õ Fñ8 §¡ð 8Às÷ 8ñ 8r4   r6   c            
       ó`   ‡ — e Zd ZdZd	dedededee   fˆ fd„Zdej                  fˆ fd„Z
ˆ xZS )
ÚBartScaledWordEmbeddingz\
    This module overrides nn.Embeddings' forward by multiplying with embeddings scale.
    r7   r8   Úpadding_idxÚembed_scalec                 ó6   •— t         ‰| �  |||«       || _        y ©N)r=   r>   rY   )r?   r7   r8   rX   rY   r@   s        €r2   r>   z BartScaledWordEmbedding.__init__{   s   ø€ Ü‰Ñ˜¨¸ÔDØ&ˆÕr4   r'   c                 ó<   •— t         ‰| �  |«      | j                  z  S r[   )r=   rJ   rY   )r?   r'   r@   s     €r2   rJ   zBartScaledWordEmbedding.forward   s   ø€ Ü‰w‰˜yÓ)¨D×,<Ñ,<Ñ<Ð<r4   )ç      ð?)rN   rO   rP   rQ   rR   r   Úfloatr>   rE   rS   rJ   rT   rU   s   @r2   rW   rW   v   sE   ø„ ññ' sð '¸3ð 'ÈSð 'Ð_gÐhmÑ_nõ 'ð= §¡÷ =ñ =r4   rW   c                   ó†  ‡ — e Zd ZdZ	 	 	 	 	 ddededededededee   fˆ fd	„Z	d
e
j                  dedefd„Z	 	 	 	 	 dde
j                  dee
j                     deee
j                        dee
j                     dee
j                     dedee
j                  ee
j                     eee
j                        f   fd„Zˆ xZS )ÚBartAttentionz=Multi-headed attention from 'Attention Is All You Need' paperÚ	embed_dimÚ	num_headsÚdropoutÚ
is_decoderÚbiasÚ	is_causalÚconfigc                 ó
  •— t         ‰| �  «        || _        || _        || _        ||z  | _        || _        | j
                  |z  | j                  k7  rt        d| j                  › d|› d�«      ‚| j
                  dz  | _        || _	        || _
        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        y )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).g      à¿©re   )r=   r>   ra   rb   rc   Úhead_dimrg   r/   Úscalingrd   rf   r   ÚLinearÚk_projÚv_projÚq_projÚout_proj)	r?   ra   rb   rc   rd   re   rf   rg   r@   s	           €r2   r>   zBartAttention.__init__†   sä   ø€ ô 	‰ÑÔØ"ˆŒØ"ˆŒØˆŒØ! YÑ.ˆŒØˆŒà�M‰M˜IÑ%¨$¯.©.Ò8ÜØMÈdÏnÉnÐM]Ø$ Y K¨rð3óð ð —}‘} dÑ*ˆŒØ$ˆŒØ"ˆŒä—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜŸ	™	 )¨Y¸TÔBˆ�r4   ÚtensorrL   rK   c                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S )Nr"   r;   )Úviewrb   rj   Ú	transposeÚ
contiguous©r?   rq   rL   rK   s       r2   Ú_shapezBartAttention._shape¥   s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr4   Úhidden_statesÚkey_value_statesÚpast_key_valueÚattention_maskÚlayer_head_maskÚoutput_attentionsÚreturnc                 ó
  — |du}|j                  «       \  }}	}
| j                  |«      | j                  z  }|r0|�.|d   j                  d   |j                  d   k(  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} | j	                  ||	|«      j                  |Ž } |j                  |Ž } |j                  |Ž }|j                  d«      }t        j                  ||j                  dd«      «      }|j                  «       || j                  z  |	|fk7  r/t!        d|| j                  z  |	|f› d|j                  «       › �«      ‚|�{|j                  «       |d|	|fk7  r#t!        d	|d|	|f› d|j                  «       › �«      ‚|j                  || j                  |	|«      |z   }|j                  || j                  z  |	|«      }t"        j$                  j'                  |d¬«      }|�›|j                  «       | j                  fk7  r*t!        d
| j                  f› d|j                  «       › �«      ‚|j                  dddd«      |j                  || j                  |	|«      z  }|j                  || j                  z  |	|«      }|r?|j                  || j                  |	|«      }|j                  || j                  z  |	|«      }nd}t"        j$                  j)                  || j(                  | j*                  ¬«      }t        j                  ||«      }|j                  «       || j                  z  |	| j                  fk7  r9t!        d|| j                  z  |	| j                  f› d|j                  «       › �«      ‚|j                  || j                  |	| j                  «      }|j                  dd«      }|j                  ||	| j,                  «      }| j/                  |«      }|||fS )ú#Input shape: Batch x Time x ChannelNr   r;   r"   r+   ©Údimz$Attention weights should be of size ú	, but is z!Attention mask should be of size z/Head mask for a single layer should be of size ©ÚpÚtrainingú `attn_output` should be of size )Úsizero   rk   r-   rw   rm   rn   rE   Úcatrd   rb   rj   rs   ÚreshapeÚbmmrt   r/   r   Ú
functionalÚsoftmaxrc   r†   ra   rp   )r?   rx   ry   rz   r{   r|   r}   Úis_cross_attentionrK   Útgt_lenÚ_Úquery_statesÚ
key_statesÚvalue_statesÚ
proj_shapeÚsrc_lenÚattn_weightsÚattn_weights_reshapedÚ
attn_probsÚattn_outputs                       r2   rJ   zBartAttention.forward¨   s  € ð .°TÐ9Ðà'×,Ñ,Ó.‰ˆˆW�að —{‘{ =Ó1°D·L±LÑ@ˆñ ØÐ*Ø˜qÑ!×'Ñ'¨Ñ*Ð.>×.DÑ.DÀQÑ.GÒGð (¨Ñ*ˆ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ÈÔJˆJÜ Ÿ9™9 n°QÑ&7¸Ð%FÈAÔN‰Lð Ÿ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLà�?Š?ð )¨,Ð7ˆNà˜DŸN™NÑ*¨B°·±Ð>ˆ
ØC�t—{‘{ <°¸#Ó>×CÑCÀZÐPˆØ'�Z×'Ñ'¨Ð4ˆ
Ø+�|×+Ñ+¨ZÐ8ˆà—/‘/ !Ó$ˆÜ—y‘y ¨z×/CÑ/CÀAÀqÓ/IÓJˆà×ÑÓ 3¨¯©Ñ#7¸À'Ð"JÒJÜØ6¸¸d¿n¹nÑ8LÈgÐW^Ð7_Ð6`ð aØ ×%Ñ%Ó'Ð(ð*óð ð
 Ð%Ø×"Ñ"Ó$¨¨a°¸'Ð(BÒBÜ Ø7¸¸aÀÈ'Ð8RÐ7SÐS\Ð]k×]pÑ]pÓ]rÐ\sÐtóð ð (×,Ñ,¨S°$·.±.À'È7ÓSÐVdÑdˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLä—}‘}×,Ñ,¨\¸rÐ,ÓBˆàÐ&Ø×#Ñ#Ó%¨$¯.©.Ð):Ò:Ü ØEÀtÇ~Á~ÐFWÐEXð YØ'×,Ñ,Ó.Ð/ð1óð ð +×/Ñ/°°2°q¸!Ó<¸|×?PÑ?PÐQTÐVZ×VdÑVdÐfmÐovÓ?wÑwˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLáð
 %1×$5Ñ$5°c¸4¿>¹>È7ÐT[Ó$\Ð!Ø0×5Ñ5°c¸D¿N¹NÑ6JÈGÐU\Ó]‰Là$(Ð!ä—]‘]×*Ñ*¨<¸4¿<¹<ÐRV×R_ÑR_Ð*Ó`ˆ
ä—i‘i 
¨LÓ9ˆà×ÑÓ #¨¯©Ñ"6¸ÀÇÁÐ!OÒOÜØ2°C¸$¿.¹.Ñ4HÈ'ÐSW×S`ÑS`Ð3aÐ2bð cØ×$Ñ$Ó&Ð'ð)óð ð
 "×&Ñ& s¨D¯N©N¸GÀTÇ]Á]ÓSˆØ!×+Ñ+¨A¨qÓ1ˆð "×)Ñ)¨#¨w¸¿¹ÓGˆà—m‘m KÓ0ˆàÐ1°>ÐAÐAr4   )r&   FTFN©NNNNF)rN   rO   rP   rQ   rR   r^   Úboolr   r#   r>   rE   rS   rw   r   rJ   rT   rU   s   @r2   r`   r`   ƒ   sM  ø„ ÙGð Ø ØØØ'+ñCàðCð ðCð ð	Cð
 ðCð ðCð ðCð ˜Ñ$õCð>e˜UŸ\™\ð e°Cð e¸có eð 48Ø8<Ø15Ø26Ø"'ñvBà—|‘|ðvBð # 5§<¡<Ñ0ðvBð !  u§|¡|Ñ!4Ñ5ð	vBð
 ! §¡Ñ.ðvBð " %§,¡,Ñ/ðvBð  ðvBð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷vBr4   r`   c                   óV  ‡ — e Zd ZdZˆ fd„Zdej                  dedefd„Z	 	 	 	 	 ddej                  de	ej                     d	e	e
ej                        d
e	ej                     de	ej                     dede
ej                  e	ej                     e	e
ej                        f   fd„Zˆ xZS )ÚBartFlashAttention2aD  
    Bart flash attention module. This module inherits from `BartAttention` as the weights of the module stays
    untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
    flash attention and deal with padding tokens in case the input contains any of them.
    c                 óB   •— t        ‰| �  |i |¤Ž t        «       | _        y r[   )r=   r>   r   Ú_flash_attn_uses_top_left_mask)r?   ÚargsÚkwargsr@   s      €r2   r>   zBartFlashAttention2.__init__(  s#   ø€ Ü‰Ñ˜$Ð) &Ò)ô
 /PÓ.QˆÕ+r4   rq   rL   rK   c                 óR   — |j                  ||| j                  | j                  «      S r[   )rs   rb   rj   rv   s       r2   Ú_reshapezBartFlashAttention2._reshape0  s   € Ø�{‰{˜3 ¨¯©¸¿¹ÓGÐGr4   rx   ry   rz   r{   r|   r}   r~   c           
      óÎ  — |rt        d«      ‚|d u}|j                  «       \  }}	}
| j                  | j                  |«      d|«      }|rP|�N|d   j                  d   |j                  d   k(  r,|d   j                  dd«      }|d   j                  dd«      }�n*|rE| j                  | j                  |«      d|«      }| j                  | j                  |«      d|«      }nã|��| j                  | j                  |«      d|«      }| j                  | j                  |«      d|«      }t        j                  |d   j                  dd«      |gd¬«      }t        j                  |d   j                  dd«      |gd¬«      }nD| j                  | j                  |«      d|«      }| j                  | j                  |«      d|«      }| j                  r$|j                  dd«      |j                  dd«      f}|j                  d   }|�||d   j                  d   z  }|j                  }|t        j                  k(  rÂt        j                  «       rt        j                  «       }nMt        | j                   d«      r| j                   j"                  }n | j                  j$                  j                  }t&        j)                  d	|› d
�«       |j+                  |«      }|j+                  |«      }|j+                  |«      }t-        |||||	| j.                  r| j0                  nd| j2                  | j4                  ¬«      }|j7                  ||	d«      }| j9                  |«      }|sd }||fS )Nz@BartFlashAttention2 attention does not support output_attentionsr+   r   r;   r"   r�   éþÿÿÿÚ_pre_quantization_dtypez¾The input hidden states seems to be silently casted in float32, this might be related to the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in ú.r&   )rc   rf   Úuse_top_left_mask)r/   rˆ   r£   ro   r-   rt   rm   rn   rE   r‰   rd   rC   Úfloat32Úis_autocast_enabledÚget_autocast_gpu_dtypeÚhasattrrg   r¦   rH   ÚloggerÚwarning_onceÚtor$   r†   rc   rf   rŸ   rŠ   rp   )r?   rx   ry   rz   r{   r|   r}   rŽ   rK   Úq_lenr�   r‘   r’   r“   Ú
kv_seq_lenÚinput_dtypeÚtarget_dtyper™   r–   s                      r2   rJ   zBartFlashAttention2.forward3  s0  € ñ ÜÐ_Ó`Ð`ð .°TÐ9Ðà%×*Ñ*Ó,‰ˆˆU�Að —}‘} T§[¡[°Ó%?ÀÀSÓIˆñ ØÐ*Ø˜qÑ!×'Ñ'¨Ñ*Ð.>×.DÑ.DÀQÑ.GÒGð (¨Ñ*×4Ñ4°Q¸Ó:ˆJØ)¨!Ñ,×6Ñ6°q¸!Ó<ŠLÙàŸ™ t§{¡{Ð3CÓ'DÀbÈ#ÓNˆJØŸ=™=¨¯©Ð5EÓ)FÈÈCÓP‰LØÐ'àŸ™ t§{¡{°=Ó'AÀ2ÀsÓKˆJØŸ=™=¨¯©°]Ó)CÀRÈÓMˆLÜŸ™ N°1Ñ$5×$?Ñ$?ÀÀ1Ó$EÀzÐ#RÐXYÔZˆJÜ Ÿ9™9 n°QÑ&7×&AÑ&AÀ!ÀQÓ&GÈÐ%VÐ\]Ô^‰Lð Ÿ™ t§{¡{°=Ó'AÀ2ÀsÓKˆJØŸ=™=¨¯©°]Ó)CÀRÈÓMˆLà�?Š?ð )×2Ñ2°1°aÓ8¸,×:PÑ:PÐQRÐTUÓ:VÐWˆNà×%Ñ% bÑ)ˆ
ØÐ%Ø˜.¨Ñ+×1Ñ1°"Ñ5Ñ5ˆJð #×(Ñ(ˆØœ%Ÿ-™-Ò'Ü×(Ñ(Ô*Ü$×;Ñ;Ó=‘ä˜Ÿ™Ð&?Ô@Ø#Ÿ{™{×BÑB‘à#Ÿ{™{×1Ñ1×7Ñ7�ä×Ñðà �> ð$ôð (Ÿ?™?¨<Ó8ˆLØ#Ÿ™ |Ó4ˆJØ'Ÿ?™?¨<Ó8ˆLä.ØØØØØØ$(§M¢M�D—L’L°sØ—n‘nØ"×AÑAô	
ˆð "×)Ñ)¨#¨u°bÓ9ˆØ—m‘m KÓ0ˆá ØˆLà˜L¨.Ð8Ð8r4   rš   )rN   rO   rP   rQ   r>   rE   rS   rR   r£   r   r   r›   rJ   rT   rU   s   @r2   r�   r�   !  sæ   ø„ ñôRðH˜uŸ|™|ð H°cð HÀó Hð 48Ø8<Ø15Ø26Ø"'ñi9à—|‘|ði9ð # 5§<¡<Ñ0ði9ð !  u§|¡|Ñ!4Ñ5ð	i9ð
 ! §¡Ñ.ði9ð " %§,¡,Ñ/ði9ð  ði9ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷i9r4   r�   c                   ó$  ‡ — e Zd Z	 	 	 	 	 d	dej                  deej                     deeej                        deej                     deej                     dedeej                  eej                     eeej                        f   fˆ fd„Zˆ xZ	S )
ÚBartSdpaAttentionrx   ry   rz   r{   r|   r}   r~   c                 óz  •— |s|�*t         j                  d«       t        ‰| �  ||||||¬«      S |du}|j	                  «       \  }}	}
| j                  |«      }|r0|�.|d   j                  d   |j                  d   k(  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                  ||	|«      }| j                  r	|€|	dkD  rd	nd
}t        j                  j                  j!                  ||||| j"                  r| j$                  nd|¬«      }|j	                  «       || j&                  |	| j(                  fk7  r7t+        d|| j&                  |	| j(                  f› d|j	                  «       › �«      ‚|j-                  dd«      }|j/                  ||	| j0                  «      }| j3                  |«      }|d|fS )r€   Na£  BartModel is using BartSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True` or `layer_head_mask` not None. Falling back to the manual attention implementation, but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.)ry   rz   r{   r|   r}   r   r;   r"   r+   r�   TFr&   )Ú	attn_maskÚ	dropout_prf   r‡   rƒ   )r­   r®   r=   rJ   rˆ   ro   r-   rw   rm   rn   rE   r‰   rd   rf   r   rŒ   Úscaled_dot_product_attentionr†   rc   rb   rj   r/   rt   rŠ   ra   rp   )r?   rx   ry   rz   r{   r|   r}   rŽ   rK   r�   r�   r‘   r’   r“   rf   r™   r@   s                   €r2   rJ   zBartSdpaAttention.forward   sÕ  ø€ ñ  Ð ;ä×Ñðlôô ‘7‘?ØØ!1Ø-Ø-Ø /Ø"3ð #ó ð ð .°TÐ9Ðà'×,Ñ,Ó.‰ˆˆW�að —{‘{ =Ó1ˆñ ØÐ*Ø˜qÑ!×'Ñ'¨Ñ*Ð.>×.DÑ.DÀQÑ.GÒGð (¨Ñ*ˆ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ÈÔJˆJÜ Ÿ9™9 n°QÑ&7¸Ð%FÈAÔN‰Lð Ÿ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLà�?Š?ð )¨,Ð7ˆNà—{‘{ <°¸#Ó>ˆð
 !ŸNšN¨~Ð/EÈ'ÐTUÊ+‘DÐ[`ˆ	ô —h‘h×)Ñ)×FÑFØØØØ$Ø&*§m¢m�d—l’l¸Øð Gó 
ˆð ×ÑÓ # t§~¡~°wÀÇÁÐ!NÒNÜØ2°C¸¿¹ÈÐRV×R_ÑR_Ð3`Ð2að bØ×$Ñ$Ó&Ð'ð)óð ð
 "×+Ñ+¨A¨qÓ1ˆð "×)Ñ)¨#¨w¸¿¹ÓGˆà—m‘m KÓ0ˆà˜D .Ð0Ð0r4   rš   )
rN   rO   rP   rE   rS   r   r   r›   rJ   rT   rU   s   @r2   rµ   rµ   Ÿ  s¿   ø„ ð 48Ø8<Ø15Ø26Ø"'ñf1à—|‘|ðf1ð # 5§<¡<Ñ0ðf1ð !  u§|¡|Ñ!4Ñ5ð	f1ð
 ! §¡Ñ.ðf1ð " %§,¡,Ñ/ðf1ð  ðf1ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷f1ñ f1r4   rµ   )ÚeagerÚsdpaÚflash_attention_2c                   ó¾   ‡ — e Zd Zdefˆ fd„Z	 d	dej                  dej                  dej                  dee   de	ej                  eej                     f   f
d„Z
ˆ xZS )
ÚBartEncoderLayerrg   c                 ó‚  •— t         ‰| �  «        |j                  | _        t	        |j
                     | j                  |j                  |j                  |¬«      | _        t        j                  | j                  «      | _        |j                  | _        t        |j                     | _        |j                   | _        t        j"                  | j                  |j$                  «      | _        t        j"                  |j$                  | j                  «      | _        t        j                  | j                  «      | _        y )N)ra   rb   rc   rg   )r=   r>   Úd_modelra   ÚBART_ATTENTION_CLASSESÚ_attn_implementationÚencoder_attention_headsÚattention_dropoutÚ	self_attnr   Ú	LayerNormÚself_attn_layer_normrc   r   Úactivation_functionÚactivation_fnÚactivation_dropoutrl   Úencoder_ffn_dimÚfc1Úfc2Úfinal_layer_norm©r?   rg   r@   s     €r2   r>   zBartEncoderLayer.__init__  sÜ   ø€ Ü‰ÑÔØŸ™ˆŒä/°×0KÑ0KÑLØ—n‘nØ×4Ñ4Ø×,Ñ,Øô	
ˆŒô %'§L¡L°·±Ó$@ˆÔ!Ø—~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔÜ—9‘9˜TŸ^™^¨V×-CÑ-CÓDˆŒÜ—9‘9˜V×3Ñ3°T·^±^ÓDˆŒÜ "§¡¨T¯^©^Ó <ˆÕr4   rx   r{   r|   r}   r~   c                 ó¤  — |}| j                  ||||¬«      \  }}}t        j                  j                  || j                  | j                  ¬«      }||z   }| j                  |«      }|}| j                  | j                  |«      «      }t        j                  j                  || j                  | j                  ¬«      }| j                  |«      }t        j                  j                  || j                  | j                  ¬«      }||z   }| j                  |«      }|j                  t        j                  k(  r‹t        j                  |«      j                  «       s#t        j                   |«      j                  «       rEt        j"                  |j                  «      j$                  dz
  }t        j&                  || |¬«      }|f}	|r|	|fz  }	|	S )a§  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`): attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
                `(encoder_attention_heads,)`.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        )rx   r{   r|   r}   r„   iè  )ÚminÚmax)rÅ   r   rŒ   rc   r†   rÇ   rÉ   rÌ   rÊ   rÍ   rÎ   rC   rE   Úfloat16ÚisinfÚanyÚisnanÚfinforÒ   Úclamp)
r?   rx   r{   r|   r}   Úresidualr–   r�   Úclamp_valueÚoutputss
             r2   rJ   zBartEncoderLayer.forward#  s�  € ð$ !ˆØ)-¯©Ø'Ø)Ø+Ø/ð	 *8ó *
Ñ&ˆ�| Qô Ÿ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆØ×1Ñ1°-Ó@ˆà ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆÜŸ™×-Ñ-¨m¸t×?VÑ?VÐae×anÑanÐ-ÓoˆØŸ™ Ó/ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆØ×-Ñ-¨mÓ<ˆà×Ñ¤%§-¡-Ò/Ü�K‰K˜Ó&×*Ñ*Ô,´·±¸MÓ0J×0NÑ0NÔ0PäŸ+™+ m×&9Ñ&9Ó:×>Ñ>ÀÑEˆKÜ!ŸK™K¨¸K¸<È[ÔYˆMà Ð"ˆáØ˜�Ñ&ˆGàˆr4   )F)rN   rO   rP   r#   r>   rE   ÚFloatTensorr   r›   r   rJ   rT   rU   s   @r2   r¾   r¾     sz   ø„ ð=˜zõ =ð. -2ñ0à×(Ñ(ð0ð ×)Ñ)ð0ð ×*Ñ*ð	0ð
 $ D™>ð0ð 
ˆu× Ñ  (¨5×+<Ñ+<Ñ"=Ð=Ñ	>÷0r4   r¾   c                   ó~  ‡ — e Zd Zdefˆ fd„Z	 	 	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     deej                     d	eeej                        d
ee	   dee	   deej                  eeej                  ej                  f      f   fd„Zˆ xZS )ÚBartDecoderLayerrg   c                 óN  •— t         ‰| �  «        |j                  | _        t	        |j
                     | j                  |j                  |j                  dd|¬«      | _        |j                  | _	        t        |j                     | _        |j                  | _        t        j                  | j                  «      | _        t	        |j
                     | j                  |j                  |j                  d|¬«      | _        t        j                  | j                  «      | _        t        j&                  | j                  |j(                  «      | _        t        j&                  |j(                  | j                  «      | _        t        j                  | j                  «      | _        y )NT)ra   rb   rc   rd   rf   rg   )rc   rd   rg   )r=   r>   rÀ   ra   rÁ   rÂ   Údecoder_attention_headsrÄ   rÅ   rc   r   rÈ   rÉ   rÊ   r   rÆ   rÇ   Úencoder_attnÚencoder_attn_layer_normrl   Údecoder_ffn_dimrÌ   rÍ   rÎ   rÏ   s     €r2   r>   zBartDecoderLayer.__init__W  s0  ø€ Ü‰ÑÔØŸ™ˆŒä/°×0KÑ0KÑLØ—n‘nØ×4Ñ4Ø×,Ñ,ØØØô
ˆŒð —~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔä$&§L¡L°·±Ó$@ˆÔ!Ü2°6×3NÑ3NÑOØ�N‰NØ×*Ñ*Ø×,Ñ,ØØô
ˆÔô (*§|¡|°D·N±NÓ'CˆÔ$Ü—9‘9˜TŸ^™^¨V×-CÑ-CÓDˆŒÜ—9‘9˜V×3Ñ3°T·^±^ÓDˆŒÜ "§¡¨T¯^©^Ó <ˆÕr4   rx   r{   Úencoder_hidden_statesÚencoder_attention_maskr|   Úcross_attn_layer_head_maskrz   r}   Ú	use_cacher~   c
                 ót  — |}
|�|dd nd}| j                  |||||¬«      \  }}}t        j                  j                  || j                  | j                  ¬«      }|
|z   }| j                  |«      }d}d}|�w|}
|�|dd nd}| j                  ||||||¬«      \  }}}t        j                  j                  || j                  | j                  ¬«      }|
|z   }| j                  |«      }||z   }|}
| j                  | j                  |«      «      }t        j                  j                  || j                  | j                  ¬«      }| j                  |«      }t        j                  j                  || j                  | j                  ¬«      }|
|z   }| j                  |«      }|f}|r|||fz  }|	r||fz  }|S )a  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`): attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            encoder_hidden_states (`torch.FloatTensor`):
                cross attention input to the layer of shape `(batch, seq_len, embed_dim)`
            encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
                `(encoder_attention_heads,)`.
            cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
                size `(decoder_attention_heads,)`.
            past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        Nr;   )rx   rz   r{   r|   r}   r„   r¥   )rx   ry   r{   r|   rz   r}   )rÅ   r   rŒ   rc   r†   rÇ   rá   râ   rÉ   rÌ   rÊ   rÍ   rÎ   )r?   rx   r{   rä   rå   r|   ræ   rz   r}   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_valuerÛ   s                     r2   rJ   zBartDecoderLayer.forwardt  s  € ð< !ˆð :HÐ9S >°"°1Ñ#5ÐY]Ð à>B¿n¹nØ'Ø3Ø)Ø+Ø/ð ?Mó ?
Ñ;ˆÐ(Ð*;ô Ÿ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆØ×1Ñ1°-Ó@ˆð (,Ð$Ø!ÐØ Ð,Ø$ˆHð @NÐ?Y¨°r°sÑ(;Ð_cÐ%ØNR×N_ÑN_Ø+Ø!6Ø5Ø :Ø8Ø"3ð O`ó OÑKˆMÐ-Ð/Kô ŸM™M×1Ñ1°-À4Ç<Á<ÐZ^×ZgÑZgÐ1ÓhˆMØ$ }Ñ4ˆMØ ×8Ñ8¸ÓGˆMð !2Ð4PÑ PÐð !ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆÜŸ™×-Ñ-¨m¸t×?VÑ?VÐae×anÑanÐ-ÓoˆØŸ™ Ó/ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆØ×-Ñ-¨mÓ<ˆà Ð"ˆáØÐ)Ð+=Ð>Ñ>ˆGáØÐ)Ð+Ñ+ˆGàˆr4   )NNNNNNFT)rN   rO   rP   r#   r>   rE   rS   r   r   r›   rÜ   rJ   rT   rU   s   @r2   rÞ   rÞ   V  s  ø„ ð=˜zõ =ð@ 26Ø8<Ø9=Ø26Ø=AØ8<Ø,1Ø$(ñWà—|‘|ðWð ! §¡Ñ.ðWð  (¨¯©Ñ5ð	Wð
 !)¨¯©Ñ 6ðWð " %§,¡,Ñ/ðWð %-¨U¯\©\Ñ$:ðWð !  u§|¡|Ñ!4Ñ5ðWð $ D™>ðWð ˜D‘>ðWð 
ˆu× Ñ  (¨5°×1BÑ1BÀE×DUÑDUÐ1UÑ+VÑ"WÐWÑ	X÷Wr4   rÞ   c                   ól   ‡ — e Zd ZdZdedededefˆ fd„Zdej                  dej                  fd	„Z	ˆ xZ
S )
ÚBartClassificationHeadz-Head for sentence-level classification tasks.Ú	input_dimÚ	inner_dimÚnum_classesÚpooler_dropoutc                 óÄ   •— t         ‰| �  «        t        j                  ||«      | _        t        j
                  |¬«      | _        t        j                  ||«      | _        y )N)r…   )r=   r>   r   rl   ÚdenseÚDropoutrc   rp   )r?   rñ   rò   ró   rô   r@   s        €r2   r>   zBartClassificationHead.__init__Ñ  sD   ø€ ô 	‰ÑÔÜ—Y‘Y˜y¨)Ó4ˆŒ
Ü—z‘z NÔ3ˆŒÜŸ	™	 )¨[Ó9ˆ�r4   rx   r~   c                 ó¸   — | j                  |«      }| j                  |«      }t        j                  |«      }| j                  |«      }| j	                  |«      }|S r[   )rc   rö   rE   Útanhrp   )r?   rx   s     r2   rJ   zBartClassificationHead.forwardÝ  sN   € ØŸ™ ]Ó3ˆØŸ
™
 =Ó1ˆÜŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ mÓ4ˆØÐr4   )rN   rO   rP   rQ   rR   r^   r>   rE   rS   rJ   rT   rU   s   @r2   rð   rð   Î  sL   ø„ Ù7ð
:àð
:ð ð
:ð ð	
:ð
 õ
:ð U§\¡\ð °e·l±l÷ r4   rð   c                   óJ   — e Zd ZeZdZdZddgZddgZdZ	dZ
dZd„ Zed	„ «       Zy
)ÚBartPreTrainedModelÚmodelTzencoder.versionzdecoder.versionr¾   rÞ   Úpast_key_valuesc                 ó  — | j                   j                  }t        |t        j                  «      rY|j
                  j                  j                  d|¬«       |j                  �%|j                  j                  j                  «        y y t        |t        j                  «      rf|j
                  j                  j                  d|¬«       |j                  �2|j
                  j                  |j                     j                  «        y y y )Nr&   )ÚmeanÚstd)rg   Úinit_stdÚ
isinstancer   rl   rH   ÚdataÚnormal_re   Úzero_Ú	EmbeddingrX   )r?   Úmoduler   s      r2   Ú_init_weightsz!BartPreTrainedModel._init_weightsð  sÃ   € Ø�k‰k×"Ñ"ˆÜ�fœbŸi™iÔ(Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ð .r4   c                 ó®   — | j                   j                  }t        j                  g d¢dddd|gg| j                  ¬«      }|j                  |«      |dœ}|S )N)r   é   é
   é   r;   r   r%   é   r;   ©rD   )r{   r'   )rg   r(   rE   rq   rD   Úne)r?   Ú	pad_tokenr'   Údummy_inputss       r2   r  z BartPreTrainedModel.dummy_inputsû  sW   € à—K‘K×,Ñ,ˆ	Ü—L‘LÒ"2°Q¸¸2¸qÀ)Ð4LÐ!MÐVZ×VaÑVaÔbˆ	à'Ÿl™l¨9Ó5Ø"ñ
ˆð Ðr4   N)rN   rO   rP   r#   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ"_keys_to_ignore_on_load_unexpectedÚ_no_split_modulesÚ_skip_keys_device_placementÚ_supports_flash_attn_2Ú_supports_sdpar  Úpropertyr  © r4   r2   rû   rû   æ  sU   „ Ø€LØÐØ&*Ð#Ø*;Ð=NÐ)OÐ&Ø,Ð.AÐBÐØ"3ÐØ!ÐØ€Nò	?ð ñó ñr4   rû   c                   ó   — e Zd Zd„ Zy)ÚPretrainedBartModelc                 ó8   — t        j                  dt        «       y ©Nz_The class `PretrainedBartModel` has been depreciated, please use `BartPreTrainedModel` instead.©ÚwarningsÚwarnÚFutureWarning©r?   s    r2   Ú__init_subclass__z%PretrainedBartModel.__init_subclass__  ó   € Ü�‰ØmÜõ	
r4   N©rN   rO   rP   r%  r  r4   r2   r  r    ó   „ ó
r4   r  c                   ó   — e Zd Zd„ Zy)ÚBartPretrainedModelc                 ó8   — t        j                  dt        «       y r  r   r$  s    r2   r%  z%BartPretrainedModel.__init_subclass__  r&  r4   Nr'  r  r4   r2   r*  r*    r(  r4   r*  aI  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

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

    Parameters:
        config ([`BartConfig`]):
            Model configuration class with all the parameters of the model. Initializing with a config file does not
            load the weights associated with the model, only the configuration. Check out the
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a!  
    Summarization example:

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

    >>> model = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn")
    >>> tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn")

    >>> ARTICLE_TO_SUMMARIZE = (
    ...     "PG&E stated it scheduled the blackouts in response to forecasts for high winds "
    ...     "amid dry conditions. The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were "
    ...     "scheduled to be affected by the shutoffs which were expected to last through at least midday tomorrow."
    ... )
    >>> inputs = tokenizer([ARTICLE_TO_SUMMARIZE], max_length=1024, return_tensors="pt")

    >>> # Generate Summary
    >>> summary_ids = model.generate(inputs["input_ids"], num_beams=2, min_length=0, max_length=20)
    >>> tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
    'PG&E scheduled the blackouts in response to forecasts for high winds amid dry conditions'
    ```

    Mask filling example:

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

    >>> tokenizer = AutoTokenizer.from_pretrained("facebook/bart-base")
    >>> model = BartForConditionalGeneration.from_pretrained("facebook/bart-base")

    >>> TXT = "My friends are <mask> but they eat too many carbs."
    >>> input_ids = tokenizer([TXT], return_tensors="pt")["input_ids"]
    >>> logits = model(input_ids).logits

    >>> masked_index = (input_ids[0] == tokenizer.mask_token_id).nonzero().item()
    >>> probs = logits[0, masked_index].softmax(dim=0)
    >>> values, predictions = probs.topk(5)

    >>> tokenizer.decode(predictions).split()
    ['not', 'good', 'healthy', 'great', 'very']
    ```
a‹  
    Args:
        input_ids (`torch.LongTensor` 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 (`torch.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)
        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary.

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

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

            Bart 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`).

            For translation and summarization training, `decoder_input_ids` should be provided. If no
            `decoder_input_ids` is provided, the model will create this tensor by shifting the `input_ids` to the right
            for denoising pre-training following the paper.
        decoder_attention_mask (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.

            If you want to change padding behavior, you should read [`modeling_bart._prepare_decoder_attention_mask`]
            and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
            information on the default strategy.
        head_mask (`torch.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 (`torch.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**.

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

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

        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*):
            Tuple consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*: `attentions`)
            `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) is a sequence of
            hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
        past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
            Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
            `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
            `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

            Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
            blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

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

            If `decoder_input_ids` and `decoder_inputs_embeds` are both unset, `decoder_inputs_embeds` takes the value
            of `inputs_embeds`.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                   ó  ‡ — e Zd ZdZddedeej                     fˆ fd„Zd„ Z	d„ Z
	 	 	 	 	 	 	 ddeej                     deej                     d	eej                     d
eej                     dee   dee   dee   deeef   fd„Zˆ xZS )ÚBartEncoderzà
    Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
    [`BartEncoderLayer`].

    Args:
        config: BartConfig
        embed_tokens (nn.Embedding): output embedding
    rg   Úembed_tokensc                 ó  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j
                  }|j                  | _        |j                  | _	        |j                  rt        j                  |«      nd}t        |j                  || j                  |¬«      | _        |�|j                   | j                  _        t#        |j                  |«      | _        t'        j(                  t+        |j,                  «      D �cg c]  }t/        |«      ‘Œ c}«      | _        |j2                  dk(  | _        |j2                  dk(  | _        t'        j8                  |«      | _        d| _        | j?                  «        y c c}w ©Nr]   ©rY   r¼   r»   F) r=   r>   rc   Úencoder_layerdropÚ	layerdroprÀ   r(   rX   Úmax_position_embeddingsÚmax_source_positionsÚscale_embeddingÚmathÚsqrtrW   Ú
vocab_sizer.  rH   r6   Úembed_positionsr   Ú
ModuleListÚrangeÚencoder_layersr¾   ÚlayersrÂ   Ú_use_flash_attention_2Ú	_use_sdparÆ   Úlayernorm_embeddingÚgradient_checkpointingÚ	post_init)r?   rg   r.  ra   rY   r�   r@   s         €r2   r>   zBartEncoder.__init__½  s9  ø€ Ü‰Ñ˜Ô à—~‘~ˆŒØ×1Ñ1ˆŒà—N‘Nˆ	Ø!×.Ñ.ˆÔØ$*×$BÑ$BˆÔ!Ø.4×.DÒ.D”d—i‘i 	Ô*È#ˆä3Ø×Ñ˜y¨$×*:Ñ*:Èô
ˆÔð Ð#Ø'3×':Ñ':ˆD×ÑÔ$ä=Ø×*Ñ*Øó 
ˆÔô —m‘mÄuÈV×MbÑMbÓGcÖ$dÀ!Ô%5°fÕ%=Ò$dÓeˆŒØ&,×&AÑ&AÐEXÑ&XˆÔ#Ø×4Ñ4¸Ñ>ˆŒÜ#%§<¡<°	Ó#:ˆÔ à&+ˆÔ#à�‰Õùò %es   Ä
Fc                 ó   — | j                   S r[   ©r.  r$  s    r2   Úget_input_embeddingsz BartEncoder.get_input_embeddingsÜ  ó   € Ø× Ñ Ð r4   c                 ó   — || _         y r[   rE  ©r?   Úvalues     r2   Úset_input_embeddingsz BartEncoder.set_input_embeddingsß  ó
   € Ø!ˆÕr4   r'   r{   Ú	head_maskÚinputs_embedsr}   Úoutput_hidden_statesÚreturn_dictr~   c                 ó¬  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|�t	        d«      ‚|�"|}|j                  d|j                  d   «      }n|�|dd…dd…df   }nt	        d«      ‚|€| j                  |«      }| j                  |«      }	|	j                  |j                  «      }	||	z   }
| j                  |
«      }
t        j                  j                  |
| j                  | j                  ¬«      }
|�R| j                   r	d|v r|nd}n=| j"                  r|€|st%        ||j&                  «      }nt)        ||j&                  «      }|rdnd}|rdnd}|�_|j+                  «       d   t-        | j.                  «      k7  r6t	        dt-        | j.                  «      › d	|j+                  «       d   › d
�«      ‚t1        | j.                  «      D ]©  \  }}|r||
fz   }d}| j                  r&t3        j4                  g «      }|| j6                  k  rd}|rd}nW| j8                  r3| j                  r'| j;                  |j<                  |
||�||   nd|«      }n ||
||�||   nd|¬«      }|d   }
|sŒ¡||d   fz   }Œ« |r||
fz   }|st?        d„ |
||fD «       «      S tA        |
||¬«      S )a~  
        Args:
            input_ids (`torch.LongTensor` 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 (`torch.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 (`torch.Tensor` of shape `(encoder_layers, encoder_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**.

            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
                This is useful if you want more control over how to convert `input_ids` indices into associated vectors
                than the model's internal embedding lookup matrix.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        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  z&The head_mask should be specified for ú layers, but it is for r§   FT)NN)r|   r}   r"   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr[   r  ©Ú.0Úvs     r2   ú	<genexpr>z&BartEncoder.forward.<locals>.<genexpr>i  s   è ø€ Òe˜qÐWXÑWdœÑeùs   ‚Š©Úlast_hidden_staterx   Ú
attentions)!rg   r}   rO  Úuse_return_dictr/   rs   r-   r.  r:  r¯   rD   rA  r   rŒ   rc   r†   r?  r@  r   rC   r   rˆ   Úlenr>  Ú	enumeraterE   Úrandr3  rB  Ú_gradient_checkpointing_funcÚ__call__Útupler   )r?   r'   r{   rM  rN  r}   rO  rP  ÚinputÚ	embed_posrx   Úencoder_statesÚall_attentionsÚidxÚencoder_layerÚto_dropÚdropout_probabilityÚlayer_outputss                     r2   rJ   zBartEncoder.forwardâ  s$  € ð\ 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð  ]Ð%>ÜÐcÓdÐdØÐ"ØˆEØ!Ÿ™ r¨9¯?©?¸2Ñ+>Ó?‰IØÐ&Ø!¢!¢Q¨ (Ñ+‰EäÐTÓUÐUàÐ Ø ×-Ñ-¨iÓ8ˆMà×(Ñ(¨Ó/ˆ	Ø—L‘L ×!5Ñ!5Ó6ˆ	à%¨	Ñ1ˆØ×0Ñ0°Ó?ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆð Ð%Ø×*Ò*Ø34¸Ñ3F¡ÈD‘Ø—’ IÐ$5Ñ>Oô "EÀ^ÐUb×UhÑUhÓ!i‘ô "<¸NÈM×L_ÑL_Ó!`�á3™¸ˆÙ0™°dˆð Ð Ø�~‰~Ó Ñ"¤s¨4¯;©;Ó'7Ò8Ü Ø<¼SÀÇÁÓ=MÐ<Nð OØ!Ÿ™Ó(¨Ñ+Ð,¨Að/óð ô
 #,¨D¯K©KÓ"8ò  	FÑˆC�Ù#Ø!/°=Ð2BÑ!B�àˆGØ�}Š}Ü&+§j¡j°£nÐ#Ø&¨¯©Ò7Ø"�GáØ ,‘à×.Ò.°4·=²=Ø$(×$EÑ$EØ%×.Ñ.Ø%Ø&Ø+4Ð+@˜ 3šÀdØ)ó%‘Mñ %2Ø%Ø&Ø;DÐ;P¨°3ªÐVZØ*;ô	%�Mð !.¨aÑ 0�â Ø!/°=ÀÑ3CÐ2EÑ!E‘ðA 	FñD  Ø+¨}Ð.>Ñ>ˆNáÜÑe ]°NÀNÐ$SÔeÓeÐeÜØ+¸>ÐVdô
ð 	
r4   r[   )NNNNNNN)rN   rO   rP   rQ   r#   r   r   r  r>   rF  rK  rE   Ú
LongTensorrS   rÜ   r›   r   r   r   rJ   rT   rU   s   @r2   r-  r-  ³  sß   ø„ ññ˜zð ¸À"Ç,Á,Ñ9Oõ ò>!ò"ð
 15Ø15Ø,0Ø59Ø,0Ø/3Ø&*ñJ
à˜E×,Ñ,Ñ-ðJ
ð ! §¡Ñ.ðJ
ð ˜EŸL™LÑ)ð	J
ð
   × 1Ñ 1Ñ2ðJ
ð $ D™>ðJ
ð ' t™nðJ
ð ˜d‘^ðJ
ð 
ˆu�oÐ%Ñ	&÷J
r4   r-  c                   ó¢  ‡ — e Zd ZdZddedeej                     fˆ fd„Zd„ Z	d„ Z
	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     d	eej                     d
eej                     deej                     deej                     deeej                        deej                     dee   dee   dee   dee   deeef   fd„Zˆ xZS )ÚBartDecoderzÌ
    Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`BartDecoderLayer`]

    Args:
        config: BartConfig
        embed_tokens (nn.Embedding): output embedding
    rg   r.  c                 óF  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  rt        j                  |j                  «      nd}t        |j                  |j                  | j                  |¬«      | _        |�|j                   | j                  _        t#        |j                  |j                  «      | _        t'        j(                  t+        |j,                  «      D �cg c]  }t/        |«      ‘Œ c}«      | _        |j2                  dk(  | _        |j2                  dk(  | _        t'        j8                  |j                  «      | _        d| _        | j?                  «        y c c}w r0  ) r=   r>   rc   Údecoder_layerdropr3  r(   rX   r4  Úmax_target_positionsr6  r7  r8  rÀ   rW   r9  r.  rH   r6   r:  r   r;  r<  Údecoder_layersrÞ   r>  rÂ   r?  r@  rÆ   rA  rB  rC  )r?   rg   r.  rY   r�   r@   s        €r2   r>   zBartDecoder.__init__x  s@  ø€ Ü‰Ñ˜Ô Ø—~‘~ˆŒØ×1Ñ1ˆŒØ!×.Ñ.ˆÔØ$*×$BÑ$BˆÔ!Ø39×3IÒ3I”d—i‘i §¡Ô/Èsˆä3Ø×Ñ˜vŸ~™~¨t×/?Ñ/?È[ô
ˆÔð Ð#Ø'3×':Ñ':ˆD×ÑÔ$ä=Ø×*Ñ*Ø�N‰Nó 
ˆÔô —m‘mÄuÈV×MbÑMbÓGcÖ$dÀ!Ô%5°fÕ%=Ò$dÓeˆŒØ&,×&AÑ&AÐEXÑ&XˆÔ#Ø×4Ñ4¸Ñ>ˆŒä#%§<¡<°·±Ó#?ˆÔ à&+ˆÔ#à�‰Õùò %es   ÄFc                 ó   — | j                   S r[   rE  r$  s    r2   rF  z BartDecoder.get_input_embeddings•  rG  r4   c                 ó   — || _         y r[   rE  rI  s     r2   rK  z BartDecoder.set_input_embeddings˜  rL  r4   r'   r{   rä   rå   rM  Úcross_attn_head_maskrý   rN  rç   r}   rO  rP  r~   c                 ó  — |
�|
n| j                   j                  }
|�|n| j                   j                  }|	�|	n| j                   j                  }	|�|n| j                   j                  }|�|�t        d«      ‚|�$|}|j                  }|j                  d|d   «      }n-|� |j                  «       dd }|dd…dd…df   }nt        d«      ‚|�|d   d   j                  d   nd}|€| j                  |«      }| j                  r|�d|v r|nd}n-| j                  r|
s|€t        ||||«      }nt        ||||«      }|�^|�\| j                  r	d|v r|nd}nG| j                  r |€|
st        ||j                  |d   ¬«      }nt!        ||j                  |d   ¬«      }| j#                  ||«      }|j%                  |j&                  «      }||z   }| j)                  |«      }t*        j,                  j/                  || j.                  | j0                  ¬«      }| j2                  r%| j0                  r|	rt4        j7                  d	«       d
}	|rdnd}|
rdnd}|
r|�dnd}|	rdnd}t9        ||gddg«      D ]j  \  }}|€Œ	|j                  «       d   t;        | j<                  «      k7  sŒ3t        d|› dt;        | j<                  «      › d|j                  «       d   › d�«      ‚ t?        | j<                  «      D ]Ý  \  }}|r||fz  }| j0                  r%tA        jB                  g «      }|| jD                  k  rŒ?|�||   nd}| j2                  r?| j0                  r3| jG                  |jH                  |||||�||   nd|�||   ndd|
|	«
      }n ||||||�||   nd|�||   nd||
|	¬«	      }|d   }|	r|||
rdnd   fz  }|
sŒÉ||d   fz  }|€ŒÕ||d   fz  }Œß |r||fz  }|	r|nd}|stK        d„ |||||fD «       «      S tM        |||||¬«      S )a  
        Args:
            input_ids (`torch.LongTensor` 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 (`torch.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 (`torch.FloatTensor` 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 (`torch.LongTensor` 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 (`torch.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**.

            cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the cross-attention modules in the decoder 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(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
                Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
                shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
                shape `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

                Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
                cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

                If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
                that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
                all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
                This is useful if you want more control over how to convert `input_ids` indices into associated vectors
                than the model's internal embedding lookup matrix.
            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   r;   )r�   r„   zZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Fr  rM  rt  zThe `z` should be specified for rR  r§   )r{   rä   rå   r|   ræ   rz   r}   rç   r   r"   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr[   r  rT  s     r2   rW  z&BartDecoder.forward.<locals>.<genexpr>€  s   è ø€ ò àØ�=ô ñùs   ‚)rY  rý   rx   rZ  Úcross_attentions)'rg   r}   rO  rç   r[  r/   r-   rs   rˆ   r.  r?  r@  r   r   r   rC   r   r:  r¯   rD   rA  r   rŒ   rc   r†   rB  r­   r®   Úzipr\  r>  r]  rE   r^  r3  r_  r`  ra  r   )r?   r'   r{   rä   rå   rM  rt  rý   rN  rç   r}   rO  rP  rb  Úinput_shaperA   rM   rx   Úall_hidden_statesÚall_self_attnsÚall_cross_attentionsÚnext_decoder_cacher·   Ú	mask_namerf  Údecoder_layerri  rz   rj  Ú
next_caches                                 r2   rJ   zBartDecoder.forward›  s
  € ð` 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð  ]Ð%>ÜÐsÓtÐtØÐ"ØˆEØŸ+™+ˆKØ!Ÿ™ r¨;°r©?Ó;‰IØÐ&Ø'×,Ñ,Ó.¨s°Ð3ˆKØ!¢!¢Q¨ (Ñ+‰EäÐdÓeÐeð DSÐC^ °Ñ!3°AÑ!6×!<Ñ!<¸QÒ!?ÐdeÐàÐ Ø ×-Ñ-¨eÓ4ˆMà×&Ò&à0>Ð0JÈqÐTbÑOb™^Ðim‰NØ�^Š^Ñ$5Ð:NÐ:Vô HØØØØ&ó	‰Nô ?Ø ¨]Ð<RóˆNð
 !Ð,Ð1GÐ1SØ×*Ò*ØCDÐH^ÑC^Ñ)?ÐdhÑ&Ø—’Ð$8Ð$@ÑIZô *MØ*Ø!×'Ñ'Ø'¨™Oô*Ñ&ô *DØ*¨M×,?Ñ,?ÈÐUWÉô*Ð&ð
 ×(Ñ(¨Ð0FÓGˆ	Ø—L‘L ×!5Ñ!5Ó6ˆ	à%¨	Ñ1ˆØ×0Ñ0°Ó?ˆäŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆà×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øpôð "�	ñ #7™B¸DÐÙ0™°dˆÙ&7Ð<QÐ<]™rÐdhÐÙ#,™R°$Ðô %(¨Ð4HÐ(IÈKÐYoÐKpÓ$qò 	Ñ ˆI�yØÑ$Ø—>‘>Ó# AÑ&¬3¨t¯{©{Ó+;Ó<Ü$Ø 	˜{Ð*DÄSÈÏÉÓEUÐDVð WØ%ŸN™NÓ,¨QÑ/Ð0°ð3óð ð	ô #,¨D¯K©KÓ"8ò /	@ÑˆC�á#Ø! mÐ%5Ñ5Ð!Ø�}Š}Ü&+§j¡j°£nÐ#Ø&¨¯©Ò7Øà5DÐ5P˜_¨SÒ1ÐVZˆNà×*Ò*¨t¯}ª}Ø $× AÑ AØ!×*Ñ*Ø!Ø"Ø)Ø*Ø&/Ð&;�I˜c’NÀØ1EÐ1QÐ(¨Ò-ÐW[ØØ%Øó!‘ñ !.Ø!Ø#1Ø*?Ø+AØ7@Ð7L Y¨s¢^ÐRVà5IÐ5UÐ,¨SÒ1Ð[_à#1Ø&7Ø'ô!�ð *¨!Ñ,ˆMáØ" }Ñ:K±QÐQRÑ'SÐ&UÑUÐ"â Ø =°Ñ#3Ð"5Ñ5�à(Ñ4Ø(¨]¸1Ñ-=Ð,?Ñ?Ñ(ð_/	@ñd  Ø -Ð!1Ñ1Ðá+4Ñ'¸$ˆ
ÙÜñ à'¨Ð5FÈÐXlÐmôó ð ô
 9Ø+Ø&Ø+Ø%Ø1ô
ð 	
r4   r[   )NNNNNNNNNNNN)rN   rO   rP   rQ   r#   r   r   r  r>   rF  rK  rE   rk  rS   rÜ   r   r›   r   r   r   rJ   rT   rU   s   @r2   rm  rm  o  sY  ø„ ññ˜zð ¸À"Ç,Á,Ñ9Oõ ò:!ò"ð
 15Ø15Ø=AØ=AØ,0Ø7;Ø=AØ59Ø$(Ø,0Ø/3Ø&*ñp
à˜E×,Ñ,Ñ-ðp
ð ! §¡Ñ.ðp
ð  (¨×(9Ñ(9Ñ:ð	p
ð
 !)¨×)9Ñ)9Ñ :ðp
ð ˜EŸL™LÑ)ðp
ð ' u§|¡|Ñ4ðp
ð " $ u×'8Ñ'8Ñ"9Ñ:ðp
ð   × 1Ñ 1Ñ2ðp
ð ˜D‘>ðp
ð $ D™>ðp
ð ' t™nðp
ð ˜d‘^ðp
ð 
ˆuÐ?Ð?Ñ	@÷p
r4   rm  zRThe bare BART Model outputting raw hidden-states without any specific head on top.c            %       ó2  ‡ — e Zd ZddgZdefˆ fd„Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
 ee«       eeeee¬
«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej(                     deej*                     deej(                     deej(                     deej*                     deej*                     deej*                     deeej.                        deeej.                        deej.                     deej.                     dee   dee   dee   dee   deeef   f d„«       «       Zˆ xZS )Ú	BartModelúencoder.embed_tokens.weightúdecoder.embed_tokens.weightrg   c                 óv  •— t         ‰| �  |«       |j                  |j                  }}|j                  rt        j                  |j                  «      nd}t        ||j                  ||¬«      | _	        t        || j                  «      | _        t        || j                  «      | _        | j                  «        y )Nr]   r1  )r=   r>   r(   r9  r6  r7  r8  rÀ   rW   Úsharedr-  Úencoderrm  ÚdecoderrC  )r?   rg   rX   r9  rY   r@   s        €r2   r>   zBartModel.__init__•  sˆ   ø€ Ü‰Ñ˜Ô à"(×"5Ñ"5°v×7HÑ7H�ZˆØ39×3IÒ3I”d—i‘i §¡Ô/ÈsˆÜ-¨j¸&¿.¹.È+ÐcnÔoˆŒä" 6¨4¯;©;Ó7ˆŒÜ" 6¨4¯;©;Ó7ˆŒð 	�‰Õr4   c                 ó¶  — | j                   j                  �rB| j                  j                  j                  t        j                  d«      k(  r«| j                  j                  j                  j                  t        j                  d«      k7  rk| j                  | j                  j                  | j                  j                  «       | j                  | j                  | j                  j                  «       y | j                  | j                  j                  | j                  «       | j                  | j                  j                  | j                  «       y y )NÚmeta)
rg   Útie_word_embeddingsr†  rH   rD   rE   rˆ  r.  Ú_tie_or_clone_weightsr‡  r$  s    r2   Ú_tie_weightszBartModel._tie_weights¢  sß   € Ø�;‰;×*Ó*à�{‰{×!Ñ!×(Ñ(¬E¯L©LØó-ò à—,‘,×+Ñ+×2Ñ2×9Ñ9¼U¿\¹\È&Ó=QÒQØ×*Ñ*¨4¯<©<×+DÑ+DÀdÇlÁl×F_ÑF_Ô`Ø×*Ñ*¨4¯;©;¸¿¹×8QÑ8QÕRà×*Ñ*¨4¯<©<×+DÑ+DÀdÇkÁkÔRØ×*Ñ*¨4¯<©<×+DÑ+DÀdÇkÁkÕRð +r4   c                 ó   — | j                   S r[   )r†  r$  s    r2   rF  zBartModel.get_input_embeddings®  s   € Ø�{‰{Ðr4   c                 ó~   — || _         | j                   | j                  _        | j                   | j                  _        y r[   )r†  r‡  r.  rˆ  rI  s     r2   rK  zBartModel.set_input_embeddings±  s)   € ØˆŒØ$(§K¡Kˆ�‰Ô!Ø$(§K¡Kˆ�‰Õ!r4   c                 ó   — | j                   S r[   )r‡  r$  s    r2   Úget_encoderzBartModel.get_encoder¶  ó   € Ø�|‰|Ðr4   c                 ó   — | j                   S r[   ©rˆ  r$  s    r2   Úget_decoderzBartModel.get_decoder¹  r’  r4   )Ú
checkpointÚoutput_typer  Úexpected_outputr'   r{   Údecoder_input_idsÚdecoder_attention_maskrM  Údecoder_head_maskrt  Úencoder_outputsrý   rN  Údecoder_inputs_embedsrç   r}   rO  rP  r~   c                 ó:  — |€D|€B|€t        d«      ‚t        || j                  j                  | j                  j                  «      }|�|n| j                  j
                  }|�|n| j                  j                  }|�|n| j                  j                  }|�|n| j                  j                  }|€| j                  ||||
|||¬«      }nI|rGt        |t        «      s7t        |d   t        |«      dkD  r|d   nd t        |«      dkD  r|d   nd ¬«      }| j                  |||d   ||||	|||||¬«      }|s||z   S t        |j                  |j                   |j"                  |j$                  |j&                  |j                  |j"                  |j$                  ¬«      S )	Nz°If no `decoder_input_ids` or `decoder_inputs_embeds` are passed, `input_ids` cannot be `None`. Please pass either `input_ids` or `decoder_input_ids` or `decoder_inputs_embeds`.)r'   r{   rM  rN  r}   rO  rP  r   r"   r;   rX  ©r'   r{   rä   rå   rM  rt  rý   rN  rç   r}   rO  rP  )rY  rý   Údecoder_hidden_statesÚdecoder_attentionsrw  Úencoder_last_hidden_staterä   Úencoder_attentions)r/   r3   rg   r(   r)   r}   rO  rç   r[  r‡  r  r   r\  rˆ  r   rY  rý   rx   rZ  rw  )r?   r'   r{   r™  rš  rM  r›  rt  rœ  rý   rN  r�  rç   r}   rO  rP  Údecoder_outputss                    r2   rJ   zBartModel.forward¼  sÕ  € ð6 Ð$Ð)>Ð)FØÐ Ü ðUóð ô !3Ø˜4Ÿ;™;×3Ñ3°T·[±[×5WÑ5Wó!Ðð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ"Ø"Ÿl™lØ#Ø-Ø#Ø+Ø"3Ø%9Ø'ð +ó ‰Oñ ¤¨O¼_Ô!MÜ-Ø"1°!Ñ"4Ü47¸Ó4HÈ1Ò4L˜o¨aÒ0ÐRVÜ14°_Ó1EÈÒ1I˜?¨1Ò-ÈtôˆOð Ÿ,™,Ø'Ø1Ø"1°!Ñ"4Ø#1Ø'Ø!5Ø+Ø/ØØ/Ø!5Ø#ð 'ó 
ˆñ Ø" _Ñ4Ð4ä!Ø-×?Ñ?Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô	
ð 		
r4   ©NNNNNNNNNNNNNNN)rN   rO   rP   Ú_tied_weights_keysr#   r>   r�  rF  rK  r‘  r•  r   ÚBART_INPUTS_DOCSTRINGr   Ú_CHECKPOINT_FOR_DOCr   Ú_CONFIG_FOR_DOCÚ_EXPECTED_OUTPUT_SHAPEr   rE   rk  rS   r   rÜ   r›   r   r   rJ   rT   rU   s   @r2   r‚  r‚  Ž  sà  ø„ ð
 8Ð9VÐWÐð˜zõ ò
Sòò0ò
òñ +Ð+@ÓAÙØ&Ø&Ø$Ø.ô	ð 15Ø15Ø8<Ø=AØ,0Ø48Ø7;Ø=AØ=AØ59Ø=AØ$(Ø,0Ø/3Ø&*ñ!U
à˜E×,Ñ,Ñ-ðU
ð ! §¡Ñ.ðU
ð $ E×$4Ñ$4Ñ5ð	U
ð
 !)¨×)9Ñ)9Ñ :ðU
ð ˜EŸL™LÑ)ðU
ð $ E§L¡LÑ1ðU
ð ' u§|¡|Ñ4ðU
ð " $ u×'8Ñ'8Ñ"9Ñ:ðU
ð " $ u×'8Ñ'8Ñ"9Ñ:ðU
ð   × 1Ñ 1Ñ2ðU
ð  (¨×(9Ñ(9Ñ:ðU
ð ˜D‘>ðU
ð $ D™>ðU
ð ' t™nðU
ð  ˜d‘^ð!U
ð" 
ˆuÐ(Ð(Ñ	)ò#U
óó BôU
r4   r‚  zLThe BART Model with a language modeling head. Can be used for summarization.c            (       óè  ‡ — e Zd ZdZg d¢ZdgZdefˆ fd„Zd„ Zd„ Z		 d&d	e
d
ee
   dedej                  fˆ fd„Zd	e
ddfd„Zd„ Zd„ Zd„ Z ee«       eee¬«       ee«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'deej8                     deej:                     deej8                     deej8                     deej:                     deej:                     deej:                     deeej>                        deeej>                        deej>                     deej>                     deej8                     dee   d ee   d!ee   d"ee   de e!ef   f"d#„«       «       «       Z"dej:                  fd$„Z#e$d%„ «       Z%ˆ xZ&S )(ÚBartForConditionalGenerationrü   )rƒ  r„  úlm_head.weightÚfinal_logits_biasrg   c                 óx  •— t         ‰| �  |«       t        |«      | _        | j	                  dt        j                  d| j                  j                  j                  f«      «       t        j                  |j                  | j                  j                  j                  d¬«      | _        | j                  «        y )Nr®  r"   Fri   )r=   r>   r‚  rü   Úregister_bufferrE   Úzerosr†  r7   r   rl   rÀ   Úlm_headrC  rÏ   s     €r2   r>   z%BartForConditionalGeneration.__init__#  s€   ø€ Ü‰Ñ˜Ô Ü˜vÓ&ˆŒ
Ø×ÑÐ0´%·+±+¸qÀ$Ç*Á*×BSÑBS×BbÑBbÐ>cÓ2dÔeÜ—y‘y §¡°·±×1BÑ1B×1QÑ1QÐX]Ô^ˆŒð 	�‰Õr4   c                 ó6   — | j                   j                  «       S r[   )rü   r‘  r$  s    r2   r‘  z(BartForConditionalGeneration.get_encoder,  ó   € Ø�z‰z×%Ñ%Ó'Ð'r4   c                 ó6   — | j                   j                  «       S r[   )rü   r•  r$  s    r2   r•  z(BartForConditionalGeneration.get_decoder/  r´  r4   NÚnew_num_tokensÚpad_to_multiple_ofÚmean_resizingr~   c                 óz   •— t         ‰| �  |||«      }| j                  |j                  j                  d   «       |S )Nr   )r=   Úresize_token_embeddingsÚ_resize_final_logits_biasrH   r-   )r?   r¶  r·  r¸  Únew_embeddingsr@   s        €r2   rº  z4BartForConditionalGeneration.resize_token_embeddings2  s?   ø€ ô ™Ñ8¸ÐI[Ð]jÓkˆØ×&Ñ& ~×'<Ñ'<×'BÑ'BÀ1Ñ'EÔFØÐr4   c                 ó6  — | j                   j                  d   }||k  r| j                   d d …d |…f   }nSt        j                  d||z
  f| j                   j                  ¬«      }t        j
                  | j                   |gd¬«      }| j                  d|«       y )Nr+   r"   r  r�   r®  )r®  r-   rE   r±  rD   r‰   r°  )r?   r¶  Úold_num_tokensÚnew_biasÚ
extra_biass        r2   r»  z6BartForConditionalGeneration._resize_final_logits_bias9  sŒ   € Ø×/Ñ/×5Ñ5°bÑ9ˆØ˜^Ò+Ø×-Ñ-ªa°°.°Ð.@ÑA‰HäŸ™ a¨¸.Ñ)HÐ%IÐRV×RhÑRh×RoÑRoÔpˆJÜ—y‘y $×"8Ñ"8¸*Ð!EÈ1ÔMˆHØ×ÑÐ0°(Õ;r4   c                 ó   — | j                   S r[   ©r²  r$  s    r2   Úget_output_embeddingsz2BartForConditionalGeneration.get_output_embeddingsB  r’  r4   c                 ó   — || _         y r[   rÂ  ©r?   r¼  s     r2   Úset_output_embeddingsz2BartForConditionalGeneration.set_output_embeddingsE  ó	   € Ø%ˆ�r4   c                 óÆ   — | j                   j                  rK| j                  j                  «        | j	                  | j
                  | j                  j                  «       y y r[   )rg   r‹  rü   r�  rŒ  r²  r†  r$  s    r2   r�  z)BartForConditionalGeneration._tie_weightsH  sB   € Ø�;‰;×*Ò*Ø�J‰J×#Ñ#Ô%Ø×&Ñ& t§|¡|°T·Z±Z×5FÑ5FÕGð +r4   ©r—  r  r'   r{   r™  rš  rM  r›  rt  rœ  rý   rN  r�  Úlabelsrç   r}   rO  rP  c                 ó>  — |�|n| j                   j                  }|�R|rt        j                  d«       d}|€7|€5t	        || j                   j
                  | j                   j                  «      }| j                  |||||||||	|
|||||¬«      }| j                  |d   «      }|| j                  j                  |j                  «      z   }d}|�a|j                  |j                  «      }t        «       } ||j                  d| j                   j                  «      |j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                   |j"                  |j$                  |j&                  |j(                  |j*                  |j,                  ¬«	      S )	a¿  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
            config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
            (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

        Returns:
        NzJThe `use_cache` argument is changed to `False` since `labels` is provided.F)r{   r™  rœ  rš  rM  r›  rt  rý   rN  r�  rç   r}   rO  rP  r   r+   r"   ©	ÚlossÚlogitsrý   r   r¡  rw  r¢  rä   r£  )rg   r[  r­   Úwarningr3   r(   r)   rü   r²  r®  r¯   rD   r	   rs   r9  r   rý   r   r¡  rw  r¢  rä   r£  )r?   r'   r{   r™  rš  rM  r›  rt  rœ  rý   rN  r�  rÊ  rç   r}   rO  rP  rÛ   Ú	lm_logitsÚmasked_lm_lossÚloss_fctÚoutputs                         r2   rJ   z$BartForConditionalGeneration.forwardM  s³  € ð< &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐÙÜ—‘ÐkÔlØˆIØ Ð(Ð-BÐ-JÜ$6Ø˜DŸK™K×4Ñ4°d·k±k×6XÑ6Xó%Ð!ð —*‘*ØØ)Ø/Ø+Ø#9ØØ/Ø!5Ø+Ø'Ø"7ØØ/Ø!5Ø#ð ó 
ˆð$ —L‘L ¨¡Ó,ˆ	Ø × 6Ñ 6× 9Ñ 9¸)×:JÑ:JÓ KÑKˆ	àˆØÐØ—Y‘Y˜y×/Ñ/Ó0ˆFÜ'Ó)ˆHÙ% i§n¡n°R¸¿¹×9OÑ9OÓ&PÐRX×R]ÑR]Ð^`ÓRaÓbˆNáØ�\ G¨A¨B KÑ/ˆFØ3AÐ3M�^Ð%¨Ñ.ÐYÐSYÐYäØØØ#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r4   c                 ól   — t        || j                  j                  | j                  j                  «      S r[   )r3   rg   r(   r)   )r?   rÊ  s     r2   Ú%prepare_decoder_input_ids_from_labelszBBartForConditionalGeneration.prepare_decoder_input_ids_from_labels¡  s%   € Ü! &¨$¯+©+×*BÑ*BÀDÇKÁK×DfÑDfÓgÐgr4   c                 ó\   ‡— d}| D ]#  }|t        ˆfd„|d d D «       «      |dd  z   fz  }Œ% |S )Nr  c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­w©r   N©Úindex_selectr¯   rD   ©rU  Ú
past_stateÚbeam_idxs     €r2   rW  z>BartForConditionalGeneration._reorder_cache.<locals>.<genexpr>ª  s.   øè ø€ ÒrÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑrùó   ƒ58r;   ©ra  ©rý   rÝ  Úreordered_pastÚ
layer_pasts    `  r2   Ú_reorder_cachez+BartForConditionalGeneration._reorder_cache¤  sT   ø€ àˆØ)ò 	ˆJàÜÓrÐcmÐnpÐopÐcqÔrÓrØ˜Q˜R�.ñ!ðñ ‰Nð	ð Ðr4   )NT©NNNNNNNNNNNNNNNN)'rN   rO   rP   r  r¦  Ú_keys_to_ignore_on_load_missingr#   r>   r‘  r•  rR   r   r›   r   r  rº  r»  rÃ  rÆ  r�  r   r§  r!   r   r©  r   ÚBART_GENERATION_EXAMPLErE   rk  rS   r   rÜ   r   r   rJ   rÕ  Ústaticmethodrã  rT   rU   s   @r2   r¬  r¬    st  ø„ ð  ÐÚiÐØ':Ð&;Ð#ð˜zõ ò(ò(ð dhñØ!ðØ7?À±}ðØ\`ðà	�‰õð<¸ð <Àó <òò&òHñ
 +Ð+@ÓAÙ¨?ÈÔYÙÐ/Ó0ð 15Ø15Ø8<Ø=AØ,0Ø48Ø7;Ø=AØ=AØ59Ø=AØ-1Ø$(Ø,0Ø/3Ø&*ñ#O
à˜E×,Ñ,Ñ-ðO
ð ! §¡Ñ.ðO
ð $ E×$4Ñ$4Ñ5ð	O
ð
 !)¨×)9Ñ)9Ñ :ðO
ð ˜EŸL™LÑ)ðO
ð $ E§L¡LÑ1ðO
ð ' u§|¡|Ñ4ðO
ð " $ u×'8Ñ'8Ñ"9Ñ:ðO
ð " $ u×'8Ñ'8Ñ"9Ñ:ðO
ð   × 1Ñ 1Ñ2ðO
ð  (¨×(9Ñ(9Ñ:ðO
ð ˜×)Ñ)Ñ*ðO
ð ˜D‘>ðO
ð $ D™>ðO
ð  ' t™nð!O
ð" ˜d‘^ð#O
ð$ 
ˆu�oÐ%Ñ	&ò%O
ó 1ó Zó BðO
ðbh¸E¿L¹Ló hð ñó ôr4   r¬  z…
    Bart model with a sequence classification/head on top (a linear layer on top of the pooled output) e.g. for GLUE
    tasks.
    c            %       ó  ‡ — e Zd ZddgZdefˆ fd„Z ee«       ee	e
eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                      deej"                     deej                      d	eej                      d
eej"                     deej"                     deej"                     deeej&                        deej&                     deej&                     deej                      dee   dee   dee   dee   deee
f   f d„«       «       Zˆ xZS )ÚBartForSequenceClassificationrƒ  r„  rg   c                 óÜ   •— t        ‰| �  |fi |¤Ž t        |«      | _        t	        |j
                  |j
                  |j                  |j                  «      | _        | j                  «        y r[   )
r=   r>   r‚  rü   rð   rÀ   Ú
num_labelsÚclassifier_dropoutÚclassification_headrC  )r?   rg   r¡   r@   s      €r2   r>   z&BartForSequenceClassification.__init__º  sZ   ø€ Ü‰Ñ˜Ñ* 6Ò*Ü˜vÓ&ˆŒ
Ü#9Ø�N‰NØ�N‰NØ×ÑØ×%Ñ%ó	$
ˆÔ ð 	�‰Õr4   )r–  r—  r  r˜  Úexpected_lossr'   r{   r™  rš  rM  r›  rt  rœ  rN  r�  rÊ  rç   r}   rO  rP  r~   c                 óæ  — |�|n| j                   j                  }|�d}|€$|	�"t        d| j                  j                  › �«      ‚| j                  |||||||||	|
||||¬«      }|d   }|j                  | j                   j                  «      j                  |j                  «      }t        t        j                  |j                  d«      «      «      dkD  rt        d«      ‚||dd…f   j                  |j!                  d«      d|j!                  d«      «      dd…ddd…f   }| j#                  |«      }d}|��Ê|j                  |j                  «      }| j                   j$                  €¡| j                   j&                  dk(  rd	| j                   _        nv| j                   j&                  dkD  rL|j(                  t        j*                  k(  s|j(                  t        j,                  k(  rd
| j                   _        nd| j                   _        | j                   j$                  d	k(  rSt/        «       }| j                   j&                  dk(  r& ||j1                  «       |j1                  «       «      }n– |||«      }nŒ| j                   j$                  d
k(  rGt3        «       } ||j                  d| j                   j&                  «      |j                  d«      «      }n,| j                   j$                  dk(  rt5        «       } |||«      }|s|f|dd z   }|�|f|z   S |S t7        |||j8                  |j:                  |j<                  |j>                  |j@                  |jB                  |jD                  ¬«	      S )a3  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        NFz8Passing input embeddings is currently not supported for ©r{   r™  rš  rM  r›  rt  rœ  rN  r�  rç   r}   rO  rP  r   r"   z7All examples must have the same number of <eos> tokens.r+   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationrÌ  )#rg   r[  ÚNotImplementedErrorr@   rN   rü   ÚeqÚeos_token_idr¯   rD   r\  rE   Úunique_consecutiveÚsumr/   rs   rˆ   rí  Úproblem_typerë  rC   rG   rR   r
   Úsqueezer	   r   r   rý   r   r¡  rw  r¢  rä   r£  )r?   r'   r{   r™  rš  rM  r›  rt  rœ  rN  r�  rÊ  rç   r}   rO  rP  rÛ   rx   Úeos_maskÚsentence_representationrÎ  rÍ  rÒ  rÓ  s                           r2   rJ   z%BartForSequenceClassification.forwardÇ  s  € ð> &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆØÐØˆIàÐ Ð!:Ü%ØJÈ4Ï>É>×KbÑKbÐJcÐdóð ð —*‘*ØØ)Ø/Ø#9ØØ/Ø!5Ø+Ø'Ø"7ØØ/Ø!5Ø#ð ó 
ˆð    ™
ˆà—<‘< §¡× 8Ñ 8Ó9×<Ñ<¸]×=QÑ=QÓRˆäŒu×'Ñ'¨¯©°Q«Ó8Ó9¸AÒ=ÜÐVÓWÐWØ"/°º!°Ñ"<×"AÑ"AÀ-×BTÑBTÐUVÓBWÐY[Ð]j×]oÑ]oÐprÓ]sÓ"tÚˆr’1ˆHñ#
Ðð ×)Ñ)Ð*AÓBˆàˆØÑØ—Y‘Y˜vŸ}™}Ó-ˆFØ�{‰{×'Ñ'Ð/Ø—;‘;×)Ñ)¨QÒ.Ø/;�D—K‘KÕ,Ø—[‘[×+Ñ+¨aÒ/°V·\±\ÄUÇZÁZÒ5OÐSY×S_ÑS_Ôch×clÑclÒSlØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—;‘;×)Ñ)¨QÒ.Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# F¨FÓ3‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù §¡¨B°·±×0FÑ0FÓ GÈÏÉÐUWËÓY‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨Ó/�ÙØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä.ØØØ#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r4   r¥  )rN   rO   rP   r¦  r#   r>   r   r§  r   Ú'_CHECKPOINT_FOR_SEQUENCE_CLASSIFICATIONr   r©  Ú_SEQ_CLASS_EXPECTED_OUTPUTÚ_SEQ_CLASS_EXPECTED_LOSSr   rE   rk  rS   r   rÜ   r›   r   r   rJ   rT   rU   s   @r2   ré  ré  °  sÄ  ø„ ð 8Ð9VÐWÐð˜zõ ñ +Ð+@ÓAÙØ:Ø3Ø$Ø2Ø.ôð 15Ø15Ø8<Ø=AØ,0Ø48Ø7;Ø=AØ59Ø=AØ-1Ø$(Ø,0Ø/3Ø&*ñ!`
à˜E×,Ñ,Ñ-ð`
ð ! §¡Ñ.ð`
ð $ E×$4Ñ$4Ñ5ð	`
ð
 !)¨×)9Ñ)9Ñ :ð`
ð ˜EŸL™LÑ)ð`
ð $ E§L¡LÑ1ð`
ð ' u§|¡|Ñ4ð`
ð " $ u×'8Ñ'8Ñ"9Ñ:ð`
ð   × 1Ñ 1Ñ2ð`
ð  (¨×(9Ñ(9Ñ:ð`
ð ˜×)Ñ)Ñ*ð`
ð ˜D‘>ð`
ð $ D™>ð`
ð ' t™nð`
ð  ˜d‘^ð!`
ð" 
ˆuÐ5Ð5Ñ	6ò#`
óó Bô`
r4   ré  zÜ
    BART Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
    layer on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c            '       ó*  ‡ — e Zd ZddgZˆ fd„Z ee«       eee	e
ee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                      deej                      d	eej                     d
eej                     deej                     deeej$                        deej                      deej                      deej$                     deej$                     dee   dee   dee   dee   deee	f   f"d„«       «       Zˆ xZS )ÚBartForQuestionAnsweringrƒ  r„  c                 óò   •— t         ‰| �  |«       d|_        |j                  | _        t        |«      | _        t        j                  |j                  |j                  «      | _        | j                  «        y r:   )
r=   r>   rë  r‚  rü   r   rl   Úhidden_sizeÚ
qa_outputsrC  rÏ   s     €r2   r>   z!BartForQuestionAnswering.__init__<  s[   ø€ Ü‰Ñ˜Ô àˆÔØ ×+Ñ+ˆŒä˜vÓ&ˆŒ
ÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr4   )r–  r—  r  rî  r˜  r'   r{   r™  rš  rM  r›  rt  rœ  Ústart_positionsÚend_positionsrN  r�  rç   r}   rO  rP  r~   c                 ó¬  — |�|n| j                   j                  }|	�|
�d}| j                  ||||||||||||||¬«      }|d   }| j                  |«      }|j	                  dd¬«      \  }}|j                  d«      j                  «       }|j                  d«      j                  «       }d}|	�·|
�µt        |	j                  «       «      dkD  r|	j                  d«      }	t        |
j                  «       «      dkD  r|
j                  d«      }
|j                  d«      }|	j                  d|«      }	|
j                  d|«      }
t        |¬«      } |||	«      } |||
«      }||z   d	z  }|s||f|dd z   }|�|f|z   S |S t        ||||j                  |j                  |j                  |j                  |j                   |j"                  |j$                  ¬
«
      S )a  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (*sequence_length*). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (*sequence_length*). Position outside of the sequence
            are not taken into account for computing the loss.
        NFrð  r   r"   r+   r�   )Úignore_indexr;   )
rÍ  Ústart_logitsÚ
end_logitsrý   r   r¡  rw  r¢  rä   r£  )rg   r[  rü   r  Úsplitrú  ru   r\  rˆ   rØ   r	   r   rý   r   r¡  rw  r¢  rä   r£  )r?   r'   r{   r™  rš  rM  r›  rt  rœ  r  r  rN  r�  rç   r}   rO  rP  rÛ   Úsequence_outputrÎ  r	  r
  Ú
total_lossÚignored_indexrÒ  Ú
start_lossÚend_lossrÓ  s                               r2   rJ   z BartForQuestionAnswering.forwardH  s  € ðJ &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆØÐ&¨=Ð+DØˆIà—*‘*ØØ)Ø/Ø#9ØØ/Ø!5Ø+Ø'Ø"7ØØ/Ø!5Ø#ð ó 
ˆð" " !™*ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ó#:Ñ ˆ�jØ#×+Ñ+¨BÓ/×:Ñ:Ó<ˆØ×'Ñ'¨Ó+×6Ñ6Ó8ˆ
àˆ
ØÐ&¨=Ð+Dä�?×'Ñ'Ó)Ó*¨QÒ.Ø"1×"9Ñ"9¸"Ó"=�Ü�=×%Ñ%Ó'Ó(¨1Ò,Ø -× 5Ñ 5°bÓ 9�à(×-Ñ-¨aÓ0ˆMØ-×3Ñ3°A°}ÓEˆOØ)×/Ñ/°°=ÓAˆMä'°]ÔCˆHÙ! ,°Ó@ˆJÙ 
¨MÓ:ˆHØ$ xÑ/°1Ñ4ˆJáàØðð ˜˜�ñˆFð 0:Ð/E�Z�M FÑ*ÐQÈ6ÐQä2ØØ%Ø!Ø#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô
ð 	
r4   rä  )rN   rO   rP   r¦  r>   r   r§  r   Ú_CHECKPOINT_FOR_QAr   r©  Ú_QA_EXPECTED_LOSSÚ_QA_EXPECTED_OUTPUTr   rE   rS   rk  r   rÜ   r›   r   r   rJ   rT   rU   s   @r2   r  r  2  sÔ  ø„ ð 8Ð9VÐWÐô
ñ +Ð+@ÓAÙØ%Ø7Ø$Ø'Ø+ôð -1Ø15Ø8<Ø=AØ,0Ø48Ø7;Ø=AØ6:Ø48Ø59Ø=AØ$(Ø,0Ø/3Ø&*ñ#\
à˜EŸL™LÑ)ð\
ð ! §¡Ñ.ð\
ð $ E×$4Ñ$4Ñ5ð	\
ð
 !)¨×)9Ñ)9Ñ :ð\
ð ˜EŸL™LÑ)ð\
ð $ E§L¡LÑ1ð\
ð ' u§|¡|Ñ4ð\
ð " $ u×'8Ñ'8Ñ"9Ñ:ð\
ð " %×"2Ñ"2Ñ3ð\
ð   × 0Ñ 0Ñ1ð\
ð   × 1Ñ 1Ñ2ð\
ð  (¨×(9Ñ(9Ñ:ð\
ð ˜D‘>ð\
ð $ D™>ð\
ð  ' t™nð!\
ð" ˜d‘^ð#\
ð$ 
ˆuÐ9Ð9Ñ	:ò%\
óó Bô\
r4   r  c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )ÚBartDecoderWrapperz½
    This wrapper class is a helper class to correctly load pretrained checkpoints when the causal language model is
    used in combination with the [`EncoderDecoderModel`] framework.
    c                 óD   •— t         ‰| �  |«       t        |«      | _        y r[   )r=   r>   rm  rˆ  rÏ   s     €r2   r>   zBartDecoderWrapper.__init__µ  s   ø€ Ü‰Ñ˜Ô Ü" 6Ó*ˆ�r4   c                 ó&   —  | j                   |i |¤ŽS r[   r”  )r?   r    r¡   s      r2   rJ   zBartDecoderWrapper.forward¹  s   € Øˆt�|‰|˜TÐ, VÑ,Ð,r4   )rN   rO   rP   rQ   r>   rJ   rT   rU   s   @r2   r  r  ¯  s   ø„ ñô
+ö-r4   r  zu
    BART decoder with a language modeling head on top (linear layer with weights tied to the input embeddings).
    c                    óà  ‡ — e Zd ZdgZˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
 eee¬	«      	 	 	 	 	 	 	 	 	 	 	 	 	 dd
eej                      deej"                     deej$                     deej$                     deej"                     deej"                     deeej$                        deej$                     deej                      dee   dee   dee   dee   deeef   fd„«       Zed„ «       Zˆ xZS )ÚBartForCausalLMr­  c                 ó  •— t        j                  |«      }d|_        d|_        t        ‰| �  |«       t        |«      | _        t        j                  |j                  |j                  d¬«      | _        | j                  «        y )NTFri   )ÚcopyÚdeepcopyrd   Úis_encoder_decoderr=   r>   r  rü   r   rl   r  r9  r²  rC  rÏ   s     €r2   r>   zBartForCausalLM.__init__Æ  sf   ø€ Ü—‘˜vÓ&ˆØ ˆÔØ$)ˆÔ!Ü‰Ñ˜Ô Ü'¨Ó/ˆŒ
ä—y‘y ×!3Ñ!3°V×5FÑ5FÈUÔSˆŒð 	�‰Õr4   c                 óB   — | j                   j                  j                  S r[   ©rü   rˆ  r.  r$  s    r2   rF  z$BartForCausalLM.get_input_embeddingsÒ  s   € Ø�z‰z×!Ñ!×.Ñ.Ð.r4   c                 ó:   — || j                   j                  _        y r[   r  rI  s     r2   rK  z$BartForCausalLM.set_input_embeddingsÕ  s   € Ø*/ˆ�
‰
×ÑÕ'r4   c                 ó   — | j                   S r[   rÂ  r$  s    r2   rÃ  z%BartForCausalLM.get_output_embeddingsØ  r’  r4   c                 ó   — || _         y r[   rÂ  rÅ  s     r2   rÆ  z%BartForCausalLM.set_output_embeddingsÛ  rÇ  r4   c                 ó&   — || j                   _        y r[   ©rü   rˆ  )r?   rˆ  s     r2   Úset_decoderzBartForCausalLM.set_decoderÞ  s   € Ø$ˆ�
‰
Õr4   c                 ó.   — | j                   j                  S r[   r$  r$  s    r2   r•  zBartForCausalLM.get_decoderá  s   € Ø�z‰z×!Ñ!Ð!r4   rÉ  r'   r{   rä   rå   rM  rt  rý   rN  rÊ  rç   r}   rO  rP  r~   c                 óz  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }| j                  j                  |||||||||
|||¬«      }| j                  |d   «      }d}|	�a|	j                  |j                  «      }	t        «       } ||j                  d| j                   j                  «      |	j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  |j                   ¬«      S )aæ  
        Args:
            input_ids (`torch.LongTensor` 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 (`torch.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  (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
                if the model is configured as a decoder.
            encoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used
                in the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:
            head_mask (`torch.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**.

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

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

            past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
                Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
                shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
                shape `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`. The two additional
                tensors are only required when the model is used as a decoder in a Sequence to Sequence model.

                Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
                cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential 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)`.
            labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
                config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
                (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
            use_cache (`bool`, *optional*):
                If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
                (see `past_key_values`).

                - 1 for tokens that are **not masked**,
                - 0 for tokens that are **masked**.
            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.

        Returns:

        Example:

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

        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/bart-base")
        >>> model = BartForCausalLM.from_pretrained("facebook/bart-base", add_cross_attention=False)
        >>> assert model.config.is_decoder, f"{model.__class__} has to be configured as a decoder."
        >>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
        >>> outputs = model(**inputs)

        >>> logits = outputs.logits
        >>> expected_shape = [1, inputs.input_ids.shape[-1], model.config.vocab_size]
        >>> list(logits.shape) == expected_shape
        True
        ```NrŸ  r   r+   r"   )rÍ  rÎ  rý   rx   rZ  rw  )rg   r}   rO  r[  rü   rˆ  r²  r¯   rD   r	   rs   r9  r   rý   rx   rZ  rw  )r?   r'   r{   rä   rå   rM  rt  rý   rN  rÊ  rç   r}   rO  rP  rÛ   rÎ  rÍ  rÒ  rÓ  s                      r2   rJ   zBartForCausalLM.forwardä  sX  € ðL 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð —*‘*×$Ñ$ØØ)Ø"7Ø#9ØØ!5Ø+Ø'ØØ/Ø!5Ø#ð %ó 
ˆð —‘˜g a™jÓ)ˆàˆØÐØ—Y‘Y˜vŸ}™}Ó-ˆFÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯K©K×,BÑ,BÓCÀVÇ[Á[ÐQSÃ_ÓUˆDáØ�Y ¨¨ Ñ,ˆFØ'+Ð'7�D�7˜VÑ#ÐC¸VÐCä0ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô
ð 	
r4   c                 óJ   ‡— d}| D ]  }|t        ˆfd„|D «       «      fz  }Œ |S )Nr  c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­wrØ  rÙ  rÛ  s     €r2   rW  z1BartForCausalLM._reorder_cache.<locals>.<genexpr>z  s.   øè ø€ ÒnÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑnùrÞ  rß  rà  s    `  r2   rã  zBartForCausalLM._reorder_cacheu  s=   ø€ àˆØ)ò 	ˆJØÜÓnÐcmÔnÓnðñ ‰Nð	ð Ðr4   )NNNNNNNNNNNNN)rN   rO   rP   r¦  r>   rF  rK  rÃ  rÆ  r%  r•  r!   r   r©  r   rE   rk  rS   rÜ   r   r›   r   r   rJ   rç  rã  rT   rU   s   @r2   r  r  ½  s¤  ø„ ð +Ð+Ðô
ò/ò0òò&ò%ò"ñ Ð+LÐ[jÔkð 15Ø15Ø=AØ>BØ,0Ø7;Ø=AØ59Ø-1Ø$(Ø,0Ø/3Ø&*ñN
à˜E×,Ñ,Ñ-ðN
ð ! §¡Ñ.ðN
ð  (¨×(9Ñ(9Ñ:ð	N
ð
 !)¨×):Ñ):Ñ ;ðN
ð ˜EŸL™LÑ)ðN
ð ' u§|¡|Ñ4ðN
ð " $ u×'8Ñ'8Ñ"9Ñ:ðN
ð   × 1Ñ 1Ñ2ðN
ð ˜×)Ñ)Ñ*ðN
ð ˜D‘>ðN
ð $ D™>ðN
ð ' t™nðN
ð ˜d‘^ðN
ð 
ˆuÐ7Ð7Ñ	8òN
ó lðN
ð` ñó ôr4   r  )r  r¬  r  ré  r‚  rû   r*  r  )YrQ   r  r7  r!  Útypingr   r   r   r   rE   Útorch.utils.checkpointr   Útorch.nnr   r	   r
   Úactivationsr   Ú
generationr   Úmodeling_attn_mask_utilsr   r   r   r   Úmodeling_flash_attention_utilsr   r   Úmodeling_outputsr   r   r   r   r   r   r   Úmodeling_utilsr   Úutilsr   r   r   r   r    r!   Úconfiguration_bartr#   r$   Ú
get_loggerrN   r­   r¨  r©  rª  rý  rÿ  rþ  r  r  r  rS   rR   r3   r  r6   rW   ÚModuler`   r�   rµ   rÁ   r¾   rÞ   rð   rû   r  r*  ÚBART_START_DOCSTRINGræ  r§  r-  rm  r‚  r¬  ré  r  r  r  Ú__all__r  r4   r2   ú<module>r9     sÔ  ðñ ã Û Û ß /Ó /ã Û Ý ß AÑ Aå !Ý )÷ó ÷ i÷÷ ñ õ .÷÷ õ +ñ ÔÝJð 
ˆ×	Ñ	˜HÓ	%€à*Ð Ø€ò %Ð ð +EÐ 'ØÐ Ø)Ð ð =Ð ØÐ Ø&Ð ð %§,¡,ð ¸cð Ð[^ó ô 8 R§\¡\ô 8ô,
=˜bŸl™lô 
=ô[B�B—I‘Iô [Bô|{9˜-ô {9ô|g1˜ô g1ðV ØØ,ñÐ ôC�r—y‘yô CôLu�r—y‘yô uôp˜RŸY™Yô ô0˜/ô ô@
Ð-ô 
ô
Ð-ô 
ðÐ ð )Ð ðV_Ð ôDy
Ð%ô y
ôx\
Ð%ô \
ñ~ ØXØóôF
Ð#ó F
ó	ðF
ñR ØRÐThóôOÐ#6¸ó OóðOñd ðð óôx
Ð$7ó x
óðx
ñv ðð óôs
Ð2ó s
óðs
ôl-Ð,ô -ñ ðð ó	ôyÐ)¨?ó yóðyòx	�r4   