
    qi                     B   d Z ddlZddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZmZm Z m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z-  e+j\                  e/      Z0dejb                  de2de2fdZ3 G d dejh                        Z5	 	 d:dejl                  dejb                  dejb                  dejb                  dejb                  dz  de7dz  d e7d!e&e(   fd"Z8 G d# d$ejl                        Z9 G d% d&e      Z: G d' d(e      Z;e) G d) d*e$             Z< G d+ d,e<      Z= G d- d.e<      Z>e) G d/ d0e<             Z? e)d12       G d3 d4e<e             Z@ G d5 d6e<      ZA G d7 d8e<e      ZBg d9ZCy);z=PyTorch MarianMTModel model, ported from the Marian C++ repo.    N)Callable)nn)CrossEntropyLoss   )initialization)ACT2FN)CacheDynamicCacheEncoderDecoderCache)GenerationMixin)create_bidirectional_maskcreate_causal_mask)FlashAttentionKwargs)GradientCheckpointingLayer)BaseModelOutput)BaseModelOutputWithPastAndCrossAttentions!CausalLMOutputWithCrossAttentionsSeq2SeqLMOutputSeq2SeqModelOutput)ALL_ATTENTION_FUNCTIONSPreTrainedModel)Unpack)TransformersKwargsauto_docstringis_torchdynamo_compilinglogging   )MarianConfig	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.
    Nr   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       \/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/marian/modeling_marian.pyshift_tokens_rightr+   5   s}     "++IOO<(CRC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dz  ddf fdZd Z ej                         	 dd	ej                  d
edej                  dz  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         |   ||d       y )NT)_freeze)super__init__)selfr/   r0   r1   	__class__s       r*   r6   z,MarianSinusoidalPositionalEmbedding.__init__H   s    tDr,   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<   |S 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)weightr%   nparrayrangepowertorchemptyr;   FloatTensorsincos)r7   n_posdimposjposition_encoutsentinels           r*   create_weightz1MarianSinusoidalPositionalEmbedding.create_weightK   s   
 [[&&
sxxX]^cXdeQTsLAcBHHUAaL3$677Le
 kk%DKK,=,=US"Qw!|3!8#(a"..rvvl1add76K/LMAqzM!--bff\!QTT'5J.KLAxyL
 Mes   D>
	)D92D>
9D>
input_ids_shapepast_key_values_lengthposition_idsc                     |F|dd \  }}t        j                  |||z   t         j                  | j                  j                        }t
        |   |      S )z3`input_ids_shape` is expected to be [bsz x seqlen].Nr:   )r;   device)rB   arangelongr=   rS   r5   forward)r7   rO   rP   rQ   bszseq_lenr8   s         r*   rV   z+MarianSinusoidalPositionalEmbedding.forwardZ   s]    
 *2A.LC <<&(>(HPUPZPZcgcncncucuL w|,,r,   N)r   N)__name__
__module____qualname____doc__intr6   rN   rB   no_gradSizeTensorrV   __classcell__r8   s   @r*   r.   r.   E   s    NEc E# ECRVJ Ebf E U]]_pt	-$zz	-CF	-Z_ZfZfimZm	-		- 	-r,   r.   modulequerykeyvalueattention_maskscalingdropoutkwargsc                    ||j                  d      dz  }t        j                  ||j                  dd            |z  }|||z   }t        j
                  j                  |d      }t        j
                  j                  ||| j                        }t        j                  ||      }	|	j                  dd      j                         }	|	|fS )Nr#         r:   r   rH   ptrainingr   )
sizerB   matmul	transposer   
functionalsoftmaxrj   rq   
contiguous)
rd   re   rf   rg   rh   ri   rj   rk   attn_weightsattn_outputs
             r*   eager_attention_forwardrz   h   s     **R.D( <<s}}Q':;gEL!#n4==((2(>L==((6??([L,,|U3K''1-88:K$$r,   c                   Z    e Zd ZdZ	 	 	 	 	 	 ddedededededed	edz  d
edz  f fdZ	 	 	 	 	 dde	j                  de	j                  dz  dedz  de	j                  dz  dede	j                  dz  dee   dee	j                  e	j                  dz  ee	j                     dz  f   fdZ xZS )MarianAttentionz=Multi-headed attention from 'Attention Is All You Need' paperN	embed_dim	num_headsrj   
is_decoderbias	is_causalconfig	layer_idxc	                    t         	|           || _        || _        || _        ||z  | _        || _        | j
                  |z  | j                  k7  rt        d| j                   d| d      | j
                  dz  | _        || _	        || _
        || _        |9| j                  r-t        j                  d| j                  j                   d       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).rm   zInstantiating a decoder z without passing `layer_idx` is not recommended and will lead to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` when creating this class.r   )r5   r6   r}   r~   rj   head_dimr   r'   ri   r   r   r   loggerwarning_oncer8   rZ   r   Lineark_projv_projq_projout_proj)
r7   r}   r~   rj   r   r   r   r   r   r8   s
            r*   r6   zMarianAttention.__init__   s$    	""!Y.MMI%$..8MdnnM]$YKr3  }}d*$""*4>>+B+B*C D, , ii	94@ii	94@ii	94@		)YTBr,   hidden_stateskey_value_statespast_key_valuesrh   output_attentionscache_positionrk   r2   c                    |du}|j                   dd \  }	}
|r|j                   d   n|
}|	|
d| j                  f}|	|d| j                  f} | j                  |      j                  | j	                  dd      }d}|St        |t              rA|j                  j                  | j                        }|r|j                  }n|j                  }n|}|r|n|}|rK|I|rGj                  | j                     j                  }|j                  | j                     j                  }n| j                  |      }| j!                  |      } |j                  | j	                  dd      } |j                  | j	                  dd      }|T|s|nd}j#                  ||| j                  d|i      \  }}|r)t        |t              rd|j                  | j                  <   t%        j&                  | j(                  j*                  t,              } || ||||f| j.                  sdn| j0                  | j2                  |d	|\  }}|j5                  |	|
d      j7                         }| j9                  |      }||fS )
z#Input shape: Batch x Time x ChannelNr#   r   r:   Fr   T        )rj   ri   r   )r%   r   r   viewrt   
isinstancer   
is_updatedgetr   cross_attention_cacheself_attention_cachelayerskeysvaluesr   r   updater   get_interfacer   _attn_implementationrz   rq   rj   ri   reshaperw   r   )r7   r   r   r   rh   r   r   rk   is_cross_attentionrW   tgt_lensrc_lenq_input_shapekv_input_shapequery_statesr   curr_past_key_valuescurrent_states
key_statesvalue_statesattention_interfacery   rx   s                          r*   rV   zMarianAttention.forward   s{     .T9 %**3B/W/A"((+wgr4==9wDMM: 7t{{=166FPPQRTUV
&/+>?,77;;DNNK
%+:+P+P(+:+O+O('6$-?)]/"=*-44T^^DIIJ/66t~~FMML^4J;;~6L(.9CCAqIJ,<,,n=GG1ML*7It+?+F+Fdnn?OQ_>`,(
L &*_FY*ZAEO..t~~>(?(M(MKK,,.E)
 %8
%
  $}}C$,,LL/
%
 
%
!\ "))#w;FFHmmK0L((r,   )r   FTFNN)NNNFN)rZ   r[   r\   r]   r^   floatboolr   r6   rB   ra   r	   r   r   tuplerV   rb   rc   s   @r*   r|   r|      s=   G  &* $%C%C %C 	%C
 %C %C %C t#%C :%CT 15(,.2"'.2P)||P)  ,,-P) 	P)
 t+P)  P) t+P) -.P) 
u||U\\D0%2E2LL	MP)r,   r|   c                        e Zd Zd
dededz  f fdZ	 ddej                  dej                  dedz  de	ej                  ej                  dz  f   fd	Z
 xZS )MarianEncoderLayerNr   r   c                 j   t         |           |j                  | _        t	        | j                  |j
                  |j                  ||      | _        t        j                  | j                        | _
        |j                  | _        t        |j                     | _        |j                  | _        t        j                   | j                  |j"                        | _        t        j                   |j"                  | j                        | _        t        j                  | j                        | _        y )N)r}   r~   rj   r   r   )r5   r6   d_modelr}   r|   encoder_attention_headsattention_dropout	self_attnr   	LayerNormself_attn_layer_normrj   r   activation_functionactivation_fnactivation_dropoutr   encoder_ffn_dimfc1fc2final_layer_normr7   r   r   r8   s      r*   r6   zMarianEncoderLayer.__init__  s    (nn44,,
 %'LL$@!~~#F$>$>?"(";";99T^^V-C-CD99V33T^^D "T^^ <r,   r   rh   r   r2   c                 Z   |}| 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(  rht        j                  |      j                         sEt        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.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        )r   rh   r   ro   i  )minmax)r   r   ru   rj   rq   r   r   r   r   r   r   r;   rB   float16isfiniteallfinfor   clamp)r7   r   rh   r   residualrx   clamp_valueoutputss           r*   rV   zMarianEncoderLayer.forward  su    !&*nn')/ '5 '
#|
 --mt||VZVcVc-d =011-@ **488M+BC--mt?V?Vaeanan-o/--mt||VZVcVc-d =0--m<%--/}8U8Y8Y8[++m&9&9:>>EK!KKK<[YM "&Gr,   rY   )F)rZ   r[   r\   r   r^   r6   rB   rD   r   r   rV   rb   rc   s   @r*   r   r     su    =| =d
 =. */	*((* ))*  $;	*
 
u  %"3"3d"::	;*r,   r   c                   P    e Zd Zddededz  f fdZ	 	 	 	 	 	 	 ddej                  dej                  dz  dej                  dz  dej                  dz  d	edz  d
e	dz  de	dz  dej                  dz  de
ej                  e
ej                  ej                  f   dz  f   fdZ xZS )MarianDecoderLayerNr   r   c           	         t         |           |j                  | _        t	        | j                  |j
                  |j                  dd||      | _        |j                  | _        t        |j                     | _        |j                  | _        t        j                  | j                        | _        t	        | j                  |j
                  |j                  d||      | _        t        j                  | j                        | _        t        j$                  | j                  |j&                        | _        t        j$                  |j&                  | j                        | _        t        j                  | j                        | _        y )NT)r}   r~   rj   r   r   r   r   )rj   r   r   r   )r5   r6   r   r}   r|   decoder_attention_headsr   r   rj   r   r   r   r   r   r   r   encoder_attnencoder_attn_layer_normr   decoder_ffn_dimr   r   r   r   s      r*   r6   zMarianDecoderLayer.__init__F  s    (nn44,,
 ~~#F$>$>?"(";";$&LL$@!+NN**,,
 (*||DNN'C$99T^^V-C-CD99V33T^^D "T^^ <r,   r   rh   encoder_hidden_statesencoder_attention_maskr   r   	use_cacher   r2   c	                 .   |}	| j                  |||||      \  }}
t        j                  j                  || j                  | j                        }|	|z   }| j                  |      }d}|h|}	| j                  ||||||      \  }}t        j                  j                  || j                  | j                        }|	|z   }| j                  |      }|}	| j                  | j                  |            }t        j                  j                  || j                  | j                        }| j                  |      }t        j                  j                  || j                  | j                        }|	|z   }| 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.
            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.
            past_key_values (`Cache`): 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.
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence. It is used to update the
                cache in the correct position and to infer the complete sequence length.
        )r   r   rh   r   r   ro   N)r   r   rh   r   r   r   )r   r   ru   rj   rq   r   r   r   r   r   r   r   r   )r7   r   rh   r   r   r   r   r   r   r   self_attn_weightscross_attn_weightsr   s                r*   rV   zMarianDecoderLayer.forwarde  s   8 ! ,0>>'+)/) ,: ,
(( --mt||VZVcVc-d =011-@ " ,$H040A0A+!65 /"3- 1B 1-M- MM11-4<<Z^ZgZg1hM$}4M 88GM !**488M+BC--mt?V?Vaeanan-o/--mt||VZVcVc-d =0--m< ")+=>>Gr,   rY   )NNNNFTN)rZ   r[   r\   r   r^   r6   rB   ra   r	   r   r   rD   rV   rb   rc   s   @r*   r   r   E  s    =| =d
 =D /3596:(,).!%.2I||I t+I  %||d2	I
 !&t 3I I  $;I $;I t+I 
u  %(9(95;L;L(L"MPT"TT	UIr,   r   c                   z     e Zd ZU eed<   dZdZdZdZdZ	dZ
 ej                          fd       Zed        Z xZS )MarianPreTrainedModelr   modelTc                    t         |   |       t        |t              r/t	        j
                  |j                  |j                                y t        |t              r t	        j                  |j                         y y rY   )r5   _init_weightsr   r.   initcopy_r=   rN   MarianMTModelzeros_final_logits_bias)r7   rd   r8   s     r*   r   z#MarianPreTrainedModel._init_weights  sW    f%fABJJv}}f&:&:&<=.KK001 /r,   c                     | j                   j                  }t        j                  g ddddd|gg| j                        }|j                  |      ||d}|S )N)r      
      r:   r         r:   rS   )rh   r   decoder_input_ids)r   r    rB   tensorrS   ne)r7   	pad_tokenr   dummy_inputss       r*   r   z"MarianPreTrainedModel.dummy_inputs  sZ    KK,,	LL"2Q2q)4L!MVZVaVab	'll95"!*

 r,   )rZ   r[   r\   r   __annotations__base_model_prefixsupports_gradient_checkpointing_supports_flash_attn_supports_sdpa_supports_flex_attn_can_compile_fullgraphrB   r_   r   propertyr   rb   rc   s   @r*   r   r     sZ    &*#N!U]]_2 2  r,   r   c                        e Zd ZdZdef fdZ	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  de	dz  d	e	dz  d
e	dz  de
ej                     ez  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
    r   c                    t         |   |       |j                  | _        |j                  | _        |j
                  }|j                  | _        |j                  | _	        |j                  rt        j                  |      nd| _        t        j                  |j                   || j                        | _        t%        |j                  || j                        | _        t        j(                  t+        |j,                        D cg c]  }t/        |       c}      | _        d| _        | j5                          y c c}w )N      ?F)r5   r6   rj   encoder_layerdrop	layerdropr   r    r1   max_position_embeddingsmax_source_positionsscale_embeddingmathsqrtembed_scaler   	Embedding
vocab_sizeembed_tokensr.   embed_positions
ModuleListr@   encoder_layersr   r   gradient_checkpointing	post_init)r7   r   r}   _r8   s       r*   r6   zMarianEncoder.__init__  s     ~~11NN	!..$*$B$B!393I3I499Y/sLL):):ItGWGWXB**It7G7G 
 mmvOdOdIe$fA%7%?$fg&+#	 %gs   D;Nr   rh   inputs_embedsr   output_hidden_statesreturn_dictr2   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}t!        | j"                        D ]b  \  }}|r||
fz   }d}| j                  r&t%        j&                  g       }|| j(                  k  rd	}|rd
}n ||
||      }|d   }
|sZ||d   fz   }d |r||
fz   }|st+        d |
||fD              S t-        |
||      S )a8  
        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)
            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_embedsro   )r   r  rh    FT)NN)r   r   r   c              3   &   K   | ]	  }||  y wrY   r  .0vs     r*   	<genexpr>z(MarianEncoder.forward.<locals>.<genexpr>W  s     eqWXWdes   last_hidden_stater   
attentions)r   r   r  use_return_dictr'   %warn_if_padding_and_no_attention_maskrr   r   r  r  r  r   ru   rj   rq   r   	enumerater   rB   randr   r   r   )r7   r   rh   r  r   r  r  rk   input_shape	embed_posr   encoder_statesall_attentionsidxencoder_layerto_dropdropout_probabilitylayer_outputss                     r*   rV   zMarianEncoder.forward  s-   P 2C1N-TXT_T_TqTq$8$D $++JjJj 	 &1%<k$++B]B]  ]%>cdd"66y.Q#..*K!r;r?;I&',,.s3KTUU  --i84;K;KKM((5	%	1--mt||VZVcVc-d2;;')
  40d"+DKK"8 	FC#!/=2B!BG}}&+jjn#&7"G , -!"&7! !.a 0 !/=3C2E!E-	F0  +}.>>Ne]NN$Seee+>Vd
 	
r,   )NNNNNN)rZ   r[   r\   r]   r   r6   rB   
LongTensorrD   r   r   ra   r   rV   rb   rc   s   @r*   r   r     s    | 0 .22626)-,0#'j
##d*j
 ((4/j
 ((4/	j

  $;j
 #Tkj
 D[j
 
u||		.j
r,   r   c                   R    e Zd ZdZdef fdZ	 	 	 	 	 	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  dej                  dz  d	e
dz  d
ej                  dz  dedz  dedz  dedz  dedz  dej                  dz  deej                     ez  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
    r   c           	         t         |   |       |j                  | _        |j                  | _        |j
                  | _        |j                  | _        |j                  rt        j                  |j                        nd| _        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 )Nr   )r   F)r5   r6   rj   decoder_layerdropr   r    r1   r   max_target_positionsr   r   r  r   r  r   r  decoder_vocab_sizer  r.   r  r  r@   decoder_layersr   r   r	  r
  )r7   r   ir8   s      r*   r6   zMarianDecoder.__init__f  s     ~~11!..$*$B$B!8>8N8N499V^^4TWLL)B)BFNNTXTdTdeB**FNND<L<L 
 mmV[\b\q\qVr$sQR%7!%L$st&+#	 %ts   ENr   rh   r   r   r   r  r   r   r  r  r   r2   c                    ||n| j                   j                  }|	|	n| j                   j                  }	||n| j                   j                  }|
|
n| j                   j                  }
| j
                  r%| j                  r|rt        j                  d       d}|du |duz  rt        d      |$|}|j                  }|j                  d|d         }n!||j                         dd }|dddddf   }|| j                        }|| j                  z  }|rd|b|| j                   j                  r4t!        t#        | j                         t#        | j                               nt#        | j                         }|j                         dd \  }}||j%                         nd}|%t'        j(                  |||z   |j*                        }|1t-               s'||z   }t'        j.                  |||j*                        }t1        |t               r|j2                  n|}t5        | j                   ||||	      }t7        | j                   |||
      }| j9                  ||f||      }||z   }t:        j<                  j?                  || j>                  | j                        }|	rdnd}|rdnd}|r|dnd}tA        | jB                        D ]k  \  }}|	r||fz  }| j                  r%t'        jD                  g       }|| jF                  k  r? |||||||||      }|d   }|sW||d   fz  }|c||d   fz  }m |	r||fz  }|
stI        d |||||fD              S tK        |||||      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)
            past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
                It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

                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.
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence. It is used to update the
                cache in the correct position and to infer the complete sequence length.
        NzZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Fz:You must specify exactly one of input_ids or inputs_embedsr#   )r   r   r   )r   r  rh   r   r   )r   r  rh   r   )rQ   ro   r  )r   r   r   r   r   r   r:   c              3   $   K   | ]  }|| 
 y wrY   r  r  s     r*   r  z(MarianDecoder.forward.<locals>.<genexpr>0  s      = s   )r  r   r   r  cross_attentions)&r   r   r  r   r  r	  rq   r   r   r'   r%   r   rr   r  r  is_encoder_decoderr   r
   get_seq_lengthrB   rT   rS   r   onesr   r   r   r   r  r   ru   rj   r  r   r  r   r   r   )r7   r   rh   r   r   r   r  r   r   r  r  r   rk   inputr  
batch_size
seq_lengthrP   mask_seq_lengthself_attn_cachecausal_maskrQ   r   all_hidden_statesall_self_attnsall_cross_attentionsr!  decoder_layerr$  r%  s                                 r*   rV   zMarianDecoder.forwardy  s   H 2C1N-TXT_T_TqTq$8$D $++JjJj 	 "+!6IDKK<Q<Q	%0%<k$++B]B]&&4==##p "	 -t";<YZZ"E++K!r;r?;I&',,.s3K!!Q(+E  --e4M &(8(88 0 )48V8V $L$DlZ^ZeZeFfg!5  "/!3!3!5cr!:
JETE`!?!?!Afg!"\\&(>(KTaThThN !*B*D4zAO"ZZ
OML`L`aN /+>? 00  	 );;'))+
 ";;;'1"7	"
 ++$&<> , 
 &4--mt||VZVcVc-d #7BD0d&7<Q<]rdh"+DKK"8 	@C#!m%55!}}&+jjn#&7)%'= /"3#-	M *!,M =#3"55(4(]1-=,??(3	@8  -!11 ':K^]qr  
 9+++%1
 	
r,   )NNNNNNNNNNN)rZ   r[   r\   r]   r   r6   rB   r&  ra   rD   r	   r   r   r   rV   rb   rc   s   @r*   r(  r(  ]  s    | * .2.2:>:>(,26!%)-,0#'.2B
##d*B
 t+B
  %0047	B

 !& 0 04 7B
 B
 ((4/B
 $;B
  $;B
 #TkB
 D[B
 t+B
 
u||	H	HB
r,   r(  c                       e Zd ZddgZdef fdZd Zd Zd Zd Z	d	e
d
ej                  fdZe	 	 	 	 	 	 	 	 	 	 	 	 	 ddej                   dz  dej"                  dz  dej                   dz  dej"                  dz  deej"                     ez  dz  dedz  dej*                  dz  dej*                  dz  dedz  dedz  dedz  dedz  dej"                  dz  d
efd       Z xZS )MarianModel$model.encoder.embed_positions.weight$model.decoder.embed_positions.weightr   c                 P   t         |   |       |j                  |j                  }}| j                  j
                  r1t        j                  ||j                  |      | _	        ddd| _
        nd | _
        t        |      | _        t        |      | _        | j                          y )Nzshared.weight)zdecoder.embed_tokens.weightzencoder.embed_tokens.weight)r5   r6   r    r  r    share_encoder_decoder_embeddingsr   r  r   shared_tied_weights_keysr   encoderr(  decoderr
  )r7   r   r1   r  r8   s       r*   r6   zMarianModel.__init__E  s     "("5"5v7H7HZ ;;77,,z6>>;ODK/>/>'D#
 '+D#$V,$V, 	r,   c                 >    | j                         j                         S rY   )get_encoderget_input_embeddingsr7   s    r*   rK  z MarianModel.get_input_embeddingsZ  s    !6688r,   c                     | j                   j                  r>|| _        | j                  | j                  _        | j                  | j
                  _        y || j                  _        y rY   )r   rD  rE  rG  r  rH  r7   rg   s     r*   set_input_embeddingsz MarianModel.set_input_embeddings^  sB    ;;77DK(,DLL%(,DLL%(-DLL%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.)r   rD  r'   get_decoderrK  rL  s    r*   get_decoder_input_embeddingsz(MarianModel.get_decoder_input_embeddingsf  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.)r   rD  r'   rH  r  rN  s     r*   set_decoder_input_embeddingsz(MarianModel.set_decoder_input_embeddingsn  s0    ;;77r 
 %*!r,   new_num_tokensr2   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.)r   rD  r'   rR  _get_resized_embeddingsrT  r,  tie_weights)r7   rU  old_embeddingsnew_embeddingsmodel_embedss        r*   resize_decoder_token_embeddingsz+MarianModel.resize_decoder_token_embeddingsw  s    ;;77K 
 ::<55nnU)).988:! *8& 	r,   Nr   rh   r   decoder_attention_maskencoder_outputsr   r  decoder_inputs_embedsr   r   r  r  r   c                 v   |
|
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 )	a  
        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.

        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   rh   r  r   r  r  r   r   r:   r  r   rh   r   r   r   r  r   r   r  r  r   )r  r   decoder_hidden_statesdecoder_attentionsr1  encoder_last_hidden_stater   encoder_attentions)r   r   r  r  rG  r   r   lenrH  r   r  r   r   r  r1  )r7   r   rh   r   r^  r_  r   r  r`  r   r   r  r  r   rk   decoder_outputss                   r*   rV   zMarianModel.forward  sm   l 2C1N-TXT_T_TqTq$8$D $++JjJj 	 &1%<k$++B]B] ""ll#-+"3%9' + O O_!M-"1!"4474H14Loa0RV14_1E1I?1-tO ,,'1"1!"4#1+//!5#) ' 
 "_44!-??+;;"1"?"?.99,==&5&G&G"1"?"?.99	
 		
r,   )NNNNNNNNNNNNN)rZ   r[   r\   _keys_to_ignore_on_load_missingr   r6   rK  rO  rR  rT  r^   r   r  r]  r   rB   r&  ra   r   r   r	   rD   r   r   rV   rb   rc   s   @r*   r@  r@  >  s    	/.'#
| *9.9*c bll 0  .2.2596:HL(,26:>!%)-,0#'.2h
##d*h
 t+h
 !++d2	h

 !&t 3h
 u||,>Eh
 h
 ((4/h
  %0047h
 $;h
  $;h
 #Tkh
 D[h
 t+h
  
!h
 h
r,   r@  zX
    The Marian Model with a language modeling head. Can be used for summarization.
    )custom_introc                    v    e Zd ZdZg dZddgZddiZdef fdZ	 d$d
e	de	d	z  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ej                  fdZe	 	 	 	 	 	 	 	 	 	 	 	 	 	 d&dej(                  d	z  dej*                  d	z  dej(                  d	z  dej*                  d	z  deej*                     ez  d	z  ded	z  dej2                  d	z  dej2                  d	z  dej(                  d	z  de
d	z  de
d	z  de
d	z  d e
d	z  d!ej*                  d	z  defd"       Zdej*                  fd#Z xZS )'r   r   )r   rA  rB  rA  rB  lm_head.weight!model.decoder.embed_tokens.weightr   c                    t         |   |       t        |      | _        | j                  j
                  rdddd| _        |j
                  r|j                  n|j                  }| j                  dt        j                  d|f             t        j                  |j                  |d      | _        | j!                          y )Nzmodel.shared.weight)rl  rm  z!model.encoder.embed_tokens.weightr   r   Fr   )r5   r6   r@  r   r   rD  rF  r  r,  register_bufferrB   zerosr   r   r   lm_headr
  )r7   r   target_vocab_sizer8   s      r*   r6   zMarianMTModel.__init__
  s      (
;;77"75J5J'D# 281X1XF--^d^w^w0%++qBS>T2UVyy1BO 	r,   NrU  pad_to_multiple_ofmean_resizingr2   c                 x    t         |   |||      }| j                  j                  r| j	                  |       |S rY   )r5   resize_token_embeddingsr   rD  _resize_final_logits_bias)r7   rU  rs  rt  r[  r8   s        r*   rv  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   )rK  rX  rO  r=   r%   r   rD  r,  get_output_embeddingstie_word_embeddings_get_resized_lm_headset_output_embeddings)r7   rU  rs  argsrZ  r[  old_lm_headnew_lm_heads           r*   _resize_token_embeddingsz&MarianMTModel._resize_token_embeddings$  s    22455nnVhi!!.1'..44Q7;;77-;DKK* KK88**,8KK33446K33KPK&&{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 rW  )r   rD  r'   r   rR  rX  rT  ry  rz  r{  r|  r,  rY  rw  )r7   rU  rZ  r[  r~  r  r\  s          r*   r]  z-MarianMTModel.resize_decoder_token_embeddings:  s    ;;77K 
 @@B55nnU

//? %%'3DKK<[<[446K33KPK&&{3zz>>@! *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   rn   r   )r   r%   rB   rp  rS   catro  )r7   rU  old_num_tokensnew_bias
extra_biass        r*   rw  z'MarianMTModel._resize_final_logits_biasZ  s    //55b9^+--a..@AHa.)H%IRVRhRhRoRopJyy$"8"8*!E1MH0(;r,   r[  c                     || _         y rY   )rq  )r7   r[  s     r*   r|  z#MarianMTModel.set_output_embeddingsc  s	    %r,   r   rh   r   r^  r_  r   r  r`  labelsr   r   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 )	u  
        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.
        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]`.

        Example:

        ```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?"
        ```
        NzJThe `use_cache` argument is changed to `False` since `labels` is provided.F)rh   r   r_  r^  r   r  r`  r   r   r  r  r   r   r#   r   )	losslogitsr   rc  rd  r1  re  r   rf  )r   r  r   warningr+   r    r!   r   rq  r   r   r   r,  r   r   rc  rd  r1  re  r   rf  )r7   r   rh   r   r^  r_  r   r  r`  r  r   r   r  r  r   rk   r   	lm_logitsmasked_lm_lossloss_fctoutputs                        r*   rV   zMarianMTModel.forwardf  s   v &1%<k$++B]B]klI (-B-J$6DKK44dkk6X6X%! **)/+#9+'"7/!5#)  
 LL,t/E/EE	')H%innR9W9W&XZ`ZeZefhZijN\GABK/F3A3M^%.YSYY#33")"?"?&99$55&-&G&G")"?"?&99

 
	
r,   c                 l    t        || j                  j                  | j                  j                        S rY   )r+   r   r    r!   )r7   r  s     r*   %prepare_decoder_input_ids_from_labelsz3MarianMTModel.prepare_decoder_input_ids_from_labels  s%    !&$++*B*BDKKDfDfggr,   )NTrY   )NNNNNNNNNNNNNN)rZ   r[   r\   r   ri  _keys_to_ignore_on_saverF  r   r6   r^   r   r   r  rv  r  r]  rw  r|  r   rB   r&  ra   r   r   r	   rD   r   rV   r  rb   rc   s   @r*   r   r     s"     '#
  FGmn*,OP| $ ae!7:TzY]	+s +_a_k_k +,@< < <&BLL &  .2.2596:HL(,26:>*.!%)-,0#'.2i
##d*i
 t+i
 !++d2	i

 !&t 3i
 u||,>Ei
 i
 ((4/i
  %0047i
   4'i
 $;i
  $;i
 #Tki
 D[i
 t+i
" 
#i
 i
VhELL hr,   r   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        |      | _        | j	                          y rY   )r5   r6   r(  rH  r
  r7   r   r8   s     r*   r6   zMarianDecoderWrapper.__init__  s&     $V,r,   c                 &     | j                   |i |S rY   )rH  )r7   r}  rk   s      r*   rV   zMarianDecoderWrapper.forward  s    t||T,V,,r,   )rZ   r[   r\   r]   r6   rV   rb   rc   s   @r*   r  r    s    

-r,   r  c                       e Zd ZddiZ fdZd Zd Ze	 	 	 	 	 	 	 	 	 	 	 	 	 ddej                  dz  dej                  dz  d	ej                  dz  d
ej                  dz  dedz  dej                  dz  dej                  dz  dedz  dedz  dedz  dedz  dej                  dz  deej                  z  deez  fd       Z xZS )MarianForCausalLMrl  rm  c                     d|_         d|_        t        |   |       t	        |      | _        t        j                  |j                  |j                  d      | _
        | j                          y )NTFr   )r   r2  r5   r6   r  r   r   r   hidden_sizer  rq  r
  r  s     r*   r6   zMarianForCausalLM.__init__  sX     $)! )&1
yy!3!3V5F5FUS 	r,   c                 B    | j                   j                  j                  S rY   r   rH  r  rL  s    r*   rK  z&MarianForCausalLM.get_input_embeddings  s    zz!!...r,   c                 :    || j                   j                  _        y rY   r  rN  s     r*   rO  z&MarianForCausalLM.set_input_embeddings  s    */

'r,   Nr   rh   r   r   r   r  r  r   r   r  r  r   logits_to_keepr2   c                    |	|	n| j                   j                  }	|
|
n| j                   j                  }
||n| j                   j                  }| j                  j                  ||||||||	|
||      }|d   }t        |t              rt        | d      n|}| j                  |dd|ddf         }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 )aT  
        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]`.

        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")
        >>> 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
        ```Nrb  r   r#   r   )r  r  r   r   r  r1  )r   r   r  r  r   rH  r   r^   slicerq  torS   r   r   r  r   r   r   r  r1  )r7   r   rh   r   r   r   r  r  r   r   r  r  r   r  rk   r   r   slice_indicesr  r  r  r  s                         r*   rV   zMarianForCausalLM.forward  s   R 2C1N-TXT_T_TqTq$8$D $++JjJj 	 &1%<k$++B]B] **$$)"7#9+'/!5#) % 
  
8B>SV8W~ot4]kmA}a,?@AYYv}}-F')HFKKDKK,B,BCV[[QS_UDY,F'+'7D7V#CVC0#33!//))$55
 	
r,   )NNNNNNNNNNNNr   )rZ   r[   r\   rF  r6   rK  rO  r   rB   r&  ra   rD   r	   r   r^   r   r   rV   rb   rc   s   @r*   r  r    se   =	/0  .2.2:>;?(,26*.!%)-,0#'26-.S
##d*S
 t+S
  %0047	S

 !& 1 1D 8S
 S
 ((4/S
   4'S
 $;S
  $;S
 #TkS
 D[S
 ((4/S
 ell*S
  
2	2!S
 S
r,   r  )r  r@  r   r   )Nr   )Dr]   r   collections.abcr   numpyr>   rB   r   torch.nnr    r   r   activationsr   cache_utilsr	   r
   r   
generationr   masking_utilsr   r   modeling_flash_attention_utilsr   modeling_layersr   modeling_outputsr   r   r   r   r   modeling_utilsr   r   processing_utilsr   utilsr   r   r   r   configuration_marianr   
get_loggerrZ   r   ra   r^   r+   r  r.   Moduler   rz   r|   r   r   r   r   r(  r@  r   r  r  __all__r  r,   r*   <module>r     s   D  $    % & ! C C ) J B 9  G &  / 
		H	%%,, c [^  -",, -R !%II%<<% 
% <<	%
 LL4'% T\% % '(%:z)bii z)|>3 >Di3 iX O  <J
) J
Z^
) ^
B y
' y
 y
x 
Sh)? Sh
Shn-0 - j
- j
Z Yr,   