Ë
    T^(h(  ã                   óv  — d Z ddlZddlZddlmZ ddl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 dd	lmZmZ dd
lmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4  e1jj                  e6«      Z7dZ8dZ9ejt                  Z:ejv                  fdejx                  fd„Z=dZ>dZ?dZ@dZA 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
j„                  «      ZI G d)„ d*e
j„                  «      ZJ G d+„ d,e*«      ZK e/d-e>«       G d.„ d/eK«      «       ZL e+eLe8e&e9«        G d0„ d1e
j„                  «      ZM e/d2e>«       G d3„ d4eK«      «       ZNd5ZO e-eNe?eOz   «        e,eNe%e9¬6«        G d7„ d8e
j„                  «      ZP e/d9e>«       G d:„ d;eK«      «       ZQd<ZR e-eQe?eRz   «        e,eQe'e9¬6«       g d=¢ZSy)>zFlax whisper model.é    N)Úpartial)ÚOptionalÚTuple)Ú
FrozenDictÚfreezeÚunfreeze)Úcombine_masksÚmake_causal_mask)Úpartitioning)Údot_product_attention_weights)Úflatten_dictÚunflatten_dict)Úlax)ÚPRNGKeyé   )Ú#FlaxWhisperTimeStampLogitsProcessor)ÚFlaxBaseModelOutputÚ-FlaxBaseModelOutputWithPastAndCrossAttentionsÚ%FlaxCausalLMOutputWithCrossAttentionsÚFlaxSeq2SeqLMOutputÚFlaxSeq2SeqModelOutputÚFlaxSequenceClassifierOutput)Ú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é   )ÚWhisperConfigzopenai/whisper-tinyr#   Úreturnc                 óà  — |\  }}|dz  dk7  rt        d|› d�«      ‚t        j                  d«      |dz  dz
  z  }t        j                  | t        j
                  |dz  «      z  «      }t        j
                  |«      j                  dd«      |j                  dd«      z  }t        j                  t        j                  |«      t        j                  |«      gd¬«      j                  |«      S )	z*Returns sinusoids for positional embeddingé   r   zVNumber of channels has to be divisible by 2 for sinusoidal positional embeddings, got z
 channels.i'  r"   éÿÿÿÿ©Úaxis)Ú
ValueErrorÚmathÚlogÚjnpÚexpÚarangeÚreshapeÚconcatenateÚsinÚcosÚastype)ÚkeyÚshapeÚdtypeÚlengthÚchannelsÚlog_timescale_incrementÚinv_timescalesÚscaled_times           úo/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/whisper/modeling_flax_whisper.pyÚsinusoidal_embedding_initr>   >   sØ   € àÑ€FˆHØ�!�|�qÒÜØdÐemÐdnÐnxÐyó
ð 	
ô #Ÿh™h u›o°¸Q±ÀÑ1BÑCÐÜ—W‘WÐ5Ð5¼¿
¹
À8ÈqÁ=Ó8QÑQÓR€NÜ—*‘*˜VÓ$×,Ñ,¨R°Ó3°n×6LÑ6LÈQÐPRÓ6SÑS€KÜ�?‰?œCŸG™G KÓ0´#·'±'¸+Ó2FÐGÈaÔP×WÑWÐX]Ó^Ð^ó    aå  
    This model inherits from [`FlaxPreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its models (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 ([`WhisperConfig`]): 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_features (`numpy.ndarray` of shape `(batch_size, feature_size, sequence_length)`):
            Float values mel features extracted from the raw speech waveform. Raw speech waveform can be obtained by
            loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `numpy.ndarray`, *e.g.* via
            the soundfile library (`pip install soundfile`). To prepare the array into `input_features`, the
            [`WhisperFeatureExtractor`] should be used for extracting the features, padding and conversion into a
            tensor of type `numpy.ndarray`. See [`~WhisperFeatureExtractor.__call__`]
        attention_mask (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Whisper does not support masking of the `input_features`, this argument is preserved for compatibility, but
            is not used. By default the silence in the input log mel spectrogram are ignored.
        decoder_input_ids (`numpy.ndarray` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary. Indices can be obtained using
            [`WhisperTokenizer`]. See [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details.
            [What are decoder input IDs?](../glossary#decoder-input-ids) Whisper uses the `decoder_start_token_id` as
            the starting token for `decoder_input_ids` generation.
        decoder_attention_mask (`numpy.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*):
            Whisper does not use `position_ids` in the encoder as `input_features` is always the same size and doesn't
            use masking, but this argument is preserved for compatibility. By default the silence in the input log mel
            spectrogram are ignored.
        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_features (`numpy.ndarray` of shape `(batch_size, feature_size, sequence_length)`):
            Float values mel features extracted from the raw speech waveform. Raw speech waveform can be obtained by
            loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a `numpy.ndarray`, *e.g.* via
            the soundfile library (`pip install soundfile`). To prepare the array into `input_features`, the
            [`WhisperFeatureExtractor`] should be used for extracting the mel features, padding and conversion into a
            tensor of type `numpy.ndarray`. See [`~WhisperFeatureExtractor.__call__`].
        attention_mask (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
            Whisper does not support masking of the `input_features`, this argument is preserved for compatibility, but
            is not used. By default the silence in the input log mel spectrogram are ignored.
        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 (`numpy.ndarray` of shape `(batch_size, target_sequence_length)`):
            Indices of decoder input sequence tokens in the vocabulary. Indices can be obtained using
            [`WhisperTokenizer`]. See [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details.
            [What are decoder input IDs?](../glossary#decoder-input-ids)
        encoder_outputs (`tuple(tuple(numpy.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 (`numpy.ndarray` of shape `(batch_size, sequence_length)`, *optional*):
           Whisper does not support masking of the `input_features`, this argument is preserved for compatibility,
            but it is not used. By default the silence in the input log mel spectrogram are ignored.
        decoder_attention_mask (`numpy.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, numpy.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                   óÒ  — 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dej                  deej                     deej                     de	de	deej                     fd„Zdej                  fd„Zdej                  fd„Zej,                  deej                  ej                  ej                  f   fd„«       Zy)ÚFlaxWhisperAttentionÚconfigÚ	embed_dimÚ	num_headsç        ÚdropoutFÚcausalTÚbiasr7   r$   Nc                 óð  — | j                   | j                  z  | _        | j                  | j                  z  | j                   k7  r&t        d| j                   › d| j                  › d�«      ‚t	        t
        j                  | j                   | j                  t        j
                  j                  j                  | j                  j                  «      ¬«      } || j                  ¬«      | _         |d¬«      | _         || j                  ¬«      | _         || j                  ¬«      | _        | j$                  r>t'        t)        j*                  d| j                  j,                  fd¬	«      d¬	«      | _        y y )
Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).©r7   Úkernel_init)Úuse_biasFr"   Úbool©r7   )rC   rD   Úhead_dimr*   r   ÚnnÚDenser7   ÚjaxÚinitializersÚnormalrB   Úinit_stdrH   Úq_projÚk_projÚv_projÚout_projrG   r
   r-   ÚonesÚmax_target_positionsÚcausal_mask)ÚselfÚdenses     r=   ÚsetupzFlaxWhisperAttention.setupÉ   s  € ØŸ™¨$¯.©.Ñ8ˆŒØ�=‰=˜4Ÿ>™>Ñ)¨T¯^©^Ò;ÜØMÈdÏnÉnÐM]Ø$ T§^¡^Ð$4°Bð8óð ô
 Ü�H‰HØ�N‰NØ—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô	
ˆñ  T§Y¡YÔ/ˆŒÙ UÔ+ˆŒÙ T§Y¡YÔ/ˆŒÙ t§y¡yÔ1ˆŒà�;Š;Ü/Ü—‘˜!˜TŸ[™[×=Ñ=Ð>ÀfÔMÐU[ô ˆDÕð r?   Úhidden_statesÚkey_value_statesÚattention_maskÚ
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 )Nr   r"   ÚcacheÚ
cached_keyÚcache_index)éýÿÿÿéþÿÿÿr(   rE   rF   T)rH   Údropout_rngÚdropout_rateÚbroadcast_dropoutrd   r7   Ú	precisionz...hqk,...khd->...qhd)r6   rV   rW   rX   Ú_split_headsrG   Úhas_variableÚ	variablesr   Údynamic_slicer\   r-   Úbroadcast_toÚexpand_dimsr	   Ú_concatenate_to_cacheÚselectÚfullr4   r7   ÚfinfoÚminrF   Úmake_rngr   ÚeinsumÚ_merge_headsrY   )r]   r`   ra   rb   rc   rd   Úis_cross_attentionÚ
batch_sizeÚquery_statesÚ
key_statesÚvalue_statesÚquery_lengthÚ
key_lengthÚ
mask_shiftÚmax_decoder_lengthr\   Úattention_biasrk   Úattn_weightsÚattn_outputs                       r=   Ú__call__zFlaxWhisperAttention.__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Ð)Ø˜˜<Ð);Ð<ó‘ð #×.Ñ.ª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?   c                 óp   — |j                  |j                  d d | j                  | j                  fz   «      S ©Nr&   )r0   r6   rD   rO   ©r]   Úhidden_states     r=   ro   z!FlaxWhisperAttention._split_heads:  s2   € Ø×#Ñ# L×$6Ñ$6°r¸Ð$:¸d¿n¹nÈdÏmÉmÐ=\Ñ$\Ó]Ð]r?   c                 óZ   — |j                  |j                  d d | j                  fz   «      S r‹   )r0   r6   rC   rŒ   s     r=   r|   z!FlaxWhisperAttention._merge_heads=  s,   € Ø×#Ñ# L×$6Ñ$6°r¸Ð$:¸d¿n¹nÐ=NÑ$NÓOÐOr?   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 )	Nrf   rg   Úcached_valuerh   c                  óL   — t        j                  dt         j                  ¬«      S )Nr   rN   )r-   ÚarrayÚint32© r?   r=   ú<lambda>z<FlaxWhisperAttention._concatenate_to_cache.<locals>.<lambda>F  s   € ÄCÇIÁIÈaÔWZ×W`ÑW`ÔDa€ r?   )r   r   r"   )rp   Úvariabler-   Úzerosr6   r7   ÚvalueÚlenr   Údynamic_update_slicers   r/   Útupler	   )r]   r5   r˜   Úqueryrb   Úis_initializedrg   r�   rh   Ú
batch_dimsÚ
max_lengthrD   Údepth_per_headÚ	cur_indexÚindicesÚnum_updated_cache_vectorsÚpad_masks                    r=   ru   z*FlaxWhisperAttention._concatenate_to_cache@  st  € ð ×*Ñ*¨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?   ©r$   N)NNFT)Ú__name__Ú
__module__Ú__qualname__r#   Ú__annotations__ÚintrF   ÚfloatrG   rM   rH   r-   Úfloat32r7   r_   Úndarrayr   r   r‰   ro   r|   rP   Úcompactru   r”   r?   r=   rA   rA   À   s  … ØÓØƒNØƒNØ€GˆUÓØ€FˆDÓØ€Dˆ$ÓØ—{‘{€Eˆ3�9‰9Ó"óð8 37Ø04Ø Ø"ñV)à—{‘{ðV)ð # 3§;¡;Ñ/ðV)ð ! §¡Ñ-ð	V)ð
 ðV)ð ðV)ð 
ˆs�{‰{Ñ	óV)ðp^¨C¯K©Kó ^ðP¨C¯K©Kó Pð ‡Z�Zð*È%ÐPS×P[ÑP[Ð]`×]hÑ]hÐjm×juÑjuÐPuÑJvò *ó ñ*r?   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)ÚFlaxWhisperEncoderLayerrB   r7   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   r7   çñhãˆµøä>©r7   Úepsilon©ÚraterJ   )rB   Úd_modelrC   rA   Úencoder_attention_headsÚattention_dropoutr7   Ú	self_attnrP   Ú	LayerNormÚself_attn_layer_normÚDropoutrF   Údropout_layerr   Úactivation_functionÚactivation_fnÚactivation_dropoutÚactivation_dropout_layerrQ   Úencoder_ffn_dimrR   rS   rT   rU   Úfc1Úfc2Úfinal_layer_norm©r]   s    r=   r_   zFlaxWhisperEncoderLayer.setupd  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?   r`   rb   Úoutput_attentionsrd   c                 ó|  — |}| j                  |«      }| j                  ||¬«      \  }}| j                  ||¬«      }||z   }|}| j                  |«      }| j	                  | j                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }||z   }|f}|r||fz  }|S )N)r`   rb   ©rd   )r½   r»   r¿   rÇ   rÁ   rÅ   rÃ   rÆ   )r]   r`   rb   rÉ   rd   Úresidualr‡   Úoutputss           r=   r‰   z FlaxWhisperEncoderLayer.__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àˆr?   r¥   )TT)r¦   r§   r¨   r#   r©   r-   r¬   r7   r_   r­   rM   r   r‰   r”   r?   r=   r°   r°   `  sn   … ØÓØ—{‘{€Eˆ3�9‰9Ó"óNð6 #'Ø"ñà—{‘{ðð Ÿ™ðð  ð	ð
 ðð 
ˆs�{‰{Ñ	ôr?   r°   c            	       ó„   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   d„ Z
	 	 	 	 dde	de	de	d	e	fd
„Zy)Ú!FlaxWhisperEncoderLayerCollectionrB   r7   FÚgradient_checkpointingc           	      óð  — | j                   rjt        t        d¬«      }t        | j                  j
                  «      D �cg c]*  } || j                  t        |«      | j                  ¬«      ‘Œ, c}| _        n[t        | j                  j
                  «      D �cg c]-  }t        | j                  t        |«      | j                  ¬«      ‘Œ/ c}| _        | j                  j                  | _
        y c c}w c c}w )N)r&   r   ©Ústatic_argnums©Únamer7   )rÐ   Úrematr°   ÚrangerB   Úencoder_layersÚstrr7   ÚlayersÚencoder_layerdropÚ	layerdrop)r]   Ú!FlaxWhisperEncoderCheckpointLayerÚis      r=   r_   z'FlaxWhisperEncoderLayerCollection.setup�  sº   € Ø×&Ò&Ü05Ô6MÐ^dÔ0eÐ-ô ˜tŸ{™{×9Ñ9Ó:öàñ 2°$·+±+ÄCÈÃFÐRV×R\ÑR\Ö]òˆD�Kô ˜tŸ{™{×9Ñ9Ó:öàô (¨¯©¼#¸a»&ÈÏ
É
ÖSòˆDŒKð Ÿ™×6Ñ6ˆ�ùòùò
ó   ¿/C.Â2C3rd   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 )Nr”   r   r"   )NNc              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­w©Nr”   ©Ú.0Úvs     r=   ú	<genexpr>z=FlaxWhisperEncoderLayerCollection.__call__.<locals>.<genexpr>Ï  ó   è ø€ Ò=˜q¨q©}œÑ=ùó   ‚Š©Úlast_hidden_stater`   Ú
attentions)rÚ   ÚrandomÚuniformrÜ   r›   r   )r]   r`   rb   rd   rÉ   rà   rá   Úall_attentionsÚall_hidden_statesÚencoder_layerÚdropout_probabilityÚlayer_outputsrÍ   s                r=   r‰   z*FlaxWhisperEncoderLayerCollection.__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¬   r7   rÐ   rM   r_   r‰   r”   r?   r=   rÏ   rÏ   ˜  se   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ò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)ÚFlaxWhisperDecoderLayerrB   r7   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   r7   r¶   r³   r´   r²   rJ   )rB   r¸   rC   rA   Údecoder_attention_headsrº   r7   r»   rP   r¾   rF   r¿   r   rÀ   rÁ   rÂ   rÃ   r¼   r½   Úencoder_attnÚencoder_attn_layer_normrQ   Údecoder_ffn_dimrR   rS   rT   rU   rÅ   rÆ   rÇ   rÈ   s    r=   r_   zFlaxWhisperDecoderLayer.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ˆÔ!Ü0Ø—;‘;Ø—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?   r`   rb   Úencoder_hidden_statesÚencoder_attention_maskrc   rÉ   rd   c                 ó  — |}| j                  |«      }| j                  |||¬«      \  }}	| j                  ||¬«      }||z   }d }
|�B|}| j                  |«      }| j	                  |||¬«      \  }}
| j                  ||¬«      }||z   }|}| j                  |«      }| j                  | j                  |«      «      }| j                  ||¬«      }| j                  |«      }| j                  ||¬«      }||z   }|f}|r||	|
fz  }|S )N)r`   rb   rc   rË   )r`   ra   rb   )
r½   r»   r¿   rû   rú   rÇ   rÁ   rÅ   rÃ   rÆ   )r]   r`   rb   rý   rþ   rc   rÉ   rd   rÌ   Úself_attn_weightsÚcross_attn_weightsrÍ   s               r=   r‰   z FlaxWhisperDecoderLayer.__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àˆr?   r¥   )NNFTT)r¦   r§   r¨   r#   r©   r-   r¬   r7   r_   r­   r   rM   r   r‰   r”   r?   r=   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e	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)Ú!FlaxWhisperDecoderLayerCollectionrB   r7   FrÐ   c           	      óð  — | j                   rjt        t        d¬«      }t        | j                  j
                  «      D �cg c]*  } || j                  t        |«      | j                  ¬«      ‘Œ, c}| _        n[t        | j                  j
                  «      D �cg c]-  }t        | j                  t        |«      | j                  ¬«      ‘Œ/ c}| _        | j                  j                  | _
        y c c}w c c}w )N)é   é   é   rÒ   rÔ   )rÐ   rÖ   r÷   r×   rB   Údecoder_layersrÙ   r7   rÚ   Údecoder_layerdroprÜ   )r]   Ú!FlaxWhisperDecoderCheckpointLayerrÞ   s      r=   r_   z'FlaxWhisperDecoderLayerCollection.setup4  sº   € Ø×&Ò&Ü05Ô6MÐ^gÔ0hÐ-ô ˜tŸ{™{×9Ñ9Ó:öàñ 2°$·+±+ÄCÈÃFÐRV×R\ÑR\Ö]òˆD�Kô ˜tŸ{™{×9Ñ9Ó:öàô (¨¯©¼#¸a»&ÈÏ
É
ÖSòˆDŒKð Ÿ™×6Ñ6ˆ�ùòùò
rß   Nrý   rþ   rd   rc   rÉ   rà   rá   c
           
      óh  — |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ŒK||d   fz  }|€ŒW||d   fz  }Œa |r|
|fz  }
||
||g}|	st	        d„ |D «       «      S t        ||
||¬«      S )Nr”   r   r"   ©NNNr&   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wrä   r”   rå   s     r=   rè   z=FlaxWhisperDecoderLayerCollection.__call__.<locals>.<genexpr>s  ré   rê   ©rì   r`   rí   Úcross_attentions)rÚ   rî   rï   rÜ   r›   r   )r]   r`   rb   rý   rþ   rd   rc   rÉ   rà   rá   rñ   Úall_self_attnsÚall_cross_attentionsÚdecoder_layerró   rô   rÍ   s                    r=   r‰   z*FlaxWhisperDecoderLayerCollection.__call__B  s  € ñ #7™B¸DÐÙ0™°dˆÙ&7Ð<QÐ<]™rÐdhÐà!Ÿ[™[ò 	@ˆMÙ#Ø! mÐ%5Ñ5Ð!ä"(§.¡.°°AÓ"6ÐÙ Ð&9¸D¿N¹NÒ&JØ 2‘á -Ø!Ø"Ø)Ø*ØØ%Ø!ó!�ð *¨!Ñ,ˆMÚ Ø =°Ñ#3Ð"5Ñ5�à(Ñ4Ø(¨]¸1Ñ-=Ð,?Ñ?Ñ(ð/	@ñ4  Ø -Ð!1Ñ1Ðà Ð"3°^ÐEYÐZˆáÜÑ= GÔ=Ó=Ð=ä<Ø+Ø+Ø%Ø1ô	
ð 	
r?   )NNTFFFT)r¦   r§   r¨   r#   r©   r-   r¬   r7   rÐ   rM   r_   r   r­   r‰   r”   r?   r=   r  r  /  sž   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ò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                  Zej                  ed<   dZe	ed<   dd„Z
	 	 	 	 ddej                  d	e	d
e	de	de	deej                     fd„Zy)ÚFlaxWhisperEncoderrB   r7   FrÐ   r$   Nc           	      óš  — t        j                  | j                  j                  ddt        j                   j
                  j                  | j                  j                  «      | j                  ¬«      | _	        t        j                  | j                  j                  dddt        j                   j
                  j                  | j                  j                  «      | j                  ¬«      | _
        t        j                  | j                  j                  ¬«      | _        t        | j                  | j                  | j                  ¬«      | _        t        j"                  | j                  j$                  | j                  j                  | j                  t&        ¬«      | _        t        j*                  | j                  d	¬
«      | _        y )N)r   r"   )Úkernel_sizeÚpaddingrK   r7   r&   )r  Ústridesr  rK   r7   r¶   ©r7   rÐ   )r7   Úembedding_initr³   r´   )rP   ÚConvrB   r¸   rR   rS   rT   rU   r7   Úconv1Úconv2r¾   rF   r¿   rÏ   rÐ   rÚ   ÚEmbedÚmax_source_positionsr>   Úembed_positionsr¼   Ú
layer_normrÈ   s    r=   r_   zFlaxWhisperEncoder.setup‚  s.  € Ü—W‘WØ�K‰K×ÑØØÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHØ—*‘*ô
ˆŒ
ô —W‘WØ�K‰K×ÑØØØÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHØ—*‘*ô
ˆŒ
ô  ŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔä7Ø�K‰KØ—*‘*Ø#'×#>Ñ#>ô
ˆŒô  "Ÿx™xØ�K‰K×,Ñ,Ø�K‰K×ÑØ—*‘*Ü4ô	 
ˆÔô Ÿ,™,¨T¯Z©ZÀÔGˆ�r?   Úinput_featuresrÉ   rà   rá   rd   c           	      óÖ  — |j                   dd  | j                  j                  | j                  j                  dz  fk7  rMt	        d|j                   dd  › d| j                  j                  › d| j                  j                  dz  › d�«      ‚|j                  ddd«      }t        j                  j                  | j                  |«      d¬	«      }t        j                  j                  | j                  |«      d¬	«      }| j                  t        j                  | j                  j                  «      «      }t        j                  j                  |«      }||z   }| j!                  ||¬
«      }| j#                  |d ||||¬«      }|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&   zqinput_features.shape[1:], must be equal to (self.config.num_mel_bins, self.config.max_source_positions * 2) (got z, but should be (z, z))r   F)ÚapproximaterË   )rb   rd   rÉ   rà   rá   r'   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wrä   r”   rå   s     r=   rè   z.FlaxWhisperEncoder.__call__.<locals>.<genexpr>Ò  ré   rê   rë   )r6   rB   Únum_mel_binsr  r*   Ú	transposerR   rP   Úgelur  r  r   r-   r/   r   Ústop_gradientr¿   rÚ   r!  r›   r   rí   )
r]   r"  rÉ   rà   rá   rd   r`   r   rÍ   Úlast_hidden_statess
             r=   r‰   zFlaxWhisperEncoder.__call__¤  sü  € ð ×Ñ  Ð#¨¯©×(@Ñ(@À$Ç+Á+×BbÑBbÐefÑBfÐ'gÒgÜð?Ø?M×?SÑ?SÐTUÐTVÐ?WÐ>Xð YØ—[‘[×-Ñ-Ð.¨b°·±×1QÑ1QÐTUÑ1UÐ0VÐVXðZóð ð (×1Ñ1°!°Q¸Ó:ˆÜŸ™Ÿ™ D§J¡J¨~Ó$>ÈE˜ÓRˆÜŸ™Ÿ™ D§J¡J¨}Ó$=È5˜ÓQˆà×.Ñ.¬s¯z©z¸$¿+¹+×:ZÑ:ZÓ/[Ó\ˆäŸ'™'×/Ñ/°Ó@ˆØ%¨Ñ7ˆà×*Ñ*¨=ÈÐ*Ó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Ø'Ø×)Ñ)ô
ð 	
r?   r¥   ©FFTT)r¦   r§   r¨   r#   r©   r-   r¬   r7   rÐ   rM   r_   r­   r   r‰   r”   r?   r=   r  r  }  s†   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ó HðJ #(Ø%*Ø Ø"ñ4
àŸ™ð4
ð  ð4
ð #ð	4
ð
 ð4
ð ð4
ð 
ˆs�{‰{Ñ	ô4
r?   r  c                   ó  — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   dd„Z
	 	 	 	 	 	 ddej                  d	ej                  d
ej                  deej                     de	de	de	de	de	deej                     fd„Zy)ÚFlaxWhisperDecoderrB   r7   FrÐ   r$   Nc                 óL  — t        j                  | j                  j                  | j                  j                  | j
                  ¬«      | _        t        j                  | j                  j                  | j                  j                  | j
                  ¬«      | _        t        | j                  | j
                  | j                  ¬«      | _        t        j                  | j                  j                  ¬«      | _        t        j                  | j
                  d¬«      | _        y )NrN   r  r¶   r³   r´   )rP   r  rB   Ú
vocab_sizer¸   r7   Úembed_tokensr[   r   r  rÐ   rÚ   r¾   rF   r¿   r¼   r!  rÈ   s    r=   r_   zFlaxWhisperDecoder.setupà  s¶   € ÜŸH™H T§[¡[×%;Ñ%;¸T¿[¹[×=PÑ=PÐX\×XbÑXbÔcˆÔÜ!Ÿx™x¨¯©×(HÑ(HÈ$Ï+É+×J]ÑJ]Ðei×eoÑeoÔpˆÔä7Ø�K‰K˜tŸz™zÀ$×B]ÑB]ô
ˆŒô  ŸZ™Z¨T¯[©[×-@Ñ-@ÔAˆÔäŸ,™,¨T¯Z©ZÀÔFˆ�r?   Ú	input_idsrb   Úposition_idsrý   rc   rÉ   rà   rá   rd   c
           
      óˆ  — | j                  |«      }
| j                  |«      }|
|z   }| 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Ë   )rb   rý   rd   rc   rÉ   rà   rá   r   r"   r'   r&   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wrä   r”   rå   s     r=   rè   z.FlaxWhisperDecoder.__call__.<locals>.<genexpr>  ré   rê   r  )	r0  r   r¿   rÚ   r!  r›   r   rí   r  )r]   r1  rb   r2  rý   rc   rÉ   rà   rá   rd   Úinput_embedsÚposition_embedsr`   rÍ   r*  s                  r=   r‰   zFlaxWhisperDecoder.__call__ì  s  € ð ×(Ñ(¨Ó3ˆØ×.Ñ.¨|Ó<ˆà$ Ñ6ˆØ×*Ñ*¨=ÈÐ*ÓVˆà—+‘+ØØ)Ø"7Ø'Ø!Ø/Ø!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ô	
ð 	
r?   r¥   )NFFFTT)r¦   r§   r¨   r#   r©   r-   r¬   r7   rÐ   rM   r_   r­   r   r   r‰   r”   r?   r=   r-  r-  Û  sÄ   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ó
Gð" 8<Ø Ø"'Ø%*Ø Ø"ñ/
à—;‘;ð/
ð Ÿ™ð/
ð —k‘kð	/
ð
  (¨¯©Ñ4ð/
ð ð/
ð  ð/
ð #ð/
ð ð/
ð ð/
ð 
ˆs�{‰{Ñ	ô/
r?   r-  c                   óò   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   dd„Z
	 	 	 	 ddej                  dej                  d	ej                  d
ej                  de	de	de	de	fd„Zd„ Zd„ Zy)ÚFlaxWhisperModulerB   r7   FrÐ   Nc                 óÈ   — t        | j                  | j                  | j                  ¬«      | _        t        | j                  | j                  | j                  ¬«      | _        y )Nr  )r  rB   r7   rÐ   Úencoderr-  ÚdecoderrÈ   s    r=   r_   zFlaxWhisperModule.setup#  sF   € Ü)Ø�K‰K˜tŸz™zÀ$×B]ÑB]ô
ˆŒô *Ø�K‰K˜tŸz™zÀ$×B]ÑB]ô
ˆ�r?   r"  Údecoder_input_idsÚdecoder_attention_maskÚdecoder_position_idsrÉ   rà   rá   rd   c	           
      ó$  — | j                  |||||¬«      }	| j                  ||||	d   ||||¬«      }
|s|
|	z   S t        |
j                  |
j                  |
j
                  |
j                  |	j                  |	j                  |	j
                  ¬«      S )N)rÉ   rà   rá   rd   r   )r1  rb   r2  rý   rÉ   rà   rá   rd   )rì   Údecoder_hidden_statesÚdecoder_attentionsr  Úencoder_last_hidden_staterý   Úencoder_attentions)r:  r;  r   rì   r`   rí   r  )r]   r"  r<  r=  r>  rÉ   rà   rá   rd   Úencoder_outputsÚdecoder_outputss              r=   r‰   zFlaxWhisperModule.__call__+  s´   € ð Ÿ,™,ØØ/Ø!5Ø#Ø'ð 'ó 
ˆð Ÿ,™,Ø'Ø1Ø-Ø"1°!Ñ"4Ø/Ø!5Ø#Ø'ð 'ó 	
ˆñ Ø" _Ñ4Ð4ä%Ø-×?Ñ?Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô
ð 	
r?   c                 ó   — | j                   S rä   )r:  rÈ   s    r=   Ú_get_encoder_modulez%FlaxWhisperModule._get_encoder_moduleV  ó   € Ø�|‰|Ðr?   c                 ó   — | j                   S rä   )r;  rÈ   s    r=   Ú_get_decoder_modulez%FlaxWhisperModule._get_decoder_moduleY  rH  r?   r¥   r+  )r¦   r§   r¨   r#   r©   r-   r¬   r7   rÐ   rM   r_   r­   r‰   rG  rJ  r”   r?   r=   r8  r8    s¦   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ó
ð #(Ø%*Ø Ø"ñ)
àŸ™ð)
ð Ÿ;™;ð)
ð !$§¡ð	)
ð
 "Ÿk™kð)
ð  ð)
ð #ð)
ð ð)
ð ó)
òVór?   r8  c                   ó~  ‡ — e Zd ZU eZdZeed<   dZdZ	e
j                  ed<   ddej                  ddfd	ed
ee   dedej                   dedefˆ fd„Z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j<                  deej<                     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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$ e%e&«      	 	 	 	 	 	 	 	 	 	 d(dej<                  d#ej<                  deej<                     deej<                     d$eej<                     d eej<                     dee   dee   dee   dede defd%„«       Z'ˆ xZ(S ))ÚFlaxWhisperPreTrainedModelÚmodelÚbase_model_prefixr"  NÚmodule_classr   TFrB   Úinput_shapeÚseedr7   Ú_do_initrÐ   c                 ó˜   •—  | j                   d|||dœ|¤Ž}|€d|j                  d|j                  z  f}t        ‰	| �  ||||||¬«       y )N©rB   r7   rÐ   r"   r&   )rP  rQ  r7   rR  r”   )rO  r&  r  ÚsuperÚ__init__)
r]   rB   rP  rQ  r7   rR  rÐ   ÚkwargsÚmoduleÚ	__class__s
            €r=   rV  z#FlaxWhisperPreTrainedModel.__init__c  sd   ø€ ð #�×"Ñ"Ðw¨&¸ÐVlÑwÐpvÑwˆØÐØ˜f×1Ñ1°1°v×7RÑ7RÑ3RÐSˆKÜ‰Ñ˜ °[ÀtÐSXÐckÐÕlr?   c                 ó^   — | j                  | j                  | j                  d¬«      | _        y )NTrT  )rO  rB   r7   Ú_modulerÈ   s    r=   Úenable_gradient_checkpointingz8FlaxWhisperPreTrainedModel.enable_gradient_checkpointingr  s*   € Ø×(Ñ(Ø—;‘;Ø—*‘*Ø#'ð )ó 
ˆ�r?   ÚrngÚparamsr$   c                 óÜ  — t        j                  |d¬«      }|j                  d   j                  | j                  j
                  «      }t        j                  |d   dfd¬«      }t        j                  |«      }|j                  \  }}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Úf4rN   ©.r'   r   r"   Úi4©r^  rF   )r"  r<  r=  r>  r^  )r-   r—   ÚatÚsetrB   Úeos_token_idÚ	ones_liker6   rs   r/   rR   rî   ÚsplitrX  Úinitr   r   Ú_missing_keysr   r   )r]   r]  rP  r^  r"  r<  r=  r~   Úsequence_lengthr>  Ú
params_rngrk   ÚrngsÚrandom_paramsÚmissing_keys                  r=   Úinit_weightsz'FlaxWhisperPreTrainedModel.init_weightsy  s_  € äŸ™ ;°dÔ;ˆØ'×*Ñ*¨9Ñ5×9Ñ9¸$¿+¹+×:RÑ:RÓSˆäŸI™I {°1¡~°qÐ&9ÀÔFÐÜ!$§¡Ð/@Ó!AÐà&7×&=Ñ&=Ñ#ˆ
�OÜ"×/Ñ/´·
±
¸?Ó0KÈDÒRSÈGÑ0TÐWaÐcrÐVsÓtÐä"%§*¡*×"2Ñ"2°3Ó"7Ñˆ
�KØ$°Ñ=ˆàŸ™×(Ñ(ØØ)Ø/Ø#9Ø!5ð )ó 
ð ñˆð ÐÜ(¬°-Ó)@Ó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.
        rb  rN   r'   c                 ó8   — | j                  «       } ||||fi |¤ŽS rä   ©rJ  ©rX  r<  r=  r>  rW  Údecoder_modules         r=   Ú_decoder_forwardz?FlaxWhisperPreTrainedModel.init_cache.<locals>._decoder_forward¯  s0   € Ø#×7Ñ7Ó9ˆNÙ!Ø!Ø&Ø$ñð ñ	ð r?   r   T)r<  r=  r>  rý   rc   Úmethodrf   )r-   rZ   rg  rs   r/   Ú
atleast_2dr6   rX  ri  rR   rî   r   r   )	r]   r~   rŸ   rD  r<  r=  r>  rv  Úinit_variabless	            r=   rc   z%FlaxWhisperPreTrainedModel.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Ð0r?   ©Úoutput_typeÚconfig_classrb   rÉ   rà   rá   Útrainrk   c	           
      óH  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }i }
|�||
d<   d„ }| j                  j                  d|xs | j                  it        j                  |d¬«      |||| |
|¬«      S )aÁ  
        Returns:

        Example:

        ```python
        >>> from transformers import WhisperProcessor, FlaxWhisperForConditionalGeneration
        >>> from datasets import load_dataset

        >>> processor = WhisperProcessor.from_pretrained("openai/whisper-tiny.en")
        >>> model = FlaxWhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny.en", from_pt=True)
        >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> inputs = processor(ds[0]["audio"]["array"], return_tensors="np")
        >>> input_features = inputs.input_features
        >>> encoder_outputs = model.encode(input_features=input_features)
        ```rF   c                 ó4   — | j                  «       } ||fi |¤ŽS rä   )rG  )rX  r"  rW  Úencode_modules       r=   Ú_encoder_forwardz;FlaxWhisperPreTrainedModel.encode.<locals>._encoder_forwardì  s    € Ø"×6Ñ6Ó8ˆMÙ  Ñ:°6Ñ:Ð:r?   r^  r`  rN   )r"  rÉ   rà   rá   rd   rm  rw  ©	rB   rÉ   rà   rá   rX  Úapplyr^  r-   r’   )r]   r"  rb   rÉ   rà   rá   r}  r^  rk   rW  rm  r�  s               r=   Úencodez!FlaxWhisperPreTrainedModel.encodeÃ  s¾   € ð< 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆð ˆØÐ"Ø)ˆD�‰Oò	;ð �{‰{× Ñ Ø�vÒ, §¡Ð-ÜŸ9™9 ^¸4Ô@Ø/Ø!5Ø#Ø#˜)ØØ#ð !ó 	
ð 		
r?   rþ   r=  r>  Úpast_key_valuesc                 óV  — |�|n| j                   j                  }|�|n| j                   j                  }|	�|	n| j                   j                  }	|d   }|j                  \  }}|€Y|�t        d«      ‚|�|j                  d«      |z  dz
  }n2t        j                  t        j                  |«      ddd…f   ||f«      }|€t        j                  ||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¬«      ||||	|
 |||¬«      }|�|	r|\  }}t        |d   «      |d<   |S |�"|	s |\  }}|dd t        |d   «      fz   |dd z   }|S )a  
        Returns:

        Example:

        ```python
        >>> from transformers import WhisperProcessor, FlaxWhisperForConditionalGeneration
        >>> from datasets import load_dataset
        >>> import jax.numpy as jnp

        >>> processor = WhisperProcessor.from_pretrained("openai/whisper-tiny.en")
        >>> model = FlaxWhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny.en", from_pt=True)
        >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> input_features = processor(ds[0]["audio"]["array"], return_tensors="np").input_features

        >>> encoder_outputs = model.encode(input_features=input_features)
        >>> decoder_start_token_id = model.config.decoder_start_token_id

        >>> decoder_input_ids = jnp.ones((input_features.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   úKMake sure to provide `decoder_position_ids` when passing `past_key_values`.r'   r"   rF   r^  rf   Fc                 ó:   — | j                  «       } |d|||dœ|¤ŽS )N©r1  rb   r2  r”   rs  rt  s         r=   rv  z;FlaxWhisperPreTrainedModel.decode.<locals>._decoder_forwardK  s5   € Ø#×7Ñ7Ó9ˆNÙ!ð Ø+Ø5Ø1ñð ñ	ð r?   rb  rN   ©r<  r=  r>  rý   rÉ   rà   rá   rd   rm  Úmutablerw  r…  )rB   rÉ   rà   rá   r6   r*   Úcumsumr-   rs   r/   rZ   r^  rX  rƒ  r’   r   )r]   r<  rD  rþ   r=  r>  r…  rÉ   rà   rá   r}  r^  rk   rý   r~   rk  rm  Úinputsr‹  rv  rÍ   Úpasts                         r=   Údecodez!FlaxWhisperPreTrainedModel.decodeû  s  € ðR 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆà /°Ñ 2Ðà&7×&=Ñ&=Ñ#ˆ
�OØÐ'ØÐ*Ü Ð!nÓoÐoà%Ð1Ø(>×(EÑ(EÀbÓ(IÐLbÑ(bÐfgÑ'gÑ$ä'*×'7Ñ'7Ü—J‘J˜Ó/°²a°Ñ8¸:ÀÐ:Wó(Ð$ð "Ð)Ü%(§X¡X¨z¸?Ð.KÓ%LÐ"ð ˆØÐ"Ø)ˆ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Ø/Ø!5Ø#Ø#˜)ØØØ#ð $ó 
ˆð  Ð&©;Ø#‰MˆG�TÜ)1°$°w±-Ó)@ˆGÐ%Ñ&ØˆNØÐ(±Ø#‰MˆG�TØ˜b˜q�k¤X¨d°7©mÓ%<Ð$>Ñ>ÀÈÈÀÑLˆGàˆr?   r<  r2  c                 óª  — |�|n| j                   j                  }|�|n| j                   j                  }|	�|	n| j                   j                  }	|€[|�|j	                  d«      |z  dz
  }nA|j
                  \  }}t        j                  t        j                  |«      d d d …f   ||f«      }|€t        j                  |«      }|�d|ini }| j                  j                  d|xs | j                  it        j                  |d¬«      t        j                  |d¬«      t        j                  |d¬«      t        j                  |d¬«      |||	|
 |¬«
      S )	Nr'   r"   rF   r^  r`  rN   rb  )	r"  r<  r=  r>  rÉ   rà   rá   rd   rm  )rB   rÉ   rà   rá   rŒ  r6   r-   rs   r/   rg  rX  rƒ  r^  r’   )r]   r"  r<  rb   r=  r2  r>  rÉ   rà   rá   r}  r^  rk   r~   rk  rm  s                   r=   r‰   z#FlaxWhisperPreTrainedModel.__call__n  s^  € ð  2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆð  Ð'Ø%Ð1Ø(>×(EÑ(EÀbÓ(IÐLbÑ(bÐfgÑ'gÑ$à.?×.EÑ.EÑ+�
˜OÜ'*×'7Ñ'7Ü—J‘J˜Ó/°²a°Ñ8¸:ÀÐ:Wó(Ð$ð "Ð)Ü%(§]¡]Ð3DÓ%EÐ"ð ,7Ð+B�	˜;Ñ'Èˆà�{‰{× Ñ Ø�vÒ, §¡Ð-ÜŸ9™9 ^¸4Ô@Ü!Ÿi™iÐ(9ÀÔFÜ#&§9¡9Ð-CÈ4Ô#PÜ!$§¡Ð+?ÀtÔ!LØ/Ø!5Ø#Ø#˜)Øð !ó 
ð 	
r?   rä   ©NNNNFNN©
NNNNNNNFNN))r¦   r§   r¨   r#   r|  rN  rÙ   r©   Úmain_input_namerO  rP   ÚModuler-   r¬   r   rª   r7   rM   rV  r\  rR   rî   r   r   rp  rc   r   ÚWHISPER_ENCODE_INPUTS_DOCSTRINGr!   r   r­   r   Údictr„  ÚWHISPER_DECODE_INPUTS_DOCSTRINGr   r�  r   ÚWHISPER_INPUTS_DOCSTRINGr‰   Ú__classcell__©rY  s   @r=   rL  rL  ]  s9  ø… Ø €LØ$Ð�sÓ$Ø&€OØ"€L�"—)‘)Ó"ð
 #'ØØŸ;™;ØØ',ñmàðmð ˜3‘Zðmð ð	mð
 �y‰yðmð ðmð !%õmò
ñ! §
¡
× 2Ñ 2ð !Àð !ÐPZð !Ðfpó !òB'1ñR Ð9Ó:ÙÐ+>È]Ô[ð 15Ø,0Ø/3Ø&*ØØØ#ñ4
àŸ™ð4
ð ! §¡Ñ-ð4
ð $ D™>ð	4
ð
 ' t™nð4
ð ˜d‘^ð4
ð ð4
ð ð4
ð ò4
ó \ó ;ð4
ñl Ð9Ó:ÙÐ+XÐgtÔuð
 9=Ø8<Ø6:Ø $Ø,0Ø/3Ø&*ØØØ#ñoð !)¨¯©Ñ 5ð	oð
 !)¨¯©Ñ 5ðoð ' s§{¡{Ñ3ðoð ðoð $ D™>ðoð ' t™nðoð ˜d‘^ðoð ðoð ðoð òoó vó ;ðoñb +Ð+CÓDð
 15Ø8<Ø.2Ø6:Ø,0Ø/3Ø&*ØØØ#ñ/
àŸ™ð/
ð Ÿ;™;ð/
ð ! §¡Ñ-ð	/
ð
 !)¨¯©Ñ 5ð/
ð ˜sŸ{™{Ñ+ð/
ð ' s§{¡{Ñ3ð/
ð $ D™>ð/
ð ' t™nð/
ð ˜d‘^ð/
ð ð/
ð ð/
ð ò/
ó Eô/
r?   rL  zaThe bare Whisper 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)ÚFlaxWhisperModelrB   r7   N)
r¦   r§   r¨   r#   r©   r-   r¬   r7   r8  rO  r”   r?   r=   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<   dZe	ed<   dd„Z
d„ Zd„ Z	 	 	 	 	 	 	 	 dd	ej                  d
ej                  dej                  dej                  de	de	de	de	fd„Zy)Ú)FlaxWhisperForConditionalGenerationModulerB   r7   FrÐ   Nc                 óT  — t        | j                  | j                  | j                  ¬«      | _        t        j                  | j                  j                  d| j                  t        j
                  j                  j                  | j                  j                  «      ¬«      | _        y )NrT  F)rL   r7   rK   )r8  rB   r7   rÐ   rM  rP   rQ   r/  rR   rS   rT   rU   Úlm_headrÈ   s    r=   r_   z/FlaxWhisperForConditionalGenerationModule.setup³  sn   € Ü&Ø—;‘; d§j¡jÈ×IdÑIdô
ˆŒ
ô —x‘xØ�K‰K×"Ñ"ØØ—*‘*ÜŸ™×+Ñ+×2Ñ2°4·;±;×3GÑ3GÓHô	
ˆ�r?   c                 ó.   — | j                   j                  S rä   )rM  r:  rÈ   s    r=   rG  z=FlaxWhisperForConditionalGenerationModule._get_encoder_module¾  ó   € Ø�z‰z×!Ñ!Ð!r?   c                 ó.   — | j                   j                  S rä   )rM  r;  rÈ   s    r=   rJ  z=FlaxWhisperForConditionalGenerationModule._get_decoder_moduleÁ  r¢  r?   r=  r>  r2  rb   rÉ   rà   rá   rd   c           
      óø  — | j                  |||||||	|
¬«      }|d   }| j                  j                  r[| j                   j                  j                  j
                  d   d   }| j                  j                  dd|j                  ii|«      }n| j                  |«      }|	s|f|dd  z   }|S t        ||j                  |j                  |j                  |j                  |j                  |j                  ¬«      S )N)r"  r<  r=  r>  rÉ   rà   rá   rd   r   r^  Ú	embeddingÚkernelr"   )Úlogitsr@  rA  r  rB  rý   rC  )rM  rB   Útie_word_embeddingsr;  r0  rq   r   rƒ  ÚTr   r@  rA  r  rB  rý   rC  )r]   r"  r<  r=  r>  r2  rb   rÉ   rà   rá   rd   rÍ   r`   Úshared_embeddingÚ	lm_logitsÚoutputs                   r=   r‰   z2FlaxWhisperForConditionalGenerationModule.__call__Ä  s  € ð —*‘*Ø)Ø/Ø#9Ø!5Ø/Ø!5Ø#Ø'ð ó 	
ˆð   ™
ˆà�;‰;×*Ò*Ø#Ÿz™z×1Ñ1×>Ñ>×HÑHÈÑRÐS^Ñ_ÐØŸ™×*Ñ*¨H°xÐAQ×ASÑASÐ6TÐ+UÐWdÓe‰IàŸ™ ]Ó3ˆIáØ�\ G¨A¨B KÑ/ˆFØˆMä"ØØ")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô
ð 	
r?   r¥   )NNNNFFTT)r¦   r§   r¨   r#   r©   r-   r¬   r7   rÐ   rM   r_   rG  rJ  r­   r‰   r”   r?   r=   rž  rž  ®  s³   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ó	
ò"ò"ð /3Ø,0Ø$(Ø&*Ø"'Ø%*Ø Ø"ñ,
ð !$§¡ð	,
ð
 "Ÿk™kð,
ð —k‘kð,
ð Ÿ™ð,
ð  ð,
ð #ð,
ð ð,
ð ô,
r?   rž  z0The Whisper Model with a language modeling head.c                   ó�  ‡ — 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ˆ fd„	Z	 	 	 ddeej,                     deej,                     fd„Zd„ Zˆ xZS )Ú#FlaxWhisperForConditionalGenerationr7   rz  rþ   r=  r>  r…  rÉ   rà   rá   r}  r^  rk   c                 óÞ  ‡ — |�|n‰ j                   j                  }|�|n‰ j                   j                  }|	�|	n‰ j                   j                  }	|d   }|j                  \  }}|€Y|�t        d«      ‚|�|j                  d«      |z  dz
  }n2t        j                  t        j                  |«      ddd…f   ||f«      }|€t        j                  ||fd¬«      }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¬«      ||||	|
 |||¬«      }|€|\  }}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 WhisperProcessor, FlaxWhisperForConditionalGeneration
        >>> from datasets import load_dataset

        >>> processor = WhisperProcessor.from_pretrained("openai/whisper-tiny.en")
        >>> model = FlaxWhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny.en", from_pt=True)
        >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> inputs = processor(ds[0]["audio"]["array"], return_tensors="np")
        >>> input_features = inputs.input_features
        >>> encoder_outputs = model.encode(input_features=input_features)
        >>> 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‡  r'   r"   rb  rN   rF   r^  rf   Fc                 óX  •— | j                  «       } |d|||dœ|¤Ž}|d   }‰
j                  j                  r^| j                  j                  j
                  j                  d   d   }| j                  j                  dd|j                  ii|«      }	|	|fS | j                  |«      }	|	|fS )Nr‰  r   r^  r¥  r¦  r”   )
rJ  rB   r¨  rM  r;  r0  rq   r   rƒ  r©  )rX  r<  r=  r>  rW  ru  rÍ   r`   rª  r«  r]   s             €r=   rv  zDFlaxWhisperForConditionalGeneration.decode.<locals>._decoder_forwardE  sÂ   ø€ Ø#×7Ñ7Ó9ˆNÙ$ð Ø+Ø5Ø1ñð ñ	ˆGð $ A™JˆMà�{‰{×.Ò.Ø#)§<¡<×#7Ñ#7×#DÑ#D×#NÑ#NÈxÑ#XÐYdÑ#eÐ Ø"ŸN™N×0Ñ0°(¸XÐGW×GYÑGYÐ<ZÐ1[Ð]jÓk�	ð ˜gÐ%Ð%ð #ŸN™N¨=Ó9�	à˜gÐ%Ð%r?   rŠ  )r§  r`   rí   r  r…  )rB   rÉ   rà   rá   r6   r*   rŒ  r-   rs   r/   rZ   r^  rX  rƒ  r’   r   r`   rí   r  r   )r]   r<  rD  rþ   r=  r>  r…  rÉ   rà   rá   r}  r^  rk   rý   r~   rk  rm  r�  r‹  rv  rÍ   r«  rE  rŽ  s   `                       r=   r�  z*FlaxWhisperForConditionalGeneration.decodeø  s[  ø€ ðN 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆà /°Ñ 2Ðà&7×&=Ñ&=Ñ#ˆ
�OØÐ'ØÐ*Ü Ð!nÓoÐoà%Ð1Ø(>×(EÑ(EÀbÓ(IÐLbÑ(bÐfgÑ'gÑ$ä'*×'7Ñ'7Ü—J‘J˜Ó/°²a°Ñ8¸:ÀÐ:Wó(Ð$ð "Ð)Ü%(§X¡X¨z¸?Ð.KÐSWÔ%XÐ"ð ˆØÐ"Ø)ˆ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Ø/Ø!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                 óD  •— |€| j                   }|�||_        |�||_        |�||_        |�||_        |�d|v rt        |d   «      }	nd}	g }
t        |d«      r«|j                  rŸt        |d«      r+|
j                  d|j                  |j                     f«       n|
j                  d«       t        |d«      r+|
j                  d|j                  |j                     f«       n |
j                  d|j                  d   f«       t        |d	«      r|j                  s|rt        || j                  |	«      g}nC|
rA|
d
   d   |j                  k7  r,|
r|
d
   d   dz   nd}|
j                  ||j                  f«       t        |
«      dkD  r|
|_        t        ‰| �<  ||fd|i|¤ŽS )Nr<  r"   Úis_multilingualÚlanguage)r"   NÚtaskr&   Ú
transcribeÚreturn_timestampsr'   r   Úlogits_processor)Úgeneration_configr¶  r´  r²  r³  r™   ÚhasattrÚappendÚ
lang_to_idÚ
task_to_idr   rB   Úno_timestamps_token_idÚforced_decoder_idsrU  Úgenerate)r]   r"  r¸  r·  r¶  r´  r³  r²  rW  Údecoder_input_lengthr¾  ÚidxrY  s               €r=   r¿  z,FlaxWhisperForConditionalGeneration.generate~  sê  ø€ ð Ð$Ø $× 6Ñ 6ÐàÐ(Ø2CÐÔ/àÐØ%)ÐÔ"àÐ&Ø0?ÐÔ-àÐØ)1ÐÔ&àÐÐ"5¸Ñ"?Ü#& vÐ.AÑ'BÓ#CÑ à#$Ð àÐäÐ$Ð&7Ô8Ð=N×=^Ò=^ÜÐ(¨*Ô5Ø"×)Ñ)¨1Ð.?×.JÑ.JÐK\×KeÑKeÑ.fÐ*gÕhà"×)Ñ)¨)Ô4äÐ(¨&Ô1Ø"×)Ñ)¨1Ð.?×.JÑ.JÐK\×KaÑKaÑ.bÐ*cÕdà"×)Ñ)¨1Ð.?×.JÑ.JÈ<Ñ.XÐ*YÔZô Ð%Ð':Ô;Ð@Q×@cÒ@cÙä3Ð4EÀtÇ{Á{ÐThÓið Ññ "Ð&8¸Ñ&<¸QÑ&?ÐCT×CkÑCkÒ&kÙ7IÐ(¨Ñ,¨QÑ/°!Ò3Èq�Ø"×)Ñ)¨3Ð0A×0XÑ0XÐ*YÔZäÐ!Ó" QÒ&Ø3EÐÔ0ä‰wÑØØñ
ð .ð
ð ñ	
ð 	
r?   rb   c                 óL  — |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 )Nrb  rN   r'   r"   )r   r   )r…  rD  rþ   r=  r>  )	r6   rc   r-   rZ   rŒ  r   rš   rs   r/   )r]   r<  rŸ   rb   r=  rD  rW  r~   Ú
seq_lengthr…  Úextended_attention_maskr2  s               r=   Úprepare_inputs_for_generationzAFlaxWhisperForConditionalGeneration.prepare_inputs_for_generation¿  sº   € ð "3×!8Ñ!8Ñˆ
�JàŸ/™/¨*°jÀ/ÓRˆô #&§(¡(¨J¸
Ð+CÈ4Ô"PÐØ!Ð-Ø1×8Ñ8¸Ó<¸qÑ@ˆ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 )Nr…  r>  r'   r"   )r…  )r]   Úmodel_outputsÚmodel_kwargss      r=   Úupdate_inputs_for_generationz@FlaxWhisperForConditionalGeneration.update_inputs_for_generationÞ  s?   € Ø*7×*GÑ*GˆÐ&Ñ'Ø/;Ð<RÑ/SÒTUÐWYÑWZÐTZÑ/[Ð^_Ñ/_ˆÐ+Ñ,ØÐr?   r’  )NNNNNNr  )r¦   r§   r¨   rž  rO  r-   r¬   r7   r©   r   r—  r!   r   r#   r   r­   r–  rM   r   r�  r¿  rR   ÚArrayrÅ  rÉ  r™  rš  s   @r=   r®  r®  ó  sQ  ø… à<€LØ—{‘{€Eˆ3�9‰9Ó"áÐ9Ó:ÙÐ+PÐ_lÔmð
 9=Ø8<Ø6:Ø $Ø,0Ø/3Ø&*ØØØ#ñBð !)¨¯©Ñ 5ð	Bð
 !)¨¯©Ñ 5ðBð ' s§{¡{Ñ3ðBð ðBð $ D™>ðBð ' t™nðBð ˜d‘^ðBð ðBð ðBð òBó nó ;ðBðN ØØØØØõ?
ðJ /3Ø6:Øñ
ð ! §¡Ñ+ð	
ð
 !)¨¯©Ñ 3ó
ö>r?   r®  al  
    Returns:

    Transcription example:

    ```python
    >>> from transformers import WhisperProcessor, FlaxWhisperForConditionalGeneration
    >>> from datasets import load_dataset

    >>> processor = WhisperProcessor.from_pretrained("openai/whisper-tiny.en")
    >>> model = FlaxWhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny.en", from_pt=True)
    >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
    >>> inputs = processor(ds[0]["audio"]["array"], return_tensors="np")
    >>> input_features = inputs.input_features
    >>> generated_ids = model.generate(input_ids=input_features)
    >>> transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
    >>> transcription
    ' Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel.'
    ```
rz  c                   ó~   — e Zd ZU eed<   ej                  Zej                  ed<   dZe	ed<   d
d„Z
	 	 	 	 dde	de	fd	„Zy)Ú'FlaxWhisperForAudioClassificationModulerB   r7   FrÐ   Nc                 ó
  — t        | j                  | j                  | j                  ¬«      | _        d| j                  _        | j                  j                  dz   }| j                  j                  rt        j                  d|z  |«      | _
        t        j                  | j                  j                  | j                  ¬«      | _        t        j                  | j                  j                  | j                  ¬«      | _        y )NrT  Fr"   rN   )r  rB   r7   rÐ   r:  Úis_encoder_decoderÚnum_hidden_layersÚuse_weighted_layer_sumr-   ÚrepeatÚlayer_weightsrP   rQ   Úclassifier_proj_sizeÚ	projectorÚ
num_labelsÚ
classifier)r]   Ú
num_layerss     r=   r_   z-FlaxWhisperForAudioClassificationModule.setup  s©   € Ü)Ø—;‘; d§j¡jÈ×IdÑIdô
ˆŒð */ˆ�‰Ô&Ø—[‘[×2Ñ2°QÑ6ˆ
Ø�;‰;×-Ò-Ü!$§¡¨A°
©N¸JÓ!GˆDÔÜŸ™ $§+¡+×"BÑ"BÈ$Ï*É*ÔUˆŒÜŸ(™( 4§;¡;×#9Ñ#9ÀÇÁÔLˆ�r?   rà   rá   c                 ó´  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|€| j	                  ||||¬«      }| j                   j
                  rst        j                  |d¬«      }t        j                  j                  | j                  d¬«      }t        j                  |t        j                  |g d¢«      z  d¬«      }n|d   }| j                  |«      }t        j                  |d¬«      }| j!                  |«      }	|s	|	f|dd  z   S t#        |	|j$                  |j&                  ¬«      S )N)rÉ   rà   rá   r"   r(   r'   )r'   r"   r"   r   )r§  r`   rí   )rB   rÉ   rà   Úuse_return_dictr:  rÐ  r-   ÚstackrR   rP   ÚsoftmaxrÒ  Úsumr0   rÔ  ÚmeanrÖ  r   r`   rí   )
r]   r"  rD  rÉ   rà   rá   r`   Únorm_weightsÚpooled_outputr§  s
             r=   r‰   z0FlaxWhisperForAudioClassificationModule.__call__  sB  € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ"Ø"Ÿl™lØØ"3Ø%9Ø'ð	 +ó ˆOð �;‰;×-Ò-ÜŸI™I o¸AÔ>ˆMÜŸ6™6Ÿ>™>¨$×*<Ñ*<À2˜>ÓFˆLÜŸG™G M´C·K±KÀÊjÓ4YÑ$YÐ`aÔb‰Mà+¨AÑ.ˆMàŸ™ }Ó5ˆÜŸ™ °QÔ7ˆà—‘ Ó/ˆáØ�9˜¨q¨rÐ2Ñ2Ð2ä+ØØ)×7Ñ7Ø&×1Ñ1ô
ð 	
r?   r¥   )NNTTrõ   r”   r?   r=   rÌ  rÌ    sR   … ØÓØ—{‘{€Eˆ3�9‰9Ó"Ø#(Ð˜DÓ(ó	Mð ØØ%)Ø ñ)
ð
 #ð)
ð ô)
r?   rÌ  z;The Whisper Model with an audio classification head on top.c                   ó  — e Zd ZU eZej                  Zej                  ed<   dde	j                  j                  dededefd„Z ee«      	 	 	 	 	 	 	 ddej"                  d	eej"                     d
ee   dee   dee   dededefd„«       Zy)Ú!FlaxWhisperForAudioClassificationr7   Nr]  rP  r^  r$   c                 óò  — t        j                  |d¬«      }|j                  d   j                  | j                  j
                  «      }t        j                  j                  |«      \  }}||dœ}| j                  j                  ||¬«      d   }|�dt        t        |«      «      }t        t        |«      «      }| j                  D ]
  }	||	   ||	<   Œ t        «       | _        t        t        |«      «      S |S )Nr`  rN   ra  rc  )r"  r^  )r-   r—   rd  re  rB   rf  rR   rî   rh  rX  ri  r   r   rj  r   r   )
r]   r]  rP  r^  r"  rl  rk   rm  rn  ro  s
             r=   rp  z.FlaxWhisperForAudioClassification.init_weightsB  sï   € äŸ™ ;°dÔ;ˆØ'×*Ñ*¨9Ñ5×9Ñ9¸$¿+¹+×:RÑ:RÓSˆä"%§*¡*×"2Ñ"2°3Ó"7Ñˆ
�KØ$°Ñ=ˆàŸ™×(Ñ(ØØ)ð )ó 
ð ñˆð
 ÐÜ(¬°-Ó)@ÓAˆMÜ!¤(¨6Ó"2Ó3ˆFØ#×1Ñ1ò A�Ø&3°KÑ&@��{Ò#ðAä!$£ˆDÔÜœ.¨Ó0Ó1Ð1à Ð r?   r"  rb   rÉ   rà   rá   r}  rk   c	                 ó<  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }i }
|�||
d<   | j                  j                  d|xs | j                  it        j                  |d¬«      ||||
¬«      S )NrF   r^  r`  rN   )r"  rÉ   rà   rá   rm  r‚  )r]   r"  rb   rÉ   rà   rá   r}  r^  rk   rW  rm  s              r=   r‰   z*FlaxWhisperForAudioClassification.__call__Y  s¯   € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆð ˆØÐ"Ø)ˆD�‰Oà�{‰{× Ñ Ø�vÒ, §¡Ð-ÜŸ9™9 ^¸4Ô@Ø/Ø!5Ø#Øð !ó 
ð 	
r?   rä   r‘  )r¦   r§   r¨   rÌ  rO  r-   r¬   r7   r©   rR   rî   r   r   r   rp  r   r˜  r­   r   rM   r–  r‰   r”   r?   r=   rá  rá  =  sß   … à:€LØ—{‘{€Eˆ3�9‰9Ó"ñ! §
¡
× 2Ñ 2ð !Àð !ÐPZð !Ðfpó !ñ. +Ð+CÓDð 15Ø,0Ø/3Ø&*ØØØ#ñ
àŸ™ð
ð ! §¡Ñ-ð
ð $ D™>ð	
ð
 ' t™nð
ð ˜d‘^ð
ð ð
ð ð
ð ò
ó Eñ
r?   rá  a  
    Returns:

    Transcription example:

    ```python
    >>> import jax.numpy as jnp
    >>> from transformers import AutoFeatureExtractor, FlaxWhisperForAudioClassification
    >>> from datasets import load_dataset

    >>> feature_extractor = AutoFeatureExtractor.from_pretrained("sanchit-gandhi/whisper-medium-fleurs-lang-id")
    >>> model = FlaxWhisperForAudioClassification.from_pretrained(
    ...     "sanchit-gandhi/whisper-medium-fleurs-lang-id", from_pt=True
    ... )
    >>> ds = load_dataset("google/fleurs", "all", split="validation", streaming=True, trust_remote_code=True)

    >>> sample = next(iter(ds))

    >>> inputs = feature_extractor(
    ...     sample["audio"]["array"], sampling_rate=sample["audio"]["sampling_rate"], return_tensors="np"
    ... )
    >>> input_features = inputs.input_features

    >>> logits = model(input_features).logits

    >>> predicted_class_ids = jnp.argmax(logits).item()
    >>> predicted_label = model.config.id2label[predicted_class_ids]
    >>> predicted_label
    'af_za'
    ```
)r®  rœ  rL  rá  )TÚ__doc__r+   rî   Ú	functoolsr   Útypingr   r   Ú
flax.linenÚlinenrP   rR   Ú	jax.numpyÚnumpyr-   Úflax.core.frozen_dictr   r   r   r	   r
   r   Únn_partitioningÚflax.linen.attentionr   Úflax.traverse_utilr   r   r   Ú
jax.randomr   Úgeneration.flax_logits_processr   Úmodeling_flax_outputsr   r   r   r   r   r   Úmodeling_flax_utilsr   r   r   r   r   Úutilsr   r   r    r!   Úconfiguration_whisperr#   Ú
get_loggerr¦   ÚloggerÚ_CHECKPOINT_FOR_DOCÚ_CONFIG_FOR_DOCrÖ   Úfloat_rÊ  r>   ÚWHISPER_START_DOCSTRINGr˜  r•  r—  r”  rA   r°   rÏ   r÷   r  r  r-  r8  rL  rœ  rž  r®  Ú-FLAX_WHISPER_CONDITIONAL_GENERATION_DOCSTRINGrÌ  rá  Ú+FLAX_WHISPER_AUDIO_CLASSIFICATION_DOCSTRINGÚ__all__r”   r?   r=   ú<module>rþ     s  ðñ ã Û Ý ß "å Û 
Ý ß >Ñ >ß 6Ý 6Ý >ß ;Ý Ý å Q÷÷ ÷õ ÷ uÓ tÝ 0ð 
ˆ×	Ñ	˜HÓ	%€ð ,Ð Ø!€à×Ñ€ð 14·
±
ñ 
_¸s¿y¹yó 
_ðÐ ð2#Ð ðJ#Ð ð*#Ð ôD\*˜2Ÿ9™9ô \*ô@5˜bŸi™iô 5ôp;
¨¯	©	ô ;
ô~U˜bŸi™iô UôpK
¨¯	©	ô K
ô\[
˜Ÿ™ô [
ô|@
˜Ÿ™ô @
ôF<˜Ÿ	™	ô <ô~A
Ð!4ô A
ñH
 ØgØóô%Ð1ó %ó	ð%ñ Ð-Ð/BÐDZÐ\kÔ lôB
°·	±	ô B
ñJ ÐHÐJaÓbômÐ*Dó mó cðmð`1Ð -ñ* Ø'Ð)AÐDqÑ)qôñ !Ø'Ð5HÐWfõô
9
¨b¯i©iô 9
ñx ÐSÐUlÓmô:
Ð(Bó :
ó nð:
ðz/Ð +ñ@ Ø%Ð'?ÐBmÑ'môñ !Ø%Ð3OÐ^mõò
�r?   