§
    ‚Štj\  ã                   ó–  — d dl Z d dlmZ d dlZd dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZ d dlmZ 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 ddlmZmZ ddlmZ ddlm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7  e#j8        e9¦  «        Z: G d„ de7e¦  «        Z; G d„ ded¬¦  «        Z<e! G d„ de¦  «        ¦   «         Z= e!d¬¦  «        e G d „ d!e/¦  «        ¦   «         ¦   «         Z> e!d¬¦  «        e G d"„ d#e.¦  «        ¦   «         ¦   «         Z? G d$„ d%ej@        ¦  «        ZA G d&„ d'e*¦  «        ZB G d(„ d)e)¦  «        ZC G d*„ d+e2¦  «        ZD G d,„ d-e1¦  «        ZE G d.„ d/e5¦  «        ZF G d0„ d1e3¦  «        ZG e!d2¬3¦  «         G d4„ d5eF¦  «        ¦   «         ZH G d6„ d7e4¦  «        ZIg d8¢ZJdS )9é    N)ÚCallable)Ústrict)Ú	TokenizerÚdecodersÚnormalizersÚpre_tokenizersÚ
processors)ÚUnigram)Únné   )Ú
AudioInputÚmake_list_of_audio)Úcreate_bidirectional_mask)ÚALL_ATTENTION_FUNCTIONS)ÚProcessingKwargsÚProcessorMixinÚUnpack)ÚPreTokenizedInputÚ	TextInput)ÚTokenizersBackend)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚlogging)Úmerge_with_config_defaults)Úcapture_outputsé   )ÚLlamaAttentionÚLlamaRotaryEmbeddingÚapply_rotary_pos_embÚeager_attention_forward)ÚParakeetCTCConfigÚParakeetEncoderConfig)ÚParakeetEncoderBlockÚ ParakeetEncoderConvolutionModuleÚParakeetEncoderModelOutputÚParakeetForCTCÚParakeetPreTrainedModel)ÚT5Tokenizerc                   ób   — e Zd Z	 	 	 	 	 	 	 	 dd„Z	 	 	 dd	eee         z  d
ededz  dedef
d„ZdS )ÚLasrTokenizerú</s>ú<unk>ú<pad>Néd   c	           	      ó   — || _         |�ld„ |D ¦   «         }
t          |
¦  «        dk     r|d„ t          |¦  «        D ¦   «         z  }nK|dk    r)|t          |
¦  «        k    rt          d|› d|› d�¦  «        ‚nd„ t          |¦  «        D ¦   «         }
|
}|�|| _        not          |¦  «        d	ft          |¦  «        d	ft          |¦  «        d	fd
g| _        t          |dz
  dd¦  «        D ]"}| j                             d|› d�d	f¦  «         Œ#t          t          | j        dd¬¦  «        ¦  «        | _	        |�t          j        |¦  «        | j	        _        t          j        t          j        ¦   «         t          j        ddd¬¦  «        g¦  «        | j	        _        t%          j        ddd¬¦  «        | j	        _        t)          j        d|||||dœ|	¤Ž t-          j        ddgg d¢d| j        fg¬¦  «        | j	        _        d S )Nc                 ó4   — g | ]}d t          |¦  «        v ¯|‘ŒS )ú
<extra_id_)Ústr)Ú.0Úxs     úc/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/models/lasr/modular_lasr.pyú
<listcomp>z*LasrTokenizer.__init__.<locals>.<listcomp>A   s,   € Ð[Ð[Ð[ !ÀLÕTWÐXYÑTZÔTZÐDZÐDZ˜AÐDZÐDZÐDZó    é   c                 ó   — g | ]}d |› d�‘Œ	S ©r2   ú>© ©r4   Úis     r6   r7   z*LasrTokenizer.__init__.<locals>.<listcomp>C   s$   € Ð-ZÐ-ZÐ-ZÀAÐ.?¸1Ð.?Ð.?Ð.?Ð-ZÐ-ZÐ-Zr8   r   zBoth extra_ids (z!) and additional_special_tokens (zm) are provided to LasrTokenizer. In this case the additional_special_tokens must include the extra_ids tokensc                 ó   — g | ]}d |› d�‘Œ	S r;   r=   r>   s     r6   r7   z*LasrTokenizer.__init__.<locals>.<listcomp>K   s$   € ÐHÐHÐH°!Ð-¨Ð-Ð-Ð-ÐHÐHÐHr8   ç        )õ   â–�g       Àéÿÿÿÿr2   r<   r   F)Úunk_idÚbyte_fallbackrB   ÚalwaysT)ÚreplacementÚprepend_schemeÚsplit)Ú	eos_tokenÚ	unk_tokenÚ	pad_tokenÚ	extra_idsÚadditional_special_tokensú$Ar,   )rO   r,   z$Br,   )ÚsingleÚpairÚspecial_tokensr=   )Ú
_extra_idsÚlenÚrangeÚ
ValueErrorÚ_vocab_scoresr3   Úappendr   r
   Ú
_tokenizerr   ÚPrecompiledÚ
normalizerr   ÚSequenceÚWhitespaceSplitÚ	MetaspaceÚpre_tokenizerr   Údecoderr   Ú__init__r	   ÚTemplateProcessingÚeos_token_idÚpost_processor)ÚselfrJ   rK   rL   Ú_spm_precompiled_charsmaprM   rN   ÚvocabÚ
vocab_fileÚkwargsÚextra_tokensr?   s               r6   ra   zLasrTokenizer.__init__1   s•  € ð $ˆŒð %Ð0Ø[Ð[Ð'@Ð[Ñ[Ô[ˆLÝ�<Ñ Ô  1Ò$Ð$Ø)Ð-ZÐ-ZÍÈyÑIYÔIYÐ-ZÑ-ZÔ-ZÑZÐ)Ð)Ø˜Q’� 9µ°LÑ0AÔ0AÒ#AÐ#AÝ ð yð ð ÐSlð ð ð ñô ð øð IÐHµu¸YÑ7GÔ7GÐHÑHÔHˆLØ(4Ð%ð ÐØ!&ˆDÔÐõ �Y‘” Ð%Ý�Y‘” Ð%Ý�Y‘” Ð%Øð	"ˆDÔõ ˜9 q™=¨"¨bÑ1Ô1ð Dð D�ØÔ"×)Ò)Ð+<¸Ð+<Ð+<Ð+<¸cÐ*BÑCÔCÐCÐCÝ#ÝØÔ"ØØ#ðñ ô ñ
ô 
ˆŒð %Ð0Ý)4Ô)@ÐAZÑ)[Ô)[ˆDŒOÔ&å(6Ô(?åÔ.Ñ0Ô0ÝÔ(°UÈ8Ð[_Ð`Ñ`Ô`ðñ)
ô )
ˆŒÔ%õ #+Ô"4ÀÐW_ÐgkÐ"lÑ"lÔ"lˆŒÔåÔ"ð 	
ØØØØØ&?ð	
ð 	
ð ð	
ð 	
ð 	
õ *4Ô)FØ˜&�>Ø-Ð-Ð-à˜Ô*Ð+ðð*
ñ *
ô *
ˆŒÔ&Ð&Ð&r8   FTÚ	token_idsÚskip_special_tokensÚclean_up_tokenization_spacesÚgroup_tokensÚreturnc                 ó¼   ‡ — t          |t          ¦  «        r|g}|rd„ t          j        |¦  «        D ¦   «         }ˆ fd„|D ¦   «         }t	          j        ‰ f|||dœ|¤ŽS )Nc                 ó   — g | ]
}|d          ‘ŒS )r   r=   )r4   Útoken_groups     r6   r7   z)LasrTokenizer._decode.<locals>.<listcomp>‰   s   € ÐXÐXÐX¨K˜ QœÐXÐXÐXr8   c                 ó*   •— g | ]}|‰j         k    ¯|‘ŒS r=   )Úpad_token_id)r4   Útokenre   s     €r6   r7   z)LasrTokenizer._decode.<locals>.<listcomp>Œ   s&   ø€ ÐPÐPÐP˜u°U¸dÔ>OÒ5OÐ5O�UÐ5OÐ5OÐ5Or8   )rk   rl   rm   )Ú
isinstanceÚintÚ	itertoolsÚgroupbyr   Ú_decode)re   rk   rl   rm   rn   ri   s   `     r6   rz   zLasrTokenizer._decode~   s–   ø€ õ �i¥Ñ%Ô%ð 	$Ø"˜ˆIØð 	YØXÐX½9Ô;LÈYÑ;WÔ;WÐXÑXÔXˆIð QÐPÐPÐP¨	ÐPÑPÔPˆ	å Ô(Øð
àØ 3Ø)Eð	
ð 
ð
 ð
ð 
ð 	
r8   )r,   r-   r.   Nr/   NNN)FNT)	Ú__name__Ú
__module__Ú__qualname__ra   rw   ÚlistÚboolr3   rz   r=   r8   r6   r+   r+   0   s§   € € € € € ð ØØØ"&ØØ"&ØØðK
ð K
ð K
ð K
ð` %*Ø48Ø!ð
ð 
à˜˜cœ‘?ð
ð "ð
ð '+¨T¡kð	
ð
 ð
ð 
ð
ð 
ð 
ð 
ð 
ð 
r8   r+   c                   ó.   — e Zd Zddddœddddœdd	id
œZdS )ÚLasrProcessorKwargsi€>  ÚlongestT)Úsampling_rateÚpaddingÚreturn_attention_maskÚrightF)r„   Úpadding_sideÚadd_special_tokensÚreturn_tensorsÚpt)Úaudio_kwargsÚtext_kwargsÚcommon_kwargsN)r{   r|   r}   Ú	_defaultsr=   r8   r6   r�   r�   —   sN   € € € € € ð #Ø Ø%)ð
ð 
ð Ø#Ø"'ð
ð 
ð
 +¨DÐ1ðð €I€I€Ir8   r�   F)Útotalc                   ó¤   ‡ — e Zd Zˆ fd„Ze	 	 d	dedeez  ee         z  ee         z  dz  de	dz  de
e         fd„¦   «         Zed„ ¦   «         Zˆ xZS )
ÚLasrProcessorc                 óL   •— t          ¦   «                              ||¦  «         d S ©N)Úsuperra   )re   Úfeature_extractorÚ	tokenizerÚ	__class__s      €r6   ra   zLasrProcessor.__init__©   s$   ø€ Ý‰Œ×ÒÐ*¨IÑ6Ô6Ð6Ð6Ð6r8   NÚaudioÚtextrƒ   ri   c                 óš  — t          |¦  «        } | j        t          fd| j        j        i|¤Ž}|€+t
                               d|d         d         › d�¦  «         n4||d         d         k    r"t          d|› d|d         d         › d	�¦  «        ‚|� | j        |fi |d         ¤Ž}|� | j        |fi |d
         ¤Ž}|€|S |d         |d<   |S )aÊ  
        sampling_rate (`int`, *optional*):
            The sampling rate of the input audio in Hz. This should match the sampling rate expected by the feature
            extractor (defaults to 16000 Hz). If provided, it will be validated against the processor's expected
            sampling rate, and an error will be raised if they don't match. If not provided, a warning will be
            issued and the default sampling rate will be assumed.
        Útokenizer_init_kwargsNzUYou've provided audio without specifying the sampling rate. It will be assumed to be r‹   rƒ   z$, which can result in silent errors.z The sampling rate of the audio (z5) does not match the sampling rate of the processor (zD). Please provide resampled the audio to the expected sampling rate.rŒ   Ú	input_idsÚlabels)	r   Ú_merge_kwargsr�   r–   Úinit_kwargsÚloggerÚwarning_oncerV   r•   )re   r˜   r™   rƒ   ri   Úoutput_kwargsÚinputsÚ	encodingss           r6   Ú__call__zLasrProcessor.__call__¬   s{  € õ # 5Ñ)Ô)ˆà*˜Ô*Ýð
ð 
à"&¤.Ô"<ð
ð ð
ð 
ˆð Ð Ý×Òð }Ðhuð  wEô  iFð  GVô  iWð  }ð  }ð  }ñô ð ð ð ˜m¨NÔ;¸OÔLÒLÐLÝð l°=ð  lð  lð  xEð  FTô  xUð  Veô  xfð  lð  lð  lñô ð ð ÐØ+�TÔ+¨EÐSÐS°]À>Ô5RÐSÐSˆFØÐØ&˜œ tÐLÐL¨}¸]Ô/KÐLÐLˆIàˆ<ØˆMà(¨Ô5ˆF�8ÑØˆMr8   c                 ó&   — | j         j        }|dgz   S )Nr�   )r•   Úmodel_input_names)re   Úfeature_extractor_input_namess     r6   r§   zLasrProcessor.model_input_names×   s   € à(,Ô(>Ô(PÐ%Ø,°¨zÑ9Ð9r8   ©NN)r{   r|   r}   ra   r   r   r   r   r~   rw   r   r�   r¥   Úpropertyr§   Ú__classcell__©r—   s   @r6   r‘   r‘   §   sÓ   ø€ € € € € ð7ð 7ð 7ð 7ð 7ð ð bfØ$(ð	(ð (àð(ð Ð+Ñ+¨d°9¬oÑ=ÀÐEVÔ@WÑWÐZ^Ñ^ð(ð ˜T‘zð	(ð
 Ð,Ô-ð(ð (ð (ñ „^ð(ðT ð:ð :ñ „Xð:ð :ð :ð :ð :r8   r‘   zgoogle/medasr)Ú
checkpointc                   óJ  — e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	e
ed	<   dZe
ed
<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZee         eedf         z  ed<   dZee         eedf         z  ed<   dZeed<   dZedz  ed<    e¦   «         Z e¦   «         ZdS )ÚLasrEncoderConfiga  
    convolution_bias (`bool`, *optional*, defaults to `False`):
        Whether to use bias in convolutions of the conformer's convolution module.
    conv_kernel_size (`int`, *optional*, defaults to 32):
        The kernel size of the convolution layers in the Conformer block.
    subsampling_conv_channels (`int`, *optional*, defaults to 256):
        The number of channels in the subsampling convolution layers.
    subsampling_conv_kernel_size (`int`, *optional*, defaults to 5):
        The kernel size of the subsampling convolution layers.
    subsampling_conv_stride (`int`, *optional*, defaults to 2):
        The stride of the subsampling convolution layers.
    dropout_positions (`float`, *optional*, defaults to 0.0):
        The dropout ratio for the positions in the input sequence.
    feed_forward_residual_weights (`tuple[float, float]`, *optional*, defaults to `[1.5, 0.5]`):
        The residual weights for the feed forward layers.
    conv_residual_weights (`tuple[float, float]`, *optional*, defaults to `[2.0, 1.0]`):
        The residual weights for the convolution layers.
    batch_norm_momentum (`float`, *optional*, defaults to 0.01):
        The momentum for the batch normalization layers

    Example:
    ```python
    >>> from transformers import LasrEncoderModel, LasrEncoderConfig

    >>> # Initializing a `LasrEncoder` configuration
    >>> configuration = LasrEncoderConfig()

    >>> # Initializing a model from the configuration
    >>> model = LasrEncoderModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```

    This configuration class is based on the LasrEncoder architecture from Google Health AI. You can find more details
    and pre-trained models at [google/medasr](https://huggingface.co/google/medasr).
    é   Úhidden_sizeé   Únum_hidden_layersi   Úintermediate_sizeFÚattention_biasÚconvolution_biasé    Úconv_kernel_sizeé   Úsubsampling_conv_kernel_sizeé€   Únum_mel_binsi'  Úmax_position_embeddingsg�íµ ÷Æ°>Úlayer_norm_eps)g      ø?g      à?.Úfeed_forward_residual_weights)g       @g      ð?Úconv_residual_weightsg{®Gáz„?Úbatch_norm_momentumNÚrope_parameters)r{   r|   r}   Ú__doc__r±   rw   Ú__annotations__r³   r´   rµ   r   r¶   r¸   rº   r¼   r½   r¾   Úfloatr¿   r~   ÚtuplerÀ   rÁ   rÂ   ÚdictÚAttributeErrorÚsubsampling_factorÚscale_inputr=   r8   r6   r¯   r¯   Ý   sI  € € € € € € ð$ð $ðL €K�ÐÐÑØÐ�sÐÐÑØ!Ð�sÐ!Ð!Ñ!Ø €N�DÐ Ð Ñ Ø"Ð�dÐ"Ð"Ñ"ØÐ�cÐÐÑØ()Ð  #Ð)Ð)Ñ)Ø€L�#ÐÐÑØ#(Ð˜SÐ(Ð(Ñ(Ø €N�EÐ Ð Ñ ØEOÐ! 4¨¤;°°u¸c°zÔ1BÑ#BÐOÐOÑOØ=GÐ˜4 œ;¨¨u°c¨zÔ):Ñ:ÐGÐGÑGØ!%Ð˜Ð%Ð%Ñ%Ø#'€O�T˜D‘[Ð'Ð'Ñ'à'˜Ñ)Ô)ÐØ �.Ñ"Ô"€K€K€Kr8   r¯   c                   óF   — e Zd ZU dZdZeed<   dZeed<   ed„ ¦   «         Z	dS )ÚLasrCTCConfigaE  
    ctc_loss_reduction (`str`, *optional*, defaults to `"mean"`):
        Specifies the reduction to apply to the output of `torch.nn.CTCLoss`. Only relevant when training an
        instance of [`LasrForCTC`].
    ctc_zero_infinity (`bool`, *optional*, defaults to `True`):
        Whether to zero infinite losses and the associated gradients of `torch.nn.CTCLoss`. Infinite losses mainly
        occur when the inputs are too short to be aligned to the targets. Only relevant when training an instance
        of [`LasrForCTC`].

    Example:
    ```python
    >>> from transformers import LasrForCTC, LasrCTCConfig
    >>> # Initializing a Lasr configuration
    >>> configuration = LasrCTCConfig()
    >>> # Initializing a model from the configuration
    >>> model = LasrForCTC(configuration)
    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```
    This configuration class is based on the Lasr CTC architecture from Google Health AI. You can find more details
    and pre-trained models at [google/medasr](https://huggingface.co/google/medasr).
    r°   Ú
vocab_sizer   rt   c                 ó    — | j         j        dz  S )Nr   )Úencoder_configÚsubsampling_conv_stride)re   s    r6   Úinputs_to_logits_ratioz$LasrCTCConfig.inputs_to_logits_ratio6  s   € àÔ"Ô:¸AÑ=Ð=r8   N)
r{   r|   r}   rÃ   rÍ   rw   rÄ   rt   rª   rÑ   r=   r8   r6   rÌ   rÌ     s[   € € € € € € ðð ð. €J�ÐÐÑØ€L�#ÐÐÑàð>ð >ñ „Xð>ð >ð >r8   rÌ   c                   óH   ‡ — e Zd Zdefˆ fd„Zdej        dej        fd„Zˆ xZS )ÚLasrEncoderSubsamplingÚconfigc                 óÌ  •— t          ¦   «                              ¦   «          t          j        |j        |j        ¦  «        | _        t          j        |j        |j        |j        |j	        ¬¦  «        | _
        t          j        |j        |j        |j        |j	        ¬¦  «        | _        t          j        |j        |j        ¦  «        | _        t          j        ¦   «         | _        d S )N)Úkernel_sizeÚstride)r”   ra   r   ÚLinearr¼   r±   Údense_0ÚConv1drº   rÐ   Úconv_0Úsubsampling_conv_channelsÚconv_1Údense_1ÚReLUÚact_fn©re   rÔ   r—   s     €r6   ra   zLasrEncoderSubsampling.__init__<  sÀ   ø€ Ý‰Œ×ÒÑÔÐÝ”y Ô!4°fÔ6HÑIÔIˆŒÝ”iØÔØÔØÔ;ØÔ1ð	
ñ 
ô 
ˆŒõ ”iØÔØÔ,ØÔ;ØÔ1ð	
ñ 
ô 
ˆŒõ ”y Ô!AÀ6ÔCUÑVÔVˆŒÝ”g‘i”iˆŒˆˆr8   Úinput_featuresro   c                 ót  — |                       |                      |¦  «        ¦  «        }|                     dd¦  «        }|                       |                      |¦  «        ¦  «        }|                       |                      |¦  «        ¦  «        }|                     dd¦  «        }|                      |¦  «        S )Nr9   r   )rà   rÙ   Ú	transposerÛ   rÝ   rÞ   )re   râ   Úhidden_statess      r6   ÚforwardzLasrEncoderSubsampling.forwardN  s•   € ØŸš D§L¢L°Ñ$@Ô$@ÑAÔAˆØ%×/Ò/°°1Ñ5Ô5ˆØŸš D§K¢K°Ñ$>Ô$>Ñ?Ô?ˆØŸš D§K¢K°Ñ$>Ô$>Ñ?Ô?ˆØ%×/Ò/°°1Ñ5Ô5ˆØ�|Š|˜MÑ*Ô*Ð*r8   )	r{   r|   r}   r¯   ra   ÚtorchÚTensorræ   r«   r¬   s   @r6   rÓ   rÓ   ;  sk   ø€ € € € € ð Ð0ð  ð  ð  ð  ð  ð  ð$+ e¤lð +°u´|ð +ð +ð +ð +ð +ð +ð +ð +r8   rÓ   c                   ó   — e Zd ZdS )ÚLasrEncoderRotaryEmbeddingN©r{   r|   r}   r=   r8   r6   rê   rê   W  s   € € € € € € € r8   rê   c                   ó¾   ‡ — e Zd Zdedefˆ fd„Z	 	 ddej        deej        ej        f         dz  dej        dz  de	e
         d	eej        ej        f         f
d
„Zˆ xZS )ÚLasrEncoderAttentionrÔ   Ú	layer_idxc                 óZ   •— t          ¦   «                              ||¦  «         d| _        d S )NF)r”   ra   Ú	is_causal©re   rÔ   rî   r—   s      €r6   ra   zLasrEncoderAttention.__init__[  s(   ø€ Ý‰Œ×Ò˜ Ñ+Ô+Ð+ØˆŒˆˆr8   Nrå   Úposition_embeddingsÚattention_maskri   ro   c                 óà  — |j         d d…         }g |¢d‘| j        ‘R }|                      |¦  «                             |¦  «                             dd¦  «        }|                      |¦  «                             |¦  «                             dd¦  «        }|                      |¦  «                             |¦  «                             dd¦  «        }	|\  }
}t          |||
|¦  «        \  }}t          j	        | j
        j        t          ¦  «        } || |||	|f| j        sdn| j        | j        dœ|¤Ž\  }} |j        g |¢d‘R Ž                      ¦   «         }|                      |¦  «        }||fS )NrC   r9   r   rA   )ÚdropoutÚscaling)ÚshapeÚhead_dimÚq_projÚviewrä   Úk_projÚv_projr    r   Úget_interfacerÔ   Ú_attn_implementationr!   ÚtrainingÚattention_dropoutrö   ÚreshapeÚ
contiguousÚo_proj)re   rå   rò   ró   ri   Úinput_shapeÚhidden_shapeÚquery_statesÚ
key_statesÚvalue_statesÚcosÚsinÚattention_interfaceÚattn_outputÚattn_weightss                  r6   ræ   zLasrEncoderAttention.forward_  sš  € ð $Ô)¨#¨2¨#Ô.ˆØ8˜Ð8 bÐ8¨$¬-Ð8Ð8ˆà—{’{ =Ñ1Ô1×6Ò6°|ÑDÔD×NÒNÈqÐRSÑTÔTˆØ—[’[ Ñ/Ô/×4Ò4°\ÑBÔB×LÒLÈQÐPQÑRÔRˆ
Ø—{’{ =Ñ1Ô1×6Ò6°|ÑDÔD×NÒNÈqÐRSÑTÔTˆà&‰ˆˆSÝ#7¸ÀjÐRUÐWZÑ#[Ô#[Ñ ˆ�jå(?Ô(MØŒKÔ,Õ.Eñ)
ô )
Ðð %8Ð$7ØØØØØð	%
ð  $œ}ÐH�C�C°$Ô2HØ”Lð	%
ð 	%
ð ð	%
ð 	%
Ñ!ˆ�\ð *�kÔ)Ð;¨;Ð;¸Ð;Ð;Ð;×FÒFÑHÔHˆØ—k’k +Ñ.Ô.ˆØ˜LÐ(Ð(r8   r©   )r{   r|   r}   r¯   rw   ra   rç   rè   rÆ   r   r   ræ   r«   r¬   s   @r6   rí   rí   Z  sÏ   ø€ € € € € ðÐ0ð ¸Sð ð ð ð ð ð ð IMØ.2ð	")ð ")à”|ð")ð # 5¤<°´Ð#=Ô>ÀÑEð")ð œ tÑ+ð	")ð
 Ð+Ô,ð")ð 
ˆuŒ|˜Uœ\Ð)Ô	*ð")ð ")ð ")ð ")ð ")ð ")ð ")ð ")r8   rí   c                   ó&   ‡ — e Zd Zddefˆ fd„Zˆ xZS )ÚLasrEncoderConvolutionModuleNrÔ   c                 ó¤   •— t          ¦   «                              ||¦  «         d| _        t          j        |j        |j        ¬¦  «        | _        d S )NÚsame)Úmomentum)r”   ra   r„   r   ÚBatchNorm1dr±   rÁ   Únorm)re   rÔ   Úmodule_configr—   s      €r6   ra   z%LasrEncoderConvolutionModule.__init__…  sD   ø€ Ý‰Œ×Ò˜ Ñ/Ô/Ð/ØˆŒÝ”N 6Ô#5ÀÔ@ZÐ[Ñ[Ô[ˆŒ	ˆ	ˆ	r8   r“   )r{   r|   r}   r¯   ra   r«   r¬   s   @r6   r  r  „  sV   ø€ € € € € ð\ð \Ð0ð \ð \ð \ð \ð \ð \ð \ð \ð \ð \r8   r  c                   óŠ   ‡ — e Zd Zdedefˆ fd„Z	 	 ddej        dej        dz  dej        dz  dee	         d	ej        f
d
„Z
ˆ xZS )ÚLasrEncoderBlockrÔ   rî   c                 óø  •— t          ¦   «                              ||¦  «         |j        | _        |j        | _        t	          j        |j        |j        d¬¦  «        | _        t	          j        |j        |j        d¬¦  «        | _	        t	          j        |j        |j        d¬¦  «        | _
        t	          j        |j        |j        d¬¦  «        | _        t	          j        |j        |j        d¬¦  «        | _        d S )NF)Úbias)r”   ra   r¿   rÀ   r   Ú	LayerNormr±   r¾   Únorm_feed_forward1Únorm_self_attÚ	norm_convÚnorm_feed_forward2Únorm_outrñ   s      €r6   ra   zLasrEncoderBlock.__init__Œ  sÕ   ø€ Ý‰Œ×Ò˜ Ñ+Ô+Ð+à-3Ô-QˆÔ*Ø%+Ô%AˆÔ"å"$¤,¨vÔ/AÀ6ÔCXÐ_dÐ"eÑ"eÔ"eˆÔÝœ\¨&Ô*<¸fÔ>SÐZ_Ð`Ñ`Ô`ˆÔÝœ fÔ&8¸&Ô:OÐV[Ð\Ñ\Ô\ˆŒÝ"$¤,¨vÔ/AÀ6ÔCXÐ_dÐ"eÑ"eÔ"eˆÔÝœ VÔ%7¸Ô9NÐUZÐ[Ñ[Ô[ˆŒˆˆr8   Nrå   ró   rò   ri   ro   c                 óN  — |}|                       |                      |¦  «        ¦  «        }| j        d         |z  | j        d         |z  z   }|                      |¦  «        } | j        d|||dœ|¤Ž\  }}||z   }|                      |                      |¦  «        |¬¦  «        }	| j        d         |z  | j        d         |	z  z   }|}|                      |  	                    |¦  «        ¦  «        }| j        d         |z  | j        d         |z  z   }|  
                    |¦  «        }|S )Nr   r9   )rå   ró   rò   )ró   r=   )Úfeed_forward1r  r¿   r  Ú	self_attnÚconvr  rÀ   Úfeed_forward2r  r  )
re   rå   ró   rò   ri   ÚresidualÚnormalized_hidden_statesr  Ú_Úconv_outputs
             r6   ræ   zLasrEncoderBlock.forward˜  sX  € ð !ˆØ×*Ò*¨4×+BÒ+BÀ=Ñ+QÔ+QÑRÔRˆàÔ.¨qÔ1°HÑ<¸tÔ?aÐbcÔ?dÐgtÑ?tÑtð 	ð $(×#5Ò#5°mÑ#DÔ#DÐ Ø'˜œð 
Ø2Ø)Ø 3ð
ð 
ð ð	
ð 
‰ˆ�Qð &¨Ñ3ˆà—i’i §¢¨}Ñ =Ô =Èn�iÑ]Ô]ˆØÔ2°1Ô5¸ÑEÈÔHbÐcdÔHeÐhsÑHsÑsˆà ˆØ×*Ò*¨4×+BÒ+BÀ=Ñ+QÔ+QÑRÔRˆàÔ.¨qÔ1°HÑ<¸tÔ?aÐbcÔ?dÐgtÑ?tÑtð 	ð Ÿš mÑ4Ô4ˆàÐr8   r©   )r{   r|   r}   r¯   rw   ra   rç   rè   r   r   ræ   r«   r¬   s   @r6   r  r  ‹  s½   ø€ € € € € ð
\Ð0ð 
\¸Sð 
\ð 
\ð 
\ð 
\ð 
\ð 
\ð /3Ø37ð	!ð !à”|ð!ð œ tÑ+ð!ð #œ\¨DÑ0ð	!ð
 Ð+Ô,ð!ð 
Œð!ð !ð !ð !ð !ð !ð !ð !r8   r  c                   ó.   — e Zd ZdZd„ Zdej        fd„ZdS )ÚLasrPreTrainedModelFc                 ó    — t          d¦  «        ‚)NzNormal super call)rÈ   )re   Úmodules     r6   Ú_init_weightsz!LasrPreTrainedModel._init_weightsÀ  s   € ÝÐ0Ñ1Ô1Ð1r8   Úinput_lengthsc                 óº   — t          | j        t          ¦  «        r| j        j        n| j        }|j        }|j        }d}t          |¦  «        D ]}||z
  |z  dz   }Œ|S )Nr   r9   )rv   rÔ   rÌ   rÏ   rº   rÐ   rU   )re   r.  rÏ   rÖ   r×   Ú
num_layersr'  s          r6   Ú_get_subsampling_output_lengthz2LasrPreTrainedModel._get_subsampling_output_lengthÃ  sp   € Ý7AÀ$Ä+Í}Ñ7]Ô7]Ðn˜œÔ3Ð3ÐcgÔcnˆØ$ÔAˆØÔ7ˆàˆ
Ý�zÑ"Ô"ð 	Hð 	HˆAØ*¨[Ñ8¸VÑCÀaÑGˆMˆMàÐr8   N)r{   r|   r}   Ú_supports_flex_attnr-  rç   rè   r1  r=   r8   r6   r*  r*  ¼  sF   € € € € € àÐð2ð 2ð 2ð	¸E¼Lð 	ð 	ð 	ð 	ð 	ð 	r8   r*  c                   ó   — e Zd ZdS )ÚLasrEncoderModelOutputNrë   r=   r8   r6   r4  r4  Ï  s   € € € € € Ø€Dr8   r4  zh
    The LasrEncoder model, based on the Conformer architecture](https://arxiv.org/abs/2005.08100).
    )Úcustom_introc                   óÂ   ‡ — e Zd ZU eed<   dZdefˆ fd„Zeee	e
	 	 ddej        dej        dz  dedz  dee         d	ef
d
„¦   «         ¦   «         ¦   «         ¦   «         Zˆ xZS )ÚLasrEncoderrÔ   Úencoderc                 óÔ  •‡— t          ¦   «                              ‰¦  «         d| _        ‰j        | _        ‰j        | _        ‰j        | _        t          ‰¦  «        | _        t          ‰¦  «        | _	        t          j        ˆfd„t          ‰j        ¦  «        D ¦   «         ¦  «        | _        t          j        ‰j        ‰j        d¬¦  «        | _        |                      ¦   «          d S )NFc                 ó0   •— g | ]}t          ‰|¦  «        ‘ŒS r=   )r  )r4   rî   rÔ   s     €r6   r7   z(LasrEncoder.__init__.<locals>.<listcomp>ç  s$   ø€ ÐbÐbÐb°YÕ˜f iÑ0Ô0ÐbÐbÐbr8   )Úepsr  )r”   ra   Úgradient_checkpointingrõ   Údropout_positionsÚ	layerdroprÓ   Ú
subsamplerrê   Ú
rotary_embr   Ú
ModuleListrU   r³   Úlayersr  r±   r¾   Úout_normÚ	post_initrá   s    `€r6   ra   zLasrEncoder.__init__Ü  sÌ   øø€ Ý‰Œ×Ò˜Ñ Ô Ð Ø&+ˆÔ#à”~ˆŒØ!'Ô!9ˆÔØÔ)ˆŒå0°Ñ8Ô8ˆŒÝ4°VÑ<Ô<ˆŒÝ”mØbÐbÐbÐbÅ%ÈÔH`ÑBaÔBaÐbÑbÔbñ
ô 
ˆŒõ œ VÔ%7¸VÔ=RÐY^Ð_Ñ_Ô_ˆŒà�ŠÑÔÐÐÐr8   Nrâ   ró   Úoutput_attention_maskri   ro   c                 óV  — |                       |¦  «        }|                      |t          j        |j        d         |j        ¬¦  «                             d¦  «        ¦  «        \  }}t          j         	                    || j	        | j
        ¬¦  «        }t          j         	                    || j        | j
        ¬¦  «        }t          j         	                    || j        | j
        ¬¦  «        }d}|�$|                      ||j        d         ¬¦  «        }|}t          | j        ||¬¦  «        }| j        D ]<}	d}
| j
        r!t          j        g ¦  «        }|| j        k     rd	}
|
s |	|f|||fd
œ|¤Ž}Œ=|                      |¦  «        }t'          ||r|�|                     ¦   «         nd¬¦  «        S )a;  
        output_attention_mask (`bool`, *optional*):
            Whether to return the output attention mask.

        Example:

        ```python
        >>> from transformers import AutoProcessor, LasrEncoder
        >>> from datasets import load_dataset, Audio

        >>> model_id = "google/medasr"
        >>> processor = AutoProcessor.from_pretrained(model_id)
        >>> encoder = ParakeetEncoder.from_pretrained(model_id)

        >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> ds = ds.cast_column("audio", Audio(sampling_rate=processor.feature_extractor.sampling_rate))

        >>> inputs = processor(ds[0]["audio"]["array"])
        >>> encoder_outputs = encoder(**inputs)

        >>> print(encoder_outputs.last_hidden_state.shape)
        ```
        r9   )Údevicer   )Úprÿ   N)Útarget_length)rÔ   Úinputs_embedsró   FT)ró   rò   )Úlast_hidden_stateró   )r?  r@  rç   Úaranger÷   rG  Ú	unsqueezer   Ú
functionalrõ   rÿ   r=  Ú_get_output_attention_maskr   rÔ   rB  Úrandr>  rC  r4  rw   )re   râ   ró   rE  ri   rå   r	  r
  Úoutput_maskÚencoder_layerÚto_dropÚdropout_probabilitys               r6   ræ   zLasrEncoder.forwardí  sÙ  € ðF Ÿš¨Ñ7Ô7ˆØ—?’?Ø�5œ<¨Ô(;¸AÔ(>À}ÔG[Ð\Ñ\Ô\×fÒfÐghÑiÔiñ
ô 
‰ˆˆSõ œ×-Ò-¨m¸t¼|ÐVZÔVcÐ-ÑdÔdˆÝŒm×#Ò# C¨4Ô+AÈDÌMÐ#ÑZÔZˆÝŒm×#Ò# C¨4Ô+AÈDÌMÐ#ÑZÔZˆàˆØÐ%Ø×9Ò9¸.ÐXeÔXkÐlmÔXnÐ9ÑoÔoˆKØ(ˆNå2Ø”;Ø'Ø)ð
ñ 
ô 
ˆð "œ[ð 	ð 	ˆMàˆGØŒ}ð #Ý&+¤j°¡n¤nÐ#Ø&¨¬Ò7Ð7Ø"�Gàð Ø - Ø!ð!à#1Ø),¨c¨
ð!ð !ð ð	!ð !�øð Ÿš mÑ4Ô4ˆå%Ø+Ø0EÐkÈ+ÐJa˜;Ÿ?š?Ñ,Ô,Ð,Ðgkð
ñ 
ô 
ð 	
r8   r©   )r{   r|   r}   r¯   rÄ   Úbase_model_prefixra   r   r   r   r   rç   rè   r   r   r   r4  ræ   r«   r¬   s   @r6   r7  r7  Ó  sù   ø€ € € € € € ð ÐÐÑØ!ÐðÐ0ð ð ð ð ð ð ð" ØØØð /3Ø-1ð	H
ð H
àœðH
ð œ tÑ+ðH
ð  $ d™{ð	H
ð
 Ð+Ô,ðH
ð 
 ðH
ð H
ð H
ñ Ôñ „_ñ  Ôñ „^ðH
ð H
ð H
ð H
ð H
r8   r7  c                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )Ú
LasrForCTCc                  ó6   •—  t          ¦   «         j        di | ¤ŽS )a   
        Example:

        ```python
        >>> from transformers import AutoProcessor, LasrForCTC
        >>> from datasets import load_dataset, Audio

        >>> model_id = "google/medasr"
        >>> processor = AutoProcessor.from_pretrained(model_id)
        >>> model = LasrForCTC.from_pretrained(model_id)

        >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> ds = ds.cast_column("audio", Audio(sampling_rate=processor.feature_extractor.sampling_rate))

        >>> inputs = processor(ds[0]["audio"]["array"], text=ds[0]["text"])
        >>> predicted_ids = model.generate(**inputs)
        >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)

        >>> print(transcription)
        ```
        r=   )r”   Úgenerate)Úsuper_kwargsr—   s    €r6   rY  zLasrForCTC.generate=  s"   ø€ ð,  �u‰wŒwÔÐ/Ð/ ,Ð/Ð/Ð/r8   )r{   r|   r}   rY  r«   r¬   s   @r6   rW  rW  <  s8   ø€ € € € € ð0ð 0ð 0ð 0ð 0ð 0ð 0ð 0ð 0r8   rW  )rW  r7  r*  r‘   r¯   rÌ   r+   )Krx   Úcollections.abcr   rç   Úhuggingface_hub.dataclassesr   Ú
tokenizersr   r   r   r   r	   Útokenizers.modelsr
   r   Úaudio_utilsr   r   Úmasking_utilsr   Úmodeling_utilsr   Úprocessing_utilsr   r   r   Útokenization_utils_baser   r   Útokenization_utils_tokenizersr   Úutilsr   r   r   r   Úutils.genericr   Úutils.output_capturingr   Úllama.modeling_llamar   r   r    r!   Úparakeet.configuration_parakeetr"   r#   Úparakeet.modeling_parakeetr$   r%   r&   r'   r(   Út5.tokenization_t5r)   Ú
get_loggerr{   r    r+   r�   r‘   r¯   rÌ   ÚModulerÓ   rê   rí   r  r  r*  r4  r7  rW  Ú__all__r=   r8   r6   ú<module>ro     s  ðð Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $à €€€Ø .Ð .Ð .Ð .Ð .Ð .Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SØ %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð à 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ >Ð >Ð >Ð >Ð >Ð >Ø RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RØ 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø vÐ vÐ vÐ vÐ vÐ vÐ vÐ vÐ vÐ vÐ vÐ vØ VÐ VÐ VÐ VÐ VÐ VÐ VÐ Vðð ð ð ð ð ð ð ð ð ð ð ð ð ð -Ð ,Ð ,Ð ,Ð ,Ð ,ð 
ˆÔ	˜HÑ	%Ô	%€ðd
ð d
ð d
ð d
ð d
�KÐ!2ñ d
ô d
ð d
ðNð ð ð ð Ð*°%ð ñ ô ð ð  ð2:ð 2:ð 2:ð 2:ð 2:�Nñ 2:ô 2:ñ „ð2:ðj €˜?Ð+Ñ+Ô+Øð7#ð 7#ð 7#ð 7#ð 7#Ð-ñ 7#ô 7#ñ „ñ ,Ô+ð7#ðt €˜?Ð+Ñ+Ô+Øð>ð >ð >ð >ð >Ð%ñ >ô >ñ „ñ ,Ô+ð>ð@+ð +ð +ð +ð +˜RœYñ +ô +ð +ð8 <Ð ;Ð ;Ð ;Ð ;Ð!5Ñ ;Ô ;Ð ;ð')ð ')ð ')ð ')ð ')˜>ñ ')ô ')ð ')ðT\ð \ð \ð \ð \Ð#Cñ \ô \ð \ð.ð .ð .ð .ð .Ð+ñ .ô .ð .ðbð ð ð ð Ð1ñ ô ð ð&	ð 	ð 	ð 	ð 	Ð7ñ 	ô 	ð 	ð €ððñ ô ð
a
ð a
ð a
ð a
ð a
Ð%ñ a
ô a
ñô ð
a
ðH0ð 0ð 0ð 0ð 0�ñ 0ô 0ð 0ð4ð ð €€€r8   