Ë
    T^(hXû  ã                   óÒ  — d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z ddlZddlmZ ddlZddlmZmZmZ ddl	mZmZ ddlmZ ddlmZ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'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1  e.jd                  e3«      Z4dZ5dZ6dZ7dZ8dZ9dZ:d„ Z;dejx                  de=de=dejx                  fd„Z> G d„ dej~                  «      Z@ G d„ d ej~                  «      ZA G d!„ d"ej~                  «      ZB G d#„ d$ej~                  «      ZC G d%„ d&ej~                  «      ZD G d'„ d(ej~                  «      ZE G d)„ d*ej~                  «      ZF G d+„ d,ej~                  «      ZG G d-„ d.e'«      ZH e,d/e7«       G d0„ d1eH«      «       ZI e(eIe5e$e6«        G d2„ d3ej~                  «      ZJ e,d4e7«       G d5„ d6eH«      «       ZKd7ZL e*eKe8eLz   «        e)eKe#e6¬8«       g d9¢ZMy):zFlax Marian model.é    N)Úpartial)ÚCallableÚOptionalÚTuple)Ú
FrozenDictÚfreezeÚunfreeze)Úcombine_masksÚmake_causal_mask)Údot_product_attention_weights)Úflatten_dictÚunflatten_dict)Úlax)ÚPRNGKeyé   )ÚFlaxBaseModelOutputÚ-FlaxBaseModelOutputWithPastAndCrossAttentionsÚ%FlaxCausalLMOutputWithCrossAttentionsÚFlaxSeq2SeqLMOutputÚFlaxSeq2SeqModelOutput)ÚACT2FNÚFlaxPreTrainedModelÚappend_call_sample_docstringÚ append_replace_return_docstringsÚoverwrite_call_docstring)Úadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚMarianConfigzHelsinki-NLP/opus-mt-en-der!   a  
    This model inherits from [`FlaxPreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a Flax Linen
    [flax.nn.Module](https://flax.readthedocs.io/en/latest/_autosummary/flax.nn.module.html) subclass. Use it as a
    regular Flax Module and refer to the Flax documentation for all matter related to general usage and behavior.

    Finally, this model supports inherent JAX features such as:

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

    Parameters:
        config ([`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 [`~FlaxPreTrainedModel.from_pretrained`] method to load the model weights.
        dtype (`jax.numpy.dtype`, *optional*, defaults to `jax.numpy.float32`):
            The data type of the computation. Can be one of `jax.numpy.float32`, `jax.numpy.float16` (on GPUs) and
            `jax.numpy.bfloat16` (on TPUs).

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

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

            If you wish to change the dtype of the model parameters, see [`~FlaxPreTrainedModel.to_fp16`] and
            [`~FlaxPreTrainedModel.to_bf16`].
aÓ  
    Args:
        input_ids (`jnp.ndarray` 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 (`jnp.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        decoder_input_ids (`jnp.ndarray` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary.

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

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

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

            If you want to change padding behavior, you should modify to your needs. See diagram 1 in [the
            paper](https://arxiv.org/abs/1910.13461) for more information on the default strategy.
        position_ids (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.
        decoder_position_ids (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each decoder input sequence tokens in the position embeddings. Selected in the
            range `[0, config.max_position_embeddings - 1]`.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
a:  
    Args:
        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. 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 (`jnp.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        position_ids (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
a  
    Args:
        decoder_input_ids (`jnp.ndarray` of shape `(batch_size, target_sequence_length)`):
            Indices of decoder input sequence tokens in the vocabulary.

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

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

            For translation and summarization training, `decoder_input_ids` should be provided. If no
            `decoder_input_ids` is provided, the model will create this tensor by shifting the `input_ids` to the right
            for denoising pre-training following the paper.
        encoder_outputs (`tuple(tuple(jnp.ndarray)`):
            Tuple consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*: `attentions`)
            `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) is a sequence of
            hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
        encoder_attention_mask (`jnp.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.

            [What are attention masks?](../glossary#attention-mask)
        decoder_attention_mask (`jnp.ndarray` of shape `(batch_size, target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.

            If you want to change padding behavior, you should modify to your needs. See diagram 1 in [the
            paper](https://arxiv.org/abs/1910.13461) for more information on the default strategy.
        decoder_position_ids (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each decoder input sequence tokens in the position embeddings. Selected in the
            range `[0, config.max_position_embeddings - 1]`.
        past_key_values (`Dict[str, np.ndarray]`, *optional*, returned by `init_cache` or when passing previous `past_key_values`):
            Dictionary of pre-computed hidden-states (key and values in the attention blocks) that can be used for fast
            auto-regressive decoding. Pre-computed key and value hidden-states are of shape *[batch_size, max_length]*.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                 óì  — t        j                  t        | «      D ��cg c];  }t        |«      D �cg c]$  }|t        j                  dd|dz  z  |z  «      z  ‘Œ& c}‘Œ= c}}«      }|dz  |dz  z   }t        j                  |«      }t        j
                  |d d …dd d…f   «      |d d …d|…f<   t        j                  |d d …dd d…f   «      |d d …|d …f<   t        j                  |«      S c c}w c c}}w )Ni'  é   r   r    )ÚnpÚarrayÚrangeÚpowerÚ
zeros_likeÚsinÚcosÚjnp)Ún_posÚdimÚposÚjÚposition_encÚsentinelÚouts          úm/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/marian/modeling_flax_marian.pyÚcreate_sinusoidal_positionsr4   Û   sÛ   € Ü—8‘8ÔhmÐnsÓht×uÐadÔQVÐWZÓQ[Ö\ÈA˜c¤B§H¡H¨U°A¸¸a¹±LÀ3Ñ4FÓ$GÓGÔ\ÓuÓv€LØ�a‰x˜# ™'Ñ!€HÜ
�-‰-˜Ó
%€CÜŸ™ ªQ°°°1°¨WÑ 5Ó6€CŠˆ1ˆXˆ:ˆÑÜŸ™˜|ªA¨q¨t°!¨t¨GÑ4Ó5€CŠˆ8‰9ˆÑä�9‰9�S‹>Ðùò ]ùÓus   žC0
°)C+ÁC0
Ã+C0
Ú	input_idsÚpad_token_idÚdecoder_start_token_idÚreturnc                 ó  — t        j                  | «      }|j                  dd…dd…f   j                  | dd…dd…f   «      }|j                  dd…df   j                  |«      }t        j                  |dk(  ||«      }|S )z1
    Shift input ids one token to the right.
    Nr    éÿÿÿÿr   iœÿÿÿ)r+   r(   ÚatÚsetÚwhere)r5   r6   r7   Úshifted_input_idss       r3   Úshift_tokens_rightr?   æ   sƒ   € ô Ÿ™ yÓ1ÐØ)×,Ñ,ªQ°±¨UÑ3×7Ñ7¸	Â!ÀSÀbÀSÀ&Ñ8IÓJÐØ)×,Ñ,ªQ°¨TÑ2×6Ñ6Ð7MÓNÐäŸ	™	Ð"3°tÑ";¸\ÐK\Ó]ÐØÐó    c                   óP  — e Zd ZU eed<   eed<   eed<   dZeed<   dZe	ed<   dZ
e	ed	<   ej                  Zej                  ed
<   dd„Zd„ Zd„ Zej$                  d„ «       Z	 	 	 	 ddej(                  deej(                     deej(                     de	de	deej(                     fd„Zy)ÚFlaxMarianAttentionÚconfigÚ	embed_dimÚ	num_headsç        ÚdropoutFÚcausalTÚbiasÚdtyper8   Nc           	      ó  — | j                   | j                  z  | _        | j                  | j                  z  | j                   k7  r&t        d| j                   › d| j                  › d�«      ‚t	        t
        j                  | j                   | j                  | j                  t        j
                  j                  j                  | j                  j                  «      ¬«      } |«        |«        |«       c| _        | _        | _         |«       | _        t        j$                  | j&                  ¬«      | _        | j*                  r>t-        t/        j0                  d| j                  j2                  fd¬«      d¬«      | _        y y )	Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).©Úuse_biasrJ   Úkernel_init©Úrater    Úbool©rJ   )rD   rE   Úhead_dimÚ
ValueErrorr   ÚnnÚDenserI   rJ   ÚjaxÚinitializersÚnormalrC   Úinit_stdÚq_projÚk_projÚv_projÚout_projÚDropoutrG   Údropout_layerrH   r   r+   ÚonesÚmax_position_embeddingsÚcausal_mask)ÚselfÚdenses     r3   ÚsetupzFlaxMarianAttention.setupü   s  € ØŸ™¨$¯.©.Ñ8ˆŒØ�=‰=˜4Ÿ>™>Ñ)¨T¯^©^Ò;ÜØMÈdÏnÉnÐM]Ø$ T§^¡^Ð$4°Bð8óð ô
 Ü�H‰HØ�N‰NØ—Y‘YØ—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô
ˆñ 16³¹»Á%Ã'Ð-ˆŒ�T”[ $¤+Ù›ˆŒäŸZ™Z¨T¯\©\Ô:ˆÔà�;Š;Ü/Ü—‘˜!˜TŸ[™[×@Ñ@ÐAÈÔPÐX^ô ˆDÕð r@   c                 óp   — |j                  |j                  d d | j                  | j                  fz   «      S ©Nr#   )ÚreshapeÚshaperE   rS   ©rd   Úhidden_statess     r3   Ú_split_headsz FlaxMarianAttention._split_heads  s5   € Ø×$Ñ$ ]×%8Ñ%8¸¸!Ð%<ÀÇÁÐPT×P]ÑP]Ð?^Ñ%^Ó_Ð_r@   c                 óZ   — |j                  |j                  d d | j                  fz   «      S rh   )ri   rj   rD   rk   s     r3   Ú_merge_headsz FlaxMarianAttention._merge_heads  s,   € Ø×$Ñ$ ]×%8Ñ%8¸¸!Ð%<ÀÇÁÐ?PÑ%PÓQÐQr@   c                 ó(  — | j                  dd«      }| j                  ddt        j                  |j                  |j
                  «      }| j                  ddt        j                  |j                  |j
                  «      }| j                  ddd„ «      }|rø|j                  j                  �^ }	}
}}|j                  }dt        |	«      z  |ddfz   }t        j                  |j                  ||«      }t        j                  |j                  ||«      }||_        ||_        |j                  d   }|j                  |z   |_        t        j                  t        j                  |
«      ||z   k  t        |	«      d||
fz   «      }t        ||«      }|||fS )	a\  
        This function takes projected key, value states from a single input token and concatenates the states to cached
        states from previous steps. This function is slightly adapted from the official Flax repository:
        https://github.com/google/flax/blob/491ce18759622506588784b4fca0e4bf05f8c8cd/flax/linen/attention.py#L252
        ÚcacheÚ
cached_keyÚcached_valueÚcache_indexc                  óL   — t        j                  dt         j                  ¬«      S )Nr   rR   )r+   r%   Úint32© r@   r3   ú<lambda>z;FlaxMarianAttention._concatenate_to_cache.<locals>.<lambda>'  s   € ÄCÇIÁIÈaÔWZ×W`ÑW`ÔDa€ r@   )r   r   r    )Úhas_variableÚvariabler+   Úzerosrj   rJ   ÚvalueÚlenr   Údynamic_update_sliceÚbroadcast_toÚarangeÚtupler
   )rd   Úkeyr|   ÚqueryÚattention_maskÚis_initializedrr   rs   rt   Ú
batch_dimsÚ
max_lengthrE   Údepth_per_headÚ	cur_indexÚindicesÚnum_updated_cache_vectorsÚpad_masks                    r3   Ú_concatenate_to_cachez)FlaxMarianAttention._concatenate_to_cache  sr  € ð ×*Ñ*¨7°LÓAˆØ—]‘] 7¨L¼#¿)¹)ÀSÇYÁYÐPS×PYÑPYÓZˆ
Ø—}‘} W¨n¼c¿i¹iÈÏÉÐV[×VaÑVaÓbˆØ—m‘m G¨]Ñ<aÓbˆáØAK×AQÑAQ×AWÑAWÑ>ˆZ˜ Y°à#×)Ñ)ˆIØœS ›_Ñ,°	¸1¸aÐ/@Ñ@ˆGÜ×*Ñ*¨:×+;Ñ+;¸SÀ'ÓJˆCÜ×,Ñ,¨\×-?Ñ-?ÀÈÓPˆEØ"ˆJÔØ!&ˆLÔØ(-¯©°A©Ð%Ø +× 1Ñ 1Ð4MÑ MˆKÔä×'Ñ'Ü—
‘
˜:Ó&¨Ð5NÑ)NÑNÜ�jÓ! QÐ(AÀ:Ð$NÑNóˆHô +¨8°^ÓDˆNØ�E˜>Ð)Ð)r@   rl   Úkey_value_statesr„   Ú
init_cacheÚdeterministicc                 óÊ  — |du}|j                   d   }| j                  |«      }|r#| j                  |«      }	| j                  |«      }
n"| j                  |«      }	| j                  |«      }
| j	                  |«      }| j	                  |	«      }	| j	                  |
«      }
| j
                  rÍ|j                   d   |	j                   d   }}| j                  dd«      r[| j                  d   d   }| j                  d   d   j                   d   }t        j                  | j                  dd|dfdd||f«      }n| j                  dd…dd…d|…d|…f   }t        j                  ||f|j                   dd z   «      }|�N| j
                  rBt        j                  t        j                  |d¬«      j                   «      }t        ||«      }n(| j
                  r}n|�t        j                  |d¬«      }| j
                  r,| j                  dd«      s|r| j                  |	|
||«      \  }	}
}|�°t        j                   |dkD  t        j"                  |j                   d	«      j%                  | j&                  «      t        j"                  |j                   t        j(                  | j&                  «      j*                  «      j%                  | j&                  «      «      }nd}d}|s | j,                  d	kD  r| j/                  d
«      }t1        ||	||| j,                  d|| j&                  d¬«	      }t        j2                  d||
«      }| j5                  |«      }| j7                  |«      }||fS )z#Input shape: Batch x Time x ChannelNr   r    rq   rr   rt   )éýÿÿÿéþÿÿÿ©ÚaxisrF   rG   T)rI   Údropout_rngÚdropout_rateÚbroadcast_dropoutr�   rJ   Ú	precisionz...hqk,...khd->...qhd)rj   r[   r\   r]   rm   rH   ry   Ú	variablesr   Údynamic_slicerc   r+   r   Úexpand_dimsr
   r�   ÚselectÚfullÚastyperJ   ÚfinfoÚminrG   Úmake_rngr   Úeinsumro   r^   )rd   rl   rŽ   r„   r�   r�   Úis_cross_attentionÚ
batch_sizeÚquery_statesÚ
key_statesÚvalue_statesÚquery_lengthÚ
key_lengthÚ
mask_shiftÚmax_decoder_lengthrc   Úattention_biasr–   Úattn_weightsÚattn_outputs                       r3   Ú__call__zFlaxMarianAttention.__call__<  s,  € ð .°TÐ9ÐØ"×(Ñ(¨Ñ+ˆ
ð —{‘{ =Ó1ˆáàŸ™Ð%5Ó6ˆJØŸ;™;Ð'7Ó8‰Lð Ÿ™ ]Ó3ˆJØŸ;™; }Ó5ˆLà×(Ñ(¨Ó6ˆØ×&Ñ& zÓ2ˆ
Ø×(Ñ(¨Ó6ˆð �;Š;Ø'3×'9Ñ'9¸!Ñ'<¸j×>NÑ>NÈqÑ>Q˜*ˆLØ× Ñ  ¨,Ô7Ø!Ÿ^™^¨GÑ4°]ÑC�
Ø%)§^¡^°GÑ%<¸\Ñ%J×%PÑ%PÐQRÑ%SÐ"Ü!×/Ñ/Ø×$Ñ$ q¨!¨Z¸Ð&;¸aÀÀLÐRdÐ=eó‘ð #×.Ñ.ªq²!°]°l°]ÀKÀZÀKÐ/OÑP�Ü×*Ñ*¨;¸¸È×HYÑHYÐZ[ÐZ\ÐH]Ñ8]Ó^ˆKð Ð%¨$¯+ª+Ü ×-Ñ-¬c¯o©o¸nÐS[Ô.\Ð^i×^oÑ^oÓpˆNÜ*¨>¸;ÓG‰NØ�[Š[Ø(‰NØÐ'Ü Ÿ_™_¨^À(ÔKˆNð �;Š;˜D×-Ñ-¨g°|ÔDÉ
Ø7;×7QÑ7QØ˜L¨,¸ó8Ñ4ˆJ˜ nð
 Ð%ä ŸZ™ZØ Ñ"Ü—‘˜×-Ñ-¨sÓ3×:Ñ:¸4¿:¹:ÓFÜ—‘˜×-Ñ-¬s¯y©y¸¿¹Ó/D×/HÑ/HÓI×PÑPÐQU×Q[ÑQ[Ó\ó‰Nð "ˆNàˆÙ §¡°Ò!3ØŸ-™-¨	Ó2ˆKä4ØØØØ#ØŸ™Ø"Ø'Ø—*‘*Øô

ˆô —j‘jÐ!8¸,ÈÓUˆØ×'Ñ'¨Ó4ˆØ—m‘m KÓ0ˆà˜LÐ(Ð(r@   ©r8   N)NNFT)Ú__name__Ú
__module__Ú__qualname__r!   Ú__annotations__ÚintrG   ÚfloatrH   rQ   rI   r+   Úfloat32rJ   rf   rm   ro   rU   Úcompactr�   Úndarrayr   r   r°   rw   r@   r3   rB   rB   ó   sß   … ØÓØƒNØƒNØ€GˆUÓØ€FˆDÓØ€Dˆ$ÓØ—{‘{€Eˆ3�9‰9Ó"óò4`òRð ‡Z�Zñ*ó ð*ðD 37Ø04Ø Ø"ñ[)à—{‘{ð[)ð # 3§;¡;Ñ/ð[)ð ! §¡Ñ-ð	[)ð
 ð[)ð ð[)ð 
ˆs�{‰{Ñ	ô[)r@   rB   c                   óº   — e Zd ZU eed<   ej                  Zej                  ed<   dd„Z	 	 ddej                  dej                  de
d	e
deej                     f
d
„Zy)ÚFlaxMarianEncoderLayerrC   rJ   r8   Nc                 óL  — | j                   j                  | _        t        | j                   | j                  | j                   j                  | j                   j
                  | j                  ¬«      | _        t        j                  | j                  d¬«      | _
        t        j                  | j                   j                  ¬«      | _        t        | j                   j                     | _        t        j                  | j                   j"                  ¬«      | _        t        j&                  | j                   j(                  | j                  t*        j                  j,                  j/                  | j                   j0                  «      ¬«      | _        t        j&                  | j                  | j                  t*        j                  j,                  j/                  | j                   j0                  «      ¬«      | _        t        j                  | j                  d¬«      | _        y )N©rC   rD   rE   rG   rJ   çñhãˆµøä>©rJ   ÚepsilonrO   ©rJ   rN   )rC   Úd_modelrD   rB   Úencoder_attention_headsÚattention_dropoutrJ   Ú	self_attnrU   Ú	LayerNormÚself_attn_layer_normr_   rG   r`   r   Úactivation_functionÚactivation_fnÚactivation_dropoutÚactivation_dropout_layerrV   Úencoder_ffn_dimrW   rX   rY   rZ   Úfc1Úfc2Úfinal_layer_norm©rd   s    r3   rf   zFlaxMarianEncoderLayer.setupŸ  sV  € ØŸ™×,Ñ,ˆŒÜ,Ø—;‘;Ø—n‘nØ—k‘k×9Ñ9Ø—K‘K×1Ñ1Ø—*‘*ô
ˆŒô %'§L¡L°t·z±zÈ5Ô$QˆÔ!ÜŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔÜ# D§K¡K×$CÑ$CÑDˆÔÜ(*¯
©
¸¿¹×8VÑ8VÔ(WˆÔ%Ü—8‘8Ø�K‰K×'Ñ'Ø—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô
ˆŒô
 —8‘8Ø�N‰N $§*¡*¼#¿&¹&×:MÑ:M×:TÑ:TÐUY×U`ÑU`×UiÑUiÓ:jô
ˆŒô !#§¡°4·:±:ÀuÔ MˆÕr@   rl   r„   Úoutput_attentionsr�   c                 ó|  — |}| j                  ||¬«      \  }}| j                  ||¬«      }||z   }| j                  |«      }|}| j                  | j	                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }||z   }| j                  |«      }|f}|r||fz  }|S )N)rl   r„   ©r�   )rÆ   r`   rÈ   rÊ   rÎ   rÌ   rÏ   rÐ   )rd   rl   r„   rÒ   r�   Úresidualr®   Úoutputss           r3   r°   zFlaxMarianEncoderLayer.__call__¶  sÝ   € ð !ˆØ&*§n¡nÀ=Ðao nÓ&pÑ#ˆ�|à×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆØ×1Ñ1°-Ó@ˆà ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆØ×5Ñ5°mÐS`Ð5ÓaˆØŸ™ Ó/ˆØ×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆØ×-Ñ-¨mÓ<ˆà Ð"ˆáØ˜�Ñ&ˆGàˆr@   r±   )TT)r²   r³   r´   r!   rµ   r+   r¸   rJ   rf   rº   rQ   r   r°   rw   r@   r3   r¼   r¼   ›  sn   … ØÓØ—{‘{€Eˆ3�9‰9Ó"óNð6 #'Ø"ñà—{‘{ðð Ÿ™ðð  ð	ð
 ðð 
ˆs�{‰{Ñ	ôr@   r¼   c            	       óv   — e Zd ZU eed<   ej                  Zej                  ed<   d„ Z	 	 	 	 d
de	de	de	de	fd„Z
y	)Ú FlaxMarianEncoderLayerCollectionrC   rJ   c           	      óú   — t        | j                  j                  «      D �cg c]-  }t        | j                  t	        |«      | j
                  ¬«      ‘Œ/ c}| _        | j                  j                  | _        y c c}w ©N)ÚnamerJ   )	r&   rC   Úencoder_layersr¼   ÚstrrJ   ÚlayersÚencoder_layerdropÚ	layerdrop©rd   Úis     r3   rf   z&FlaxMarianEncoderLayerCollection.setupÙ  óZ   € ô ˜4Ÿ;™;×5Ñ5Ó6ö
àô # 4§;¡;´S¸³VÀ4Ç:Á:ÖNò
ˆŒð Ÿ™×6Ñ6ˆ�ùò	
ó   ¢2A8r�   rÒ   Úoutput_hidden_statesÚreturn_dictc                 ó6  — |rdnd }|rdnd }| j                   D ]P  }	|r||fz   }t        j                  dd«      }
|s|
| j                  k  rd}n |	||||«      }|d   }|sŒH||d   fz   }ŒR |r||fz  }|||f}|st	        d„ |D «       «      S t        |||¬«      S )Nrw   r   r    )NNc              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­w©Nrw   ©Ú.0Úvs     r3   ú	<genexpr>z<FlaxMarianEncoderLayerCollection.__call__.<locals>.<genexpr>  ó   è ø€ Ò=˜q¨q©}œÑ=ùó   ‚Š©Úlast_hidden_staterl   Ú
attentions)rÞ   ÚrandomÚuniformrà   r�   r   )rd   rl   r„   r�   rÒ   rå   ræ   Úall_attentionsÚall_hidden_statesÚencoder_layerÚdropout_probabilityÚlayer_outputsrÖ   s                r3   r°   z)FlaxMarianEncoderLayerCollection.__call__à  sã   € ñ  1™°dˆÙ"6™B¸DÐà!Ÿ[™[ò 	FˆMÙ#Ø$5¸Ð8HÑ$HÐ!ä"(§.¡.°°AÓ"6ÐÙ Ð&9¸D¿N¹NÒ&JØ ,‘á -Ø!Ø"Ø%Ø!ó	!�ð *¨!Ñ,ˆMÚ Ø!/°=ÀÑ3CÐ2EÑ!E‘ð!	Fñ$  Ø -Ð!1Ñ1Ðà Ð"3°^ÐDˆáÜÑ= GÔ=Ó=Ð=ä"Ø+Ð;LÐYgô
ð 	
r@   N)TFFT)r²   r³   r´   r!   rµ   r+   r¸   rJ   rf   rQ   r°   rw   r@   r3   rØ   rØ   Õ  sZ   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò7ð #Ø"'Ø%*Ø ñ(
ð ð	(
ð
  ð(
ð #ð(
ð ô(
r@   rØ   c                   ó   — e Zd ZU eed<   ej                  Zej                  ed<   dd„Z	 	 	 	 	 ddej                  dej                  de
ej                     d	e
ej                     d
edededeej                     fd„Zy)ÚFlaxMarianDecoderLayerrC   rJ   r8   Nc                 óP  — | j                   j                  | _        t        | j                   | j                  | j                   j                  | j                   j
                  d| j                  ¬«      | _        t        j                  | j                   j                  ¬«      | _        t        | j                   j                     | _        t        j                  | j                   j                  ¬«      | _        t        j"                  | j                  d¬«      | _        t        | j                   | j                  | j                   j                  | j                   j
                  | j                  ¬«      | _        t        j"                  | j                  d¬«      | _        t        j*                  | j                   j,                  | j                  t.        j                  j0                  j3                  | j                   j4                  «      ¬«      | _        t        j*                  | j                  | j                  t.        j                  j0                  j3                  | j                   j4                  «      ¬«      | _        t        j"                  | j                  d¬«      | _        y )NT)rC   rD   rE   rG   rH   rJ   rO   r¿   rÀ   r¾   rÂ   )rC   rÃ   rD   rB   Údecoder_attention_headsrÅ   rJ   rÆ   rU   r_   rG   r`   r   rÉ   rÊ   rË   rÌ   rÇ   rÈ   Úencoder_attnÚencoder_attn_layer_normrV   Údecoder_ffn_dimrW   rX   rY   rZ   rÎ   rÏ   rÐ   rÑ   s    r3   rf   zFlaxMarianDecoderLayer.setup  s®  € ØŸ™×,Ñ,ˆŒÜ,Ø—;‘;Ø—n‘nØ—k‘k×9Ñ9Ø—K‘K×1Ñ1ØØ—*‘*ô
ˆŒô  ŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔÜ# D§K¡K×$CÑ$CÑDˆÔÜ(*¯
©
¸¿¹×8VÑ8VÔ(WˆÔ%ä$&§L¡L°t·z±zÈ5Ô$QˆÔ!Ü/Ø—;‘;Ø—n‘nØ—k‘k×9Ñ9Ø—K‘K×1Ñ1Ø—*‘*ô
ˆÔô (*§|¡|¸$¿*¹*ÈeÔ'TˆÔ$Ü—8‘8Ø�K‰K×'Ñ'Ø—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô
ˆŒô
 —8‘8Ø�N‰N $§*¡*¼#¿&¹&×:MÑ:M×:TÑ:TÐUY×U`ÑU`×UiÑUiÓ:jô
ˆŒô !#§¡°4·:±:ÀuÔ MˆÕr@   rl   r„   Úencoder_hidden_statesÚencoder_attention_maskr�   rÒ   r�   c                 ó  — |}| j                  |||¬«      \  }}	| j                  ||¬«      }||z   }| j                  |«      }d }
|�B|}| j                  |||¬«      \  }}
| j                  ||¬«      }||z   }| j	                  |«      }|}| j                  | j                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }||z   }| j                  |«      }|f}|r||	|
fz  }|S )N)rl   r„   r�   rÔ   )rl   rŽ   r„   )
rÆ   r`   rÈ   rþ   rÿ   rÊ   rÎ   rÌ   rÏ   rÐ   )rd   rl   r„   r  r  r�   rÒ   r�   rÕ   Úself_attn_weightsÚcross_attn_weightsrÖ   s               r3   r°   zFlaxMarianDecoderLayer.__call__1  sZ  € ð !ˆð ,0¯>©>Ø'¸ÐS]ð ,:ó ,
Ñ(ˆÐ(ð ×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆØ×1Ñ1°-Ó@ˆð "ÐØ Ð,Ø$ˆHà04×0AÑ0AØ+Ø!6Ø5ð 1Bó 1Ñ-ˆMÐ-ð
 !×.Ñ.¨}ÈMÐ.ÓZˆMØ$ }Ñ4ˆMØ ×8Ñ8¸ÓGˆMð !ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆØ×5Ñ5°mÐS`Ð5ÓaˆØŸ™ Ó/ˆØ×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆØ×-Ñ-¨mÓ<ˆà Ð"ˆáØÐ)Ð+=Ð>Ñ>ˆGàˆr@   r±   )NNFTT)r²   r³   r´   r!   rµ   r+   r¸   rJ   rf   rº   r   rQ   r   r°   rw   r@   r3   rû   rû     s¨   … ØÓØ—{‘{€Eˆ3�9‰9Ó"óNðJ 8<Ø8<Ø Ø"&Ø"ñ0à—{‘{ð0ð Ÿ™ð0ð  (¨¯©Ñ4ð	0ð
 !)¨¯©Ñ 5ð0ð ð0ð  ð0ð ð0ð 
ˆs�{‰{Ñ	ô0r@   rû   c                   ó¼   — e Zd ZU eed<   ej                  Zej                  ed<   d„ Z	 	 	 	 	 	 	 dde	ej                     de	ej                     deded	ed
edefd„Zy)Ú FlaxMarianDecoderLayerCollectionrC   rJ   c           	      óú   — t        | j                  j                  «      D �cg c]-  }t        | j                  t	        |«      | j
                  ¬«      ‘Œ/ c}| _        | j                  j                  | _        y c c}w rÚ   )	r&   rC   Údecoder_layersrû   rÝ   rJ   rÞ   Údecoder_layerdroprà   rá   s     r3   rf   z&FlaxMarianDecoderLayerCollection.setupi  rã   rä   Nr  r  r�   r�   rÒ   rå   ræ   c
           
      ój  — |rdnd }
|rdnd }|r|�dnd }| j                   D ]`  }|r|
|fz  }
t        j                  dd«      }|s|| j                  k  rd}n ||||||||¬«      }|d   }|sŒL||d   fz  }|€ŒX||d   fz  }Œb |r|
|fz  }
||
||g}|	st	        d„ |D «       «      S t        ||
||¬«      S )	Nrw   r   r    ©NNN)r„   r  r  r�   rÒ   r�   r#   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wré   rw   rê   s     r3   rí   z<FlaxMarianDecoderLayerCollection.__call__.<locals>.<genexpr>¡  rî   rï   ©rñ   rl   rò   Úcross_attentions)rÞ   ró   rô   rà   r�   r   )rd   rl   r„   r  r  r�   r�   rÒ   rå   ræ   rö   Úall_self_attnsÚall_cross_attentionsÚdecoder_layerrø   rù   rÖ   s                    r3   r°   z)FlaxMarianDecoderLayerCollection.__call__p  s  € ñ #7™B¸DÐÙ0™°dˆÙ&7Ð<QÐ<]™rÐdhÐà!Ÿ[™[ò 	@ˆMÙ#Ø! mÐ%5Ñ5Ð!ä"(§.¡.°°AÓ"6ÐÙ Ð&9¸D¿N¹NÒ&JØ 2‘á -Ø!Ø#1Ø*?Ø+AØ)Ø&7Ø"/ô!�ð *¨!Ñ,ˆMÚ Ø =°Ñ#3Ð"5Ñ5�à(Ñ4Ø(¨]¸1Ñ-=Ð,?Ñ?Ñ(ð/	@ñ4  Ø -Ð!1Ñ1Ðà Ð"3°^ÐEYÐZˆáÜÑ= GÔ=Ó=Ð=ä<Ø+Ø+Ø%Ø1ô	
ð 	
r@   )NNTFFFT)r²   r³   r´   r!   rµ   r+   r¸   rJ   rf   r   rº   rQ   r°   rw   r@   r3   r  r  e  s“   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò7ð 8<Ø8<Ø"Ø Ø"'Ø%*Ø ñ8
ð  (¨¯©Ñ4ð	8
ð
 !)¨¯©Ñ 5ð8
ð ð8
ð ð8
ð  ð8
ð #ð8
ð ô8
r@   r  c            	       ó”   — e Zd ZU eed<   ej                  ed<   ej                  Z	ej                  ed<   d„ Z
	 	 	 	 ddedededefd	„Zy
)ÚFlaxMarianEncoderrC   Úembed_tokensrJ   c                 ó¼  — t        j                  | j                  j                  ¬«      | _        | j                  j
                  }| j                  j                  | _        | j                  j                  rt        j                  |«      nd| _        t        | j                  j                  |«      | _        t        | j                  | j                  «      | _        y ©NrO   g      ð?)rU   r_   rC   rG   r`   rÃ   rb   Úmax_source_positionsÚscale_embeddingÚmathÚsqrtÚembed_scaler4   Úembed_positionsrØ   rJ   rÞ   ©rd   rD   s     r3   rf   zFlaxMarianEncoder.setup°  sŽ   € ÜŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔà—K‘K×'Ñ'ˆ	Ø$(§K¡K×$GÑ$GˆÔ!Ø37·;±;×3NÒ3Nœ4Ÿ9™9 YÔ/ÐTWˆÔä:¸4¿;¹;×;^Ñ;^Ð`iÓjˆÔÜ6°t·{±{ÀDÇJÁJÓOˆ�r@   rÒ   rå   ræ   r�   c                 ó¸  — |j                   }|j                  d|d   «      }| j                  |«      | j                  z  }	t	        j
                  | j                  |d¬«      }
|
j                  |	j                  «      }
|	|
z   }| j                  ||¬«      }| j                  ||||||¬«      }|s|S t        |j                  |j                  |j                  ¬«      S )Nr:   r   r”   rÔ   )r�   rÒ   rå   ræ   rð   )rj   ri   r  r  r+   Útaker  rŸ   rJ   r`   rÞ   r   rñ   rl   rò   )rd   r5   r„   Úposition_idsrÒ   rå   ræ   r�   Úinput_shapeÚinputs_embedsÚ	positionsrl   rÖ   s                r3   r°   zFlaxMarianEncoder.__call__º  sâ   € ð  —o‘oˆØ×%Ñ% b¨+°b©/Ó:ˆ	à×)Ñ)¨)Ó4°t×7GÑ7GÑGˆä—H‘H˜T×1Ñ1°<ÀaÔHˆ	à×$Ñ$ ]×%8Ñ%8Ó9ˆ	à%¨	Ñ1ˆØ×*Ñ*¨=ÈÐ*ÓVˆà—+‘+ØØØ'Ø/Ø!5Ø#ð ó 
ˆñ ØˆNä"Ø%×7Ñ7Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r@   N©FFTT)r²   r³   r´   r!   rµ   rU   ÚEmbedr+   r¸   rJ   rf   rQ   r°   rw   r@   r3   r  r  «  se   … ØÓØ—(‘(ÓØ—{‘{€Eˆ3�9‰9Ó"òPð #(Ø%*Ø Ø"ñ&
ð
  ð&
ð #ð&
ð ð&
ð ô&
r@   r  c                   óÚ   — e Zd ZU eed<   ej                  ed<   ej                  Z	ej                  ed<   d„ Z
	 	 	 	 	 	 	 ddeej                     deej                     ded	ed
ededefd„Zy)ÚFlaxMarianDecoderrC   r  rJ   c                 óä  — t        j                  | j                  j                  ¬«      | _        | j                  j
                  }| j                  j                  | _        | j                  j                  r)t        j                  | j                  j
                  «      nd| _        t        | j                  j                  |«      | _        t        | j                  | j                  «      | _        y r  )rU   r_   rC   rG   r`   rÃ   rb   Úmax_target_positionsr  r  r  r  r4   r  r  rJ   rÞ   r  s     r3   rf   zFlaxMarianDecoder.setupè  s˜   € ÜŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔà—K‘K×'Ñ'ˆ	Ø$(§K¡K×$GÑ$GˆÔ!Ø=A¿[¹[×=XÒ=Xœ4Ÿ9™9 T§[¡[×%8Ñ%8Ô9Ð^aˆÔä:¸4¿;¹;×;^Ñ;^Ð`iÓjˆÔÜ6°t·{±{ÀDÇJÁJÓOˆ�r@   Nr  r  r�   rÒ   rå   ræ   r�   c                 óÔ  — |j                   }|j                  d|d   «      }| j                  |«      | j                  z  }t	        j
                  | j                  |d¬«      }|j                  |j                  «      }||z   }| j                  ||
¬«      }| j                  |||||
||||	¬«	      }|	s|S t        |j                  |j                  |j                  |j                  ¬«      S )Nr:   r   r”   rÔ   )r�   r�   rÒ   rå   ræ   r  )rj   ri   r  r  r+   r   r  rŸ   rJ   r`   rÞ   r   rñ   rl   rò   r  )rd   r5   r„   r!  r  r  r�   rÒ   rå   ræ   r�   r"  r#  r$  rl   rÖ   s                   r3   r°   zFlaxMarianDecoder.__call__ò  sö   € ð  —o‘oˆØ×%Ñ% b¨+°b©/Ó:ˆ	à×)Ñ)¨)Ó4°t×7GÑ7GÑGˆô —H‘H˜T×1Ñ1°<ÀaÔHˆ	à×$Ñ$ ]×%8Ñ%8Ó9ˆ	à%¨	Ñ1ˆà×*Ñ*¨=ÈÐ*ÓVˆà—+‘+ØØØ!Ø"Ø'Ø!Ø/Ø!5Ø#ð ó 

ˆñ ØˆNä<Ø%×7Ñ7Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô	
ð 	
r@   )NNFFFTT)r²   r³   r´   r!   rµ   rU   r&  r+   r¸   rJ   rf   r   rº   rQ   r°   rw   r@   r3   r(  r(  ã  sž   … ØÓØ—(‘(ÓØ—{‘{€Eˆ3�9‰9Ó"òPð 8<Ø8<Ø Ø"'Ø%*Ø Ø"ñ/
ð
  (¨¯©Ñ4ð/
ð !)¨¯©Ñ 5ð/
ð ð/
ð  ð/
ð #ð/
ð ð/
ð ô/
r@   r(  c            	       ó‚   — e Zd ZU eed<   ej                  Zej                  ed<   d„ Zd„ Z	d„ Z
	 	 	 	 ddededed	efd
„Zy)ÚFlaxMarianModulerC   rJ   c                 óÈ  — t        j                  | j                  j                  | j                  j                  t
        j                   j                  j                  | j                  j                  «      ¬«      | _	        t        | j                  | j                  | j                  ¬«      | _        t        | j                  | j                  | j                  ¬«      | _        y )N)Úembedding_init)rJ   r  )rU   r&  rC   Ú
vocab_sizerÃ   rW   rX   rY   rZ   Úsharedr  rJ   Úencoderr(  ÚdecoderrÑ   s    r3   rf   zFlaxMarianModule.setup(  sŽ   € Ü—h‘hØ�K‰K×"Ñ"Ø�K‰K×ÑÜŸ6™6×.Ñ.×5Ñ5°d·k±k×6JÑ6JÓKô
ˆŒô )¨¯©¸D¿J¹JÐUY×U`ÑU`ÔaˆŒÜ(¨¯©¸D¿J¹JÐUY×U`ÑU`Ôaˆ�r@   c                 ó   — | j                   S ré   )r2  rÑ   s    r3   Ú_get_encoder_modulez$FlaxMarianModule._get_encoder_module2  ó   € Ø�|‰|Ðr@   c                 ó   — | j                   S ré   )r3  rÑ   s    r3   Ú_get_decoder_modulez$FlaxMarianModule._get_decoder_module5  r6  r@   rÒ   rå   ræ   r�   c                 ó*  — | j                  ||||||	|
¬«      }| j                  ||||d   ||||	|
¬«	      }|	s||z   S t        |j                  |j                  |j
                  |j                  |j                  |j                  |j
                  ¬«      S )N)r5   r„   r!  rÒ   rå   ræ   r�   r   )	r5   r„   r!  r  r  rÒ   rå   ræ   r�   )rñ   Údecoder_hidden_statesÚdecoder_attentionsr  Úencoder_last_hidden_stater  Úencoder_attentions)r2  r3  r   rñ   rl   rò   r  )rd   r5   r„   Údecoder_input_idsÚdecoder_attention_maskr!  Údecoder_position_idsrÒ   rå   ræ   r�   Úencoder_outputsÚdecoder_outputss                r3   r°   zFlaxMarianModule.__call__8  s½   € ð Ÿ,™,ØØ)Ø%Ø/Ø!5Ø#Ø'ð 'ó 
ˆð Ÿ,™,Ø'Ø1Ø-Ø"1°!Ñ"4Ø#1Ø/Ø!5Ø#Ø'ð 'ó 

ˆñ Ø" _Ñ4Ð4ä%Ø-×?Ñ?Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô
ð 	
r@   Nr%  )r²   r³   r´   r!   rµ   r+   r¸   rJ   rf   r5  r8  rQ   r°   rw   r@   r3   r-  r-  $  se   … ØÓØ—{‘{€Eˆ3�9‰9Ó"òbòòð #(Ø%*Ø Ø"ñ.
ð  ð.
ð #ð.
ð ð.
ð ô.
r@   r-  c                   ó–  ‡ — e Zd ZU eZdZeed<   dZe	j                  ed<   ddej                  dfded	ee   d
edej                  def
ˆ fd„Zd$dej&                  j(                  d	ededefd„Zd„ Z ee«       eee¬«      	 	 	 	 	 	 	 	 d%dej8                  deej8                     deej8                     dee   dee   dee   dededefd„«       «       Z ee «       ee!e¬«      	 	 	 	 	 	 	 	 	 	 d&deej8                     deej8                     deej8                     d edee   dee   dee   dededefd!„«       «       Z" e#e$«      	 	 	 	 	 	 	 	 	 	 	 d'dej8                  deej8                     d"eej8                     deej8                     deej8                     deej8                     dee   dee   dee   dededefd#„«       Z%ˆ xZ&S )(ÚFlaxMarianPreTrainedModelÚmodelÚbase_model_prefixNÚmodule_class)r    r    r   TrC   r"  ÚseedrJ   Ú_do_initc                 óZ   •—  | j                   d||dœ|¤Ž}t        ‰| �	  ||||||¬«       y )N©rC   rJ   )r"  rH  rJ   rI  rw   )rG  ÚsuperÚ__init__)	rd   rC   r"  rH  rJ   rI  ÚkwargsÚmoduleÚ	__class__s	           €r3   rM  z"FlaxMarianPreTrainedModel.__init__n  s=   ø€ ð #�×"Ñ"ÐH¨&¸ÑHÀÑHˆÜ‰Ñ˜ °[ÀtÐSXÐckÐÕlr@   ÚrngÚparamsr8   c           	      ó8  — t        j                  |d¬«      }|j                  d   j                  | j                  j
                  «      }t        j                  |«      }|}t        j                  |«      }|j                  \  }}	t        j                  t        j                  |	«      d d d …f   ||	f«      }
t        j                  t        j                  |	«      d d d …f   ||	f«      }t        j                  j                  |«      \  }}||dœ}| j                  j                  ||||||
|«      d   }|�dt        t!        |«      «      }t        t!        |«      «      }| j"                  D ]
  }||   ||<   Œ t        «       | _        t%        t'        |«      «      S |S )NÚi4rR   ).r:   )rR  rG   rR  )r+   r{   r;   r<   rC   Úeos_token_idÚ	ones_likerj   r   r€   rW   ró   ÚsplitrO  Úinitr   r	   Ú_missing_keysr   r   )rd   rQ  r"  rR  r5   r„   r>  r?  r¥   Úsequence_lengthr!  r@  Ú
params_rngr–   ÚrngsÚrandom_paramsÚmissing_keys                    r3   Úinit_weightsz&FlaxMarianPreTrainedModel.init_weightsz  s  € ä—I‘I˜k°Ô6ˆ	à—L‘L Ñ+×/Ñ/°·±×0HÑ0HÓIˆ	ÜŸ™ yÓ1ˆØ%ÐÜ!$§¡¨yÓ!9Ðà&/§o¡oÑ#ˆ
�OÜ×'Ñ'¬¯
©
°?Ó(CÀDÊ!ÀGÑ(LÈzÐ[jÐNkÓlˆÜ"×/Ñ/´·
±
¸?Ó0KÈDÒRSÈGÑ0TÐWaÐcrÐVsÓtÐä"%§*¡*×"2Ñ"2°3Ó"7Ñˆ
�KØ$°Ñ=ˆàŸ™×(Ñ(ØØØØØ"ØØ ó
ð ñˆð ÐÜ(¬°-Ó)@ÓAˆMÜ!¤(¨6Ó"2Ó3ˆFØ#×1Ñ1ò A�Ø&3°KÑ&@��{Ò#ðAä!$£ˆDÔÜœ.¨Ó0Ó1Ð1à Ð r@   c           	      óª  — t        j                  ||fd¬«      }t        j                  |«      }t        j                  t        j                  t        j
                  |«      j                  d   «      |j                  «      }d„ }| j                  j                  t        j                  j                  d«      ||||d   d|¬«      }t        |d   «      S )	a+  
        Args:
            batch_size (`int`):
                batch_size used for fast auto-regressive decoding. Defines the batch size of the initialized cache.
            max_length (`int`):
                maximum possible length for auto-regressive decoding. Defines the sequence length of the initialized
                cache.
            encoder_outputs (`Union[FlaxBaseModelOutput, tuple(tuple(jnp.ndarray)]`):
                `encoder_outputs` consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*:
                `attentions`). `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*)
                is a sequence of hidden-states at the output of the last layer of the encoder. Used in the
                cross-attention of the decoder.
        rT  rR   r:   c                 ó8   — | j                  «       } ||||fi |¤ŽS ré   ©r8  ©rO  r>  r?  r@  rN  Údecoder_modules         r3   Ú_decoder_forwardz>FlaxMarianPreTrainedModel.init_cache.<locals>._decoder_forward³  s(   € Ø#×7Ñ7Ó9ˆNÙ!Ð"3Ð5KÐMaÑlÐekÑlÐlr@   r   T)r>  r?  r@  r  r�   Úmethodrq   )r+   ra   rV  r   r€   Ú
atleast_2drj   rO  rX  rW   ró   r   r	   )	rd   r¥   r‡   rA  r>  r?  r@  re  Úinit_variabless	            r3   r�   z$FlaxMarianPreTrainedModel.init_cachež  sÁ   € ô  ŸH™H j°*Ð%=ÀTÔJÐÜ!$§¡Ð/@Ó!AÐÜ"×/Ñ/Ü�J‰J”s—~‘~Ð&7Ó8×>Ñ>¸rÑBÓCÐEV×E\ÑE\ó 
Ðò	mð Ÿ™×)Ñ)Ü�J‰J×Ñ˜qÓ!Ø/Ø#9Ø!5Ø"1°!Ñ"4ØØ#ð *ó 
ˆô ˜ wÑ/Ó0Ð0r@   ©Úoutput_typeÚconfig_classr5   r„   r!  rÒ   rå   ræ   Útrainr–   c
                 óT  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|€t	        j
                  |«      }|€A|j                  \  }
}t	        j                  t	        j                  |«      ddd…f   |
|f«      }i }|	�|	|d<   d„ }| j                  j                  d|xs | j                  it	        j                  |d¬«      t	        j                  |d¬«      t	        j                  |d¬«      |||| ||¬«
      S )a÷  
        Returns:

        Example:

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

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

        >>> text = "My friends are cool but they eat too many carbs."
        >>> inputs = tokenizer(text, max_length=64, return_tensors="jax")
        >>> encoder_outputs = model.encode(**inputs)
        ```NrG   c                 ó8   — | j                  «       } ||||fi |¤ŽS ré   )r5  )rO  r5   r„   r!  rN  Úencode_modules         r3   Ú_encoder_forwardz:FlaxMarianPreTrainedModel.encode.<locals>._encoder_forwardñ  s$   € Ø"×6Ñ6Ó8ˆMÙ  ¨N¸LÑSÈFÑSÐSr@   rR  rT  rR   )	r5   r„   r!  rÒ   rå   ræ   r�   r\  rf  )rC   rÒ   rå   ræ   r+   rV  rj   r   r€   rO  ÚapplyrR  r%   )rd   r5   r„   r!  rÒ   rå   ræ   rl  rR  r–   r¥   rZ  r\  rp  s                 r3   Úencodez FlaxMarianPreTrainedModel.encodeÂ  s.  € ð< 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆàÐ!Ü Ÿ]™]¨9Ó5ˆNØÐØ*3¯/©/Ñ'ˆJ˜Ü×+Ñ+¬C¯J©J°Ó,GÈÊaÈÑ,PÐS]Ð_nÐRoÓpˆLð ˆØÐ"Ø)ˆD�‰Oò	Tð �{‰{× Ñ Ø�vÒ, §¡Ð-Ü—i‘i 	°Ô6ÜŸ9™9 ^¸4Ô@ÜŸ™ <°tÔ<Ø/Ø!5Ø#Ø#˜)ØØ#ð !ó 
ð 	
r@   r  r?  r@  Úpast_key_valuesc                 ó¤  — |�|n| j                   j                  }|�|n| j                   j                  }|	�|	n| j                   j                  }	|d   }|€)|j                  dd \  }}t        j                  ||f«      }|j                  \  }}|€t        j                  ||f«      }|€?|�t        d«      ‚t        j                  t        j                  |«      ddd…f   ||f«      }i }|�||d<   d|xs | j                  i}|r	||d<   dg}nd}d	„ }| j                  j                  |t        j                  |d
¬«      t        j                  |d
¬«      t        j                  |d
¬«      |t        j                  |d
¬«      |||	|
 |||¬«      }|�|	r|\  }}t        |d   «      |d<   |S |�"|	s |\  }}|dd t        |d   «      fz   |dd z   }|S )a^  
        Returns:

        Example:

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

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

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

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

        >>> outputs = model.decode(decoder_input_ids, encoder_outputs)
        >>> last_decoder_hidden_states = outputs.last_hidden_state
        ```Nr   r#   úKMake sure to provide `decoder_position_ids` when passing `past_key_values`.rG   rR  rq   Fc                 ó8   — | j                  «       } ||||fi |¤ŽS ré   rb  rc  s         r3   re  z:FlaxMarianPreTrainedModel.decode.<locals>._decoder_forwardP  s0   € Ø#×7Ñ7Ó9ˆNÙ!Ø!Ø&Ø$ñð ñ	ð r@   rT  rR   ©r>  r?  r@  r  r  rÒ   rå   ræ   r�   r\  Úmutablerf  rs  r    )rC   rÒ   rå   ræ   rj   r+   ra   rT   r   r€   rR  rO  rq  r%   r	   )rd   r>  rA  r  r?  r@  rs  rÒ   rå   ræ   rl  rR  r–   r  r¥   rZ  r\  Úinputsrx  re  rÖ   Úpasts                         r3   Údecodez FlaxMarianPreTrainedModel.decode  s#  € ðN 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆà /°Ñ 2ÐØ!Ð)Ø*?×*EÑ*EÀbÀqÐ*IÑ'ˆJ˜Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"à&7×&=Ñ&=Ñ#ˆ
�OØ!Ð)Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"àÐ'ØÐ*Ü Ð!nÓoÐoä#&×#3Ñ#3Ü—
‘
˜?Ó+¨D²!¨GÑ4°zÀ?Ð6Só$Ð ð
 ˆØÐ"Ø)ˆD�‰Oà˜FÒ1 d§k¡kÐ2ˆñ
 Ø-ˆF�7‰OØ�i‰GàˆGò	ð —+‘+×#Ñ#ØÜ!Ÿi™iÐ(9ÀÔFÜ#&§9¡9Ð-CÈ4Ô#PÜ!$§¡Ð+?ÀtÔ!LØ"7Ü#&§9¡9Ð-CÈ4Ô#PØ/Ø!5Ø#Ø#˜)ØØØ#ð $ó 
ˆð" Ð&©;Ø#‰MˆG�TÜ)1°$°w±-Ó)@ˆGÐ%Ñ&ØˆNØÐ(±Ø#‰MˆG�TØ˜b˜q�k¤X¨d°7©mÓ%<Ð$>Ñ>ÀÈÈÀÑLˆGàˆr@   r>  c                 óò  — |�|n| j                   j                  }|�|n| j                   j                  }|	�|	n| j                   j                  }	|€t	        j
                  |«      }|€A|j                  \  }}t	        j                  t	        j                  |«      d d d …f   ||f«      }|€6t        || j                   j                  | j                   j                  ¬«      }|€t	        j
                  |«      }|€A|j                  \  }}t	        j                  t	        j                  |«      d d d …f   ||f«      }|�d|ini }| j                  j                  d|xs | j                  it	        j                  |d¬«      t	        j                  |d¬«      t	        j                  |d¬«      t	        j                  |d¬«      t	        j                  |d¬«      t	        j                  |d¬«      |||	|
 |¬«      S )N)r7   rG   rR  rT  rR   )r5   r„   r!  r>  r?  r@  rÒ   rå   ræ   r�   r\  )rC   rÒ   rå   ræ   r+   rV  rj   r   r€   r?   r6   r7   rO  rq  rR  r%   )rd   r5   r„   r>  r?  r!  r@  rÒ   rå   ræ   rl  rR  r–   r¥   rZ  r\  s                   r3   r°   z"FlaxMarianPreTrainedModel.__call__t  sØ  € ð  2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆð Ð!Ü Ÿ]™]¨9Ó5ˆNØÐØ*3¯/©/Ñ'ˆJ˜Ü×+Ñ+¬C¯J©J°Ó,GÈÊaÈÑ,PÐS]Ð_nÐRoÓpˆLð Ð$Ü 2Ø˜4Ÿ;™;×3Ñ3ÈDÏKÉK×LnÑLnô!Ðð "Ð)Ü%(§]¡]Ð3DÓ%EÐ"ØÐ'Ø*;×*AÑ*AÑ'ˆJ˜Ü#&×#3Ñ#3Ü—
‘
˜?Ó+¨D²!¨GÑ4°zÀ?Ð6Só$Ð ð
 ,7Ð+B�	˜;Ñ'Èˆà�{‰{× Ñ Ø�vÒ, §¡Ð-Ü—i‘i 	°Ô6ÜŸ9™9 ^¸4Ô@ÜŸ™ <°tÔ<Ü!Ÿi™iÐ(9ÀÔFÜ#&§9¡9Ð-CÈ4Ô#PÜ!$§¡Ð+?ÀtÔ!LØ/Ø!5Ø#Ø#˜)Øð !ó 
ð 	
r@   ré   )NNNNNFNN©
NNNNNNNFNN)NNNNNNNNFNN)'r²   r³   r´   r!   rk  rF  rÝ   rµ   rG  rU   ÚModuler+   r¸   r   r¶   rJ   rQ   rM  rW   ró   r   r   r_  r�   r   ÚMARIAN_ENCODE_INPUTS_DOCSTRINGr   r   rº   r   Údictrr  ÚMARIAN_DECODE_INPUTS_DOCSTRINGr   r{  r   ÚMARIAN_INPUTS_DOCSTRINGr°   Ú__classcell__)rP  s   @r3   rD  rD  i  s?  ø… Ø€LØ$Ð�sÓ$Ø"€L�"—)‘)Ó"ð
 #)ØØŸ;™;Øñ
màð
mð ˜3‘Zð
mð ð	
mð
 �y‰yð
mð õ
mñ"! §
¡
× 2Ñ 2ð "!Àð "!ÐPZð "!Ðfpó "!òH"1ñH Ð8Ó9ÙÐ+>È\ÔZð 15Ø.2Ø,0Ø/3Ø&*ØØØ#ñ<
à—;‘;ð<
ð ! §¡Ñ-ð<
ð ˜sŸ{™{Ñ+ð	<
ð
 $ D™>ð<
ð ' t™nð<
ð ˜d‘^ð<
ð ð<
ð ð<
ð ò<
ó [ó :ð<
ñ| Ð8Ó9ÙÐ+XÐgsÔtð
 9=Ø8<Ø6:Ø $Ø,0Ø/3Ø&*ØØØ#ñnð !)¨¯©Ñ 5ð	nð
 !)¨¯©Ñ 5ðnð ' s§{¡{Ñ3ðnð ðnð $ D™>ðnð ' t™nðnð ˜d‘^ðnð ðnð ðnð ònó uó :ðnñ` +Ð+BÓCð 15Ø37Ø8<Ø.2Ø6:Ø,0Ø/3Ø&*ØØØ#ñ9
à—;‘;ð9
ð ! §¡Ñ-ð9
ð $ C§K¡KÑ0ð	9
ð
 !)¨¯©Ñ 5ð9
ð ˜sŸ{™{Ñ+ð9
ð ' s§{¡{Ñ3ð9
ð $ D™>ð9
ð ' t™nð9
ð ˜d‘^ð9
ð ð9
ð ð9
ð ò9
ó Dô9
r@   rD  z`The bare Marian Model transformer outputting raw hidden-states without any specific head on top.c                   óR   — e Zd ZU eed<   ej                  Zej                  ed<   eZ	y)ÚFlaxMarianModelrC   rJ   N)
r²   r³   r´   r!   rµ   r+   r¸   rJ   r-  rG  rw   r@   r3   r…  r…  ±  s!   … ð
 ÓØ—{‘{€Eˆ3�9‰9Ó"Ø#�Lr@   r…  c            	       óê   — e Zd ZU eed<   ej                  Zej                  ed<   ej                  j                  j                  Zedej                  f   ed<   d„ Zd„ Zd„ Z	 	 	 	 dded	ed
edefd„Zy)ÚFlaxMarianMTModulerC   rJ   .Ú	bias_initc                 óÖ  — t        | j                  | j                  ¬«      | _        t	        j
                  | j                  j                  j                  d| j                  t        j                  j                  j                  | j                  j                  «      ¬«      | _        | j                  d| j                  d| j                  j                  j                  f«      | _        y )NrK  FrL   Úfinal_logits_biasr    )r-  rC   rJ   rE  rU   rV   r1  Únum_embeddingsrW   rX   rY   rZ   Úlm_headÚparamrˆ  rŠ  rÑ   s    r3   rf   zFlaxMarianMTModule.setupÃ  sœ   € Ü%¨T¯[©[ÀÇ
Á
ÔKˆŒ
Ü—x‘xØ�J‰J×Ñ×,Ñ,ØØ—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô	
ˆŒð "&§¡Ð,?ÀÇÁÐRSÐUY×U_ÑU_×UfÑUf×UuÑUuÐQvÓ!wˆÕr@   c                 ó.   — | j                   j                  S ré   )rE  r2  rÑ   s    r3   r5  z&FlaxMarianMTModule._get_encoder_moduleÍ  ó   € Ø�z‰z×!Ñ!Ð!r@   c                 ó.   — | j                   j                  S ré   )rE  r3  rÑ   s    r3   r8  z&FlaxMarianMTModule._get_decoder_moduleÐ  r�  r@   rÒ   rå   ræ   r�   c                 ó*  — | j                  |||||||||	|
¬«
      }|d   }| j                  j                  rJ| j                   j                  d   d   d   }| j                  j                  dd|j                  ii|«      }n| j	                  |«      }|| j                  j                  | j                  «      z  }|	s|f|dd  z   }|S t        ||j                  |j                  |j                  |j                  |j                  |j                   ¬«      S )	N)
r5   r„   r>  r?  r!  r@  rÒ   rå   ræ   r�   r   rR  r1  Ú	embeddingÚkernelr    )Úlogitsr:  r;  r  r<  r  r=  )rE  rC   Útie_word_embeddingsrš   rŒ  rq  ÚTrŠ  rŸ   rJ   r   r:  r;  r  r<  r  r=  )rd   r5   r„   r>  r?  r!  r@  rÒ   rå   ræ   r�   rÖ   rl   Úshared_embeddingÚ	lm_logitsÚoutputs                   r3   r°   zFlaxMarianMTModule.__call__Ó  s!  € ð —*‘*ØØ)Ø/Ø#9Ø%Ø!5Ø/Ø!5Ø#Ø'ð ó 
ˆð   ™
ˆà�;‰;×*Ò*Ø#Ÿz™z×3Ñ3°HÑ=¸hÑGÈÑTÐØŸ™×*Ñ*¨H°xÐAQ×ASÑASÐ6TÐ+UÐWdÓe‰IàŸ™ ]Ó3ˆIà�T×+Ñ+×2Ñ2°4·:±:Ó>Ñ>ˆ	áØ�\ G¨A¨B KÑ/ˆFØˆMä"ØØ")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô
ð 	
r@   Nr%  )r²   r³   r´   r!   rµ   r+   r¸   rJ   rW   rU   rX   r{   rˆ  r   rº   rf   r5  r8  rQ   r°   rw   r@   r3   r‡  r‡  ¾  s�   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø,/¯F©F×,?Ñ,?×,EÑ,E€Iˆx˜˜SŸ[™[Ð(Ñ)ÓEòxò"ò"ð #(Ø%*Ø Ø"ñ0
ð  ð0
ð #ð0
ð ð0
ð ô0
r@   r‡  zLThe MARIAN Model with a language modeling head. Can be used for translation.c                   óv  — e Zd ZU eZej                  Zej                  ed<    e	e
«       eee¬«      	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     dedee   d	ee   d
ee   dededefd„«       «       Zd„ Z	 	 	 ddeej,                     deej,                     fd„Zd„ Zy)ÚFlaxMarianMTModelrJ   ri  Nr  r?  r@  rs  rÒ   rå   ræ   rl  rR  r–   c                 ó(  ‡ — |�|n‰ j                   j                  }|�|n‰ j                   j                  }|	�|	n‰ j                   j                  }	|d   }|€)|j                  dd \  }}t        j                  ||f«      }|j                  \  }}|€t        j                  ||f«      }|€?|�t        d«      ‚t        j                  t        j                  |«      ddd…f   ||f«      }i }|�||d<   d|xs ‰ j                  i}|r	||d<   dg}nd}ˆ fd	„}‰ j                  j                  |t        j                  |d
¬«      t        j                  |d
¬«      t        j                  |d
¬«      |t        j                  |d
¬«      |||	|
 |||¬«      }|€|\  }}n|\  \  }}}|	r.t        ||j                  |j                   |j"                  ¬«      }n	|f|dd z   }|�|	rt%        d   «      |d<   |S |�|	s|dd t%        d   «      fz   |dd z   }|S )a?  
        Returns:

        Example:

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

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

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

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

        >>> outputs = model.decode(decoder_input_ids, encoder_outputs)
        >>> logits = outputs.logits
        ```Nr   r#   ru  rG   rR  rq   Fc                 ó~  •— | j                  «       } ||||fi |¤Ž}|d   }‰
j                  j                  rJ| j                  j                  d   d   d   }| j
                  j                  dd|j                  ii|«      }	n| j                  |«      }	|	| j                  j                  ‰
j                  «      z  }	|	|fS )Nr   rR  r1  r’  r“  )r8  rC   r•  rE  rš   rŒ  rq  r–  rŠ  rŸ   rJ   )rO  r>  r?  r@  rN  rd  rÖ   rl   r—  r˜  rd   s             €r3   re  z2FlaxMarianMTModel.decode.<locals>._decoder_forward[  sÅ   ø€ Ø#×7Ñ7Ó9ˆNÙ$Ø!Ø&Ø$ñð ñ	ˆGð $ A™JˆMà�{‰{×.Ò.Ø#)§<¡<×#9Ñ#9¸(Ñ#CÀHÑ#MÈkÑ#ZÐ Ø"ŸN™N×0Ñ0°(¸XÐGW×GYÑGYÐ<ZÐ1[Ð]jÓk‘	à"ŸN™N¨=Ó9�	Ø˜×1Ñ1×8Ñ8¸¿¹ÓDÑDˆIà˜gÐ%Ð%r@   rT  rR   rw  )r”  rl   rò   r  r    rs  )rC   rÒ   rå   ræ   rj   r+   ra   rT   r   r€   rR  rO  rq  r%   r   rl   rò   r  r	   )rd   r>  rA  r  r?  r@  rs  rÒ   rå   ræ   rl  rR  r–   r  r¥   rZ  r\  ry  rx  re  rÖ   r˜  rB  rz  s   `                       r3   r{  zFlaxMarianMTModel.decode  ss  ø€ ðN 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆà /°Ñ 2ÐØ!Ð)Ø*?×*EÑ*EÀbÀqÐ*IÑ'ˆJ˜Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"à&7×&=Ñ&=Ñ#ˆ
�OØ!Ð)Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"àÐ'ØÐ*Ü Ð!nÓoÐoä#&×#3Ñ#3Ü—
‘
˜?Ó+¨D²!¨GÑ4°zÀ?Ð6Só$Ð ð
 ˆØÐ"Ø)ˆD�‰Oà˜FÒ1 d§k¡kÐ2ˆñ
 Ø-ˆF�7‰OØ�i‰GàˆGô	&ð& —+‘+×#Ñ#ØÜ!Ÿi™iÐ(9ÀÔFÜ#&§9¡9Ð-CÈ4Ô#PÜ!$§¡Ð+?ÀtÔ!LØ"7Ü#&§9¡9Ð-CÈ4Ô#PØ/Ø!5Ø#Ø#˜)ØØØ#ð $ó 
ˆð  Ð"Ø)0Ñ&ˆI‘à18Ñ.Ñ(ˆY˜¨$áÜ;Ø Ø-×;Ñ;Ø*×5Ñ5Ø!0×!AÑ!Aô	‰Gð !�l _°Q°RÐ%8Ñ8ˆGð Ð&©;Ü)1°$°w±-Ó)@ˆGÐ%Ñ&ØˆNØÐ(±Ø˜b˜q�k¤X¨d°7©mÓ%<Ð$>Ñ>ÀÈÈÀÑLˆGàˆr@   c                 óŠ   — |j                   dd…dd…| j                  j                  f   j                  t	        d«      «      }|S )z?This function enforces the padding token never to be generated.Nz-inf)r;   rC   r6   r<   r·   )rd   r”  s     r3   Ú_adapt_logits_for_beam_searchz/FlaxMarianMTModel._adapt_logits_for_beam_search–  s5   € à—‘š1ša §¡×!9Ñ!9Ð9Ñ:×>Ñ>¼uÀV»}ÓMˆØˆr@   r„   c                 óN  — |j                   \  }}| j                  |||«      }	t        j                  ||fd¬«      }
|�-|j	                  d¬«      dz
  }t        j                  |
|d«      }
n4t        j                  t        j                  |d¬«      d d d …f   ||f«      }|	|||
|dœS )NrT  rR   r:   r”   r    )r   r   )rs  rA  r  r?  r@  )	rj   r�   r+   ra   Úcumsumr   r~   r   r€   )rd   r>  r‡   r„   r?  rA  rN  r¥   Ú
seq_lengthrs  Úextended_attention_maskr!  s               r3   Úprepare_inputs_for_generationz/FlaxMarianMTModel.prepare_inputs_for_generation›  s½   € ð "3×!8Ñ!8Ñˆ
�JàŸ/™/¨*°jÀ/ÓRˆô #&§(¡(¨J¸
Ð+CÈ4Ô"PÐØ!Ð-Ø1×8Ñ8¸bÐ8ÓAÀAÑEˆLÜ&)×&>Ñ&>Ð?VÐXnÐpvÓ&wÑ#ä×+Ñ+¬C¯J©J°zÈÔ,NÈtÒUVÈwÑ,WÐZdÐfpÐYqÓrˆLð  /Ø.Ø&4Ø&=Ø$0ñ
ð 	
r@   c                 óL   — |j                   |d<   |d   d d …dd …f   dz   |d<   |S )Nrs  r@  r:   r    )rs  )rd   Úmodel_outputsÚmodel_kwargss      r3   Úupdate_inputs_for_generationz.FlaxMarianMTModel.update_inputs_for_generationº  s?   € Ø*7×*GÑ*GˆÐ&Ñ'Ø/;Ð<RÑ/SÒTUÐWYÑWZÐTZÑ/[Ð^_Ñ/_ˆÐ+Ñ,ØÐr@   r}  r  )r²   r³   r´   r‡  rG  r+   r¸   rJ   rµ   r   r�  r   r   r!   r   rº   r€  rQ   r   r{  rŸ  rW   ÚArrayr¤  r¨  rw   r@   r3   r›  r›    s=  … ð &€LØ—{‘{€Eˆ3�9‰9Ó"áÐ8Ó9ÙÐ+PÐ_kÔlð
 9=Ø8<Ø6:Ø $Ø,0Ø/3Ø&*ØØØ#ñEð !)¨¯©Ñ 5ð	Eð
 !)¨¯©Ñ 5ðEð ' s§{¡{Ñ3ðEð ðEð $ D™>ðEð ' t™nðEð ˜d‘^ðEð ðEð ðEð òEó mó :ðEòNð /3Ø6:Øñ
ð ! §¡Ñ+ð	
ð
 !)¨¯©Ñ 3ó
ó>r@   r›  a¨  
    Returns:

    Example:

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

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

    >>> text = "My friends are cool but they eat too many carbs."
    >>> input_ids = tokenizer(text, max_length=64, return_tensors="jax").input_ids

    >>> sequences = model.generate(input_ids, max_length=64, num_beams=2).sequences

    >>> outputs = tokenizer.batch_decode(sequences, skip_special_tokens=True)
    >>> # should give *Meine Freunde sind cool, aber sie essen zu viele Kohlenhydrate.*
    ```
ri  )r…  r›  rD  )NÚ__doc__r  ró   Ú	functoolsr   Útypingr   r   r   Ú
flax.linenÚlinenrU   rW   Ú	jax.numpyÚnumpyr+   r$   Úflax.core.frozen_dictr   r   r	   r
   r   Úflax.linen.attentionr   Úflax.traverse_utilr   r   r   Ú
jax.randomr   Úmodeling_flax_outputsr   r   r   r   r   Úmodeling_flax_utilsr   r   r   r   r   Úutilsr   r   r   r   Úconfiguration_marianr!   Ú
get_loggerr²   ÚloggerÚ_CHECKPOINT_FOR_DOCÚ_CONFIG_FOR_DOCÚMARIAN_START_DOCSTRINGr‚  r  r�  r4   rº   r¶   r?   r~  rB   r¼   rØ   rû   r  r  r(  r-  rD  r…  r‡  r›  ÚFLAX_MARIAN_MT_DOCSTRINGÚ__all__rw   r@   r3   ú<module>rÀ     s  ðñ ã Û Ý ß ,Ñ ,å Û 
Ý Û ß >Ñ >ß 6Ý >ß ;Ý Ý ÷õ ÷õ ÷ uÓ tÝ .ð 
ˆ×	Ñ	˜HÓ	%€à2Ð Ø €ð Ð ðD0Ð ðf"Ð ð<,"Ð ò^ð	 #§+¡+ð 	¸Sð 	ÐZ]ð 	Ðbe×bmÑbmó 	ôd)˜"Ÿ)™)ô d)ôP6˜RŸY™Yô 6ôt3
 r§y¡yô 3
ônU˜RŸY™Yô UôrC
 r§y¡yô C
ôL5
˜Ÿ	™	ô 5
ôp>
˜Ÿ	™	ô >
ôBB
�r—y‘yô B
ôJE
Ð 3ô E
ñP
 ØfØóô$Ð/ó $ó	ð$ñ ˜_Ð.AÐCYÐ[jÔ kôE
˜Ÿ™ô E
ñP ØRÐTjóôtÐ1ó tóðtðnÐ ñ* ØØÐ6Ñ6ôñ !Ð!2Ð@SÐbqÕ rò P�r@   