Ë
    T^(h& ã                   óÎ  — 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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#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/m0Z0 ddl1m2Z2  e/jf                  e4«      Z5dZ6dZ7dZ8dZ9dZ:dZ;dejx                  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j~                  «      ZH G d-„ d.e(«      ZI e-d/e8«       G d0„ d1eI«      «       ZJ e)eJe6e#e7«        G d2„ d3ej~                  «      ZK e-d4e8«       G d5„ d6eI«      «       ZLd7ZM e+eLe9eMz   «        e*eLe"e7¬8«        G d9„ d:ej~                  «      ZN e-d;e8«       G d<„ d=eI«      «       ZO e)eOe6e%e7«        G d>„ d?ej~                  «      ZP e-d@e8«       G dA„ dBeI«      «       ZQ e)eQe6e$e7«       g dC¢ZRy)DzFlax MBart 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Ú'FlaxSeq2SeqQuestionAnsweringModelOutputÚ#FlaxSeq2SeqSequenceClassifierOutput)Ú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é   )ÚMBartConfigzfacebook/mbart-large-cc25r#   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 ([`MBartConfig`]): 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.
Ú	input_idsÚpad_token_idÚreturnc           	      óf  — t        j                  | «      j                  «       }|€t        d«      ‚t        j                  |dk(  || «      }t        j                  ||k7  dd«      j                  d¬«      dz
  j                  dd«      }t        j                  t        |«      D ��cg c]  \  }}|||f   ‘Œ c}}t         j                  ¬«      j                  «       }|j                  dd…dd…f   j                  |dd…dd…f   «      }|j                  dd…df   j                  |«      }|S c c}}w )	zÎ
    Shift input ids one token to the right, and wrap the last non pad token (the <LID> token) Note that MBart does not
    have a single `decoder_start_token_id` in contrast to other Bart-like models.
    Nz1self.model.config.pad_token_id has to be defined.iœÿÿÿr"   r   éÿÿÿÿ©Úaxis©Údtype)ÚjnpÚarrayÚcopyÚ
ValueErrorÚwhereÚsumÚreshapeÚ	enumerateÚint32ÚsqueezeÚatÚset)r$   r%   Úprev_output_tokensÚindex_of_eosÚiÚeos_idxÚdecoder_start_tokenss          úk/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/mbart/modeling_flax_mbart.pyÚshift_tokens_rightr?   Ü   s)  € ô
 Ÿ™ 9Ó-×2Ñ2Ó4ÐàÐÜÐLÓMÐMô Ÿ™Ð#5¸Ñ#=¸|ÈYÓWÐÜ—I‘IÐ0°LÑ@À!ÀQÓG×KÑKÐQSÐKÓTÐWXÑX×aÑaÐbdÐfgÓh€LÜŸ9™9Ü:CÀLÓ:Q×R©J¨A¨wÐ	˜A˜w˜JÓ	'ÓRÔZ]×ZcÑZcôç�gƒið ð ,×.Ñ.ªq°!±"¨uÑ5×9Ñ9Ð:LÊQÐPSÐQSÐPSÈVÑ:TÓUÐØ+×.Ñ.ªq°!¨tÑ4×8Ñ8Ð9MÓNÐàÐùó 	Ss   Â%D-
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)ÚFlaxMBartAttentionÚconfigÚ	embed_dimÚ	num_headsç        ÚdropoutFÚcausalTÚbiasr,   r&   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_biasr,   Úkernel_init©Úrater"   Úboolr+   )rC   rD   Úhead_dimr0   r   ÚnnÚDenserH   r,   ÚjaxÚinitializersÚnormalrB   Úinit_stdÚq_projÚk_projÚv_projÚout_projÚDropoutrF   Údropout_layerrG   r   r-   ÚonesÚmax_position_embeddingsÚcausal_mask)ÚselfÚdenses     r>   ÚsetupzFlaxMBartAttention.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Õð ó    c                 óp   — |j                  |j                  d d | j                  | j                  fz   «      S ©Né   )r3   ÚshaperD   rP   ©r`   Úhidden_statess     r>   Ú_split_headszFlaxMBartAttention._split_heads  s5   € Ø×$Ñ$ ]×%8Ñ%8¸¸!Ð%<ÀÇÁÐPT×P]ÑP]Ð?^Ñ%^Ó_Ð_rc   c                 óZ   — |j                  |j                  d d | j                  fz   «      S re   )r3   rg   rC   rh   s     r>   Ú_merge_headszFlaxMBartAttention._merge_heads  s,   € Ø×$Ñ$ ]×%8Ñ%8¸¸!Ð%<ÀÇÁÐ?PÑ%PÓQÐQrc   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   r+   )r-   r.   r5   © rc   r>   ú<lambda>z:FlaxMBartAttention._concatenate_to_cache.<locals>.<lambda>(  s   € ÄCÇIÁIÈaÔWZ×W`ÑW`ÔDa€ rc   )r   r   r"   )Úhas_variableÚvariabler-   Úzerosrg   r,   ÚvalueÚlenr   Údynamic_update_sliceÚbroadcast_toÚarangeÚtupler
   )r`   Úkeyrx   ÚqueryÚattention_maskÚis_initializedro   rp   rq   Ú
batch_dimsÚ
max_lengthrD   Údepth_per_headÚ	cur_indexÚindicesÚnum_updated_cache_vectorsÚpad_masks                    r>   Ú_concatenate_to_cachez(FlaxMBartAttention._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˜>Ð)Ð)rc   ri   Ú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"   rn   ro   rq   )éýÿÿÿéþÿÿÿr)   rE   rF   T)rH   Údropout_rngÚdropout_rateÚbroadcast_dropoutrŒ   r,   Ú	precisionz...hqk,...khd->...qhd)rg   rW   rX   rY   rj   rG   ru   Ú	variablesr   Údynamic_slicer_   r-   r{   Úexpand_dimsr
   r‰   ÚselectÚfullÚastyper,   ÚfinfoÚminrF   Úmake_rngr   Úeinsumrl   rZ   )r`   ri   rŠ   r€   r‹   rŒ   Úis_cross_attentionÚ
batch_sizeÚquery_statesÚ
key_statesÚvalue_statesÚquery_lengthÚ
key_lengthÚ
mask_shiftÚmax_decoder_lengthr_   Úattention_biasr�   Úattn_weightsÚattn_outputs                       r>   Ú__call__zFlaxMBartAttention.__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Ð(Ð(rc   ©r&   N)NNFT)Ú__name__Ú
__module__Ú__qualname__r#   Ú__annotations__ÚintrF   ÚfloatrG   rO   rH   r-   Úfloat32r,   rb   rj   rl   rQ   Úcompactr‰   Úndarrayr   r   rª   rs   rc   r>   rA   rA   ô   sß   … ØÓØƒNØƒNØ€GˆUÓØ€FˆDÓØ€Dˆ$ÓØ—{‘{€Eˆ3�9‰9Ó"óò4`òRð ‡Z�Zñ*ó ð*ðD 37Ø04Ø Ø"ñ[)à—{‘{ð[)ð # 3§;¡;Ñ/ð[)ð ! §¡Ñ-ð	[)ð
 ð[)ð ð[)ð 
ˆs�{‰{Ñ	ô[)rc   rA   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)ÚFlaxMBartEncoderLayerrB   r,   r&   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©rB   rC   rD   rF   r,   çñhãˆµøä>©r,   ÚepsilonrM   ©r,   rL   )rB   Úd_modelrC   rA   Úencoder_attention_headsÚattention_dropoutr,   Ú	self_attnrQ   Ú	LayerNormÚself_attn_layer_normr[   rF   r\   r   Úactivation_functionÚactivation_fnÚactivation_dropoutÚactivation_dropout_layerrR   Úencoder_ffn_dimrS   rT   rU   rV   Úfc1Úfc2Úfinal_layer_norm©r`   s    r>   rb   zFlaxMBartEncoderLayer.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ˆÕrc   ri   r€   Úoutput_attentionsrŒ   c                 ó|  — |}| j                  |«      }| j                  ||¬«      \  }}| j                  ||¬«      }||z   }|}| j                  |«      }| j	                  | j                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }||z   }|f}|r||fz  }|S )N)ri   r€   ©rŒ   )rÂ   rÀ   r\   rÊ   rÄ   rÈ   rÆ   rÉ   )r`   ri   r€   rÌ   rŒ   Úresidualr¨   Úoutputss           r>   rª   zFlaxMBartEncoderLayer.__call__¶  sÝ   € ð !ˆØ×1Ñ1°-Ó@ˆØ&*§n¡nÀ=Ðao nÓ&pÑ#ˆ�|Ø×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆà ˆØ×-Ñ-¨mÓ<ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆØ×5Ñ5°mÐS`Ð5ÓaˆØŸ™ Ó/ˆØ×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆà Ð"ˆáØ˜�Ñ&ˆGàˆrc   r«   )TT)r¬   r­   r®   r#   r¯   r-   r²   r,   rb   r´   rO   r   rª   rs   rc   r>   r¶   r¶   ›  sn   … ØÓØ—{‘{€Eˆ3�9‰9Ó"óNð6 #'Ø"ñà—{‘{ðð Ÿ™ðð  ð	ð
 ðð 
ˆs�{‰{Ñ	ôrc   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	)ÚFlaxMBartEncoderLayerCollectionrB   r,   c           	      óú   — t        | j                  j                  «      D �cg c]-  }t        | j                  t	        |«      | j
                  ¬«      ‘Œ/ c}| _        | j                  j                  | _        y c c}w ©N)Únamer,   )	ÚrangerB   Úencoder_layersr¶   Ústrr,   ÚlayersÚencoder_layerdropÚ	layerdrop©r`   r;   s     r>   rb   z%FlaxMBartEncoderLayerCollection.setupØ  óZ   € ô ˜4Ÿ;™;×5Ñ5Ó6ö
àô " $§+¡+´C¸³FÀ$Ç*Á*ÖMò
ˆŒð Ÿ™×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 )Nrs   r   r"   )NNc              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­w©Nrs   ©Ú.0Úvs     r>   ú	<genexpr>z;FlaxMBartEncoderLayerCollection.__call__.<locals>.<genexpr>  ó   è ø€ Ò=˜q¨q©}œÑ=ùó   ‚Š©Úlast_hidden_stateri   Ú
attentions)rÙ   ÚrandomÚuniformrÛ   r}   r   )r`   ri   r€   rŒ   rÌ   rß   rà   Úall_attentionsÚall_hidden_statesÚencoder_layerÚdropout_probabilityÚlayer_outputsrÐ   s                r>   rª   z(FlaxMBartEncoderLayerCollection.__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ô
ð 	
rc   N)TFFT)r¬   r­   r®   r#   r¯   r-   r²   r,   rb   rO   rª   rs   rc   r>   rÒ   rÒ   Ô  sZ   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò7ð #Ø"'Ø%*Ø ñ(
ð ð	(
ð
  ð(
ð #ð(
ð ô(
rc   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)ÚFlaxMBartDecoderLayerrB   r,   r&   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)rB   rC   rD   rF   rG   r,   rM   r¹   rº   r¸   r¼   )rB   r½   rC   rA   Údecoder_attention_headsr¿   r,   rÀ   rQ   r[   rF   r\   r   rÃ   rÄ   rÅ   rÆ   rÁ   rÂ   Úencoder_attnÚencoder_attn_layer_normrR   Údecoder_ffn_dimrS   rT   rU   rV   rÈ   rÉ   rÊ   rË   s    r>   rb   zFlaxMBartDecoderLayer.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ˆÕrc   ri   r€   Úencoder_hidden_statesÚencoder_attention_maskr‹   rÌ   rŒ   c                 ó  — |}| j                  |«      }| j                  |||¬«      \  }}	| j                  ||¬«      }||z   }d }
|�B|}| j                  |«      }| j	                  |||¬«      \  }}
| j                  ||¬«      }||z   }|}| j                  |«      }| j                  | j                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }||z   }|f}|r||	|
fz  }|S )N)ri   r€   r‹   rÎ   )ri   rŠ   r€   )
rÂ   rÀ   r\   rù   rø   rÊ   rÄ   rÈ   rÆ   rÉ   )r`   ri   r€   rû   rü   r‹   rÌ   rŒ   rÏ   Úself_attn_weightsÚcross_attn_weightsrÐ   s               r>   rª   zFlaxMBartDecoderLayer.__call__/  sZ  € ð !ˆØ×1Ñ1°-Ó@ˆð ,0¯>©>Ø'¸ÐS]ð ,:ó ,
Ñ(ˆÐ(ð ×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆð "ÐØ Ð,Ø$ˆHà ×8Ñ8¸ÓGˆMØ04×0AÑ0AØ+Ø!6Ø5ð 1Bó 1Ñ-ˆMÐ-ð
 !×.Ñ.¨}ÈMÐ.ÓZˆMØ$ }Ñ4ˆMð !ˆØ×-Ñ-¨mÓ<ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆØ×5Ñ5°mÐS`Ð5ÓaˆØŸ™ Ó/ˆØ×*Ñ*¨=ÈÐ*ÓVˆØ  =Ñ0ˆà Ð"ˆáØÐ)Ð+=Ð>Ñ>ˆGàˆrc   r«   )NNFTT)r¬   r­   r®   r#   r¯   r-   r²   r,   rb   r´   r   rO   r   rª   rs   rc   r>   rõ   rõ   
  s¨   … ØÓØ—{‘{€Eˆ3�9‰9Ó"óNðJ 8<Ø8<Ø Ø"&Ø"ñ0à—{‘{ð0ð Ÿ™ð0ð  (¨¯©Ñ4ð	0ð
 !)¨¯©Ñ 5ð0ð ð0ð  ð0ð ð0ð 
ˆs�{‰{Ñ	ô0rc   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)ÚFlaxMBartDecoderLayerCollectionrB   r,   c           	      óú   — t        | j                  j                  «      D �cg c]-  }t        | j                  t	        |«      | j
                  ¬«      ‘Œ/ c}| _        | j                  j                  | _        y c c}w rÔ   )	rÖ   rB   Údecoder_layersrõ   rØ   r,   rÙ   Údecoder_layerdroprÛ   rÜ   s     r>   rb   z%FlaxMBartDecoderLayerCollection.setupg  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 )	Nrs   r   r"   ©NNN)r€   rû   rü   r‹   rÌ   rŒ   rf   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wrã   rs   rä   s     r>   rç   z;FlaxMBartDecoderLayerCollection.__call__.<locals>.<genexpr>Ÿ  rè   ré   ©rë   ri   rì   Úcross_attentions)rÙ   rí   rî   rÛ   r}   r   )r`   ri   r€   rû   rü   rŒ   r‹   rÌ   rß   rà   rð   Úall_self_attnsÚall_cross_attentionsÚdecoder_layerrò   ró   rÐ   s                    r>   rª   z(FlaxMBartDecoderLayerCollection.__call__n  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ô	
ð 	
rc   )NNTFFFT)r¬   r­   r®   r#   r¯   r-   r²   r,   rb   r   r´   rO   rª   rs   rc   r>   r  r  c  s“   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò7ð 8<Ø8<Ø"Ø Ø"'Ø%*Ø ñ8
ð  (¨¯©Ñ4ð	8
ð
 !)¨¯©Ñ 5ð8
ð ð8
ð ð8
ð  ð8
ð #ð8
ð ô8
rc   r  c                   óš   — e Zd ZU dZeed<   eed<   eed<   eed<   ej                  Z
ej                  ed<   d„ Zdej                  d	efd
„Zy)ÚFlaxMBartClassificationHeadz-Head for sentence-level classification tasks.rB   Ú	inner_dimÚnum_classesÚpooler_dropoutr,   c                 óþ  — t        j                  | j                  | j                  t        j                   j
                  j                  | j                  j                  «      ¬«      | _	        t        j                  | j                  ¬«      | _        t        j                  | j                  | j                  t        j                   j
                  j                  | j                  j                  «      ¬«      | _        y )Nr¼   rM   )rQ   rR   r  r,   rS   rT   rU   rB   rV   ra   r[   r  rF   r  rZ   rË   s    r>   rb   z!FlaxMBartClassificationHead.setup³  s�   € Ü—X‘XØ�N‰N $§*¡*¼#¿&¹&×:MÑ:M×:TÑ:TÐUY×U`ÑU`×UiÑUiÓ:jô
ˆŒ
ô —z‘z t×':Ñ':Ô;ˆŒÜŸ™Ø×ÑØ—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô
ˆ�rc   ri   rŒ   c                 óÀ   — | j                  ||¬«      }| j                  |«      }t        j                  |«      }| j                  ||¬«      }| j	                  |«      }|S )NrÎ   )rF   ra   r-   ÚtanhrZ   )r`   ri   rŒ   s      r>   rª   z$FlaxMBartClassificationHead.__call__¾  sV   € ØŸ™ ]À-˜ÓPˆØŸ
™
 =Ó1ˆÜŸ™ Ó/ˆØŸ™ ]À-˜ÓPˆØŸ™ mÓ4ˆØÐrc   N)r¬   r­   r®   Ú__doc__r#   r¯   r°   r±   r-   r²   r,   rb   r´   rO   rª   rs   rc   r>   r  r  ª  sJ   … Ù7àÓØƒNØÓØÓØ—{‘{€Eˆ3�9‰9Ó"ò	
ð c§k¡kð À$ô rc   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
)ÚFlaxMBartEncoderrB   Úembed_tokensr,   c                 ó@  — t        j                  | j                  j                  ¬«      | _        | j                  j
                  }| j                  j                  | _        | j                  j                  | _	        | j                  j                  rt        j                  |«      nd| _        d| _        t        j                  | j                  j                  | j                  z   |t         j                   j"                  j%                  | j                  j&                  «      ¬«      | _        t+        | j                  | j,                  «      | _        t        j0                  | j,                  d¬«      | _        t        j0                  | j,                  d¬«      | _        y ©NrM   g      ð?rf   )Úembedding_initr¹   rº   )rQ   r[   rB   rF   r\   r½   r%   Úpadding_idxr^   Úmax_source_positionsÚscale_embeddingÚmathÚsqrtÚembed_scaleÚoffsetÚEmbedrS   rT   rU   rV   Úembed_positionsrÒ   r,   rÙ   rÁ   Úlayernorm_embeddingÚ
layer_norm©r`   rC   s     r>   rb   zFlaxMBartEncoder.setupÌ  s
  € ÜŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔà—K‘K×'Ñ'ˆ	ØŸ;™;×3Ñ3ˆÔØ$(§K¡K×$GÑ$GˆÔ!Ø37·;±;×3NÒ3Nœ4Ÿ9™9 YÔ/ÐTWˆÔð ˆŒÜ!Ÿx™xØ�K‰K×/Ñ/°$·+±+Ñ=ØÜŸ6™6×.Ñ.×5Ñ5°d·k±k×6JÑ6JÓKô 
ˆÔô
 6°d·k±kÀ4Ç:Á:ÓNˆŒÜ#%§<¡<°d·j±jÈ%Ô#PˆÔ ÜŸ,™,¨T¯Z©ZÀÔGˆ�rc   rÌ   rß   rà   rŒ   c                 ó  — |j                   }|j                  d|d   «      }| j                  |«      | j                  z  }	| j	                  || j
                  z   «      }
|	|
z   }| j                  |«      }| j                  ||¬«      }| j                  ||||||¬«      }|d   }| j                  |«      }d }|r|d   }|d d |fz   }|s#||f|r|dd  n|dd  z   }t        d„ |D «       «      S t        |||j                  ¬«      S )	Nr(   rÎ   )rŒ   rÌ   rß   rà   r   r"   rf   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wrã   rs   rä   s     r>   rç   z,FlaxMBartEncoder.__call__.<locals>.<genexpr>	  rè   ré   rê   )rg   r3   r  r!  r$  r"  r%  r\   rÙ   r&  r}   r   rì   )r`   r$   r€   Úposition_idsrÌ   rß   rà   rŒ   Úinput_shapeÚinputs_embedsÚ	embed_posri   rÐ   Úlast_hidden_statess                 r>   rª   zFlaxMBartEncoder.__call__à  sC  € ð  —o‘oˆØ×%Ñ% b¨+°b©/Ó:ˆ	à×)Ñ)¨)Ó4°t×7GÑ7GÑGˆà×(Ñ(¨¸¿¹Ñ)CÓDˆ	à%¨	Ñ1ˆØ×0Ñ0°Ó?ˆØ×*Ñ*¨=ÈÐ*ÓVˆà—+‘+ØØØ'Ø/Ø!5Ø#ð ó 
ˆð % Q™ZÐØ!Ÿ_™_Ð-?Ó@Ðð ˆÙØ# A™JˆMØ)¨#¨2Ð.Ð2DÐ1FÑFˆMáØ)¨=Ð9ÑL`¸WÀQÀR¹[ÐfmÐnoÐnpÐfqÑrˆGÜÑ= GÔ=Ó=Ð=ä"Ø0Ø'Ø×)Ñ)ô
ð 	
rc   N©FFTT)r¬   r­   r®   r#   r¯   rQ   r#  r-   r²   r,   rb   rO   rª   rs   rc   r>   r  r  Ç  se   … ØÓØ—(‘(ÓØ—{‘{€Eˆ3�9‰9Ó"òHð2 #(Ø%*Ø Ø"ñ/
ð
  ð/
ð #ð/
ð ð/
ð ô/
rc   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)ÚFlaxMBartDecoderrB   r  r,   c                 óh  — t        j                  | j                  j                  ¬«      | _        | j                  j
                  }| j                  j                  | _        | j                  j                  | _	        | j                  j                  r)t        j                  | j                  j
                  «      nd| _        d| _        t        j                  | j                  j                  | j                  z   |t         j                   j"                  j%                  | j                  j&                  «      ¬«      | _        t+        | j                  | j,                  «      | _        t        j0                  | j,                  d¬«      | _        t        j0                  | j,                  d¬«      | _        y r  )rQ   r[   rB   rF   r\   r½   r%   r  r^   Úmax_target_positionsr  r  r   r!  r"  r#  rS   rT   rU   rV   r$  r  r,   rÙ   rÁ   r%  r&  r'  s     r>   rb   zFlaxMBartDecoder.setup  s  € ÜŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔà—K‘K×'Ñ'ˆ	ØŸ;™;×3Ñ3ˆÔØ$(§K¡K×$GÑ$GˆÔ!Ø=A¿[¹[×=XÒ=Xœ4Ÿ9™9 T§[¡[×%8Ñ%8Ô9Ð^aˆÔð ˆŒÜ!Ÿx™xØ�K‰K×/Ñ/°$·+±+Ñ=ØÜŸ6™6×.Ñ.×5Ñ5°d·k±k×6JÑ6JÓKô 
ˆÔô 6°d·k±kÀ4Ç:Á:ÓNˆŒÜ#%§<¡<°d·j±jÈ%Ô#PˆÔ ÜŸ,™,¨T¯Z©ZÀÔGˆ�rc   Nrû   rü   r‹   rÌ   rß   rà   rŒ   c                 ó"  — |j                   }|j                  d|d   «      }| j                  |«      | j                  z  }| j	                  || j
                  z   «      }||z   }| j                  |«      }| j                  ||
¬«      }| j                  |||||
||||	¬«	      }|d   }| j                  |«      }d }|r|d   }|d d |fz   }|	s#||f|r|dd  n|dd  z   }t        d„ |D «       «      S t        |||j                  |j                  ¬«      S )	Nr(   rÎ   )rŒ   r‹   rÌ   rß   rà   r   r"   rf   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wrã   rs   rä   s     r>   rç   z,FlaxMBartDecoder.__call__.<locals>.<genexpr>]  rè   ré   r  )rg   r3   r  r!  r$  r"  r%  r\   rÙ   r&  r}   r   rì   r	  )r`   r$   r€   r*  rû   rü   r‹   rÌ   rß   rà   rŒ   r+  r,  Ú	positionsri   rÐ   r.  s                    r>   rª   zFlaxMBartDecoder.__call__,  sW  € ð  —o‘oˆØ×%Ñ% b¨+°b©/Ó:ˆ	à×)Ñ)¨)Ó4°t×7GÑ7GÑGˆð ×(Ñ(¨¸¿¹Ñ)CÓDˆ	à%¨	Ñ1ˆØ×0Ñ0°Ó?ˆà×*Ñ*¨=ÈÐ*ÓVˆà—+‘+ØØØ!Ø"Ø'Ø!Ø/Ø!5Ø#ð ó 

ˆð % Q™ZÐØ!Ÿ_™_Ð-?Ó@Ðð ˆÙØ# A™JˆMØ)¨#¨2Ð.Ð2DÐ1FÑFˆMáØ)¨=Ð9ÑL`¸WÀQÀR¹[ÐfmÐnoÐnpÐfqÑrˆGÜÑ= GÔ=Ó=Ð=ä<Ø0Ø'Ø×)Ñ)Ø$×5Ñ5ô	
ð 	
rc   )NNFFFTT)r¬   r­   r®   r#   r¯   rQ   r#  r-   r²   r,   rb   r   r´   rO   rª   rs   rc   r>   r1  r1    sž   … ØÓØ—(‘(ÓØ—{‘{€Eˆ3�9‰9Ó"òHð4 8<Ø8<Ø Ø"'Ø%*Ø Ø"ñ8
ð
  (¨¯©Ñ4ð8
ð !)¨¯©Ñ 5ð8
ð ð8
ð  ð8
ð #ð8
ð ð8
ð ô8
rc   r1  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)ÚFlaxMBartModulerB   r,   c                 óÞ  — t        j                  | j                  j                  | j                  j                  t
        j                   j                  j                  | j                  j                  «      | j                  ¬«      | _
        t        | j                  | j                  | j                  ¬«      | _        t        | j                  | j                  | j                  ¬«      | _        y )N)r  r,   )r,   r  )rQ   r#  rB   Ú
vocab_sizer½   rS   rT   rU   rV   r,   Úsharedr  Úencoderr1  ÚdecoderrË   s    r>   rb   zFlaxMBartModule.setupl  s•   € Ü—h‘hØ�K‰K×"Ñ"Ø�K‰K×ÑÜŸ6™6×.Ñ.×5Ñ5°d·k±k×6JÑ6JÓKØ—*‘*ô	
ˆŒô (¨¯©¸4¿:¹:ÐTX×T_ÑT_Ô`ˆŒÜ'¨¯©¸4¿:¹:ÐTX×T_ÑT_Ô`ˆ�rc   c                 ó   — | j                   S rã   )r<  rË   s    r>   Ú_get_encoder_modulez#FlaxMBartModule._get_encoder_modulew  ó   € Ø�|‰|Ðrc   c                 ó   — | j                   S rã   )r=  rË   s    r>   Ú_get_decoder_modulez#FlaxMBartModule._get_decoder_modulez  r@  rc   rÌ   rß   rà   rŒ   c                 ó*  — | j                  ||||||	|
¬«      }| j                  ||||d   ||||	|
¬«	      }|	s||z   S t        |j                  |j                  |j
                  |j                  |j                  |j                  |j
                  ¬«      S )N)r$   r€   r*  rÌ   rß   rà   rŒ   r   )	r$   r€   r*  rû   rü   rÌ   rß   rà   rŒ   )rë   Údecoder_hidden_statesÚdecoder_attentionsr	  Úencoder_last_hidden_staterû   Úencoder_attentions)r<  r=  r   rë   ri   rì   r	  )r`   r$   r€   Údecoder_input_idsÚdecoder_attention_maskr*  Údecoder_position_idsrÌ   rß   rà   rŒ   Úencoder_outputsÚdecoder_outputss                r>   rª   zFlaxMBartModule.__call__}  s½   € ð Ÿ,™,ØØ)Ø%Ø/Ø!5Ø#Ø'ð 'ó 
ˆð Ÿ,™,Ø'Ø1Ø-Ø"1°!Ñ"4Ø#1Ø/Ø!5Ø#Ø'ð 'ó 

ˆñ Ø" _Ñ4Ð4ä%Ø-×?Ñ?Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô
ð 	
rc   Nr/  )r¬   r­   r®   r#   r¯   r-   r²   r,   rb   r?  rB  rO   rª   rs   rc   r>   r8  r8  h  se   … ØÓØ—{‘{€Eˆ3�9‰9Ó"ò	aòòð #(Ø%*Ø Ø"ñ.
ð  ð.
ð #ð.
ð ð.
ð ô.
rc   r8  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 )(ÚFlaxMBartPreTrainedModelÚmodelÚbase_model_prefixNÚmodule_class)r"   r"   r   TrB   r+  Úseedr,   Ú_do_initc                 óZ   •—  | j                   d||dœ|¤Ž}t        ‰| �	  ||||||¬«       y )N©rB   r,   )r+  rR  r,   rS  rs   )rQ  ÚsuperÚ__init__)	r`   rB   r+  rR  r,   rS  ÚkwargsÚmoduleÚ	__class__s	           €r>   rW  z!FlaxMBartPreTrainedModel.__init__³  s=   ø€ ð #�×"Ñ"ÐH¨&¸ÑHÀÑHˆÜ‰Ñ˜ °[ÀtÐSXÐckÐÕlrc   ÚrngÚparamsr&   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Úi4r+   ).r(   )r\  rF   r\  )r-   rw   r7   r8   rB   Úeos_token_idÚ	ones_likerg   r{   r|   rS   rí   ÚsplitrY  Úinitr   r	   Ú_missing_keysr   r   )r`   r[  r+  r\  r$   r€   rH  rI  rŸ   Úsequence_lengthr*  rJ  Ú
params_rngr�   ÚrngsÚrandom_paramsÚmissing_keys                    r>   Úinit_weightsz%FlaxMBartPreTrainedModel.init_weights¿  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à Ð rc   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.
        r^  r+   r(   c                 ó8   — | j                  «       } ||||fi |¤ŽS rã   ©rB  ©rY  rH  rI  rJ  rX  Údecoder_modules         r>   Ú_decoder_forwardz=FlaxMBartPreTrainedModel.init_cache.<locals>._decoder_forwardù  ó0   € Ø#×7Ñ7Ó9ˆNÙ!Ø!Ø&Ø$ñð ñ	ð rc   r   T)rH  rI  rJ  rû   r‹   Úmethodrn   )r-   r]   r`  r{   r|   Ú
atleast_2drg   rY  rb  rS   rí   r   r	   )	r`   rŸ   rƒ   rK  rH  rI  rJ  ro  Úinit_variabless	            r>   r‹   z#FlaxMBartPreTrainedModel.init_cacheä  sÀ   € ô  ŸH™H j°*Ð%=ÀTÔJÐÜ!$§¡Ð/@Ó!AÐÜ"×/Ñ/Ü�J‰J”s—~‘~Ð&7Ó8×>Ñ>¸rÑBÓCÐEV×E\ÑE\ó 
Ðò	ð Ÿ™×)Ñ)Ü�J‰J×Ñ˜qÓ!Ø/Ø#9Ø!5Ø"1°!Ñ"4ØØ#ð *ó 
ˆô ˜ wÑ/Ó0Ð0rc   ©Úoutput_typeÚconfig_classr$   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, FlaxMBartForConditionalGeneration

        >>> model = FlaxMBartForConditionalGeneration.from_pretrained("facebook/mbart-large-cc25")
        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/mbart-large-cc25")

        >>> text = "My friends are cool but they eat too many carbs."
        >>> inputs = tokenizer(text, max_length=1024, return_tensors="jax")
        >>> encoder_outputs = model.encode(**inputs)
        ```NrF   c                 ó8   — | j                  «       } ||||fi |¤ŽS rã   )r?  )rY  r$   r€   r*  rX  Úencode_modules         r>   Ú_encoder_forwardz9FlaxMBartPreTrainedModel.encode.<locals>._encoder_forward;  s$   € Ø"×6Ñ6Ó8ˆMÙ  ¨N¸LÑSÈFÑSÐSrc   r\  r^  r+   )	r$   r€   r*  rÌ   rß   rà   rŒ   rf  rq  )rB   rÌ   rß   rà   r-   r`  rg   r{   r|   rY  Úapplyr\  r.   )r`   r$   r€   r*  rÌ   rß   rà   rw  r\  r�   rŸ   rd  rf  r{  s                 r>   ÚencodezFlaxMBartPreTrainedModel.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Ø#Ø#˜)ØØ#ð !ó 
ð 	
rc   rü   rI  rJ  Ú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 )aZ  
        Returns:

        Example:

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

        >>> model = FlaxMBartForConditionalGeneration.from_pretrained("facebook/mbart-large-cc25")
        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/mbart-large-cc25")

        >>> text = "My friends are cool but they eat too many carbs."
        >>> inputs = tokenizer(text, max_length=1024, 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   rf   úKMake sure to provide `decoder_position_ids` when passing `past_key_values`.rF   r\  rn   Fc                 ó8   — | j                  «       } ||||fi |¤ŽS rã   rl  rm  s         r>   ro  z9FlaxMBartPreTrainedModel.decode.<locals>._decoder_forward™  rp  rc   r^  r+   ©rH  rI  rJ  rû   rü   rÌ   rß   rà   rŒ   rf  Úmutablerq  r~  r"   )rB   rÌ   rß   rà   rg   r-   r]   r0   r{   r|   r\  rY  r|  r.   r	   )r`   rH  rK  rü   rI  rJ  r~  rÌ   rß   rà   rw  r\  r�   rû   rŸ   rd  rf  Úinputsrƒ  ro  rÐ   Úpasts                         r>   ÚdecodezFlaxMBartPreTrainedModel.decodeL  s#  € ðL 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àˆrc   rH  c                 óÆ  — |�|n| j                   j                  }|�|n| j                   j                  }|	�|	n| j                   j                  }	|€t	        j
                  |«      }|€A|j                  \  }}t	        j                  t	        j                  |«      d d d …f   ||f«      }|€ t        || 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 )NrF   r\  r^  r+   )r$   r€   r*  rH  rI  rJ  rÌ   rß   rà   rŒ   rf  )rB   rÌ   rß   rà   r-   r`  rg   r{   r|   r?   r%   rY  r|  r\  r.   )r`   r$   r€   rH  rI  r*  rJ  rÌ   rß   rà   rw  r\  r�   rŸ   rd  rf  s                   r>   rª   z!FlaxMBartPreTrainedModel.__call__½  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°9¸d¿k¹k×>VÑ>VÓ WÐØ!Ð)Ü%(§]¡]Ð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Ø#Ø#˜)Øð !ó 
ð 	
rc   rã   )NNNNNFNN©
NNNNNNNFNN)NNNNNNNNFNN)'r¬   r­   r®   r#   rv  rP  rØ   r¯   rQ  rQ   ÚModuler-   r²   r   r°   r,   rO   rW  rS   rí   r   r   ri  r‹   r   ÚMBART_ENCODE_INPUTS_DOCSTRINGr!   r   r´   r   Údictr}  ÚMBART_DECODE_INPUTS_DOCSTRINGr   r†  r   ÚMBART_INPUTS_DOCSTRINGrª   Ú__classcell__)rZ  s   @r>   rN  rN  ®  s?  ø… Ø€LØ$Ð�sÓ$Ø"€L�"—)‘)Ó"ð
 #)ØØŸ;™;Øñ
màð
mð ˜3‘Zð
mð ð	
mð
 �y‰yð
mð õ
mñ"! §
¡
× 2Ñ 2ð "!Àð "!ÐPZð "!Ðfpó "!òJ'1ñR Ð7Ó8ÙÐ+>È[ÔYð 15Ø.2Ø,0Ø/3Ø&*ØØØ#ñ;
à—;‘;ð;
ð ! §¡Ñ-ð;
ð ˜sŸ{™{Ñ+ð	;
ð
 $ D™>ð;
ð ' t™nð;
ð ˜d‘^ð;
ð ð;
ð ð;
ð ò;
ó Zó 9ð;
ñz Ð7Ó8ÙÐ+XÐgrÔsð
 9=Ø8<Ø6:Ø $Ø,0Ø/3Ø&*ØØØ#ñmð !)¨¯©Ñ 5ð	mð
 !)¨¯©Ñ 5ðmð ' s§{¡{Ñ3ðmð ðmð $ D™>ðmð ' t™nðmð ˜d‘^ðmð ðmð ðmð òmó tó 9ðmñ^ +Ð+AÓBð 15Ø37Ø8<Ø.2Ø6:Ø,0Ø/3Ø&*ØØØ#ñ7
à—;‘;ð7
ð ! §¡Ñ-ð7
ð $ C§K¡KÑ0ð	7
ð
 !)¨¯©Ñ 5ð7
ð ˜sŸ{™{Ñ+ð7
ð ' s§{¡{Ñ3ð7
ð $ D™>ð7
ð ' t™nð7
ð ˜d‘^ð7
ð ð7
ð ð7
ð ò7
ó Cô7
rc   rN  z_The bare MBart 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)ÚFlaxMBartModelrB   r,   N)
r¬   r­   r®   r#   r¯   r-   r²   r,   r8  rQ  rs   rc   r>   r�  r�  ø  s!   … ð
 ÓØ—{‘{€Eˆ3�9‰9Ó"Ø"�Lrc   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)Ú'FlaxMBartForConditionalGenerationModulerB   r,   .Ú	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 )NrU  FrJ   Úfinal_logits_biasr"   )r8  rB   r,   rO  rQ   rR   r;  Únum_embeddingsrS   rT   rU   rV   Úlm_headÚparamr“  r•  rË   s    r>   rb   z-FlaxMBartForConditionalGenerationModule.setup  sœ   € Ü$¨D¯K©K¸t¿z¹zÔJˆŒ
Ü—x‘xØ�J‰J×Ñ×,Ñ,ØØ—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô	
ˆŒð "&§¡Ð,?ÀÇÁÐRSÐUY×U_ÑU_×UfÑUf×UuÑUuÐQvÓ!wˆÕrc   c                 ó.   — | j                   j                  S rã   ©rO  r<  rË   s    r>   r?  z;FlaxMBartForConditionalGenerationModule._get_encoder_module  ó   € Ø�z‰z×!Ñ!Ð!rc   c                 ó.   — | j                   j                  S rã   ©rO  r=  rË   s    r>   rB  z;FlaxMBartForConditionalGenerationModule._get_decoder_module  r›  rc   rÌ   rß   rà   rŒ   c                 ód  — | j                  |||||||||	|
¬«
      }|d   }| j                  j                  rJ| j                   j                  d   d   d   }| j                  j                  dd|j                  ii|«      }n| j	                  |«      }|t        j                  j                  | j                  j                  | j                  «      «      z  }|	s|f|dd  z   }|S t        ||j                  |j                  |j                   |j"                  |j$                  |j&                  ¬«      S )	N©
r$   r€   rH  rI  r*  rJ  rÌ   rß   rà   rŒ   r   r\  r;  Ú	embeddingÚkernelr"   ©ÚlogitsrD  rE  r	  rF  rû   rG  )rO  rB   Útie_word_embeddingsr”   r—  r|  ÚTrS   r   Ústop_gradientr•  r™   r,   r   rD  rE  r	  rF  rû   rG  )r`   r$   r€   rH  rI  r*  rJ  rÌ   rß   rà   rŒ   rÐ   ri   Úshared_embeddingÚ	lm_logitsÚoutputs                   r>   rª   z0FlaxMBartForConditionalGenerationModule.__call__  s0  € ð —*‘*ØØ)Ø/Ø#9Ø%Ø!5Ø/Ø!5Ø#Ø'ð ó 
ˆð   ™
ˆà�;‰;×*Ò*Ø#Ÿz™z×3Ñ3°HÑ=¸hÑGÈÑTÐØŸ™×*Ñ*¨H°xÐAQ×ASÑASÐ6TÐ+UÐWdÓe‰IàŸ™ ]Ó3ˆIà”S—W‘W×*Ñ*¨4×+AÑ+A×+HÑ+HÈÏÉÓ+TÓUÑUˆ	áØ�\ G¨A¨B KÑ/ˆFØˆMä"ØØ")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô
ð 	
rc   Nr/  )r¬   r­   r®   r#   r¯   r-   r²   r,   rS   rQ   rT   rw   r“  r   r´   rb   r?  rB  rO   rª   rs   rc   r>   r’  r’    s�   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø,/¯F©F×,?Ñ,?×,EÑ,E€Iˆx˜˜SŸ[™[Ð(Ñ)ÓEòxò"ò"ð #(Ø%*Ø Ø"ñ0
ð  ð0
ð #ð0
ð ð0
ð ô0
rc   r’  zNThe MMBart Model with a language modeling head. Can be used for summarization.c                   óp  — 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deej*                     deej*                     fd„Zd„ Zy)Ú!FlaxMBartForConditionalGenerationr,   rt  Nrü   rI  rJ  r~  rÌ   rß   rà   rw  r\  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
        >>> from transformers import AutoTokenizer, FlaxMBartForConditionalGeneration

        >>> model = FlaxMBartForConditionalGeneration.from_pretrained("facebook/mbart-large-cc25")
        >>> tokenizer = AutoTokenizer.from_pretrained("facebook/mbart-large-cc25")

        >>> text = "My friends are cool but they eat too many carbs."
        >>> inputs = tokenizer(text, max_length=1024, 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   rf   r€  rF   r\  rn   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   r\  r;  r   r¡  )rB  rB   r¤  rO  r”   r—  r|  r¥  r•  r™   r,   )rY  rH  rI  rJ  rX  rn  rÐ   ri   r§  r¨  r`   s             €r>   ro  zBFlaxMBartForConditionalGeneration.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Ð%Ð%rc   r^  r+   r‚  )r£  ri   rì   r	  r"   r~  )rB   rÌ   rß   rà   rg   r-   r]   r0   r{   r|   r\  rY  r|  r.   r   ri   rì   r	  r	   )r`   rH  rK  rü   rI  rJ  r~  rÌ   rß   rà   rw  r\  r�   rû   rŸ   rd  rf  r„  rƒ  ro  rÐ   r¨  rL  r…  s   `                       r>   r†  z(FlaxMBartForConditionalGeneration.decodeU  ss  ø€ ðL 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àˆrc   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 )Nr^  r+   r(   r)   r"   )r   r   )r~  rK  rü   rI  rJ  )	rg   r‹   r-   r]   Úcumsumr   rz   r{   r|   )r`   rH  rƒ   r€   rI  rK  rX  rŸ   Ú
seq_lengthr~  Úextended_attention_maskr*  s               r>   Úprepare_inputs_for_generationz?FlaxMBartForConditionalGeneration.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ñ
ð 	
rc   c                 óL   — |j                   |d<   |d   d d …dd …f   dz   |d<   |S )Nr~  rJ  r(   r"   )r~  )r`   Úmodel_outputsÚmodel_kwargss      r>   Úupdate_inputs_for_generationz>FlaxMBartForConditionalGeneration.update_inputs_for_generationü  s?   € Ø*7×*GÑ*GˆÐ&Ñ'Ø/;Ð<RÑ/SÒTUÐWYÑWZÐTZÑ/[Ð^_Ñ/_ˆÐ+Ñ,ØÐrc   rˆ  r  )r¬   r­   r®   r’  rQ  r-   r²   r,   r¯   r   rŒ  r!   r   r#   r   r´   r‹  rO   r   r†  rS   ÚArrayr²  r¶  rs   rc   r>   r«  r«  N  s8  … ð ;€LØ—{‘{€Eˆ3�9‰9Ó"áÐ7Ó8ÙÐ+PÐ_jÔkð
 9=Ø8<Ø6:Ø $Ø,0Ø/3Ø&*ØØØ#ñDð !)¨¯©Ñ 5ð	Dð
 !)¨¯©Ñ 5ðDð ' s§{¡{Ñ3ðDð ðDð $ D™>ðDð ' t™nðDð ˜d‘^ðDð ðDð ðDð òDó ló 9ðDðT /3Ø6:Øñ
ð ! §¡Ñ+ð	
ð
 !)¨¯©Ñ 3ó
ó>rc   r«  a-  
    Returns:

    Summarization example:

    ```python
    >>> from transformers import AutoTokenizer, FlaxMBartForConditionalGeneration, MBartConfig

    >>> model = FlaxMBartForConditionalGeneration.from_pretrained("facebook/mbart-large-cc25")
    >>> tokenizer = AutoTokenizer.from_pretrained("facebook/mbart-large-cc25")

    >>> ARTICLE_TO_SUMMARIZE = "Meine Freunde sind cool, aber sie essen zu viel Kuchen."
    >>> inputs = tokenizer([ARTICLE_TO_SUMMARIZE], max_length=1024, return_tensors="np")

    >>> # Generate Summary
    >>> summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=5).sequences
    >>> print(tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False))
    ```

    Mask filling example:

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

    >>> model = FlaxMBartForConditionalGeneration.from_pretrained("facebook/mbart-large-cc25")
    >>> tokenizer = AutoTokenizer.from_pretrained("facebook/mbart-large-cc25")

    >>> # de_DE is the language symbol id <LID> for German
    >>> TXT = "</s> Meine Freunde sind <mask> nett aber sie essen zu viel Kuchen. </s> de_DE"
    >>> input_ids = tokenizer([TXT], add_special_tokens=False, return_tensors="np")["input_ids"]

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

    >>> tokenizer.decode(predictions).split()
    ```
rt  c            	       ó–   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	e
   ed<   d„ Zd„ Zd„ Z	 	 	 	 dded	ed
edefd„Zy)Ú(FlaxMBartForSequenceClassificationModulerB   r,   NÚ
num_labelsc                 ó4  — t        | j                  | j                  ¬«      | _        t	        | j                  | j                  j
                  | j                  �| j                  n| j                  j                  | j                  j                  ¬«      | _        y )NrU  )rB   r  r  r  )	r8  rB   r,   rO  r  r½   rº  Úclassifier_dropoutÚclassification_headrË   s    r>   rb   z.FlaxMBartForSequenceClassificationModule.setup8  sb   € Ü$¨D¯K©K¸t¿z¹zÔJˆŒ
Ü#>Ø—;‘;Ø—k‘k×)Ñ)Ø+/¯?©?Ð+F˜ŸšÈDÏKÉK×LbÑLbØŸ;™;×9Ñ9ô	$
ˆÕ rc   c                 ó.   — | j                   j                  S rã   rš  rË   s    r>   r?  z<FlaxMBartForSequenceClassificationModule._get_encoder_moduleA  r›  rc   c                 ó.   — | j                   j                  S rã   r�  rË   s    r>   rB  z<FlaxMBartForSequenceClassificationModule._get_decoder_moduleD  r›  rc   rÌ   rß   rà   rŒ   c                 óª  — | j                  |||||||||	|
¬«
      }|d   }t        j                  || j                  j                  k(  dd«      }t        |t        j                  j                  j                  «      sÄt        t        j                  |j                  d«      «      «      dkD  rt        d«      ‚t        |j                  d«      dk(  «      rt        d«      ‚|t        j                  |j                   d   «      dz  z   }t        j                  ||j#                  d«      j%                  dd«      k(  dd«      }t        j&                  d||«      j                  d«      }| j)                  ||
¬	«      }|	s|f|dd  z   }|S t+        ||j,                  |j.                  |j0                  |j2                  |j4                  |j6                  ¬
«      S )NrŸ  r   r"   z7All examples must have the same number of <eos> tokens.z+There are missing <eos> tokens in input_idsg�íµ ÷Æ°>r(   zijk, ij -> ijkrÎ   r¢  )rO  r-   r1   rB   r_  Ú
isinstancerS   ÚinterpretersÚpartial_evalÚDynamicJaxprTracerry   Úuniquer2   r0   Úanyr|   rg   Úmaxr3   r�   r½  r   rD  rE  r	  rF  rû   rG  )r`   r$   r€   rH  rI  r*  rJ  rÌ   rß   rà   rŒ   rÐ   ri   Úeos_maskÚeos_mask_noisedÚsentence_representationr£  r©  s                     r>   rª   z1FlaxMBartForSequenceClassificationModule.__call__G  s·  € ð —*‘*ØØ)Ø/Ø#9Ø%Ø!5Ø/Ø!5Ø#Ø'ð ó 
ˆð   ™
ˆä—9‘9˜Y¨$¯+©+×*BÑ*BÑBÀAÀqÓIˆô ˜(¤C×$4Ñ$4×$AÑ$A×$TÑ$TÔUÜ”3—:‘:˜hŸl™l¨1›oÓ.Ó/°!Ò3Ü Ð!ZÓ[Ð[ä�8—<‘< “? aÑ'Ô(Ü Ð!NÓOÐOð '¬¯©°H·N±NÀ1Ñ4EÓ)FÈÑ)MÑMˆOÜ—y‘y °O×4GÑ4GÈÓ4J×4RÑ4RÐSUÐWXÓ4YÑ!YÐ[\Ð^_Ó`ˆHä"%§*¡*Ð-=¸}ÈhÓ"W×"[Ñ"[Ð\]Ó"^ÐØ×)Ñ)Ð*AÐQ^Ð)Ó_ˆáØ�Y ¨¨ Ñ,ˆFØˆMä2ØØ")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô
ð 	
rc   r/  )r¬   r­   r®   r#   r¯   r-   r²   r,   rº  r   r°   rb   r?  rB  rO   rª   rs   rc   r>   r¹  r¹  3  sr   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø $€J�˜‘Ó$ò
ò"ò"ð #(Ø%*Ø Ø"ñ9
ð  ð9
ð #ð9
ð ð9
ð ô9
rc   r¹  z†
    MBart model with a sequence classification/head on top (a linear layer on top of the pooled output) e.g. for GLUE
    tasks.
    c                   ó(   — e Zd ZeZej                  Zy)Ú"FlaxMBartForSequenceClassificationN)r¬   r­   r®   r¹  rQ  r-   r²   r,   rs   rc   r>   rÌ  rÌ  ƒ  s   „ ð <€LØ�K‰K�Erc   rÌ  c            	       ó†   — e Zd ZU eed<   ej                  Zej                  ed<   dZd„ Z	d„ Z
d„ Z	 	 	 	 ddeded	ed
efd„Zy)Ú#FlaxMBartForQuestionAnsweringModulerB   r,   rf   c                 ó(  — t        | j                  | j                  ¬«      | _        t	        j
                  | j                  | j                  t        j                  j                  j                  | j                  j                  «      ¬«      | _        y )NrU  r¼   )r8  rB   r,   rO  rQ   rR   rº  rS   rT   rU   rV   Ú
qa_outputsrË   s    r>   rb   z)FlaxMBartForQuestionAnsweringModule.setup�  sY   € Ü$¨D¯K©K¸t¿z¹zÔJˆŒ
ÜŸ(™(Ø�O‰O 4§:¡:¼3¿6¹6×;NÑ;N×;UÑ;UÐVZ×VaÑVa×VjÑVjÓ;kô
ˆ�rc   c                 ó.   — | j                   j                  S rã   rš  rË   s    r>   r?  z7FlaxMBartForQuestionAnsweringModule._get_encoder_module£  r›  rc   c                 ó.   — | j                   j                  S rã   r�  rË   s    r>   rB  z7FlaxMBartForQuestionAnsweringModule._get_decoder_module¦  r›  rc   rÌ   rß   rà   rŒ   c                 ó²  — | j                  |||||||||	|
¬«
      }|d   }| j                  |«      }t        j                  ||j                  d   d¬«      \  }}|j                  d«      }|j                  d«      }|	s||f|dd  z   }|S t        |||j                  |j                  |j                  |j                  |j                  |j                  ¬«      S )NrŸ  r   r(   r)   r"   )Ústart_logitsÚ
end_logitsrD  rE  r	  rF  rû   rG  )rO  rÐ  r-   ra  rg   r6   r   rD  rE  r	  rF  rû   rG  )r`   r$   r€   rH  rI  r*  rJ  rÌ   rß   rà   rŒ   rÐ   Úsequence_outputr£  rÔ  rÕ  r©  s                    r>   rª   z,FlaxMBartForQuestionAnsweringModule.__call__©  sô   € ð —*‘*ØØ)Ø/Ø#9Ø%Ø!5Ø/Ø!5Ø#Ø'ð ó 
ˆð " !™*ˆà—‘ Ó1ˆÜ#&§9¡9¨V°V·\±\À"Ñ5EÈBÔ#OÑ ˆ�jØ#×+Ñ+¨BÓ/ˆØ×'Ñ'¨Ó+ˆ
áØ" JÐ/°'¸!¸"°+Ñ=ˆFØˆMä6Ø%Ø!Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô	
ð 		
rc   Nr/  )r¬   r­   r®   r#   r¯   r-   r²   r,   rº  rb   r?  rB  rO   rª   rs   rc   r>   rÎ  rÎ  ˜  si   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø€Jò
ò"ò"ð #(Ø%*Ø Ø"ñ.
ð  ð.
ð #ð.
ð ð.
ð ô.
rc   rÎ  zÝ
    MBart Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
    layer on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c                   ó(   — e Zd ZeZej                  Zy)ÚFlaxMBartForQuestionAnsweringN)r¬   r­   r®   rÎ  rQ  r-   r²   r,   rs   rc   r>   rØ  rØ  Ú  s   „ ð 7€LØ�K‰K�Erc   rØ  )r«  rØ  rÌ  r�  rN  )Sr  r  rí   Ú	functoolsr   Útypingr   r   r   Ú
flax.linenÚlinenrQ   rS   Ú	jax.numpyÚnumpyr-   Ú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   r   r   Úmodeling_flax_utilsr   r   r   r   r   Úutilsr   r   r    r!   Úconfiguration_mbartr#   Ú
get_loggerr¬   ÚloggerÚ_CHECKPOINT_FOR_DOCÚ_CONFIG_FOR_DOCÚMBART_START_DOCSTRINGr�  rŠ  rŒ  r´   r°   r?   r‰  rA   r¶   rÒ   rõ   r  r  r  r1  r8  rN  r�  r’  r«  Ú+FLAX_MBART_CONDITIONAL_GENERATION_DOCSTRINGr¹  rÌ  rÎ  rØ  Ú__all__rs   rc   r>   ú<module>rî     sË  ðñ ã Û Ý ß ,Ñ ,å Û 
Ý ß >Ñ >ß 6Ý >ß ;Ý Ý ÷÷ ñ ÷õ ÷ uÓ tÝ ,ð 
ˆ×	Ñ	˜HÓ	%€à1Ð Ø€ð Ð ðD0Ð ðf!Ð ð<,!Ð ð^ #§+¡+ð ¸Sð ÀSÇ[Á[ó ô0d)˜Ÿ™ô d)ôN5˜BŸI™Iô 5ôr3
 b§i¡iô 3
ôlU˜BŸI™Iô UôrC
 b§i¡iô C
ôN "§)¡)ô ô:H
�r—y‘yô H
ôVR
�r—y‘yô R
ôlC
�b—i‘iô C
ôLG
Ð2ô G
ñT
 ØeØóô#Ð-ó #ó	ð#ñ ˜^Ð-@ÐBXÐZiÔ jôE
¨b¯i©iô E
ñP ØTÐVkóônÐ(@ó nóðnðb&/Ð +ñP Ø%Ð'=Ð@kÑ'kôñ !Ø%Ð3FÐUdõôM
¨r¯y©yô M
ñ` ðð óôÐ)Aó óðñ
 Ø&ØØ'Øô	ô?
¨"¯)©)ô ?
ñD ðð óôÐ$<ó óðñ
 Ø!ØØ+Øô	ò�rc   