Ë
    T^(hñ] ã                   óœ  — d Z ddlZddlmZmZmZmZ ddlZddl	Z	ddl
Z	ddl	mZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ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"m#Z#m$Z$m%Z% ddl&m'Z'm(Z(  e$jR                  e*«      Z+dZ,dZ-de	j\                  de/de/fd„Z0	 d~de	j\                  de/dee	j\                     fd„Z1	 	 ddee/e/f   de2de/dee	jf                     de/dejh                  fd„Z5 G d„ d ejl                  «      Z7 G d!„ d"ejl                  «      Z8 G d#„ d$ejl                  «      Z9 G d%„ d&ejl                  «      Z: G d'„ d(ejl                  «      Z; G d)„ d*ejl                  «      Z< G d+„ d,e	j                  jl                  «      Z= G d-„ d.ejl                  «      Z> G d/„ d0ejl                  «      Z? G d1„ d2ejl                  «      Z@ G d3„ d4ejl                  «      ZA G d5„ d6ejl                  «      ZB G d7„ d8ejl                  «      ZC G d9„ d:ejl                  «      ZD G d;„ d<ejl                  «      ZE G d=„ d>ejl                  «      ZF G d?„ d@ejl                  «      ZG G dA„ dBejl                  «      ZH G dC„ dDejl                  «      ZI G dE„ dFejl                  «      ZJ G dG„ dHejl                  «      ZK G dI„ dJe «      ZL G dK„ dLeL«      ZM G dM„ dNeL«      ZN G dO„ dPeL«      ZO G dQ„ dReL«      ZP G dS„ dTeL«      ZQ G dU„ dVeL«      ZR G dW„ dXeL«      ZS G dY„ dZeL«      ZT G d[„ d\ejl                  «      ZU G d]„ d^ejl                  «      ZVd_ZWd`ZXdaZY e"dbeW«       G dc„ ddeL«      «       ZZ e"deeX«       G df„ dgeL«      «       Z[	 	 	 	 	 	 	 	 d€dheLde	j¸                  diee	j¸                     dee	jf                     dje2dke2dle2dmeejl                     dne]doe]dee	j¸                  ee	j¸                  e	j¸                  f   f   fdp„Z^ e"dqeX«       G dr„ dseL«      «       Z_ e"dteX«       G du„ dveL«      «       Z`dwZa G dx„ dyejl                  «      Zb e"dzea«       G d{„ d|e «      «       Zcg d}¢Zdy)�zPyTorch SpeechT5 model.é    N)ÚListÚOptionalÚTupleÚUnion)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚL1Lossé   )ÚACT2FN)Úis_deepspeed_zero3_enabled)Úis_fsdp_managed_module)Ú_prepare_4d_attention_maskÚ!_prepare_4d_causal_attention_mask)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚSeq2SeqLMOutputÚSeq2SeqModelOutputÚSeq2SeqSpectrogramOutput)ÚPreTrainedModel)Úadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚSpeechT5ConfigÚSpeechT5HifiGanConfigr   Ú	input_idsÚpad_token_idÚdecoder_start_token_idc                 óÖ   — | j                  | j                  «      }| dd…dd…f   j                  «       |dd…dd…f<   ||dd…df<   |€t        d«      ‚|j	                  |dk(  |«       |S )z1
    Shift input ids one token to the right.
    Néÿÿÿÿr   r   z1self.model.config.pad_token_id has to be defined.iœÿÿÿ)Ú	new_zerosÚshapeÚcloneÚ
ValueErrorÚmasked_fill_)r   r   r    Úshifted_input_idss       úl/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/speecht5/modeling_speecht5.pyÚshift_tokens_rightr*   4   s}   € ð "×+Ñ+¨I¯O©OÓ<ÐØ(ª¨C¨R¨C¨Ñ0×6Ñ6Ó8Ð’a˜™�eÑØ4Ð’a˜�dÑàÐÜÐLÓMÐMà×"Ñ"Ð#4¸Ñ#<¸lÔKàÐó    Úinput_valuesÚreduction_factorÚattention_maskc                 óø   — |dkD  r | dd…|dz
  d|…f   } |�|dd…|dz
  d|…f   }| j                  | j                  «      }| dd…dd…f   j                  «       |dd…dd…f<   |j                  |dk(  d«       ||fS )zw
    Shift input spectrograms one timestep to the right. Also applies the reduction factor to the sequence length.
    r   Nr"   ç      YÀç        )r#   r$   r%   r'   )r,   r-   r.   Úshifted_input_valuess       r)   Úshift_spectrograms_rightr3   D   s¯   € ð ˜!ÒØ#¢AÐ'7¸!Ñ';Ð'OÐ?OÐ'OÐ$OÑPˆØÐ%Ø+ªAÐ/?À!Ñ/CÐ/WÐGWÐ/WÐ,WÑXˆNà'×1Ñ1°,×2DÑ2DÓEÐØ".ªq°#°2°#¨vÑ"6×"<Ñ"<Ó">Ðš˜A™B˜Ñð ×%Ñ%Ð&:¸fÑ&DÀcÔJà Ð/Ð/r+   r$   Ú	mask_probÚmask_lengthÚ	min_masksÚreturnc                 óà  ‡‡‡‡‡— | \  }Š‰dk  rt        d«      ‚‰‰kD  rt        d‰› d‰› d�«      ‚t        j                  j                  d«      j	                  «       Šˆˆˆˆˆfd„}|�-|j                  «       j                  d«      j                  «       nt        |«      D �cg c]  }‰‘Œ c}}t        j                  |‰ft        ¬	«      }	g }
 |‰«      }|d
k(  r|	S |D ]¯  } ||«      }t        j                  j                  t        j                  |‰dz
  z
  «      |d¬«      }t        |«      d
k(  r‰dz
  }n|d
   }t        j                  |t        j                  ||z
  t        j                   ¬	«      |z  g«      }|
j#                  |«       Œ± t        j$                  |
«      }
t        j&                  |
dd…dd…df   ||‰f«      }
|
j)                  ||‰z  «      }
t        j                  ‰«      dddd…f   }t        j&                  |||‰f«      j)                  ||‰z  «      }|
|z   }
|
j+                  «       ‰dz
  kD  r‰dz
  |
|
‰dz
  kD  <   t        j,                  |	|
dd«       |	S c c}w )af  
    Computes random mask spans for a given shape. Used to implement [SpecAugment: A Simple Data Augmentation Method for
    ASR](https://arxiv.org/abs/1904.08779). Note that this method is not optimized to run on TPU and should be run on
    CPU as part of the preprocessing during training.

    Args:
        shape: The shape for which to compute masks. This should be of a tuple of size 2 where
               the first element is the batch size and the second element is the length of the axis to span.
        mask_prob:  The percentage of the whole axis (between 0 and 1) which will be masked. The number of
                    independently generated mask spans of length `mask_length` is computed by
                    `mask_prob*shape[1]/mask_length`. Note that due to overlaps, `mask_prob` is an upper bound and the
                    actual percentage will be smaller.
        mask_length: size of the mask
        min_masks: minimum number of masked spans
        attention_mask: A (right-padded) attention mask which independently shortens the feature axis of
                        each batch dimension.
    r   z&`mask_length` has to be bigger than 0.zO`mask_length` has to be smaller than `sequence_length`, but got `mask_length`: z and `sequence_length`: ú`c                 óœ   •— t        ‰| z  ‰z  ‰z   «      }t        |‰«      }|‰z  ‰kD  r‰‰z  }| ‰dz
  z
  |k  rt        | ‰dz
  z
  d«      }|S )z;Given input length, compute how many spans should be maskedr   r   )ÚintÚmax)Úinput_lengthÚnum_masked_spanÚepsilonr5   r4   r6   Úsequence_lengths     €€€€€r)   Úcompute_num_masked_spanz6_compute_mask_indices.<locals>.compute_num_masked_span€   so   ø€ ä˜i¨,Ñ6¸ÑDÀwÑNÓOˆÜ˜o¨yÓ9ˆð ˜[Ñ(¨?Ò:Ø-°Ñ<ˆOð ˜;¨™?Ñ+¨oÒ=Ü! ,°+À±/Ñ"BÀAÓFˆOàÐr+   Nr"   ©Údtyper   F)Úreplace)r&   ÚnpÚrandomÚrandÚitemÚdetachÚsumÚtolistÚrangeÚzerosÚboolÚchoiceÚarangeÚlenÚconcatenateÚonesÚint32ÚappendÚarrayÚbroadcast_toÚreshaper<   Úput_along_axis)r$   r4   r5   r.   r6   Ú
batch_sizerA   Ú_Úinput_lengthsÚspec_aug_maskÚspec_aug_mask_idxsÚmax_num_masked_spanr=   r>   Úspec_aug_mask_idxÚdummy_mask_idxÚoffsetsr?   r@   s    `` `            @@r)   Ú_compute_mask_indicesrc   Z   s­  ü€ ð0 #(Ñ€J�à�Q‚ÜÐAÓBÐBà�_Ò$ÜØ]Ð^iÐ]jØ& Ð&7°qð:ó
ð 	
ô �i‰i�n‰n˜QÓ×$Ñ$Ó&€G÷ð ð$ Ð%ð 	×ÑÓ×#Ñ# BÓ'×.Ñ.Ô0ä',¨ZÓ'8Ö9 !ŠoÒ9ð ô —H‘H˜j¨/Ð:Ä$ÔG€MØÐá1°/ÓBÐà˜aÒØÐà%ò 5ˆá1°,Ó?ˆô ŸI™I×,Ñ,Ü�I‰I�l k°A¡oÑ6Ó7¸ÐRWð -ó 
Ðô Ð Ó! QÒ&ð -¨qÑ0‰Nà.¨qÑ1ˆNäŸN™NØ¤§¡Ð(;¸oÑ(MÔUW×U]ÑU]Ô ^ÐaoÑ oÐpó
Ðð 	×!Ñ!Ð"3Õ4ð/5ô2 Ÿ™Ð"4Ó5Ðô Ÿ™Øš1ša ˜:Ñ&¨Ð5HÈ+Ð(VóÐð ,×3Ñ3°JÐ@SÐVaÑ@aÓbÐô �i‰i˜Ó$ T¨4² ]Ñ3€GÜ�o‰o˜g¨
Ð4GÈÐ'UÓV×^Ñ^ØÐ'¨+Ñ5ó€Gð ,¨gÑ5Ðð ×ÑÓ /°AÑ"5Ò5ØGVÐYZÑGZÐÐ-°À!Ñ0CÑCÑDô ×Ñ�mÐ%7¸¸BÔ?àÐùòw :s   Â$	I+c                   ó&   ‡ — e Zd Zdˆ fd„	Zd„ Zˆ xZS )ÚSpeechT5NoLayerNormConvLayerc                 ód  •— t         ‰| �  «        |dkD  r|j                  |dz
     nd| _        |j                  |   | _        t        j                  | j                  | j                  |j                  |   |j                  |   |j                  ¬«      | _
        t        |j                     | _        y )Nr   r   ©Úkernel_sizeÚstrideÚbias)ÚsuperÚ__init__Úconv_dimÚin_conv_dimÚout_conv_dimr   ÚConv1dÚconv_kernelÚconv_strideÚ	conv_biasÚconvr   Úfeat_extract_activationÚ
activation©ÚselfÚconfigÚlayer_idÚ	__class__s      €r)   rl   z%SpeechT5NoLayerNormConvLayer.__init__Ó   s—   ø€ Ü‰ÑÔØ<DÀqºL˜6Ÿ?™?¨8°a©<Ò8ÈaˆÔØ"ŸO™O¨HÑ5ˆÔä—I‘IØ×ÑØ×ÑØ×*Ñ*¨8Ñ4Ø×%Ñ% hÑ/Ø×!Ñ!ô
ˆŒ	ô ! ×!?Ñ!?Ñ@ˆ�r+   c                 óJ   — | j                  |«      }| j                  |«      }|S ©N)rt   rv   ©rx   Úhidden_statess     r)   Úforwardz$SpeechT5NoLayerNormConvLayer.forwardá   s$   € ØŸ	™	 -Ó0ˆØŸ™¨Ó6ˆØÐr+   ©r   ©Ú__name__Ú
__module__Ú__qualname__rl   r€   Ú__classcell__©r{   s   @r)   re   re   Ò   s   ø„ õAör+   re   c                   ó&   ‡ — e Zd Zdˆ fd„	Zd„ Zˆ xZS )ÚSpeechT5LayerNormConvLayerc                 ó°  •— t         ‰| �  «        |dkD  r|j                  |dz
     nd| _        |j                  |   | _        t        j                  | j                  | j                  |j                  |   |j                  |   |j                  ¬«      | _
        t        j                  | j                  d¬«      | _        t        |j                     | _        y )Nr   r   rg   T)Úelementwise_affine)rk   rl   rm   rn   ro   r   rp   rq   rr   rs   rt   Ú	LayerNormÚ
layer_normr   ru   rv   rw   s      €r)   rl   z#SpeechT5LayerNormConvLayer.__init__é   s¯   ø€ Ü‰ÑÔØ<DÀqºL˜6Ÿ?™?¨8°a©<Ò8ÈaˆÔØ"ŸO™O¨HÑ5ˆÔä—I‘IØ×ÑØ×ÑØ×*Ñ*¨8Ñ4Ø×%Ñ% hÑ/Ø×!Ñ!ô
ˆŒ	ô Ÿ,™, t×'8Ñ'8ÈTÔRˆŒÜ  ×!?Ñ!?Ñ@ˆ�r+   c                 ó´   — | j                  |«      }|j                  dd«      }| j                  |«      }|j                  dd«      }| j                  |«      }|S )Néþÿÿÿr"   )rt   Ú	transposer�   rv   r~   s     r)   r€   z"SpeechT5LayerNormConvLayer.forwardø   sV   € ØŸ	™	 -Ó0ˆà%×/Ñ/°°BÓ7ˆØŸ™¨Ó6ˆØ%×/Ñ/°°BÓ7ˆàŸ™¨Ó6ˆØÐr+   r�   r‚   r‡   s   @r)   r‰   r‰   è   s   ø„ õAör+   r‰   c                   ó&   ‡ — e Zd Zdˆ fd„	Zd„ Zˆ xZS )ÚSpeechT5GroupNormConvLayerc                 óÆ  •— t         ‰| �  «        |dkD  r|j                  |dz
     nd| _        |j                  |   | _        t        j                  | j                  | j                  |j                  |   |j                  |   |j                  ¬«      | _
        t        |j                     | _        t        j                  | j                  | j                  d¬«      | _        y )Nr   r   rg   T)Ú
num_groupsÚnum_channelsÚaffine)rk   rl   rm   rn   ro   r   rp   rq   rr   rs   rt   r   ru   rv   Ú	GroupNormr�   rw   s      €r)   rl   z#SpeechT5GroupNormConvLayer.__init__  s¹   ø€ Ü‰ÑÔØ<DÀqºL˜6Ÿ?™?¨8°a©<Ò8ÈaˆÔØ"ŸO™O¨HÑ5ˆÔä—I‘IØ×ÑØ×ÑØ×*Ñ*¨8Ñ4Ø×%Ñ% hÑ/Ø×!Ñ!ô
ˆŒ	ô ! ×!?Ñ!?Ñ@ˆŒäŸ,™,°$×2CÑ2CÐRV×RcÑRcÐlpÔqˆ�r+   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S r}   )rt   r�   rv   r~   s     r)   r€   z"SpeechT5GroupNormConvLayer.forward  s2   € ØŸ	™	 -Ó0ˆØŸ™¨Ó6ˆØŸ™¨Ó6ˆØÐr+   r�   r‚   r‡   s   @r)   r’   r’     s   ø„ õrö r+   r’   c            	       óú   ‡ — e Zd ZdZddededee   fˆ fd„Zddededee   fd„Zeddededee   fd„«       Z	 e
j                  «       dd	e
j                  d
efd„«       Z	 dd	e
j                  ded
ee   fd„Zˆ xZS )Ú%SpeechT5SinusoidalPositionalEmbeddingzDThis module produces sinusoidal positional embeddings of any length.Únum_positionsÚembedding_dimÚpadding_idxc                 óŒ   •— t         ‰| �  «        d| _        || _        || _        | j                  || j                  z   ||«       y ©Né   )rk   rl   Úoffsetrœ   r�   Úmake_weights)rx   r›   rœ   r�   r{   s       €r)   rl   z.SpeechT5SinusoidalPositionalEmbedding.__init__   s@   ø€ Ü‰ÑÔØˆŒØ*ˆÔØ&ˆÔØ×Ñ˜-¨$¯+©+Ñ5°}ÀkÕRr+   Únum_embeddingsc                 óB  — | j                  |||«      }t        | d«      r;|j                  | j                  j                  | j                  j
                  ¬«      }t        j                  |«      | _        d| j                  _        | j                  j                  «        y )NÚweights©rC   ÚdeviceF)
Úget_embeddingÚhasattrÚtor¥   rC   r§   r   Ú	ParameterÚrequires_gradÚdetach_)rx   r£   rœ   r�   Úemb_weightss        r)   r¢   z2SpeechT5SinusoidalPositionalEmbedding.make_weights'  sr   € Ø×(Ñ(¨¸ÈÓTˆÜ�4˜Ô#à%Ÿ.™.¨t¯|©|×/AÑ/AÈ$Ï,É,×J]ÑJ]˜.Ó^ˆKä—|‘| KÓ0ˆŒØ%*ˆ�‰Ô"Ø�‰×ÑÕr+   c                 óâ  — |dz  }t        j                  d«      |dz
  z  }t        j                  t        j                  |t        j
                  ¬«      j                  «       | z  «      }t        j                  | t        j
                  ¬«      j                  «       j                  d«      |j                  d«      z  }t        j                  t        j                  |«      t        j                  |«      gd¬«      j                  | d«      }|dz  dk(  r-t        j                  |t        j                  | d«      gd¬«      }|�	d||dd…f<   |j                  t        j                  «       «      S )	zÁ
        Build sinusoidal embeddings. This matches the implementation in tensor2tensor, but differs slightly from the
        description in Section 3.5 of "Attention Is All You Need".
        r    i'  r   rB   r   ©Údimr"   N)ÚmathÚlogÚtorchÚexprP   Úint64ÚfloatÚ	unsqueezeÚcatÚsinÚcosÚviewrM   rª   Úget_default_dtype)r£   rœ   r�   Úhalf_dimÚembs        r)   r¨   z3SpeechT5SinusoidalPositionalEmbedding.get_embedding1  s  € ð ! AÑ%ˆÜ�h‰h�u‹o ¨A¡Ñ.ˆÜ�i‰iœŸ™ X´U·[±[ÔA×GÑGÓIÈSÈDÑPÓQˆÜ�l‰l˜>´·±Ô=×CÑCÓE×OÑOÐPQÓRÐUX×UbÑUbÐcdÓUeÑeˆÜ�i‰iœŸ™ 3›¬¯©°3«Ð8¸aÔ@×EÑEÀnÐVXÓYˆØ˜1Ñ Ò!ä—)‘)˜S¤%§+¡+¨n¸aÓ"@ÐAÀqÔIˆCØÐ"Ø"#ˆC�šQ�ÑØ�v‰v”e×-Ñ-Ó/Ó0Ð0r+   r   Úpast_key_values_lengthc                 óð  — |j                  «       \  }}| j                  || j                  |«      j                  |j                  «      }| j                  dz   |z   }|| j
                  j                  d«      kD  r4| j                  || j                  z   | j                  | j                  «       | j
                  j                  d|j                  d«      «      j                  ||d«      j                  «       S )Nr   r   r"   )ÚsizeÚ"create_position_ids_from_input_idsr�   rª   r§   r¥   r¢   r¡   rœ   Úindex_selectr¼   rI   )rx   r   rÀ   ÚbszÚseq_lenÚposition_idsÚmax_poss          r)   r€   z-SpeechT5SinusoidalPositionalEmbedding.forwardC  sÑ   € à —~‘~Ó'‰ˆˆWà×>Ñ>¸yÈ$×JZÑJZÐ\rÓs×vÑvØ×Ñó
ˆð
 ×"Ñ" QÑ&¨Ñ0ˆØ�T—\‘\×&Ñ& qÓ)Ò)Ø×Ñ˜g¨¯©Ñ3°T×5GÑ5GÈ×IYÑIYÔZà�|‰|×(Ñ(¨¨L×,=Ñ,=¸bÓ,AÓB×GÑGÈÈWÐVXÓY×`Ñ`ÓbÐbr+   c                 ó¾   — |j                  |«      j                  «       }t        j                  |d¬«      j	                  |«      |z   |z  }|j                  «       |z   S )a  
        Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding
        symbols are ignored. This is modified from fairseq's `utils.make_positions`.

        Args:
            x: torch.Tensor x:
        Returns: torch.Tensor
        r   r°   )Úner;   r´   ÚcumsumÚtype_asÚlong)rx   r   r�   rÀ   ÚmaskÚincremental_indicess         r)   rÃ   zHSpeechT5SinusoidalPositionalEmbedding.create_position_ids_from_input_idsR  sW   € ð �|‰|˜KÓ(×,Ñ,Ó.ˆÜ$Ÿ|™|¨D°aÔ8×@Ñ@ÀÓFÐI_Ñ_ÐcgÑgÐØ"×'Ñ'Ó)¨KÑ7Ð7r+   r}   r�   )rƒ   r„   r…   Ú__doc__r;   r   rl   r¢   Ústaticmethodr¨   r´   Úno_gradÚTensorr€   rÃ   r†   r‡   s   @r)   rš   rš     sØ   ø„ ÙNñS cð S¸#ð SÈHÐUXÉMõ Sñ¨3ð ¸sð ÐQYÐZ]ÑQ^ó ð ñ1 cð 1¸#ð 1ÈHÐUXÉMò 1ó ð1ð" €U‡]�]ƒ_ñc §¡ð cÀsò có ðcð bcñ8ØŸ™ð8Ø47ð8ØQYÐZ]ÑQ^÷8r+   rš   c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚSpeechT5PositionalConvEmbeddingc                 ó¦  •— t         ‰| �  «        t        j                  |j                  |j                  |j
                  |j
                  dz  |j                  ¬«      | _        t        j                  j                  }t        t        j                  j                  d«      r$t        j                  j                  j                  }t        «       �r(dd l}|j                  j                  | j                  j                   d¬«      5   || j                  dd¬«      | _        d d d «       t        | j                  d«      rU| j                  j                  j                   j"                  }| j                  j                  j                   j$                  }n,| j                  j&                  }| j                  j(                  }|j                  j+                  | |«       |j                  j+                  | |«       n || j                  dd¬«      | _        t-        |j
                  «      | _        t0        |j2                     | _        y # 1 sw Y   �Œ'xY w)	Nr    )rh   ÚpaddingÚgroupsÚweight_normr   )Úmodifier_rankÚweight)Únamer±   Úparametrizations)rk   rl   r   rp   Úhidden_sizeÚnum_conv_pos_embeddingsÚnum_conv_pos_embedding_groupsrt   ÚutilsrÙ   r©   rÝ   r   Ú	deepspeedÚzeroÚGatheredParametersrÛ   Ú	original0Ú	original1Úweight_gÚweight_vÚregister_external_parameterÚSpeechT5SamePadLayerr×   r   ru   rv   )rx   ry   rÙ   râ   rç   rè   r{   s         €r)   rl   z(SpeechT5PositionalConvEmbedding.__init__e  s¥  ø€ Ü‰ÑÔÜ—I‘IØ×ÑØ×ÑØ×6Ñ6Ø×2Ñ2°aÑ7Ø×7Ñ7ô
ˆŒ	ô —h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKä%Õ'Ûà—‘×2Ñ2°4·9±9×3CÑ3CÐSTÐ2ÓUñ IÙ'¨¯	©	¸ÀaÔH�”	÷Iä�t—y‘yÐ"4Ô5ØŸ9™9×5Ñ5×<Ñ<×FÑF�ØŸ9™9×5Ñ5×<Ñ<×FÑF‘àŸ9™9×-Ñ-�ØŸ9™9×-Ñ-�Ø�N‰N×6Ñ6°t¸XÔFØ�N‰N×6Ñ6°t¸XÕFá# D§I¡I°HÀ!ÔDˆDŒIä+¨F×,JÑ,JÓKˆŒÜ  ×!?Ñ!?Ñ@ˆ�÷Iñ Iús   ÄIÉIc                 ó´   — |j                  dd«      }| j                  |«      }| j                  |«      }| j                  |«      }|j                  dd«      }|S ©Nr   r    )r�   rt   r×   rv   r~   s     r)   r€   z'SpeechT5PositionalConvEmbedding.forward†  sV   € Ø%×/Ñ/°°1Ó5ˆàŸ	™	 -Ó0ˆØŸ™ ]Ó3ˆØŸ™¨Ó6ˆà%×/Ñ/°°1Ó5ˆØÐr+   r‚   r‡   s   @r)   rÕ   rÕ   d  s   ø„ ôAöBr+   rÕ   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )Ú SpeechT5ScaledPositionalEncodinguS   
    Scaled positional encoding, see Â§3.2 in https://arxiv.org/abs/1809.08895
    c                 ó  •— t        j                  ||«      }t        j                  d|«      j                  d«      }t        j                  t        j                  d|dt         j
                  ¬«      j                  «       t        j                  d«      |z   z  «      }t        j                  |j                  «       |z  «      |d d …dd d…f<   t        j                  |j                  «       |z  «      |d d …dd d…f<   |j                  d«      }t        ‰| �1  «        | j                  d|d¬«       t        j                  |¬	«      | _        || _        t         j                  j%                  t        j&                  d
«      «      | _        y )Nr   r   r    rB   g     ˆÃ@ÚpeF)Ú
persistent©Úpç      ð?)r´   rM   rP   r¸   rµ   r¶   r·   r²   r³   rº   r»   rk   rl   Úregister_bufferr   ÚDropoutÚdropoutr±   r«   ÚtensorÚalpha)rx   r÷   r±   Úmax_lenrð   ÚpositionÚdiv_termr{   s          €r)   rl   z)SpeechT5ScaledPositionalEncoding.__init__–  s&  ø€ Ü�[‰[˜ #Ó&ˆÜ—<‘<  7Ó+×5Ñ5°aÓ8ˆÜ—9‘9œeŸl™l¨1¨c°1¼E¿K¹KÔH×NÑNÓPÔUY×U]ÑU]Ð^eÓUfÐilÑUlÐSmÑmÓoˆÜ—i‘i §¡Ó 0°8Ñ ;Ó<ˆŠ1ˆaˆd�ˆdˆ7‰Ü—i‘i §¡Ó 0°8Ñ ;Ó<ˆŠ1ˆaˆd�ˆdˆ7‰Ø�\‰\˜!‹_ˆÜ‰ÑÔØ×Ñ˜T 2°%ÐÔ8Ü—z‘z GÔ,ˆŒØˆŒÜ—X‘X×'Ñ'¬¯©°SÓ(9Ó:ˆ�
r+   c                 ó�   — || j                   | j                  d d …d |j                  d«      …f   z  z   }| j                  |«      }|S )Nr   )rù   rð   rÂ   r÷   )rx   r¿   s     r)   r€   z(SpeechT5ScaledPositionalEncoding.forward£  sB   € Ø�D—J‘J §¡ª¨M¨c¯h©h°q«k¨MÐ)9Ñ!:Ñ:Ñ:ˆØ�l‰l˜3ÓˆØˆ
r+   )iˆ  )rƒ   r„   r…   rÐ   rl   r€   r†   r‡   s   @r)   rî   rî   ‘  s   ø„ ñõ;ör+   rî   c                   ó&   ‡ — e Zd Zdˆ fd„	Zd„ Zˆ xZS )Ú"SpeechT5RelativePositionalEncodingc                 óŽ   •— t         ‰| �  «        || _        || _        t        j
                  j                  d|z  |«      | _        y rŸ   )rk   rl   r±   Ú
max_lengthr´   r   Ú	EmbeddingÚpe_k)rx   r±   r  r{   s      €r)   rl   z+SpeechT5RelativePositionalEncoding.__init__ª  s8   ø€ Ü‰ÑÔØˆŒØ$ˆŒÜ—H‘H×&Ñ& q¨:¡~°sÓ;ˆ�	r+   c                 ó~  — |j                   d   }t        j                  d|«      j                  |j                  t        j
                  ¬«      }|d d …d f   |d d d …f   z
  }| j                   ||| j                   k  <   | j                  dz
  ||| j                  k\  <   || j                  z   }| j                  |«      S )Nr   r   ©r§   rC   )r$   r´   rP   rª   r§   rÍ   r  r  )rx   r   rÆ   Úpos_seqs       r)   r€   z*SpeechT5RelativePositionalEncoding.forward°  s±   € Ø×%Ñ% aÑ(ˆÜ—,‘,˜q 'Ó*×-Ñ-°]×5IÑ5IÔQV×Q[ÑQ[Ð-Ó\ˆØš!˜T˜'Ñ" W¨T²1¨WÑ%5Ñ5ˆà/3¯©Ð.>ˆ�˜4Ÿ?™?Ð*Ñ*Ñ+Ø.2¯o©oÀÑ.Aˆ�˜4Ÿ?™?Ñ*Ñ+Ø˜DŸO™OÑ+ˆà�y‰y˜Ó!Ð!r+   )iè  r‚   r‡   s   @r)   rÿ   rÿ   ©  s   ø„ õ<ö	"r+   rÿ   c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )rê   c                 óP   •— t         ‰| �  «        |dz  dk(  rd| _        y d| _        y )Nr    r   r   )rk   rl   Únum_pad_remove)rx   rß   r{   s     €r)   rl   zSpeechT5SamePadLayer.__init__¾  s)   ø€ Ü‰ÑÔØ#:¸QÑ#>À!Ò#C˜aˆÕÈˆÕr+   c                 óV   — | j                   dkD  r|d d …d d …d | j                    …f   }|S ©Nr   )r	  r~   s     r)   r€   zSpeechT5SamePadLayer.forwardÂ  s6   € Ø×Ñ Ò"Ø)ª!ªQÐ0F°4×3FÑ3FÐ2FÐ0FÐ*FÑGˆMØÐr+   r‚   r‡   s   @r)   rê   rê   ½  s   ø„ ôKör+   rê   c                   ó.   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ xZS )ÚSpeechT5FeatureEncoderz.Construct the features from raw audio waveformc           	      óØ  •— t         ‰| �  «        |j                  dk(  rDt        |d¬«      gt	        |j
                  dz
  «      D �cg c]  }t        ||dz   ¬«      ‘Œ c}z   }nV|j                  dk(  r.t	        |j
                  «      D �cg c]  }t        ||¬«      ‘Œ }}nt        d|j                  › d�«      ‚t        j                  |«      | _        d| _        d	| _        y c c}w c c}w )
NÚgroupr   )rz   r   Úlayerz`config.feat_extract_norm` is z), but has to be one of ['group', 'layer']FT)rk   rl   Úfeat_extract_normr’   rL   Únum_feat_extract_layersre   r‰   r&   r   Ú
ModuleListÚconv_layersÚgradient_checkpointingÚ_requires_grad)rx   ry   Úir  r{   s       €r)   rl   zSpeechT5FeatureEncoder.__init__Ì  sñ   ø€ Ü‰ÑÔà×#Ñ# wÒ.Ü5°fÀqÔIÐJÜNSÐTZ×TrÑTrÐuvÑTvÓNwöNØIJÔ,¨V¸aÀ!¹eÖDòNñ ‰Kð ×%Ñ%¨Ò0äHMÈf×NlÑNlÓHmöØCDÔ*¨6¸AÖ>ðˆKñ ô Ø0°×1IÑ1IÐ0JÐJsÐtóð ô Ÿ=™=¨Ó5ˆÔØ&+ˆÔ#Ø"ˆÕùòNùòs   ÁC"Â	C'c                 óJ   — | j                  «       D ]	  }d|_        Œ d| _        y ©NF)Ú
parametersr¬   r  )rx   Úparams     r)   Ú_freeze_parametersz)SpeechT5FeatureEncoder._freeze_parametersß  s(   € Ø—_‘_Ó&ò 	(ˆEØ"'ˆEÕð	(à#ˆÕr+   c                 ó
  — |d d …d f   }| j                   r| j                  rd|_        | j                  D ]K  }| j                   r5| j                  r)| j                  r| j                  |j                  |«      }ŒD ||«      }ŒM |S ©NT)r  Útrainingr¬   r  r  Ú_gradient_checkpointing_funcÚ__call__)rx   r,   r   Ú
conv_layers       r)   r€   zSpeechT5FeatureEncoder.forwardä  s…   € Ø$¢Q¨ WÑ-ˆð ×Ò 4§=¢=Ø*.ˆMÔ'à×*Ñ*ò 	:ˆJØ×"Ò" t×'BÒ'BÀtÇ}Â}Ø $× AÑ AØ×'Ñ'Ø!ó!‘ñ
 !+¨=Ó 9‘ð	:ð Ðr+   )rƒ   r„   r…   rÐ   rl   r  r€   r†   r‡   s   @r)   r  r  É  s   ø„ Ù8ô#ò&$ö
r+   r  c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚSpeechT5FeatureProjectionc                 ó4  •— t         ‰| �  «        t        j                  |j                  d   |j
                  ¬«      | _        t        j                  |j                  d   |j                  «      | _	        t        j                  |j                  «      | _        y )Nr"   ©Úeps)rk   rl   r   rŒ   rm   Úlayer_norm_epsr�   ÚLinearrÞ   Ú
projectionrö   Úfeat_proj_dropoutr÷   ©rx   ry   r{   s     €r)   rl   z"SpeechT5FeatureProjection.__init__ù  sf   ø€ Ü‰ÑÔÜŸ,™, v§¡°rÑ':À×@UÑ@UÔVˆŒÜŸ)™) F§O¡O°BÑ$7¸×9KÑ9KÓLˆŒÜ—z‘z &×":Ñ":Ó;ˆ�r+   c                 óp   — | j                  |«      }| j                  |«      }| j                  |«      }||fS r}   )r�   r*  r÷   )rx   r   Únorm_hidden_statess      r)   r€   z!SpeechT5FeatureProjection.forwardÿ  s:   € à!Ÿ_™_¨]Ó;ÐØŸ™Ð(:Ó;ˆØŸ™ ]Ó3ˆØÐ0Ð0Ð0r+   r‚   r‡   s   @r)   r$  r$  ø  s   ø„ ô<ö1r+   r$  c                   ó6  ‡ — e Zd Zˆ fd„Zd„ Z	 	 ddej                  deej                     deej                     fd„Z
dedej                  fd„Zd	eej                  ef   fd
„Z	 	 ddej                  deej                     deej                     fd„Zˆ xZS )ÚSpeechT5SpeechEncoderPrenetc                 óÖ  •— t         ‰| �  «        || _        t        |«      | _        t        |«      | _        |j                  dkD  s|j                  dkD  rEt        j                  t        j                  |j                  «      j                  «       «      | _        t!        |«      | _        t%        |j&                  |j(                  z   dz   |j                  |j(                  «      | _        y )Nr1   r   )rk   rl   ry   r  Úfeature_encoderr$  Úfeature_projectionÚmask_time_probÚmask_feature_probr   r«   r´   rÓ   rÞ   Úuniform_Úmasked_spec_embedrÕ   Úpos_conv_embedrš   Úmax_speech_positionsr   Úpos_sinusoidal_embedr,  s     €r)   rl   z$SpeechT5SpeechEncoderPrenet.__init__  sº   ø€ Ü‰ÑÔØˆŒÜ5°fÓ=ˆÔÜ";¸FÓ"CˆÔð × Ñ  3Ò&¨&×*BÑ*BÀSÒ*HÜ%'§\¡\´%·,±,¸v×?QÑ?QÓ2R×2[Ñ2[Ó2]Ó%^ˆDÔ"ä=¸fÓEˆÔÜ$IØ×'Ñ'¨&×*=Ñ*=Ñ=ÀÑAØ×ÑØ×Ñó%
ˆÕ!r+   c                 ó8   — | j                   j                  «        y r}   )r2  r  ©rx   s    r)   Úfreeze_feature_encoderz2SpeechT5SpeechEncoderPrenet.freeze_feature_encoder  s   € Ø×Ñ×/Ñ/Õ1r+   r,   r.   Úmask_time_indicesc                 óø  — | j                  |«      }|j                  dd«      }|�| j                  |j                  d   |«      }| j	                  |«      \  }}| j                  |||¬«      }| j                  |«      }||z   }|� |j                  d«      j                  «       }n=t        j                  |j                  d d t        j                  |j                  ¬«      }| j                  |«      }||z   }||fS )Nr   r    )r>  r.   r¦   )r2  r�   Ú"_get_feature_vector_attention_maskr$   r3  Ú_mask_hidden_statesr8  rÊ   rÍ   r´   rM   r§   r:  )	rx   r,   r.   r>  Úextract_featuresr   Úpositional_conv_embeddingÚpadding_maskÚ positional_sinusoidal_embeddingss	            r)   r€   z#SpeechT5SpeechEncoderPrenet.forward  s  € ð  ×/Ñ/°Ó=ÐØ+×5Ñ5°a¸Ó;ÐàÐ%à!×DÑDØ ×&Ñ& qÑ)ØóˆNð
 +/×*AÑ*AÐBRÓ*SÑ'ˆÐ'Ø×0Ñ0ØÐ->È~ð 1ó 
ˆð %)×$7Ñ$7¸Ó$FÐ!Ø%Ð(AÑAˆàÐ%Ø)×,Ñ,¨QÓ/×4Ñ4Ó6‰Lä Ÿ;™; }×':Ñ':¸2¸AÐ'>ÄeÇjÁjÐYf×YmÑYmÔnˆLà+/×+DÑ+DÀ\Ó+RÐ(Ø%Ð(HÑHˆà˜nÐ,Ð,r+   Úfeature_vector_lengthc                 óø  — |j                  d¬«      d d …df   }| j                  |«      j                  t        j                  «      }|j
                  d   }t        j                  ||f|j                  |j                  ¬«      }d|t        j                  |j
                  d   |j                  ¬«      |dz
  f<   |j                  dg«      j                  d«      j                  dg«      j                  «       }|S )Nr"   r°   r   r¦   r   ©r§   )rË   Ú _get_feat_extract_output_lengthsrª   r´   rÍ   r$   rM   rC   r§   rP   ÚfliprN   )rx   rF  r.   Únon_padded_lengthsÚoutput_lengthsrZ   s         r)   r@  z>SpeechT5SpeechEncoderPrenet._get_feature_vector_attention_mask?  së   € ð ,×2Ñ2°rÐ2Ó:º1¸b¸5ÑAÐØ×>Ñ>Ð?QÓR×UÑUÔV[×V`ÑV`ÓaˆØ#×)Ñ)¨!Ñ,ˆ
äŸ™ØÐ.Ð/°~×7KÑ7KÐTb×TiÑTiô
ˆð uvˆœŸ™ ^×%9Ñ%9¸!Ñ%<À^×EZÑEZÔ[Ð]kÐnoÑ]oÐpÑqØ'×,Ñ,¨b¨TÓ2×9Ñ9¸"Ó=×BÑBÀBÀ4ÓH×MÑMÓOˆØÐr+   r\   c                 ó˜   — d„ }t        | j                  j                  | j                  j                  «      D ]  \  }} ||||«      }Œ |S )zH
        Computes the output length of the convolutional layers
        c                 ó>   — t        j                  | |z
  |d¬«      dz   S )NÚfloor)Úrounding_moder   )r´   Údiv)r=   rh   ri   s      r)   Ú_conv_out_lengthzVSpeechT5SpeechEncoderPrenet._get_feat_extract_output_lengths.<locals>._conv_out_lengthT  s"   € ô —9‘9˜\¨KÑ7¸ÈwÔWÐZ[Ñ[Ð[r+   )Úzipry   rq   rr   )rx   r\   rR  rh   ri   s        r)   rI  z<SpeechT5SpeechEncoderPrenet._get_feat_extract_output_lengthsO  sQ   € ò
	\ô
 $' t§{¡{×'>Ñ'>ÀÇÁ×@WÑ@WÓ#Xò 	QÑˆK˜Ù,¨]¸KÈÓP‰Mð	Qð Ðr+   r   c                 óÎ  — t        | j                  dd«      s|S |j                  «       \  }}}|�)| j                  j	                  |j
                  «      ||<   nË| j                  j                  dkD  r²| j                  r¦t        ||f| j                  j                  | j                  j                  || j                  j                  ¬«      }t        j                  ||j                  t        j                  ¬«      }| j                  j	                  |j
                  «      ||<   | j                  j                  dkD  r¨| j                  rœt        ||f| j                  j                  | j                  j                   | j                  j"                  ¬«      }t        j                  ||j                  t        j                  ¬«      }|dd…df   j%                  d|d«      }d||<   |S )	zš
        Masks extracted features along time axis and/or along feature axis according to
        [SpecAugment](https://arxiv.org/abs/1904.08779).
        Úapply_spec_augmentTNr   )r4   r5   r.   r6   r  )r4   r5   r6   r"   )Úgetattrry   rÂ   r7  rª   rC   r4  r  rc   Úmask_time_lengthÚmask_time_min_masksr´   rø   r§   rN   r5  Úmask_feature_lengthÚmask_feature_min_masksÚexpand)rx   r   r>  r.   rZ   r@   rÞ   Úmask_feature_indicess           r)   rA  z/SpeechT5SpeechEncoderPrenet._mask_hidden_states_  sš  € ô �t—{‘{Ð$8¸$Ô?Ø Ð ð 4A×3EÑ3EÓ3GÑ0ˆ
�O [àÐ(à/3×/EÑ/E×/HÑ/HÈ×I\ÑI\Ó/]ˆMÐ+Ò,Ø�[‰[×'Ñ'¨!Ò+°·²Ü 5Ø˜_Ð-ØŸ+™+×4Ñ4Ø ŸK™K×8Ñ8Ø-ØŸ+™+×9Ñ9ô!Ðô !&§¡Ð->À}×G[ÑG[Ôch×cmÑcmÔ nÐØ/3×/EÑ/E×/HÑ/HÈ×I\ÑI\Ó/]ˆMÐ+Ñ,à�;‰;×(Ñ(¨1Ò,°·²ä#8Ø˜[Ð)ØŸ+™+×7Ñ7Ø ŸK™K×;Ñ;ØŸ+™+×<Ñ<ô	$Ð ô $)§<¡<Ð0DÈ]×MaÑMaÔin×isÑisÔ#tÐ Ø#7º¸4¸Ñ#@×#GÑ#GÈÈOÐ]_Ó#`Ð Ø23ˆMÐ.Ñ/àÐr+   ©NN)rƒ   r„   r…   rl   r=  r´   rÓ   r   Ú
LongTensorÚFloatTensorr€   r;   r@  r   rI  rA  r†   r‡   s   @r)   r0  r0    sÍ   ø„ ô
ò"2ð 6:Ø9=ñ	 -à—l‘lð -ð ! ×!1Ñ!1Ñ2ð -ð $ E×$5Ñ$5Ñ6ó	 -ðFÈð Ð]b×]mÑ]mó ð ¸eÀE×DTÑDTÐVYÐDYÑ>Zó ð& :>Ø59ñ	,à×(Ñ(ð,ð $ E×$5Ñ$5Ñ6ð,ð ! ×!1Ñ!1Ñ2÷	,r+   r0  c                   óf   ‡ — e Zd Zˆ fd„Zd„ Z	 ddej                  deej                     fd„Zˆ xZ	S )ÚSpeechT5SpeechDecoderPrenetc           	      óX  •— t         ‰| �  «        || _        t        j                  t        |j                  «      D �cg c]=  }t        j                  |dk(  r|j                  n|j                  |j                  «      ‘Œ? c}«      | _
        t        j                  |j                  |j                  «      | _        t        |j                  |j                  |j                  «      | _        t        j                  |j"                  |j                  z   |j                  «      | _        y c c}w r  )rk   rl   ry   r   r  rL   Úspeech_decoder_prenet_layersr)  Únum_mel_binsÚspeech_decoder_prenet_unitsÚlayersrÞ   Úfinal_layerrî   Úpositional_dropoutr9  Úencode_positionsÚspeaker_embedding_dimÚspeaker_embeds_layer©rx   ry   r  r{   s      €r)   rl   z$SpeechT5SpeechDecoderPrenet.__init__�  sî   ø€ Ü‰ÑÔØˆŒä—m‘mô ˜v×BÑBÓCöð
 ô	 —	‘	Ø+,°ª6�F×'Ò'°v×7YÑ7YØ×6Ñ6õòó
ˆŒô Ÿ9™9 V×%GÑ%GÈ×I[ÑI[Ó\ˆÔÜ @Ø×%Ñ%Ø×ÑØ×'Ñ'ó!
ˆÔô
 %'§I¡I¨f×.JÑ.JÈV×M_ÑM_Ñ._Ðag×asÑasÓ$tˆÕ!ùòs   ½AD'c                 óÞ   — t        j                  |d   |¬«      }|j                  d«      j                  |j	                  d«      dd«      }t        j
                  |dk(  |d«      dz  d|z
  z  S )Nr   rò   r   )r´   Ú	bernoullir¸   ÚrepeatrÂ   Úwhere)rx   Úinputs_embedsró   rÎ   Ú	all_maskss        r)   Ú_consistent_dropoutz/SpeechT5SpeechDecoderPrenet._consistent_dropout¥  sd   € Ü�‰˜}¨QÑ/°1Ô5ˆØ—N‘N 1Ó%×,Ñ,¨]×-?Ñ-?ÀÓ-BÀAÀqÓIˆ	Ü�{‰{˜9¨™>¨=¸!Ó<¸qÑ@ÀAÈÁEÑJÐJr+   r,   Úspeaker_embeddingsc                 ó8  — |}| j                   D ]M  }t        j                  j                   ||«      «      }| j	                  || j
                  j                  «      }ŒO | j                  |«      }| j                  |«      }|�—t        j                  j                  |«      }|j                  d«      j                  d|j                  d«      d«      }t        j                  ||gd¬«      }t        j                  j                  | j                  |«      «      }|S )Nr   r"   r°   )rf  r   Ú
functionalÚrelurs  ry   Úspeech_decoder_prenet_dropoutrg  ri  Ú	normalizer¸   r[  rÂ   r´   r¹   rk  )rx   r,   rt  rq  r  s        r)   r€   z#SpeechT5SpeechDecoderPrenet.forwardª  sù   € ð %ˆØ—[‘[ò 	oˆEÜŸM™M×.Ñ.©u°]Ó/CÓDˆMØ ×4Ñ4°]ÀDÇKÁK×DmÑDmÓn‰Mð	oð ×(Ñ(¨Ó7ˆØ×-Ñ-¨mÓ<ˆàÐ)Ü!#§¡×!8Ñ!8Ð9KÓ!LÐØ!3×!=Ñ!=¸aÓ!@×!GÑ!GÈÈM×L^ÑL^Ð_`ÓLaÐceÓ!fÐÜ!ŸI™I }Ð6HÐ&IÈrÔRˆMÜŸM™M×.Ñ.¨t×/HÑ/HÈÓ/WÓXˆMàÐr+   r}   )
rƒ   r„   r…   rl   rs  r´   rÓ   r   r€   r†   r‡   s   @r)   ra  ra  Ž  s8   ø„ ôuò,Kð 6:ñà—l‘lðð % U§\¡\Ñ2÷r+   ra  c                   ó&   ‡ — e Zd Zdˆ fd„	Zd„ Zˆ xZS )ÚSpeechT5BatchNormConvLayerc                 ó
  •— t         ‰| �  «        |dk(  r|j                  }n|j                  }||j                  dz
  k(  r|j                  }n|j                  }t        j                  |||j                  d|j                  dz
  dz  d¬«      | _        t        j                  |«      | _
        ||j                  dz
  k  rt        j                  «       | _        nd | _        t        j                  |j                  «      | _        y )Nr   r   r    F)rh   ri   r×   rj   )rk   rl   rd  Úspeech_decoder_postnet_unitsÚspeech_decoder_postnet_layersr   rp   Úspeech_decoder_postnet_kernelrt   ÚBatchNorm1dÚ
batch_normÚTanhrv   rö   Úspeech_decoder_postnet_dropoutr÷   )rx   ry   rz   rn   ro   r{   s        €r)   rl   z#SpeechT5BatchNormConvLayer.__init__Ã  sÛ   ø€ Ü‰ÑÔà�qŠ=Ø ×-Ñ-‰Kà ×=Ñ=ˆKà�v×;Ñ;¸aÑ?Ò?Ø!×.Ñ.‰Là!×>Ñ>ˆLä—I‘IØØØ×<Ñ<ØØ×9Ñ9¸AÑ=À!ÑCØô
ˆŒ	ô Ÿ.™.¨Ó6ˆŒà�f×:Ñ:¸QÑ>Ò>Ü Ÿg™g›iˆD�Oà"ˆDŒOä—z‘z &×"GÑ"GÓHˆ�r+   c                 ó¦   — | j                  |«      }| j                  |«      }| j                  �| j                  |«      }| j                  |«      }|S r}   )rt   r�  rv   r÷   r~   s     r)   r€   z"SpeechT5BatchNormConvLayer.forwardá  sJ   € ØŸ	™	 -Ó0ˆØŸ™¨Ó6ˆØ�?‰?Ð&Ø ŸO™O¨MÓ:ˆMØŸ™ ]Ó3ˆØÐr+   r�   r‚   r‡   s   @r)   r{  r{  Â  s   ø„ õIö<r+   r{  c                   ó^   ‡ — e Zd Zˆ fd„Zdej
                  fd„Zdej
                  fd„Zˆ xZS )ÚSpeechT5SpeechDecoderPostnetc           	      óš  •— t         ‰| �  «        || _        t        j                  |j
                  |j                  |j                  z  «      | _        t        j                  |j
                  |j                  «      | _	        t        j                  t        |j                  «      D �cg c]  }t        ||«      ‘Œ c}«      | _        y c c}w r}   )rk   rl   ry   r   r)  rÞ   rd  r-   Úfeat_outÚprob_outr  rL   r~  r{  rf  rl  s      €r)   rl   z%SpeechT5SpeechDecoderPostnet.__init__ë  s�   ø€ Ü‰ÑÔØˆŒäŸ	™	 &×"4Ñ"4°f×6IÑ6IÈF×LcÑLcÑ6cÓdˆŒÜŸ	™	 &×"4Ñ"4°f×6MÑ6MÓNˆŒä—m‘mÜ<AÀ&×BfÑBfÓ<gÖh°qÔ'¨°Õ2Òhó
ˆ�ùÚhs   Â(Cr   c                 ó  — | j                  |«      j                  |j                  d«      d| j                  j                  «      }| j                  |«      }| j                  |«      j                  |j                  d«      d«      }|||fS )Nr   r"   )rˆ  r¼   rÂ   ry   rd  Úpostnetr‰  )rx   r   Úoutputs_before_postnetÚoutputs_after_postnetÚlogitss        r)   r€   z$SpeechT5SpeechDecoderPostnet.forwardö  s~   € Ø!%§¡¨}Ó!=×!BÑ!BÀ=×CUÑCUÐVWÓCXÐZ\Ð^b×^iÑ^i×^vÑ^vÓ!wÐØ $§¡Ð-CÓ DÐØ—‘˜}Ó-×2Ñ2°=×3EÑ3EÀaÓ3HÈ"ÓMˆØ%Ð'<¸fÐDÐDr+   c                 ó‚   — |j                  dd«      }| j                  D ]
  } ||«      }Œ ||j                  dd«      z   S rì   )r�   rf  )rx   r   Úlayer_outputr  s       r)   r‹  z$SpeechT5SpeechDecoderPostnet.postnetü  sI   € Ø$×.Ñ.¨q°!Ó4ˆØ—[‘[ò 	/ˆEÙ  Ó.‰Lð	/à˜|×5Ñ5°a¸Ó;Ñ;Ð;r+   )	rƒ   r„   r…   rl   r´   rÓ   r€   r‹  r†   r‡   s   @r)   r†  r†  ê  s*   ø„ ô	
ðE U§\¡\ó Eð< U§\¡\÷ <r+   r†  c                   óJ   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zdej                  fd„Zˆ xZ	S )ÚSpeechT5TextEncoderPrenetc                 ó  •— t         ‰| �  «        || _        t        j                  |j
                  |j                  |j                  «      | _        t        |j                  |j                  |j                  «      | _        y r}   )rk   rl   ry   r   r  Ú
vocab_sizerÞ   r   Úembed_tokensrî   rh  Úmax_text_positionsri  r,  s     €r)   rl   z"SpeechT5TextEncoderPrenet.__init__  se   ø€ Ü‰ÑÔØˆŒÜŸL™L¨×):Ñ):¸F×<NÑ<NÐPV×PcÑPcÓdˆÔÜ @Ø×%Ñ%Ø×ÑØ×%Ñ%ó!
ˆÕr+   c                 ó   — | j                   S r}   ©r•  r<  s    r)   Úget_input_embeddingsz.SpeechT5TextEncoderPrenet.get_input_embeddings  ó   € Ø× Ñ Ð r+   c                 ó   — || _         y r}   r˜  ©rx   Úvalues     r)   Úset_input_embeddingsz.SpeechT5TextEncoderPrenet.set_input_embeddings  ó
   € Ø!ˆÕr+   r   c                 óJ   — | j                  |«      }| j                  |«      }|S r}   )r•  ri  )rx   r   rq  s      r)   r€   z!SpeechT5TextEncoderPrenet.forward  s(   € Ø×)Ñ)¨)Ó4ˆØ×-Ñ-¨mÓ<ˆØÐr+   )
rƒ   r„   r…   rl   r™  rž  r´   rÓ   r€   r†   r‡   s   @r)   r’  r’    s"   ø„ ô
ò!ò"ð §¡÷ r+   r’  c            	       ó’   ‡ — e Zd Zˆ fd„Zd„ Zd„ Z	 	 ddej                  deej                     dee
ej                        fd„Zˆ xZS )	ÚSpeechT5TextDecoderPrenetc                 óÐ  •— t         ‰| �  «        || _        t        j                  |j
                  «      | _        |j                  rt        j                  |j                  «      nd| _        t        j                  |j                  |j                  |j                  «      | _        t!        |j"                  |j                  z   dz   |j                  |j                  «      | _        y )Nrô   r   )rk   rl   ry   r   rö   rh  r÷   Úscale_embeddingr²   ÚsqrtrÞ   Úembed_scaler  r”  r   r•  rš   r–  Úembed_positionsr,  s     €r)   rl   z"SpeechT5TextDecoderPrenet.__init__  s­   ø€ Ü‰ÑÔØˆŒÜ—z‘z &×";Ñ";Ó<ˆŒØ<B×<RÒ<Rœ4Ÿ9™9 V×%7Ñ%7Ô8ÐX[ˆÔäŸL™L¨×):Ñ):¸F×<NÑ<NÐPV×PcÑPcÓdˆÔäDØ×%Ñ%¨×(;Ñ(;Ñ;¸aÑ?Ø×ÑØ×Ñó 
ˆÕr+   c                 ó   — | j                   S r}   r˜  r<  s    r)   r™  z.SpeechT5TextDecoderPrenet.get_input_embeddings)  rš  r+   c                 ó   — || _         y r}   r˜  rœ  s     r)   rž  z.SpeechT5TextDecoderPrenet.set_input_embeddings,  rŸ  r+   r   r.   Úpast_key_valuesc                 ó.  — |�&|j                  «       }|j                  d|d   «      }nt        d«      ‚|�|d   d   j                  d   nd}| j	                  ||«      }| j                  |«      | j                  z  }||z  }| j                  |«      }||fS )Nr"   z'You have to specify `decoder_input_ids`r   r    )rÂ   r¼   r&   r$   r§  r•  r¦  r÷   )rx   r   r.   rª  Úinput_shaperÀ   Ú	positionsrq  s           r)   r€   z!SpeechT5TextDecoderPrenet.forward/  sª   € ð Ð Ø#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;‰IäÐFÓGÐGàCRÐC^ °Ñ!3°AÑ!6×!<Ñ!<¸QÒ!?ÐdeÐØ×(Ñ(¨Ð4JÓKˆ	à×)Ñ)¨)Ó4°t×7GÑ7GÑGˆØ˜Ñ"ˆØŸ™ ]Ó3ˆà˜nÐ,Ð,r+   r]  )rƒ   r„   r…   rl   r™  rž  r´   rÓ   r   r^  r   r_  r€   r†   r‡   s   @r)   r¢  r¢    sZ   ø„ ô
ò!ò"ð 6:Ø=Añ	-à—<‘<ð-ð ! ×!1Ñ!1Ñ2ð-ð " $ u×'8Ñ'8Ñ"9Ñ:÷	-r+   r¢  c                   óJ   ‡ — e Zd Zˆ fd„Zdej
                  fd„Zd„ Zd„ Zˆ xZ	S )ÚSpeechT5TextDecoderPostnetc                 ó’   •— t         ‰| �  «        || _        t        j                  |j
                  |j                  d¬«      | _        y )NF©rj   )rk   rl   ry   r   r)  rÞ   r”  Úlm_headr,  s     €r)   rl   z#SpeechT5TextDecoderPostnet.__init__F  s5   ø€ Ü‰ÑÔØˆŒÜ—y‘y ×!3Ñ!3°V×5FÑ5FÈUÔSˆ�r+   r   c                 ó$   — | j                  |«      S r}   ©r²  r~   s     r)   r€   z"SpeechT5TextDecoderPostnet.forwardK  s   € Ø�|‰|˜MÓ*Ð*r+   c                 ó   — | j                   S r}   r´  r<  s    r)   Úget_output_embeddingsz0SpeechT5TextDecoderPostnet.get_output_embeddingsN  ó   € Ø�|‰|Ðr+   c                 ó   — || _         y r}   r´  ©rx   Únew_embeddingss     r)   Úset_output_embeddingsz0SpeechT5TextDecoderPostnet.set_output_embeddingsQ  s	   € Ø%ˆ�r+   )
rƒ   r„   r…   rl   r´   rÓ   r€   r¶  r»  r†   r‡   s   @r)   r¯  r¯  E  s#   ø„ ôTð
+ U§\¡\ó +òö&r+   r¯  c                   ó”  ‡ — e Zd ZdZ	 	 	 ddededededef
ˆ fd„Zdej                  d	ed
efd„Z
	 	 	 	 	 	 ddej                  deej                     deeej                        deej                     deej                     deej                     dedeej                  eej                     eeej                        f   fd„Zˆ xZS )ÚSpeechT5Attentionz“
    Multi-headed attention from 'Attention Is All You Need' paper with relative position bias (see
    https://aclanthology.org/N18-2074.pdf)
    Ú	embed_dimÚ	num_headsr÷   Ú
is_decoderrj   c                 óî  •— t         ‰| �  «        || _        || _        || _        ||z  | _        | j
                  |z  | j                  k7  rt        d| j                  › d|› d�«      ‚| j
                  dz  | _        || _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        y )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).g      à¿r±  )rk   rl   r¾  r¿  r÷   Úhead_dimr&   ÚscalingrÀ  r   r)  Úk_projÚv_projÚq_projÚout_proj)rx   r¾  r¿  r÷   rÀ  rj   r{   s         €r)   rl   zSpeechT5Attention.__init__[  sÖ   ø€ ô 	‰ÑÔØ"ˆŒØ"ˆŒØˆŒØ! YÑ.ˆŒà�M‰M˜IÑ%¨$¯.©.Ò8ÜØMÈdÏnÉnÐM]Ø$ Y K¨rð3óð ð —}‘} dÑ*ˆŒØ$ˆŒä—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜŸ	™	 )¨Y¸TÔBˆ�r+   rø   rÆ   rÅ   c                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S rì   )r¼   r¿  rÂ  r�   Ú
contiguous)rx   rø   rÆ   rÅ   s       r)   Ú_shapezSpeechT5Attention._shapev  s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr+   r   Úkey_value_statesÚpast_key_valuer.   Úlayer_head_maskÚposition_biasÚoutput_attentionsr7   c                 óD  — |du}|j                  «       \  }	}
}| j                  |«      | j                  z  }|r|�|d   }|d   }�n
|rE| j                  | j	                  |«      d|	«      }| j                  | j                  |«      d|	«      }nÃ|�}| j                  | j	                  |«      d|	«      }| j                  | j                  |«      d|	«      }t        j                  |d   |gd¬«      }t        j                  |d   |gd¬«      }nD| j                  | j	                  |«      d|	«      }| j                  | j                  |«      d|	«      }| j                  r||f}|	| j                  z  d| j                  f} | j                  ||
|	«      j                  |Ž } |j                  |Ž } |j                  |Ž }|j                  d«      }t        j                  ||j                  dd«      «      }|j                  «       |	| j                  z  |
|fk7  r/t        d|	| j                  z  |
|f› d|j                  «       › �«      ‚|�Á|j                  «       j                  |	| j                  z  d| j                  «      j                  dd«      }t        j                   ||j                  d	d«      «      }|j                  dd«      j                  |	| j                  z  |j                  d«      |j                  d«      «      }||z  }|�{|j                  «       |	d|
|fk7  r#t        d
|	d|
|f› d|j                  «       › �«      ‚|j                  |	| j                  |
|«      |z   }|j                  |	| j                  z  |
|«      }t"        j$                  j'                  |d¬«      }|�›|j                  «       | j                  fk7  r*t        d| j                  f› d|j                  «       › �«      ‚|j                  dddd«      |j                  |	| j                  |
|«      z  }|j                  |	| j                  z  |
|«      }|r?|j                  |	| j                  |
|«      }|j                  |	| j                  z  |
|«      }nd}t"        j$                  j)                  || j(                  | j*                  ¬«      }t        j                  ||«      }|j                  «       |	| j                  z  |
| j                  fk7  r7t        d|	| j                  |
| j                  f› d|j                  «       › �«      ‚|j                  |	| j                  |
| j                  «      }|j                  dd«      }|j-                  |	|
| j.                  «      }| j1                  |«      }|||fS )z#Input shape: Batch x Time x ChannelNr   r   r"   r    r°   z$Attention weights should be of size z	, but is r�   z!Attention mask should be of size z/Head mask for a single layer should be of size )ró   r  z `attn_output` should be of size )rÂ   rÆ  rÃ  rÊ  rÄ  rÅ  r´   r¹   rÀ  r¿  rÂ  r¼   Úbmmr�   r&   rÉ  Úmatmulr   rv  Úsoftmaxr÷   r  rX   r¾  rÇ  )rx   r   rË  rÌ  r.   rÍ  rÎ  rÏ  Úis_cross_attentionrÅ   Útgt_lenr[   Úquery_statesÚ
key_statesÚvalue_statesÚ
proj_shapeÚsrc_lenÚattn_weightsÚ	reshape_qÚrel_pos_biasÚattn_weights_reshapedÚ
attn_probsÚattn_outputs                          r)   r€   zSpeechT5Attention.forwardy  s„  € ð .°TÐ9Ðà'×,Ñ,Ó.‰ˆˆW�að —{‘{ =Ó1°D·L±LÑ@ˆá .Ð"<à'¨Ñ*ˆJØ)¨!Ñ,ŠLÙàŸ™ T§[¡[Ð1AÓ%BÀBÈÓLˆJØŸ;™; t§{¡{Ð3CÓ'DÀbÈ#ÓN‰LØÐ'àŸ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLÜŸ™ N°1Ñ$5°zÐ#BÈÔJˆJÜ Ÿ9™9 n°QÑ&7¸Ð%FÈAÔN‰Lð Ÿ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLà�?Š?ð )¨,Ð7ˆNà˜DŸN™NÑ*¨B°·±Ð>ˆ
ØC�t—{‘{ <°¸#Ó>×CÑCÀZÐPˆØ$�Z—_‘_ jÐ1ˆ
Ø(�|×(Ñ(¨*Ð5ˆà—/‘/ !Ó$ˆÜ—y‘y ¨z×/CÑ/CÀAÀqÓ/IÓJˆà×ÑÓ 3¨¯©Ñ#7¸À'Ð"JÒJÜØ6¸¸d¿n¹nÑ8LÈgÐW^Ð7_Ð6`ð aØ ×%Ñ%Ó'Ð(ð*óð ð Ð$Ø$×/Ñ/Ó1×6Ñ6°s¸T¿^¹^Ñ7KÈRÐQU×Q^ÑQ^Ó_×iÑiÐjkÐmnÓoˆIÜ Ÿ<™<¨	°=×3JÑ3JÈ2ÈrÓ3RÓSˆLØ'×1Ñ1°!°QÓ7×<Ñ<Ø�d—n‘nÑ$ m×&8Ñ&8¸Ó&;¸]×=OÑ=OÐPQÓ=RóˆLð ˜LÑ(ˆLàÐ%Ø×"Ñ"Ó$¨¨a°¸'Ð(BÒBÜ Ø7¸¸aÀÈ'Ð8RÐ7SÐS\Ð]k×]pÑ]pÓ]rÐ\sÐtóð ð (×,Ñ,¨S°$·.±.À'È7ÓSÐVdÑdˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLä—}‘}×,Ñ,¨\¸rÐ,ÓBˆàÐ&Ø×#Ñ#Ó%¨$¯.©.Ð):Ò:Ü ØEÀtÇ~Á~ÐFWÐEXð YØ'×,Ñ,Ó.Ð/ð1óð ð +×/Ñ/°°2°q¸!Ó<¸|×?PÑ?PÐQTÐVZ×VdÑVdÐfmÐovÓ?wÑwˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLáð
 %1×$5Ñ$5°c¸4¿>¹>È7ÐT[Ó$\Ð!Ø0×5Ñ5°c¸D¿N¹NÑ6JÈGÐU\Ó]‰Là$(Ð!ä—]‘]×*Ñ*¨<¸4¿<¹<ÐRV×R_ÑR_Ð*Ó`ˆ
ä—i‘i 
¨LÓ9ˆà×ÑÓ #¨¯©Ñ"6¸ÀÇÁÐ!OÒOÜØ2°C¸¿¹ÈÐRV×R_ÑR_Ð3`Ð2að bØ×$Ñ$Ó&Ð'ð)óð ð
 "×&Ñ& s¨D¯N©N¸GÀTÇ]Á]ÓSˆØ!×+Ñ+¨A¨qÓ1ˆð "×)Ñ)¨#¨w¸¿¹ÓGˆà—m‘m KÓ0ˆàÐ1°>ÐAÐAr+   )r1   FT)NNNNNF)rƒ   r„   r…   rÐ   r;   r·   rN   rl   r´   rÓ   rÊ  r   r   r€   r†   r‡   s   @r)   r½  r½  U  sF  ø„ ñð Ø ØñCàðCð ðCð ð	Cð
 ðCð õCð6e˜UŸ\™\ð e°Cð e¸có eð 48Ø8<Ø15Ø26Ø04Ø"'ñyBà—|‘|ðyBð # 5§<¡<Ñ0ðyBð !  u§|¡|Ñ!4Ñ5ð	yBð
 ! §¡Ñ.ðyBð " %§,¡,Ñ/ðyBð   §¡Ñ-ðyBð  ðyBð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷yBr+   r½  c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚSpeechT5FeedForwardc                 óÎ  •— t         ‰| �  «        t        j                  |j                  «      | _        t        j                  |j                  |«      | _        t        |j                  t        «      rt        |j                     | _        n|j                  | _        t        j                  ||j                  «      | _        t        j                  |j                  «      | _        y r}   )rk   rl   r   rö   Úactivation_dropoutÚintermediate_dropoutr)  rÞ   Úintermediate_denseÚ
isinstanceÚ
hidden_actÚstrr   Úintermediate_act_fnÚoutput_denseÚhidden_dropoutÚoutput_dropout)rx   ry   Úintermediate_sizer{   s      €r)   rl   zSpeechT5FeedForward.__init__ö  s¡   ø€ Ü‰ÑÔÜ$&§J¡J¨v×/HÑ/HÓ$IˆÔ!ä"$§)¡)¨F×,>Ñ,>Ð@QÓ"RˆÔÜ�f×'Ñ'¬Ô-Ü'-¨f×.?Ñ.?Ñ'@ˆDÕ$à'-×'8Ñ'8ˆDÔ$äŸI™IÐ&7¸×9KÑ9KÓLˆÔÜ Ÿj™j¨×)>Ñ)>Ó?ˆÕr+   c                 ó°   — | j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }| j	                  |«      }|S r}   )ræ  rê  rå  rë  rí  r~   s     r)   r€   zSpeechT5FeedForward.forward  sX   € Ø×/Ñ/°Ó>ˆØ×0Ñ0°Ó?ˆØ×1Ñ1°-Ó@ˆà×)Ñ)¨-Ó8ˆØ×+Ñ+¨MÓ:ˆØÐr+   r‚   r‡   s   @r)   râ  râ  õ  s   ø„ ô@ör+   râ  c                   ó¬   ‡ — e Zd Zdefˆ fd„Z	 	 	 	 d	dej                  deej                     deej                     deej                     def
d„Z	ˆ xZ
S )
ÚSpeechT5EncoderLayerry   c                 óÄ  •— t         ‰| �  «        t        |j                  |j                  |j
                  d¬«      | _        t        j                  |j                  «      | _
        t        j                  |j                  |j                  ¬«      | _        t        ||j                  «      | _        t        j                  |j                  |j                  ¬«      | _        y )NF©r¾  r¿  r÷   rÀ  r&  )rk   rl   r½  rÞ   Úencoder_attention_headsÚattention_dropoutÚ	attentionr   rö   rì  r÷   rŒ   r(  r�   râ  Úencoder_ffn_dimÚfeed_forwardÚfinal_layer_normr,  s     €r)   rl   zSpeechT5EncoderLayer.__init__  s¢   ø€ Ü‰ÑÔÜ*Ø×(Ñ(Ø×4Ñ4Ø×,Ñ,Øô	
ˆŒô —z‘z &×"7Ñ"7Ó8ˆŒÜŸ,™, v×'9Ñ'9¸v×?TÑ?TÔUˆŒÜ/°¸×8NÑ8NÓOˆÔÜ "§¡¨V×-?Ñ-?ÀV×EZÑEZÔ [ˆÕr+   r   r.   rÍ  rÎ  rÏ  c                 óì   — |}| j                  |||||¬«      \  }}}| j                  |«      }||z   }| j                  |«      }|| j                  |«      z   }| j	                  |«      }|f}	|r|	|fz  }	|	S )as  
        Args:
            hidden_states (`torch.FloatTensor`):
                input to the layer of shape `(batch, seq_len, hidden_size)`
            attention_mask (`torch.FloatTensor`):
                attention mask of size `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very
                large negative values.
            layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
                `(config.encoder_attention_heads,)`.
            position_bias (`torch.FloatTensor`):
                relative position embeddings of size `(seq_len, seq_len, hidden_size // encoder_attention_heads)`
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        )r   r.   rÍ  rÎ  rÏ  )rö  r÷   r�   rø  rù  )
rx   r   r.   rÍ  rÎ  rÏ  ÚresidualrÛ  r[   Úoutputss
             r)   r€   zSpeechT5EncoderLayer.forward  s›   € ð. !ˆØ)-¯©Ø'Ø)Ø+Ø'Ø/ð *8ó *
Ñ&ˆ�| Qð Ÿ™ ]Ó3ˆØ  =Ñ0ˆàŸ™¨Ó6ˆØ%¨×(9Ñ(9¸-Ó(HÑHˆØ×-Ñ-¨mÓ<ˆà Ð"ˆáØ˜�Ñ&ˆGàˆr+   )NNNF)rƒ   r„   r…   r   rl   r´   rÓ   r   rN   r€   r†   r‡   s   @r)   rñ  rñ    ss   ø„ ð\˜~õ \ð  26Ø26Ø04Ø"'ñ,à—|‘|ð,ð ! §¡Ñ.ð,ð " %§,¡,Ñ/ð	,ð
   §¡Ñ-ð,ð  ÷,r+   rñ  c                   ó$  ‡ — e Zd Zdefˆ fd„Z	 	 	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     deej                     d	eeej                        d
ee	   dee	   fd„Z
ˆ xZS )ÚSpeechT5DecoderLayerry   c                 óˆ  •— t         ‰| �  «        t        |j                  |j                  |j
                  d¬«      | _        t        j                  |j                  «      | _
        t        j                  |j                  |j                  ¬«      | _        t        |j                  |j                  |j
                  d¬«      | _        t        j                  |j                  |j                  ¬«      | _        t!        ||j"                  «      | _        t        j                  |j                  |j                  ¬«      | _        y )NTró  r&  )r÷   rÀ  )rk   rl   r½  rÞ   Údecoder_attention_headsrõ  Ú	self_attnr   rö   rì  r÷   rŒ   r(  Úself_attn_layer_normÚencoder_attnÚencoder_attn_layer_normrâ  Údecoder_ffn_dimrø  rù  r,  s     €r)   rl   zSpeechT5DecoderLayer.__init__K  sï   ø€ Ü‰ÑÔÜ*Ø×(Ñ(Ø×4Ñ4Ø×,Ñ,Øô	
ˆŒô —z‘z &×"7Ñ"7Ó8ˆŒÜ$&§L¡L°×1CÑ1CÈ×I^ÑI^Ô$_ˆÔ!ä-Ø×ÑØ×*Ñ*Ø×,Ñ,Øô	
ˆÔô (*§|¡|°F×4FÑ4FÈF×LaÑLaÔ'bˆÔ$ä/°¸×8NÑ8NÓOˆÔÜ "§¡¨V×-?Ñ-?ÀV×EZÑEZÔ [ˆÕr+   r   r.   Úencoder_hidden_statesÚencoder_attention_maskrÍ  Úcross_attn_layer_head_maskrÌ  rÏ  Ú	use_cachec
                 óÀ  — |}
|�|dd nd}| j                  |||||¬«      \  }}}| j                  |«      }|
|z   }| j                  |«      }d}d}|�R|}
|�|dd nd}| j                  ||||||¬«      \  }}}| j                  |«      }|
|z   }| j	                  |«      }||z   }|| j                  |«      z   }| j                  |«      }|f}|r|||fz  }|	r||fz  }|S )a  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, hidden_size)`
            attention_mask (`torch.FloatTensor`): attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            encoder_hidden_states (`torch.FloatTensor`):
                cross attention input to the layer of shape `(batch, seq_len, hidden_size)`
            encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
                `(encoder_attention_heads,)`.
            cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
                size `(decoder_attention_heads,)`.
            past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        Nr    )r   rÌ  r.   rÍ  rÏ  r�   )r   rË  r.   rÍ  rÌ  rÏ  )r  r÷   r  r  r  rø  rù  )rx   r   r.   r  r  rÍ  r  rÌ  rÏ  r	  rû  Úself_attn_past_key_valueÚself_attn_weightsÚpresent_key_valueÚcross_attn_present_key_valueÚcross_attn_weightsÚcross_attn_past_key_valuerü  s                     r)   r€   zSpeechT5DecoderLayer.forwarda  sm  € ð< !ˆð :HÐ9S >°"°1Ñ#5ÐY]Ð à>B¿n¹nØ'Ø3Ø)Ø+Ø/ð ?Mó ?
Ñ;ˆÐ(Ð*;ð Ÿ™ ]Ó3ˆØ  =Ñ0ˆØ×1Ñ1°-Ó@ˆð (,Ð$Ø!ÐØ Ð,Ø$ˆHð @NÐ?Y¨°r°sÑ(;Ð_cÐ%ØNR×N_ÑN_Ø+Ø!6Ø5Ø :Ø8Ø"3ð O`ó OÑKˆMÐ-Ð/Kð !ŸL™L¨Ó7ˆMØ$ }Ñ4ˆMØ ×8Ñ8¸ÓGˆMð !2Ð4PÑ PÐð &¨×(9Ñ(9¸-Ó(HÑHˆØ×-Ñ-¨mÓ<ˆà Ð"ˆáØÐ)Ð+=Ð>Ñ>ˆGáØÐ)Ð+Ñ+ˆGàˆr+   )NNNNNNFT)rƒ   r„   r…   r   rl   r´   rÓ   r   r   rN   r€   r†   r‡   s   @r)   rþ  rþ  J  sÙ   ø„ ð\˜~õ \ð2 26Ø8<Ø9=Ø26Ø=AØ8<Ø,1Ø$(ñRà—|‘|ðRð ! §¡Ñ.ðRð  (¨¯©Ñ5ð	Rð
 !)¨¯©Ñ 6ðRð " %§,¡,Ñ/ðRð %-¨U¯\©\Ñ$:ðRð !  u§|¡|Ñ!4Ñ5ðRð $ D™>ðRð ˜D‘>÷Rr+   rþ  c                   ó&   — e Zd ZdZeZdZdZdZd„ Z	y)ÚSpeechT5PreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    Úspeecht5r,   Tc           
      óp  — t        |t        «      r²t        j                  j	                  |j
                  j                  ddt        j                  d|j
                  j                  d   |j
                  j                  z  z  «      z  ¬«       t        j                  j                  |j
                  j                  d«       yt        |t        «      r›t        j                  d|j                  j                  z  «      }t        j                  j!                  |j                  j                  | |¬«       t        j                  j!                  |j                  j                  | |¬«       yt        |t        j"                  «      rm|j                  j$                  j	                  d| j&                  j(                  ¬«       |j                  �%|j                  j$                  j+                  «        yyt        |t        j,                  t        j.                  f«      rJ|j                  j$                  j+                  «        |j                  j$                  j1                  d«       yt        |t        j2                  «      r t        j                  j5                  |j                  «       |j                  �jt        j                  |j6                  |j                  |j                  d   z  z  «      }t        j                  j!                  |j                  | |¬«       yyt        |t        j8                  «      rz|j                  j$                  j	                  d| j&                  j(                  ¬«       |j:                  �2|j                  j$                  |j:                     j+                  «        yyy)	zInitialize the weightsr   r    r   ©ÚmeanÚstd)ÚaÚbr1   Nrô   )rç  rÕ   r   ÚinitÚnormal_rt   rÛ   r²   r¥  rh   Úin_channelsÚ	constant_rj   r$  r*  Úin_featuresr6  r)  Údatary   Úinitializer_rangeÚzero_rŒ   r—   Úfill_rp   Úkaiming_normal_rØ   r  r�   )rx   ÚmoduleÚks      r)   Ú_init_weightsz%SpeechT5PreTrainedModel._init_weightsÁ  s‹  € ä�fÔ=Ô>Ü�G‰G�O‰OØ—‘×"Ñ"ØØœŸ	™	 ! v§{¡{×'>Ñ'>¸qÑ'AÀFÇKÁK×D[ÑD[Ñ'[Ñ"\Ó]Ñ]ð ô ô
 �G‰G×Ñ˜fŸk™k×.Ñ.°Õ2Ü˜Ô 9Ô:Ü—	‘	˜!˜f×/Ñ/×;Ñ;Ñ;Ó<ˆAÜ�G‰G×Ñ˜V×.Ñ.×5Ñ5¸!¸¸qÐÔAÜ�G‰G×Ñ˜V×.Ñ.×3Ñ3¸°r¸QÐÕ?Ü˜¤§	¡	Ô*Ø�M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡¬r¯|©|Ð <Ô=Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)Ü˜¤§	¡	Ô*Ü�G‰G×#Ñ# F§M¡MÔ2Ø�{‰{Ð&Ü—I‘I˜fŸm™m¨v×/AÑ/AÀF×DVÑDVÐWXÑDYÑ/YÑZÓ[�Ü—‘× Ñ  §¡°°°aÐ Õ8ð 'ô ˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ð .r+   N)
rƒ   r„   r…   rÐ   r   Úconfig_classÚbase_model_prefixÚmain_input_nameÚsupports_gradient_checkpointingr&  © r+   r)   r  r  ¶  s$   „ ñð
 "€LØ"ÐØ$€OØ&*Ð#ó?r+   r  c                   ó¼   ‡ — e Zd ZdZdefˆ fd„Z	 	 	 	 	 ddej                  deej                     deej                     dee
   dee
   d	ee
   d
eeef   fd„Zˆ xZS )ÚSpeechT5Encoderzu
    Transformer encoder consisting of *config.encoder_layers* layers. Each layer is a [`SpeechT5EncoderLayer`].
    ry   c                 ó  •— t         ‰| �  |«       t        j                  |j                  |j
                  ¬«      | _        t        j                  |j                  «      | _	        |j                  | _        t        j                  t        |j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _        t#        |j                  |j$                  z  |j&                  «      | _        d| _        | j-                  «        y c c}w )Nr&  F)rk   rl   r   rŒ   rÞ   r(  r�   rö   rì  r÷   Úencoder_layerdropÚ	layerdropr  rL   Úencoder_layersrñ  rf  rÿ   rô  Úencoder_max_relative_positionr§  r  Ú	post_init©rx   ry   r[   r{   s      €r)   rl   zSpeechT5Encoder.__init__å  sÃ   ø€ Ü‰Ñ˜Ô ÜŸ,™, v×'9Ñ'9¸v×?TÑ?TÔUˆŒÜ—z‘z &×"7Ñ"7Ó8ˆŒØ×1Ñ1ˆŒä—m‘mÌ5ÐQW×QfÑQfÓKgÖ$hÀaÔ%9¸&Õ%AÒ$hÓiˆŒäAØ×Ñ &×"@Ñ"@Ñ@À&×BfÑBfó 
ˆÔð ',ˆÔ#ð 	�‰Õùò %is   ÂDr   r.   Ú	head_maskrÏ  Úoutput_hidden_statesÚreturn_dictr7   c           	      ó  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�t	        ||j
                  «      }| j                  |«      }| j                  |«      }| j                  |«      }t        «       xs t        | «      }|rdnd}	|rdnd}
|�_|j                  «       d   t        | j                  «      k7  r6t        dt        | j                  «      › d|j                  «       d   › d�«      ‚t        | j                  «      D ]¬  \  }}|r|	|fz   }	d}| j                   r$t#        j$                  g «      }|| j&                  k  }|r|rY| j(                  r4| j                   r(| j+                  |j,                  |||�||   nd||«      }n |||||�||   nd|¬«      }|d   }|rd	}|sŒ¤|
d
   fz   }
Œ® |r|	|fz   }	|st/        d„ ||	|
fD «       «      S t1        ||	|
¬«      S )añ  
        Args:
            hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, feature_size)`):
                Features extracted from the speech or text input by the encoder prenet.
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing convolution and attention on padding token indices. Mask values selected in
                `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            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.
        Nr+  r   z&The head_mask should be specified for ú layers, but it is for ú.F)r.   rÎ  rÍ  rÏ  r]  r   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr}   r+  ©Ú.0Úvs     r)   ú	<genexpr>z*SpeechT5Encoder.forward.<locals>.<genexpr>`  s   è ø€ Òm˜qÐ_`Ñ_lœÑmùs   ‚Š©Úlast_hidden_stater   Ú
attentions)ry   rÏ  r6  Úuse_return_dictr   rC   r�   r÷   r§  r   r   rÂ   rQ   rf  r&   Ú	enumerater  r´   rG   r0  r  r   r!  Útupler   )rx   r   r.   r5  rÏ  r6  r7  rÎ  Úsynced_gpusÚall_hidden_statesÚall_self_attentionsÚidxÚencoder_layerÚskip_the_layerÚdropout_probabilityÚlayer_outputss                   r)   r€   zSpeechT5Encoder.forwardö  s^  € ðH 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð%ä7¸È×H[ÑH[Ó\ˆNàŸ™¨Ó6ˆØŸ™ ]Ó3ˆà×,Ñ,¨]Ó;ˆä0Ó2ÒRÔ6LÈTÓ6Rˆá"6™B¸DÐÙ$5™b¸4Ðð Ð Ø�~‰~Ó Ñ"¤c¨$¯+©+Ó&6Ò6Ü Ø<¼SÀÇÁÓ=MÐ<Nð OØ!Ÿ™Ó(¨Ñ+Ð,¨Að/óð ô
 #,¨D¯K©KÓ"8ò #	PÑˆC�Ù#Ø$5¸Ð8HÑ$HÐ!ð #ˆNØ�}Š}Ü&+§j¡j°£nÐ#Ø!4°t·~±~Ñ!E�á!¡[à×.Ò.°4·=²=Ø$(×$EÑ$EØ%×.Ñ.Ø%Ø&Ø+4Ð+@˜ 3šÀdØ%Ø)ó%‘Mñ %2Ø%Ø'5Ø&3Ø;DÐ;P¨°3ªÐVZØ*;ô%�Mð !.¨aÑ 0�áØ ,�â Ø&9¸]È1Ñ=MÐ<OÑ&OÑ#ðG#	PñJ  Ø 1°]Ð4DÑ DÐáÜÑm ]Ð4EÐGZÐ$[ÔmÓmÐmäØ+Ø+Ø*ô
ð 	
r+   ©NNNNN©rƒ   r„   r…   rÐ   r   rl   r´   r_  r   rÓ   rN   r   r   r   r€   r†   r‡   s   @r)   r-  r-  à  s¤   ø„ ñð˜~õ ð( 26Ø,0Ø,0Ø/3Ø&*ñp
à×(Ñ(ðp
ð ! §¡Ñ.ðp
ð ˜EŸL™LÑ)ð	p
ð
 $ D™>ðp
ð ' t™nðp
ð ˜d‘^ðp
ð 
ˆu�oÐ%Ñ	&÷p
r+   r-  c                   ó¼   ‡ — e Zd ZdZdefˆ fd„Z	 	 	 	 	 ddej                  deej                     deej                     dee
   dee
   d	ee
   d
eeef   fd„Zˆ xZS )ÚSpeechT5EncoderWithSpeechPrenetzŒ
    Wrapper around SpeechT5Encoder that applies SpeechT5SpeechEncoderPrenet to convert the audio waveform data to
    hidden features.
    ry   c                 ó„   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        | j                  «        y r}   )rk   rl   r0  Úprenetr-  Úwrapped_encoderr3  r,  s     €r)   rl   z(SpeechT5EncoderWithSpeechPrenet.__init__o  ó5   ø€ Ü‰Ñ˜Ô Ü1°&Ó9ˆŒÜ.¨vÓ6ˆÔð 	�‰Õr+   r,   r.   r5  rÏ  r6  r7  r7   c                 ó^   — | j                  ||«      \  }}| j                  ||||||¬«      }|S ©N)r   r.   r5  rÏ  r6  r7  ©rS  rT  ©	rx   r,   r.   r5  rÏ  r6  r7  r   rü  s	            r)   r€   z'SpeechT5EncoderWithSpeechPrenet.forwardw  sG   € ð )-¯©°LÀ.Ó(QÑ%ˆ�~à×&Ñ&Ø'Ø)ØØ/Ø!5Ø#ð 'ó 
ˆð ˆr+   rN  rO  r‡   s   @r)   rQ  rQ  i  sœ   ø„ ñð
˜~õ ð 26Ø,0Ø,0Ø/3Ø&*ñà×'Ñ'ðð ! §¡Ñ.ðð ˜EŸL™LÑ)ð	ð
 $ D™>ðð ' t™nðð ˜d‘^ðð 
ˆu�oÐ%Ñ	&÷r+   rQ  c                   óÈ   ‡ — e Zd ZdZdefˆ fd„Zd„ Zd„ Z	 	 	 	 	 ddej                  de
ej                     de
ej                     d	e
e   d
e
e   de
e   deeef   fd„Zˆ xZS )ÚSpeechT5EncoderWithTextPrenetz|
    Wrapper around SpeechT5Encoder that applies SpeechT5TextEncoderPrenet to convert the input_ids to hidden features.
    ry   c                 ó„   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        | j                  «        y r}   )rk   rl   r’  rS  r-  rT  r3  r,  s     €r)   rl   z&SpeechT5EncoderWithTextPrenet.__init__“  ó5   ø€ Ü‰Ñ˜Ô Ü/°Ó7ˆŒÜ.¨vÓ6ˆÔð 	�‰Õr+   c                 ó6   — | j                   j                  «       S r}   ©rS  r™  r<  s    r)   r™  z2SpeechT5EncoderWithTextPrenet.get_input_embeddings›  ó   € Ø�{‰{×/Ñ/Ó1Ð1r+   c                 ó:   — | j                   j                  |«       y r}   ©rS  rž  rœ  s     r)   rž  z2SpeechT5EncoderWithTextPrenet.set_input_embeddingsž  ó   € Ø�‰×(Ñ(¨Õ/r+   r,   r.   r5  rÏ  r6  r7  r7   c                 óV   — | j                  |«      }| j                  ||||||¬«      }|S rW  rX  rY  s	            r)   r€   z%SpeechT5EncoderWithTextPrenet.forward¡  s@   € ð Ÿ™ LÓ1ˆà×&Ñ&Ø'Ø)ØØ/Ø!5Ø#ð 'ó 
ˆð ˆr+   rN  )rƒ   r„   r…   rÐ   r   rl   r™  rž  r´   r_  r   rÓ   rN   r   r   r   r€   r†   r‡   s   @r)   r[  r[  Ž  s¦   ø„ ñð˜~õ ò2ò0ð 26Ø,0Ø,0Ø/3Ø&*ñà×'Ñ'ðð ! §¡Ñ.ðð ˜EŸL™LÑ)ð	ð
 $ D™>ðð ' t™nðð ˜d‘^ðð 
ˆu�oÐ%Ñ	&÷r+   r[  c                   ó¼   ‡ — e Zd ZdZdefˆ fd„Z	 	 	 	 	 ddej                  deej                     deej                     dee
   dee
   d	ee
   d
eeef   fd„Zˆ xZS )ÚSpeechT5EncoderWithoutPrenetúŒ
    This wrapper class is a helper class to correctly load pretrained checkpoints when used in combination with
    [`SpeechT5Model`].
    ry   c                 ód   •— t         ‰| �  |«       t        |«      | _        | j	                  «        y r}   )rk   rl   r-  rT  r3  r,  s     €r)   rl   z%SpeechT5EncoderWithoutPrenet.__init__¾  ó)   ø€ Ü‰Ñ˜Ô Ü.¨vÓ6ˆÔð 	�‰Õr+   r,   r.   r5  rÏ  r6  r7  r7   c                 ó0   — | j                  ||||||¬«      S rW  )rT  )rx   r,   r.   r5  rÏ  r6  r7  s          r)   r€   z$SpeechT5EncoderWithoutPrenet.forwardÅ  s.   € ð ×#Ñ#Ø&Ø)ØØ/Ø!5Ø#ð $ó 
ð 	
r+   rN  rO  r‡   s   @r)   rf  rf  ¸  sœ   ø„ ñð
˜~õ ð 26Ø,0Ø,0Ø/3Ø&*ñ
à×'Ñ'ð
ð ! §¡Ñ.ð
ð ˜EŸL™LÑ)ð	
ð
 $ D™>ð
ð ' t™nð
ð ˜d‘^ð
ð 
ˆu�oÐ%Ñ	&÷
r+   rf  c                   óV  ‡ — e Zd ZdZdefˆ fd„Z	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eeej                        dee   dee   dee   dee   deeef   fd„Zˆ xZS )ÚSpeechT5Decoderzt
    Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`SpeechT5DecoderLayer`]
    ry   c                 ó  •— t         ‰| �  |«       |j                  | _        t	        j
                  t        |j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _	        d| _
        | j                  «        y c c}w r  )rk   rl   Údecoder_layerdropr0  r   r  rL   Údecoder_layersrþ  rf  r  r3  r4  s      €r)   rl   zSpeechT5Decoder.__init__Ý  sd   ø€ Ü‰Ñ˜Ô Ø×1Ñ1ˆŒä—m‘mÌ5ÐQW×QfÑQfÓKgÖ$hÀaÔ%9¸&Õ%AÒ$hÓiˆŒà&+ˆÔ#ð 	�‰Õùò %is   ÁA>r   r.   r  r  r5  Úcross_attn_head_maskrª  r	  rÏ  r6  r7  r7   c                 ó¦  — |	�|	n| j                   j                  }	|
�|
n| j                   j                  }
|�|n| j                   j                  }|�|n| j                   j                  }|j                  «       dd }|�|d   d   j                  d   nd}t        ||||«      }|�|�t        ||j                  |d   ¬«      }t        «       xs t        | «      }| j                  r%| j                  r|rt        j                  d«       d}|
rdnd}|	rdnd}|	r|�dnd}|rdnd}t!        ||gd	d
g«      D ]j  \  }}|€Œ	|j                  «       d   t#        | j$                  «      k7  sŒ3t'        d|› dt#        | j$                  «      › d|j                  «       d   › d�«      ‚ t)        | j$                  «      D ]ã  \  }}|
r||fz   }d}| j                  r$t+        j,                  g «      }|| j.                  k  }|r|sŒE|�||   nd}| j                  r?| j                  r3| j1                  |j2                  |||||�||   nd|�||   ndd|	|«
      }n ||||||�||   nd|�||   nd||	|¬«	      }|d   }|r|||	rdnd   fz  }|	sŒÏ||d   fz   }|€ŒÛ||d   fz   }Œå |
r||fz   }|r|nd}|st5        d„ |||||fD «       «      S t7        |||||¬«      S )a  
        Args:
            hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, feature_size)`):
                Features extracted from the speech or text input by the decoder prenet.
            attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, encoder_sequence_length, hidden_size)`, *optional*):
                Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
                of the decoder.
            encoder_attention_mask (`torch.LongTensor` of shape `(batch_size, encoder_sequence_length)`, *optional*):
                Mask to avoid performing cross-attention on padding tokens indices of encoder input_ids. Mask values
                selected in `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the cross-attention modules in the decoder to avoid performing
                cross-attention on hidden heads. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
                Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
                shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
                shape `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

                Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
                cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

                If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
                that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
                all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
                This is useful if you want more control over how to convert `input_ids` indices into associated vectors
                than the model's internal embedding lookup matrix.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        Nr"   r   r    )rÕ  zZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Fr+  r5  rp  zThe `z` should be specified for r9  r:  )r.   r  r  rÍ  r  rÌ  rÏ  r	  r   r   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr}   r+  r<  s     r)   r?  z*SpeechT5Decoder.forward.<locals>.<genexpr>˜  s   è ø€ ò àØ�=ô ñùs   ‚)rA  rª  r   rB  Úcross_attentions)ry   rÏ  r6  r	  rC  rÂ   r$   r   r   rC   r   r   r  r  ÚloggerÚwarning_oncerS  rQ   rf  r&   rD  r´   rG   r0  r   r!  rE  r   )rx   r   r.   r  r  r5  rp  rª  r	  rÏ  r6  r7  r¬  rÀ   rF  rG  rH  Úall_cross_attentionsÚnext_decoder_cacheÚ	attn_maskÚ	mask_namerI  Údecoder_layerrK  rL  rÌ  rM  Ú
next_caches                               r)   r€   zSpeechT5Decoder.forwardè  s³  € ðR 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà#×(Ñ(Ó*¨3¨BÐ/ˆàCRÐC^ °Ñ!3°AÑ!6×!<Ñ!<¸QÒ!?ÐdeÐä:Ø˜K¨Ð8Nó
ˆð
 !Ð,Ð1GÐ1Sä%?Ø&¨×(;Ñ(;À[ÐQSÁ_ô&Ð"ô 1Ó2ÒRÔ6LÈTÓ6Rˆà×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øpôð "�	ñ #7™B¸DÐÙ$5™b¸4ÐÙ&7Ð<QÐ<]™rÐdhÐÙ#,™R°$Ðô %(¨Ð4HÐ(IÈKÐYoÐKpÓ$qò 	Ñ ˆI�yØÑ$Ø—>‘>Ó# AÑ&¬3¨t¯{©{Ó+;Ó<Ü$Ø 	˜{Ð*DÄSÈÏÉÓEUÐDVð WØ%ŸN™NÓ,¨QÑ/Ð0°ð3óð ð	ô #,¨D¯K©KÓ"8ò 2	VÑˆC�Ù#Ø$5¸Ð8HÑ$HÐ!ð #ˆNØ�}Š}Ü&+§j¡j°£nÐ#Ø!4°t·~±~Ñ!E�Ù¡kØà5DÐ5P˜_¨SÒ1ÐVZˆNà×*Ò*¨t¯}ª}Ø $× AÑ AØ!×*Ñ*Ø!Ø"Ø)Ø*Ø&/Ð&;�I˜c’NÀØ1EÐ1QÐ(¨Ò-ÐW[ØØ%Øó!‘ñ !.Ø!Ø#1Ø*?Ø+AØ7@Ð7L Y¨s¢^ÐRVà5IÐ5UÐ,¨SÒ1Ð[_à#1Ø&7Ø'ô!�ð *¨!Ñ,ˆMáØ" }Ñ:K±QÐQRÑ'SÐ&UÑUÐ"â Ø&9¸]È1Ñ=MÐ<OÑ&OÐ#à(Ñ4Ø+?À=ÐQRÑCSÐBUÑ+UÑ(ðe2	Vñh  Ø 1°]Ð4DÑ DÐá+4Ñ'¸$ˆ
ÙÜñ à'¨Ð5FÐH[Ð]qÐrôó ð ô 9Ø+Ø&Ø+Ø*Ø1ô
ð 	
r+   ©NNNNNNNNNNN©rƒ   r„   r…   rÐ   r   rl   r   r´   r_  r^  rÓ   r   rN   r   r   r   r€   r†   r‡   s   @r)   rl  rl  Ø  s(  ø„ ñð	˜~õ 	ð 6:Ø59Ø=AØ=AØ,0Ø7;Ø=AØ$(Ø,0Ø/3Ø&*ñ|
à × 1Ñ 1Ñ2ð|
ð ! ×!1Ñ!1Ñ2ð|
ð  (¨×(9Ñ(9Ñ:ð	|
ð
 !)¨×)9Ñ)9Ñ :ð|
ð ˜EŸL™LÑ)ð|
ð ' u§|¡|Ñ4ð|
ð " $ u×'8Ñ'8Ñ"9Ñ:ð|
ð ˜D‘>ð|
ð $ D™>ð|
ð ' t™nð|
ð ˜d‘^ð|
ð 
ˆuÐ?Ð?Ñ	@÷|
r+   rl  c                   óv  ‡ — e Zd ZdZdefˆ fd„Z	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eej                     deeej                        dee   dee   dee   dee   deeef   fd„Zˆ xZS )ÚSpeechT5DecoderWithSpeechPrenetzˆ
    Wrapper around SpeechT5Decoder that applies SpeechT5SpeechDecoderPrenet to convert log-mel filterbanks to hidden
    features.
    ry   c                 ó„   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        | j                  «        y r}   )rk   rl   ra  rS  rl  Úwrapped_decoderr3  r,  s     €r)   rl   z(SpeechT5DecoderWithSpeechPrenet.__init__­  rU  r+   r,   r.   r  r  rt  r5  rp  rª  r	  rÏ  r6  r7  r7   c                 ób   — | j                  ||«      }| j                  ||||||||	|
||¬«      }|S ©N)r   r.   r  r  r5  rp  rª  r	  rÏ  r6  r7  ©rS  r�  )rx   r,   r.   r  r  rt  r5  rp  rª  r	  rÏ  r6  r7  Údecoder_hidden_statesrü  s                  r)   r€   z'SpeechT5DecoderWithSpeechPrenet.forwardµ  sS   € ð !%§¡¨LÐ:LÓ MÐà×&Ñ&Ø/Ø)Ø"7Ø#9ØØ!5Ø+ØØ/Ø!5Ø#ð 'ó 
ˆð ˆr+   )NNNNNNNNNNNNr}  r‡   s   @r)   r  r  §  s1  ø„ ñð
˜~õ ð 59Ø59Ø=AØ=AØ59Ø,0Ø7;Ø=AØ$(Ø,0Ø/3Ø&*ñà˜u×0Ñ0Ñ1ðð ! ×!1Ñ!1Ñ2ðð  (¨×(9Ñ(9Ñ:ð	ð
 !)¨×)9Ñ)9Ñ :ðð % U§\¡\Ñ2ðð ˜EŸL™LÑ)ðð ' u§|¡|Ñ4ðð " $ u×'8Ñ'8Ñ"9Ñ:ðð ˜D‘>ðð $ D™>ðð ' t™nðð ˜d‘^ðð 
ˆuÐ?Ð?Ñ	@÷r+   r  c                   ób  ‡ — e Zd ZdZdefˆ fd„Zd„ Zd„ Z	 	 	 	 	 	 	 	 	 	 	 ddee	j                     dee	j                     dee	j                     d	ee	j                     d
ee	j                     dee	j                     deee	j                        dee   dee   dee   dee   deeef   fd„Zˆ xZS )ÚSpeechT5DecoderWithTextPrenetz{
    Wrapper around SpeechT5Decoder that applies SpeechT5TextDecoderPrenet to convert input tokens to hidden features.
    ry   c                 ó„   •— t         ‰| �  |«       t        |«      | _        t	        |«      | _        | j                  «        y r}   )rk   rl   r¢  rS  rl  r�  r3  r,  s     €r)   rl   z&SpeechT5DecoderWithTextPrenet.__init__Ü  r]  r+   c                 ó6   — | j                   j                  «       S r}   r_  r<  s    r)   r™  z2SpeechT5DecoderWithTextPrenet.get_input_embeddingsä  r`  r+   c                 ó:   — | j                   j                  |«       y r}   rb  rœ  s     r)   rž  z2SpeechT5DecoderWithTextPrenet.set_input_embeddingsç  rc  r+   r,   r.   r  r  r5  rp  rª  r	  rÏ  r6  r7  r7   c                 ój   — | j                  |||«      \  }}| j                  |||||||||	|
|¬«      }|S rƒ  r„  )rx   r,   r.   r  r  r5  rp  rª  r	  rÏ  r6  r7  r…  rü  s                 r)   r€   z%SpeechT5DecoderWithTextPrenet.forwardê  sZ   € ð 15·±¸LÈ.ÐZiÓ0jÑ-Ð˜~à×&Ñ&Ø/Ø)Ø"7Ø#9ØØ!5Ø+ØØ/Ø!5Ø#ð 'ó 
ˆð ˆr+   r|  )rƒ   r„   r…   rÐ   r   rl   r™  rž  r   r´   r_  r^  rÓ   r   rN   r   r   r   r€   r†   r‡   s   @r)   r‡  r‡  ×  s%  ø„ ñð˜~õ ò2ò0ð
 59Ø59Ø=AØ=AØ,0Ø7;Ø=AØ$(Ø,0Ø/3Ø&*ñà˜u×0Ñ0Ñ1ðð ! ×!1Ñ!1Ñ2ðð  (¨×(9Ñ(9Ñ:ð	ð
 !)¨×)9Ñ)9Ñ :ðð ˜EŸL™LÑ)ðð ' u§|¡|Ñ4ðð " $ u×'8Ñ'8Ñ"9Ñ:ðð ˜D‘>ðð $ D™>ðð ' t™nðð ˜d‘^ðð 
ˆuÐ?Ð?Ñ	@÷r+   r‡  c                   óV  ‡ — e Zd ZdZdefˆ fd„Z	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     deej                     deej                     d	eej                     d
eeej                        dee   dee   dee   dee   deeef   fd„Zˆ xZS )ÚSpeechT5DecoderWithoutPrenetrg  ry   c                 ód   •— t         ‰| �  |«       t        |«      | _        | j	                  «        y r}   )rk   rl   rl  r�  r3  r,  s     €r)   rl   z%SpeechT5DecoderWithoutPrenet.__init__  ri  r+   r,   r.   r  r  r5  rp  rª  r	  rÏ  r6  r7  r7   c                 ó>   — | j                  |||||||||	|
|¬«      }|S rƒ  )r�  )rx   r,   r.   r  r  r5  rp  rª  r	  rÏ  r6  r7  rü  s                r)   r€   z$SpeechT5DecoderWithoutPrenet.forward  sA   € ð ×&Ñ&Ø&Ø)Ø"7Ø#9ØØ!5Ø+ØØ/Ø!5Ø#ð 'ó 
ˆð ˆr+   r|  r}  r‡   s   @r)   r�  r�    s  ø„ ñð
˜~õ ð 59Ø59Ø=AØ=AØ,0Ø7;Ø=AØ$(Ø,0Ø/3Ø&*ñà˜u×0Ñ0Ñ1ðð ! ×!1Ñ!1Ñ2ðð  (¨×(9Ñ(9Ñ:ð	ð
 !)¨×)9Ñ)9Ñ :ðð ˜EŸL™LÑ)ðð ' u§|¡|Ñ4ðð " $ u×'8Ñ'8Ñ"9Ñ:ðð ˜D‘>ðð $ D™>ðð ' t™nðð ˜d‘^ðð 
ˆuÐ?Ð?Ñ	@÷r+   r�  c                   ó¦   ‡ — e Zd ZdZdefˆ fd„Zdej                  dej                  dej                  dej                  fd„Z
d	„ Zed
„ «       Zˆ xZS )Ú$SpeechT5GuidedMultiheadAttentionLosszà
    Guided attention loss from the paper [Efficiently Trainable Text-to-Speech System Based on Deep Convolutional
    Networks with Guided Attention](https://arxiv.org/abs/1710.08969), adapted for multi-head attention.
    ry   c                 óf   •— t         ‰| �  «        |j                  | _        |j                  | _        y r}   )rk   rl   Úguided_attention_loss_sigmaÚsigmaÚguided_attention_loss_scaleÚscaler,  s     €r)   rl   z-SpeechT5GuidedMultiheadAttentionLoss.__init__<  s(   ø€ Ü‰ÑÔØ×7Ñ7ˆŒ
Ø×7Ñ7ˆ�
r+   rB  Úinput_masksÚoutput_masksr7   c                 óF  — | j                  |||j                  «      }|j                  d«      |j                  d«      z  }|j                  |j                  «      j                  d«      }||z  }t	        j
                  |j                  |«      «      }| j                  |z  S )aY  
        Compute the attention loss.

        Args:
            attentions (`torch.FloatTensor` of shape `(batch_size, layers * heads, output_sequence_length, input_sequence_length)`):
                Batch of multi-head attention weights
            input_masks (`torch.BoolTensor` of shape `(batch_size, input_sequence_length)`):
                Input attention mask as booleans.
            output_masks (`torch.BoolTensor` of shape `(batch_size, output_sequence_length)`):
                Target attention mask as booleans.

        Returns:
            `torch.Tensor` with the loss value
        r"   r�   r   )Ú_make_guided_attention_masksr§   r¸   rª   r´   r  Úmasked_selectr–  )rx   rB  r—  r˜  Úguided_attn_masksÚmasksÚlossesÚlosss           r)   r€   z,SpeechT5GuidedMultiheadAttentionLoss.forwardA  s‘   € ð" !×=Ñ=¸kÈ<ÐYc×YjÑYjÓkÐØ×&Ñ& rÓ*¨[×-BÑ-BÀ2Ó-FÑFˆØ—‘˜×*Ñ*Ó+×5Ñ5°aÓ8ˆà" ZÑ/ˆÜ�z‰z˜&×.Ñ.¨uÓ5Ó6ˆØ�z‰z˜DÑ Ð r+   c                 ór  — |j                  d«      }|j                  d«      }t        j                  t        |«      |j                  d   |j                  d   f|¬«      }t        t        ||«      «      D ]0  \  }\  }}	| j                  ||	| j                  |«      ||d |	…d |…f<   Œ2 |j                  d«      S )Nr"   r   rH  )
rJ   r´   rM   rQ   r$   rD  rS  Ú_make_guided_attention_maskr”  r¸   )
rx   r—  r˜  r§   r\   rL  rœ  rI  ÚilenÚolens
             r)   rš  zASpeechT5GuidedMultiheadAttentionLoss._make_guided_attention_masksZ  sÄ   € Ø#Ÿ™¨Ó+ˆØ%×)Ñ)¨"Ó-ˆä!ŸK™K¬¨[Ó)9¸<×;MÑ;MÈaÑ;PÐR]×RcÑRcÐdeÑRfÐ(gÐpvÔwÐä!*¬3¨}¸nÓ+MÓ!Nò 	tÑˆC‘�$˜Ø37×3SÑ3SÐTXÐZ^Ð`d×`jÑ`jÐlrÓ3sÐ˜c 5 D 5¨%¨4¨%Ð/Ò0ð	tð !×*Ñ*¨1Ó-Ð-r+   c                 ó(  — t        j                  t        j                  | |¬«      t        j                  ||¬«      d¬«      \  }}|j                  «       |z  }|j                  «       | z  }dt        j                  ||z
  dz   d|dz  z  z  «      z
  S )NrH  Úxy)Úindexingrô   r    )r´   ÚmeshgridrP   r·   rµ   )r=   Úoutput_lengthr”  r§   Úgrid_yÚgrid_xs         r)   r¡  z@SpeechT5GuidedMultiheadAttentionLoss._make_guided_attention_maske  s‚   € äŸ™Ü�L‰L˜¨fÔ5Ü�L‰L˜¨vÔ6Øô
‰ˆ�ð
 —‘“ -Ñ/ˆØ—‘“ ,Ñ.ˆØ”U—Y‘Y &¨6¡/°aÑ!7Ð8¸AÀÈÁ¹NÑKÓLÑLÐLr+   )rƒ   r„   r…   rÐ   r   rl   r´   r_  Ú
BoolTensorrÓ   r€   rš  rÑ   r¡  r†   r‡   s   @r)   r‘  r‘  6  sj   ø„ ñð
8˜~õ 8ð
!Ø×+Ñ+ð!Ø:?×:JÑ:Jð!ØZ_×ZjÑZjð!à	�‰ó!ò2	.ð ñMó ôMr+   r‘  c                   óâ   ‡ — e Zd ZdZdefˆ fd„Z	 ddej                  dej                  dej                  dej                  dej                  d	e	ej                     d
ej                  fd„Zˆ xZS )ÚSpeechT5SpectrogramLossz;
    Loss computation used by SpeechT5ForTextToSpeech.
    ry   c                 ó(  •— t         ‰| �  «        |j                  | _        |j                  | _        |j                  | _        t        «       | _        t        t        j                  d«      ¬«      | _
        | j                  rt        |«      | _        y y )Ng      @)Ú
pos_weight)rk   rl   Úuse_guided_attention_lossÚguided_attention_loss_num_headsr-   r
   Úl1_criterionr   r´   rø   Úbce_criterionr‘  Úattn_criterionr,  s     €r)   rl   z SpeechT5SpectrogramLoss.__init__v  ss   ø€ Ü‰ÑÔØ)/×)IÑ)IˆÔ&Ø/5×/UÑ/UˆÔ,Ø &× 7Ñ 7ˆÔä"›HˆÔÜ.¼%¿,¹,ÀsÓ:KÔLˆÔà×)Ò)Ü"FÀvÓ"NˆDÕð *r+   r.   rŒ  r�  rŽ  Úlabelsrs  r7   c           	      óV  — |dk7  }|j                  |«      }|j                  |«      }|j                  |«      }| j                  ||«      | j                  ||«      z   }|d d …d d …df   }	t        j                  |	 dz  t        j                  |	j                  d«      d«      j                  |	j                  «      gd¬«      }
|
d d …dd …f   j                  |	«      }
|j                  |	«      }| j                  ||
«      }||z   }| j                  r“t        j                  |D �cg c]  }|d d …d | j                  …f   ‘Œ c}d¬«      }|dk(  }|d d …d d …df   }| j                  dkD  r#|d d …| j                  dz
  d | j                  …f   }| j                  |||«      }||z  }|S c c}w )Nr0   r   rô   r   r°   )r›  r²  r´   r¹   rS   rÂ   rª   r§   r³  r°  r±  r-   r´  )rx   r.   rŒ  r�  rŽ  rµ  rs  rD  Úl1_lossr�  Ústop_labelsÚbce_lossrŸ  ÚxÚattnr—  r˜  Ú	attn_losss                     r)   r€   zSpeechT5SpectrogramLoss.forward‚  s½  € ð  Ñ'ˆð ×%Ñ% lÓ3ˆØ!7×!EÑ!EÀlÓ!SÐØ 5× CÑ CÀLÓ QÐð ×#Ñ#Ð$9¸6ÓBÀT×EVÑEVÐWmÐouÓEvÑvˆð šQ¢ 1˜WÑ%ˆÜ—i‘i % ¨#¡¬u¯z©z¸%¿*¹*ÀQ»-ÈÓ/K×/NÑ/NÈuÏ|É|Ó/\Ð ]ÐcdÔeˆØ!¢! Q¡R %Ñ(×6Ñ6°uÓ=ˆØ×%Ñ% eÓ,ˆð ×%Ñ% f¨kÓ:ˆð ˜Ñ!ˆð ×)Ò)Ü—9‘9ÐTdÖeÈq˜a¢Ð#I T×%IÑ%IÐ#IÐ IÓJÒeÐklÔmˆDØ(¨AÑ-ˆKØ'ªª1¨a¨Ñ0ˆLØ×$Ñ$ qÒ(Ø+ªA¨t×/DÑ/DÀqÑ/HÐ/aÈD×LaÑLaÐ/aÐ,aÑb�Ø×+Ñ+¨D°+¸|ÓLˆIØ�IÑˆDàˆùò fs   Ä$F&r}   )rƒ   r„   r…   rÐ   r   rl   r´   r^  r_  r   rÓ   r€   r†   r‡   s   @r)   r­  r­  q  s‘   ø„ ñð
O˜~õ 
Oð& 9=ñ)à×(Ñ(ð)ð !&× 1Ñ 1ð)ð  %×0Ñ0ð	)ð
 ×!Ñ!ð)ð ×!Ñ!ð)ð # 5×#4Ñ#4Ñ5ð)ð 
�‰÷)r+   r­  aó  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`SpeechT5Config`]):
            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
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
        encoder ([`SpeechT5EncoderWithSpeechPrenet`] or [`SpeechT5EncoderWithTextPrenet`] or `None`):
            The Transformer encoder module that applies the appropiate speech or text encoder prenet. If `None`,
            [`SpeechT5EncoderWithoutPrenet`] will be used and the `input_values` are assumed to be hidden states.
        decoder ([`SpeechT5DecoderWithSpeechPrenet`] or [`SpeechT5DecoderWithTextPrenet`] or `None`):
            The Transformer decoder module that applies the appropiate speech or text decoder prenet. If `None`,
            [`SpeechT5DecoderWithoutPrenet`] will be used and the `decoder_input_values` are assumed to be hidden
            states.
aM  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`SpeechT5Config`]):
            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
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a­  
    Args:
        attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing convolution and attention on padding token indices. Mask values selected in `[0,
            1]`:

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

            [What are attention masks?](../glossary#attention-mask)

            <Tip warning={true}>

            `attention_mask` should only be passed if the corresponding processor has `config.return_attention_mask ==
            True`. For all models whose processor has `config.return_attention_mask == False`, `attention_mask` should
            **not** be passed to avoid degraded performance when doing batched inference. For such models
            `input_values` should simply be padded with 0 and passed without `attention_mask`. Be aware that these
            models also yield slightly different results depending on whether `input_values` is padded or not.

            </Tip>

        decoder_attention_mask (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_values`. Causal mask will
            also be used by default.

            If you want to change padding behavior, you should read [`SpeechT5Decoder._prepare_decoder_attention_mask`]
            and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
            information on the default strategy.

        head_mask (`torch.FloatTensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the attention modules in the encoder. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        decoder_head_mask (`torch.FloatTensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the attention modules in the decoder. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the cross-attention modules. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*):
            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.

        past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
            Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
            `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
            `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

            Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
            blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

            If `past_key_values` are used, the user can optionally input only the last `decoder_input_values` (those
            that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_values` of shape `(batch_size, sequence_length)`. decoder_inputs_embeds (`torch.FloatTensor`
            of shape `(batch_size, target_sequence_length, hidden_size)`, *optional*): Optionally, instead of passing
            `decoder_input_values` you can choose to directly pass an embedded representation. If `past_key_values` is
            used, optionally only the last `decoder_inputs_embeds` have to be input (see `past_key_values`). This is
            useful if you want more control over how to convert `decoder_input_values` indices into associated vectors
            than the model's internal embedding lookup matrix.

        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).

        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.

        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.
zlThe bare SpeechT5 Encoder-Decoder Model outputting raw hidden-states without any specific pre- or post-nets.c            #       ón  ‡ — e Zd Z	 	 ddedeej                     deej                     fˆ fd„Zd„ Zd„ Z	d„ Z
d„ Zd	„ Z ee«       eee¬
«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej&                     deej(                     deej&                     deej(                     deej*                     deej*                     deej&                     deeeej*                           deeeej*                           dee   deej*                     dee   dee   dee   deeej*                     ef   fd„«       «       Zˆ xZS )ÚSpeechT5Modelry   ÚencoderÚdecoderc                 ó¢   •— t         ‰| �  |«       || _        |€t        |«      n|| _        |€t        |«      n|| _        | j                  «        y r}   )rk   rl   ry   rf  r¿  r�  rÀ  r3  )rx   ry   r¿  rÀ  r{   s       €r)   rl   zSpeechT5Model.__init__2  sM   ø€ ô 	‰Ñ˜Ô ØˆŒØ?F¸Ô3°FÔ;ÐT[ˆŒØ?F¸Ô3°FÔ;ÐT[ˆŒð 	�‰Õr+   c                 óÞ   — t        | j                  t        «      r| j                  j                  «       S t        | j                  t
        «      r| j                  j                  «       S t        ‚r}   )rç  r¿  r[  r™  rÀ  r‡  ÚNotImplementedErrorr<  s    r)   r™  z"SpeechT5Model.get_input_embeddings@  sL   € Ü�d—l‘lÔ$AÔBØ—<‘<×4Ñ4Ó6Ð6Ü�d—l‘lÔ$AÔBØ—<‘<×4Ñ4Ó6Ð6Ü!Ð!r+   c                 óÚ   — t        | j                  t        «      r| j                  j                  |«       t        | j                  t
        «      r| j                  j                  |«       y y r}   )rç  r¿  r[  rž  rÀ  r‡  rœ  s     r)   rž  z"SpeechT5Model.set_input_embeddingsG  sJ   € Ü�d—l‘lÔ$AÔBØ�L‰L×-Ñ-¨eÔ4Ü�d—l‘lÔ$AÔBØ�L‰L×-Ñ-¨eÕ4ð Cr+   c                 ó   — | j                   S r}   )r¿  r<  s    r)   Úget_encoderzSpeechT5Model.get_encoderM  r·  r+   c                 ó   — | j                   S r}   )rÀ  r<  s    r)   Úget_decoderzSpeechT5Model.get_decoderP  r·  r+   c                 ó‚   — t        | j                  t        «      r%| j                  j                  j	                  «        yy©z¨
        Calling this function will disable the gradient computation for the feature encoder so that its parameter will
        not be updated during training.
        N)rç  r¿  rQ  rS  r=  r<  s    r)   r=  z$SpeechT5Model.freeze_feature_encoderS  s/   € ô
 �d—l‘lÔ$CÔDØ�L‰L×Ñ×6Ñ6Õ8ð Er+   ©Úoutput_typer'  r,   r.   Údecoder_input_valuesÚdecoder_attention_maskr5  Údecoder_head_maskrp  Úencoder_outputsrª  r	  rt  rÏ  r6  r7  r7   c                 óš  — |�|n| j                   j                  }|�|n| j                   j                  }|
�|
n| j                   j                  }
|�|n| j                   j                  }|€| j                  ||||||¬«      }nI|rGt        |t        «      s7t        |d   t        |«      dkD  r|d   ndt        |«      dkD  r|d   nd¬«      }|�Qt        | j
                  t        «      r7| j
                  j                  j                  |d   j                  d   |«      }n|}t        | j                  t        «      rd|i}ni } | j                  d
|||d   ||||	|
|||dœ|¤Ž}|s||z   S t        |j                   |j"                  |j$                  |j&                  |j(                  |j                   |j$                  |j&                  ¬	«      S )au  
        input_values (`torch.Tensor` of shape `(batch_size, sequence_length)`):
            Depending on which encoder is being used, the `input_values` are either: float values of the input raw
            speech waveform, or indices of input sequence tokens in the vocabulary, or hidden states.

        decoder_input_values (`torch.Tensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Depending on which decoder is being used, the `decoder_input_values` are either: float values of log-mel
            filterbank features extracted from the raw speech waveform, or indices of decoder input sequence tokens in
            the vocabulary, or hidden states.

        speaker_embeddings (`torch.FloatTensor` of shape `(batch_size, config.speaker_embedding_dim)`, *optional*):
            Tensor containing the speaker embeddings.

        Returns:
        N)r,   r.   r5  rÏ  r6  r7  r   r   r    r@  rt  )r,   r.   r  r  r5  rp  rª  r	  rÏ  r6  r7  )rA  rª  r…  Údecoder_attentionsrs  Úencoder_last_hidden_stater  Úencoder_attentionsr+  )ry   rÏ  r6  r	  rC  r¿  rç  r   rQ   rQ  rS  r@  r$   rÀ  r  r   rA  rª  r   rB  rs  )rx   r,   r.   rÍ  rÎ  r5  rÏ  rp  rÐ  rª  r	  rt  rÏ  r6  r7  r  Údecoder_argsÚdecoder_outputss                     r)   r€   zSpeechT5Model.forward[  sú  € ðD 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð"Ø"Ÿl™lØ)Ø-Ø#Ø"3Ø%9Ø'ð +ó ‰Oñ ¤¨O¼_Ô!MÜ-Ø"1°!Ñ"4Ü47¸Ó4HÈ1Ò4L˜o¨aÒ0ÐRVÜ14°_Ó1EÈÒ1I˜?¨1Ò-ÈtôˆOð Ð%¬*°T·\±\ÔCbÔ*cØ%)§\¡\×%8Ñ%8×%[Ñ%[Ø Ñ"×(Ñ(¨Ñ+¨^ó&Ñ"ð &4Ð"ä�d—l‘lÔ$CÔDØ0Ð2DÐE‰LàˆLà&˜$Ÿ,™,ð 
Ø-Ø1Ø"1°!Ñ"4Ø#9Ø'Ø!5Ø+ØØ/Ø!5Ø#ñ
ð ñ
ˆñ Ø" _Ñ4Ð4ä!Ø-×?Ñ?Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô	
ð 		
r+   r]  ©NNNNNNNNNNNNNN)rƒ   r„   r…   r   r   r   ÚModulerl   r™  rž  rÆ  rÈ  r=  r   ÚSPEECHT5_INPUTS_DOCSTRINGr   r   Ú_CONFIG_FOR_DOCr´   rÓ   r^  r_  r   rN   r   r€   r†   r‡   s   @r)   r¾  r¾  -  sö  ø„ ð (,Ø'+ñ	àðð ˜"Ÿ)™)Ñ$ðð ˜"Ÿ)™)Ñ$õ	ò"ò5òòò9ñ +Ð+DÓEÙÐ+=ÈOÔ\ð 04Ø59Ø7;Ø=AØ15Ø9=Ø7;ØEIØEIØ$(Ø:>Ø,0Ø/3Ø&*ña
à˜uŸ|™|Ñ,ða
ð ! ×!1Ñ!1Ñ2ða
ð ' u§|¡|Ñ4ð	a
ð
 !)¨×)9Ñ)9Ñ :ða
ð ˜E×-Ñ-Ñ.ða
ð $ E×$5Ñ$5Ñ6ða
ð ' u§|¡|Ñ4ða
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBða
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBða
ð ˜D‘>ða
ð % U×%6Ñ%6Ñ7ða
ð $ D™>ða
ð ' t™nða
ð ˜d‘^ða
ð  
ˆu�U×&Ñ&Ñ'Ð);Ð;Ñ	<ò!a
ó ]ó Fôa
r+   r¾  z8SpeechT5 Model with a speech encoder and a text decoder.c            #       ó>  ‡ — e Zd ZdgZdefˆ fd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
 ee«       eee¬	«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
eej$                     deej&                     deej&                     deej&                     deej$                     deej$                     deej(                     deeeej$                           deeeej$                           dee   dee   dee   dee   deej&                     deeef   fd„«       «       Z	 	 	 	 	 	 	 dd„Zed„ «       Zˆ xZS )ÚSpeechT5ForSpeechToTextz#text_decoder_postnet.lm_head.weightry   c                 óþ   •— t         ‰| �  |«       |j                  €t        d| j                  › d�«      ‚t        |«      }t        |«      }t        |||«      | _        t        |«      | _
        | j                  «        y )NúYou are trying to instantiate a    with a configuration that does not define the vocabulary size of the language model head. Please instantiate the model as follows: `SpeechT5ForSpeechToText.from_pretrained(..., vocab_size=vocab_size)`. or define `vocab_size` of your model's configuration.)rk   rl   r”  r&   r{   rQ  r‡  r¾  r  r¯  Útext_decoder_postnetr3  )rx   ry   Úspeech_encoderÚtext_decoderr{   s       €r)   rl   z SpeechT5ForSpeechToText.__init__È  s   ø€ Ü‰Ñ˜Ô à×ÑÐ$ÜØ0°·±Ð0@ð A/ð /óð ô 9¸Ó@ˆÜ4°VÓ<ˆÜ% f¨n¸lÓKˆŒä$>¸vÓ$FˆÔ!ð 	�‰Õr+   c                 ó6   — | j                   j                  «       S r}   ©r  rÆ  r<  s    r)   rÆ  z#SpeechT5ForSpeechToText.get_encoderÜ  ó   € Ø�}‰}×(Ñ(Ó*Ð*r+   c                 ó6   — | j                   j                  «       S r}   ©r  rÈ  r<  s    r)   rÈ  z#SpeechT5ForSpeechToText.get_decoderß  rä  r+   c                 óT   — | j                  «       j                  j                  «        yrÊ  ©rÆ  rS  r=  r<  s    r)   r=  z.SpeechT5ForSpeechToText.freeze_feature_encoderâ  ó   € ð
 	×ÑÓ×!Ñ!×8Ñ8Õ:r+   c                 ó6   — | j                   j                  «       S r}   )rß  r¶  r<  s    r)   r¶  z-SpeechT5ForSpeechToText.get_output_embeddingsé  s   € Ø×(Ñ(×>Ñ>Ó@Ð@r+   c                 ó:   — | j                   j                  |«       y r}   )rß  r»  r¹  s     r)   r»  z-SpeechT5ForSpeechToText.set_output_embeddingsì  s   € Ø×!Ñ!×7Ñ7¸ÕGr+   rË  r,   r.   Údecoder_input_idsrÎ  r5  rÏ  rp  rÐ  rª  r	  rÏ  r6  r7  rµ  r7   c                 ó~  — |�|n| j                   j                  }|�7|€5t        || j                   j                  | j                   j                  «      }| j                  |||||||||	|
||d¬«      }| j                  |d   «      }d}|�Ft        «       } ||j                  d| j                   j                  «      |j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  |j                  |j                  |j                   |j"                  ¬«	      S )a‘  
        input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
            Float values of input raw speech waveform. Values 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_values`, the [`SpeechT5Processor`] should be used for padding
            and conversion into a tensor of type `torch.FloatTensor`. See [`SpeechT5Processor.__call__`] for details.

        decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary.

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

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

            SpeechT5 uses the `eos_token_id` as the starting token for `decoder_input_ids` generation. If
            `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
            `past_key_values`).

        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the language modeling loss. Indices should either be in `[0, ..., config.vocab_size]`
            or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored (masked), the loss is
            only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

            Label indices can be obtained using [`SpeechT5Tokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

        Returns:

        Example:

        ```python
        >>> from transformers import SpeechT5Processor, SpeechT5ForSpeechToText
        >>> from datasets import load_dataset

        >>> dataset = load_dataset(
        ...     "hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True
        ... )  # doctest: +IGNORE_RESULT
        >>> dataset = dataset.sort("id")
        >>> sampling_rate = dataset.features["audio"].sampling_rate

        >>> processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_asr")
        >>> model = SpeechT5ForSpeechToText.from_pretrained("microsoft/speecht5_asr")

        >>> # audio file is decoded on the fly
        >>> inputs = processor(audio=dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")
        >>> predicted_ids = model.generate(**inputs, max_length=100)

        >>> # transcribe speech
        >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
        >>> transcription[0]
        'mister quilter is the apostle of the middle classes and we are glad to welcome his gospel'
        ```

        ```python
        >>> inputs["labels"] = processor(text_target=dataset[0]["text"], return_tensors="pt").input_ids

        >>> # compute loss
        >>> loss = model(**inputs).loss
        >>> round(loss.item(), 2)
        19.68
        ```
        NT)r,   r.   rÍ  rÎ  r5  rÏ  rp  rÐ  rª  r	  rÏ  r6  r7  r   r"   r   )	rŸ  rŽ  rª  r…  rÒ  rs  rÓ  r  rÔ  )ry   rC  r*   r   r    r  rß  r	   r¼   r”  r   rª  r…  rÒ  rs  rÓ  r  rÔ  )rx   r,   r.   rì  rÎ  r5  rÏ  rp  rÐ  rª  r	  rÏ  r6  r7  rµ  rü  rŽ  rŸ  Úloss_fctÚoutputs                       r)   r€   zSpeechT5ForSpeechToText.forwardï  sZ  € ðd &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐØ Ð(Ü$6Ø˜DŸK™K×4Ñ4°d·k±k×6XÑ6Xó%Ð!ð —-‘-Ø%Ø)Ø!2Ø#9ØØ/Ø!5Ø+Ø+ØØ/Ø!5Øð  ó 
ˆð  ×*Ñ*¨7°1©:Ó6ˆàˆØÐÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯K©K×,BÑ,BÓCÀVÇ[Á[ÐQSÃ_ÓUˆDáØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEäØØØ#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r+   c	           	      óª   — |�G|d   d   j                   d   }
|j                   d   |
kD  r|
}n|j                   d   dz
  }|d d …|d …f   }||||||||dœS )Nr   r    r   )rÐ  rª  rì  r.   r5  rÏ  rp  r	  )r$   )rx   rì  rª  r.   r5  rÏ  rp  r	  rÐ  ÚkwargsÚpast_lengthÚremove_prefix_lengths               r)   Úprepare_inputs_for_generationz5SpeechT5ForSpeechToText.prepare_inputs_for_generationp	  s�   € ð Ð&Ø)¨!Ñ,¨QÑ/×5Ñ5°aÑ8ˆKð !×&Ñ& qÑ)¨KÒ7Ø'2Ñ$ð (9×'>Ñ'>¸qÑ'AÀAÑ'EÐ$à 1²!Ð5IÑ5JÐ2JÑ KÐð  /Ø.Ø!2Ø,Ø"Ø!2Ø$8Ø"ñ	
ð 		
r+   c                 óJ   ‡— d}| D ]  }|t        ˆfd„|D «       «      fz  }Œ |S )Nr+  c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­w)r   N)rÄ   rª   r§   )r=  Ú
past_stateÚbeam_idxs     €r)   r?  z9SpeechT5ForSpeechToText._reorder_cache.<locals>.<genexpr>›	  s.   øè ø€ ÒnÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑnùs   ƒ58)rE  )rª  rø  Úreordered_pastÚ
layer_pasts    `  r)   Ú_reorder_cachez&SpeechT5ForSpeechToText._reorder_cache–	  s=   ø€ àˆØ)ò 	ˆJØÜÓnÐcmÔnÓnðñ ‰Nð	ð Ðr+   r×  )NNNNNNN)rƒ   r„   r…   Ú_tied_weights_keysr   rl   rÆ  rÈ  r=  r¶  r»  r   rÙ  r   r   rÚ  r   r´   r_  r^  rÓ   r   rN   r   r€   rô  rÑ   rû  r†   r‡   s   @r)   rÜ  rÜ  Á  sþ  ø„ ð
 @Ð@Ðð˜~õ ò(+ò+ò;òAòHñ +Ð+DÓEÙ¨?ÈÔYð 59Ø59Ø8<Ø=AØ15Ø9=Ø7;ØEIØEIØ$(Ø,0Ø/3Ø&*Ø-1ñ}
à˜u×0Ñ0Ñ1ð}
ð ! ×!1Ñ!1Ñ2ð}
ð $ E×$4Ñ$4Ñ5ð	}
ð
 !)¨×)9Ñ)9Ñ :ð}
ð ˜E×-Ñ-Ñ.ð}
ð $ E×$5Ñ$5Ñ6ð}
ð ' u§|¡|Ñ4ð}
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBð}
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBð}
ð ˜D‘>ð}
ð $ D™>ð}
ð ' t™nð}
ð ˜d‘^ð}
ð ˜×)Ñ)Ñ*ð}
ð  
ˆu�oÐ%Ñ	&ò!}
ó Zó Fð}
ðD ØØØØ!ØØó$
ðL ñó ôr+   rÜ  Úmodelrt  Ú	thresholdÚminlenratioÚmaxlenratioÚvocoderÚoutput_cross_attentionsÚreturn_output_lengthsc
           
      ój  — |€t        d«      ‚|€+d|| j                  j                  k(  j                  «       z
  }
n|}
|j	                  d«      }| j
                  j                  ||
d¬«      }|j                  }t        | j
                  j                  t        «      r@| j
                  j                  j                  j                  |d   j                  d   |
«      }
t        |j	                  d«      |z  | j                  j                  z  «      }t        |j	                  d«      |z  | j                  j                  z  «      }|j                  |d| j                  j                  «      }g }g }d }d}i }	 |dz  }| j
                  j                   j                  ||«      }| j
                  j                   j#                  |d d …dd …f   d ||
|d|d¬«      }|r0|j%                  t'        j(                  |j*                  d¬«      «       |j                  j-                  d«      }|j.                  }| j0                  j3                  |«      }|j5                  || j                  j                  | j                  j                  «      }|j%                  |«       |d d …dd d …f   j5                  |d| j                  j                  «      }t'        j(                  ||fd¬«      }t'        j6                  | j0                  j9                  |«      «      }||k  r�Œ¡||k  rAt'        j:                  |d¬«      |k\  }t'        j<                  |«      d   j?                  «       }ntA        tC        |«      «      }|D �cg c]	  }||vsŒ|‘Œ }}tC        |«      dkD  rat'        jD                  |«      }|jG                  dd«      jI                  dd	«      }| j0                  jK                  |«      }|D ]
  } ||    || <   Œ tC        |«      |k\  rn�ŒŽtA        tC        |«      «      D �cg c]  }||   ‘Œ	 }}|	s°|dk(  r|d   n4t&        jL                  jN                  jP                  jS                  |d¬
«      }|�	 ||«      }!n|}!|r`t'        j(                  |d	¬«      }|dkD  r@ |j4                  |t        |j	                  d«      |z  «      g|j	                  «       dd  ¢­Ž }|!|f}!|!S g }"tA        |«      D ]%  }|"j%                  ||   j	                  d«      «       Œ' |€:t&        jL                  jN                  jP                  jS                  |d¬
«      }||"f}!nyg }#t&        jL                  jN                  jP                  jS                  |d¬
«      } ||«      }#|"D �cg c]+  }t        |#j	                  d«      tU        |"«      z  «      |z  ‘Œ- }$}|#|$f}!|r^t'        j(                  |d	¬«      } |j4                  |t        |j	                  d«      |z  «      g|j	                  «       dd  ¢­Ž }g |!¢|‘­}!|!S c c}w c c}w c c}w )Na  `speaker_embeddings` must be specified. For example, you can use a speaker embeddings by following
                    the code snippet provided in this link:
                    https://huggingface.co/datasets/Matthijs/cmu-arctic-xvectors
                    r   r   T)r,   r.   r7  r"   )r   r.   r  r  rª  r	  rÏ  r7  r°   r    )Úbatch_firstéýÿÿÿ)+r&   ry   r   r;   rÂ   r  r¿  rA  rç  rQ  rS  r@  r$   r-   r#   rd  rÀ  r�  rU   r´   r¹   rs  Úsqueezerª  Úspeech_decoder_postnetrˆ  r¼   Úsigmoidr‰  rJ   rp  rK   rL   rQ   Ústackr�   Úflattenr‹  r   rá   ÚrnnÚpad_sequencer<   )%rý  r,   rt  r.   rþ  rÿ  r   r  r  r  r  rÅ   Úencoder_outrÓ  ÚmaxlenÚminlenÚoutput_sequenceÚspectrogramrs  rª  rI  Úresult_spectrogramr…  Údecoder_outÚlast_decoder_outputÚspectrumÚnew_spectrogramÚprobÚmeet_thresholdsÚmeet_indexesr  ÚspectrogramsÚ
meet_indexrü  Úspectrogram_lengthsÚ	waveformsÚwaveform_lengthss%                                        r)   Ú_generate_speechr    	  s  € ð Ð!Üðó
ð 	
ð ÐØ!" l°e·l±l×6OÑ6OÑ&O×%TÑ%TÓ%VÑ!VÑà!/Ðà
×
Ñ
˜AÓ
€Cà—.‘.×(Ñ(Ø!Ø-Øð )ó €Kð !,× =Ñ =Ðô �%—.‘.×(Ñ(Ô*IÔJØ!&§¡×!7Ñ!7×!>Ñ!>×!aÑ!aØ˜‰N× Ñ  Ñ#Ð%;ó"
Ðô Ð*×/Ñ/°Ó2°[Ñ@À5Ç<Á<×C`ÑC`Ñ`Óa€FÜÐ*×/Ñ/°Ó2°[Ñ@À5Ç<Á<×C`ÑC`Ñ`Óa€Fð 0×9Ñ9¸#¸qÀ%Ç,Á,×B[ÑB[Ó\€Oà€KØÐØ€OØ
€CØÐà
Øˆq‰ˆð !&§¡× 6Ñ 6× =Ñ =¸oÐOaÓ bÐà—n‘n×,Ñ,×<Ñ<Ø/²°2±3°Ñ7ØØ";Ø#9Ø+ØØ5Øð =ó 	
ˆñ #Ø×#Ñ#¤E§I¡I¨k×.JÑ.JÐPQÔ$RÔSà)×;Ñ;×CÑCÀAÓFÐØ%×5Ñ5ˆð ×/Ñ/×8Ñ8Ð9LÓMˆØ—=‘=  e§l¡l×&CÑ&CÀUÇ\Á\×E^ÑE^Ó_ˆØ×Ñ˜8Ô$ð #¢1 bª! 8Ñ,×1Ñ1°#°q¸%¿,¹,×:SÑ:SÓTˆÜŸ)™) _°oÐ$FÈAÔNˆä�}‰}˜U×9Ñ9×BÑBÐCVÓWÓXˆà�Š<Ùð �VŠ|Ü"'§)¡)¨D°bÔ"9¸YÑ"F�Ü$Ÿ{™{¨?Ó;¸AÑ>×EÑEÓG‘ä$¤S¨£YÓ/�Ø'3ÖS !°qÐ@RÒ7RšAÐSˆLÐSÜ�<Ó  1Ò$Ü$Ÿ{™{¨;Ó7�Ø+×5Ñ5°a¸Ó;×CÑCÀAÀqÓI�Ø$×;Ñ;×CÑCÀLÓQ�Ø".ò N�JØ5AÀ*Ñ5MÐ& zÒ2ðNäÐ%Ó&¨#Ò-Øñi ôj 49¼Ð=OÓ9PÓ3QÖR¨aÐ& qÓ)ÐR€LÐRÙ Ø),°ª�l 1’o´u·x±x·~±~×7IÑ7I×7VÑ7VÐWcÐquÐ7VÓ7vˆØÐÙ˜kÓ*‰Gà!ˆGÙ"Ü$Ÿy™yÐ)9¸qÔAÐØ�QŠwØ#8Ð#3×#8Ñ#8ØœÐ-×2Ñ2°1Ó5¸Ñ;Ó<ð$Ø?O×?TÑ?TÓ?VÐWYÐWZÐ?[ò$Ð ð Ð 0Ð1ˆGð* €Nð% !ÐÜ�s“ò 	@ˆAØ×&Ñ& |°A¡×';Ñ';¸AÓ'>Õ?ð	@àˆ?Ü Ÿ8™8Ÿ>™>×-Ñ-×:Ñ:¸<ÐUYÐ:ÓZˆLØ#Ð%8Ð9‰GàˆIÜ Ÿ8™8Ÿ>™>×-Ñ-×:Ñ:¸<ÐUYÐ:ÓZˆLÙ Ó-ˆIØ_rÖsÐZ[¤ I§N¡N°1Ó$5¼Ð<OÓ8PÑ$PÓ QÐTUÓ UÐsÐÐsØ Ð"2Ð3ˆGÙ"Ü$Ÿy™yÐ)9¸qÔAÐØ4Ð/×4Ñ4Ø”SÐ)×.Ñ.¨qÓ1°CÑ7Ó8ð Ø;K×;PÑ;PÓ;RÐSUÐSVÐ;Wò Ðð 3˜Ð2Ð!1Ñ2ˆGØ€NùòW Tùò Sùò4  ts   Í4	X&Í>X&ÐX+Ö0X0z8SpeechT5 Model with a text encoder and a speech decoder.c            '       ó’  ‡ — e Zd ZdZdefˆ fd„Zedefd„«       Zd„ Z	d„ Z
 ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!deej$                     d	eej$                     d
eej&                     deej$                     deej&                     deej&                     deej(                     deeeej&                           deeeej&                           dee   dee   dee   dee   deej&                     deej&                     deej(                     deeef   f"d„«       «       Z ej0                  «       	 	 	 	 	 	 	 	 d"dej$                  d	eej$                     deej&                     dedededeej6                     dededeej&                  eej&                  ej&                  f   f   fd„«       Z ej0                  «       	 	 	 	 	 	 	 	 d"dej$                  deej&                     d	eej$                     dedededeej6                     dededeej&                  eej&                  ej&                  f   f   fd „«       Zˆ xZS )#ÚSpeechT5ForTextToSpeechr   ry   c                 óþ   •— t         ‰| �  |«       |j                  €t        d| j                  › d�«      ‚t        |«      }t        |«      }t        |||«      | _        t        |«      | _
        | j                  «        y )NrÞ  a    with a configuration that does not define the vocabulary size of the language model head. Please instantiate the model as follows: `SpeechT5ForTextToSpeech.from_pretrained(..., vocab_size=vocab_size)`. or define `vocab_size` of your model's configuration.)rk   rl   r”  r&   r{   r[  r  r¾  r  r†  r  r3  )rx   ry   Útext_encoderÚspeech_decoderr{   s       €r)   rl   z SpeechT5ForTextToSpeech.__init__6
  s   ø€ Ü‰Ñ˜Ô à×ÑÐ$ÜØ0°·±Ð0@ð A/ð /óð ô 5°VÓ<ˆÜ8¸Ó@ˆÜ% f¨l¸NÓKˆŒä&BÀ6Ó&JˆÔ#ð 	�‰Õr+   r7   c                  ó   — yr  r+  )Úclss    r)   Úcan_generatez$SpeechT5ForTextToSpeech.can_generateJ
  s   € ð
 r+   c                 ó6   — | j                   j                  «       S r}   rã  r<  s    r)   rÆ  z#SpeechT5ForTextToSpeech.get_encoderQ
  rä  r+   c                 ó6   — | j                   j                  «       S r}   ræ  r<  s    r)   rÈ  z#SpeechT5ForTextToSpeech.get_decoderT
  rä  r+   rË  r.   rÍ  rÎ  r5  rÏ  rp  rÐ  rª  r	  rÏ  r6  r7  rt  rµ  r¸  c                 ób  — |�|n| j                   j                  }|�>|€$t        || j                   j                  |«      \  }}| j                   j                  rd}| j                  |||||||||	|
|||d¬«      }| j                  |d   «      \  }}}d}|�,t        | j                   «      } |||||||j                  «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  |j                  |j                  |j                  |j                  ¬«	      S )aš  
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

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

            [What are input IDs?](../glossary#input-ids)
        decoder_input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.num_mel_bins)`):
            Float values of input mel spectrogram.

            SpeechT5 uses an all-zero spectrum as the starting token for `decoder_input_values` generation. If
            `past_key_values` is used, optionally only the last `decoder_input_values` have to be input (see
            `past_key_values`).
        speaker_embeddings (`torch.FloatTensor` of shape `(batch_size, config.speaker_embedding_dim)`, *optional*):
            Tensor containing the speaker embeddings.
        labels (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.num_mel_bins)`, *optional*):
            Float values of target mel spectrogram. Timesteps set to `-100.0` are ignored (masked) for the loss
            computation. Spectrograms can be obtained using [`SpeechT5Processor`]. See [`SpeechT5Processor.__call__`]
            for details.

        Returns:

        Example:

        ```python
        >>> from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, set_seed
        >>> import torch

        >>> processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
        >>> model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
        >>> vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")

        >>> inputs = processor(text="Hello, my dog is cute", return_tensors="pt")
        >>> speaker_embeddings = torch.zeros((1, 512))  # or load xvectors from a file

        >>> set_seed(555)  # make deterministic

        >>> # generate speech
        >>> speech = model.generate(inputs["input_ids"], speaker_embeddings=speaker_embeddings, vocoder=vocoder)
        >>> speech.shape
        torch.Size([15872])
        ```
        NT©r,   r.   rÍ  rÎ  r5  rÏ  rp  rÐ  rª  r	  rt  rÏ  r6  r7  r   r   ©	rŸ  r  rª  r…  rÒ  rs  rÓ  r  rÔ  )ry   rC  r3   r-   r°  r  r  r­  rs  r   rª  r…  rÒ  rÓ  r  rÔ  )rx   r   r.   rÍ  rÎ  r5  rÏ  rp  rÐ  rª  r	  rÏ  r6  r7  rt  rµ  r¸  rü  rŒ  r�  rŽ  rŸ  Ú	criterionrï  s                           r)   r€   zSpeechT5ForTextToSpeech.forwardW
  s}  € ðB &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐØ#Ð+Ü?WØ˜DŸK™K×8Ñ8Ð:Pó@Ñ<Ð$Ð&<ð �{‰{×4Ò4Ø$(Ð!à—-‘-Ø"Ø)Ø!5Ø#9ØØ/Ø!5Ø+Ø+ØØ1Ø/Ø!5Øð  ó 
ˆð" AE×@[Ñ@[Ð\cÐdeÑ\fÓ@gÑ=ÐÐ 5°vàˆØÐÜ/°·±Ó<ˆIÙØØ&Ø%ØØØ×(Ñ(óˆDñ Ø+Ð-°¸¸°Ñ;ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä'ØØ-Ø#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r+   rþ  rÿ  r   r  r  r  c
                 óÜ   — |�W|j                  d«      }|j                  d«      |k7  r2|j                  d«      dk(  r|j                  |d«      }nt        d«      ‚t        | |||||||||	«
      S )aE  
        Converts a sequence of input tokens into a sequence of mel spectrograms, which are subsequently turned into a
        speech waveform using a vocoder.

        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary.

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

                [What are input IDs?](../glossary#input-ids)
            attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Attention mask from the tokenizer, required for batched inference to signal to the model where to
                ignore padded tokens from the input_ids.
            speaker_embeddings (`torch.FloatTensor` of shape `(batch_size, config.speaker_embedding_dim)`, *optional*):
                Tensor containing the speaker embeddings.
            threshold (`float`, *optional*, defaults to 0.5):
                The generated sequence ends when the predicted stop token probability exceeds this value.
            minlenratio (`float`, *optional*, defaults to 0.0):
                Used to calculate the minimum required length for the output sequence.
            maxlenratio (`float`, *optional*, defaults to 20.0):
                Used to calculate the maximum allowed length for the output sequence.
            vocoder (`nn.Module`, *optional*):
                The vocoder that converts the mel spectrogram into a speech waveform. If `None`, the output is the mel
                spectrogram.
            output_cross_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of the decoder's cross-attention layers.
            return_output_lengths (`bool`, *optional*, defaults to `False`):
                Whether or not to return the concrete spectrogram/waveform lengths.

        Returns:
            `tuple(torch.FloatTensor)` comprising various elements depending on the inputs:
            - when `return_output_lengths` is False
                - **spectrogram** (*optional*, returned when no `vocoder` is provided) `torch.FloatTensor` of shape
                `(output_sequence_length, config.num_mel_bins)` -- The predicted log-mel spectrogram.
                - **waveform** (*optional*, returned when a `vocoder` is provided) `torch.FloatTensor` of shape
                `(num_frames,)` -- The predicted speech waveform.
                - **cross_attentions** (*optional*, returned when `output_cross_attentions` is `True`)
                `torch.FloatTensor` of shape `(config.decoder_layers, config.decoder_attention_heads,
                output_sequence_length, input_sequence_length)` -- The outputs of the decoder's cross-attention layers.
            - when `return_output_lengths` is True
                - **spectrograms** (*optional*, returned when no `vocoder` is provided) `torch.FloatTensor` of shape
                `(batch_size, output_sequence_length, config.num_mel_bins)` -- The predicted log-mel spectrograms that
                are padded to the maximum length.
                - **spectrogram_lengths** (*optional*, returned when no `vocoder` is provided) `List[Int]` -- A list of
                all the concrete lengths for each spectrogram.
                - **waveforms** (*optional*, returned when a `vocoder` is provided) `torch.FloatTensor` of shape
                `(batch_size, num_frames)` -- The predicted speech waveforms that are padded to the maximum length.
                - **waveform_lengths** (*optional*, returned when a `vocoder` is provided) `List[Int]` -- A list of all
                the concrete lengths for each waveform.
                - **cross_attentions** (*optional*, returned when `output_cross_attentions` is `True`)
                `torch.FloatTensor` of shape `(batch_size, config.decoder_layers, config.decoder_attention_heads,
                output_sequence_length, input_sequence_length)` -- The outputs of the decoder's cross-attention layers.
        r   r   zUThe first dimension of speaker_embeddings must be either 1 or the same as batch_size.©rÂ   ro  r&   r   )rx   r   r.   rt  rþ  rÿ  r   r  r  r  rñ  rZ   s               r)   Úgeneratez SpeechT5ForTextToSpeech.generateÑ
  s�   € ðJ Ð)Ø"Ÿ™¨Ó*ˆJØ!×&Ñ& qÓ)¨ZÒ7Ø%×*Ñ*¨1Ó-°Ò2Ø);×)BÑ)BÀ:ÈqÓ)QÑ&ä$Øoóð ô  ØØØØØØØØØ#Ø!ó
ð 	
r+   c
                 óÜ   — |�W|j                  d«      }
|j                  d«      |
k7  r2|j                  d«      dk(  r|j                  |
d«      }nt        d«      ‚t        | |||||||||	«
      S )aÿ  
        Converts a sequence of input tokens into a sequence of mel spectrograms, which are subsequently turned into a
        speech waveform using a vocoder.

        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary.

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

                [What are input IDs?](../glossary#input-ids)
            speaker_embeddings (`torch.FloatTensor` of shape `(batch_size, config.speaker_embedding_dim)`, *optional*):
                Tensor containing the speaker embeddings.
            attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing convolution and attention on padding token indices. Mask values selected in
                `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            threshold (`float`, *optional*, defaults to 0.5):
                The generated sequence ends when the predicted stop token probability exceeds this value.
            minlenratio (`float`, *optional*, defaults to 0.0):
                Used to calculate the minimum required length for the output sequence.
            maxlenratio (`float`, *optional*, defaults to 20.0):
                Used to calculate the maximum allowed length for the output sequence.
            vocoder (`nn.Module`, *optional*, defaults to `None`):
                The vocoder that converts the mel spectrogram into a speech waveform. If `None`, the output is the mel
                spectrogram.
            output_cross_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of the decoder's cross-attention layers.
            return_output_lengths (`bool`, *optional*, defaults to `False`):
                Whether or not to return the concrete spectrogram/waveform lengths.

        Returns:
            `tuple(torch.FloatTensor)` comprising various elements depending on the inputs:
            - when `return_output_lengths` is False
                - **spectrogram** (*optional*, returned when no `vocoder` is provided) `torch.FloatTensor` of shape
                `(output_sequence_length, config.num_mel_bins)` -- The predicted log-mel spectrogram.
                - **waveform** (*optional*, returned when a `vocoder` is provided) `torch.FloatTensor` of shape
                `(num_frames,)` -- The predicted speech waveform.
                - **cross_attentions** (*optional*, returned when `output_cross_attentions` is `True`)
                `torch.FloatTensor` of shape `(config.decoder_layers, config.decoder_attention_heads,
                output_sequence_length, input_sequence_length)` -- The outputs of the decoder's cross-attention layers.
            - when `return_output_lengths` is True
                - **spectrograms** (*optional*, returned when no `vocoder` is provided) `torch.FloatTensor` of shape
                `(batch_size, output_sequence_length, config.num_mel_bins)` -- The predicted log-mel spectrograms that
                are padded to the maximum length.
                - **spectrogram_lengths** (*optional*, returned when no `vocoder` is provided) `List[Int]` -- A list of
                all the concrete lengths for each spectrogram.
                - **waveforms** (*optional*, returned when a `vocoder` is provided) `torch.FloatTensor` of shape
                `(batch_size, num_frames)` -- The predicted speech waveforms that are padded to the maximum length.
                - **waveform_lengths** (*optional*, returned when a `vocoder` is provided) `List[Int]` -- A list of all
                the concrete lengths for each waveform.
                - **cross_attentions** (*optional*, returned when `output_cross_attentions` is `True`)
                `torch.FloatTensor` of shape `(batch_size, config.decoder_layers, config.decoder_attention_heads,
                output_sequence_length, input_sequence_length)` -- The outputs of the decoder's cross-attention layers.
        r   r   zUThe first dimension of speaker_embeddings must be either 1 or the same as batch size.r0  )rx   r   rt  r.   rþ  rÿ  r   r  r  r  rZ   s              r)   Úgenerate_speechz'SpeechT5ForTextToSpeech.generate_speech-  s�   € ðR Ð)Ø"Ÿ™¨Ó*ˆJØ!×&Ñ& qÓ)¨ZÒ7Ø%×*Ñ*¨1Ó-°Ò2Ø);×)BÑ)BÀ:ÈqÓ)QÑ&ä$Øoóð ô  ØØØØØØØØØ#Ø!ó
ð 	
r+   ©NNNNNNNNNNNNNNNN©NNg      à?r1   g      4@NFF)rƒ   r„   r…   r)  r   rl   ÚclassmethodrN   r(  rÆ  rÈ  r   rÙ  r   r   rÚ  r   r´   r^  r_  rÓ   r   r   r€   rÒ   r·   r   rØ  r1  r3  r†   r‡   s   @r)   r"  r"  /
  sä  ø„ ð
 "€Oð˜~õ ð( ð˜Tò ó ðò+ò+ñ +Ð+DÓEÙÐ+CÐRaÔbð 15Ø59Ø<@Ø=AØ15Ø9=Ø7;ØEIØEIØ$(Ø,0Ø/3Ø&*Ø:>Ø.2Ø.2ñ#v
à˜E×,Ñ,Ñ-ðv
ð ! ×!1Ñ!1Ñ2ðv
ð ' u×'8Ñ'8Ñ9ð	v
ð
 !)¨×)9Ñ)9Ñ :ðv
ð ˜E×-Ñ-Ñ.ðv
ð $ E×$5Ñ$5Ñ6ðv
ð ' u§|¡|Ñ4ðv
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðv
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðv
ð ˜D‘>ðv
ð $ D™>ðv
ð ' t™nðv
ð ˜d‘^ðv
ð % U×%6Ñ%6Ñ7ðv
ð  ˜×*Ñ*Ñ+ð!v
ð" ˜eŸl™lÑ+ð#v
ð$ 
ˆuÐ.Ð.Ñ	/ò%v
ó có Fðv
ðp €U‡]�]ƒ_ð 6:Ø:>ØØ Ø!Ø'+Ø(-Ø&+ñY
à×#Ñ#ðY
ð ! ×!1Ñ!1Ñ2ðY
ð % U×%6Ñ%6Ñ7ð	Y
ð
 ðY
ð ðY
ð ðY
ð ˜"Ÿ)™)Ñ$ðY
ð "&ðY
ð  $ðY
ð 
ˆu× Ñ  %¨×(9Ñ(9¸5×;LÑ;LÐ(LÑ"MÐMÑ	NòY
ó ðY
ðv €U‡]�]ƒ_ð ;?Ø59ØØ Ø!Ø'+Ø(-Ø&+ñ]
à×#Ñ#ð]
ð % U×%6Ñ%6Ñ7ð]
ð ! ×!1Ñ!1Ñ2ð	]
ð
 ð]
ð ð]
ð ð]
ð ˜"Ÿ)™)Ñ$ð]
ð "&ð]
ð  $ð]
ð 
ˆu× Ñ  %¨×(9Ñ(9¸5×;LÑ;LÐ(LÑ"MÐMÑ	Nò]
ó ô]
r+   r"  z:SpeechT5 Model with a speech encoder and a speech decoder.c            '       ó&  ‡ — e Zd Zdefˆ fd„Zd„ Zd„ Zd„ Z ee	«       e
ee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d deej                     deej                      d	eej                     d
eej                      deej                     deej                     deej"                     deeeej                           deeeej                           dee   dee   dee   dee   deej                     deej                     deej"                     deeef   f"d„«       «       Z ej,                  «       	 	 	 	 	 	 	 	 d!dej                  deej                     deej                      dedededeej2                     dededej                  fd„«       Zˆ xZS )"ÚSpeechT5ForSpeechToSpeechry   c                 ó´   •— t         ‰| �  |«       t        |«      }t        |«      }t	        |||«      | _        t        |«      | _        | j                  «        y r}   )	rk   rl   rQ  r  r¾  r  r†  r  r3  )rx   ry   rà  r%  r{   s       €r)   rl   z"SpeechT5ForSpeechToSpeech.__init__“  sM   ø€ Ü‰Ñ˜Ô ä8¸Ó@ˆÜ8¸Ó@ˆÜ% f¨n¸nÓMˆŒä&BÀ6Ó&JˆÔ#ð 	�‰Õr+   c                 ó6   — | j                   j                  «       S r}   rã  r<  s    r)   rÆ  z%SpeechT5ForSpeechToSpeech.get_encoderŸ  rä  r+   c                 ó6   — | j                   j                  «       S r}   ræ  r<  s    r)   rÈ  z%SpeechT5ForSpeechToSpeech.get_decoder¢  rä  r+   c                 óT   — | j                  «       j                  j                  «        yrÊ  rè  r<  s    r)   r=  z0SpeechT5ForSpeechToSpeech.freeze_feature_encoder¥  ré  r+   rË  r,   r.   rÍ  rÎ  r5  rÏ  rp  rÐ  rª  r	  rÏ  r6  r7  rt  rµ  r¸  r7   c                 óÖ  — |�|n| j                   j                  }|�&|€$t        || j                   j                  |«      \  }}| j	                  |||||||||	|
|||d¬«      }| j                  |d   «      \  }}}d}|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  |j                  |j                  |j                  |j                  ¬«	      S )aª
  
        input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
            Float values of input raw speech waveform. Values 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_values`, the [`SpeechT5Processor`] should be used for padding
            and conversion into a tensor of type `torch.FloatTensor`. See [`SpeechT5Processor.__call__`] for details.
        decoder_input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.num_mel_bins)`):
            Float values of input mel spectrogram.

            SpeechT5 uses an all-zero spectrum as the starting token for `decoder_input_values` generation. If
            `past_key_values` is used, optionally only the last `decoder_input_values` have to be input (see
            `past_key_values`).
        speaker_embeddings (`torch.FloatTensor` of shape `(batch_size, config.speaker_embedding_dim)`, *optional*):
            Tensor containing the speaker embeddings.
        labels (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.num_mel_bins)`, *optional*):
            Float values of target mel spectrogram. Spectrograms can be obtained using [`SpeechT5Processor`]. See
            [`SpeechT5Processor.__call__`] for details.

        Returns:

        Example:

        ```python
        >>> from transformers import SpeechT5Processor, SpeechT5ForSpeechToSpeech, SpeechT5HifiGan, set_seed
        >>> from datasets import load_dataset
        >>> import torch

        >>> dataset = load_dataset(
        ...     "hf-internal-testing/librispeech_asr_demo", "clean", split="validation", trust_remote_code=True
        ... )  # doctest: +IGNORE_RESULT
        >>> dataset = dataset.sort("id")
        >>> sampling_rate = dataset.features["audio"].sampling_rate

        >>> processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_vc")
        >>> model = SpeechT5ForSpeechToSpeech.from_pretrained("microsoft/speecht5_vc")
        >>> vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")

        >>> # audio file is decoded on the fly
        >>> inputs = processor(audio=dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")

        >>> speaker_embeddings = torch.zeros((1, 512))  # or load xvectors from a file

        >>> set_seed(555)  # make deterministic

        >>> # generate speech
        >>> speech = model.generate_speech(inputs["input_values"], speaker_embeddings, vocoder=vocoder)
        >>> speech.shape
        torch.Size([77824])
        ```
        NTr,  r   r   r-  )ry   rC  r3   r-   r  r  r   rª  r…  rÒ  rs  rÓ  r  rÔ  )rx   r,   r.   rÍ  rÎ  r5  rÏ  rp  rÐ  rª  r	  rÏ  r6  r7  rt  rµ  r¸  rü  r[   r  rŽ  rŸ  rï  s                          r)   r€   z!SpeechT5ForSpeechToSpeech.forward¬  s*  € ðN &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐØ#Ð+Ü?WØ˜DŸK™K×8Ñ8Ð:Pó@Ñ<Ð$Ð&<ð —-‘-Ø%Ø)Ø!5Ø#9ØØ/Ø!5Ø+Ø+ØØ1Ø/Ø!5Øð  ó 
ˆð" "&×!<Ñ!<¸WÀQ¹ZÓ!HÑˆˆ;˜àˆáØ!�^ g¨a¨b kÑ1ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä'ØØ#Ø#×3Ñ3Ø")×"?Ñ"?Ø&×9Ñ9Ø$×5Ñ5Ø&-×&GÑ&GØ")×"?Ñ"?Ø&×9Ñ9ô

ð 
	
r+   rþ  rÿ  r   r  r  r  c
                 óp   — |€!t        j                  d|j                  ¬«      }t        | |||||||||	«
      S )aÐ  
        Converts a raw speech waveform into a sequence of mel spectrograms, which are subsequently turned back into a
        speech waveform using a vocoder.

        Args:
            input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
                Float values of input raw speech waveform.

                Values 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_values`, the [`SpeechT5Processor`] should be used for padding and conversion into a tensor
                of type `torch.FloatTensor`. See [`SpeechT5Processor.__call__`] for details.
            speaker_embeddings (`torch.FloatTensor` of shape `(batch_size, config.speaker_embedding_dim)`, *optional*):
                Tensor containing the speaker embeddings.
            attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing convolution and attention on padding token indices. Mask values selected in
                `[0, 1]`:

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

                [What are attention masks?](../glossary#attention-mask)
            threshold (`float`, *optional*, defaults to 0.5):
                The generated sequence ends when the predicted stop token probability exceeds this value.
            minlenratio (`float`, *optional*, defaults to 0.0):
                Used to calculate the minimum required length for the output sequence.
            maxlenratio (`float`, *optional*, defaults to 20.0):
                Used to calculate the maximum allowed length for the output sequence.
            vocoder (`nn.Module`, *optional*, defaults to `None`):
                The vocoder that converts the mel spectrogram into a speech waveform. If `None`, the output is the mel
                spectrogram.
            output_cross_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of the decoder's cross-attention layers.
            return_output_lengths (`bool`, *optional*, defaults to `False`):
                Whether or not to return the concrete spectrogram/waveform lengths.

        Returns:
            `tuple(torch.FloatTensor)` comprising various elements depending on the inputs:
            - when `return_output_lengths` is False
                - **spectrogram** (*optional*, returned when no `vocoder` is provided) `torch.FloatTensor` of shape
                `(output_sequence_length, config.num_mel_bins)` -- The predicted log-mel spectrogram.
                - **waveform** (*optional*, returned when a `vocoder` is provided) `torch.FloatTensor` of shape
                `(num_frames,)` -- The predicted speech waveform.
                - **cross_attentions** (*optional*, returned when `output_cross_attentions` is `True`)
                `torch.FloatTensor` of shape `(config.decoder_layers, config.decoder_attention_heads,
                output_sequence_length, input_sequence_length)` -- The outputs of the decoder's cross-attention layers.
            - when `return_output_lengths` is True
                - **spectrograms** (*optional*, returned when no `vocoder` is provided) `torch.FloatTensor` of shape
                `(batch_size, output_sequence_length, config.num_mel_bins)` -- The predicted log-mel spectrograms that
                are padded to the maximum length.
                - **spectrogram_lengths** (*optional*, returned when no `vocoder` is provided) `List[Int]` -- A list of
                all the concrete lengths for each spectrogram.
                - **waveforms** (*optional*, returned when a `vocoder` is provided) `torch.FloatTensor` of shape
                `(batch_size, num_frames)` -- The predicted speech waveforms that are padded to the maximum length.
                - **waveform_lengths** (*optional*, returned when a `vocoder` is provided) `List[Int]` -- A list of all
                the concrete lengths for each waveform.
                - **cross_attentions** (*optional*, returned when `output_cross_attentions` is `True`)
                `torch.FloatTensor` of shape `(batch_size, config.decoder_layers, config.decoder_attention_heads,
                output_sequence_length, input_sequence_length)` -- The outputs of the decoder's cross-attention layers.
        )r   i   rH  )r´   rM   r§   r   )
rx   r,   rt  r.   rþ  rÿ  r   r  r  r  s
             r)   r3  z)SpeechT5ForSpeechToSpeech.generate_speech   sM   € ðR Ð%Ü!&§¡¨X¸l×>QÑ>QÔ!RÐäØØØØØØØØØ#Ø!ó
ð 	
r+   r4  r5  )rƒ   r„   r…   r   rl   rÆ  rÈ  r=  r   rÙ  r   r   rÚ  r   r´   r_  r^  rÓ   r   rN   r   r€   rÒ   r·   r   rØ  r3  r†   r‡   s   @r)   r8  r8  Ž  s·  ø„ ð

˜~õ 
ò+ò+ò;ñ +Ð+DÓEÙÐ+CÐRaÔbð 59Ø59Ø<@Ø=AØ15Ø9=Ø7;ØEIØEIØ$(Ø,0Ø/3Ø&*Ø:>Ø.2Ø.2ñ#p
à˜u×0Ñ0Ñ1ðp
ð ! ×!1Ñ!1Ñ2ðp
ð ' u×'8Ñ'8Ñ9ð	p
ð
 !)¨×)9Ñ)9Ñ :ðp
ð ˜E×-Ñ-Ñ.ðp
ð $ E×$5Ñ$5Ñ6ðp
ð ' u§|¡|Ñ4ðp
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðp
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðp
ð ˜D‘>ðp
ð $ D™>ðp
ð ' t™nðp
ð ˜d‘^ðp
ð % U×%6Ñ%6Ñ7ðp
ð  ˜×*Ñ*Ñ+ð!p
ð" ˜eŸl™lÑ+ð#p
ð$ 
ˆuÐ.Ð.Ñ	/ò%p
ó có Fðp
ðd €U‡]�]ƒ_ð ;?Ø59ØØ Ø!Ø'+Ø(-Ø&+ñV
à×'Ñ'ðV
ð % U×%6Ñ%6Ñ7ðV
ð ! ×!1Ñ!1Ñ2ð	V
ð
 ðV
ð ðV
ð ðV
ð ˜"Ÿ)™)Ñ$ðV
ð "&ðV
ð  $ðV
ð 
×	Ñ	òV
ó ôV
r+   r8  aT  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`SpeechT5HifiGanConfig`]):
            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
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
c                   ó:   ‡ — e Zd Zdˆ fd„	Zdd„Zd„ Zd„ Zd„ Zˆ xZS )ÚHifiGanResidualBlockc                 óÜ  •— t         ‰| �  «        || _        t        j                  t        t        |«      «      D �cg c]3  }t        j                  |||d||   | j                  |||   «      ¬«      ‘Œ5 c}«      | _	        t        j                  t        t        |«      «      D �cg c]-  }t        j                  |||dd| j                  |d«      ¬«      ‘Œ/ c}«      | _
        y c c}w c c}w )Nr   )ri   Údilationr×   )rk   rl   Úleaky_relu_sloper   r  rL   rQ   rp   Úget_paddingÚconvs1Úconvs2)rx   Úchannelsrh   rB  rC  r  r[   r{   s          €r)   rl   zHifiGanResidualBlock.__init__Œ  sà   ø€ Ü‰ÑÔØ 0ˆÔä—m‘mô œs 8›}Ó-ö
ð ô —	‘	ØØØØØ% a™[Ø ×,Ñ,¨[¸(À1¹+ÓFöò
ó
ˆŒô —m‘mô œs 8›}Ó-ö
ð ô —	‘	ØØØØØØ ×,Ñ,¨[¸!Ó<öò
ó
ˆ�ùò
ùò
s   ¼8C$Â%2C)c                 ó   — ||z  |z
  dz  S rŸ   r+  )rx   rh   rB  s      r)   rD  z HifiGanResidualBlock.get_padding«  s   € Ø˜hÑ&¨Ñ1°aÑ7Ð7r+   c                 ó,  — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  }| j
                  D ]
  } ||«       Œ | j                  D ]
  } ||«       Œ y ©NrÙ   )r   rá   rÙ   r©   rÝ   rE  rF  ©rx   rÙ   r  s      r)   Úapply_weight_normz&HifiGanResidualBlock.apply_weight_norm®  sp   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKà—[‘[ò 	ˆEÙ˜Õð	à—[‘[ò 	ˆEÙ˜Õñ	r+   c                 óÄ   — | j                   D ]!  }t        j                  j                  |«       Œ# | j                  D ]!  }t        j                  j                  |«       Œ# y r}   )rE  r   rá   Úremove_weight_normrF  ©rx   r  s     r)   rN  z'HifiGanResidualBlock.remove_weight_norm¸  sL   € Ø—[‘[ò 	/ˆEÜ�H‰H×'Ñ'¨Õ.ð	/à—[‘[ò 	/ˆEÜ�H‰H×'Ñ'¨Õ.ñ	/r+   c                 ó,  — t        | j                  | j                  «      D ]p  \  }}|}t        j                  j                  || j                  «      } ||«      }t        j                  j                  || j                  «      } ||«      }||z   }Œr |S r}   )rS  rE  rF  r   rv  Ú
leaky_relurC  )rx   r   Úconv1Úconv2rû  s        r)   r€   zHifiGanResidualBlock.forward¾  s‡   € Ü §¡¨T¯[©[Ó9ò 	5‰LˆE�5Ø$ˆHÜŸM™M×4Ñ4°]ÀD×DYÑDYÓZˆMÙ! -Ó0ˆMÜŸM™M×4Ñ4°]ÀD×DYÑDYÓZˆMÙ! -Ó0ˆMØ)¨HÑ4‰Mð	5ð Ðr+   )r   )r   r   é   gš™™™™™¹?)r   )	rƒ   r„   r…   rl   rD  rL  rN  r€   r†   r‡   s   @r)   r@  r@  ‹  s   ø„ õ
ó>8òò/ör+   r@  zHiFi-GAN vocoder.c                   óv   ‡ — e Zd ZeZdZdefˆ fd„Zd„ Zd„ Zd„ Z	de
j                  de
j                  fd„Zˆ xZS )	ÚSpeechT5HifiGanr  ry   c                 ó²  •— t         ‰| �  |«       t        |j                  «      | _        t        |j
                  «      | _        t        j                  |j                  |j                  ddd¬«      | _        t        j                  «       | _        t        t        |j
                  |j                   «      «      D ]d  \  }\  }}| j                  j#                  t        j$                  |j                  d|z  z  |j                  d|dz   z  z  ||||z
  dz  ¬«      «       Œf t        j                  «       | _        t)        t        | j                  «      «      D ]p  }|j                  d|dz   z  z  }t        |j                  |j*                  «      D ]6  \  }}| j&                  j#                  t-        ||||j.                  «      «       Œ8 Œr t        j                  dddd¬«      | _        | j3                  dt5        j6                  |j                  «      «       | j3                  dt5        j8                  |j                  «      «       | j;                  «        y )Né   r   r   )rh   ri   r×   r    r  r–  )rk   rl   rQ   Úresblock_kernel_sizesÚnum_kernelsÚupsample_ratesÚnum_upsamplesr   rp   Úmodel_in_dimÚupsample_initial_channelÚconv_prer  Ú	upsamplerrD  rS  Úupsample_kernel_sizesrU   ÚConvTranspose1dÚ	resblocksrL   Úresblock_dilation_sizesr@  rC  Ú	conv_postrõ   r´   rM   rS   r3  )rx   ry   r  Úupsample_raterh   rG  rB  r{   s          €r)   rl   zSpeechT5HifiGan.__init__Ñ  s÷  ø€ Ü‰Ñ˜Ô Ü˜v×;Ñ;Ó<ˆÔÜ  ×!6Ñ!6Ó7ˆÔÜŸ	™	Ø×ÑØ×+Ñ+ØØØô
ˆŒô Ÿ™›ˆŒÜ/8¼¸V×=RÑ=RÐTZ×TpÑTpÓ9qÓ/rò 		Ñ+ˆAÑ+�˜{Ø�N‰N×!Ñ!Ü×"Ñ"Ø×3Ñ3¸¸1¹Ñ=Ø×3Ñ3¸¸aÀ!¹e¹ÑEØ +Ø(Ø(¨=Ñ8¸QÑ>ôõð		ô Ÿ™›ˆŒÜ”s˜4Ÿ>™>Ó*Ó+ò 	vˆAØ×6Ñ6¸1ÀÀQÁ¹<ÑHˆHÜ),¨V×-IÑ-IÈ6×KiÑKiÓ)jò vÑ%�˜XØ—‘×%Ñ%Ô&:¸8À[ÐRZÐ\b×\sÑ\sÓ&tÕuñvð	vô
 Ÿ™ 8¨Q¸AÀaÐQRÔSˆŒà×Ñ˜V¤U§[¡[°×1DÑ1DÓ%EÔFØ×Ñ˜W¤e§j¡j°×1DÑ1DÓ&EÔFð 	�‰Õr+   c                 ó2  — t        |t        j                  t        j                  f«      rm|j                  j
                  j                  d| j                  j                  ¬«       |j                  �%|j                  j
                  j                  «        yyy)zInitialize the weights.r1   r  N)rç  r   r)  rp   rÛ   r  r  ry   r   rj   r!  )rx   r$  s     r)   r&  zSpeechT5HifiGan._init_weights÷  sj   € ä�fœrŸy™y¬"¯)©)Ð4Ô5Ø�M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ð 6r+   c                 ó„  — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «       | j                  D ]
  } ||«       Œ | j                  D ]  }|j                  «        Œ  || j                  «       y rJ  )
r   rá   rÙ   r©   rÝ   r_  r`  rc  rL  re  rK  s      r)   rL  z!SpeechT5HifiGan.apply_weight_normþ  sŒ   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKá�D—M‘MÔ"Ø—^‘^ò 	ˆEÙ˜Õð	à—^‘^ò 	&ˆEØ×#Ñ#Õ%ð	&á�D—N‘NÕ#r+   c                 óJ  — t         j                  j                  | j                  «       | j                  D ]!  }t         j                  j                  |«       Œ# | j
                  D ]  }|j                  «        Œ t         j                  j                  | j                  «       y r}   )r   rá   rN  r_  r`  rc  re  rO  s     r)   rN  z"SpeechT5HifiGan.remove_weight_norm
  sr   € Ü
�‰×#Ñ# D§M¡MÔ2Ø—^‘^ò 	/ˆEÜ�H‰H×'Ñ'¨Õ.ð	/à—^‘^ò 	'ˆEØ×$Ñ$Õ&ð	'ä
�‰×#Ñ# D§N¡NÕ3r+   r7   c                 ó¾  — | j                   j                  r|| j                  z
  | j                  z  }|j	                  «       dk(  }|s|j                  d«      }|j                  dd«      }| j                  |«      }t        | j                  «      D ]¿  }t        j                  j                  || j                   j                  «      } | j                  |   |«      } | j                  || j                   z     |«      }t        d| j                   «      D ]*  }| | j                  || j                   z  |z      |«      z  }Œ, || j                   z  }ŒÁ t        j                  j                  |«      }| j#                  |«      }t%        j&                  |«      }|s2|j)                  d«      j                  dd«      j+                  d«      }|S |j)                  d«      }|S )a  
        Converts a log-mel spectrogram into a speech waveform. Passing a batch of log-mel spectrograms returns a batch
        of speech waveforms. Passing a single, un-batched log-mel spectrogram returns a single, un-batched speech
        waveform.

        Args:
            spectrogram (`torch.FloatTensor`):
                Tensor containing the log-mel spectrograms. Can be batched and of shape `(batch_size, sequence_length,
                config.model_in_dim)`, or un-batched and of shape `(sequence_length, config.model_in_dim)`.

        Returns:
            `torch.FloatTensor`: Tensor containing the speech waveform. If the input spectrogram is batched, will be of
            shape `(batch_size, num_frames,)`. If un-batched, will be of shape `(num_frames,)`.
        r   r   r    r   r"   )ry   Únormalize_beforer  r–  r±   r¸   r�   r_  rL   r\  r   rv  rQ  rC  r`  rc  rZ  re  r´   Útanhr  r¼   )rx   r  Ú
is_batchedr   r  Ú	res_stateÚjÚwaveforms           r)   r€   zSpeechT5HifiGan.forward  s¯  € ð �;‰;×'Ò'Ø&¨¯©Ñ2°d·j±jÑ@ˆKà —_‘_Ó&¨!Ñ+ˆ
ÙØ%×/Ñ/°Ó2ˆKà#×-Ñ-¨a°Ó3ˆàŸ™ mÓ4ˆÜ�t×)Ñ)Ó*ò 	9ˆAÜŸM™M×4Ñ4°]ÀDÇKÁK×D`ÑD`ÓaˆMØ-˜DŸN™N¨1Ñ-¨mÓ<ˆMà<˜Ÿ™ q¨4×+;Ñ+;Ñ';Ñ<¸]ÓKˆIÜ˜1˜d×.Ñ.Ó/ò U�ØÐE˜TŸ^™^¨A°×0@Ñ0@Ñ,@À1Ñ,DÑEÀmÓTÑT‘	ðUà%¨×(8Ñ(8Ñ8‰Mð	9ô Ÿ™×0Ñ0°Ó?ˆØŸ™ }Ó5ˆÜŸ
™
 =Ó1ˆáà$×,Ñ,¨QÓ/×9Ñ9¸!¸QÓ?×DÑDÀRÓHˆHð
 ˆð %×,Ñ,¨QÓ/ˆHàˆr+   )rƒ   r„   r…   r   r'  r)  rl   r&  rL  rN  r´   r_  r€   r†   r‡   s   @r)   rV  rV  É  sK   ø„ ð
 )€LØ#€Oð$Ð4õ $òL)ò
$ò4ð- 5×#4Ñ#4ð -¸×9JÑ9J÷ -r+   rV  )rÜ  r8  r"  r¾  r  rV  )r   Nr  r5  )erÐ   r²   Útypingr   r   r   r   ÚnumpyrE   r´   Útorch.utils.checkpointr   Útorch.nnr   r	   r
   Úactivationsr   Úintegrations.deepspeedr   Úintegrations.fsdpr   Úmodeling_attn_mask_utilsr   r   Úmodeling_outputsr   r   r   r   r   Úmodeling_utilsr   rá   r   r   r   r   Úconfiguration_speecht5r   r   Ú
get_loggerrƒ   rt  Ú_HIDDEN_STATES_START_POSITIONrÚ  rÓ   r;   r*   r3   r·   r^  Úndarrayrc   rØ  re   r‰   r’   rš   rÕ   rî   rÿ   rê   r  r$  r0  ra  r{  r†  r’  r¢  r¯  r½  râ  rñ  rþ  r  r-  rQ  r[  rf  rl  r  r‡  r�  r‘  r­  ÚSPEECHT5_BASE_START_DOCSTRINGÚSPEECHT5_START_DOCSTRINGrÙ  r¾  rÜ  r_  rN   r   r"  r8  ÚHIFIGAN_START_DOCSTRINGr@  rV  Ú__all__r+  r+   r)   ú<module>rƒ     s!  ðñ ã ß /Ó /ã Û Û Ý ß @Ñ @å !Ý @Ý 7ß e÷õ õ .ß tÓ tß Ið 
ˆ×	Ñ	˜HÓ	%€ð !"Ð ð #€ð %§,¡,ð ¸cð Ð[^ó ð" eiñ0Ø—,‘,ð0Ø25ð0ØKSÐTY×T`ÑT`ÑKaó0ð4 26ØñtØ��c�‰?ðtàðtð ðtð ˜U×-Ñ-Ñ.ð	tð
 ðtð ‡Z�Zótôp 2§9¡9ô ô, §¡ô ô8 §¡ô ô2C8¨B¯I©Iô C8ôN* b§i¡iô *ôZ r§y¡yô ô0"¨¯©¯©ô "ô(˜2Ÿ9™9ô ô+˜RŸY™Yô +ô^1 §	¡	ô 1ôD "§)¡)ô DôN1 "§)¡)ô 1ôh% §¡ô %ôP< 2§9¡9ô <ô2 §	¡	ô ô.(- §	¡	ô (-ôV& §¡ô &ô ]B˜Ÿ	™	ô ]Bô@˜"Ÿ)™)ô ô0:˜2Ÿ9™9ô :ôzi˜2Ÿ9™9ô iôX'?˜oô '?ôTF
Ð-ô F
ôR"Ð&=ô "ôJ'Ð$;ô 'ôT
Ð#:ô 
ô@L
Ð-ô L
ô^-Ð&=ô -ô`1Ð$;ô 1ôh(Ð#:ô (ôV8M¨2¯9©9ô 8Môv:˜bŸi™iô :ðz!Ð ð0Ð ð"SÐ ñl ØrØ!óôM
Ð+ó M
ó	ðM
ñ` ØBØóôXÐ5ó Xó	ðXð| 7;Ø15ØØØØ#'Ø$)Ø"'ñLØ"ðLà×#Ñ#ðLð ! ×!2Ñ!2Ñ3ðLð ˜U×-Ñ-Ñ.ð	Lð
 ðLð ðLð ðLð �b—i‘iÑ ðLð "ðLð  ðLð ˆ5×Ñ˜e E×$5Ñ$5°u×7HÑ7HÐ$HÑIÐIÑJóLñ^ ØBØóôX
Ð5ó X
ó	ðX
ñv
 ØDØóôe
Ð 7ó e
ó	ðe
ðPÐ ô";˜2Ÿ9™9ô ;ñ| ØØóôr�oó ró	ðròj�r+   