Ë
    S^(h¿e ã                   óP  — d Z ddlZddlZddlmZ ddlmZmZmZm	Z	 ddl
Z
ddl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 ddlmZmZmZmZ ddlmZ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)m*Z*m+Z+  e&jX                  e-«      Z.dZ/de
j`                  de
j`                  fd„Z1de
j`                  de
j`                  fd„Z2d„ Z3dCd„Z4	 	 	 	 	 	 dDd„Z5e G d„ de#«      «       Z6e G d„ de#«      «       Z7 G d„ dejp                  «      Z9 G d „ d!ejp                  «      Z: G d"„ d#ejp                  «      Z; G d$„ d%ejp                  «      Z< G d&„ d'ejp                  «      Z= G d(„ d)ejp                  «      Z> G d*„ d+ejp                  «      Z? G d,„ d-ejp                  «      Z@ G d.„ d/ejp                  «      ZA G d0„ d1e«      ZBd2ZCd3ZDd4ZE G d5„ d6eB«      ZF G d7„ d8eB«      ZG e$d9eC«       G d:„ d;eB«      «       ZH e$d<eC«       G d=„ d>eBe«      «       ZI e$d?eC«       G d@„ dAeBe«      «       ZJg dB¢ZKy)EzPyTorch CLVP model.é    N)Ú	dataclass)ÚDictÚOptionalÚTupleÚUnion)Únn)ÚCrossEntropyLossé   )ÚACT2FN)ÚGenerationConfigÚGenerationMixin)Ú_prepare_4d_attention_maskÚ!_prepare_4d_causal_attention_mask)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚBaseModelOutputWithPoolingÚ!CausalLMOutputWithCrossAttentions)ÚPreTrainedModelÚSequenceSummary)ÚConv1DÚisin_mps_friendly)ÚModelOutputÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )Ú
ClvpConfigÚClvpDecoderConfigÚClvpEncoderConfigzsusnato/clvp_devÚlogitsÚreturnc                 ó’   — t         j                  j                  | t        j                  t        | «      | j                  ¬«      «      S )N©Údevice)r   Ú
functionalÚcross_entropyÚtorchÚarangeÚlenr%   )r!   s    úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/clvp/modeling_clvp.pyÚcontrastive_lossr,   ;   s/   € Ü�=‰=×&Ñ& v¬u¯|©|¼CÀ»KÐPV×P]ÑP]Ô/^Ó_Ð_ó    Ú
similarityc                 óZ   — t        | «      }t        | j                  «       «      }||z   dz  S )Ng       @)r,   Út)r.   Úcaption_lossÚspeech_losss      r+   Ú	clvp_lossr3   @   s,   € Ü# JÓ/€LÜ" :§<¡<£>Ó2€KØ˜;Ñ&¨#Ñ-Ð-r-   c                 óš   — | dd| j                   d   dz  …f   }| d| j                   d   dz  d…f   }t        j                  | |fd¬«      S )z*Rotates half the hidden dims of the input..Néÿÿÿÿé   ©Údim)Úshaper(   Úcat)ÚxÚx1Úx2s      r+   Úrotate_halfr>   G   sZ   € à	
ˆ3Ð"�!—'‘'˜"‘+ Ñ"Ð"Ð"Ñ	#€BØ	
ˆ3�—‘˜‘˜qÑ Ñ"Ð"Ñ	#€BÜ�9‰9�r�c˜2�Y BÔ'Ð'r-   c                 óÔ   — ||   j                  |«      }||   j                  |«      }| |z  t        | «      |z  z   }||z  t        |«      |z  z   }||z  t        |«      |z  z   }	|||	fS )an  Applies Rotary Position Embedding to the query and key tensors.

    Args:
        q (`torch.Tensor`): The query tensor.
        k (`torch.Tensor`): The key tensor.
        cos (`torch.Tensor`): The cosine part of the rotary embedding.
        sin (`torch.Tensor`): The sine part of the rotary embedding.
        position_ids (`torch.Tensor`):
            The position indices of the tokens corresponding to the query and key tensors. For example, this can be
            used to pass offsetted position ids when working with a KV-cache.
        unsqueeze_dim (`int`, *optional*, defaults to 1):
            The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
            sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
            that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
            k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
            cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
            the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
    Returns:
        `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
    )Ú	unsqueezer>   )
ÚqÚkÚvÚcosÚsinÚposition_idsÚunsqueeze_dimÚq_embedÚk_embedÚv_embeds
             r+   Úapply_rotary_pos_embrK   N   s€   € ð* ˆlÑ
×
%Ñ
% mÓ
4€CØ
ˆlÑ
×
%Ñ
% mÓ
4€CØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�G˜WÐ$Ð$r-   c                 óT  — |r\t         j                  j                  j                  | d|¬«      } |�,t         j                  j                  j                  |dd¬«      n|}| }|�rBt        j                  | j
                  d   | j
                  d   dz   f| j                  | j                  ¬«      }t        | «      D ]¹  \  }}	t        |	|«      j                  «       rkt        j                  |	|k(  «      d   j                  «       }
t        j                  |	d|
 t        j                  |g| j                  ¬«      |	|
d g«      ||<   Œ‹t         j                  j                  j                  |	d|¬«      ||<   Œ» |�,t         j                  j                  j                  |dd¬«      n|}||fS )	zß
    This method adds extra bos and eos tokens to input_ids and accordingly modifies the attention_mask which is used in
    `ClvpConditioningEncoder` and the generation loop of the `ClvpModelForConditionalGeneration`.
    )r   r   ©ÚvalueNr   r   ©Údtyper%   r$   )r   r   )r(   r   r&   ÚpadÚzerosr9   rP   r%   Ú	enumerater   ÚsumÚwhereÚminÚconcatenateÚtensor)Ú	input_idsÚattention_maskÚpad_token_idÚbos_token_idÚeos_token_idÚadd_bos_tokenÚadd_eos_tokenÚmodified_input_idsÚiÚeach_input_idÚposs              r+   Ú_pad_extra_bos_eos_tokensrd   k   s˜  € ñ Ü—H‘H×'Ñ'×+Ñ+¨I°vÀ\Ð+ÓRˆ	àHVÐHbŒE�H‰H×Ñ×#Ñ# N°FÀ!Ð#ÔDÐhvð 	ð #ÐÚÜ"Ÿ[™[Ø�_‰_˜QÑ §¡°Ñ!3°aÑ!7Ð8À	ÇÁÐXa×XhÑXhô
Ðô !*¨)Ó 4ò 		kÑˆAˆ}ä  °Ó=×AÑAÔCÜ—k‘k -°<Ñ"?Ó@ÀÑC×GÑGÓI�Ü(-×(9Ñ(9Ø" 4 CÐ(¬%¯,©,¸°~Èi×N^ÑN^Ô*_ÐanÐorÐosÐatÐuó)Ð" 1Ò%ô
 ).¯©×(;Ñ(;×(?Ñ(?ÀÈvÐ]iÐ(?Ó(jÐ" 1Ò%ð		kð IWÐHbŒE�H‰H×Ñ×#Ñ# N°FÀ!Ð#ÔDÐhvð 	ð ˜~Ð-Ð-r-   c                   óæ   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZ
eej                     ed<   dZeeej                        ed<   dZeeej                        ed<   y)ÚClvpEncoderOutputak  
    Base class for CLVP encoder's outputs that contains a pooling of the last hidden states as well as a projection
    output (a linear layer on top of the pooled output).

    Args:
        embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)`, *optional*, returned when model is initialized with `with_projection=True`):
            The embeddings obtained by applying the projection layer to the pooler_output.
        last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
            The hidden state of the last layer of the model.
        pooler_output (`torch.FloatTensor` of shape `(batch_size, hidden_size)`):
            Pooled output of the `last_hidden_state`.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
            one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`. Hidden-states of
            the model at the output of each layer plus the optional initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`. Attentions weights after the attention softmax, used to compute the weighted average in
            the self-attention heads.
    NÚembedsÚlast_hidden_stateÚpooler_outputÚhidden_statesÚ
attentions)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rg   r   r(   ÚFloatTensorÚ__annotations__rh   ri   rj   r   rk   © r-   r+   rf   rf   –   s}   … ñð* +/€FˆH�U×&Ñ&Ñ'Ó.Ø59Ð�x × 1Ñ 1Ñ2Ó9Ø15€M�8˜E×-Ñ-Ñ.Ó5Ø8<€M�8˜E %×"3Ñ"3Ñ4Ñ5Ó<Ø59€J�˜˜u×0Ñ0Ñ1Ñ2Ô9r-   rf   c                   ó–  — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeej                     ed<   dZeed	<   dZeed
<   dZeej                     ed<   dZeej                     ed<   dZeej                     ed<   y)Ú
ClvpOutputai  
    Args:
        loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `return_loss` is `True`):
            Contrastive loss for speech-text similarity.
        speech_ids (`torch.LongTensor`, *optional*):
            speech_ids (or speech candidates) generated by the `ClvpForCausalLM` model.
        logits_per_speech (`torch.FloatTensor` of shape `(speech_batch_size, text_batch_size)`):
            The scaled dot product scores between `speech_embeds` and `text_embeds`. This represents the speech-text
            similarity scores.
        logits_per_text (`torch.FloatTensor` of shape `(text_batch_size, speech_batch_size)`):
            The scaled dot product scores between `text_embeds` and `speech_embeds`. This represents the text-speech
            similarity scores.
        text_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim`):
            The text embeddings obtained by applying the projection layer to the pooled output of the text encoder
            model.
        speech_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim`):
            The speech embeddings obtained by applying the projection layer to the pooled output of the speech encoder
            model.
        text_model_output (`BaseModelOutputWithPooling`):
            The pooled output of the `last_hidden_state` of the text encoder Model.
        speech_model_output (`BaseModelOutputWithPooling`):
            The pooled output of the `last_hidden_state` of the speech encoder Model.
        decoder_hidden_states (`torch.FloatTensor`, *optional*):
            The hidden states of the decoder model.
        text_encoder_hidden_states (`torch.FloatTensor`, *optional*):
            The hidden states of the text encoder model.
        speech_encoder_hidden_states (`torch.FloatTensor`, *optional*):
            The hidden states of the speech encoder model.
    NÚlossÚ
speech_idsÚlogits_per_speechÚlogits_per_textÚtext_embedsÚspeech_embedsÚtext_model_outputÚspeech_model_outputÚdecoder_hidden_statesÚtext_encoder_hidden_statesÚspeech_encoder_hidden_states)rl   rm   rn   ro   ru   r   r(   rp   rq   rv   Ú
LongTensorrw   rx   ry   rz   r{   r   r|   r}   r~   r   rr   r-   r+   rt   rt   ´   sâ   … ñð< )-€Dˆ(�5×$Ñ$Ñ
%Ó,Ø-1€J�˜×)Ñ)Ñ*Ó1Ø59Ð�x × 1Ñ 1Ñ2Ó9Ø37€O�X˜e×/Ñ/Ñ0Ó7Ø/3€K�˜%×+Ñ+Ñ,Ó3Ø15€M�8˜E×-Ñ-Ñ.Ó5Ø48ÐÐ1Ó8Ø6:ÐÐ3Ó:Ø9=Ð˜8 E×$5Ñ$5Ñ6Ó=Ø>BÐ ¨×):Ñ):Ñ ;ÓBØ@DÐ  (¨5×+<Ñ+<Ñ"=ÔDr-   rt   c                   ó,   ‡ — e Zd Zdˆ fd„	Zd„ Zd„ Zˆ xZS )ÚClvpRMSNormc                 óŠ   •— t         ‰| �  «        t        j                  t	        j
                  |«      «      | _        || _        y)z:
        ClvpRMSNorm is equivalent to T5LayerNorm
        N)ÚsuperÚ__init__r   Ú	Parameterr(   ÚonesÚweightÚvariance_epsilon)ÚselfÚhidden_sizeÚepsÚ	__class__s      €r+   r…   zClvpRMSNorm.__init__ã   s1   ø€ ô 	‰ÑÔÜ—l‘l¤5§:¡:¨kÓ#:Ó;ˆŒØ #ˆÕr-   c                 ó"  — |j                   }|j                  t        j                  «      }|j	                  d«      j                  dd¬«      }|t        j                  || j                  z   «      z  }| j                  |j                  |«      z  S )Nr6   r5   T)Úkeepdim)	rP   Útor(   Úfloat32ÚpowÚmeanÚrsqrtr‰   rˆ   )rŠ   rj   Úinput_dtypeÚvariances       r+   ÚforwardzClvpRMSNorm.forwardë   sy   € Ø#×)Ñ)ˆØ%×(Ñ(¬¯©Ó7ˆØ ×$Ñ$ QÓ'×,Ñ,¨R¸Ð,Ó>ˆØ%¬¯©°H¸t×?TÑ?TÑ4TÓ(UÑUˆØ�{‰{˜]×-Ñ-¨kÓ:Ñ:Ð:r-   c                 ó^   — t        | j                  j                  «      › d| j                  › �S )Nz, eps=)Útuplerˆ   r9   r‰   ©rŠ   s    r+   Ú
extra_reprzClvpRMSNorm.extra_reprò   s*   € Ü˜Ÿ™×)Ñ)Ó*Ð+¨6°$×2GÑ2GÐ1HÐIÐIr-   )g�íµ ÷Æ°>)rl   rm   rn   r…   r—   r›   Ú__classcell__©r�   s   @r+   r‚   r‚   â   s   ø„ õ$ò;öJr-   r‚   c                   óZ   ‡ — e Zd ZdZˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚClvpRotaryPositionalEmbeddingzÉ
    Rotary Position Embedding Class for CLVP. It was proposed in the paper 'ROFORMER: ENHANCED TRANSFORMER WITH ROTARY
    POSITION EMBEDDING', Please see https://arxiv.org/pdf/2104.09864v1.pdf .
    c                 ó*  •— t         ‰| �  «        t        |j                  |j                  dz  z  d«      }ddt        j                  d|dt
        j                  ¬«      j                  «       |z  z  z  }| j                  d|«       d | _
        d | _        y )Nr6   é    ç      ð?i'  r   ©rP   Úinv_freq)r„   r…   ÚmaxÚprojection_dimÚnum_attention_headsr(   r)   Úint64ÚfloatÚregister_bufferÚcached_sequence_lengthÚ"cached_rotary_positional_embedding)rŠ   Úconfigr8   r¤   r�   s       €r+   r…   z&ClvpRotaryPositionalEmbedding.__init__ü   s�   ø€ Ü‰ÑÔÜ�&×'Ñ'¨F×,FÑ,FÈÑ,JÑKÈRÓPˆØ˜%¤E§L¡L°°C¸Ä%Ç+Á+Ô$N×$TÑ$TÓ$VÐY\Ñ$\Ñ]Ñ^ˆà×Ñ˜Z¨Ô2Ø&*ˆÔ#Ø26ˆÕ/r-   rj   r"   c                 ó¨  — |j                   d   }|| j                  k(  r| j                  �| j                  S || _        t        j                  ||j
                  ¬«      j                  | j                  «      }t        j                  d|| j                  «      }t        j                  ||fd¬«      }|j                  d«      | _        | j                  S )Nr   r$   zi,j->ijr5   r7   r   )r9   r«   r¬   r(   r)   r%   Útype_asr¤   Úeinsumr:   r@   )rŠ   rj   Úsequence_lengthÚtime_stampsÚfreqsÚ
embeddingss         r+   r—   z%ClvpRotaryPositionalEmbedding.forward  s°   € Ø'×-Ñ-¨aÑ0ˆà˜d×9Ñ9Ò9¸d×>eÑ>eÐ>qØ×:Ñ:Ð:à&5ˆÔ#Ü—l‘l ?¸=×;OÑ;OÔP×XÑXÐY]×YfÑYfÓgˆÜ—‘˜Y¨°T·]±]ÓCˆÜ—Y‘Y  u˜~°2Ô6ˆ
à2<×2FÑ2FÀqÓ2IˆÔ/Ø×6Ñ6Ð6r-   ©	rl   rm   rn   ro   r…   r(   rp   r—   rœ   r�   s   @r+   rŸ   rŸ   ö   s,   ø„ ñô
7ð7 U×%6Ñ%6ð 7¸5×;LÑ;L÷ 7r-   rŸ   c                   óˆ  ‡ — e Zd ZdZˆ fd„Zdej                  dedefd„Z	 	 	 	 	 	 	 dd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j                     de
e   deej                  e
ej                     e
eej                        f   fd„Zˆ xZS )ÚClvpSelfAttentionzu
    Multi-headed attention to combine Absolute and Rotary Positional Embeddings into a single Attention module.
    c                 óF  •— t         ‰| �  «        || _        |j                  | _        |j
                  | _        | j                  | j                  z  | _        | j                  | j                  z  | j                  k7  r&t        d| j                  › d| j                  › d�«      ‚| j                  dz  | _	        |j                  | _        t        |d«      rn|j                  }t        j                  t        j                   ||ft        j"                  ¬«      «      }|j%                  dd||«      }| j'                  d|d	¬
«       t)        j*                  | j                  | j                  |j,                  ¬«      | _        t)        j*                  | j                  | j                  |j,                  ¬«      | _        t)        j*                  | j                  | j                  |j,                  ¬«      | _        t)        j*                  | j                  | j                  «      | _        y )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).ç      à¿Úmax_position_embeddingsr£   r   ÚbiasF)Ú
persistent©r»   )r„   r…   r­   r‹   Ú	embed_dimr§   Ú	num_headsÚhead_dimÚ
ValueErrorÚscaleÚattention_dropoutÚdropoutÚhasattrrº   r(   Útrilr‡   ÚboolÚviewrª   r   ÚLinearÚuse_attention_biasÚk_projÚv_projÚq_projÚout_proj)rŠ   r­   Úmax_positionsr»   r�   s       €r+   r…   zClvpSelfAttention.__init__  sŒ  ø€ Ü‰ÑÔØˆŒØ×+Ñ+ˆŒØ×3Ñ3ˆŒØŸ™¨$¯.©.Ñ8ˆŒØ�=‰=˜4Ÿ>™>Ñ)¨T¯^©^Ò;ÜØMÈdÏnÉnÐM]ð ^Ø—N‘NÐ# 2ð'óð ð —]‘] DÑ(ˆŒ
Ø×/Ñ/ˆŒä�6Ð4Ô5Ø"×:Ñ:ˆMÜ—:‘:œeŸj™j¨-¸Ð)GÌuÏzÉzÔZÓ[ˆDØ—9‘9˜Q  =°-Ó@ˆDØ× Ñ  ¨¸%Ð Ô@ä—i‘i §¡°·±ÀV×E^ÑE^Ô_ˆŒÜ—i‘i §¡°·±ÀV×E^ÑE^Ô_ˆŒÜ—i‘i §¡°·±ÀV×E^ÑE^Ô_ˆŒÜŸ	™	 $§.¡.°$·.±.ÓAˆ�r-   rX   Úseq_lenÚbszc                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S )Nr   r6   )rÈ   r¿   rÀ   Ú	transposeÚ
contiguous)rŠ   rX   rÐ   rÑ   s       r+   Ú_shapezClvpSelfAttention._shape3  s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr-   rj   Úrotary_pos_embrZ   rF   Úpast_key_valueÚ	use_cacheÚ	head_maskÚoutput_attentionsr"   c	                 óâ  — |�|€t        d«      ‚|j                  «       \  }	}
}| j                  | j                  |«      d|	«      | j                  z  }| j                  | j                  |«      d|	«      }| j                  | j                  |«      d|	«      }|�7|\  }}t        j                  ||fd¬«      }t        j                  ||fd¬«      }|du r||f}nd }|�â|j                  d   }|dd |…f   |d|d …f   }}|dd |…f   |d|d …f   }}|dd |…f   |d|d …f   }}|j                  «       j                  d«      |j                  «       j                  d«      }}t        ||||||«      \  }}}t        j                  ||fd¬«      }t        j                  ||fd¬«      }t        j                  ||fd¬«      }|j                  d   }|j                  d   }t        j                  ||j                  dd	«      «      }|�?|j                  «       |	d
||fk7  r#t        d|	d
||f› d|j                  «       › �«      ‚||z   }t         j"                  j%                  |d¬«      }|�||z  }t         j"                  j'                  || j&                  | j(                  ¬«      }t        j                  ||«      }|j                  «       |	| j*                  || j,                  fk7  r7t        d|	| j*                  || j,                  f› d|j                  «       › �«      ‚|j                  d
d«      j/                  «       }|j1                  |	|| j2                  «      }| j5                  |«      }|sd }|||fS )NzB`position_ids` must be provided when `rotary_pos_emb` is not None.r5   éþÿÿÿr7   T.r   r6   r
   r   z!Attention mask should be of size z	, but is )ÚpÚtrainingz `attn_output` should be of size )rÁ   ÚsizerÕ   rÍ   rÂ   rË   rÌ   r(   r:   r9   rD   ÚsqueezerE   rK   ÚmatmulrÓ   r   r&   ÚsoftmaxrÄ   rÞ   r¿   rÀ   rÔ   Úreshaper¾   rÎ   ) rŠ   rj   rÖ   rZ   rF   r×   rØ   rÙ   rÚ   rÑ   Ú_r¾   Úquery_statesÚ
key_statesÚvalue_statesÚpast_keyÚ
past_valueÚpresentÚrotary_emb_dimÚ	query_rotÚ
query_passÚkey_rotÚkey_passÚ	value_rotÚ
value_passrD   rE   Útgt_lenÚsrc_lenÚattn_weightsÚ
attn_probsÚattn_outputs                                    r+   r—   zClvpSelfAttention.forward6  s¼  € ð Ð%¨,Ð*>ÜÐaÓbÐbà)×.Ñ.Ó0ÑˆˆQ�	ð —{‘{ 4§;¡;¨}Ó#=¸rÀ3ÓGÈ$Ï*É*ÑTˆØ—[‘[ §¡¨]Ó!;¸RÀÓEˆ
Ø—{‘{ 4§;¡;¨}Ó#=¸rÀ3ÓGˆàÐ%Ø#1Ñ ˆH�jÜŸ™ H¨jÐ#9¸rÔBˆJÜ Ÿ9™9 j°,Ð%?ÀRÔHˆLà˜ÑØ! <Ð0‰GàˆGàÐ%Ø+×1Ñ1°"Ñ5ˆNð ˜S / > /Ð1Ñ2Ø˜S .¡/Ð1Ñ2ð "ˆIð
 ˜3   Ð/Ñ0Ø˜3 ¡Ð/Ñ0ð ˆGð
 ˜S / > /Ð1Ñ2Ø˜S .¡/Ð1Ñ2ð "ˆIð
 &×)Ñ)Ó+×3Ñ3°AÓ6¸×8JÑ8JÓ8L×8TÑ8TÐUVÓ8W�ˆCÜ,@ÀÈGÐU^Ð`cÐehÐjvÓ,wÑ)ˆI�w 	ô !Ÿ9™9 i°Ð%<À"ÔEˆLÜŸ™ G¨XÐ#6¸BÔ?ˆJÜ Ÿ9™9 i°Ð%<À"ÔEˆLà×$Ñ$ QÑ'ˆØ×"Ñ" 1Ñ%ˆÜ—|‘| L°*×2FÑ2FÀqÈ!Ó2LÓMˆàÐ%Ø×"Ñ"Ó$¨¨a°¸'Ð(BÒBÜ Ø7¸¸aÀÈ'Ð8RÐ7SÐS\Ð]k×]pÑ]pÓ]rÐ\sÐtóð ð (¨.Ñ8ˆLä—}‘}×,Ñ,¨\¸rÐ,ÓBˆð Ð Ø'¨)Ñ3ˆLä—]‘]×*Ñ*¨<¸4¿<¹<ÐRV×R_ÑR_Ð*Ó`ˆ
Ü—l‘l :¨|Ó<ˆà×ÑÓ # t§~¡~°wÀÇÁÐ!NÒNÜØ2°C¸¿¹ÈÐRV×R_ÑR_Ð3`Ð2að bØ×$Ñ$Ó&Ð'ð)óð ð
 "×+Ñ+¨A¨qÓ1×<Ñ<Ó>ˆØ!×)Ñ)¨#¨w¸¿¹ÓGˆà—m‘m KÓ0ˆá ØˆLà˜G \Ð1Ð1r-   )NNNNFNF)rl   rm   rn   ro   r…   r(   ÚTensorÚintrÕ   rp   r   r€   r   rÇ   r—   rœ   r�   s   @r+   r·   r·     s#  ø„ ñôBð4e˜UŸ\™\ð e°Cð e¸có eð 7;Ø59Ø37Ø8<Ø$)Ø15Ø,1ñ\2à×(Ñ(ð\2ð ! ×!2Ñ!2Ñ3ð\2ð ! ×!1Ñ!1Ñ2ð	\2ð
 ˜u×/Ñ/Ñ0ð\2ð !  u§|¡|Ñ!4Ñ5ð\2ð ˜D‘>ð\2ð ˜E×-Ñ-Ñ.ð\2ð $ D™>ð\2ð 
ˆu× Ñ  (¨5×+<Ñ+<Ñ"=¸xÈÈe×N_ÑN_ÑH`Ñ?aÐaÑ	b÷\2r-   r·   c                   óZ   ‡ — e Zd ZdZˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚClvpGatedLinearUnitzÈ
    `ClvpGatedLinearUnit` uses the second half of the `hidden_states` to act as a gate for the first half of the
    `hidden_states` which controls the flow of data from the first of the tensor.
    c                 ó¶   •— t         ‰| �  «        t        |j                     | _        t        j                  |j                  |j                  dz  «      | _	        y )Nr6   )
r„   r…   r   Ú
hidden_actÚactivation_fnr   rÉ   r‹   Úintermediate_sizeÚproj©rŠ   r­   r�   s     €r+   r…   zClvpGatedLinearUnit.__init__›  sD   ø€ Ü‰ÑÔÜ# F×$5Ñ$5Ñ6ˆÔÜ—I‘I˜f×0Ñ0°&×2JÑ2JÈQÑ2NÓOˆ�	r-   rj   r"   c                 ót   — | j                  |«      j                  dd¬«      \  }}|| j                  |«      z  S )Nr6   r5   r7   )rÿ   Úchunkrý   )rŠ   rj   Úgates      r+   r—   zClvpGatedLinearUnit.forward   s;   € Ø"Ÿi™i¨Ó6×<Ñ<¸QÀBÐ<ÓGÑˆ�tØ˜t×1Ñ1°$Ó7Ñ7Ð7r-   rµ   r�   s   @r+   rú   rú   •  s-   ø„ ñô
Pð
8 U×%6Ñ%6ð 8¸5×;LÑ;L÷ 8r-   rú   c                   óZ   ‡ — e Zd ZdZˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚClvpEncoderMLPzA
    This MLP is used in CLVP speech or text encoder models.
    c                 óö   •— t         ‰| �  «        || _        t        |«      | _        t        j                  |j                  |j                  «      | _	        t        j                  |j                  «      | _        y ©N)r„   r…   r­   rú   Úfc1r   rÉ   rþ   r‹   Úfc2ÚDropoutrÄ   Údropout_layerr   s     €r+   r…   zClvpEncoderMLP.__init__ª  sT   ø€ Ü‰ÑÔØˆŒä& vÓ.ˆŒÜ—9‘9˜V×5Ñ5°v×7IÑ7IÓJˆŒÜŸZ™Z¨¯©Ó7ˆÕr-   rj   r"   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S r  )r  r  r	  ©rŠ   rj   s     r+   r—   zClvpEncoderMLP.forward²  s4   € ØŸ™ Ó/ˆØ×*Ñ*¨=Ó9ˆØŸ™ Ó/ˆØÐr-   rµ   r�   s   @r+   r  r  ¥  s,   ø„ ñô8ð U×%6Ñ%6ð ¸5×;LÑ;L÷ r-   r  c                   ó¸   ‡ — e Zd Zdefˆ fd„Z	 d
dej                  dej                  dej                  dej                  dee	   de
ej                     fd	„Zˆ xZS )ÚClvpEncoderLayerr­   c                 ó*  •— t         ‰| �  «        || _        |j                  | _        t        |«      | _        t        |«      | _        t        | j                  |j                  ¬«      | _        t        | j                  |j                  ¬«      | _        y )N©rŒ   )r„   r…   r­   r‹   r¾   r·   Ú	self_attnr  Úmlpr‚   Úlayer_norm_epsÚinput_rmsnormÚpost_attention_rmsnormr   s     €r+   r…   zClvpEncoderLayer.__init__º  sl   ø€ Ü‰ÑÔØˆŒØ×+Ñ+ˆŒÜ*¨6Ó2ˆŒÜ! &Ó)ˆŒä(¨¯©¸V×=RÑ=RÔSˆÔÜ&1°$·.±.Àf×F[ÑF[Ô&\ˆÕ#r-   rj   rÖ   rZ   rF   rÚ   r"   c                 óÚ   — |}| j                  |«      }| j                  |||||¬«      }|d   }||z   }|}| j                  |«      }| j                  |«      }||z   }|f}|r	||d   fz  }|S )a6  
        Args:
            hidden_states (`torch.FloatTensor` of shape `(batch, seq_len, embed_dim)`):
                input to the layer.
            rotary_pos_emb (`torch.FloatTensor`):
                rotary position embeddings generated by `ClvpRotaryPositionalEmbedding` module.
            attention_mask (`torch.FloatTensor` of shape `(batch, 1, tgt_len, src_len)`):
                attention mask where padding elements are indicated by very large negative values.
            position_ids (`torch.LongTensor`):
                Denotes position ids of the input tokens.
            output_attentions (`bool`, *optional*, defaults to `False`):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        )rj   rÖ   rZ   rF   rÚ   r   r5   )r  r  r  r  )	rŠ   rj   rÖ   rZ   rF   rÚ   ÚresidualÚattention_outputsÚoutputss	            r+   r—   zClvpEncoderLayer.forwardÄ  s¢   € ð, !ˆà×*Ñ*¨=Ó9ˆà ŸN™NØ'Ø)Ø)Ø%Ø/ð +ó 
Ðð *¨!Ñ,ˆà  =Ñ0ˆà ˆØ×3Ñ3°MÓBˆØŸ™ Ó/ˆØ  =Ñ0ˆà Ð"ˆáØÐ)¨"Ñ-Ð/Ñ/ˆGàˆr-   )F)rl   rm   rn   r   r…   r(   rp   r€   r   rÇ   r   r—   rœ   r�   s   @r+   r  r  ¹  s|   ø„ ð]˜zõ ]ð  -2ñ0à×(Ñ(ð0ð ×)Ñ)ð0ð ×(Ñ(ð	0ð
 ×&Ñ&ð0ð $ D™>ð0ð 
ˆu× Ñ Ñ	!÷0r-   r  c                   ób   ‡ — e Zd Zˆ fd„Zdeeej                        dej                  fd„Zˆ xZ	S )ÚClvpDecoderMLPc                 óö   •— t         ‰| �  «        |j                  }t        ||«      | _        t        ||«      | _        t        |j                     | _        t        j                  |j                  «      | _        y r  )r„   r…   r‹   r   Úc_fcÚc_projr   Úactivation_functionÚactr   r
  Úresid_pdroprÄ   )rŠ   rþ   r­   r¾   r�   s       €r+   r…   zClvpDecoderMLP.__init__ù  s_   ø€ Ü‰ÑÔØ×&Ñ&ˆ	ÜÐ,¨iÓ8ˆŒ	Ü˜YÐ(9Ó:ˆŒÜ˜&×4Ñ4Ñ5ˆŒÜ—z‘z &×"4Ñ"4Ó5ˆ�r-   rj   r"   c                 óŽ   — | j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }|S r  )r  r!  r  rÄ   r  s     r+   r—   zClvpDecoderMLP.forward  s@   € ØŸ	™	 -Ó0ˆØŸ™ Ó/ˆØŸ™ MÓ2ˆØŸ™ ]Ó3ˆØÐr-   )
rl   rm   rn   r…   r   r   r(   rp   r—   rœ   r�   s   @r+   r  r  ø  s1   ø„ ô6ð X¨e°E×4EÑ4EÑ.FÑ%Gð ÈE×L]ÑL]÷ r-   r  c                   óT  ‡ — e Zd Zˆ fd„Z	 	 	 	 	 	 ddeeej                        deeej                        deej                     deej                     deej                     dee
   dee
   d	eeej                     eeej                  eej                  d
f   f      f   fd„Zˆ xZS )ÚClvpDecoderLayerc                 óN  •— t         ‰| �  «        |j                  }|j                  �|j                  nd|z  }t	        j
                  ||j                  ¬«      | _        t        |«      | _	        t	        j
                  ||j                  ¬«      | _
        t        ||«      | _        y )Né   r  )r„   r…   r‹   Ún_innerr   Ú	LayerNormÚlayer_norm_epsilonÚinput_layernormr·   ÚattnÚpost_attention_layernormr  r  )rŠ   r­   r‹   Ú	inner_dimr�   s       €r+   r…   zClvpDecoderLayer.__init__
  s}   ø€ Ü‰ÑÔØ×(Ñ(ˆØ&,§n¡nÐ&@�F—N’NÀaÈ+Áoˆ	ä!Ÿ|™|¨K¸V×=VÑ=VÔWˆÔÜ% fÓ-ˆŒ	Ü(*¯©°[Àf×F_ÑF_Ô(`ˆÔ%ä! )¨VÓ4ˆ�r-   rj   r×   rZ   rF   rÙ   rØ   rÚ   r"   .c           	      óò   — |}| j                  |«      }| j                  |||||||¬«      }	|	d   }
|	dd  }|
|z   }|}| j                  |«      }| j                  |«      }||z   }|r|f|z   }|S |f|dd  z   }|S )N©r×   rZ   rF   rÙ   rØ   rÚ   r   r   )r+  r,  r-  r  )rŠ   rj   r×   rZ   rF   rÙ   rØ   rÚ   r  Úattn_outputsrö   r  Úfeed_forward_hidden_statess                r+   r—   zClvpDecoderLayer.forward  sÂ   € ð !ˆØ×,Ñ,¨]Ó;ˆØ—y‘yØØ)Ø)Ø%ØØØ/ð !ó 
ˆð # 1‘oˆØ˜q˜rÐ"ˆà# hÑ.ˆà ˆØ×5Ñ5°mÓDˆØ%)§X¡X¨mÓ%<Ð"à Ð#=Ñ=ˆáØ$Ð&¨Ñ0ˆGð ˆð %Ð&¨°°¨Ñ4ˆGàˆr-   )NNNNFF)rl   rm   rn   r…   r   r   r(   rp   r÷   r€   rÇ   r   r—   rœ   r�   s   @r+   r%  r%  	  sí   ø„ ô	5ð 9=Ø59Ø37Ø15Ø$)Ø,1ñ%à  e×&7Ñ&7Ñ 8Ñ9ð%ð !  u§|¡|Ñ!4Ñ5ð%ð ! ×!1Ñ!1Ñ2ð	%ð
 ˜u×/Ñ/Ñ0ð%ð ˜E×-Ñ-Ñ.ð%ð ˜D‘>ð%ð $ D™>ð%ð 
ˆu�U—\‘\Ñ" H¨U°5·<±<ÀÀu×GXÑGXÐZ]ÐG]ÑA^Ð3^Ñ-_Ñ$`Ð`Ñ	a÷%r-   r%  c            
       ó¼   ‡ — e Zd ZdZdefˆ fd„Zddedefd„Z	 	 	 ddej                  de
ej                     d	e
ej                     d
e
ej                     fd„Zˆ xZS )ÚClvpConditioningEncodera—  
    This class processes the log-mel spectrograms(extracted by the Feature Extractor) and text tokens(produced by the
    tokenizer) as inputs for the decoder model.

    First each log-mel spectrogram is processed into a single vector which captures valuable characteristics from each
    of them, then the text tokens are converted into token embeddings and position embeddings are added afterwards.
    Both of these vectors are concatenated and then passed to the decoder model.

    The text tokens helps to incorporate the "text information" and the log-mel spectrogram is used to specify the
    "voice characteristics" into the generated mel tokens.
    r­   c                 óø  •— t         ‰| �  «        |j                  | _        |j                  | _        t	        j
                  | j                  j                  | j                  j                  «      | _        t	        j
                  | j                  j                  | j                  j                  «      | _
        t	        j                  | j                  j                  | j                  j                  d¬«      | _        | j                  | j                  j                  «      }t	        j                  t!        | j                  j"                  «      D �cg c]/  }t	        j$                  || j                  j                  dd¬«      ‘Œ1 c}«      | _        t	        j                  t!        | j                  j"                  «      D �cg c]  }t)        | j                  «      ‘Œ c}«      | _        d| _        y c c}w c c}w )Nr   )Úkernel_sizegñhãˆµøä>T)rŒ   ÚaffineF)r„   r…   Útext_configÚdecoder_configr   Ú	EmbeddingÚ
vocab_sizer‹   Útext_token_embeddingÚmax_text_tokensÚtext_position_embeddingÚConv1dÚfeature_sizeÚmel_convÚcompute_groupnorm_groupsÚ
ModuleListÚrangeÚnum_mel_attn_blocksÚ	GroupNormÚgroup_normsr·   Úmel_attn_blocksÚgradient_checkpointing)rŠ   r­   Ú
num_groupsrä   r�   s       €r+   r…   z ClvpConditioningEncoder.__init__J  sy  ø€ Ü‰ÑÔà!×-Ñ-ˆÔØ$×3Ñ3ˆÔä$&§L¡L°×1AÑ1A×1LÑ1LÈd×NaÑNa×NmÑNmÓ$nˆÔ!Ü')§|¡|Ø×Ñ×/Ñ/°×1DÑ1D×1PÑ1Pó(
ˆÔ$ô Ÿ	™	 $×"5Ñ"5×"BÑ"BÀD×DWÑDW×DcÑDcÐqrÔsˆŒð ×2Ñ2°4×3FÑ3F×3RÑ3RÓSˆ
ÜŸ=™=ô ˜t×2Ñ2×FÑFÓGöàô —‘˜Z¨×)<Ñ)<×)HÑ)HÈdÐ[_Ö`òó
ˆÔô  "Ÿ}™}Ü=BÀ4×CVÑCV×CjÑCjÓ=kÖl¸Ô˜t×2Ñ2Õ3Òló 
ˆÔð ',ˆÕ#ùòùò ms   Å4G2ÇG7ÚchannelsÚgroupsc                 óŠ   — |dk  rd}n|dk  rd}||z  dk7  rt        |dz  «      }||z  dk7  rŒ|dk  rt        d|› d�«      ‚|S )a  
        Calculates the value of `num_groups` for nn.GroupNorm. This logic is taken from the official tortoise
        repository. link :
        https://github.com/neonbjb/tortoise-tts/blob/4003544b6ff4b68c09856e04d3eff9da26d023c2/tortoise/models/arch_util.py#L26
        é   é   é@   r   r6   zENumber of groups for the GroupNorm must be greater than 2, but it is z0.Please consider using a different `hidden_size`)rø   rÁ   )rŠ   rK  rL  s      r+   rB  z0ClvpConditioningEncoder.compute_groupnorm_groupsg  sx   € ð �rŠ>Ø‰FØ˜Š^ØˆFØ˜Ñ 1Ò$Ü˜ !™“_ˆFð ˜Ñ 1Ó$ð �QŠ;ÜØWÐX^ÐW_ð `Bð Cóð ð
 ˆr-   Úinput_featuresrY   Úinputs_embedsrZ   c                 ó  — |�|�t        d«      ‚|�|j                  «       \  }}n$|�|j                  «       d d \  }}nt        d«      ‚|€2t        j                  ||gt        j                  |j
                  ¬«      }t        ||| j                  j                  | j                  j                  ¬«      \  }}| j                  |«      }|j                  d«      dz
  }| j                  |«      }||z   }	| j                  rù| j                  rít        j                  j                   j!                  | j"                  |«      }
t%        | j&                  «      D ]   \  }}|
j)                  dd«      }t        j                  j                   j!                  | j*                  |   |
«      j)                  dd«      }
t        j                  j                   j!                  ||
«      d   |z   }
|
j)                  dd«      }
Œ¢ n…| j#                  |«      }
t%        | j&                  «      D ]\  \  }}|
j)                  dd«      } | j*                  |   |
«      j)                  dd«      }
 ||
«      d   |z   }
|
j)                  dd«      }
Œ^ |
d d …d d …df   }
|
j-                  d«      }
|	j.                  d   dk(  r3|
j.                  d   dk7  r!|	j1                  |
j.                  d   dd«      }	n�|	j.                  d   dk7  r3|
j.                  d   dk(  r!|
j1                  |	j.                  d   dd«      }
nK|	j.                  d   |
j.                  d   k7  r,t        d	|	j.                  d   › d
|
j.                  d   › d�«      ‚t        j2                  |
|	gd¬«      S )NúDYou cannot specify both input_ids and inputs_embeds at the same timer5   ú5You have to specify either input_ids or inputs_embedsrO   )r\   r]   r   r6   r   z=The number of texts and number of audios must be same. Found z
 texts vs z audiosr7   )rÁ   rß   r(   r‡   Úlongr%   rd   r8  r\   r]   r<  Úcumsumr>  rI  rÞ   ÚutilsÚ
checkpointrA  rS   rH  rÓ   rG  r@   r9   ÚrepeatÚconcat)rŠ   rQ  rY   rR  rZ   Ú
batch_sizeÚ
seq_lengthrF   Úposition_embedsry   Úmel_specra   Úmel_attn_blockÚresidual_mel_specs                 r+   r—   zClvpConditioningEncoder.forward|  sp  € ð Ð  ]Ð%>ÜÐcÓdÐdØÐ"Ø%.§^¡^Ó%5Ñ"ˆJ™
ØÐ&Ø%2×%7Ñ%7Ó%9¸#¸2Ð%>Ñ"ˆJ™
äÐTÓUÐUð Ð!Ü"ŸZ™Z¨°ZÐ(@ÌÏ
É
Ð[d×[kÑ[kÔlˆNô %>ØØØ×)Ñ)×6Ñ6Ø×)Ñ)×6Ñ6ô	%
Ñ!ˆ	�>ð ×1Ñ1°)Ó<ˆØ%×,Ñ,¨RÓ0°1Ñ4ˆØ×6Ñ6°|ÓDˆØ# oÑ5ˆà×&Ò&¨4¯=ª=ä—{‘{×-Ñ-×8Ñ8¸¿¹ÈÓWˆHä%.¨t×/CÑ/CÓ%Dò 4Ñ!��>Ø$,×$6Ñ$6°q¸!Ó$<Ð!ä Ÿ;™;×1Ñ1×<Ñ<¸T×=MÑ=MÈaÑ=PÐRZÓ[×eÑeÐfgÐijÓk�Ü Ÿ;™;×1Ñ1×<Ñ<¸^ÈXÓVÐWXÑYÐ\mÑm�Ø#×-Ñ-¨a°Ó3‘ñ4ð —}‘} ^Ó4ˆHä%.¨t×/CÑ/CÓ%Dò 4Ñ!��>Ø$,×$6Ñ$6°q¸!Ó$<Ð!à.˜4×+Ñ+¨AÑ.¨xÓ8×BÑBÀ1ÀaÓH�Ù)¨(Ó3°AÑ6Ð9JÑJ�Ø#×-Ñ-¨a°Ó3‘ð4ð šAšq !˜GÑ$ˆØ×%Ñ% aÓ(ˆð ×Ñ˜QÑ 1Ò$¨¯©¸Ñ):¸aÒ)?Ø%×,Ñ,¨X¯^©^¸AÑ->ÀÀ1ÓE‰KØ×Ñ˜qÑ! QÒ&¨8¯>©>¸!Ñ+<ÀÒ+AØ—‘ {×'8Ñ'8¸Ñ';¸QÀÓB‰Hà×Ñ˜qÑ! X§^¡^°AÑ%6Ò6ÜðØ$×*Ñ*¨1Ñ-Ð.¨j¸¿¹ÈÑ9JÐ8KÈ7ðTóð ô
 �|‰|˜X {Ð3¸Ô;Ð;r-   )r¡   ©NNN)rl   rm   rn   ro   r   r…   rø   rB  r(   rp   r   r€   r—   rœ   r�   s   @r+   r4  r4  =  s‰   ø„ ñ
ð,˜zõ ,ñ:°ð ¸có ð0 15Ø59Ø59ñH<à×)Ñ)ðH<ð ˜E×,Ñ,Ñ-ðH<ð   × 1Ñ 1Ñ2ð	H<ð
 ! ×!1Ñ!1Ñ2÷H<r-   r4  c                   ó&   — e Zd ZdZeZdZdZdZd„ Z	y)ÚClvpPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚclvpTÚpast_key_valuesc           	      óÆ  — | j                   j                  }t        |t        j                  «      r,|j
                  j                  j                  d|dz  ¬«       �n!t        |t        j                  t        t        j                  f«      r]|j
                  j                  j                  d|dz  ¬«       |j                  ��»|j                  j                  j                  «        �n•t        |t        «      �r| j                   j                  }|j                   j                  dz  d|j                   j                  z  dz  z  |z  }d|j                   j                  z  dz  |z  }t        j                   j                  t#        |j$                  d«      r |j$                  j&                  j
                  n|j$                  j
                  |¬«       t        j                   j                  |j(                  j
                  |¬«       �ntt        |t*        «      rh| j                   j-                  «       }|j                  }|j.                  j
                  j                  j                  d||j                  dz  z  ¬«       nüt        |t0        «      r`|j2                  j
                  j                  j                  d|¬«       |j2                  j                  j                  j                  «        nŒt        |t4        «      r||j7                  «       D ]i  \  }}|d	k(  sŒ|j                  j                  d| j                   j8                  t;        j<                  d| j                   j                  z  «      z  ¬«       Œk t        |t        j>                  «      rJ|j                  j                  j                  «        |j
                  j                  jA                  d
«       yy)zInitialize the weightsg        g{®Gáz”?)r“   ÚstdNr¹   r6   rÿ   )rh  zc_proj.weightr¢   )!r­   Úinitializer_factorÚ
isinstancer   r:  rˆ   ÚdataÚnormal_rÉ   r   r?  r»   Úzero_r  r‹   Únum_hidden_layersÚinitÚgetattrr  rÿ   r	  ÚClvpEncoderÚget_text_configÚ
projectionr4  rA  ÚClvpForCausalLMÚnamed_parametersÚinitializer_rangeÚmathÚsqrtr)  Úfill_)rŠ   ÚmoduleÚfactorÚin_proj_stdÚfc_stdr­   ÚnamerÝ   s           r+   Ú_init_weightsz!ClvpPreTrainedModel._init_weightsÒ  s¿  € à—‘×/Ñ/ˆÜ�fœbŸl™lÔ+Ø�M‰M×Ñ×&Ñ&¨C°V¸d±]Ð&ÖCÜ˜¤§¡¬F´B·I±IÐ >Ô?Ø�M‰M×Ñ×&Ñ&¨C°V¸d±]Ð&ÔCØ�{‰{Ñ&Ø—‘× Ñ ×&Ñ&Ö(Ü˜¤Õ/Ø—[‘[×3Ñ3ˆFØ!Ÿ=™=×4Ñ4°dÑ:ÀÀFÇMÁM×DcÑDcÑ@cÐhlÑ?lÑmÐpvÑvˆKØ˜&Ÿ-™-×3Ñ3Ñ3¸Ñ<¸vÑEˆFÜ�G‰G�O‰O´g¸f¿j¹jÈ&Ô6Q˜FŸJ™JŸO™O×2Ò2ÐW]×WaÑWa×WhÑWhÐntˆOÔuÜ�G‰G�O‰O˜FŸJ™J×-Ñ-°;ˆOÖ?Ü˜¤Ô,Ø—[‘[×0Ñ0Ó2ˆFØ×.Ñ.ˆFØ×Ñ×$Ñ$×)Ñ)×1Ñ1°sÀÈ&×J\ÑJ\Ð^bÑJbÑ@cÐ1ÕdÜ˜Ô 7Ô8Ø�O‰O×"Ñ"×'Ñ'×/Ñ/°S¸fÐ/ÔEØ�O‰O× Ñ ×%Ñ%×+Ñ+Õ-Ü˜¤Ô0Ø!×2Ñ2Ó4ò ‘��aØ˜?Ó*Ø—F‘F—N‘NØ  t§{¡{×'DÑ'DÄtÇyÁyÐQRÐUY×U`ÑU`×UrÑUrÑQrÓGsÑ'sð #õ ðô
 �fœbŸl™lÔ+Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)ð ,r-   N)
rl   rm   rn   ro   r   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_skip_keys_device_placementr  rr   r-   r+   rd  rd  Ç  s%   „ ñð
 €LØÐØ&*Ð#Ø"3Ðó*r-   rd  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 ([`ClvpConfig`]): 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:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
            it.

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

            [What are input IDs?](../glossary#input-ids)
        input_features (`torch.FloatTensor` of shape `(batch_size, feature_size, time_dim)`):
            Indicates log mel-spectrogram representations for audio returned by [`ClvpFeatureExtractor`].
        conditioning_encoder_inputs_embeds (`torch.FloatTensor`, *optional*):
            inputs_embeds for `ClvpConditioningEncoder`. Can be used in place of `input_ids`.
        text_encoder_inputs_embeds (`torch.FloatTensor`, *optional*):
            inputs_embeds for the text encoder model passed in place of `input_ids`.
        attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding text 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)
        return_loss (`bool`, *optional*):
            Whether or not to return the contrastive loss.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
a¶  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
            Indices of input sequence tokens in the vocabulary.

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

            [What are input IDs?](../glossary#input-ids)
        past_key_values (`Tuple[Tuple[torch.Tensor]]` of length `config.n_layers`):
            Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see
            `past_key_values` output below). Can be used to speed up sequential decoding. The `input_ids` which have
            their past given to this model should not be passed as `input_ids` as they have already been computed.
        attention_mask (`torch.FloatTensor` 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**.

            If `past_key_values` is used, `attention_mask` needs to contain the masking strategy that was used for
            `past_key_values`. In other words, the `attention_mask` always has to have the length:
            `len(past_key_values) + len(input_ids)`

            [What are attention masks?](../glossary#attention-mask)
        token_type_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`, *optional*):
            Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
            1]`:

            - 0 corresponds to a *sentence A* token,
            - 1 corresponds to a *sentence B* token.

            [What are token type IDs?](../glossary#token-type-ids)
        position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.max_position_embeddings - 1]`.

            [What are position IDs?](../glossary#position-ids)
        head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
            Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

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

        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.

            If `past_key_values` is used, optionally only the last `inputs_embeds` have to be input (see
            `past_key_values`).
        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.
c                   óð   ‡ — 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   dee   dee   deeef   fd„Zˆ xZS )rq  z­
    Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
    [`ClvpEncoderLayer`].

    Args:
        config: ClvpConfig
    r­   c                 ón  •— t         ‰| �  |«       || _        t        j                  |j
                  |j                  «      | _        |j                  rt        |«      nd | _
        t        j                  t        |j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _        t!        |«      | _        t        j$                  |j                  |j&                  ¬«      | _        t        j*                  |j                  |j,                  d¬«      | _        d| _        | j3                  «        y c c}w )Nr  Fr½   )r„   r…   r­   r   r:  r;  r‹   Útoken_embeddingÚuse_rotary_embeddingrŸ   rÖ   rC  rD  rn  r  Úlayersr   Úsequence_summaryr)  r  Úfinal_layer_normrÉ   r¦   rs  rI  Ú	post_init©rŠ   r­   rä   r�   s      €r+   r…   zClvpEncoder.__init__p  sà   ø€ Ü‰Ñ˜Ô àˆŒÜ!Ÿ|™|¨F×,=Ñ,=¸v×?QÑ?QÓRˆÔØGM×GbÒGbÔ;¸FÔCÐhlˆÔÜ—m‘mÄuÈV×MeÑMeÓGfÖ$gÀ!Ô%5°fÕ%=Ò$gÓhˆŒä /°Ó 7ˆÔÜ "§¡¨V×-?Ñ-?ÀV×EZÑEZÔ [ˆÔäŸ)™) F×$6Ñ$6¸×8MÑ8MÐTYÔZˆŒà&+ˆÔ#à�‰Õùò %hs   ÂD2c                 ó   — | j                   S r  ©r†  rš   s    r+   Úget_input_embeddingsz ClvpEncoder.get_input_embeddings�  s   € Ø×#Ñ#Ð#r-   c                 ó   — || _         y r  rŽ  ©rŠ   rN   s     r+   Úset_input_embeddingsz ClvpEncoder.set_input_embeddings„  s
   € Ø$ˆÕr-   rY   rR  rZ   rF   rÚ   Úoutput_hidden_statesÚreturn_dictr"   c                 ó¼  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|�|�t	        d«      ‚|�I| j                  ||«       |j                  «       }|j                  d|d   «      }| j                  |«      }n!|�|j                  «       dd }nt	        d«      ‚|�t        ||j                  «      }|€T|�|j                  n|j                  }	t        j                  |d   t        j                  |	¬«      }|j                  d«      }|rdnd}
|rdnd}| j                   �| j!                  |«      nd}|}t#        | j$                  «      D ]{  \  }}|r|
|fz   }
| j&                  rD| j(                  r8t        j*                  j,                  j-                  |j.                  ||||«      }n ||||||¬	«      }|d   }|sŒs||d   fz   }Œ} |r|
|fz   }
|}| j1                  |«      }| j3                  |«      }| j5                  |«      }|st7        d
„ ||||
|fD «       «      S t9        ||||
|¬«      S )a­  
        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`, *optional*):
                Indices of input sequence tokens in the vocabulary.

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

                [What are input IDs?](../glossary#input-ids)
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                input embeddings for the model. This bypasses the model's internal embedding lookup matrix.
            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)
            position_ids (`torch.LongTensor`, *optional*):
                Denotes the position ids of `input_ids`.
            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.
        NrT  r5   rU  r   rO   r   rr   )rÚ   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wr  rr   ©Ú.0rC   s     r+   ú	<genexpr>z&ClvpEncoder.forward.<locals>.<genexpr>ö  s   è ø€ ò ØÐijÑiv”ñùs   ‚Š)rg   rh   ri   rj   rk   )r­   rÚ   r“  Úuse_return_dictrÁ   Ú%warn_if_padding_and_no_attention_maskrß   rÈ   r†  r   rP   r%   r(   r)   rV  r@   rÖ   rS   rˆ  rI  rÞ   rX  rY  Ú__call__rŠ  r‰  rs  r™   rf   )rŠ   rY   rR  rZ   rF   rÚ   r“  r”  Úinput_shaper%   Úencoder_statesÚall_attentionsrÖ   rj   ÚidxÚencoder_layerÚlayer_outputsrh   Úpooled_outputrg   s                       r+   r—   zClvpEncoder.forward‡  s­  € ðN 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ  ]Ð%>ÜÐcÓdÐdØÐ"Ø×6Ñ6°yÀ.ÔQØ#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;ˆIØ ×0Ñ0°Ó;‰MØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐTÓUÐUð Ð%ä7¸È×H[ÑH[Ó\ˆNàÐØ)2Ð)>�Y×%Ò%ÀM×DXÑDXˆFÜ Ÿ<™<¨°A©¼e¿j¹jÐQWÔXˆLØ'×1Ñ1°!Ó4ˆLá3™¸ˆÙ0™°dˆà?C×?RÑ?RÐ?^˜×,Ñ,¨]Ô;Ðdhˆà%ˆÜ"+¨D¯K©KÓ"8ò 	FÑˆC�Ù#Ø!/°=Ð2BÑ!B�Ø×*Ò*¨t¯}ª}Ü %§¡× 6Ñ 6× AÑ AØ!×*Ñ*Ø!Ø"Ø"Ø ó!‘ñ !.Ø!Ø"Ø"Ø Ø&7ô!�ð *¨!Ñ,ˆMâ Ø!/°=ÀÑ3CÐ2EÑ!E‘ð/	Fñ2  Ø+¨}Ð.>Ñ>ˆNà)ÐØ ×1Ñ1Ð2CÓDÐð ×-Ñ-Ð.?Ó@ˆð —‘ Ó/ˆáÜñ Ø"Ð$5°}ÀnÐVdÐeôó ð ô !ØØ/Ø'Ø(Ø%ô
ð 	
r-   )NNNNNNN)rl   rm   rn   ro   r   r…   r�  r’  r   r(   r€   rÇ   r   r   r   r—   rœ   r�   s   @r+   rq  rq  g  sÓ   ø„ ñð˜zõ ò"$ò%ð
 15Ø48Ø59Ø37Ø,0Ø/3Ø&*ñy
à˜E×,Ñ,Ñ-ðy
ð   × 0Ñ 0Ñ1ðy
ð ! ×!1Ñ!1Ñ2ð	y
ð
 ˜u×/Ñ/Ñ0ðy
ð $ D™>ðy
ð ' t™nðy
ð ˜d‘^ðy
ð 
ˆu�oÐ%Ñ	&÷y
r-   rq  c                   ó~  ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Z 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eej                           d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 )ÚClvpDecoderzs
    Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`ClvpDecoderLayer`]
    c                 ó
  •— t         ‰| �  |«       || _        t        j                  | j                  j
                  | j                  j                  «      | _        t        j                  | j                  j                  | j                  j                  «      | _	        t        j                  | j                  j                  «      | _        t        j                  t        | j                  j                  «      D �cg c]  }t!        | j                  «      ‘Œ c}«      | _        t        j$                  | j                  j                  | j                  j&                  ¬«      | _        d| _        | j-                  «        y c c}w )Nr  F)r„   r…   r­   r   r:  r;  r‹   Úinput_embeds_layerrº   Úposition_embeds_layerr
  Ú
embd_pdropÚdroprC  rD  rn  r%  rˆ  r)  r*  Ú
layer_normrI  r‹  rŒ  s      €r+   r…   zClvpDecoder.__init__  sù   ø€ Ü‰Ñ˜Ô àˆŒä"$§,¡,¨t¯{©{×/EÑ/EÀtÇ{Á{×G^ÑG^Ó"_ˆÔÜ%'§\¡\°$·+±+×2UÑ2UÐW[×WbÑWb×WnÑWnÓ%oˆÔ"ä—J‘J˜tŸ{™{×5Ñ5Ó6ˆŒ	Ü—m‘mÌEÐRV×R]ÑR]×RoÑRoÓLpÖ$qÀqÔ%5°d·k±kÕ%BÒ$qÓrˆŒÜŸ,™, t§{¡{×'>Ñ'>ÀDÇKÁK×DbÑDbÔcˆŒà&+ˆÔ#ð 	�‰Õùò %rs   Ã<F c                 ó   — | j                   S r  ©r§  rš   s    r+   r�  z ClvpDecoder.get_input_embeddings  s   € Ø×&Ñ&Ð&r-   c                 ó   — || _         y r  r­  ©rŠ   Únew_embeddingss     r+   r’  z ClvpDecoder.set_input_embeddings  s
   € Ø"0ˆÕr-   c                 ó„   — |j                  «       D ]-  \  }}| j                  |   j                  j                  |«       Œ/ y)zv
        Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer}
        N)Úitemsrˆ  r,  Úprune_heads)rŠ   Úheads_to_pruneÚlayerÚheadss       r+   Ú_prune_headszClvpDecoder._prune_heads  s=   € ð +×0Ñ0Ó2ò 	7‰LˆE�5Ø�K‰K˜Ñ×#Ñ#×/Ñ/°Õ6ñ	7r-   rY   rZ   Útoken_type_idsrF   rÙ   rf  rR  rØ   rÚ   r“  r”  r"   c           
      óÌ  — |	�|	n| j                   j                  }	|
�|
n| j                   j                  }
|�|n| j                   j                  }|�|n| j                   j                  }|�|�t        d«      ‚|�G| j                  ||«       |j                  «       }|j                  d|d   «      }|j                  d    n0|�#|j                  «       d d }|j                  d    nt        d«      ‚|�|j                  n|j                  }|�|j                  d|d   «      }|€%d}t        d gt        | j                  «      z  «      }n|d   d   j                  d«      }|€Qt        j                  ||d   |z   t        j                   |¬«      }|j#                  d«      j                  d|d   «      }|€| j%                  |«      }| j'                  |«      }||z   }t)        ||||«      }| j+                  || j                   j,                  «      }|}|�| j%                  |«      }||z   }| j/                  |«      }d|dd  z   |j                  d«      fz   }| j0                  r%| j2                  r|rt4        j7                  d	«       d
}|rdnd }|	rdnd }|	r| j                   j8                  rdnd }|
rdnd }t;        t=        | j                  |«      «      D ]¼  \  }\  }}|
r||fz   }| j0                  rH| j2                  r<t        j>                  j@                  jA                  |jB                  |d ||||   «      }n |||||||   ||	¬«      }|d   }|du r	||d   fz   }|	sŒŒ|||rdnd   fz   }| j                   j8                  sŒ°|||rdnd   fz   }Œ¾ | jE                  |«      }|j                  |«      }|
r||fz   }|st        d„ |||||fD «       «      S tG        |||||¬«      S )NrT  r5   r   rU  rÜ   rO   )r5   r   zZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Frr   r0  Tr6   r
   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr  rr   r—  s     r+   r™  z&ClvpDecoder.forward.<locals>.<genexpr>§  s   è ø€ ò àØ�=ô ñùs   ‚©rh   rf  rj   rk   Úcross_attentions)$r­   rÚ   r“  rØ   rš  rÁ   r›  rß   rÈ   r9   r%   r™   r*   rˆ  r(   r)   rV  r@   r§  r¨  r   Úget_head_maskrn  rª  rI  rÞ   ÚloggerÚwarning_onceÚadd_cross_attentionrS   ÚziprX  rY  rœ  r«  r   )rŠ   rY   rZ   r¸  rF   rÙ   rf  rR  rØ   rÚ   r“  r”  r�  r%   Úpast_key_values_lengthr^  rj   Útoken_type_embedsÚoutput_shapeÚpresentsÚall_self_attentionsÚall_cross_attentionsÚall_hidden_statesra   Úblockr×   r  s                              r+   r—   zClvpDecoder.forward&  sZ  € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ  ]Ð%>ÜÐcÓdÐdØÐ"Ø×6Ñ6°yÀ.ÔQØ#Ÿ.™.Ó*ˆKØ!Ÿ™ r¨;°r©?Ó;ˆIØ�O‰O˜AÓØÐ&Ø'×,Ñ,Ó.¨s°Ð3ˆKØ×Ñ Ó"äÐTÓUÐUà%.Ð%:�×!Ò!À×@TÑ@TˆàÐ%Ø+×0Ñ0°°[À±_ÓEˆNàÐ"Ø%&Ð"Ü# T F¬S°·±Ó-=Ñ$=Ó>‰Oà%4°QÑ%7¸Ñ%:×%?Ñ%?ÀÓ%CÐ"ØÐÜ Ÿ<™<Ø&¨°B©Ð:PÑ(PÔX]×XbÑXbÐkqôˆLð (×1Ñ1°!Ó4×9Ñ9¸"¸kÈ"¹oÓNˆLàÐ Ø ×3Ñ3°IÓ>ˆMØ×4Ñ4°\ÓBˆØ%¨Ñ7ˆä:Ø˜K¨Ð8Nó
ˆð ×&Ñ& y°$·+±+×2OÑ2OÓPˆ	à%ˆàÐ%Ø $× 7Ñ 7¸Ó GÐØ)Ð,=Ñ=ˆMàŸ	™	 -Ó0ˆà˜{¨1¨2˜Ñ.°-×2DÑ2DÀRÓ2HÐ1JÑJˆà×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øpôð "�	á"‘2¨ˆÙ$5™b¸4ÐÙ%6¸4¿;¹;×;ZÒ;Z™rÐ`dÐÙ"6™B¸DÐÜ*3´C¸¿¹À_Ó4UÓ*Vò 	dÑ&ˆAÑ&��~Ù#Ø$5¸Ð8HÑ$HÐ!à×*Ò*¨t¯}ª}ÜŸ+™+×0Ñ0×;Ñ;Ø—N‘NØ!ØØ"Ø Ø˜a‘Ló‘ñ  Ø!Ø#1Ø#1Ø!-Ø'¨™lØ'Ø&7ô�ð $ A™JˆMØ˜DÑ Ø# w¨q¡z mÑ3�â Ø&9¸WÉ)ÁQÐYZÑ=[Ð<]Ñ&]Ð#Ø—;‘;×2Ó2Ø+?À7ÑPYÉ1Ð_`ÑCaÐBcÑ+cÑ(ð?	dðB Ÿ™¨Ó6ˆà%×*Ñ*¨<Ó8ˆñ  Ø 1°]Ð4DÑ DÐáÜñ à'¨Ð3DÐFYÐ[oÐpôó ð ô 9Ø+Ø$Ø+Ø*Ø1ô
ð 	
r-   ©NNNNNNNNNNN)rl   rm   rn   ro   r…   r�  r’  r·  r   ÚCLVP_DECODER_INPUTS_DOCSTRINGr   r(   r€   rp   r   r÷   rÇ   r   r   r—   rœ   r�   s   @r+   r¥  r¥    sN  ø„ ñôò"'ò1ò7ñ +Ð+HÓIð 15Ø6:Ø59Ø37Ø15Ø@DØ59Ø$(Ø,0Ø/3Ø&*ñL
à˜E×,Ñ,Ñ-ðL
ð ! ×!2Ñ!2Ñ3ðL
ð ! ×!1Ñ!1Ñ2ð	L
ð
 ˜u×/Ñ/Ñ0ðL
ð ˜E×-Ñ-Ñ.ðL
ð " %¨¨e¯l©lÑ(;Ñ"<Ñ=ðL
ð   × 1Ñ 1Ñ2ðL
ð ˜D‘>ðL
ð $ D™>ðL
ð ' t™nðL
ð ˜d‘^ðL
ð 
ˆuÐ?Ð?Ñ	@òL
ó JôL
r-   r¥  zZThe bare Clvp decoder model outputting raw hidden-states without any specific head on top.c                   ó€  ‡ — e Zd Zdefˆ fd„Zd„ Zd„ Zd„ Z 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eej                           d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 )Ú	ClvpModelr­   c                 ó†   •— t         ‰| �  |«       || _        t        | j                  «      | _        | j                  «        y r  )r„   r…   r­   r¥  Údecoderr‹  r   s     €r+   r…   zClvpModel.__init__»  s3   ø€ Ü‰Ñ˜Ô ØˆŒÜ" 4§;¡;Ó/ˆŒð 	�‰Õr-   c                 ó.   — | j                   j                  S r  ©rÏ  r§  rš   s    r+   r�  zClvpModel.get_input_embeddingsÃ  s   € Ø�|‰|×.Ñ.Ð.r-   c                 ó&   — || j                   _        y r  rÑ  r‘  s     r+   r’  zClvpModel.set_input_embeddingsÆ  s   € Ø*/ˆ�‰Õ'r-   c                 ó   — | j                   S r  )rÏ  rš   s    r+   Úget_decoderzClvpModel.get_decoderÉ  s   € Ø�|‰|Ðr-   rY   rZ   r¸  rF   rÙ   rf  rR  rØ   rÚ   r“  r”  r"   c                 ó–  — |	�|	n| j                   j                  }	|
�|
n| j                   j                  }
|�|n| j                   j                  }|�|n| j                   j                  }| j                  |||||||||	|
|¬«      }|s|S t        |j                  |j                  |j                  |j                  |j                  ¬«      S )N)rY   rZ   r¸  rF   rÙ   rf  rR  rØ   rÚ   r“  r”  r»  )r­   rÚ   r“  rØ   rš  rÏ  r   rh   rf  rj   rk   r¼  )rŠ   rY   rZ   r¸  rF   rÙ   rf  rR  rØ   rÚ   r“  r”  Údecoder_outputss                r+   r—   zClvpModel.forwardÌ  sã   € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ÿ,™,ØØ)Ø)Ø%ØØ+Ø'ØØ/Ø!5Ø#ð 'ó 
ˆñ Ø"Ð"ä8Ø-×?Ñ?Ø+×;Ñ;Ø)×7Ñ7Ø&×1Ñ1Ø,×=Ñ=ô
ð 	
r-   rÊ  )rl   rm   rn   r   r…   r�  r’  rÔ  r   rË  r   r(   r€   rp   r   r÷   rÇ   r   r   r—   rœ   r�   s   @r+   rÍ  rÍ  ¶  sC  ø„ ð
Ð0õ ò/ò0òñ +Ð+HÓIð 15Ø6:Ø59Ø37Ø15Ø@DØ59Ø$(Ø,0Ø/3Ø&*ñ-
à˜E×,Ñ,Ñ-ð-
ð ! ×!2Ñ!2Ñ3ð-
ð ! ×!1Ñ!1Ñ2ð	-
ð
 ˜u×/Ñ/Ñ0ð-
ð ˜E×-Ñ-Ñ.ð-
ð " %¨¨e¯l©lÑ(;Ñ"<Ñ=ð-
ð   × 1Ñ 1Ñ2ð-
ð ˜D‘>ð-
ð $ D™>ð-
ð ' t™nð-
ð ˜d‘^ð-
ð 
ˆuÐ?Ð?Ñ	@ò-
ó Jô-
r-   rÍ  z=The CLVP decoder model with a language modelling head on top.c                   ó¸  ‡ — e Zd Zˆ fd„Zd„ Zd„ Z	 	 	 ddeej                     dee	   dee
eej                  f      deej                  ee   e
eej                  f   f   fd„Z	 dd	„Z ee«      	 	 	 	 	 	 	 	 	 	 	 	 dd
eej"                     dee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   dee   dee   dee   deeef   fd„«       Zedeeej                        dej                  deeej                        fd„«       Zˆ xZS )rt  c                 ól  •— t         ‰| �  |«       || _        t        | j                  «      | _        t        j                  | j                  j                  «      | _        t        j                  | j                  j                  | j                  j                  d¬«      | _        | j                  «        y )NTr½   )r„   r…   r­   rÍ  Úmodelr   r)  r‹   Ú
final_normrÉ   r;  Úlm_headr‹  r   s     €r+   r…   zClvpForCausalLM.__init__  sv   ø€ Ü‰Ñ˜Ô àˆŒÜ˜tŸ{™{Ó+ˆŒ
äŸ,™, t§{¡{×'>Ñ'>Ó?ˆŒÜ—y‘y §¡×!8Ñ!8¸$¿+¹+×:PÑ:PÐW[Ô\ˆŒð 	�‰Õr-   c                 óB   — | j                   j                  j                  S r  ©rÙ  rÏ  r§  rš   s    r+   r�  z$ClvpForCausalLM.get_input_embeddings  s   € Ø�z‰z×!Ñ!×4Ñ4Ð4r-   c                 ó:   — || j                   j                  _        y r  rÝ  r¯  s     r+   r’  z$ClvpForCausalLM.set_input_embeddings  s   € Ø0>ˆ�
‰
×ÑÕ-r-   Úinputsr\   Úmodel_kwargsr"   c                 óˆ  — | j                   }|j                  «       D ��ci c]  \  }}|€Œ	||“Œ }}}|j                  |d«      }|�|�t        d|› d|› d|› d|› d�	«      ‚|�|}|dk(  r"d|v r| j	                  |||¬	«      |d<   |d   d}}|j                  d
d«      }|��| j                  j                  j                  t        j                  |j                  d   df| j                  j                  |j                  ¬«      «      }	|	| j                  j                  j                  t        j                  |j                  d   dfd|j                  ¬«      «      z  }	t        j                   ||	gd¬«      }t#        |d«      r&|d   j%                  «       j'                  d«      dz
  }
n>t        j(                  d|j                  d   t        j$                  |j                  ¬«      }
|
j+                  d«      j-                  |j                  d   d«      }
|| j                  j                  j                  |
«      z
  |d<   t        j.                  |d   j                  d   dft        j$                  | j                  ¬«      | j                  j                  z  |d<   |d   d|fS | j	                  |||«      }|||fS c c}}w )zT
        This function extracts the model-specific `inputs` for generation.
        Nz
`inputs`: z` were passed alongside z/ which is not allowed.Make sure to either pass z or z=...rY   rR  )rà  Úconditioning_embedsr   r   )Ú
fill_valuer%   r7   rZ   r5   rO   )Úmain_input_namer²  ÚpoprÁ   Ú*_maybe_initialize_input_ids_for_generationÚgetrÙ  rÏ  r§  r(   Úfullr9   r­   r\   r%   r¨  r[  rÅ   rV  rW  r)   r@   rZ  r‡   )rŠ   rß  r\   rà  Ú
input_namerB   rC   Úinputs_kwargrâ  Úmel_start_token_embeddingrF   s              r+   Ú_prepare_model_inputsz%ClvpForCausalLM._prepare_model_inputs  së  € ð ×)Ñ)ˆ
à)5×);Ñ);Ó)=×O¡  AÀÁ˜˜1™ÐOˆÑOà#×'Ñ'¨
°DÓ9ˆØÐ#¨Ð(:ÜØ˜V˜HÐ$<¸Z¸Lð I,Ø,2¨8°4¸
°|À4ðIóð ð Ð%Ø!ˆFà˜Ò$¨¸LÑ)HØ(,×(WÑ(WØ˜°<ð )Xó )ˆL˜Ñ%ð ".¨oÑ!>À�JˆFð +×.Ñ.Ð/DÀdÓKÐàÑ*Ø(,¯
©
×(:Ñ(:×(MÑ(MÜ—
‘
Ø(×.Ñ.¨qÑ1°1Ð5Ø#Ÿ{™{×7Ñ7Ø.×5Ñ5ôó)Ð%ð &¨¯©×);Ñ);×)QÑ)QÜ—
‘
Ð/×5Ñ5°aÑ8¸!Ð<ÈÐSf×SmÑSmÔnó*ñ Ð%ô #(§,¡,Ð0CÐE^Ð/_ÐefÔ"gÐô �|Ð%5Ô6Ø+Ð,<Ñ=×BÑBÓD×KÑKÈBÓOÐRSÑS‘ä$Ÿ|™|ØÐ*×0Ñ0°Ñ3¼5¿:¹:ÐNa×NhÑNhô �ð (×1Ñ1°!Ó4×;Ñ;Ð<O×<UÑ<UÐVWÑ<XÐZ[Ó\ˆLà,?À$Ç*Á*×BTÑBT×BjÑBjØóCñ -ˆL˜Ñ)ô —
‘
˜L¨Ñ9×?Ñ?ÀÑBÀAÐFÌeÏjÉjÐae×alÑalÔmØ—+‘+×*Ñ*ñ+ð ˜Ñ%ð
   Ñ0°/À<ÐOÐOà×@Ñ@ÀÈÐWcÓdˆØ�z <Ð/Ð/ùóm Ps
    
J>«J>c                 óÖ  — |j                   d   }|j                  dd «      }|rb|d   d   j                   d   }|j                   d   |kD  r|}	n|j                   d   dz
  }	|d d …|	d …f   }|�|d d …|j                   d    d …f   }|j                  dd «      }
|j                  dd «      }|
�T|€R|
j                  «       j                  d«      dz
  }|j	                  |
dk(  d«       |r|d d …df   j                  d«      }nd }|�3|�1t        j                  |gt        j                  |j                  ¬«      }|�|€d	|i}nd
|i}|j                  ||j                  d«      ||dœ«       |S )Nr5   r¸  r   r6   r   rZ   rF   rO   rR  rY   rØ   )rf  rØ   rF   r¸  )
r9   rç  rV  rW  Úmasked_fill_r@   r(   rX   r%   Úupdate)rŠ   rY   rf  rR  râ  ÚkwargsÚinput_ids_lengthr¸  Úpast_lengthÚremove_prefix_lengthrZ   rF   Úmodel_inputss                r+   Úprepare_inputs_for_generationz-ClvpForCausalLM.prepare_inputs_for_generationW  s¤  € ð
 %Ÿ?™?¨2Ñ.ÐØŸ™Ð$4°dÓ;ˆáØ)¨!Ñ,¨QÑ/×5Ñ5°aÑ8ˆKð �‰˜qÑ! KÒ/Ø'2Ñ$ð (1§¡°qÑ'9¸AÑ'=Ð$à!¢!Ð%9Ñ%:Ð":Ñ;ˆIØÐ)Ø!/²°I·O±OÀAÑ4FÐ3FÑ3HÐ0HÑ!I�àŸ™Ð$4°dÓ;ˆØ—z‘z .°$Ó7ˆàÐ%¨,Ð*>à)×.Ñ.Ó0×7Ñ7¸Ó;¸aÑ?ˆLØ×%Ñ% n¸Ñ&9¸1Ô=ÙØ+ªA¨r¨EÑ2×<Ñ<¸RÓ@‘àˆLàÐ*¨Ð/JÜ Ÿ<™<Ð)9Ð(:Ä%Ç*Á*ÐU^×UeÑUeÔfˆLð Ð$¨Ð)@Ø+¨]Ð;‰Là'¨Ð3ˆLà×Ñà#2Ø#ŸZ™Z¨Ó4Ø ,Ø"0ñ	ô	
ð Ðr-   rY   rf  rZ   r¸  rF   rÙ   rR  ÚlabelsrØ   rÚ   r“  r”  c                 ó  — |
�|
n| j                   j                  }
|�|n| j                   j                  }|	�|	n| j                   j                  }	|�|n| j                   j                  }| j                  ||||||||	|
||¬«      }|d   }| j                  |«      }| j                  |«      }d}|��|j                  |j                  «      }|ddd…dd…f   j                  «       }|ddd…f   j                  «       }t        «       } ||j                  d|j                  d«      «      |j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                   |j"                  |j$                  ¬«      S )a³  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
            `labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
            are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
        N)rY   rf  rZ   r¸  rF   rÙ   rR  rØ   rÚ   r“  r”  r   .r5   r   )ru   r!   rf  rj   rk   r¼  )r­   rÚ   r“  rØ   rš  rÙ  rÚ  rÛ  r�   r%   rÔ   r	   rÈ   rß   r   rf  rj   rk   r¼  )rŠ   rY   rf  rZ   r¸  rF   rÙ   rR  rö  rØ   rÚ   r“  r”  r  rj   Ú	lm_logitsru   Úshift_logitsÚshift_labelsÚloss_fctÚoutputs                        r+   r—   zClvpForCausalLM.forwardŒ  s²  € ð. 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—*‘*ØØ+Ø)Ø)Ø%ØØ'ØØ/Ø!5Ø#ð ó 
ˆð   ™
ˆà—O‘O MÓ2ˆ	Ø—L‘L Ó+ˆ	àˆØÐØ—Y‘Y˜y×/Ñ/Ó0ˆFà$ S¨#¨2¨#ªq [Ñ1×<Ñ<Ó>ˆLØ! # q¡r '™?×5Ñ5Ó7ˆLä'Ó)ˆHÙ˜L×-Ñ-¨b°,×2CÑ2CÀBÓ2GÓHÈ,×J[ÑJ[Ð\^ÓJ_Ó`ˆDáØ�\ G¨A¨B KÑ/ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä0ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô
ð 	
r-   Úbeam_idxc                 ó,   ‡— t        ˆfd„| D «       «      S )a  
        This function is used to re-order the `past_key_values` cache if [`~PreTrainedModel.beam_search`] or
        [`~PreTrainedModel.beam_sample`] is called. This is required to match `past_key_values` with the correct
        beam_idx at every generation step.
        c              3   óF   •K  — | ]  }t        ˆfd „|D «       «      –— Œ y­w)c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­w)r   N)Úindex_selectr�   r%   )r˜  Ú
past_staterý  s     €r+   r™  z;ClvpForCausalLM._reorder_cache.<locals>.<genexpr>.<genexpr>ß  s.   øè ø€ ÒjÐQ[�*×)Ñ)¨!¨X¯[©[¸×9JÑ9JÓ-K×LÑjùs   ƒ58N©r™   )r˜  Ú
layer_pastrý  s     €r+   r™  z1ClvpForCausalLM._reorder_cache.<locals>.<genexpr>Þ  s%   øè ø€ ò 
àô ÓjÐ_iÔj×jñ
ùs   ƒ!r  )rf  rý  s    `r+   Ú_reorder_cachezClvpForCausalLM._reorder_cacheÔ  s   ø€ ô ó 
à-ô
ó 
ð 	
r-   rb  )NNNNNNNNNNNN)rl   rm   rn   r…   r�  r’  r   r(   r÷   rø   r   Ústrr   rì  rõ  r   rË  r€   rp   rÇ   r   r   r—   Ústaticmethodr  rœ   r�   s   @r+   rt  rt  ý  s5  ø„ ô

ò5ò?ð
 *.Ø&*Ø:>ñ	A0à˜Ÿ™Ñ&ðA0ð ˜s‘mðA0ð ˜t C¨¯©Ð$5Ñ6Ñ7ð	A0ð
 
ˆu�|‰|˜X c™]¨D°°e·l±lÐ1BÑ,CÐCÑ	DóA0ðH X\ó3ñj +Ð+HÓIð 15Ø@DØ6:Ø59Ø37Ø15Ø59Ø-1Ø$(Ø,0Ø/3Ø&*ñE
à˜E×,Ñ,Ñ-ðE
ð " %¨¨e¯l©lÑ(;Ñ"<Ñ=ðE
ð ! ×!2Ñ!2Ñ3ð	E
ð
 ! ×!1Ñ!1Ñ2ðE
ð ˜u×/Ñ/Ñ0ðE
ð ˜E×-Ñ-Ñ.ðE
ð   × 1Ñ 1Ñ2ðE
ð ˜×)Ñ)Ñ*ðE
ð ˜D‘>ðE
ð $ D™>ðE
ð ' t™nðE
ð ˜d‘^ðE
ð 
ˆuÐ7Ð7Ñ	8òE
ó JðE
ðN ð
Ø˜u U§\¡\Ñ2Ñ3ð
Ø?D¿|¹|ð
à	ˆu�U—\‘\Ñ"Ñ	#ò
ó ô
r-   rt  zîThe composite CLVP model with a text encoder, speech encoder and speech decoder model.The speech decoder model generates the speech_ids from the text and the text encoder and speech encoder workstogether to filter out the best speech_ids.c                   ó~  ‡ — e Zd ZeZdefˆ fd„Zdej                  dej                  fd„Z	 	 	 dde	ej                     de	ej                     de	ej                     dej                  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   dej                  f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   de	e   de	e   de	e   deeef   fd„«       «       Z ej.                  «       	 	 	 	 	 	 dde	ej                     d
e	ej                     de	ej                     de	e   de	e   de	e   fd„«       Zˆ xZS )Ú!ClvpModelForConditionalGenerationr­   c                 óê  •— t         ‰| �  |«       t        |j                  t        «      s"t        dt        |j                  «      › d�«      ‚t        |j                  t        «      s"t        dt        |j                  «      › d�«      ‚t        |j                  t        «      s"t        dt        |j                  «      › d�«      ‚t        |«      | _        t        |j                  «      | _        t        |j                  «      | _        t        |j                  «      | _        t#        j$                  t'        j(                  | j*                  j,                  «      «      | _        | j1                  «        y )NzPconfig.text_config is expected to be of type `ClvpEncoderConfig` but is of type ú.zRconfig.speech_config is expected to be of type `ClvpEncoderConfig` but is of type zSconfig.decoder_config is expected to be of type `ClvpDecoderConfig` but is of type )r„   r…   rj  r8  r    Ú	TypeErrorÚtypeÚspeech_configr9  r   r4  Úconditioning_encoderrt  Úspeech_decoder_modelrq  Útext_encoder_modelÚspeech_encoder_modelr   r†   r(   rX   r­   Úlogit_scale_init_valueÚlogit_scaler‹  r   s     €r+   r…   z*ClvpModelForConditionalGeneration.__init__í  s=  ø€ Ü‰Ñ˜Ô ä˜&×,Ñ,Ô.?Ô@ÜðÜ˜×+Ñ+Ó,Ð-¨Qð0óð ô
 ˜&×.Ñ.Ô0AÔBÜðÜ˜×-Ñ-Ó.Ð/¨qð2óð ô
 ˜&×/Ñ/Ô1BÔCÜðÜ˜×.Ñ.Ó/Ð0°ð3óð ô
 %<¸FÓ$CˆÔ!ä$3°F×4IÑ4IÓ$JˆÔ!ä"-¨f×.@Ñ.@Ó"AˆÔÜ$/°×0DÑ0DÓ$EˆÔ!äŸ<™<¬¯©°T·[±[×5WÑ5WÓ(XÓYˆÔð 	�‰Õr-   rv   r"   c                 óF  — | j                   j                  j                  }|dd…dd…f   }t        j                  || j
                  j                   j                  k(  dd«      }t        j                  ||j                  «       |d   ¬«      }t        |«      D ]†  \  }}|j                  «       dk(  rŒ|j                  «       }|d   |||d…f<   |dz
  |j                  d   k  sŒLt        j                  |dd g|j                  t        j                  ¬«      ||dd…f<   Œˆ |S )a#  
        This method modifies the output of the decoder model, such as replacing the `eos_token_id` and changing the
        last few tokens of each sequence.

        Args:
            speech_ids (`torch.LongTensor`):
                This refers to the output of the decoder model.
        Nr   r   )ÚmaskrN   r
   )r%   rP   éýÿÿÿ)r­   r9  Údecoder_fixing_codesr(   rU   r  r]   Úmasked_fillrÇ   rS   rT   Úargmaxr9   rX   r%   rV  )rŠ   rv   r  Ústop_token_indicesra   Úeach_seq_stop_token_indexÚstms          r+   Úfix_speech_decoder_outputz;ClvpModelForConditionalGeneration.fix_speech_decoder_output  s%  € ð  $Ÿ{™{×9Ñ9×NÑNÐØ¢ 1¡2 Ñ&ˆ
ä"Ÿ[™[¨°t×7PÑ7P×7WÑ7W×7dÑ7dÑ)dÐfgÐijÓkÐÜ×&Ñ& zÐ8J×8OÑ8OÓ8QÐYmÐnoÑYpÔqˆ
ä,5Ð6HÓ,Iò 	Ñ(ˆAÐ(ð )×,Ñ,Ó.°!Ò3Øà+×2Ñ2Ó4ˆCØ"6°qÑ"9ˆJ�q˜#™$�wÑØ�Q‰w˜×)Ñ)¨!Ñ,Ó,Ü%*§\¡\Ø)¨!¨"Ð-Ð.°z×7HÑ7HÔPU×PZÑPZô&�
˜1˜b™c˜6Ò"ð	ð Ðr-   rY   Útext_encoder_inputs_embedsrZ   c                 ó4   — | j                  |||¬«      }|d   S )a„  
        This method can be used to extract text_embeds from a text. The text embeddings obtained by applying the
        projection layer to the pooled output of the CLVP text encoder model.

        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
                provide it.

                [What are input IDs?](../glossary#input-ids)
            text_encoder_inputs_embeds (`torch.FloatTensor`, *optional*):
                inputs_embeds for the text encoder model passed in place of `input_ids`.
            attention_mask (`torch.Tensor` 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)

        Returns:
            `torch.FloatTensor` of shape `(batch_size, output_dim)`:
                The text embeddings obtained by applying the projection layer to the pooled output of the CLVP Text
                Model.

        Examples:

        ```python
        >>> from transformers import ClvpProcessor, ClvpModelForConditionalGeneration

        >>> # Define the Text
        >>> text = "This is an example text."

        >>> # Define processor and model
        >>> processor = ClvpProcessor.from_pretrained("susnato/clvp_dev")
        >>> model = ClvpModelForConditionalGeneration.from_pretrained("susnato/clvp_dev")

        >>> # Generate processor output and text embeds
        >>> processor_output = processor(text=text, return_tensors="pt")
        >>> text_embeds = model.get_text_features(input_ids=processor_output["input_ids"])
        ```
        )rY   rR  rZ   r   )r  )rŠ   rY   r  rZ   r  s        r+   Úget_text_featuresz3ClvpModelForConditionalGeneration.get_text_features.  s/   € ðb ×)Ñ)ØØ4Ø)ð *ó 
ˆð �q‰zÐr-   rQ  Ú"conditioning_encoder_inputs_embedsÚgeneration_configc                 ó$  — |€w|€|�|€t        d«      ‚|€| j                  } |j                  di |¤Ž | j                  ||||¬«      }| j                  j                  ||¬«      }| j                  |d   «      }| j                  ||¬«      }	|	d   S )a*  
        This method can be used to extract speech_embeds. The speech embeddings are obtained by applying the speech
        model on speech_ids. If speech_ids is not present but both input_ids and input_features are given then the
        decoder model will be used to first generate the speech_ids and then applying the speech model.

        Args:
            speech_ids (`torch.LongTensor` of shape `(batch_size, num_speech_ids)`, *optional*):
                Speech Tokens. Padding will be ignored by default should you provide it. If speech_ids are provided
                then input_ids and input_features will be automatically ignored.
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Input text Tokens. Processed from the [`ClvpTokenizer`]. If speech_ids is not provided, then input_ids
                and input_features will be used.
            input_features (`torch.FloatTensor` of shape `(batch_size, feature_size, time_dim)`, *optional*):
                Indicates log-melspectrogram representations for audio returned by [`ClvpFeatureExtractor`]. If
                speech_ids is not provided, then input_ids and input_features will be used.
            conditioning_encoder_inputs_embeds (`torch.FloatTensor`, *optional*):
                inputs_embeds for `ClvpConditioningEncoder`. Can be used in place of `input_ids`.
            attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding speech 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)
            generation_config (`GenerationConfig`, *optional*):
                generation config to control the generation of speech_ids if they are not provided.

        Returns:
            `torch.FloatTensor` of shape `(batch_size, output_dim)`:
                The speech embeddings obtained by applying the projection layer to the pooled output of the CLVP Speech
                Model.

        Examples:

        ```python
        >>> import datasets
        >>> from transformers import ClvpProcessor, ClvpModelForConditionalGeneration

        >>> # Define the Text and Load the Audio (We are taking an audio example from HuggingFace Hub using `datasets` library)
        >>> text = "This is an example text."
        >>> ds = datasets.load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> ds = ds.cast_column("audio", datasets.Audio(sampling_rate=22050))
        >>> _, audio, sr = ds.sort("id").select(range(1))[:1]["audio"][0].values()

        >>> # Define processor and model
        >>> processor = ClvpProcessor.from_pretrained("susnato/clvp_dev")
        >>> model = ClvpModelForConditionalGeneration.from_pretrained("susnato/clvp_dev")

        >>> # Generate processor output and model output
        >>> processor_output = processor(raw_speech=audio, sampling_rate=sr, text=text, return_tensors="pt")
        >>> speech_embeds = model.get_speech_features(
        ...     input_ids=processor_output["input_ids"], input_features=processor_output["input_features"]
        ... )
        ```
        zfEither speech_ids or input_ids/conditioning_encoder_inputs_embeds and input_features must be provided.©rQ  rY   rR  rZ   )râ  r#  r   )rY   rZ   rr   )rÁ   r#  rï  r  r  Úgenerater  r  )
rŠ   rv   rY   rQ  r"  rZ   r#  rð  râ  r  s
             r+   Úget_speech_featuresz5ClvpModelForConditionalGeneration.get_speech_featuresg  s×   € ðD ÐØÐ!Ð&HÐ&PÐUcÐUkÜ Ø|óð ð !Ð(Ø$(×$:Ñ$:Ð!Ø$Ð×$Ñ$Ñ. vÒ.à"&×";Ñ";Ø-Ø#Ø@Ø-ð	 #<ó #Ðð ×2Ñ2×;Ñ;Ø$7Ø"3ð <ó ˆJð
 ×7Ñ7¸
À1¹ÓFˆJà×+Ñ+Ø Ø)ð ,ó 
ˆð
 �q‰zÐr-   )Úoutput_typer€  Úreturn_lossr“  rÚ   r”  c
                 óx  — |�|n| j                   j                  }|	�|	n| j                   j                  }	| j                  ||||¬«      }
| j	                  |
||	¬«      }|d   }|j
                  dk(  r|j                  d«      }| j                  |«      }| j                  |||	¬«      }| j                  |||||	¬«      }|d   }|d   }||j                  dd	d
¬«      z  }||j                  dd	d
¬«      z  }| j                  j                  «       }t        j                  ||j                  «       «      |z  }|j                  «       }d}|rt!        |«      }|	s+|||||d   |d   f}|r||d	   |d	   |d	   fz  }|�|f|z   S |S t#        ||||||d   |d   |j$                  |j$                  |j$                  ¬«
      S )a·  
        Returns:

        Examples:

        ```python
        >>> import datasets
        >>> from transformers import ClvpProcessor, ClvpModelForConditionalGeneration

        >>> # Define the Text and Load the Audio (We are taking an audio example from HuggingFace Hub using `datasets` library)
        >>> text = "This is an example text."

        >>> ds = datasets.load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> ds = ds.cast_column("audio", datasets.Audio(sampling_rate=22050))
        >>> _, audio, sr = ds.sort("id").select(range(1))[:1]["audio"][0].values()

        >>> # Define processor and model
        >>> processor = ClvpProcessor.from_pretrained("susnato/clvp_dev")
        >>> model = ClvpModelForConditionalGeneration.from_pretrained("susnato/clvp_dev")

        >>> # processor outputs and model outputs
        >>> processor_output = processor(raw_speech=audio, sampling_rate=sr, text=text, return_tensors="pt")
        >>> outputs = model(
        ...     input_ids=processor_output["input_ids"],
        ...     input_features=processor_output["input_features"],
        ...     return_dict=True,
        ... )
        ```
        Nr%  )rR  r“  r”  r   r
   r6   ©rY   r“  r”  )rY   rR  rZ   r“  r”  r5   T©rÝ   r8   r�   )
ru   rw   rx   ry   rz   r{   r|   r}   r~   r   )r­   r“  rš  r  r  Úndimr  r  r  r  Únormr  Úexpr(   rá   r0   r3   rt   rj   )rŠ   rY   rQ  r"  r  rZ   r)  r“  rÚ   r”  râ  rÖ  rv   Úspeech_outputsÚtext_outputsrz   ry   r  rx   rw   ru   rü  s                         r+   r—   z)ClvpModelForConditionalGeneration.forwardÈ  sJ  € ð\ %9Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà"×7Ñ7Ø)ØØ<Ø)ð	 8ó 
Ðð ×3Ñ3Ø-Ø!5Ø#ð 4ó 
ˆð % QÑ'ˆ
ð �?‰?˜aÒØ#×*Ñ*¨1Ó-ˆJØ×3Ñ3°JÓ?ˆ
à×2Ñ2Ø Ø!5Ø#ð 3ó 
ˆð ×.Ñ.ØØ4Ø)Ø!5Ø#ð /ó 
ˆð ' qÑ)ˆØ" 1‘oˆð &¨×(:Ñ(:¸QÀBÐPTÐ(:Ó(UÑUˆØ! K×$4Ñ$4°q¸bÈ$Ð$4Ó$OÑOˆð ×&Ñ&×*Ñ*Ó,ˆÜŸ,™, {°M·O±OÓ4EÓFÈÑTˆØ+×-Ñ-Ó/ÐàˆÙÜ˜_Ó-ˆDáà!ØØØØ˜Q‘Ø˜qÑ!ðˆFñ $ØØ# BÑ'Ø  Ñ$Ø" 2Ñ&ðñ �ð *.Ð)9�T�G˜fÑ$ÐE¸vÐEäØØ/Ø+Ø#Ø'Ø*¨1™oØ .¨qÑ 1Ø"1×"?Ñ"?Ø'3×'AÑ'AØ)7×)EÑ)Eô
ð 	
r-   Úpad_to_max_mel_tokensc                 ó  — |j                   d   }|| j                  j                  j                  dz
  kD  r2t	        d|› d| j                  j                  j                  dz
  › �«      ‚|€| j
                  }t        j                  |«      } |j                  di |¤Ž}	|j                  «        | j                  |	j                  «       «       t        ||d| j                  j                  j                  | j                  j                  j                  ¬«      \  }}| j                  |||¬«      }
| j                   j#                  |
|||j$                  ¬«      }t'        |t(        «      r|j*                  }|�T|j                   d   z
  }t,        j.                  j0                  j3                  |d	|f| j
                  j                  ¬
«      }| j5                  «      }| j7                  |||j$                  ¬«      }| j9                  ||||j$                  ¬«      }|d	   }|d	   }||j;                  ddd¬«      z  }||j;                  ddd¬«      z  }| j<                  j?                  «       }t-        j@                  ||jC                  «       «      |z  }|jC                  «       }|j$                  s$||||||d   |d   f}|r||d   |d   |d   fz  }|S tE        ||||||d   |d   |jF                  |jF                  |jF                  ¬«
      S )a=
  
        Generate method for `ClvpModelForConditionalGeneration`, this method calls the `generate` method of
        `ClvpForCausalLM` and then uses those generated `speech_ids` to process `text_embeds` and `speech_embeds` using
        `ClvpEncoder`.

        Args:
            input_ids (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Input text Tokens. Processed from the [`ClvpTokenizer`].
            input_features (`torch.FloatTensor` of shape `(batch_size, feature_size, time_dim)`, *optional*):
                Indicates log-melspectrogram representations for audio returned by [`ClvpFeatureExtractor`].
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding text 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)
            generation_config (`~generation.GenerationConfig`, *optional*):
                The generation configuration to be used as base parametrization for the generation call. `**kwargs`
                passed to generate matching the attributes of `generation_config` will override them. If
                `generation_config` is not provided, the default will be used, which had the following loading
                priority: 1) from the `generation_config.json` model file, if it exists; 2) from the model
                configuration. Please note that unspecified parameters will inherit [`~generation.GenerationConfig`]'s
                default values, whose documentation should be checked to parameterize generation.
            pad_to_max_mel_tokens (`int`, *optional*):
                Pads generated speech_ids to the specified value. This is to implement the same logic from the official
                repo, link: https://github.com/neonbjb/tortoise-tts/blob/80f89987a5abda5e2b082618cd74f9c7411141dc/tortoise/api.py#L430
                and to make sure the logits are same.
                This does not affect generation quality so please don't consider using it since it is less efficient.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of decoder model, text encoder and speech encoder models.

        Returns:
            `ClvpOutput` or tuple: A `ClvpOutput` (if `return_dict_in_generate=True` or when
            `config.return_dict_in_generate=True`) or a tuple.
        r5   r
   z;Maximum sequence length reached! Found input_ids of length z:.Please make sure that the maximum length of input_ids is F)r^   r\   r]   )rQ  rY   rZ   )râ  r#  r“  r”  r   rM   r+  )rY   rZ   r“  r”  r6   Tr,  )
rv   rw   rx   ry   rz   r{   r|   r}   r~   r   rr   )$r9   r­   r9  r=  rÁ   r#  ÚcopyÚdeepcopyrï  ÚvalidateÚ_validate_model_kwargsrd   r8  r\   r]   r  r  r&  Úreturn_dict_in_generaterj  r   Ú	sequencesr(   r   r&   rQ   r  r  r  r.  r  r/  rá   r0   rt   rj   )rŠ   rY   rQ  rZ   r#  r2  r“  rð  r±   rà  râ  rÖ  rv   Úpadding_neededr0  r1  rz   ry   r  rx   rw   rü  s                         r+   r&  z*ClvpModelForConditionalGeneration.generateL  s]  € ðf $Ÿ/™/¨"Ñ-ˆØ˜dŸk™k×8Ñ8×HÑHÈ1ÑLÒMÜØMÈoÐM^ð _LØLPÏKÉK×LfÑLf×LvÑLvÐyzÑLzÐK{ð}óð ð
 Ð$Ø $× 6Ñ 6Ðä ŸM™MÐ*;Ó<ÐØ/Ð(×/Ñ/Ñ9°&Ñ9ˆØ×"Ñ"Ô$Ø×#Ñ# L×$5Ñ$5Ó$7Ô8ô %>ØØØØŸ™×0Ñ0×=Ñ=ØŸ™×0Ñ0×=Ñ=ô%
Ñ!ˆ	�>ð #×7Ñ7Ø)ØØ)ð 8ó 
Ðð ×3Ñ3×<Ñ<Ø 3Ø/Ø!5Ø)×AÑAð	 =ó 
ˆô �o¤{Ô3Ø(×2Ñ2ˆJð !Ð,Ø2°Z×5EÑ5EÀbÑ5IÑIˆNÜŸ™×,Ñ,×0Ñ0Ø˜Q Ð/°t×7MÑ7M×7ZÑ7Zð 1ó ˆJð ×3Ñ3°JÓ?ˆ
à×2Ñ2Ø Ø!5Ø)×AÑAð 3ó 
ˆð
 ×.Ñ.ØØ)Ø!5Ø)×AÑAð	 /ó 
ˆð ' qÑ)ˆØ" 1‘oˆð &¨×(:Ñ(:¸QÀBÐPTÐ(:Ó(UÑUˆØ! K×$4Ñ$4°q¸bÈ$Ð$4Ó$OÑOˆð ×&Ñ&×*Ñ*Ó,ˆÜŸ,™, {°M·O±OÓ4EÓFÈÑTˆØ+×-Ñ-Ó/Ðà ×8Ò8àØ!ØØØØ˜Q‘Ø˜qÑ!ðˆFñ $ØØ# BÑ'Ø  Ñ$Ø" 2Ñ&ðñ �ð ˆMäØ!Ø/Ø+Ø#Ø'Ø*¨1™oØ .¨qÑ 1Ø"1×"?Ñ"?Ø'3×'AÑ'AØ)7×)EÑ)Eô
ð 	
r-   rb  )NNNNNN)	NNNNNNNFN)rl   rm   rn   r   r€  r…   r(   r€   r  r   rp   r!  r÷   r   r'  r   ÚCLVP_INPUTS_DOCSTRINGr   rt   rÇ   r   r   r—   Úno_gradrø   r&  rœ   r�   s   @r+   r	  r	  ä  så  ø„ ð €Lð˜zõ ðF°E×4DÑ4Dð È×IYÑIYó ð@ 15ØBFØ59ñ	7à˜E×,Ñ,Ñ-ð7ð %-¨U×->Ñ->Ñ$?ð7ð ! ×!1Ñ!1Ñ2ð	7ð
 
×	Ñ	ó7ðv 26Ø04Ø6:ØJNØ15Ø8<ñ_à˜U×-Ñ-Ñ.ð_ð ˜E×,Ñ,Ñ-ð_ð ! ×!2Ñ!2Ñ3ð	_ð
 -5°U×5FÑ5FÑ,Gð_ð ! §¡Ñ.ð_ð $Ð$4Ñ5ð_ð 
×	Ñ	ó_ñB +Ð+@ÓAÙ¨:ÀJÔOð 15Ø6:ØJNØBFØ59Ø&*Ø/3Ø,1Ø&*ñ@
à˜E×,Ñ,Ñ-ð@
ð ! ×!2Ñ!2Ñ3ð@
ð -5°U×5FÑ5FÑ,Gð	@
ð
 %-¨U×->Ñ->Ñ$?ð@
ð ! ×!1Ñ!1Ñ2ð@
ð ˜d‘^ð@
ð ' t™nð@
ð $ D™>ð@
ð ˜d‘^ð@
ð 
ˆu�jÐ Ñ	!ò@
ó Pó Bð@
ðD €U‡]�]ƒ_ð 15Ø6:Ø59Ø8<Ø/3Ø/3ñZ
à˜E×,Ñ,Ñ-ðZ
ð ! ×!2Ñ!2Ñ3ðZ
ð ! ×!1Ñ!1Ñ2ð	Z
ð
 $Ð$4Ñ5ðZ
ð  (¨™}ðZ
ð ' t™nòZ
ó ôZ
r-   r	  )r	  rt  rÍ  rd  rq  r¥  )r   )Nr   éÿ   r   TT)Lro   r4  rw  Údataclassesr   Útypingr   r   r   r   r(   Útorch.utils.checkpointr   Útorch.nnr	   Úactivationsr   Ú
generationr   r   Úmodeling_attn_mask_utilsr   r   Úmodeling_outputsr   r   r   r   Úmodeling_utilsr   r   Úpytorch_utilsr   r   rX  r   r   r   r   r   Úconfiguration_clvpr   r   r    Ú
get_loggerrl   r¾  Ú_CHECKPOINT_FOR_DOCr÷   r,   r3   r>   rK   rd   rf   rt   ÚModuler‚   rŸ   r·   rú   r  r  r  r%  r4  rd  ÚCLVP_START_DOCSTRINGr;  rË  rq  r¥  rÍ  rt  r	  Ú__all__rr   r-   r+   ú<module>rN     sv  ðñ  ã Û Ý !ß /Ó /ã Û Ý Ý %å !ß ;ß e÷ó ÷ ?ß 6÷õ ÷ñ ð 
ˆ×	Ñ	˜HÓ	%€à(Ð ð`˜UŸ\™\ð `¨e¯l©ló `ð
.˜%Ÿ,™,ð .¨5¯<©<ó .ò(ó%ð> ØØØØØó(.ðV ô:˜ó :ó ð:ð: ô)E�ó )Eó ð)EôZJ�"—)‘)ô Jô(7 B§I¡Iô 7ô<~2˜Ÿ	™	ô ~2ôB8˜"Ÿ)™)ô 8ô �R—Y‘Yô ô(;�r—y‘yô ;ô~�R—Y‘Yô ô"1�r—y‘yô 1ôhG<˜bŸi™iô G<ôT)*˜/ô )*ðXÐ ð !Ð ðH=!Ð ô@Y
Ð%ô Y
ôxp
Ð%ô p
ñf Ø`Øóô@
Ð#ó @
ó	ð@
ñF ØCØóô`
Ð)¨?ó `
ó	ð`
ñF ð2ð ó	ô}
Ð(;¸_ó }
óð}
ò@�r-   