§
    ‚Štjëd ã                   ó  — d Z ddlZddlmZ ddlmZ ddlmZm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 dd
lmZmZ ddlmZmZ ddlmZ ddlmZ ddlmZmZmZm Z  ddl!m"Z"m#Z# ddl$m%Z%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3  e,j4        e5¦  «        Z6 e+d¬¦  «        e G d„ de¦  «        ¦   «         ¦   «         Z7 e+d¬¦  «        e G d„ de¦  «        ¦   «         ¦   «         Z8 e+d¬¦  «        e G d „ d!e¦  «        ¦   «         ¦   «         Z9e+e G d"„ d#e¦  «        ¦   «         ¦   «         Z: G d$„ d%ej;        ¦  «        Z< G d&„ d'ej;        ¦  «        Z= G d(„ d)ej;        ¦  «        Z> G d*„ d+ej;        ¦  «        Z?d,„ Z@dOd-„ZA G d.„ d/ej;        ¦  «        ZBd0e	jC        d1eDd2e	jC        fd3„ZE	 dPd5ej;        d6e	jC        d7e	jC        d8e	jC        d9e	jC        dz  d:eFd;eFd<e(e*         fd=„ZG G d>„ d?ej;        ¦  «        ZH G d@„ dAe¦  «        ZIe+ G dB„ dCe&¦  «        ¦   «         ZJ G dD„ dEeJe¦  «        ZKe+ G dF„ dGeJ¦  «        ¦   «         ZL e+dH¬¦  «         G dI„ dJeJe¦  «        ¦   «         ZM e+dK¬¦  «         G dL„ dMeJe¦  «        ¦   «         ZNg dN¢ZOdS )QzPyTorch Moshi model.é    N)ÚCallable)Ú	dataclass)ÚAnyÚOptional)ÚCrossEntropyLossé   )Úinitialization)ÚACT2FN)ÚCacheÚDynamicCache)ÚGenerationConfigÚGenerationMixin)Úcreate_causal_mask)ÚGradientCheckpointingLayer)ÚBaseModelOutputWithPastÚCausalLMOutputWithPastÚModelOutputÚSeq2SeqLMOutput)ÚROPE_INIT_FUNCTIONSÚdynamic_rope_update)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚlogging)Úmaybe_autocasté   )Ú	AutoModelé   )ÚMoshiConfigÚMoshiDepthConfigzK
    Outputs of [`MoshiForConditionalConditionalGeneration.generate`].
    )Úcustom_introc                   ó~  — e Zd ZU dZdZej        dz  ed<   dZej	        dz  ed<   dZ
ej        dz  ed<   dZeej                 dz  ed<   dZeej                 dz  ed<   dZej	        dz  ed<   dZeeej                          dz  ed	<   dZeeej                          dz  ed
<   dZedz  ed<   dZej	        dz  ed<   dS )Ú(MoshiConditionalGenerationGenerateOutputaÞ  
    audio_sequences (`torch.LongTensor` of shape `(batch_size*num_return_sequences, 1, sequence_length)`, *optional*):
        The generated audio waveforms.
    sequences (`torch.LongTensor` of shape `(batch_size*num_return_sequences, sequence_length)`):
        The generated text sequences. The second dimension (sequence_length) is either equal to `max_length` or shorter
        if all batches finished early due to the `eos_token_id`.
    sequences_scores (`torch.FloatTensor` of shape `(batch_size*num_return_sequences)`, *optional*, returned when `output_scores=True`):
        Final beam scores of the generated `sequences`.
    scores (`tuple(torch.FloatTensor)` *optional*, returned when `output_scores=True`):
        Beam transition scores for each vocabulary token at each generation step. Beam transition scores consisting
        of log probabilities of tokens conditioned on log softmax of previously generated tokens in this beam.
        Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for each generated token),
        with each tensor of shape `(batch_size*num_beams, config.vocab_size)`.
    logits (`tuple(torch.FloatTensor)` *optional*, returned when `output_logits=True`):
        Unprocessed prediction scores of the language modeling head (scores for each vocabulary token before SoftMax)
        at each generation step. Tuple of `torch.FloatTensor` with up to `max_new_tokens` elements (one element for
        each generated token), with each tensor of shape `(batch_size, config.vocab_size)`.
    beam_indices (`torch.LongTensor`, *optional*, returned when `output_scores=True`):
        Beam indices of generated token id at each generation step. `torch.LongTensor` of shape
        `(batch_size*num_return_sequences, sequence_length)`.
    attentions (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_attentions=True`):
        Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
        `torch.FloatTensor` of shape `(batch_size*num_beams, num_heads, generated_length, sequence_length)`.
    hidden_states (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `output_hidden_states=True`):
        Tuple (one element for each generated token) of tuples (one element for each layer of the decoder) of
        `torch.FloatTensor` of shape `(batch_size*num_beams*num_return_sequences, generated_length, hidden_size)`.
    past_key_values (`Cache`, *optional*, returned when `use_cache=True`):
        Contains the model cache, used to speed up decoding. Different models have a different cache format, check
        the model's documentation. Usually, a [`~cache_utils.Cache`] instance.
    audio_codes (`torch.LongTensor` of shape `(batch_size*num_return_sequences, num_codeooks, sequence_length)`, *optional*):
        The generated audio codes. Returned if `return_audio_codes=True`. Intermediate audio "tokens" which transforms to `audio_sequences` once passed through the audio decoder.
    NÚaudio_sequencesÚ	sequencesÚsequences_scoresÚscoresÚlogitsÚbeam_indicesÚ
attentionsÚhidden_statesÚpast_key_valuesÚaudio_codes)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   ÚtorchÚTensorÚ__annotations__r'   Ú
LongTensorr(   ÚFloatTensorr)   Útupler*   r+   r,   r-   r.   r   r/   © ó    úf/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/models/moshi/modeling_moshi.pyr%   r%   ,   s)  € € € € € € ðð ðB ,0€O�U”\ DÑ(Ð/Ð/Ñ/Ø)-€IˆuÔ $Ñ&Ð-Ð-Ñ-Ø15Ð�eÔ'¨$Ñ.Ð5Ð5Ñ5Ø.2€FˆE�%Ô#Ô$ tÑ+Ð2Ð2Ñ2Ø.2€FˆE�%Ô#Ô$ tÑ+Ð2Ð2Ñ2Ø,0€L�%Ô" TÑ)Ð0Ð0Ñ0Ø9=€J��e˜EÔ-Ô.Ô/°$Ñ6Ð=Ð=Ñ=Ø<@€M�5˜˜uÔ0Ô1Ô2°TÑ9Ð@Ð@Ñ@Ø$(€O�U˜T‘\Ð(Ð(Ñ(Ø+/€K�Ô! DÑ(Ð/Ð/Ñ/Ð/Ð/r;   r%   z%
    `MoshiForCausalLM` outputs.
    c                   óÞ   — e Zd ZU dZdZej        dz  ed<   dZej        dz  ed<   dZ	ej        dz  ed<   dZ
edz  ed<   dZeej        df         dz  ed<   dZeej        df         dz  ed	<   dS )
ÚMoshiCausalLMOutputWithPasta%  
    loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
        Language modeling loss (for next-token prediction).
    logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
        Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
    past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
        It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

        Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
        `past_key_values` input) to speed up sequential decoding.
    NÚlossr*   Úlast_hidden_stater.   .r-   r,   )r0   r1   r2   r3   r?   r4   r8   r6   r*   r@   r.   r   r-   r9   r,   r:   r;   r<   r>   r>   `   s¿   € € € € € € ð
ð 
ð &*€Dˆ%Ô
˜dÑ
"Ð)Ð)Ñ)Ø'+€FˆEÔ Ñ$Ð+Ð+Ñ+Ø26Ð�uÔ(¨4Ñ/Ð6Ð6Ñ6Ø$(€O�U˜T‘\Ð(Ð(Ñ(Ø:>€M�5˜Ô*¨CÐ/Ô0°4Ñ7Ð>Ð>Ñ>Ø7;€J��eÔ'¨Ð,Ô-°Ñ4Ð;Ð;Ñ;Ð;Ð;r;   r>   z2
    `MoshiForConditionalGeneration` outputs.
    c                   óŠ  — e Zd ZU dZdZej        dz  ed<   dZej        dz  ed<   dZ	ej        dz  ed<   dZ
edz  ed<   dZeej        df         dz  ed<   dZeej        df         dz  ed	<   dZej        dz  ed
<   dZej        dz  ed<   dZedz  ed<   dZeej        df         dz  ed<   dZeej        df         dz  ed<   dS )Ú(MoshiConditionalGenerationOutputWithPasta'  
    loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `text_labels` is provided):
        Text language modeling loss (for next-token prediction).
    logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
        Prediction scores of the text language modeling head (scores for each vocabulary token before SoftMax).
    past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
        It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

        Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
        `past_key_values` input) to speed up sequential decoding.
    depth_loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `audio_labels` is provided):
        Audio language modeling loss (for next-token prediction).
    audio_logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
        Prediction scores of the audio language modeling heads.
    depth_past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
        Past key-values of the depth decoder.
    depth_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
        Hidden states of the depth decoder
    depth_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
        Depth decoder's Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
        heads.
    Nr?   r*   r@   r.   .r-   r,   Ú
depth_lossÚaudio_logitsÚdepth_past_key_valuesÚdepth_hidden_statesÚdepth_attentions)r0   r1   r2   r3   r?   r4   r8   r6   r*   r@   r.   r   r-   r9   r,   rC   rD   rE   rF   rG   r:   r;   r<   rB   rB   {   sJ  € € € € € € ðð ð. &*€Dˆ%Ô
˜dÑ
"Ð)Ð)Ñ)Ø'+€FˆEÔ Ñ$Ð+Ð+Ñ+Ø26Ð�uÔ(¨4Ñ/Ð6Ð6Ñ6Ø$(€O�U˜T‘\Ð(Ð(Ñ(Ø:>€M�5˜Ô*¨CÐ/Ô0°4Ñ7Ð>Ð>Ñ>Ø7;€J��eÔ'¨Ð,Ô-°Ñ4Ð;Ð;Ñ;Ø+/€J�Ô! DÑ(Ð/Ð/Ñ/Ø-1€L�%Ô# dÑ*Ð1Ð1Ñ1Ø*.Ð˜5 4™<Ð.Ð.Ñ.Ø@DÐ˜˜uÔ0°#Ð5Ô6¸Ñ=ÐDÐDÑDØ=AÐ�e˜EÔ-¨sÐ2Ô3°dÑ:ÐAÐAÑAÐAÐAr;   rB   c                   óŒ   — e Zd ZU dZdZej        dz  ed<   dZej	        dz  ed<   dZ
ej	        dz  ed<   dZej        dz  ed<   dS )ÚMoshiUnconditionalInputa)  
    input_ids (`torch.Tensor `of shape `(batch_size, sequence_length), *optional*):
        The sequence used as a text prompt for the generation.
    user_audio_codes (`torch.Tensor `of shape `(batch_size, num_codebooks, sequence_length), *optional*):
        The audio codes used as audio user prompt for the generation. Has priority over `user_input_values` and represents the audio "tokens" of `user_input_values` once passed through the audio encoder.
    moshi_audio_codes (`torch.Tensor `of shape `(batch_size, num_codebooks, sequence_length), *optional*):
        The audio codes used as audio Moshi prompt for the generation. Has priority over `moshi_input_values` and represents the audio "tokens" of `moshi_input_values` once passed through the audio encoder.
    attention_mask (`torch.LongTensor`)  of shape `(batch_size, sequence_length)`, *optional*):
        Attention 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**.
    NÚ	input_idsÚuser_audio_codesÚmoshi_audio_codesÚattention_mask)r0   r1   r2   r3   rJ   r4   r7   r6   rK   r5   rL   rM   r:   r;   r<   rI   rI   ¦   s~   € € € € € € ð
ð 
ð *.€IˆuÔ $Ñ&Ð-Ð-Ñ-Ø,0Ð�e”l TÑ)Ð0Ð0Ñ0Ø-1Ð�u”| dÑ*Ð1Ð1Ñ1Ø.2€N�EÔ$ tÑ+Ð2Ð2Ñ2Ð2Ð2r;   rI   c                   ó<   ‡ — e Zd Zddedefˆ fd„Zd„ Zd„ Zd„ Zˆ xZ	S )	ÚMoshiRMSNormç�íµ ÷Æ°>ÚdimÚepsc                 ó¬   •— t          ¦   «                              ¦   «          || _        t          j        t          j        |¦  «        ¦  «        | _        d S ©N)ÚsuperÚ__init__rR   ÚnnÚ	Parameterr4   ÚonesÚweight)ÚselfrQ   rR   Ú	__class__s      €r<   rV   zMoshiRMSNorm.__init__½   s=   ø€ Ý‰Œ×ÒÑÔÐØˆŒÝ”l¥5¤:¨c¡?¤?Ñ3Ô3ˆŒˆˆr;   c                 ó�   — |t          j        |                     d¦  «                             dd¬¦  «        | j        z   ¦  «        z  S )Nr   éÿÿÿÿT)Úkeepdim)r4   ÚrsqrtÚpowÚmeanrR   )r[   Úxs     r<   Ú_normzMoshiRMSNorm._normÂ   s8   € Ø•5”;˜qŸušu Q™xœxŸ}š}¨R¸˜}Ñ>Ô>ÀÄÑIÑJÔJÑJÐJr;   c                 ó²   — |                       |                     ¦   «         ¦  «        }|| j                             ¦   «         z  }|                     |¦  «        S rT   )rd   ÚfloatrZ   Útype_as)r[   rc   Úoutputs      r<   ÚforwardzMoshiRMSNorm.forwardÆ   sE   € Ø—’˜AŸGšG™IœIÑ&Ô&ˆØ˜$œ+×+Ò+Ñ-Ô-Ñ-ˆØ�~Š~˜aÑ Ô Ð r;   c                 óH   — t          | j        j        ¦  «        › d| j        › �S )Nz, eps=)r9   rZ   ÚshaperR   ©r[   s    r<   Ú
extra_reprzMoshiRMSNorm.extra_reprË   s%   € Ý˜œÔ)Ñ*Ô*Ð<Ð<°$´(Ð<Ð<Ð<r;   )rP   )
r0   r1   r2   Úintrf   rV   rd   ri   rm   Ú__classcell__©r\   s   @r<   rO   rO   ¼   s€   ø€ € € € € ð4ð 4˜Cð 4 eð 4ð 4ð 4ð 4ð 4ð 4ð
Kð Kð Kð!ð !ð !ð
=ð =ð =ð =ð =ð =ð =r;   rO   c                   ó&   ‡ — e Zd Zˆ fd„Zdd„Zˆ xZS )ÚMoshiFlexibleLinearc                 ó¢   •— t          ¦   «                              ¦   «          t          j        t	          j        |||¦  «        ¦  «        | _        d S rT   )rU   rV   rW   rX   r4   ÚrandnrZ   )r[   Ú
input_sizeÚoutput_sizeÚ
num_layersr\   s       €r<   rV   zMoshiFlexibleLinear.__init__Ð   s<   ø€ Ý‰Œ×ÒÑÔÐå”l¥5¤;¨z¸;È
Ñ#SÔ#SÑTÔTˆŒˆˆr;   Nc                 ó
  — |�t          j        | j        d|¦  «        n| j        }|                     dd¦  «        ddd…dd…dd…f         }t          j        |dd…dd…ddd…f         |¦  «        }|                     d¦  «        S )aå  
        `MoshiFlexibleLinear` creates one linear layer per codebook. There's multiple ways to use it.
        In the default case, `sequence_length=num_layers`, so each element of the sequence will be matmul to the weights corresponding to its index on the sequence.

        For more advanced cases, one can specify which codebook's layer(s) to use with `layer_idx`.
        If `layer_idx` indicates a single integer, all of the element of the sequence will be matmul to this single codebook's layer.
        But if `layer_idx` is a tensor of shape `(seq_length,)`, it will matmul each i-th element of the input sequence to the corresponding layer `weight[i]`.


        Args:
            x (`torch.FloatTensor): input to the layer of shape `(batch, num_layers, embed_dim)` or of shape `(batch, seq_length, embed_dim)`
            layer_idx (`torch.Tensor`, *optional*):
                Can be used to specify which codebook's layers(s) to use.
                If it's a tensor of shape `(seq_length,)`, will matmul each element of the sequence to the corresponding weights.
                But if `layer_idx` is a tensor of shape `(seq_length,)`, it will matmul each i-th element of the input sequence to the corresponding layer `weight[i]`.
        Nr   r    r   )r4   Úindex_selectrZ   Ú	transposeÚmatmulÚsqueeze)r[   rc   Ú	layer_idxÚselected_weightss       r<   ri   zMoshiFlexibleLinear.forwardÕ   s›   € ð( MVÐLa�5Ô-¨d¬k¸1¸iÑHÔHÐHÐgkÔgrÐð ,×5Ò5°a¸Ñ;Ô;¸DÀ!À!À!ÀQÀQÀQÈÈÈ¸MÔJÐõ ŒL˜˜1˜1˜1˜a˜a˜a  q q q˜=Ô)Ð+;Ñ<Ô<ˆð �yŠy˜‰|Œ|Ðr;   rT   ©r0   r1   r2   rV   ri   ro   rp   s   @r<   rr   rr   Ï   sQ   ø€ € € € € ðUð Uð Uð Uð Uð
ð ð ð ð ð ð ð r;   rr   c                   ó(   ‡ — e Zd Zdˆ fd„	Zdd„Zˆ xZS )ÚMoshiLinearFc                 óÄ   •— t          ¦   «                              ¦   «          || _        |st          j        ||d¬¦  «        | _        d S t          |||¬¦  «        | _        d S )NF©Úbias)rw   )rU   rV   Úuse_flexible_linearrW   ÚLinearÚlinearrr   )r[   Ú	input_dimÚ
output_dimÚnum_codebooksr…   r\   s        €r<   rV   zMoshiLinear.__init__÷   sa   ø€ Ý‰Œ×ÒÑÔÐà#6ˆÔ à"ð 	_Ýœ) I¨zÀÐFÑFÔFˆDŒKˆKˆKå-¨i¸ÐP]Ð^Ñ^Ô^ˆDŒKˆKˆKr;   Nc                 óf   — | j         r|                      ||¦  «        S |                      |¦  «        S rT   )r…   r‡   )r[   rc   r}   s      r<   ri   zMoshiLinear.forward  s1   € ØÔ#ð 	"Ø—;’;˜q )Ñ,Ô,Ð,à—;’;˜q‘>”>Ð!r;   ©FrT   r   rp   s   @r<   r�   r�   ö   sW   ø€ € € € € ð_ð _ð _ð _ð _ð _ð"ð "ð "ð "ð "ð "ð "ð "r;   r�   c                   óÔ   ‡ — e Zd ZU ej        ed<   ddefˆ fd„Ze	 	 	 ddedz  de	d         de
dz  ded	ef         fd
„¦   «         Z ej        ¦   «         ed„ ¦   «         ¦   «         Zˆ xZS )ÚMoshiRotaryEmbeddingÚinv_freqNÚconfigc                 ó²  •— t          ¦   «                              ¦   «          |j        | _        |j        | _        || _        | j        j        d         | _        | j        }| j        dk    rt          | j                 } || j        |¦  «        \  }| _
        |                      d|d¬¦  «         |                      d|                     ¦   «         d¬¦  «         d S )NÚ	rope_typeÚdefaultr�   F)Ú
persistentÚoriginal_inv_freq)rU   rV   Úmax_position_embeddingsÚmax_seq_len_cachedÚoriginal_max_seq_lenr�   Úrope_parametersr’   Úcompute_default_rope_parametersr   Úattention_scalingÚregister_bufferÚclone)r[   r�   ÚdeviceÚrope_init_fnr�   r\   s        €r<   rV   zMoshiRotaryEmbedding.__init__  sÊ   ø€ Ý‰Œ×ÒÑÔÐØ"(Ô"@ˆÔØ$*Ô$BˆÔ!àˆŒàœÔ4°[ÔAˆŒØ!%Ô!EˆØŒ>˜YÒ&Ð&Ý.¨t¬~Ô>ˆLØ+7¨<¸¼ÀVÑ+LÔ+LÑ(ˆ�$Ô(à×Ò˜Z¨¸eÐÑDÔDÐDØ×ÒÐ0°(·.².Ñ2BÔ2BÈuÐÑUÔUÐUÐUÐUr;   rž   ztorch.deviceÚseq_lenÚreturnztorch.Tensorc                 óü   — | j         d         }t          | dd¦  «        p| j        | j        z  }d}d|t	          j        d|dt          j        ¬¦  «                             |t          j        ¬¦  «        |z  z  z  }||fS )	a¨  
        Computes the inverse frequencies according to the original RoPE implementation
        Args:
            config ([`~transformers.PreTrainedConfig`]):
                The model configuration.
            device (`torch.device`):
                The device to use for initialization of the inverse frequencies.
            seq_len (`int`, *optional*):
                The current sequence length. Unused for this type of RoPE.
        Returns:
            Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
            post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).
        Ú
rope_thetaÚhead_dimNg      ð?r   r   ©Údtype©rž   r¦   )	r™   ÚgetattrÚhidden_sizeÚnum_attention_headsr4   ÚarangeÚint64Útorf   )r�   rž   r    ÚbaserQ   Úattention_factorr�   s          r<   rš   z4MoshiRotaryEmbedding.compute_default_rope_parameters  sŒ   € ð& Ô% lÔ3ˆÝ�f˜j¨$Ñ/Ô/Ðc°6Ô3EÈÔIcÑ3cˆàÐð Ø•U”\ ! S¨!µ5´;Ð?Ñ?Ô?×BÒBÈ&ÕX]ÔXcÐBÑdÔdÐgjÑjÑkñ
ˆð Ð)Ð)Ð)r;   c                 óN  — | j         d d d …d f                              ¦   «                              |j        d         dd¦  «                             |j        ¦  «        }|d d …d d d …f                              ¦   «         }t          |j        j        t          ¦  «        r|j        j        dk    r|j        j        nd}t          |d¬¦  «        5  |                     ¦   «         |                     ¦   «         z   
                    dd¦  «        }t          j        ||fd¬	¦  «        }|                     ¦   «         | j        z  }|                     ¦   «         | j        z  }	d d d ¦  «         n# 1 swxY w Y   |                     |j        ¬
¦  «        |	                     |j        ¬
¦  «        fS )Nr   r^   r    ÚmpsÚcpuF)Údevice_typeÚenabledr   ©rQ   r¥   )r�   rf   Úexpandrk   r­   rž   Ú
isinstanceÚtypeÚstrr   rz   r4   ÚcatÚcosr›   Úsinr¦   )
r[   rc   Úposition_idsÚinv_freq_expandedÚposition_ids_expandedr³   ÚfreqsÚembr»   r¼   s
             r<   ri   zMoshiRotaryEmbedding.forward:  s·  € ð !œM¨$°°°°4¨-Ô8×>Ò>Ñ@Ô@×GÒGÈÔHZÐ[\ÔH]Ð_aÐcdÑeÔe×hÒhÐijÔiqÑrÔrÐØ ,¨Q¨Q¨Q°°a°a°a¨ZÔ 8× >Ò >Ñ @Ô @Ðå'1°!´(´-ÅÑ'EÔ'EÐkÈ!Ì(Ì-Ð[`ÒJ`ÐJ`�a”h”m�mÐfkˆÝ¨¸UÐCÑCÔCð 	5ð 	5Ø&×,Ò,Ñ.Ô.Ð1F×1LÒ1LÑ1NÔ1NÑN×YÒYÐZ[Ð]^Ñ_Ô_ˆEÝ”)˜U E˜N°Ð3Ñ3Ô3ˆCØ—'’'‘)”)˜dÔ4Ñ4ˆCØ—'’'‘)”)˜dÔ4Ñ4ˆCð		5ð 	5ð 	5ñ 	5ô 	5ð 	5ð 	5ð 	5ð 	5ð 	5ð 	5øøøð 	5ð 	5ð 	5ð 	5ð �vŠv˜AœGˆvÑ$Ô$ c§f¢f°1´7 fÑ&;Ô&;Ð;Ð;s   ÃBE&Å&E*Å-E*rT   )NNN)r0   r1   r2   r4   r5   r6   r!   rV   Ústaticmethodr   rn   r9   rf   rš   Úno_gradr   ri   ro   rp   s   @r<   rŽ   rŽ   	  sù   ø€ € € € € € ØŒlÐÐÑðVð V˜{ð Vð Vð Vð Vð Vð Vð  à%)Ø+/Ø"ð*ð *Ø˜dÑ"ð*à˜Ô(ð*ð �t‘ð*ð 
ˆ~˜uÐ$Ô	%ð	*ð *ð *ñ „\ð*ð: €U„]�_„_Øð<ð <ñ Ôñ „_ð<ð <ð <ð <ð <r;   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..Nr^   r   rµ   )rk   r4   rº   )rc   Úx1Úx2s      r<   Úrotate_halfrÇ   K  s]   € à	
ˆ3Ð"�!”'˜"”+ Ñ"Ð"Ð"Ô	#€BØ	
ˆ3�”˜”˜qÑ Ð"Ð"Ð"Ô	#€BÝŒ9�r�c˜2�Y BÐ'Ñ'Ô'Ð'r;   c                 ó¾   — |                      |¦  «        }|                      |¦  «        }| |z  t          | ¦  «        |z  z   }||z  t          |¦  «        |z  z   }||fS )a…  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.
        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Úkr»   r¼   Úunsqueeze_dimÚq_embedÚk_embeds          r<   Úapply_rotary_pos_embrÏ   S  sc   € ð$ �-Š-˜Ñ
&Ô
&€CØ
�-Š-˜Ñ
&Ô
&€CØ�3‰w�; q™>œ>¨CÑ/Ñ0€GØ�3‰w�; q™>œ>¨CÑ/Ñ0€GØ�GÐÐr;   c                   óP   ‡ — e Zd Zdˆ fd„	Zd	dej        dedz  dej        fd„Zˆ xZS )
ÚMoshiGatingMLPFc                 óŒ  •— t          ¦   «                              ¦   «          t          |j                 | _        |j        }|j        }|r|j        nd}|dk    r=t          j	        ||d¬¦  «        | _
        t          j	        |dz  |d¬¦  «        | _        d S t          |||¦  «        | _
        t          |dz  ||¦  «        | _        d S )Nr    Frƒ   r   )rU   rV   r
   Ú
hidden_actÚactivation_fnÚffn_dimr©   rŠ   rW   r†   Úfc1Úfc2rr   )r[   r�   r…   rÕ   r©   rw   r\   s         €r<   rV   zMoshiGatingMLP.__init__m  s¹   ø€ Ý‰Œ×ÒÑÔÐå# FÔ$5Ô6ˆÔØ”.ˆØÔ(ˆØ-@ÐG�VÔ)Ð)Àaˆ
Ø˜Š?ˆ?Ý”y ¨g¸EÐBÑBÔBˆDŒHÝ”y ¨A¡¨{ÀÐGÑGÔGˆDŒHˆHˆHå*¨;¸ÀÑLÔLˆDŒHÝ*¨7°a©<¸ÀjÑQÔQˆDŒHˆHˆHr;   Nr-   r}   r¡   c                 ó\  — |€|                       |¦  «        n|                       ||¦  «        }|j        \  }}}|                     ||dd¦  «        }|                      |ddd d …f         ¦  «        |ddd d …f         z  }|€|                      |¦  «        n|                      ||¦  «        }|S )Nr   r^   .r   r    )rÖ   rk   ÚviewrÔ   r×   )r[   r-   r}   Ú
batch_sizeÚsequence_lengthÚ_s         r<   ri   zMoshiGatingMLP.forward{  sÂ   € Ø3<Ð3D˜Ÿš Ñ/Ô/Ð/È$Ï(Ê(ÐS`ÐbkÑJlÔJlˆà)6Ô)<Ñ&ˆ
�O QØ%×*Ò*¨:°ÈÈ2ÑNÔNˆØ×*Ò*¨=¸¸aÀÀÀ¸Ô+CÑDÔDÀ}ÐUXÐZ[Ð]^Ð]^Ð]^ÐU^ÔG_Ñ_ˆØ3<Ð3D˜Ÿš Ñ/Ô/Ð/È$Ï(Ê(ÐS`ÐbkÑJlÔJlˆØÐr;   rŒ   rT   )	r0   r1   r2   rV   r4   r5   rn   ri   ro   rp   s   @r<   rÑ   rÑ   l  s{   ø€ € € € € ðRð Rð Rð Rð Rð Rðð  U¤\ð ¸cÀD¹jð ÐTYÔT`ð ð ð ð ð ð ð ð r;   rÑ   r-   Ún_repr¡   c                 ó¸   — | j         \  }}}}|dk    r| S | dd…dd…ddd…dd…f                              |||||¦  «        } |                      |||z  ||¦  «        S )zÔ
    This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
    num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
    r    N)rk   r¶   Úreshape)r-   rÝ   ÚbatchÚnum_key_value_headsÚslenr¤   s         r<   Ú	repeat_kvrã   †  s„   € ð
 2?Ô1DÑ.€EÐ  hØ�‚z€zØÐØ! ! ! ! Q Q Q¨¨a¨a¨a°°°Ð"2Ô3×:Ò:¸5ÐBUÐW\Ð^bÐdlÑmÔm€MØ× Ò  Ð(;¸eÑ(CÀTÈ8ÑTÔTÐTr;   ç        ÚmoduleÚqueryÚkeyÚvaluerM   ÚscalingÚdropoutÚkwargsc                 ó  — t          || j        ¦  «        }t          || j        ¦  «        }	t          j        ||                     dd¦  «        ¦  «        |z  }
|�|
|z   }
t
          j                             |
dt          j        ¬¦  «         	                    |j
        ¦  «        }
t
          j                             |
|| j        ¬¦  «        }
t          j        |
|	¦  «        }|                     dd¦  «                             ¦   «         }||
fS )Nr   r   r^   )rQ   r¦   )ÚpÚtrainingr    )rã   Únum_key_value_groupsr4   r{   rz   rW   Ú
functionalÚsoftmaxÚfloat32r­   r¦   rê   rî   Ú
contiguous)rå   ræ   rç   rè   rM   ré   rê   rë   Ú
key_statesÚvalue_statesÚattn_weightsÚattn_outputs               r<   Úeager_attention_forwardrø   “  sé   € õ ˜3 Ô ;Ñ<Ô<€JÝ˜U FÔ$?Ñ@Ô@€Lå”<  z×';Ò';¸A¸qÑ'AÔ'AÑBÔBÀWÑL€LØÐ!Ø# nÑ4ˆå”=×(Ò(¨¸2ÅUÄ]Ð(ÑSÔS×VÒVÐW\ÔWbÑcÔc€LÝ”=×(Ò(¨¸È6Ì?Ð(Ñ[Ô[€LÝ”,˜|¨\Ñ:Ô:€KØ×'Ò'¨¨1Ñ-Ô-×8Ò8Ñ:Ô:€Kà˜Ð$Ð$r;   c                   óÒ   ‡ — e Zd ZdZddededz  fˆ fd„Z	 	 	 	 ddej        d	ej        dz  d
ej	        dz  de
dz  dej        dz  dee         deej        ej        f         fd„Zˆ xZS )ÚMoshiAttentionz=Multi-headed attention from 'Attention Is All You Need' paperNFTr�   r}   c                 óh  •— t          ¦   «                              ¦   «          || _        || _        |j        | _        |j        | _        |j        | _        |j        | _        |j	        | _	        | j        | j	        z  | _
        d| _        dt          j        | j        ¦  «        z  | _        | j        | j        z  dk    r t          d| j        › d| j        › d�¦  «        ‚t!          | j        | j        | j        z  |j        |¦  «        | _        t!          | j        | j	        | j        z  |j        |¦  «        | _        t!          | j        | j	        | j        z  |j        |¦  «        | _        t!          | j        | j        z  | j        |j        |¦  «        | _        d | _        |rt/          |¦  «        | _        d S d S )NTr    r   z?hidden_size must be divisible by num_heads (got `hidden_size`: z and `num_heads`: z).)rU   rV   r�   r}   Úattention_dropoutr©   rª   Ú	num_headsr¤   rá   rï   Ú	is_causalÚmathÚsqrtré   Ú
ValueErrorr�   rŠ   Úq_projÚk_projÚv_projÚo_projÚ
rotary_embrŽ   ©r[   r�   r}   r…   Úuse_roper\   s        €r<   rV   zMoshiAttention.__init__¯  s¼  ø€ Ý‰Œ×ÒÑÔÐØˆŒØ"ˆŒà!'Ô!9ˆÔØ!Ô-ˆÔØÔ3ˆŒØœˆŒØ#)Ô#=ˆÔ Ø$(¤N°dÔ6NÑ$NˆÔ!ØˆŒØ�4œ9 T¤]Ñ3Ô3Ñ3ˆŒàÔ˜dœnÑ,°Ò1Ð1Ýð8ÐRVÔRbð 8ð 8Ø%)¤^ð8ð 8ð 8ñô ð õ
 "ØÔ˜dœn¨t¬}Ñ<¸fÔ>RÐTgñ
ô 
ˆŒõ "ØÔ˜dÔ6¸¼ÑFÈÔH\Ð^qñ
ô 
ˆŒõ "ØÔ˜dÔ6¸¼ÑFÈÔH\Ð^qñ
ô 
ˆŒõ "ØŒN˜Tœ]Ñ*¨DÔ,<¸fÔ>RÐTgñ
ô 
ˆŒð
 ˆŒØð 	;Ý2°6Ñ:Ô:ˆDŒOˆOˆOð	;ð 	;r;   r-   rM   r½   r.   Úcodebook_idxrë   r¡   c                 ó`  — |j         d d…         }g |¢d‘| j        ‘R }|                      ||¦  «                             |¦  «                             dd¦  «        }	|                      ||¦  «                             |¦  «                             dd¦  «        }
|                      ||¦  «                             |¦  «                             dd¦  «        }| j        �.|                      ||¦  «        \  }}t          |	|
||¦  «        \  }	}
|�| 	                    |
|| j
        ¦  «        \  }
}t          j        | j        j        t          ¦  «        } || |	|
||f| j        sdn| j        | j        dœ|¤Ž\  }} |j        g |¢d‘R Ž                      ¦   «         }|                      ||¦  «        }||fS )Nr^   r    r   rä   )rê   ré   )rk   r¤   r  rÙ   rz   r  r  r  rÏ   Úupdater}   r   Úget_interfacer�   Ú_attn_implementationrø   rî   rü   ré   rß   ró   r  )r[   r-   rM   r½   r.   r	  rë   Úinput_shapeÚhidden_shapeÚquery_statesrô   rõ   r»   r¼   Úattention_interfacer÷   rö   s                    r<   ri   zMoshiAttention.forwardÕ  sá  € ð $Ô)¨#¨2¨#Ô.ˆØ8˜Ð8 bÐ8¨$¬-Ð8Ð8ˆà—{’{ =°,Ñ?Ô?×DÒDÀ\ÑRÔR×\Ò\Ð]^Ð`aÑbÔbˆØ—[’[ °Ñ=Ô=×BÒBÀ<ÑPÔP×ZÒZÐ[\Ð^_Ñ`Ô`ˆ
Ø—{’{ =°,Ñ?Ô?×DÒDÀ\ÑRÔR×\Ò\Ð]^Ð`aÑbÔbˆàŒ?Ð&Ø—’ |°\ÑBÔB‰HˆC�Ý';¸LÈ*ÐVYÐ[^Ñ'_Ô'_Ñ$ˆL˜*àÐ&Ø'6×'=Ò'=¸jÈ,ÐX\ÔXfÑ'gÔ'gÑ$ˆJ˜å(?Ô(MØŒKÔ,Õ.Eñ)
ô )
Ðð %8Ð$7ØØØØØð	%
ð  $œ}ÐH�C�C°$Ô2HØ”Lð	%
ð 	%
ð ð	%
ð 	%
Ñ!ˆ�\ð *�kÔ)Ð;¨;Ð;¸Ð;Ð;Ð;×FÒFÑHÔHˆØ—k’k +¨|Ñ<Ô<ˆØ˜LÐ(Ð(r;   )NFT)NNNN)r0   r1   r2   r3   r!   rn   rV   r4   r5   r7   r   r   r   r9   ri   ro   rp   s   @r<   rú   rú   ¬  sö   ø€ € € € € ØGÐGð$;ð $;˜{ð $;°s¸T±zð $;ð $;ð $;ð $;ð $;ð $;ðR /3Ø04Ø(,Ø,0ð()ð ()à”|ð()ð œ tÑ+ð()ð Ô&¨Ñ-ð	()ð
  ™ð()ð ”l TÑ)ð()ð Ð+Ô,ð()ð 
ˆuŒ|˜Uœ\Ð)Ô	*ð()ð ()ð ()ð ()ð ()ð ()ð ()ð ()r;   rú   c                   óô   ‡ — e Zd Zddededefˆ fd„Z	 	 	 	 	 	 ddej        d	ej        dz  d
ej	        dz  de
dz  dedz  dedz  dej        dz  deej        eej        ej        f         dz  f         fd„Zˆ xZS )ÚMoshiDecoderLayerTr�   r}   r…   c                 óx  •— t          ¦   «                              ¦   «          |j        | _        || _        t	          ||||¬¦  «        | _        t          ||¦  «        | _        t          | j        |j	        ¬¦  «        | _
        t          | j        |j	        ¬¦  «        | _        |j        | _        |j        | _        d S )N)r�   r}   r…   r  ©rR   )rU   rV   r©   r…   rú   Ú	self_attnrÑ   ÚmlprO   Úrms_norm_epsÚinput_layernormÚpost_attention_layernormÚsliding_windowr  r  s        €r<   rV   zMoshiDecoderLayer.__init__  s³   ø€ Ý‰Œ×ÒÑÔÐØ!Ô-ˆÔØ#6ˆÔ å'Ø YÐDWÐbjð
ñ 
ô 
ˆŒõ " &Ð*=Ñ>Ô>ˆŒÝ+¨DÔ,<À&ÔBUÐVÑVÔVˆÔÝ(4°TÔ5EÈ6ÔK^Ð(_Ñ(_Ô(_ˆÔ%Ø$Ô3ˆÔà$*Ô$?ˆÔ!Ð!Ð!r;   NFr-   rM   r½   r.   Úoutput_attentionsÚ	use_cacher	  r¡   c                 ó   — |}	|                       |¦  «        } | j        d|||||||dœ|¤Ž\  }}
|	|z   }|}	|                      |¦  «        }| j        s|                      |¦  «        n|                      ||¦  «        }|	|z   }|f}|r||
fz  }|S )N)r-   rM   r½   r.   r  r  r	  r:   )r  r  r  r…   r  )r[   r-   rM   r½   r.   r  r  r	  rë   ÚresidualÚself_attn_weightsÚoutputss               r<   ri   zMoshiDecoderLayer.forward  sæ   € ð !ˆà×,Ò,¨]Ñ;Ô;ˆð ,:¨4¬>ð 	,
Ø'Ø)Ø%Ø+Ø/ØØ%ð	,
ð 	,
ð ð	,
ð 	,
Ñ(ˆÐ(ð ! =Ñ0ˆð !ˆØ×5Ò5°mÑDÔDˆà+/Ô+CÐnˆD�HŠH�]Ñ#Ô#Ð#ÈÏÊÐR_ÐamÑInÔInð 	ð ! =Ñ0ˆà Ð"ˆàð 	,ØÐ)Ð+Ñ+ˆGàˆr;   )T)NNNFFN)r0   r1   r2   r!   rn   ÚboolrV   r4   r5   r7   r   r9   r8   ri   ro   rp   s   @r<   r  r    s$  ø€ € € € € ð@ð @˜{ð @°sð @ÐQUð @ð @ð @ð @ð @ð @ð& /3Ø04Ø(,Ø).Ø!&Ø,0ð)ð )à”|ð)ð œ tÑ+ð)ð Ô&¨Ñ-ð	)ð
  ™ð)ð   $™;ð)ð ˜$‘;ð)ð ”l TÑ)ð)ð 
ˆuÔ  %¨Ô(9¸5Ô;LÐ(LÔ"MÐPTÑ"TÐTÔ	Uð)ð )ð )ð )ð )ð )ð )ð )r;   r  c                   ó|   ‡ — e Zd ZU eed<   dZdZdZddgZdZ	dZ
dZdZdZ ej        ¦   «         ˆ fd„¦   «         Zˆ xZS )	ÚMoshiPreTrainedModelr�   Úmodel©ÚaudioÚtextTr  ÚMimiTransformerLayerrJ   c                 óª   •— t          ¦   «                              |¦  «         t          |t          ¦  «        rt	          j        |j        ¦  «         d S d S rT   )rU   Ú_init_weightsr·   rr   ÚinitÚnormal_rZ   )r[   rå   r\   s     €r<   r+  z"MoshiPreTrainedModel._init_weightsM  sP   ø€ å‰Œ×Ò˜fÑ%Ô%Ð%Ý�fÕ1Ñ2Ô2ð 	(ÝŒL˜œÑ'Ô'Ð'Ð'Ð'ð	(ð 	(r;   )r0   r1   r2   r!   r6   Úbase_model_prefixÚinput_modalitiesÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_supports_flash_attnÚ_supports_sdpaÚ_supports_flex_attnÚ_supports_attention_backendÚmain_input_namer4   rÃ   r+  ro   rp   s   @r<   r$  r$  ?  s’   ø€ € € € € € àÐÐÑØÐØ(ÐØ&*Ð#Ø,Ð.DÐEÐØÐØ€NØÐØ"&Ðà!€Oà€U„]�_„_ð(ð (ð (ð (ñ „_ð(ð (ð (ð (ð (r;   r$  c                   ó  ‡ — e Zd ZU dZeed<   defˆ fd„Z	 	 	 	 	 	 	 	 	 	 	 ddej        dz  dej        dz  dej	        dz  de
dz  d	ej        dz  d
edz  dedz  dedz  dedz  dej        dz  dej        dz  deez  fd„Zˆ xZS )ÚMoshiDepthDecoderz¥
    Transformer depth decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`MoshiTransformerLayer`]

    Args:
        config: MoshiConfig
    r�   c                 ól  •‡— t          ¦   «                              ‰¦  «         t          j        ‰j        dz   ‰j        ¦  «        | _        t          j        ˆfd„t          ‰j	        dz
  ¦  «        D ¦   «         ¦  «        | _
        t          ‰j        ‰j        ‰j	        ¦  «        | _        t          j        ˆfd„t          ‰j        ¦  «        D ¦   «         ¦  «        | _        t          ‰j        ‰j        ‰j	        ¦  «        | _        ‰j        | _        d| _        ‰| _        |                      ¦   «          d S )Nr    c                 óT   •— g | ]$}t          j        ‰j        d z   ‰j        ¦  «        ‘Œ%S ©r    ©rW   Ú	EmbeddingÚaudio_vocab_sizer©   ©Ú.0rÜ   r�   s     €r<   ú
<listcomp>z.MoshiDepthDecoder.__init__.<locals>.<listcomp>e  ó0   ø€ ÐtÐtÐtÈq�RŒ\˜&Ô1°AÑ5°vÔ7IÑJÔJÐtÐtÐtr;   c                 ó6   •— g | ]}t          ‰|d d¬¦  «        ‘ŒS )TF)r…   r  ©r  ©r@  r}   r�   s     €r<   rA  z.MoshiDepthDecoder.__init__.<locals>.<listcomp>k  s;   ø€ ð ð ð àõ " &¨)ÈÐX]Ð^Ñ^Ô^ðð ð r;   F)rU   rV   rW   r=  Ú
vocab_sizer©   Útext_embed_tokensÚ
ModuleListÚrangerŠ   Úembed_tokensrr   ru   Úinput_projectionsÚnum_hidden_layersÚlayersr>  Úlm_headsr  Úgradient_checkpointingr�   Ú	post_init©r[   r�   r\   s    `€r<   rV   zMoshiDepthDecoder.__init__^  s.  øø€ Ý‰Œ×Ò˜Ñ Ô Ð å!#¤¨fÔ.?À!Ñ.CÀVÔEWÑ!XÔ!XˆÔõ œMØtÐtÐtÐtÕTYÐZ`ÔZnÐqrÑZrÑTsÔTsÐtÑtÔtñ
ô 
ˆÔõ "5°VÔ5FÈÔHZÐ\bÔ\pÑ!qÔ!qˆÔå”mðð ð ð å!& vÔ'?Ñ!@Ô!@ðñ ô ñ
ô 
ˆŒõ ,¨FÔ,>ÀÔ@WÐY_ÔYmÑnÔnˆŒØ$*Ô$?ˆÔ!Ø&+ˆÔ#ØˆŒà�ŠÑÔÐÐÐr;   NrJ   r@   rM   r.   Úinputs_embedsr  r  Úoutput_hidden_statesÚreturn_dictr½   Úlabelsr¡   c           
      óì  — |�|n| j         j        }|�|n| j         j        }|�|n| j         j        }|	�|	n| j         j        }	| j        r%| j        r|rt                               d¦  «         d}|r|€t          | j         ¬¦  «        }|€dn| 
                    ¦   «         }t          j        |j        d         |j        ¬¦  «        |z   }|
€|                     d¦  «        }
|€¥g }|D ]Š}|                     ¦   «         }|dk    r4|                     |                      |dd…|gf         ¦  «        ¦  «         ŒP|                      | j        |dz
           |dd…||z
  gf         ¦  «        ¦  «         Œ‹t          j        |d¬¦  «        }||                      ||¦  «        z  }d}|�t-          | j         ||||
¬	¦  «        }|rd
nd}|rd
nd}|}| j        D ]2}|r||fz  } ||||
||||¬¦  «        }|d         }|r||d         fz  }Œ3|r||fz  }|                      ||¦  «        }d}|��|                     ¦   «         }t5          ¦   «         }|                     || j         j        k    d¦  «                             d¦  «        }|                     |j        ¦  «        } ||                     d| j         j        ¦  «        |¦  «        }|	st?          d„ |||||fD ¦   «         ¦  «        S tA          |||||¬¦  «        S )a  
        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens. The first element of the sequence must the text token associated to the audio codebooks.
                The rest of the elements must be flatten audio codebooks.
            last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
                Sequence of hidden-states at the output of the last layer of the main decoder. Used to contextualize `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)

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

                If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
                `past_key_values`).

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

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.
            past_key_values (`Cache`, *optional*):
                It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

                If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
                have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
                of shape `(batch_size, sequence_length)`.
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
                is useful if you want more control over how to convert the inputs into associated vectors than the
                model's internal embedding lookup matrix.
            use_cache (`bool`, *optional*):
                If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
                `past_key_values`).
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
                tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
                more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            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.n_positions - 1]`.

                [What are position IDs?](../glossary#position-ids)
            labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
                config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
                (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
        NúX`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`.F©r�   r   r    ©rž   rµ   ©r�   rR  rM   r.   r½   r:   )rM   r½   r.   r  r  r	  iœÿÿÿr^   c              3   ó   K  — | ]}|®|V — Œ	d S rT   r:   ©r@  Úvs     r<   ú	<genexpr>z,MoshiDepthDecoder.forward.<locals>.<genexpr>  s1   è è € ð ð ØÐabÐan�ÐanÐanÐanÐanðð r;   )r?   r*   r.   r-   r,   )!r�   r  rS  r  rT  rO  rî   ÚloggerÚwarning_oncer   Úget_seq_lengthr4   r«   rk   rž   rÉ   ÚitemÚappendrG  rJ  rº   rK  r   rM  rN  rf   r   Úmasked_fillr>  rß   r­   r9   r   )r[   rJ   r@   rM   r.   rR  r  r  rS  rT  r½   rU  rë   Úpast_seen_tokensr	  Úposition_idxÚcausal_maskÚall_hidden_statesÚall_self_attnsr-   Údecoder_layerÚlayer_outputsr*   r?   Úloss_fcts                            r<   ri   zMoshiDepthDecoder.forwardx  sé  € ðR 2CÐ1NÐ-Ð-ÐTXÔT_ÔTqÐà$8Ð$DÐ Ð È$Ì+ÔJjð 	ð "+Ð!6�I�I¸D¼KÔ<Qˆ	à%0Ð%<�k�kÀ$Ä+ÔBYˆàÔ&ð 	¨4¬=ð 	¸Yð 	Ý×ÒØjñô ð ð ˆIàð 	?˜Ð0Ý*°$´+Ð>Ñ>Ô>ˆOà /Ð 7˜1˜1¸_×=[Ò=[Ñ=]Ô=]ÐÝ”| I¤O°AÔ$6¸yÔ?OÐPÑPÔPÐScÑcˆàÐØ'×1Ò1°!Ñ4Ô4ˆLð Ð ØˆMØ ,ð ð �Ø+×0Ò0Ñ2Ô2�Ø 1Ò$Ð$Ø!×(Ò(¨×)?Ò)?À	È!È!È!ÈlÈ^ÐJ[Ô@\Ñ)]Ô)]Ñ^Ô^Ð^Ð^à!×(Ò(Ø=˜Ô)¨<¸!Ñ+;Ô=¸iÈÈÈÈLÐ[kÑLkÐKlÐHlÔ>mÑnÔnñô ð ð õ "œI m¸Ð;Ñ;Ô;ˆMà˜×/Ò/Ð0AÀ<ÑPÔPÑPˆàˆØÐ%Ý,Ø”{Ø+Ø-Ø /Ø)ðñ ô ˆKð #7Ð@˜B˜B¸DÐØ0Ð:˜˜°dˆØ%ˆØ!œ[ð 	6ð 	6ˆMØ#ð 6Ø! mÐ%5Ñ5Ð!à)˜MØØ*Ø)Ø /Ø"3Ø#Ø)ðñ ô ˆMð *¨!Ô,ˆMà ð 6Ø =°Ô#3Ð"5Ñ5�øð  ð 	2Ø -Ð!1Ñ1Ðà—’˜}¨lÑ;Ô;ˆàˆØÐà—\’\‘^”^ˆFÝ'Ñ)Ô)ˆHà×'Ò'¨°$´+Ô2NÒ(NÐPTÑUÔU×]Ò]Ð^`ÑaÔaˆFØ—Y’Y˜vœ}Ñ-Ô-ˆFØ�8˜FŸNšN¨2¨t¬{Ô/KÑLÔLÈfÑUÔUˆDàð 	Ýð ð Ø  &¨/Ð;LÈnÐ]ðñ ô ñ ô ð õ &ØØØ+Ø)Ø%ð
ñ 
ô 
ð 	
r;   )NNNNNNNNNNN)r0   r1   r2   r3   r"   r6   rV   r4   r7   Ú
BoolTensorr   r8   r"  r9   r   ri   ro   rp   s   @r<   r8  r8  T  sp  ø€ € € € € € ðð ð ÐÐÑðÐ/ð ð ð ð ð ð ð8 .2Ø59Ø26Ø(,Ø26Ø!%Ø)-Ø,0Ø#'Ø04Ø*.ðl
ð l
àÔ# dÑ*ðl
ð !Ô+¨dÑ2ðl
ð Ô(¨4Ñ/ð	l
ð
  ™ðl
ð Ô(¨4Ñ/ðl
ð ˜$‘;ðl
ð   $™;ðl
ð # T™kðl
ð ˜D‘[ðl
ð Ô&¨Ñ-ðl
ð Ô  4Ñ'ðl
ð 
Ð(Ñ	(ðl
ð l
ð l
ð l
ð l
ð l
ð l
ð l
r;   r8  c                   óÜ   ‡ — e Zd Zdefˆ fd„Ze	 	 	 	 	 	 	 	 	 ddej        dz  dej        dz  dej        dz  de	dz  dej
        dz  d	edz  d
edz  dedz  dedz  deez  fd„¦   «         Zˆ xZS )Ú
MoshiModelr�   c                 óº  •‡— t          ¦   «                              ‰¦  «         ‰j        | _        ‰j        | _        t          j        ‰j        dz   ‰j        | j        ¦  «        | _        t          j	        ˆfd„t          ‰j        ¦  «        D ¦   «         ¦  «        | _        t          ‰j        ‰j        ¬¦  «        | _        d| _        |                      ¦   «          d S )Nr    c                 ó4   •— g | ]}t          ‰|d ¬¦  «        ‘ŒS )F)r…   rD  rE  s     €r<   rA  z'MoshiModel.__init__.<locals>.<listcomp>0  s8   ø€ ð ð ð àõ " &¨)ÈÐOÑOÔOðð ð r;   r  F)rU   rV   Úpad_token_idÚpadding_idxrF  rW   r=  r©   rJ  rH  rI  rL  rM  rO   r  ÚnormrO  rP  rQ  s    `€r<   rV   zMoshiModel.__init__)  sÖ   øø€ Ý‰Œ×Ò˜Ñ Ô Ð Ø!Ô.ˆÔØ Ô+ˆŒåœL¨Ô):¸QÑ)>ÀÔ@RÐTXÔTdÑeÔeˆÔÝ”mðð ð ð å!& vÔ'?Ñ!@Ô!@ðñ ô ñ
ô 
ˆŒõ ! Ô!3¸Ô9LÐMÑMÔMˆŒ	Ø&+ˆÔ#ð 	�ŠÑÔÐÐÐr;   NrJ   rM   r½   r.   rR  r  r  rS  rT  r¡   c
           	      óP  — |�|n| j         j        }|�|n| j         j        }|�|n| j         j        }|	�|	n| j         j        }	| j        r%| j        r|rt                               d¦  «         d}|€|  	                    |¦  «        }|€V|�| 
                    ¦   «         nd}t          j        |j        d         |j        ¬¦  «        |z   }|                     d¦  «        }d }|�t!          | j         ||||¬¦  «        }|}|r|€t#          | j         ¬¦  «        }|rdnd }|rdnd }| j        D ]1}|r||fz  } |||||||¬	¦  «        }|d         }|r||d         fz  }Œ2|                      |¦  «        }|r||fz  }|	st)          d
„ ||||fD ¦   «         ¦  «        S t+          ||||¬¦  «        S )NrW  Fr   r    rY  rZ  rX  r:   )rM   r½   r.   r  r  c              3   ó   K  — | ]}|®|V — Œ	d S rT   r:   r\  s     r<   r^  z%MoshiModel.forward.<locals>.<genexpr>‹  s1   è è € ð ð ØÐbcÐbo�ÐboÐboÐboÐboðð r;   )r@   r.   r-   r,   )r�   r  rS  r  rT  rO  rî   r_  r`  rJ  ra  r4   r«   rk   rž   rÉ   r   r   rM  rt  r9   r   )r[   rJ   rM   r½   r.   rR  r  r  rS  rT  rë   re  rg  r-   rh  ri  rj  rk  s                     r<   ri   zMoshiModel.forward;  s‡  € ð 2CÐ1NÐ-Ð-ÐTXÔT_ÔTqÐà$8Ð$DÐ Ð È$Ì+ÔJjð 	ð "+Ð!6�I�I¸D¼KÔ<Qˆ	Ø%0Ð%<�k�kÀ$Ä+ÔBYˆàÔ&ð 	¨4¬=ð 	¸Yð 	Ý×ÒØjñô ð ð ˆIàÐ Ø ×-Ò-¨iÑ8Ô8ˆMàÐØCRÐC^˜×=Ò=Ñ?Ô?Ð?ÐdeÐÝ œ<¨Ô(;¸AÔ(>À}ÔG[Ð\Ñ\Ô\Ð_oÑoˆLØ'×1Ò1°!Ñ4Ô4ˆLàˆØÐ%Ý,Ø”{Ø+Ø-Ø /Ø)ðñ ô ˆKð &ˆàð 	?˜Ð0Ý*°$´+Ð>Ñ>Ô>ˆOð #7Ð@˜B˜B¸DÐØ0Ð:˜˜°dˆà!œ[ð 	6ð 	6ˆMØ#ð 6Ø! mÐ%5Ñ5Ð!à)˜MØØ*Ø)Ø /Ø"3Ø#ðñ ô ˆMð *¨!Ô,ˆMà ð 6Ø =°Ô#3Ð"5Ñ5�øàŸ	š	 -Ñ0Ô0ˆð  ð 	2Ø -Ð!1Ñ1Ðàð 	Ýð ð Ø)¨?Ð<MÈ~Ð^ðñ ô ñ ô ð õ 'Ø+Ø+Ø+Ø%ð	
ñ 
ô 
ð 	
r;   )	NNNNNNNNN)r0   r1   r2   r!   rV   r   r4   r7   r5   r   r8   r"  r9   r   ri   ro   rp   s   @r<   ro  ro  '  s4  ø€ € € € € ð˜{ð ð ð ð ð ð ð$ ð .2Ø.2Ø04Ø(,Ø26Ø!%Ø)-Ø,0Ø#'ðW
ð W
àÔ# dÑ*ðW
ð œ tÑ+ðW
ð Ô&¨Ñ-ð	W
ð
  ™ðW
ð Ô(¨4Ñ/ðW
ð ˜$‘;ðW
ð   $™;ðW
ð # T™kðW
ð ˜D‘[ðW
ð 
Ð(Ñ	(ðW
ð W
ð W
ñ „^ðW
ð W
ð W
ð W
ð W
r;   ro  zc
    The Moshi decoder model with a text language modelling head on top. Only usable for text.
    c                   ó  ‡ — e Zd ZdZˆ fd„Ze	 	 	 	 	 	 	 	 	 	 	 ddej        dz  dej        dz  dej        dz  de	dz  d	ej
        dz  d
edz  dedz  dedz  dedz  dej        dz  deej        z  deez  fd„¦   «         Zˆ xZS )ÚMoshiForCausalLM)r(  c                 óþ   •— t          ¦   «                              |¦  «         t          |¦  «        | _        |j        | _        t          j        |j        |j        d¬¦  «        | _        |  	                    ¦   «          d S )NFrƒ   )
rU   rV   ro  r%  rF  rW   r†   r©   Úlm_headrP  rQ  s     €r<   rV   zMoshiForCausalLM.__init__Ÿ  sj   ø€ Ý‰Œ×Ò˜Ñ Ô Ð Ý Ñ'Ô'ˆŒ
Ø Ô+ˆŒÝ”y Ô!3°VÔ5FÈUÐSÑSÔSˆŒð 	�ŠÑÔÐÐÐr;   Nr   rJ   rM   r½   r.   rR  r  r  rS  rT  rU  Úlogits_to_keepr¡   c                 óB  — |�|n| j         j        }|�|n| j         j        }|	�|	n| j         j        }	|                      |||||||||	¬¦	  «	        }|d         }t          |t          ¦  «        rt          | d¦  «        n|}|                      |dd…|dd…f         ¦  «        }d}|
�½| 	                    ¦   «         }|ddd…dd…f          
                    ¦   «         }|
ddd…f          
                    ¦   «         }|                     d| j         j        ¦  «        }|                     d¦  «        }|                     |j        ¦  «        } | j        ||fd| j         j        i|¤Ž}|	s||f|dd…         z   }|�|f|z   n|S t!          ||||j        |j        |j        ¬¦  «        S )	a!  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
            config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
            (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

        Example:

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

        >>> model = MoshiForCausalLM.from_pretrained("kmhf/hf-moshiko")
        >>> tokenizer = AutoTokenizer.from_pretrained("kmhf/hf-moshiko")

        >>> prompt = "What is your favorite condiment?"
        >>> inputs = tokenizer(prompt, return_tensors="pt")

        >>> # Generate
        >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
        >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
        "What is your favorite condiment?"
        ```N)	rJ   rM   r½   r.   rR  r  r  rS  rT  r   .r^   r    rF  )r?   r*   r@   r.   r-   r,   )r�   r  rS  rT  r%  r·   rn   Úslicerz  rf   ró   rÙ   rF  r­   rž   Úloss_functionr>   r.   r-   r,   )r[   rJ   rM   r½   r.   rR  r  r  rS  rT  rU  r{  rë   r!  r-   Úslice_indicesr*   r?   Úshift_logitsÚshift_labelsrh   s                        r<   ri   zMoshiForCausalLM.forward¨  s  € ðL 2CÐ1NÐ-Ð-ÐTXÔT_ÔTqÐà$8Ð$DÐ Ð È$Ì+ÔJjð 	ð &1Ð%<�k�kÀ$Ä+ÔBYˆð —*’*ØØ)Ø%Ø+Ø'ØØ/Ø!5Ø#ð ñ 

ô 

ˆð   œ
ˆå8BÀ>ÕSVÑ8WÔ8WÐk�˜~˜o¨tÑ4Ô4Ð4Ð]kˆØ—’˜m¨A¨A¨A¨}¸a¸a¸aÐ,?Ô@ÑAÔAˆàˆØÐà—\’\‘^”^ˆFà! # s¨ s¨A¨A¨A +Ô.×9Ò9Ñ;Ô;ˆLØ! # q r r 'œ?×5Ò5Ñ7Ô7ˆLà'×,Ò,¨R°´Ô1GÑHÔHˆLØ'×,Ò,¨RÑ0Ô0ˆLØ'Ÿ?š?¨<Ô+>Ñ?Ô?ˆLØ%�4Ô%ØØðð ð  œ;Ô1ðð ð	ð ˆDð ð 	DàØðð ˜˜˜”ñˆFð (,Ð'7�D�7˜VÑ#Ð#¸VÐCå*ØØØ+Ø#Ô3Ø!Ô/ØÔ)ð
ñ 
ô 
ð 	
r;   )NNNNNNNNNNr   )r0   r1   r2   r/  rV   r   r4   r7   r5   r   r8   r"  rn   r9   r>   ri   ro   rp   s   @r<   rx  rx  –  s[  ø€ € € € € ð !Ððð ð ð ð ð ð .2Ø.2Ø04Ø(,Ø26Ø!%Ø)-Ø,0Ø#'Ø*.Ø-.ð]
ð ]
àÔ# dÑ*ð]
ð œ tÑ+ð]
ð Ô&¨Ñ-ð	]
ð
  ™ð]
ð Ô(¨4Ñ/ð]
ð ˜$‘;ð]
ð   $™;ð]
ð # T™kð]
ð ˜D‘[ð]
ð Ô  4Ñ'ð]
ð ˜eœlÑ*ð]
ð 
Ð,Ñ	,ð]
ð ]
ð ]
ñ „^ð]
ð ]
ð ]
ð ]
ð ]
r;   rx  zz
    The original Moshi model with an audio encoder, a Moshi depth decoder and a Moshi decoder, for speech-to-speech.
    c            !       ó`  ‡ — e Zd ZU eed<   dZdZdZdZdZ	dZ
dZdefˆ fd„Zd„ Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 d6dej        dz  dej        dz  d	ej        dz  d
ej        dz  dej        dz  dej        dz  dedz  dej        dz  dej        dz  dej        dz  dedz  dedz  dedz  dedz  deez  fd„¦   «         Zdej        dedeeef         dej        fd„Z	 	 	 	 	 	 	 	 	 	 d7dej        dz  d	ej        dz  d
ej        dz  dej        dz  dej        dz  dej        dz  dej        dz  dedz  dedefd„Z ej        ¦   «         	 	 	 	 	 	 	 	 	 d8dej        dz  d	ej        dz  d
ej        dz  dej        dz  dej        dz  dej        dz  dedz  dedz  dedz  dej        fˆ fd „¦   «         Z 	 	 	 	 	 	 	 	 	 	 	 d9d!ej        dz  fˆ fd"„Z!	 	 d:d$e"d%eeef         d&ed'e#deeef         f
ˆ fd(„Z$d)„ Z%d*„ Z&d+„ Z'd,„ Z(d-„ Z)d.„ Z*e+d/„ ¦   «         Z,	 d;dej        d0e#d1e#d2e#dz  fd3„Z-d<d4„Z.	 	 	 	 	 	 	 d=d5„Z/ˆ xZ0S )>ÚMoshiForConditionalGenerationr�   r&  rJ   Tc                 ó¬  •‡— t          ¦   «                              ‰¦  «         t          j        ˆfd„t	          d‰j        z  ¦  «        D ¦   «         ¦  «        | _        t          j        ‰j	        ¦  «        | _
        t          ‰¦  «        | _        t                               ‰j        ¦  «        | _        ‰j        | _        |                      ¦   «          d S )Nc                 óT   •— g | ]$}t          j        ‰j        d z   ‰j        ¦  «        ‘Œ%S r;  r<  r?  s     €r<   rA  z:MoshiForConditionalGeneration.__init__.<locals>.<listcomp>  rB  r;   r   )rU   rV   rW   rH  rI  rŠ   rJ  r   Úfrom_configÚaudio_encoder_configÚaudio_encoderrx  Údecoderr8  Ú_from_configÚdepth_decoder_configÚdepth_decoderrP  rQ  s    `€r<   rV   z&MoshiForConditionalGeneration.__init__  s»   øø€ Ý‰Œ×Ò˜Ñ Ô Ð åœMØtÐtÐtÐtÕTYÐZ[Ð^dÔ^rÑZrÑTsÔTsÐtÑtÔtñ
ô 
ˆÔõ 'Ô2°6Ô3NÑOÔOˆÔÝ'¨Ñ/Ô/ˆŒå.×;Ò;¸FÔ<WÑXÔXˆÔà#Ô1ˆÔØ�ŠÑÔÐÐÐr;   c                 ó   — | j         S rT   ©rŒ  rl   s    r<   Úget_depth_decoderz/MoshiForConditionalGeneration.get_depth_decoder&  s   € ØÔ!Ð!r;   NrM   Úuser_input_valuesrK   Úmoshi_input_valuesrL   r.   rR  Útext_labelsÚaudio_labelsr  r  rS  rT  r¡   c                 ó
  ‡ ‡— |�|n‰ j         j        }d„ |                     ¦   «         D ¦   «         }d„ |                     ¦   «         D ¦   «         }d„ |                     ¦   «         D ¦   «         }|€ë|�"|€  ‰ j        j        |fd‰ j        i|¤Žd         }|�"|€  ‰ j        j        |fd‰ j        i|¤Žd         }t          j        ||gd¬¦  «        Š|€‰€t          d	¦  «        ‚|�‰ j	        j
                             |¦  «        }‰�Ut          ˆˆ fd
„t          ‰j        d         ¦  «        D ¦   «         ¦  «        }|€|n||                     |j        ¦  «        z   } ‰ j	        d||||||d|	dœ|¤Ž}|j        }d}|j        }|	�ò|
�ð‰                      |
‰ j         j        ‰ j         j        |
j        d         dz   ¬¦  «        d         }
|	                     dd¦  «        }	|
                     dd¦  «                             d|
j        d         ¦  «        }
t          j        |	|
gd¬¦  «        }|dd…dd…f         }|                     dd|j        d         ¦  «        } ‰ j        d||||
dœ|¤Ž}||j        z  }|s/|                     ¦   «         }|�||                     ¦   «         z  }|S t5          |j        |j        ||j        |j        |j        |€dn|j        |€dn|j        |€dn|j        |€dn|j        |€dn|j        ¬¦  «        S )a¡  
        user_input_values (`torch.Tensor `of shape `(batch_size, 1, audio_sequence_length), *optional*):
            The audio waveforms used as audio user prompt for the generation.
        user_audio_codes (`torch.Tensor `of shape `(batch_size, num_codebooks, sequence_length), *optional*):
            The audio codes used as audio user prompt for the generation. Has priority over `user_input_values` and represents the audio "tokens" of `user_input_values` once passed through the audio encoder.
        moshi_input_values (`torch.Tensor `of shape `(batch_size, 1, audio_sequence_length), *optional*):
            The audio waveforms used as audio Moshi prompt for the generation.
        moshi_audio_codes (`torch.Tensor `of shape `(batch_size, num_codebooks, sequence_length), *optional*):
            The audio codes used as audio Moshi prompt for the generation. Has priority over `moshi_input_values` and represents the audio "tokens" of `moshi_input_values` once passed through the audio encoder.
        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. If `past_key_values` is used, optionally only the last `inputs_embeds` have to be
            input (see `past_key_values`). 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 `input_ids` and `inputs_embeds` are both unset, `inputs_embeds` takes the value
            of `inputs_embeds`.
        text_labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for text 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]`
        audio_labels (`torch.LongTensor` of shape `(batch_size, num_codebooks, 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.audio_vocab_size]`

        Examples:
        ```python
        >>> from transformers import MoshiForConditionalGeneration
        >>> import torch

        >>> model = MoshiForConditionalGeneration.from_pretrained("kmhf/hf-moshiko")
        >>> inputs = moshi.get_unconditional_inputs()

        >>> logits = model(**inputs, ).logits
        >>> logits.shape  # (bsz, seq_len, text_vocab_size)
        torch.Size([1, 1, 32000])
        ```Nc                 ój   — i | ]0\  }}|                      d ¦  «        ¯|t          d ¦  «                 |“Œ1S )Úaudio_encoder_©Ú
startswithÚlen©r@  Úargumentrè   s      r<   ú
<dictcomp>z9MoshiForConditionalGeneration.forward.<locals>.<dictcomp>d  sQ   € ð  
ð  
ð  
á�˜%Ø×"Ò"Ð#3Ñ4Ô4ð 
Ø•SÐ)Ñ*Ô*Ô+¨Uð 
ð  
ð  
r;   c                 ón   — i | ]2\  }}|                      d ¦  «        ¯|t          d ¦  «        d…         |“Œ3S )Údecoder_Nr—  rš  s      r<   rœ  z9MoshiForConditionalGeneration.forward.<locals>.<dictcomp>j  sT   € ð 
ð 
ð 
Ù3B°8¸UÐX`×XkÒXkÐlvÑXwÔXwð
Ø•S˜‘_”_Ð&Ð&Ô'¨ð
ð 
ð 
r;   c                 ón   — i | ]2\  }}|                      d ¦  «        ¯|t          d ¦  «        d…         |“Œ3S ©Údepth_decoder_Nr—  rš  s      r<   rœ  z9MoshiForConditionalGeneration.forward.<locals>.<dictcomp>n  sW   € ð  
ð  
ð  
á�˜%Ø×"Ò"Ð#3Ñ4Ô4ð 
Ø•SÐ)Ñ*Ô*Ð,Ð,Ô-¨uð 
ð  
ð  
r;   Únum_quantizersr   r    rµ   z`You must provide at least one of `input_ids`, `inputs_embeds`, `input_values` and `audio_codes`.c              3   óX   •K  — | ]$} ‰j         |         ‰d d …|f         ¦  «        V — Œ%d S rT   ©rJ  ©r@  Úcodebookr/   r[   s     €€r<   r^  z8MoshiForConditionalGeneration.forward.<locals>.<genexpr>‹  óT   øè è € ð *ð *ØNVÐ/�DÔ% hÔ/°¸A¸A¸A¸x¸KÔ0HÑIÔIð*ð *ð *ð *ð *ð *r;   T)rM   rR  r  rS  r  r.   rT  rU  r^   ©Úbos_token_idrr  Ú
max_lengthr   )r@   rJ   rM   rU  )r?   r*   r@   r.   r-   r,   rC   rD   rE   rF   rG   r:   )r�   rT  Úitemsrˆ  ÚencoderŠ   r4   rº   r  r‰  r%  rJ  ÚsumrI  rk   r­   rž   r@   r?   Úbuild_delay_pattern_maskr>  rÙ   rz   rß   rŒ  Úto_tuplerB   r*   r.   r-   r,   )r[   rJ   rM   r�  rK   r‘  rL   r.   rR  r’  r“  r  r  rS  rT  rë   Úkwargs_audio_encoderÚkwargs_decoderÚkwargs_depth_decoderÚaudio_inputs_embedsÚdecoder_outputsÚdecoder_last_hidden_stateÚdepth_decoder_outputsÚ
final_lossÚdepth_input_idsr!  r/   s   `                         @r<   ri   z%MoshiForConditionalGeneration.forward)  sS  øø€ ðr &1Ð%<�k�kÀ$Ä+ÔBYˆð 
ð  
à#)§<¢<¡>¤>ð 
ñ  
ô  
Ðð
ð 
ØFLÇlÂlÁnÄnð
ñ 
ô 
ˆð 
ð  
à#)§<¢<¡>¤>ð 
ñ  
ô  
Ðð Ð Ø Ð,Ð1AÐ1IØ#< 4Ô#5Ô#<Ø%ð$ð $Ø6:Ô6Hð$ØL`ð$ð $àô$Ð ð "Ð-Ð2CÐ2KØ$= DÔ$6Ô$=Ø&ð%ð %Ø7;Ô7Ið%ØMað%ð %àô%Ð!õ  œ)Ð%6Ð8HÐ$IÈqÐQÑQÔQˆKàÐ  [Ð%8Ý Øvñô ð ð Ð$Ø $¤Ô 2× ?Ò ?À	Ñ JÔ J�àÐ&Ý&)ð *ð *ð *ð *ð *ÝZ_Ð`kÔ`qÐrsÔ`tÑZuÔZuð*ñ *ô *ñ 'ô 'Ð#ð
 %Ð,ð (Ð'à,¨}×/?Ò/?Ð@SÔ@ZÑ/[Ô/[Ñ[ð ð '˜$œ,ð 

Ø)Ø'Ø/Ø!5ØØ+ØØð

ð 

ð ð

ð 

ˆð %4Ô$EÐ!à $ÐØ$Ô)ˆ
ØÐ" |Ð'?ð  ×8Ò8ØØ!œ[Ô9Ø!œ[Ô9Ø'Ô-¨bÔ1°AÑ5ð	 9ñ ô ð
 ôˆLð &×*Ò*¨2¨qÑ1Ô1ˆKð (×1Ò1°!°QÑ7Ô7×?Ò?ÀÀLÔDVÐWXÔDYÑZÔZˆLå#œi¨°lÐ(CÈÐKÑKÔKˆOà-¨a¨a¨a°°"°¨fÔ5ˆOð )B×(FÒ(FÀrÈ1ÐNgÔNmÐnpÔNqÑ(rÔ(rÐ%à$6 DÔ$6ð %Ø";Ø)Ø-Ø#ð	%ð %ð
 'ð%ð %Ð!ð Ð/Ô4Ñ4ˆJàð 	Ø%×.Ò.Ñ0Ô0ˆGØ$Ð0ØÐ0×9Ò9Ñ;Ô;Ñ;�ØˆNå7Ø Ô%Ø"Ô)Ø7Ø+Ô;Ø)Ô7Ø&Ô1Ø4Ð<�t�tÐBWÔB\Ø!6Ð!>˜˜ÐDYÔD`Ø*9Ð*A $ $ÀÔGfØ(7Ð(?  À_ÔEbØ%4Ð%<˜T˜TÀ/ÔB\ð
ñ 
ô 
ð 	
r;   Úgeneration_configrë   c                 óž  — |j         }|j        }t          j        |j        t          j        |j        ¬¦  «        }|€|S |d uo&t          j        ||¦  «                             ¦   «         }|d u p't          j        ||¦  «                             ¦   «          }||z  }	| 	                    |¦  «                             ¦   «         }
|
|	z  ||	 z  z   }|S )N©r¦   rž   )
rr  Úeos_token_idr4   rY   rk   Úlongrž   ÚisinÚanyÚne)r[   rJ   r¹  rë   rr  r¼  Údefault_attention_maskÚis_pad_token_in_inputsÚ&is_pad_token_not_equal_to_eos_token_idÚcan_infer_attention_maskÚattention_mask_from_paddingrM   s               r<   Ú&_prepare_attention_mask_for_generationzDMoshiForConditionalGeneration._prepare_attention_mask_for_generationÚ  sï   € ð )Ô5ˆØ(Ô5ˆå!&¤¨I¬OÅ5Ä:ÐV_ÔVfÐ!gÑ!gÔ!gÐØÐØ)Ð)à".°dÐ":Ð!iÅÄ
È9ÐVbÑ@cÔ@c×@gÒ@gÑ@iÔ@iÐØ2>À$Ð2Fð 2ÍEÌJØ˜,ñM
ô M
ç
Š#‰%Œ%ðLÐ.ð $:Ð<bÑ#bÐ Ø&/§l¢l°<Ñ&@Ô&@×&EÒ&EÑ&GÔ&GÐ#ð (Ð*BÑBÐE[Ð_wÐ^wÑEwÑwð 	ð Ðr;   FÚapply_delay_pattern_maskÚconcat_unconditional_inputsc                 óB  ‡ ‡— d }d }|€|€|€|€|€|€t          d¦  «        ‚|�|	rV|�)|€'‰ j                             |‰ j        ¬¦  «        d         }|�)|€'‰ j                             |‰ j        ¬¦  «        d         }|€™|
r—‰                      |j        d         ¬¦  «        }t          j        |j        |gd¬¦  «        }t          j        |j	        |gd¬¦  «        }t          j        |j
        |gd¬¦  «        }|�t          j        |j        |gd¬¦  «        }|�|	rr|	r7|�5‰                      |‰ j        j        ‰ j        j        |j        ¬¦  «        \  }}|	r7|�5‰                      |‰ j        j        ‰ j        j        |j        ¬¦  «        \  }}|�€d }|�O|�Mt          j        ||gd¬¦  «        Št!          ˆˆ fd	„t#          ‰j        d         ¦  «        D ¦   «         ¦  «        }nq|�7|Št!          ˆˆ fd
„t#          ‰j        d         ¦  «        D ¦   «         ¦  «        }n8|�6|Št!          ˆˆ fd„t#          ‰j        d         ¦  «        D ¦   «         ¦  «        }|�‰ j        j                             |¦  «        }|�!|€|n||                     |j        ¦  «        z   }|||||||fS )Nz”You must provide at least one of `input_ids`, `user_input_values`, `moshi_input_values`, `user_audio_codes`, `moshi_audio_codes` or `inputs_embeds`.©r¢  r   )Únum_samplesr   rµ   r    r¨  c              3   óX   •K  — | ]$} ‰j         |         ‰d d …|f         ¦  «        V — Œ%d S rT   r¤  r¥  s     €€r<   r^  zVMoshiForConditionalGeneration._prepare_inputs_embeds_for_generation.<locals>.<genexpr>5  r§  r;   c              3   óX   •K  — | ]$} ‰j         |         ‰d d …|f         ¦  «        V — Œ%d S rT   r¤  r¥  s     €€r<   r^  zVMoshiForConditionalGeneration._prepare_inputs_embeds_for_generation.<locals>.<genexpr>:  r§  r;   c              3   óh   •K  — | ],} ‰j         |         ‰d d …|‰j        z   f         ¦  «        V — Œ-d S rT   )rJ  rŠ   r¥  s     €€r<   r^  zVMoshiForConditionalGeneration._prepare_inputs_embeds_for_generation.<locals>.<genexpr>?  s_   øè è € ð *ð *à ð 0�DÔ% hÔ/°¸A¸A¸A¸xÈ$ÔJ\Ñ?\Ð<\Ô0]Ñ^Ô^ð*ð *ð *ð *ð *ð *r;   )r  rˆ  r¬  rŠ   Úget_unconditional_inputsrk   r4   rº   rL   rK   rJ   rM   r®  r�   r>  rª  r­  rI  r‰  r%  rJ  r­   rž   )r[   rJ   r�  rK   r‘  rL   rR  rM   r¹  rÇ  rÈ  Úuser_delay_pattern_maskÚmoshi_delay_pattern_maskÚunconditional_inputsr³  r/   s   `              @r<   Ú%_prepare_inputs_embeds_for_generationzCMoshiForConditionalGeneration._prepare_inputs_embeds_for_generationó  sÅ  øø€ ð #'ÐØ#'Ð ð Ð!ØÐ!Ø!Ð)Ø Ð(Ø"Ð*Ø!Ð)åð gñô ð ð
 Ð Ð$<Ð Ø Ð,Ð1AÐ1IØ#'Ô#5×#<Ò#<Ð=NÐ_cÔ_qÐ#<Ñ#rÔ#rÐstÔ#uÐ à!Ð-Ð2CÐ2KØ$(Ô$6×$=Ò$=Ð>PÐaeÔasÐ$=Ñ$tÔ$tÐuvÔ$wÐ!àÐ Ð%@Ð Ø#'×#@Ò#@ÐM]ÔMcÐdeÔMfÐ#@Ñ#gÔ#gÐ Ý %¤	Ð+?Ô+QÐSdÐ*eÐklÐ mÑ mÔ mÐÝ$œyÐ*>Ô*OÐQaÐ)bÐhiÐjÑjÔjÐÝœ	Ð#7Ô#AÀ9Ð"MÐSTÐUÑUÔUˆIØÐ)Ý!&¤Ð,@Ô,OÐQ_Ð+`ÐfgÐ!hÑ!hÔ!h�àÐ Ð$<Ð Ø'ð Ð,<Ð,HØ<@×<YÒ<YØ$Ø!%¤Ô!=Ø!%¤Ô!=Ø0Ô;ð	 =Zñ =ô =Ñ9Ð Ð"9ð (ð Ð,=Ð,IØ>B×>[Ò>[Ø%Ø!%¤Ô!=Ø!%¤Ô!=Ø0Ô;ð	 ?\ñ ?ô ?Ñ;Ð!Ð#;ð Ñ Ø"&ÐØÐ+Ð0AÐ0MÝ#œiÐ):Ð<LÐ(MÐSTÐUÑUÔU�Ý&)ð *ð *ð *ð *ð *ÝZ_Ð`kÔ`qÐrsÔ`tÑZuÔZuð*ñ *ô *ñ 'ô 'Ð#Ð#ð #Ð.Ø/�Ý&)ð *ð *ð *ð *ð *ÝZ_Ð`kÔ`qÐrsÔ`tÑZuÔZuð*ñ *ô *ñ 'ô 'Ð#Ð#ð "Ð-Ø.�Ý&)ð *ð *ð *ð *ð *å$)¨+Ô*;¸AÔ*>Ñ$?Ô$?ð*ñ *ô *ñ 'ô 'Ð#ð
 Ð$Ø $¤Ô 2× ?Ò ?À	Ñ JÔ J�à"Ð.ð %Ð,ð (Ð'à,¨}×/?Ò/?Ð@SÔ@ZÑ/[Ô/[Ñ[ð ð ØØØØ#Ø$Øð
ð 	
r;   Úreturn_audio_waveformsÚreturn_audio_codesc
                 ó0  •‡
‡$— t          | d¦  «        r¼t          | j        d¦  «        s§i | j        _        d| j        v r| j        | j        _        nXd„ | j                             ¦   «         D ¦   «         d         Š$ˆ$fd„| j                             ¦   «         D ¦   «         | j        _        d„ | j                             ¦   «         D ¦   «         | _        d„ ‰
D ¦   «         }ˆ
fd„|D ¦   «         } | j        ‰
                     d	d
¦  «        fi ‰
¤Ž\  }Š
|                      |||||||	¬¦  «        \  }}}}	|€|n|}|	r|j        d         dz   n|j        d         }‰
 	                    d¦  «        d
u o|j
        d
u}‰
 	                    d¦  «        d
u o|j        d
u}|                      ||||€dnd||¬¦  «        }t          |d¦  «        r|j        }n| j        dz   | j        dz   ddœ}|                     |¦  «         |}‰
                     dd
¦  «        }|€|                      ||‰
¬¦  «        }|                      ||||||||d|	¬¦
  «
        \  }}}}}}}t%          j        |j        d         dt)          | j        j        | j        j        j        z  ¦  «        f| j        | j        ¬¦  «        }| j                             || j        ¬¦  «        d         }|�|n‰
 	                    d¦  «        ‰
d<   |�|n‰
 	                    d¦  «        ‰
d<   t%          j        |t=          |j        |j         ¦  «        d¬¦  «        | _!        |j        dk    p|j"        }|j        dk    p|j#        } tI          ¦   «         j%        d%||||||||dœ‰
¤Ž}|s|s|r|j"        s|j&        S |S |s|}n|j&        }|j         dk    rt%          j        ||j         d¬¦  «        }|j        dk    rö|j'        d
d
…d
|j        d          …f         }| j!        d
d
…d
d
…|j        d         d
…f         }|d
d
…d
d…f          (                    d¦  «         )                    d| j        d¦  «        }t%          j*        |d|¬ ¦  «        }t%          j        ||j         d¬¦  «        }t%          j+        ||fd!¬¦  «        | _!        t%          j,        | j-        d|d
d
…df         ¬ ¦  «        | _-        | j-         .                    dd| j-        j        d         ¦  «        } | j        j%        d%||d
d
…dd
…f          .                    dd¦  «        d"œ|¤Ž} | d
d
…dd
…f          (                    d!¦  «        } t%          j+        | j!        | gd!¬¦  «        | _!        |  /                    | j!        |¦  «        }!|| j        j0        k    }"|!|"          1                    |"j        d         | j        d¦  «        }!d
}#|r| j         2                    |!¦  «        j3        }#|r|!nd
}!|j"        rti          d%|#|!d#œ|¤ŽS ti          |#||!¬$¦  «        S )&as  
        Generates sequences of text token ids and audio tokens ids.

        Parameters:
            input_ids (`torch.Tensor `of shape `(batch_size, sequence_length), *optional*):
                The sequence used as a text prompt for the generation.
            user_input_values (`torch.Tensor `of shape `(batch_size, 1, audio_sequence_length), *optional*):
                The audio waveforms used as audio user prompt for the generation.
            user_audio_codes (`torch.Tensor `of shape `(batch_size, num_codebooks, sequence_length), *optional*):
                The audio codes used as audio user prompt for the generation. Has priority over `user_input_values` and represents the audio "tokens" of `user_input_values` once passed through the audio encoder.
            moshi_input_values (`torch.Tensor `of shape `(batch_size, 1, audio_sequence_length), *optional*):
                The audio waveforms used as audio Moshi prompt for the generation.
            moshi_audio_codes (`torch.Tensor `of shape `(batch_size, num_codebooks, sequence_length), *optional*):
                The audio codes used as audio Moshi prompt for the generation. Has priority over `moshi_input_values` and represents the audio "tokens" of `moshi_input_values` once passed through the audio encoder.
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` and the audio inputs you can choose to directly pass an embedded representation. This
                is useful if you want more control over how to convert the inputs into associated vectors than the
                model's internal embedding lookup matrix.
            return_audio_waveforms (`bool`, *optional*, defaults to `True`):
                If `False`, won't generate the audio waveforms.
            return_audio_codes (`bool`, *optional*):
                If `True`, will also returns the generated audio codes, i.e the intermediate audio "tokens" which transforms to `audio_sequences` once passed through the audio decoder.
            concat_unconditional_inputs (`bool`, *optional*, defaults to `True`):
                If `False`, won't concatenate initial audio and text tokens.
            kwargs (`dict[str, Any]`, *optional*):
                Remaining dictionary of keyword arguments that are passed to the `generate` method. Refers to the
                original [`generate` docstrings](https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.GenerationMixin.generate)
                for more information on how to use them.
                Note that keywords with a *depth_* prefix will be input for the `generate` method of the
                depth decoder. Otherwise, the latter will use its default generation config.
        Return:
            [`MoshiConditionalGenerationGenerateOutput`]
        Úhf_device_mapÚ c                 ó   — g | ]}|d v¯|‘Œ	S )©r²   Údiskr:   )r@  Úds     r<   rA  z:MoshiForConditionalGeneration.generate.<locals>.<listcomp>�  s#   € ÐbÐbÐb QÈÐRaÐIaÐIa˜qÐIaÐIaÐIar;   r   c                 ó|   •— i | ]8\  }}|                      d ¦  «        ¯|t          d ¦  «        d…         |dv r‰n|“Œ9S )rŒ  NrÚ  r—  )r@  rç   rè   Úmain_devices      €r<   rœ  z:MoshiForConditionalGeneration.generate.<locals>.<dictcomp>Ž  sc   ø€ ð 4ð 4ð 4á"˜˜UØ—~’~ oÑ6Ô6ð4Ø�˜OÑ,Ô,Ð.Ð.Ô/ÀÈÐ@XÐ@X°°Ð^cð4ð 4ð 4r;   c                 óD   — i | ]\  }}|                      d ¦  «        °||“ŒS rŽ  ©r˜  )r@  rç   rè   s      r<   rœ  z:MoshiForConditionalGeneration.generate.<locals>.<dictcomp>”  s@   € ð "ð "ð "Ù)˜s EÈsÏ~Ê~Ð^mÑOnÔOnð"Ø�Uð"ð "ð "r;   c                 ó<   — h | ]}|                      d ¦  «        ¯|’ŒS )r¡  rà  )r@  r›  s     r<   ú	<setcomp>z9MoshiForConditionalGeneration.generate.<locals>.<setcomp>˜  s,   € Ð$nÐ$nÐ$n°(È×H[ÒH[Ð\lÑHmÔHmÐ$n XÐ$nÐ$nÐ$nr;   c                 óf   •— i | ]-}|t          d ¦  «        d…         ‰                     |¦  «        “Œ.S r   )r™  Úpop)r@  r›  rë   s     €r<   rœ  z:MoshiForConditionalGeneration.generate.<locals>.<dictcomp>™  sH   ø€ ð  
ð  
ð  
ØHPˆH•SÐ)Ñ*Ô*Ð,Ð,Ô-¨v¯zªz¸(Ñ/CÔ/Cð 
ð  
ð  
r;   r¹  N)rJ   r�  rK   r‘  rL   rR  rÈ  r^   r    rª  Ú
min_lengthrR  rJ   )r¹  Úhas_default_max_lengthÚhas_default_min_lengthÚmodel_input_nameÚinputs_tensorÚinput_ids_lengthr‹  Ústatic)rå  rª  Úcache_implementationrM   )rJ   r¹  rë   T)
rJ   r�  rK   r‘  rL   rR  rM   r¹  rÇ  rÈ  r»  rÊ  rÐ  rÑ  rµ   )rR  rJ   r¹  Úblank_user_audio_codesr²  Úreturn_dict_in_generateÚoutput_scoresrM   )rQ   Úindexr   ©r@   rJ   )r&   r/   )r&   r'   r/   r:   )5ÚhasattrrŒ  r×  Úvaluesr«  Ú_prepare_generation_configrä  Ú"_check_and_maybe_initialize_inputsrk   Úgetrª  rå  Ú_prepare_generated_lengthr‹  rŠ   r  rÆ  rÓ  r4   Úzerosrn   r�   Úsampling_rater‡  Ú
frame_rater¦   rž   rˆ  r¬  Úrepeat_interleaveÚmaxÚ	num_beamsÚnum_return_sequencesÚgenerated_audio_codesrî  rï  rU   Úgenerater'   r+   rÉ   r¶   Úgatherrº   ry   r@   rÙ   rÇ  r>  rß   ÚdecodeÚaudio_valuesr%   )&r[   rJ   r�  rK   r‘  rL   rR  rÔ  rÕ  rÈ  rë   Údepth_decoder_kwargs_keysr²  r¹  Úinputsrê  ræ  rç  Údepth_decoder_generation_configrM   rÐ  rÑ  Úblank_input_valuesrí  rî  rï  r!  Úoutput_text_idsr+   rÿ  Úexpanded_beam_indicesr@   Úlast_generated_audio_codesÚoutput_audio_codesÚmaskÚoutput_valuesrÞ  r\   s&             `                         @€r<   r   z&MoshiForConditionalGeneration.generateX  s.  øøø€ õ` �4˜Ñ)Ô)ð 	µ'¸$Ô:LÈoÑ2^Ô2^ð 	Ø/1ˆDÔÔ,Ø�TÔ'Ð'Ð'Ø37Ô3E�Ô"Ô0Ð0àbÐb¨$Ô*<×*CÒ*CÑ*EÔ*EÐbÑbÔbÐcdÔe�ð4ð 4ð 4ð 4à&*Ô&8×&>Ò&>Ñ&@Ô&@ð4ñ 4ô 4�Ô"Ô0ð"ð "Ø-1Ô-?×-EÒ-EÑ-GÔ-Gð"ñ "ô "ˆDÔð %oÐ$n¸fÐ$nÑ$nÔ$nÐ!ð 
ð  
ð  
ð  
ØTmð 
ñ  
ô  
Ðð
 %D DÔ$CÀFÇJÂJÐObÐdhÑDiÔDiÐ$tÐ$tÐmsÐ$tÐ$tÑ!Ð˜6ð ×3Ò3Ø#Ø"3Ø!1Ø#5Ø"3Ø+Ø,Gð 4ñ ô ñ 	Tˆ	Ð#Ð%6Ð8Sð #,Ð"3��¸ˆà3NÐd˜6œ<¨Ô+¨aÑ/Ð/ÐTZÔT`ÐacÔTdÐØ!'§¢¨LÑ!9Ô!9¸TÐ!AÐ!nÐFWÔFbÐjnÐFnÐØ!'§¢¨LÑ!9Ô!9¸TÐ!AÐ!nÐFWÔFbÐjnÐFnÐØ ×:Ò:Ø/Ø#9Ø#9Ø09Ð0A˜_˜_À{Ø Ø-ð ;ñ 
ô 
Ðõ Ð$Ð&<Ñ=Ô=ð 	Ø.?Ô.TÐ+Ð+ð #Ô0°1Ñ4Ø"Ô0°1Ñ4Ø(0ð/ð /Ð+ð 	(×.Ò.Ð/CÑDÔDÐDØ>ÐàŸšÐ$4°dÑ;Ô;ˆØÐ!Ø!×HÒHØ#Ø"3Øð Iñ ô ˆNð ×6Ò6ØØ/Ø-Ø1Ø/Ø'Ø)Ø/Ø%)Ø(Cð 7ñ 
ô 
ñ	
ØØØØØ#Ø$Øõ #œ[ØÔ  Ô# Q­¨D¬KÔ,EÈÌÔHhÔHsÑ,sÑ(tÔ(tÐuØ”*Ø”;ð
ñ 
ô 
Ðð
 "&Ô!3×!:Ò!:Ð;MÐ^bÔ^pÐ!:Ñ!qÔ!qÐrsÔ!tÐð (?Ð'JÐ#Ð#ÐPV×PZÒPZÐ[tÑPuÔPuð 	Ð(Ñ)ð
 (Ð3ð %Ð$à—’Ð6Ñ7Ô7ð 	Ð)Ñ*õ &+Ô%<Ø�sÐ#4Ô#>Ð@QÔ@fÑgÔgÐmnð&
ñ &
ô &
ˆÔ"ð #4Ô"=ÀÒ"AÐ"nÐEVÔEnÐØ)Ô3°aÒ7ÐZÐ;LÔ;ZˆØ"•%‘'”'Ô"ð 

Ø'ØØ/Ø#9Ø!5Ø$;Ø'Ø)ð

ð 

ð ð

ð 

ˆð &ð 	Ð.@ð 	Ø&ð )Ð/@Ô/Xð )ØÔ(Ð(ØˆNð 'ð 	0Ø%ˆOˆOà%Ô/ˆOàÔ1°AÒ5Ð5Ý',Ô'>Ø(Ð*;Ô*PÐVWð(ñ (ô (Ð$ð Ô&¨Ò*Ð*ð #Ô/°°°Ð3QÐ6GÔ6MÈbÔ6QÐ5QÐ3QÐ0QÔRˆLà$(Ô$>¸q¸q¸qÀ!À!À!ÐEVÔE\Ð]_ÔE`ÐEbÐEbÐ?bÔ$cÐ!ð %1°°°°C°R°C°Ô$8×$BÒ$BÀ1Ñ$EÔ$E×$LÒ$LÈRÐQUÔQcÐegÑ$hÔ$hÐ!Ý$)¤LÐ1FÈAÐUjÐ$kÑ$kÔ$kÐ!õ !&Ô 7Ø!Ð#4Ô#IÈqð!ñ !ô !Ðõ */¬Ð4EÐG\Ð3]ÐcdÐ)eÑ)eÔ)eˆDÔ&õ &+Ô%7¸Ô8NÐTUÐ]iÐjkÐjkÐjkÐmoÐjoÔ]pÐ%qÑ%qÔ%qˆDÔ"ð !Ô2×7Ò7¸¸A¸tÔ?UÔ?[Ð\^Ô?_Ñ`Ô`Ðà%@ TÔ%7Ô%@ð &
Ø/Ø% a a a¨¨¨ fÔ-×2Ò2°2°qÑ9Ô9ð&
ð &
ð #ð&
ð &
Ð"ð &@ÀÀÀÀ1À2À2ÀÔ%F×%PÒ%PÐQRÑ%SÔ%SÐ"å%*¤Y°Ô0JÐLfÐ/gÐmnÐ%oÑ%oÔ%oˆÔ"ð "×:Ò:¸4Ô;UÐWoÑpÔpÐð (¨4¬;Ô+GÒGˆà/°Ô5×=Ò=¸d¼jÈ¼mÈTÔM_ÐacÑdÔdÐàˆØ!ð 	Ø Ô.×5Ò5Ø"ñô äð ð 4FÐOÐ/Ð/È4ÐàÔ4ð 	Ý;ð Ø -Ð;Mðð ØQXðð ð õ 8Ø)°_ÐRdð
ñ 
ô 
ð 	
r;   rí  c                 ó4  •—  t          ¦   «         j        |f||||||||	|
||dœ|¤Ž}|d         ��g|                     d¦  «        }|                     dd|j        d         ¦  «        }|                     d¦  «        } | j        j        d||                     dd¦  «        dœ|
¤Ž}|d d …dd …f                              d¦  «        }|                      t          j
        | j        |                     | j        j        ¦  «        gd¬¦  «        |¦  «        d d …d d …dd …f         }|                      t          j
        | j        |gd¬¦  «        |	¦  «        | _        |                      || j        d d …d d …dd …f         |¬	¦  «        \  }}}}}}}d |d<   ||d
<   |S )N)r.   rM   rR  r½   r  r{  rÐ  rÑ  r²  Úis_first_iterationrí  rJ   r@   r^   r    rñ  r   rµ   )rL   rK   rR  r:   )rU   Úprepare_inputs_for_generationrä  rÙ   rk   rŒ  r   rÉ   rÇ  r4   rº   rÿ  r­   rž   rÓ  )r[   rJ   r.   rM   rR  r½   r  r{  rÐ  rÑ  r²  r  rí  rë   Úmodel_inputsr@   rÿ  rK   rÜ   r\   s                      €r<   r  z;MoshiForConditionalGeneration.prepare_inputs_for_generationV  s"  ø€ ð$ =•u‘w”wÔ<Øð
à+Ø)Ø'Ø%ØØ)Ø$;Ø%=Ø!5Ø1Ø#9ð
ð 
ð ð
ð 
ˆð& ˜Ô$Ñ0Ø &§
¢
Ð+>Ñ ?Ô ?Ðà 1× 6Ò 6°r¸1Ð>OÔ>UÐVXÔ>YÑ ZÔ ZÐà$×(Ò(¨Ñ5Ô5ˆIà$? DÔ$6Ô$?ð %Ø"3Ø#Ÿ.š.¨¨QÑ/Ô/ð%ð %ð 'ð%ð %Ð!ð %:¸!¸!¸!¸Q¸R¸R¸%Ô$@×$JÒ$JÈ1Ñ$MÔ$MÐ!à#×<Ò<Ý”	ØÔ/Ð1G×1JÒ1JÈ4ÔKeÔKlÑ1mÔ1mÐnÐtuðñ ô ð (ñ	 ô  ð
 ˆaˆa����B�C�Cˆiô Ðð *.×)FÒ)FÝ”	˜4Ô5Ð7LÐMÐSTÐUÑUÔUÐWoñ*ô *ˆDÔ&ð /3×.XÒ.XØ¨TÔ-GÈÈÈÈ1È1È1ÈbÈcÈcÈ	Ô-RÐeuð /Yñ /ô /Ñ+ˆM˜1˜a  A q¨!ð )-ˆL˜Ñ%Ø,9ˆL˜Ñ)àÐr;   r    r!  Úmodel_kwargsÚis_encoder_decoderÚnum_new_tokensc                 óÎ   •— t          ¦   «                              ||||¦  «        }|                     d¦  «        d d …dd …f                              ¦   «         }||d<   || _        |S )Nr@   r^   )rU   Ú#_update_model_kwargs_for_generationrö  r�   r@   )r[   r!  r  r  r  r@   r\   s         €r<   r  zAMoshiForConditionalGeneration._update_model_kwargs_for_generationž  ss   ø€ õ ‘w”w×BÒBØ�\Ð#5°~ñ
ô 
ˆð $ŸKšKÐ(;Ñ<Ô<¸Q¸Q¸QÀÀÀ¸VÔD×JÒJÑLÔLÐØ,=ˆÐ(Ñ)à!2ˆÔØÐr;   c                 ó4   — | j                              ¦   «         S rT   )r‰  Úget_input_embeddingsrl   s    r<   r  z2MoshiForConditionalGeneration.get_input_embeddings²  s   € ØŒ|×0Ò0Ñ2Ô2Ð2r;   c                 ó:   — | j                              |¦  «         d S rT   )r‰  Úset_input_embeddings)r[   rè   s     r<   r  z2MoshiForConditionalGeneration.set_input_embeddingsµ  s   € ØŒ×)Ò)¨%Ñ0Ô0Ð0Ð0Ð0r;   c                 ó4   — | j                              ¦   «         S rT   )r‰  Úget_output_embeddingsrl   s    r<   r  z3MoshiForConditionalGeneration.get_output_embeddings¸  s   € ØŒ|×1Ò1Ñ3Ô3Ð3r;   c                 ó:   — | j                              |¦  «         d S rT   )r‰  Úset_output_embeddings)r[   Únew_embeddingss     r<   r  z3MoshiForConditionalGeneration.set_output_embeddings»  s   € ØŒ×*Ò*¨>Ñ:Ô:Ð:Ð:Ð:r;   c                 ód   — | j                              ¦   «         D ]	}d|_        Œ
d| j         _        dS )z3
        Freeze the audio encoder weights.
        FN)rˆ  Ú
parametersÚrequires_gradÚ_requires_grad©r[   Úparams     r<   Úfreeze_audio_encoderz2MoshiForConditionalGeneration.freeze_audio_encoder¾  ó>   € ð Ô'×2Ò2Ñ4Ô4ð 	(ð 	(ˆEØ"'ˆEÔÐØ,1ˆÔÔ)Ð)Ð)r;   c                 ód   — | j                              ¦   «         D ]	}d|_        Œ
d| j         _        dS )z3
        Freeze the depth encoder weights.
        FN)rŒ  r!  r"  r#  r$  s     r<   Úfreeze_depth_decoderz2MoshiForConditionalGeneration.freeze_depth_decoderÆ  r'  r;   c                 ól   — | j         d         }|dd|…f         }t          j        |dk    | |¦  «        } | S )z®Apply a delay pattern mask to the decoder input ids, only preserving predictions where
        the mask is set to -1, and otherwise setting to the value detailed in the mask.r^   .N)rk   r4   Úwhere)rJ   Údecoder_pad_token_maskr    s      r<   rÇ  z6MoshiForConditionalGeneration.apply_delay_pattern_maskÎ  sC   € ð
 ”/ "Ô%ˆØ!7¸¸X¸g¸X¸Ô!FÐÝ”KÐ 6¸"Ò <¸iÐI_Ñ`Ô`ˆ	ØÐr;   r©  rr  rª  c                 óx  — |j         \  }}}|�|n| j        j        }t          j        |||ft          j        |j        ¬¦  «        dz  }t          ||dz
  ¦  «        }	|dd…dd|	…f         |dd…dd|	…f<   |dd…dd…d|	…f         |dd…dd…d|	dz   …f<   ||dd…dd…df<   ||dd…ddf<   |}
|dd|	…f         }||
fS )aI  Build a delayed pattern mask to the input_ids. Each codebook, except the first one, is offset by
        one, giving a delayed pattern mask at the start of sequence and end of sequence. Take the example where there
        are 4 codebooks and a max sequence length of 6, we have the delayed pattern mask of shape `(codebooks,
        seq_len)`:
        - [-1, -1, -1, -1, -1,  P]
        - [ B, -1, -1, -1, -1, -1]
        - [ B, -1, -1, -1, -1, -1]
        - [ B, -1, -1, -1, -1, -1]
        where B is the beginning-of-sentence token, P is the special padding token id and -1 indicates that the token is valid for prediction. If we include
        a prompt (input ids), the -1 positions indicate where new tokens should be predicted. Otherwise, the
        mask is set to the value in the prompt:
        - [ a0, a1, -1, -1, -1,  P]
        - [ B,  b0, b1, -1, -1, -1]
        - [ B,  c0, c1, -1, -1, -1]
        - [ B,  d0, d1, -1, -1, -1]
        where a-d indicate the codebook channel and 0/1 indicates the temporality. Now, we only override the -1
        tokens in our prediction.
        Nr»  r^   r    r   .)rk   r¹  rª  r4   rY   r½  rž   Úmin)r[   rJ   r©  rr  rª  ÚbszrŠ   r    Úinput_ids_shiftedÚseq_len_to_keepÚpattern_masks              r<   r®  z6MoshiForConditionalGeneration.build_delay_pattern_maskØ  s1  € ð* '0¤oÑ#ˆˆ]˜Gà#-Ð#9�Z�Z¸tÔ?UÔ?`ˆ
åŒJ˜˜]¨JÐ7½u¼zÐR[ÔRbÐcÑcÔcÐfhÑhð 	õ
 ˜g z°A¡~Ñ6Ô6ˆØ4=¸a¸a¸aÀÐDTÀ_ÐDTÐ>TÔ4UÐ˜!˜!˜!˜QÐ 0 Ð 0Ð0Ñ1ð =FÀaÀaÀaÈÈÈÐM]ÈoÐM]ÐF]Ô<^Ð˜!˜!˜!˜Q˜R˜R  _°qÑ%8Ð!8Ð8Ñ9ð '3Ð˜!˜!˜!˜Q˜R˜R ˜(Ñ#Ø&2Ð˜!˜!˜!˜Q ˜(Ñ#ð )ˆà% cÐ+;¨OÐ+;Ð&;Ô<ˆ	Ø˜,Ð&Ð&r;   c                 óÎ  — t          j        |df| j        t           j        ¬¦  «        | j        j        z  }t          j        || j        df| j        t           j        ¬¦  «        | j        j        z  }t          j        || j        df| j        t           j        ¬¦  «        | j        j        z  }t          j        |df| j        t           j        ¬¦  «        }t          ||||¬¦  «        S )aà  
        Helper function to get null inputs for unconditional generation, enabling the model to be used without the
        feature extractor or tokenizer.

        Args:
            num_samples (int, *optional*):
                Number of audio samples to unconditionally generate.
            max_new_tokens (int, *optional*):
                Number of tokens to generate for each sample. More tokens means longer audio samples, at the expense of
                longer inference (since more audio tokens need to be generated per sample).

        Example:
        ```python
        >>> from transformers import MoshiForConditionalGeneration

        >>> model = MoshiForConditionalGeneration.from_pretrained("kmhf/hf-moshiko-pytorch-bf16")

        >>> # get the unconditional (or 'null') inputs for the model
        >>> unconditional_inputs = model.get_unconditional_inputs(num_samples=1)
        >>> audio_samples = model.generate(**unconditional_inputs, max_new_tokens=256)
        ```r    r§   )rJ   rK   rL   rM   )
r4   rY   rž   r¬   r�   rF  rŠ   r>  r½  rI   )r[   rË  rJ   rK   rL   rM   s         r<   rÏ  z6MoshiForConditionalGeneration.get_unconditional_inputs  sã   € õ. ”J ¨QÐ/¸¼Í5Ì;ÐWÑWÔWÐZ^ÔZeÔZpÑpˆ	åŒJ˜ TÔ%7¸Ð;ÀDÄKÕW\ÔWbÐcÑcÔcØŒkÔ*ñ+ð 	õ
 ŒJ˜ TÔ%7¸Ð;ÀDÄKÕW\ÔWbÐcÑcÔcØŒkÔ*ñ+ð 	õ œ [°!Ð$4¸T¼[ÕPUÔPZÐ[Ñ[Ô[ˆå&ØØ-Ø/Ø)ð	
ñ 
ô 
ð 	
r;   c                 óZ  — |€|n|}|€|n|}	|€|n|}
|	d up|
d up|d u}|o|d uo|d u  }|r|	€t          d¦  «        ‚|r|
€t          d¦  «        ‚|r|€t          d¦  «        ‚|s,|                      ¦   «         }|j        }|j        }|j        }d}n–|	j        d         }|
j        d         }|j        d         }| j        j        j        | j        j	        z  }|€t          j        ||z  ¦  «        n|}|€t          j        ||z  ¦  «        n|}||k    s||k    rt          d¦  «        ‚||||fS )Na  No user audio inputs have been passed alongside the other inputs. Make sure either `user_input_values` or `user_audio_codes` is passed or use `MoshiForConditionalGeneration.get_unconditional_inputs`. Check the `MoshiForConditionalGeneration` docstrings for more information.a  No Moshi audio inputs have been passed alongside the other inputs. Make sure either `moshi_input_values` or `moshi_audio_codes` is passed or use `MoshiForConditionalGeneration.get_unconditional_inputs`. Check the `MoshiForConditionalGeneration` docstrings for more information.zúNo `input_ids` or `inputs_embeds` have been passed alongside the other inputs. Make sure `input_ids` is passed or use `MoshiForConditionalGeneration.get_unconditional_inputs`. Check the `MoshiForConditionalGeneration` docstrings for more information.Fr^   r    zõAt least one of the 3 inputs of `MoshiForConditionalGeneration` doesn't have the same sequence length as the others.Make sure that they all have the same sequence length. Check the `MoshiForConditionalGeneration` docstrings for more information.)r  rÏ  rJ   rK   rL   rk   r�   r‡  rú  rù  rÿ   Úceil)r[   rJ   r�  rK   r‘  rL   rR  rÈ  r  Ú
user_inputÚmoshi_inputÚone_input_has_been_passedrÒ  Úuser_seq_lengthÚmoshi_seq_lengthÚtokens_seq_lengthÚratios                    r<   rõ  z@MoshiForConditionalGeneration._check_and_maybe_initialize_inputs.  sô  € ð ,Ð3��¸ˆØ):Ð)BÐ%Ð%ÐHYˆ
Ø+=Ð+EÐ'Ð'ÐK]ˆà%/°tÐ%;Ð$qÀÐTXÐAXÐ$qÐ^dÐlpÐ^pÐ!ð 'Bð '
Ø Ð%Ð;¨)°tÐ*;ðG
Ð#ð
 %ð #	¨*Ð*<Ýð eñô ð ð 'ð 	¨KÐ,?Ýð hñô ð ð 'ð 	¨F¨NÝð Mñô ð ð +ð 	à#'×#@Ò#@Ñ#BÔ#BÐ Ø,Ô6ˆIØ3ÔDÐØ 4Ô FÐð +0Ð'Ð'ð )Ô.¨rÔ2ˆOØ*Ô0°Ô4ÐØ &¤¨Q¤Ðà”KÔ4Ô?À$Ä+ÔB[Ñ[ˆEØFWÐF_�tœyÐ)9¸EÑ)AÑBÔBÐBÐeuÐØDTÐD\�dœi¨¸%Ñ(?Ñ@Ô@Ð@ÐbqˆOà Ð$4Ò4Ð4Ð8IÈ_Ò8\Ð8\Ý ðXñô ð ð
 Ð*Ð,=Ð?ZÐZÐZr;   )NNNNNNNNNNNNNN)
NNNNNNNNFF)	NNNNNNTNT)NNNNTNNNNFN)Fr    rT   r;  )NNNNNNN)1r0   r1   r2   r!   r6   Úoutput_modalitiesr6  r0  r2  r3  r4  r5  rV   r�  r   r4   r7   rm  r8   r5   r   r"  r9   r   ri   r   Údictr¹   r   rÆ  rÓ  rÃ   r   r  r   rn   r  r  r  r  r  r&  r)  rÂ   rÇ  r®  rÏ  rõ  ro   rp   s   @r<   rƒ  rƒ  	  sé  ø€ € € € € € ð ÐÐÑØ)ÐØ!€OØ&*Ð#ØÐØ€NØÐØ"&Ðð˜{ð ð ð ð ð ð ð"ð "ð "ð ð .2Ø26Ø6:Ø04Ø7;Ø15Ø(,Ø26Ø/3Ø04Ø!%Ø)-Ø,0Ø#'ðn
ð n
àÔ# dÑ*ðn
ð Ô(¨4Ñ/ðn
ð !Ô,¨tÑ3ð	n
ð
  œ,¨Ñ-ðn
ð "Ô-°Ñ4ðn
ð !œ<¨$Ñ.ðn
ð  ™ðn
ð Ô(¨4Ñ/ðn
ð Ô%¨Ñ,ðn
ð Ô&¨Ñ-ðn
ð ˜$‘;ðn
ð   $™;ðn
ð # T™kðn
ð ˜D‘[ðn
ð" 
�Ñ	 ð#n
ð n
ð n
ñ „^ðn
ð`àÔ#ðð ,ðð �S˜#�X”ð	ð
 
Ô	ðð ð ð ð6 .2Ø6:Ø04Ø7;Ø15Ø26Ø.2Ø59Ø).Ø,1ðc
ð c
àÔ# dÑ*ðc
ð !Ô,¨tÑ3ðc
ð  œ,¨Ñ-ð	c
ð
 "Ô-°Ñ4ðc
ð !œ<¨$Ñ.ðc
ð Ô(¨4Ñ/ðc
ð œ tÑ+ðc
ð ,¨dÑ2ðc
ð #'ðc
ð &*ðc
ð c
ð c
ð c
ðJ €U„]�_„_ð .2Ø6:Ø04Ø7;Ø15Ø26Ø.2Ø*.Ø37ð{
ð {
àÔ# dÑ*ð{
ð !Ô,¨tÑ3ð{
ð  œ,¨Ñ-ð	{
ð
 "Ô-°Ñ4ð{
ð !œ<¨$Ñ.ð{
ð Ô(¨4Ñ/ð{
ð !% t¡ð{
ð ! 4™Kð{
ð &*¨D¡[ð{
ð 
Ô	ð{
ð {
ð {
ð {
ð {
ñ „_ð{
ð@ ØØØØØØ $Ø!%Ø!Ø Ø;?ðFð Fð !&Ô 1°DÑ 8ðFð Fð Fð Fð Fð FðX $)Øðð àðð ˜3 ˜8”nðð !ð	ð
 ðð 
ˆc�3ˆhŒðð ð ð ð ð ð(3ð 3ð 3ð1ð 1ð 1ð4ð 4ð 4ð;ð ;ð ;ð2ð 2ð 2ð2ð 2ð 2ð ðð ñ „\ðð koð+'ð +'ØÔ)ð+'Ø9<ð+'ØLOð+'Ø]`ÐcgÑ]gð+'ð +'ð +'ð +'ðZ'
ð '
ð '
ð '
ðV ØØØØØØ$(ð;[ð ;[ð ;[ð ;[ð ;[ð ;[ð ;[ð ;[r;   rƒ  )rx  rƒ  ro  r$  r;  )rä   )Pr3   rÿ   Úcollections.abcr   Údataclassesr   Útypingr   r   r4   Útorch.nnrW   r   rØ  r	   r,  Úactivationsr
   Úcache_utilsr   r   Ú
generationr   r   Úmasking_utilsr   Úmodeling_layersr   Úmodeling_outputsr   r   r   r   Úmodeling_rope_utilsr   r   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r   r   Úutils.genericr   Úauto.modeling_autor   Úconfiguration_moshir!   r"   Ú
get_loggerr0   r_  r%   r>   rB   rI   ÚModulerO   rr   r�   rŽ   rÇ   rÏ   rÑ   r5   rn   rã   rf   rø   rú   r  r$  r8  ro  rx  rƒ  Ú__all__r:   r;   r<   ú<module>rS     s·  ðð Ð à €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø !Ð !Ð !Ð !Ð !Ð !Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à &Ð &Ð &Ð &Ð &Ð &Ø !Ð !Ð !Ð !Ð !Ð !Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø /Ð /Ð /Ð /Ð /Ð /Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø mÐ mÐ mÐ mÐ mÐ mÐ mÐ mÐ mÐ mÐ mÐ mØ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KØ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ø +Ð +Ð +Ð +Ð +Ð +Ø *Ð *Ð *Ð *Ð *Ð *Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >ð 
ˆÔ	˜HÑ	%Ô	%€ð €ððñ ô ð
 ð+0ð +0ð +0ð +0ð +0¨{ñ +0ô +0ñ „ñô ð+0ð\ €ððñ ô ð
 ð<ð <ð <ð <ð < +ñ <ô <ñ „ñô ð<ð* €ððñ ô ð
 ð"Bð "Bð "Bð "Bð "B¨{ñ "Bô "Bñ „ñô ð"BðJ Ø
ð3ð 3ð 3ð 3ð 3˜kñ 3ô 3ñ „ñ „ð3ð(=ð =ð =ð =ð =�2”9ñ =ô =ð =ð&$ð $ð $ð $ð $˜"œ)ñ $ô $ð $ðN"ð "ð "ð "ð "�"”)ñ "ô "ð "ð&><ð ><ð ><ð ><ð ><˜2œ9ñ ><ô ><ð ><ðD(ð (ð (ðð ð ð ð2ð ð ð ð �R”Yñ ô ð ð4	U˜Uœ\ð 	U°#ð 	U¸%¼,ð 	Uð 	Uð 	Uð 	Uð( ð%ð %ØŒIð%àŒ<ð%ð 
Œð%ð Œ<ð	%ð
 ”L 4Ñ'ð%ð ð%ð ð%ð Ð'Ô(ð%ð %ð %ð %ð2Q)ð Q)ð Q)ð Q)ð Q)�R”Yñ Q)ô Q)ð Q)ðl:ð :ð :ð :ð :Ð2ñ :ô :ð :ðz ð(ð (ð (ð (ð (˜?ñ (ô (ñ „ð(ð(P
ð P
ð P
ð P
ð P
Ð,¨oñ P
ô P
ð P
ðf ðk
ð k
ð k
ð k
ð k
Ð%ñ k
ô k
ñ „ðk
ð\ €ððñ ô ð
k
ð k
ð k
ð k
ð k
Ð+¨_ñ k
ô k
ñô ð
k
ð\ €ððñ ô ð
[[ð [[ð [[ð [[ð [[Ð$8¸/ñ [[ô [[ñô ð
[[ð| fÐ
eÐ
e€€€r;   