Ë
    T^(h7 ã                   ó¾  — d 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Z
ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZmZ ddlmZ ddlmZm Z m!Z!m"Z"m#Z# ddl$m%Z%  e"jL                  e'«      Z(dZ)dZ*de
jV                  de,de,fd„Z- G d„ dej\                  «      Z/ G d„ dej`                  «      Z1 G d„ dej`                  «      Z2de1iZ3 G d„ dej`                  «      Z4 G d„ de«      Z5d Z6d!Z7d"Z8 G d#„ d$e5«      Z9 G d%„ d&e5«      Z: e d'e6«       G d(„ d)e5«      «       Z; e d*e6«       G d+„ d,e5e«      «       Z< G d-„ d.e5«      Z= G d/„ d0e5e«      Z>g d1¢Z?y)2z=PyTorch MarianMTModel model, ported from the Marian C++ repo.é    N)ÚListÚOptionalÚTupleÚUnion)Únn)ÚCrossEntropyLossé   )ÚACT2FN)ÚGenerationMixin)Ú_prepare_4d_attention_maskÚ!_prepare_4d_causal_attention_mask)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚ!CausalLMOutputWithCrossAttentionsÚSeq2SeqLMOutputÚSeq2SeqModelOutput)ÚPreTrainedModel)Úadd_end_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚMarianConfigr   zHelsinki-NLP/opus-mt-en-deÚ	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       úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/marian/modeling_marian.pyÚshift_tokens_rightr'   7   s}   € ð "×+Ñ+¨I¯O©OÓ<ÐØ(ª¨C¨R¨C¨Ñ0×6Ñ6Ó8Ð’a˜™�eÑØ4Ð’a˜�dÑàÐÜÐLÓMÐMà×"Ñ"Ð#4¸Ñ#<¸lÔKàÐó    c            	       ó¬   ‡ — e Zd ZdZddededee   ddfˆ fd„Zd„ Z ej                  «       dd	ej                  d
edej                  fˆ fd„«       Zˆ xZS )Ú#MarianSinusoidalPositionalEmbeddingzDThis module produces sinusoidal positional embeddings of any length.NÚnum_positionsÚembedding_dimÚpadding_idxÚreturnc                 ó&   •— t         ‰| �  ||«       y ©N)ÚsuperÚ__init__)Úselfr+   r,   r-   Ú	__class__s       €r&   r2   z,MarianSinusoidalPositionalEmbedding.__init__J   s   ø€ Ü‰Ñ˜¨Õ6r(   c                 ó¾  — | j                   j                  \  }}t        j                  t	        |«      D ��cg c];  }t	        |«      D �cg c]$  }|t        j
                  dd|dz  z  |z  «      z  ‘Œ& c}‘Œ= c}}«      }t        j                  ||| j                   j                  d¬«      }|dz  dk(  r|dz  n|dz  dz   }t        j                  t        j                  |dd…ddd…f   «      «      |dd…d|…f<   t        j                  t        j                  |dd…ddd…f   «      «      |dd…|d…f<   t        j                  |d¬«      | _         yc c}w c c}}w )	z°
        Identical to the XLM create_sinusoidal_embeddings except features are not interleaved. The cos features are in
        the 2nd half of the vector. [dim // 2:]
        i'  é   F)ÚdtypeÚrequires_gradr   r   N)r8   )Úweightr!   ÚnpÚarrayÚrangeÚpowerÚtorchÚemptyr7   ÚFloatTensorÚsinÚcosr   Ú	Parameter)r3   Ún_posÚdimÚposÚjÚposition_encÚoutÚsentinels           r&   Ú_init_weightz0MarianSinusoidalPositionalEmbedding._init_weightM   s&  € ð
 —[‘[×&Ñ&‰
ˆˆsÜ—x‘xÜX]Ð^cÓXd×eÐQTÄÀsÃÖL¸Aˆc”B—H‘H˜U A¨¨a©¡L°3Ñ$6Ó7Ó7ÔLÓeó
ˆô �k‰k˜% ¨D¯K©K×,=Ñ,=ÈUÔSˆØ" Q™w¨!š|�3˜!’8°#¸±(¸a±ˆÜ"×.Ñ.¬r¯v©v°lÂ1ÀaÀdÈÀdÀ7Ñ6KÓ/LÓMˆŠAˆq�ˆzˆMÑÜ!×-Ñ-¬b¯f©f°\Â!ÀQÀTÈÀTÀ'Ñ5JÓ.KÓLˆŠAˆx‰yˆLÑÜ—l‘l 3°eÔ<ˆ�ùò MùÓes   ·E
Á	)EÁ2E
ÅE
Úinput_ids_shapeÚpast_key_values_lengthc                 ó®   •— |dd \  }}t        j                  |||z   t         j                  | j                  j                  ¬«      }t
        ‰| �  |«      S )z3`input_ids_shape` is expected to be [bsz x seqlen].Nr6   )r7   Údevice)r>   ÚarangeÚlongr9   rO   r1   Úforward)r3   rL   rM   ÚbszÚseq_lenÚ	positionsr4   s         €r&   rR   z+MarianSinusoidalPositionalEmbedding.forward\   sT   ø€ ð ' r¨Ð*‰ˆˆWÜ—L‘LØ"Ð$:¸WÑ$DÌEÏJÉJÐ_c×_jÑ_j×_qÑ_qô
ˆ	ô ‰w‰˜yÓ)Ð)r(   r0   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr   r2   rK   r>   Úno_gradÚSizeÚTensorrR   Ú__classcell__©r4   s   @r&   r*   r*   G   sn   ø„ ÙNñ7 cð 7¸#ð 7ÈHÐUXÉMð 7Ðeiõ 7ò=ð €U‡]�]ƒ_ñ* u§z¡zð *È3ð *ÐW\×WcÑWcô *ó ô*r(   r*   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 )ÚMarianAttentionz=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      à¿©rf   )r1   r2   rb   rc   rd   Úhead_dimrh   r#   Úscalingre   rg   r   ÚLinearÚk_projÚv_projÚq_projÚout_proj)	r3   rb   rc   rd   re   rf   rg   rh   r4   s	           €r&   r2   zMarianAttention.__init__j   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ˆ�r(   ÚtensorrT   rS   c                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S )Nr   r6   )Úviewrc   rk   Ú	transposeÚ
contiguous)r3   rr   rT   rS   s       r&   Ú_shapezMarianAttention._shape‰   s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr(   Úhidden_statesÚkey_value_statesÚpast_key_valueÚattention_maskÚlayer_head_maskÚoutput_attentionsr.   c                 ó
  — |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 )z#Input shape: Batch x Time x ChannelNr   r6   r   r   ©rE   z$Attention weights should be of size z	, but is z!Attention mask should be of size z/Head mask for a single layer should be of size ©ÚpÚtrainingz `attn_output` should be of size )Úsizerp   rl   r!   rw   rn   ro   r>   Úcatre   rc   rk   rt   ÚreshapeÚbmmru   r#   r   Ú
functionalÚsoftmaxrd   r‚   rb   rq   )r3   rx   ry   rz   r{   r|   r}   Úis_cross_attentionrS   Útgt_lenÚ_Úquery_statesÚ
key_statesÚvalue_statesÚ
proj_shapeÚsrc_lenÚattn_weightsÚattn_weights_reshapedÚ
attn_probsÚattn_outputs                       r&   rR   zMarianAttention.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ÐAr(   )ç        FTFN)NNNNF)rV   rW   rX   rY   rZ   ÚfloatÚboolr   r   r2   r>   r]   rw   r   rR   r^   r_   s   @r&   ra   ra   g   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r(   ra   c                   ó¾   ‡ — 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 )
ÚMarianEncoderLayerrh   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)rb   rc   rd   rh   )r1   r2   Úd_modelrb   ÚMARIAN_ATTENTION_CLASSESÚ_attn_implementationÚencoder_attention_headsÚattention_dropoutÚ	self_attnr   Ú	LayerNormÚself_attn_layer_normrd   r
   Úactivation_functionÚactivation_fnÚactivation_dropoutrm   Úencoder_ffn_dimÚfc1Úfc2Úfinal_layer_norm©r3   rh   r4   s     €r&   r2   zMarianEncoderLayer.__init__  sÜ   ø€ Ü‰ÑÔØŸ™ˆŒä1°&×2MÑ2MÑNØ—n‘nØ×4Ñ4Ø×,Ñ,Øô	
ˆŒô %'§L¡L°·±Ó$@ˆÔ!Ø—~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔÜ—9‘9˜TŸ^™^¨V×-CÑ-CÓDˆŒÜ—9‘9˜V×3Ñ3°T·^±^ÓDˆŒÜ "§¡¨T¯^©^Ó <ˆÕr(   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‡   rd   r‚   r¢   r¤   r§   r¥   r¨   r©   r7   r>   Úfloat16ÚisinfÚanyÚisnanÚfinfor­   Úclamp)
r3   rx   r{   r|   r}   Úresidualr‘   r‹   Úclamp_valueÚoutputss
             r&   rR   zMarianEncoderLayer.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àˆr(   )F)rV   rW   rX   r   r2   r>   r@   r   r—   r   rR   r^   r_   s   @r&   r™   r™     sz   ø„ ð=˜|õ =ð. -2ñ0à×(Ñ(ð0ð ×)Ñ)ð0ð ×*Ñ*ð	0ð
 $ D™>ð0ð 
ˆu× Ñ  (¨5×+<Ñ+<Ñ"=Ð=Ñ	>÷0r(   r™   Úeagerc                   ó~  ‡ — 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 )ÚMarianDecoderLayerrh   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)rb   rc   rd   re   rg   rh   )rd   re   rh   )r1   r2   r›   rb   rœ   r�   Údecoder_attention_headsrŸ   r    rd   r
   r£   r¤   r¥   r   r¡   r¢   Úencoder_attnÚencoder_attn_layer_normrm   Údecoder_ffn_dimr§   r¨   r©   rª   s     €r&   r2   zMarianDecoderLayer.__init__Q  s0  ø€ Ü‰ÑÔØŸ™ˆŒä1°&×2MÑ2MÑNØ—n‘nØ×4Ñ4Ø×,Ñ,ØØØô
ˆŒð —~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔä$&§L¡L°·±Ó$@ˆÔ!Ü4°V×5PÑ5PÑQØ�N‰NØ×*Ñ*Ø×,Ñ,ØØô
ˆÔô (*§|¡|°D·N±NÓ'CˆÔ$Ü—9‘9˜TŸ^™^¨V×-CÑ-CÓDˆŒÜ—9‘9˜V×3Ñ3°T·^±^ÓDˆŒÜ "§¡¨T¯^©^Ó <ˆÕr(   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.
        Nr6   )rx   rz   r{   r|   r}   r€   éþÿÿÿ)rx   ry   r{   r|   rz   r}   )r    r   r‡   rd   r‚   r¢   r¼   r½   r¤   r§   r¥   r¨   r©   )r3   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                     r&   rR   zMarianDecoderLayer.forwardn  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àˆr(   )NNNNNNFT)rV   rW   rX   r   r2   r>   r]   r   r   r—   r@   rR   r^   r_   s   @r&   r¹   r¹   P  s  ø„ ð=˜|õ =ð@ 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r(   r¹   c                   óh   — e Zd ZeZdZdZdeej                  ej                  ef   fd„Zed„ «       Zy)ÚMarianPreTrainedModelÚmodelTÚmodulec                 óX  — | j                   j                  }t        |t        j                  «      rY|j
                  j                  j                  d|¬«       |j                  �%|j                  j                  j                  «        y y t        |t        «      r|j                  «        y t        |t        j                  «      rf|j
                  j                  j                  d|¬«       |j                  �2|j
                  j                  |j                     j                  «        y y y )Nr•   )ÚmeanÚstd)rh   Úinit_stdÚ
isinstancer   rm   r9   ÚdataÚnormal_rf   Úzero_r*   rK   Ú	Embeddingr-   )r3   rÎ   rÑ   s      r&   Ú_init_weightsz#MarianPreTrainedModel._init_weightsÍ  sÚ   € Ø�k‰k×"Ñ"ˆÜ�fœbŸi™iÔ(Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜Ô CÔDØ×ÑÕ!Ü˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ð .r(   c                 ó°   — | j                   j                  }t        j                  g d¢dddd|gg| j                  ¬«      }|j                  |«      ||dœ}|S )N)r   é   é
   é   r6   r   é   é   r6   ©rO   )r{   r   Údecoder_input_ids)rh   r   r>   rr   rO   Úne)r3   Ú	pad_tokenr   Údummy_inputss       r&   rã   z"MarianPreTrainedModel.dummy_inputsÚ  sZ   € à—K‘K×,Ñ,ˆ	Ü—L‘LÒ"2°Q¸¸2¸qÀ)Ð4LÐ!MÐVZ×VaÑVaÔbˆ	à'Ÿl™l¨9Ó5Ø"Ø!*ñ
ˆð
 Ðr(   N)rV   rW   rX   r   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingr   r   rm   r×   r*   rØ   Úpropertyrã   © r(   r&   rÌ   rÌ   È  sH   „ Ø€LØÐØ&*Ð#ð? E¨"¯)©)°R·\±\ÐCfÐ*fÑ$gó ?ð ñó ñr(   rÌ   aK  
    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 ([`MarianConfig`]):
            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.
u4  
    Pytorch version of marian-nmt's transformer.h (c++). Designed for the OPUS-NMT translation checkpoints. Available
    models are listed [here](https://huggingface.co/models?search=Helsinki-NLP).

    Examples:

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

    >>> src = "fr"  # source language
    >>> trg = "en"  # target language

    >>> model_name = f"Helsinki-NLP/opus-mt-{src}-{trg}"
    >>> model = MarianMTModel.from_pretrained(model_name)
    >>> tokenizer = AutoTokenizer.from_pretrained(model_name)

    >>> sample_text = "oÃ¹ est l'arrÃªt de bus ?"
    >>> batch = tokenizer([sample_text], return_tensors="pt")

    >>> generated_ids = model.generate(**batch)
    >>> tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
    "Where's the bus stop?"
    ```
ah  
    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)

            Marian uses the `pad_token_id` as the starting token for `decoder_input_ids` generation. If
            `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
            `past_key_values`).
        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.
        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j                     ef   fd„Zˆ xZS )ÚMarianEncoderzä
    Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
    [`MarianEncoderLayer`].

    Args:
        config: MarianConfig
        embed_tokens (nn.Embedding): output embedding
    rh   Úembed_tokensc                 ó”  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j
                  }|j                  | _        |j                  | _	        |j                  rt        j                  |«      nd| _        |�|| _        n0t        j                   |j"                  || j                  «      | _        t%        |j                  || j                  «      | _        t        j(                  t+        |j,                  «      D �cg c]  }t/        |«      ‘Œ c}«      | _        d| _        | j5                  «        y c c}w ©Ng      ð?F)r1   r2   rd   Úencoder_layerdropÚ	layerdropr›   r   r-   Úmax_position_embeddingsÚmax_source_positionsÚscale_embeddingÚmathÚsqrtÚembed_scalerë   r   r×   Ú
vocab_sizer*   Úembed_positionsÚ
ModuleListr<   Úencoder_layersr™   ÚlayersÚgradient_checkpointingÚ	post_init)r3   rh   rë   rb   r‹   r4   s        €r&   r2   zMarianEncoder.__init__t  sý   ø€ Ü‰Ñ˜Ô à—~‘~ˆŒØ×1Ñ1ˆŒà—N‘Nˆ	Ø!×.Ñ.ˆÔØ$*×$BÑ$BˆÔ!Ø39×3IÒ3Iœ4Ÿ9™9 YÔ/ÈsˆÔàÐ#Ø ,ˆDÕä "§¡¨V×->Ñ->À	È4×K[ÑK[Ó \ˆDÔäBØ×*Ñ*¨I°t×7GÑ7Gó 
ˆÔô —m‘mÌÈv×OdÑOdÓIeÖ$fÀAÔ%7¸Õ%?Ò$fÓgˆŒà&+ˆÔ#à�‰Õùò	 %gs   ÄEc                 ó   — | j                   S r0   ©rë   ©r3   s    r&   Úget_input_embeddingsz"MarianEncoder.get_input_embeddings�  ó   € Ø× Ñ Ð r(   c                 ó   — || _         y r0   rþ   ©r3   Úvalues     r&   Úset_input_embeddingsz"MarianEncoder.set_input_embeddings�  ó
   € Ø!ˆÕr(   r   r{   Ú	head_maskÚinputs_embedsr}   Úoutput_hidden_statesÚreturn_dictr.   c                 ó(  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|�t	        d«      ‚|�8| j                  ||«       |j                  «       }|j                  d|d   «      }n!|�|j                  «       dd }nt	        d«      ‚|€| j                  |«      | j                  z  }| j                  |«      }	||	z   }
t        j                  j                  |
| j                  | j                  ¬«      }
|�t        ||j                   «      }|rdnd}|rdnd}|�[|j                  «       d   t#        | j$                  «      k(  s2J dt#        | j$                  «      › d	|j                  «       d   › d
�«       ‚t'        | j$                  «      D ]©  \  }}|r||
fz   }d}| j                  r&t)        j*                  g «      }|| j,                  k  rd}|rd}nW| j.                  r3| j                  r'| j1                  |j2                  |
||�||   nd|«      }n ||
||�||   nd|¬«      }|d   }
|sŒ¡||d   fz   }Œ« |r||
fz   }|st5        d„ |
||fD «       «      S t7        |
||¬«      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 ú.FT)NN)r|   r}   r   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr0   rè   ©Ú.0Úvs     r&   ú	<genexpr>z(MarianEncoder.forward.<locals>.<genexpr>  s   è ø€ Òe˜qÐWXÑWdœÑeùs   ‚Š©Úlast_hidden_staterx   Ú
attentions)rh   r}   r	  Úuse_return_dictr#   Ú%warn_if_padding_and_no_attention_maskrƒ   rt   rë   rõ   r÷   r   r‡   rd   r‚   r   r7   Úlenrú   Ú	enumerater>   Úrandrï   rû   Ú_gradient_checkpointing_funcÚ__call__Útupler   )r3   r   r{   r  r  r}   r	  r
  Úinput_shapeÚ	embed_posrx   Úencoder_statesÚall_attentionsÚidxÚencoder_layerÚto_dropÚdropout_probabilityÚlayer_outputss                     r&   rR   zMarianEncoder.forward“  sã  € ð\ 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð  ]Ð%>ÜÐcÓdÐdØÐ"Ø×6Ñ6°yÀ.ÔQØ#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;‰IØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐTÓUÐUàÐ Ø ×-Ñ-¨iÓ8¸4×;KÑ;KÑKˆMà×(Ñ(¨Ó5ˆ	à%¨	Ñ1ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆð Ð%ä7¸È×H[ÑH[Ó\ˆNá3™¸ˆÙ0™°dˆð Ð Ø—>‘>Ó# AÑ&¬3¨t¯{©{Ó+;Ò<ð Ø8¼¸T¿[¹[Ó9IÐ8JÐJaÐbk×bpÑbpÓbrÐstÑbuÐavÐvwÐxóÐ<ô #,¨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ô
ð 	
r(   r0   )NNNNNNN)rV   rW   rX   rY   r   r   r   r×   r2   r   r  r>   Ú
LongTensorr]   r@   r—   r   r   r   rR   r^   r_   s   @r&   rê   rê   j  sê   ø„ ññ˜|ð ¸8ÀBÇLÁLÑ;Qõ ò2!ò"ð
 15Ø59Ø,0Ø59Ø,0Ø/3Ø&*ñ~
à˜E×,Ñ,Ñ-ð~
ð ! ×!1Ñ!1Ñ2ð~
ð ˜EŸL™LÑ)ð	~
ð
   × 1Ñ 1Ñ2ð~
ð $ D™>ð~
ð ' t™nð~
ð ˜d‘^ð~
ð 
ˆu�U—\‘\Ñ" OÐ3Ñ	4÷~
r(   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ej                           deej                     dee   dee   dee   dee   deeej                     ef   fd„Zˆ xZS )ÚMarianDecoderzÐ
    Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`MarianDecoderLayer`]

    Args:
        config: MarianConfig
        embed_tokens (nn.Embedding): output embedding
    rh   rë   c                 ó¸  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  rt        j                  |j                  «      nd| _        |�|| _        n:t        j                   |j"                  |j                  | j                  «      | _        t%        |j                  |j                  | j                  «      | _        t        j(                  t+        |j,                  «      D �cg c]  }t/        |«      ‘Œ c}«      | _        d| _        | j5                  «        y c c}w rí   )r1   r2   rd   Údecoder_layerdroprï   r   r-   rð   Úmax_target_positionsrò   ró   rô   r›   rõ   rë   r   r×   Údecoder_vocab_sizer*   r÷   rø   r<   Údecoder_layersr¹   rú   rû   rü   )r3   rh   rë   r‹   r4   s       €r&   r2   zMarianDecoder.__init__  s  ø€ Ü‰Ñ˜Ô Ø—~‘~ˆŒØ×1Ñ1ˆŒØ!×.Ñ.ˆÔØ$*×$BÑ$BˆÔ!Ø8>×8NÒ8Nœ4Ÿ9™9 V§^¡^Ô4ÐTWˆÔàÐ#Ø ,ˆDÕä "§¡¨V×-FÑ-FÈÏÉÐX\×XhÑXhÓ iˆDÔäBØ×*Ñ*¨F¯N©N¸D×<LÑ<Ló 
ˆÔô —m‘mÌÈv×OdÑOdÓIeÖ$fÀAÔ%7¸Õ%?Ò$fÓgˆŒà&+ˆÔ#à�‰Õùò	 %gs   Ä!Ec                 ó   — | j                   S r0   rþ   rÿ   s    r&   r   z"MarianDecoder.get_input_embeddings3  r  r(   c                 ó   — || _         y r0   rþ   r  s     r&   r  z"MarianDecoder.set_input_embeddings6  r  r(   r   r{   r¿   rÀ   r  Úcross_attn_head_maskÚpast_key_valuesr  rÂ   r}   r	  r
  r.   c                 óÈ  — |
�|
n| j                   j                  }
|�|n| j                   j                  }|	�|	n| j                   j                  }	|�|n| j                   j                  }|�|�t        d«      ‚|�&|j                  «       }|j                  d|d   «      }n!|�|j                  «       dd }nt        d«      ‚|�|d   d   j                  d   nd}|€| j                  |«      | j                  z  }t        ||||«      }|�|�t        ||j                  |d   ¬«      }| j                  ||«      }||z   }t        j                   j#                  || j"                  | j$                  ¬«      }| j&                  r%| j$                  r|	rt(        j+                  d	«       d
}	|rdnd}|
rdnd}|
r|�dnd}|	rdnd}t-        ||gddg«      D ]f  \  }}|€Œ	|j                  «       d   t/        | j0                  «      k(  rŒ3J d|› dt/        | j0                  «      › d|j                  «       d   › d�«       ‚ t3        | j0                  «      D ]Ý  \  }}|r||fz  }| j$                  r%t5        j6                  g «      }|| j8                  k  rŒ?|�||   nd}| j&                  r?| j$                  r3| j;                  |j<                  |||||�||   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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)
            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   r6   )rŠ   r€   zZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Frè   r  r1  zThe `z` should be specified for r  r  )r{   r¿   rÀ   r|   rÁ   rz   r}   rÂ   r	   r   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr0   rè   r  s     r&   r  z(MarianDecoder.forward.<locals>.<genexpr>þ  s   è ø€ ò àØ�=ô ñùs   ‚)r  r2  rx   r  Úcross_attentions)!rh   r}   r	  rÂ   r  r#   rƒ   rt   r!   rë   rõ   r   r   r7   r÷   r   r‡   rd   r‚   rû   ÚloggerÚwarning_onceÚzipr  rú   r  r>   r  rï   r  r  r  r   )r3   r   r{   r¿   rÀ   r  r1  r2  r  rÂ   r}   r	  r
  r  rM   rU   rx   Úall_hidden_statesÚall_self_attnsÚall_cross_attentionsÚnext_decoder_cacheÚ	attn_maskÚ	mask_namer"  Údecoder_layerr%  rz   r&  Ú
next_caches                                r&   rR   zMarianDecoder.forward9  sG  € ð` 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ØÐ"Ø#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;‰IØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐdÓeÐeð DSÐC^ °Ñ!3°AÑ!6×!<Ñ!<¸QÒ!?ÐdeÐàÐ Ø ×-Ñ-¨iÓ8¸4×;KÑ;KÑKˆMä:Ø˜K¨Ð8Nó
ˆð
 !Ð,Ð1GÐ1Sä%?Ø&¨×(;Ñ(;À[ÐQSÁ_ô&Ð"ð
 ×(Ñ(¨Ð6LÓMˆ	à%¨	Ñ1ˆäŸ™×-Ñ-¨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ØÑ$Ø —~‘~Ó'¨Ñ*¬s°4·;±;Ó/?Ó@ð Ø˜I˜;Ð&@ÄÀTÇ[Á[ÓAQÐ@Rð SØ!Ÿ™Ó(¨Ñ+Ð,¨Að/óÐ@ð	ô #,¨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ô
ð 	
r(   r0   )NNNNNNNNNNNN)rV   rW   rX   rY   r   r   r   r×   r2   r   r  r>   r'  r]   r@   r   r—   r   r   rR   r^   r_   s   @r&   r)  r)    sg  ø„ ññ˜|ð ¸8ÀBÇLÁLÑ;Qõ ò,!ò"ð
 15Ø15Ø=AØ=AØ,0Ø7;ØEIØ59Ø$(Ø,0Ø/3Ø&*ñP
à˜E×,Ñ,Ñ-ðP
ð ! §¡Ñ.ðP
ð  (¨×(9Ñ(9Ñ:ð	P
ð
 !)¨×)9Ñ)9Ñ :ðP
ð ˜EŸL™LÑ)ðP
ð ' u§|¡|Ñ4ðP
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðP
ð   × 1Ñ 1Ñ2ðP
ð ˜D‘>ðP
ð $ D™>ðP
ð ' t™nðP
ð ˜d‘^ðP
ð 
ˆu�U—\‘\Ñ"Ð$MÐMÑ	N÷P
r(   r)  zTThe bare Marian Model outputting raw hidden-states without any specific head on top.c            #       ó^  ‡ — e Zd ZddgZdefˆ fd„Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zdedej                  fd„Z ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej.                     deej0                     deej.                     deej0                     deej0                     deej0                     deej0                     deeeej0                     ef      deeeej8                           deej8                     deej8                     dee   dee   dee   dee   def d„«       «       Zˆ xZS ) ÚMarianModelzencoder.embed_tokens.weightzdecoder.embed_tokens.weightrh   c                 óØ  •— t         ‰| �  |«       |j                  |j                  }}t	        j
                  ||j                  |«      | _        | j                  j                  r| j                  x}}nEt        j                  | j                  «      }t        j                  | j                  «      }d | _        t        ||«      | _        t        ||«      | _        | j!                  «        y r0   )r1   r2   r   rö   r   r×   r›   Úsharedrh   Ú share_encoder_decoder_embeddingsÚcopyÚdeepcopyrê   Úencoderr)  Údecoderrü   )r3   rh   r-   rö   Úencoder_embed_tokensÚdecoder_embed_tokensr4   s         €r&   r2   zMarianModel.__init__  sµ   ø€ Ü‰Ñ˜Ô à"(×"5Ñ"5°v×7HÑ7H�Zˆô —l‘l :¨v¯~©~¸{ÓKˆŒØ�;‰;×7Ò7Ø:>¿+¹+ÐEÐ Ñ#7ô $(§=¡=°·±Ó#=Ð Ü#'§=¡=°·±Ó#=Ð ØˆDŒKä$ VÐ-AÓBˆŒÜ$ VÐ-AÓBˆŒð 	�‰Õr(   c                 ó>   — | j                  «       j                  «       S r0   )Úget_encoderr   rÿ   s    r&   r   z MarianModel.get_input_embeddings(  s   € à×ÑÓ!×6Ñ6Ó8Ð8r(   c                 óÎ   — | j                   j                  r>|| _        | j                  | j                  _        | j                  | j
                  _        y || j                  _        y r0   )rh   rE  rD  rH  rë   rI  r  s     r&   r  z MarianModel.set_input_embeddings,  sB   € Ø�;‰;×7Ò7ØˆDŒKØ(,¯©ˆD�L‰LÔ%Ø(,¯©ˆD�L‰LÕ%à(-ˆD�L‰LÕ%r(   c                 ó€   — | j                   j                  rt        d«      ‚| j                  «       j	                  «       S )Nz–`get_decoder_input_embeddings` should not be called if `config.share_encoder_decoder_embeddings` is `True`. Please use `get_input_embeddings` instead.)rh   rE  r#   Úget_decoderr   rÿ   s    r&   Úget_decoder_input_embeddingsz(MarianModel.get_decoder_input_embeddings4  s<   € Ø�;‰;×7Ò7ÜðHóð ð ×ÑÓ!×6Ñ6Ó8Ð8r(   c                 óh   — | j                   j                  rt        d«      ‚|| j                  _        y )Na   `config.share_encoder_decoder_embeddings` is set to `True` meaning the decoder input embeddings are shared with the encoder. In order to set the decoder input embeddings, you should simply set the encoder input embeddings by calling `set_input_embeddings` with the appropriate embeddings.)rh   rE  r#   rI  rë   r  s     r&   Úset_decoder_input_embeddingsz(MarianModel.set_decoder_input_embeddings<  s0   € Ø�;‰;×7Ò7Üðróð ð
 %*ˆ�‰Õ!r(   c                 ó   — | j                   S r0   )rH  rÿ   s    r&   rM  zMarianModel.get_encoderE  ó   € Ø�|‰|Ðr(   c                 ó   — | j                   S r0   ©rI  rÿ   s    r&   rP  zMarianModel.get_decoderH  rU  r(   Únew_num_tokensr.   c                 ó  — | j                   j                  rt        d«      ‚| j                  «       }| j	                  ||«      }| j                  |«       | j                  «       }|€|S || j                   _        | j                  «        |S ©Nzœ`resize_decoder_token_embeddings` should not be called if `config.share_encoder_decoder_embeddings` is `True`. Please use `resize_token_embeddings` instead.)rh   rE  r#   rQ  Ú_get_resized_embeddingsrS  r-  Útie_weights)r3   rX  Úold_embeddingsÚnew_embeddingsÚmodel_embedss        r&   Úresize_decoder_token_embeddingsz+MarianModel.resize_decoder_token_embeddingsK  sŽ   € Ø�;‰;×7Ò7ÜðKóð ð
 ×:Ñ:Ó<ˆØ×5Ñ5°nÀnÓUˆØ×)Ñ)¨.Ô9à×8Ñ8Ó:ˆàÐ!ØÐð *8ˆ�‰Ô&ð 	×ÑÔàÐr(   ©Úoutput_typerä   r   r{   rà   Údecoder_attention_maskr  Údecoder_head_maskr1  Úencoder_outputsr2  r  Údecoder_inputs_embedsrÂ   r}   r	  r
  c                 ó®  — |�|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 )	aX  
        Returns:

        Example:

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

        >>> tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de")
        >>> model = MarianModel.from_pretrained("Helsinki-NLP/opus-mt-en-de")

        >>> inputs = tokenizer("Studies have been shown that owning a dog is good for you", return_tensors="pt")
        >>> decoder_inputs = tokenizer(
        ...     "<pad> Studien haben gezeigt dass es hilfreich ist einen Hund zu besitzen",
        ...     return_tensors="pt",
        ...     add_special_tokens=False,
        ... )
        >>> outputs = model(input_ids=inputs.input_ids, decoder_input_ids=decoder_inputs.input_ids)

        >>> last_hidden_states = outputs.last_hidden_state
        >>> list(last_hidden_states.shape)
        [1, 26, 512]
        ```N)r   r{   r  r  r}   r	  r
  r   r   r6   r  ©r   r{   r¿   rÀ   r  r1  r2  r  rÂ   r}   r	  r
  )r  r2  Údecoder_hidden_statesÚdecoder_attentionsr5  Úencoder_last_hidden_stater¿   Úencoder_attentions)rh   r}   r	  rÂ   r  rH  rÓ   r   r  rI  r   r  r2  rx   r  r5  )r3   r   r{   rà   rc  r  rd  r1  re  r2  r  rf  rÂ   r}   r	  r
  Údecoder_outputss                    r&   rR   zMarianModel.forwardc  s‡  € ðV 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ô	
ð 		
r(   )NNNNNNNNNNNNNNN) rV   rW   rX   Ú_tied_weights_keysr   r2   r   r  rQ  rS  rM  rP  rZ   r   r×   r`  r   ÚMARIAN_INPUTS_DOCSTRINGr   r   Ú_CONFIG_FOR_DOCr   r>   r'  r]   r   r   r   r@   r—   rR   r^   r_   s   @r&   rB  rB    só  ø„ ð 8Ð9VÐWÐð˜|õ ò,9ò.ò9ò*òòð¸cð ÀbÇlÁló ñ0 +Ð+BÓCÙÐ+=ÈOÔ\ð 15Ø15Ø8<Ø9=Ø,0Ø48Ø7;ØQUØEIØ59Ø=AØ$(Ø,0Ø/3Ø&*ñ!^
à˜E×,Ñ,Ñ-ð^
ð ! §¡Ñ.ð^
ð $ E×$4Ñ$4Ñ5ð	^
ð
 !)¨¯©Ñ 6ð^
ð ˜EŸL™LÑ)ð^
ð $ E§L¡LÑ1ð^
ð ' u§|¡|Ñ4ð^
ð " %¨¨e¯l©lÑ(;¸_Ð(LÑ"MÑNð^
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBð^
ð   × 1Ñ 1Ñ2ð^
ð  (¨×(9Ñ(9Ñ:ð^
ð ˜D‘>ð^
ð $ D™>ð^
ð ' t™nð^
ð  ˜d‘^ð!^
ð" 
ò#^
ó ]ó Dô^
r(   rB  zNThe Marian Model with a language modeling head. Can be used for summarization.c            &       ó>  ‡ — e Zd ZdZg d¢ZddgZg d¢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,dedej                  fd„Zd„ Zdedd
fd„Zd„ Zdej                  f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"ej@                     e#f      d ee"e"ejH                           d!eejH                     d"eejH                     d#eej>                     d$ee   d%ee   d&ee   d'ee   def"d(„«       «       «       Z%d#ej@                  fd)„Z&e'd*„ «       Z(ˆ xZ)S ).ÚMarianMTModelrÍ   )Úfinal_logits_biaszencoder.embed_positions.weightzdecoder.embed_positions.weightz$model.encoder.embed_positions.weightz$model.decoder.embed_positions.weight)z!model.encoder.embed_tokens.weightz!model.decoder.embed_tokens.weightúlm_head.weightrh   c                 óH  •— t         ‰| �  |«       t        |«      | _        |j                  r|j
                  n|j                  }| j                  dt        j                  d|f«      «       t        j                  |j                  |d¬«      | _        | j                  «        y )Nrs  r   Frj   )r1   r2   rB  rÍ   rE  rö   r-  Úregister_bufferr>   Úzerosr   rm   r›   Úlm_headrü   )r3   rh   Útarget_vocab_sizer4   s      €r&   r2   zMarianMTModel.__init__Ó  s~   ø€ Ü‰Ñ˜Ô Ü  Ó(ˆŒ
à17×1XÒ1X˜F×-Ò-Ð^d×^wÑ^wÐØ×ÑÐ0´%·+±+¸qÐBSÐ>TÓ2UÔVÜ—y‘y §¡Ð1BÈÔOˆŒð 	�‰Õr(   c                 ó6   — | j                   j                  «       S r0   )rÍ   rM  rÿ   s    r&   rM  zMarianMTModel.get_encoderÞ  ó   € Ø�z‰z×%Ñ%Ó'Ð'r(   c                 ó6   — | j                   j                  «       S r0   )rÍ   rP  rÿ   s    r&   rP  zMarianMTModel.get_decoderá  r{  r(   NrX  Úpad_to_multiple_ofÚmean_resizingr.   c                 óx   •— t         ‰| �  |||«      }| j                  j                  r| j	                  |«       |S r0   )r1   Úresize_token_embeddingsrh   rE  Ú_resize_final_logits_bias)r3   rX  r}  r~  r^  r4   s        €r&   r€  z%MarianMTModel.resize_token_embeddingsä  s;   ø€ ô ™Ñ8¸ÐI[Ð]jÓkˆØ�;‰;×7Ò7Ø×*Ñ*¨>Ô:ØÐr(   c                 óè  — | j                  «       }| j                  |||«      }| j                  |«       |j                  j                  d   }| j
                  j                  r|| j
                  _        | j
                  j                  rY| j                  «       �I| j
                  j                  s3| j                  «       }| j                  ||«      }| j                  |«       | j                  «       S )Nr   )r   r[  r  r9   r!   rh   rE  r-  Úget_output_embeddingsÚtie_word_embeddingsÚ_get_resized_lm_headÚset_output_embeddings)r3   rX  r}  Úargsr]  r^  Úold_lm_headÚnew_lm_heads           r&   Ú_resize_token_embeddingsz&MarianMTModel._resize_token_embeddingsí  sÊ   € Ø×2Ñ2Ó4ˆØ×5Ñ5°nÀnÐVhÓiˆØ×!Ñ! .Ô1à'×.Ñ.×4Ñ4°QÑ7ˆà�;‰;×7Ò7Ø-;ˆD�K‰KÔ*ð �K‰K×8Ò8Ø×*Ñ*Ó,Ð8Ø—K‘K×3Ò3à×4Ñ4Ó6ˆKØ×3Ñ3°KÀÓPˆKØ×&Ñ& {Ô3à×(Ñ(Ó*Ð*r(   c                 ó(  — | j                   j                  rt        d«      ‚| j                  j	                  «       }| j                  ||«      }| j                  j                  |«       | j                  «       �I| j                   j                  s3| j                  «       }| j                  ||«      }| j                  |«       | j                  j	                  «       }|€|S || j                   _        | j                  «        | j                  |«       |S rZ  )rh   rE  r#   rÍ   rQ  r[  rS  rƒ  r„  r…  r†  r-  r\  r�  )r3   rX  r]  r^  rˆ  r‰  r_  s          r&   r`  z-MarianMTModel.resize_decoder_token_embeddings  só   € Ø�;‰;×7Ò7ÜðKóð ð
 Ÿ™×@Ñ@ÓBˆØ×5Ñ5°nÀnÓUˆØ�
‰
×/Ñ/°Ô?ð ×%Ñ%Ó'Ð3¸D¿K¹K×<[Ò<[Ø×4Ñ4Ó6ˆKØ×3Ñ3°KÀÓPˆKØ×&Ñ& {Ô3à—z‘z×>Ñ>Ó@ˆàÐ!ØÐð *8ˆ�‰Ô&ð 	×ÑÔà×&Ñ& ~Ô6àÐr(   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   rs  )rs  r!   r>   rw  rO   r„   rv  )r3   rX  Úold_num_tokensÚnew_biasÚ
extra_biass        r&   r�  z'MarianMTModel._resize_final_logits_bias#  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°(Õ;r(   c                 ó   — | j                   S r0   ©rx  rÿ   s    r&   rƒ  z#MarianMTModel.get_output_embeddings,  rU  r(   r^  c                 ó   — || _         y r0   r‘  ©r3   r^  s     r&   r†  z#MarianMTModel.set_output_embeddings/  ó	   € Ø%ˆ�r(   c                 ó@  — | j                  «       }|�Gt        | j                  dd«      r0| j                  «       j	                  «       }| j                  ||«       t        | j                  dd«      r|t        | j                  dd«      ret        | | j                  «      rt        | | j                  «      } | j                  | j                  | j                  | j                  d«      }|| _        | j                  «       D ]  }t        |d«      sŒ|j                  «        Œ! y)	zç
        Tie the weights between the input embeddings and the output embeddings.

        If the `torchscript` flag is set in the configuration, can't handle parameter sharing so we are cloning the
        weights instead.
        Nr„  TÚis_encoder_decoderFÚtie_encoder_decoderrH  Ú_tie_weights)rƒ  Úgetattrrh   rP  r   Ú_tie_or_clone_weightsÚhasattrrå   Ú_tie_encoder_decoder_weightsrH  rI  Ú_dynamic_tied_weights_keysÚmodulesr˜  )r3   Úoutput_embeddingsÚword_embeddingsÚtied_weightsrÎ   s        r&   r\  zMarianMTModel.tie_weights2  sò   € ð !×6Ñ6Ó8ÐØÐ(¬W°T·[±[ÐBWÐY]Ô-^à"×.Ñ.Ó0×EÑEÓGˆOØ×&Ñ&Ð'8¸/ÔJä�4—;‘;Ð 4°eÔ<ÄÈÏÉÐVkÐmrÔAsÜ�t˜T×3Ñ3Ô4Ü˜t T×%;Ñ%;Ó<�Ø×<Ñ<Ø—‘˜dŸl™l¨D×,BÑ,BÀIóˆLð /;ˆDÔ+à—l‘l“nò 	&ˆFÜ�v˜~Õ.Ø×#Ñ#Õ%ñ	&r(   ra  r   r{   rà   rc  r  rd  r1  re  r2  r  rf  ÚlabelsrÂ   r}   r	  r
  c                 óÒ  — |�|n| j                   j                  }|�R|rt        j                  d«       d}|€7|€5t	        || j                   j
                  | j                   j                  «      }| j                  |||||||||	|
|||||¬«      }| j                  |d   «      | j                  z   }d}|�Ft        «       } ||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à   re  rc  r  rd  r1  r2  r  rf  rÂ   r}   r	  r
  r   r   r   )	ÚlossÚlogitsr2  ri  rj  r5  rk  r¿   rl  )rh   r  r6  Úwarningr'   r   r   rÍ   rx  rs  r   rt   r-  r   r2  ri  rj  r5  rk  r¿   rl  )r3   r   r{   rà   rc  r  rd  r1  re  r2  r  rf  r¢  rÂ   r}   r	  r
  r¶   Ú	lm_logitsÚmasked_lm_lossÚloss_fctÚoutputs                         r&   rR   zMarianMTModel.forwardN  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 ¨¡Ó,¨t×/EÑ/EÑEˆ	àˆØÐÜ'Ó)ˆHÙ% i§n¡n°R¸¿¹×9WÑ9WÓ&XÐZ`×ZeÑZeÐfhÓZiÓjˆNáØ�\ G¨A¨B KÑ/ˆFØ3AÐ3M�^Ð%¨Ñ.ÐYÐSYÐYäØØØ#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r(   c                 ól   — t        || j                  j                  | j                  j                  «      S r0   )r'   rh   r   r   )r3   r¢  s     r&   Ú%prepare_decoder_input_ids_from_labelsz3MarianMTModel.prepare_decoder_input_ids_from_labels   s%   € Ü! &¨$¯+©+×*BÑ*BÀDÇKÁK×DfÑDfÓgÐgr(   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_selectÚtorO   ©r  Ú
past_stateÚbeam_idxs     €r&   r  z/MarianMTModel._reorder_cache.<locals>.<genexpr>©  s.   øè ø€ ÒrÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑrùó   ƒ58r6   ©r  ©r2  rµ  Úreordered_pastÚ
layer_pasts    `  r&   Ú_reorder_cachezMarianMTModel._reorder_cache£  sT   ø€ àˆØ)ò 	ˆJàÜÓrÐcmÐnpÐopÐcqÔrÓrØ˜Q˜R�.ñ!ðñ ‰Nð	ð Ðr(   )NTr0   )NNNNNNNNNNNNNNNN)*rV   rW   rX   rå   Ú_keys_to_ignore_on_load_missingÚ_keys_to_ignore_on_savern  r   r2   rM  rP  rZ   r   r—   r   r×   r€  rŠ  r`  r�  rƒ  r†  r\  r   ro  r   r   rp  r   ÚMARIAN_GENERATION_EXAMPLEr>   r'  r]   r   r   r   r@   rR   r¬  Ústaticmethodr»  r^   r_   s   @r&   rr  rr  Æ  s­  ø„ ð  Ðò'Ð#ð
  FÐGmÐnÐÚuÐð	˜|õ 	ò(ò(ð dhñØ!ðØ7?À±}ðØ\`ðà	�‰õñ+°sð +Ð_a×_kÑ_kó +ò,ð@<¸ð <Àó <òð&°B·L±Ló &ò&ñ8 +Ð+BÓCÙ¨?ÈÔYÙÐ1Ó2ð 15Ø15Ø8<Ø9=Ø,0Ø48Ø7;ØQUØEIØ59Ø=AØ-1Ø$(Ø,0Ø/3Ø&*ñ#M
à˜E×,Ñ,Ñ-ðM
ð ! §¡Ñ.ðM
ð $ E×$4Ñ$4Ñ5ð	M
ð
 !)¨¯©Ñ 6ðM
ð ˜EŸL™LÑ)ðM
ð $ E§L¡LÑ1ðM
ð ' u§|¡|Ñ4ðM
ð " %¨¨e¯l©lÑ(;¸_Ð(LÑ"MÑNðM
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðM
ð   × 1Ñ 1Ñ2ðM
ð  (¨×(9Ñ(9Ñ:ðM
ð ˜×)Ñ)Ñ*ðM
ð ˜D‘>ðM
ð $ D™>ðM
ð  ' t™nð!M
ð" ˜d‘^ð#M
ð$ 
ò%M
ó 3ó Zó DðM
ð^h¸E¿L¹Ló hð ñó ôr(   rr  c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )ÚMarianDecoderWrapperz½
    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 r0   )r1   r2   r)  rI  rª   s     €r&   r2   zMarianDecoderWrapper.__init__¶  s   ø€ Ü‰Ñ˜Ô Ü$ VÓ,ˆ�r(   c                 ó&   —  | j                   |i |¤ŽS r0   rW  )r3   r‡  Úkwargss      r&   rR   zMarianDecoderWrapper.forwardº  s   € Øˆt�|‰|˜TÐ, VÑ,Ð,r(   )rV   rW   rX   rY   r2   rR   r^   r_   s   @r&   rÁ  rÁ  °  s   ø„ ñô
-ö-r(   rÁ  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 )ÚMarianForCausalLMrt  c                 ó  •— t        j                  |«      }d|_        d|_        t        ‰| �  |«       t        |«      | _        t        j                  |j                  |j                  d¬«      | _        | j                  «        y )NTFrj   )rF  rG  re   r–  r1   r2   rÁ  rÍ   r   rm   Úhidden_sizerö   rx  rü   rª   s     €r&   r2   zMarianForCausalLM.__init__Â  sf   ø€ Ü—‘˜vÓ&ˆØ ˆÔØ$)ˆÔ!Ü‰Ñ˜Ô Ü)¨&Ó1ˆŒ
ä—y‘y ×!3Ñ!3°V×5FÑ5FÈUÔSˆŒð 	�‰Õr(   c                 óB   — | j                   j                  j                  S r0   ©rÍ   rI  rë   rÿ   s    r&   r   z&MarianForCausalLM.get_input_embeddingsÎ  s   € Ø�z‰z×!Ñ!×.Ñ.Ð.r(   c                 ó:   — || j                   j                  _        y r0   rÊ  r  s     r&   r  z&MarianForCausalLM.set_input_embeddingsÑ  s   € Ø*/ˆ�
‰
×ÑÕ'r(   c                 ó   — | j                   S r0   r‘  rÿ   s    r&   rƒ  z'MarianForCausalLM.get_output_embeddingsÔ  rU  r(   c                 ó   — || _         y r0   r‘  r“  s     r&   r†  z'MarianForCausalLM.set_output_embeddings×  r”  r(   c                 ó&   — || j                   _        y r0   ©rÍ   rI  )r3   rI  s     r&   Úset_decoderzMarianForCausalLM.set_decoderÚ  s   € Ø$ˆ�
‰
Õr(   c                 ó.   — | j                   j                  S r0   rÏ  rÿ   s    r&   rP  zMarianForCausalLM.get_decoderÝ  s   € Ø�z‰z×!Ñ!Ð!r(   ra  r   r{   r¿   rÀ   r  r1  r2  r  r¢  rÂ   r}   r	  r
  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, MarianForCausalLM

        >>> tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-fr-en")
        >>> model = MarianForCausalLM.from_pretrained("Helsinki-NLP/opus-mt-fr-en", 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
        ```Nrh  r   r   r   )r¤  r¥  r2  rx   r  r5  )rh   r}   r	  r  rÍ   rI  rx  r²  rO   r   rt   rö   r   r2  rx   r  r5  )r3   r   r{   r¿   rÀ   r  r1  r2  r  r¢  rÂ   r}   r	  r
  r¶   r¥  r¤  r©  rª  s                      r&   rR   zMarianForCausalLM.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ô
ð 	
r(   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     €r&   r  z3MarianForCausalLM._reorder_cache.<locals>.<genexpr>v  s.   øè ø€ ÒnÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑnùr¶  r·  r¸  s    `  r&   r»  z MarianForCausalLM._reorder_cacheq  s=   ø€ àˆØ)ò 	ˆJØÜÓnÐcmÔnÓnðñ ‰Nð	ð Ðr(   )NNNNNNNNNNNNN)rV   rW   rX   rn  r2   r   r  rƒ  r†  rÐ  rP  r   r   rp  r   r>   r'  r]   r@   r   r—   r   r   rR   r¿  r»  r^   r_   s   @r&   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
ð` ñó ôr(   rÆ  )rÆ  rB  rr  rÌ   )@rY   rF  ró   Útypingr   r   r   r   Únumpyr:   r>   Útorch.utils.checkpointr   Útorch.nnr   Úactivationsr
   Ú
generationr   Úmodeling_attn_mask_utilsr   r   Úmodeling_outputsr   r   r   r   r   Úmodeling_utilsr   Úutilsr   r   r   r   r   Úconfiguration_marianr   Ú
get_loggerrV   r6  rp  Ú_CHECKPOINT_FOR_DOCr]   rZ   r'   r×   r*   ÚModulera   r™   rœ   r¹   rÌ   ÚMARIAN_START_DOCSTRINGr¾  ro  rê   r)  rB  rr  rÁ  rÆ  Ú__all__rè   r(   r&   ú<module>rå     s©  ðñ Dã Û ß /Ó /ã Û Û Ý Ý %å !Ý )ß e÷õ õ .÷õ õ /ð 
ˆ×	Ñ	˜HÓ	%€à €Ø2Ð ð %§,¡,ð ¸cð Ð[^ó ô *¨"¯,©,ô *ô@[B�b—i‘iô [Bô~C˜Ÿ™ô CðL $ _Ð5Ð ôu˜Ÿ™ô uôp˜Oô ð<Ð ð Ð ð2XÐ ôvg
Ð)ô g
ôTu
Ð)ô u
ñp ØZÐ\róôt
Ð'ó t
óðt
ñn ØTÐVlóôcÐ)¨?ó cóðcôN-Ð0ô -ôyÐ-¨ô yòx Y�r(   