Ë
    T^(h¿ ã                   óV  — d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZ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mZmZmZmZmZ dd	lmZmZmZm Z  dd
l!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7  e#«       rddl!m8Z8 erddl9m:Z:  e/jv                  e<«      Z=dZ>dZ?e G d„ de(«      «       Z@dej‚                  deBdeBfd„ZC G d„ dejˆ                  «      ZE G d„ d ejˆ                  «      ZF G d!„ d"eF«      ZG G d#„ d$eF«      ZHeFeHeGd%œZI G d&„ d'ejˆ                  «      ZJ G d(„ d)e+«      ZKd*ZLd+ZMd,ZN G d-„ d.eK«      ZO e-d/eL«       G d0„ d1eK«      «       ZP e-d2eL«       G d3„ d4eKe«      «       ZQ e-d5eL«       G d6„ d7e+e«      «       ZRg d8¢ZSy)9zPyTorch Musicgen model.é    N)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚDictÚListÚOptionalÚTupleÚUnion)ÚCrossEntropyLossé   )ÚACT2FN)Ú%ClassifierFreeGuidanceLogitsProcessorÚGenerationConfigÚGenerationMixinÚGenerationModeÚLogitsProcessorListÚStoppingCriteriaList)Ú_prepare_4d_attention_maskÚ#_prepare_4d_attention_mask_for_sdpaÚ!_prepare_4d_causal_attention_maskÚ*_prepare_4d_causal_attention_mask_for_sdpa)Ú!flash_attn_supports_top_left_maskÚis_flash_attn_available)ÚBaseModelOutputÚ)BaseModelOutputWithPastAndCrossAttentionsÚ!CausalLMOutputWithCrossAttentionsÚModelOutputÚSeq2SeqLMOutput)ÚPreTrainedModel)Úadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )Ú
AutoConfig©Ú	AutoModelé   )ÚMusicgenConfigÚMusicgenDecoderConfig)Ú_flash_attention_forward)ÚBaseStreamerr)   zfacebook/musicgen-smallc                   óv   — e Zd ZU dZdZeej                     ed<   dZ	e
ej                     ed<   dZe
e   ed<   y)ÚMusicgenUnconditionalInputa%  
    Args:
        encoder_outputs  (`Tuple[torch.FloatTensor]` of length 1, with tensor shape `(batch_size, sequence_length, hidden_size)`):
            Sequence of hidden-states at the output of the last layer of the text encoder model.
        attention_mask (`torch.LongTensor`)  of shape `(batch_size, sequence_length)`, *optional*):
            Encoder 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**.
        guidance_scale (`float`, *optional*):
            Guidance scale for classifier free guidance, setting the balance between the conditional logits (predicted
            from the prompts) and the unconditional logits (predicted without prompts).
    NÚencoder_outputsÚattention_maskÚguidance_scale)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/   r	   ÚtorchÚFloatTensorÚ__annotations__r0   r   Ú
LongTensorr1   Úfloat© ó    úl/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/musicgen/modeling_musicgen.pyr.   r.   K   sA   … ñ
ð 15€O�U˜5×,Ñ,Ñ-Ó4Ø15€N�H˜U×-Ñ-Ñ.Ó5Ø&*€N�H˜U‘OÔ*r<   r.   Ú	input_idsÚpad_token_idÚdecoder_start_token_idc                 ó  — | j                  dd«      } | j                  | j                  «      }| ddd…f   j                  «       |ddd…f<   |€t	        d«      ‚||d<   |€t	        d«      ‚|j                  |d	k(  |«       |S )
z1
    Shift input ids one token to the right.
    r(   r$   .NéÿÿÿÿzSMake sure to set the decoder_start_token_id attribute of the model's configuration.©.r   zIMake sure to set the pad_token_id attribute of the model's configuration.éœÿÿÿ)Ú	transposeÚ	new_zerosÚshapeÚcloneÚ
ValueErrorÚmasked_fill_)r>   r?   r@   Úshifted_input_idss       r=   Úshift_tokens_rightrL   ^   s�   € ð
 ×#Ñ# A qÓ)€IØ!×+Ñ+¨I¯O©OÓ<ÐØ!*¨3°°°¨8Ñ!4×!:Ñ!:Ó!<Ð�c˜1™2�gÑØÐ%ÜÐnÓoÐoØ 6Ð�fÑàÐÜÐdÓeÐeà×"Ñ"Ð#4¸Ñ#<¸lÔKàÐr<   c                   ó¤   ‡ — e Zd ZdZdedefˆ fd„Zdedefd„Zededefd„«       Z e	j                  «       dde	j                  d	efd
„«       Zˆ xZS )Ú%MusicgenSinusoidalPositionalEmbeddingzDThis module produces sinusoidal positional embeddings of any length.Únum_positionsÚembedding_dimc                 óT   •— t         ‰| �  «        || _        | j                  ||«       y ©N)ÚsuperÚ__init__rP   Úmake_weights)ÚselfrO   rP   Ú	__class__s      €r=   rT   z.MusicgenSinusoidalPositionalEmbedding.__init__u   s&   ø€ Ü‰ÑÔØ*ˆÔØ×Ñ˜-¨Õ7r<   Únum_embeddingsc                 ó@  — | j                  ||«      }t        | d«      r;|j                  | j                  j                  | j                  j
                  ¬«      }t        j                  |«      | _        d| j                  _        | j                  j                  «        y )NÚweights©ÚdtypeÚdeviceF)
Úget_embeddingÚhasattrÚtorZ   r\   r]   ÚnnÚ	ParameterÚrequires_gradÚdetach_)rV   rX   rP   Úemb_weightss       r=   rU   z2MusicgenSinusoidalPositionalEmbedding.make_weightsz   sp   € Ø×(Ñ(¨¸ÓGˆÜ�4˜Ô#à%Ÿ.™.¨t¯|©|×/AÑ/AÈ$Ï,É,×J]ÑJ]˜.Ó^ˆKä—|‘| KÓ0ˆŒØ%*ˆ�‰Ô"Ø�‰×ÑÕr<   c                 óÌ  — |dz  }t        j                  d«      |dz
  z  }t        j                  t        j                  |t        j
                  ¬«      j                  «       | z  «      }t        j                  | t        j
                  ¬«      j                  «       j                  d«      |j                  d«      z  }t        j                  t        j                  |«      t        j                  |«      gd¬«      j                  | d«      }|dz  dk(  r-t        j                  |t        j                  | d«      gd¬«      }|j                  t        j                  «       «      S )zÁ
        Build sinusoidal embeddings. This matches the implementation in tensor2tensor, but differs slightly from the
        description in Section 3.5 of "Attention Is All You Need".
        r$   i'  r(   ©r\   r   ©ÚdimrB   )ÚmathÚlogr6   ÚexpÚarangeÚint64r:   Ú	unsqueezeÚcatÚcosÚsinÚviewÚzerosr`   Úget_default_dtype)rX   rP   Úhalf_dimÚembs       r=   r^   z3MusicgenSinusoidalPositionalEmbedding.get_embedding„   s  € ð ! AÑ%ˆÜ�h‰h�u‹o ¨A¡Ñ.ˆÜ�i‰iœŸ™ X´U·[±[ÔA×GÑGÓIÈSÈDÑPÓQˆÜ�l‰l˜>´·±Ô=×CÑCÓE×OÑOÐPQÓRÐUX×UbÑUbÐcdÓUeÑeˆÜ�i‰iœŸ™ 3›¬¯©°3«Ð8¸aÔ@×EÑEÀnÐVXÓYˆØ˜1Ñ Ò!ä—)‘)˜S¤%§+¡+¨n¸aÓ"@ÐAÀqÔIˆCØ�v‰v”e×-Ñ-Ó/Ó0Ð0r<   r>   Úpast_key_values_lengthc                 óŒ  — |j                  «       \  }}}t        j                  |«      |z   j                  |j                  «      }|| j
                  j                  d«      kD  r)| j                  || j                  z   | j                  «       | j
                  j                  d|j                  d«      «      j                  «       S )Nr   rB   )Úsizer6   rm   r`   r]   rZ   rU   ÚoffsetrP   Úindex_selectrs   Údetach)rV   r>   rx   ÚbszÚ	codebooksÚseq_lenÚposition_idss          r=   Úforwardz-MusicgenSinusoidalPositionalEmbedding.forward”   s›   € à"+§.¡.Ó"2ÑˆˆY˜äŸ™ WÓ-Ð0FÑF×JÑJÈ9×K[ÑK[Ó\ˆà�T—\‘\×&Ñ& qÓ)Ò)Ø×Ñ˜g¨¯©Ñ3°T×5GÑ5GÔHØ�|‰|×(Ñ(¨¨L×,=Ñ,=¸bÓ,AÓB×IÑIÓKÐKr<   )r   )r2   r3   r4   r5   ÚintrT   rU   Ústaticmethodr^   r6   Úno_gradÚTensorr‚   Ú__classcell__©rW   s   @r=   rN   rN   r   s€   ø„ ÙNð8 cð 8¸#õ 8ð
¨3ð ¸só ð ð1 cð 1¸#ò 1ó ð1ð €U‡]�]ƒ_ñL §¡ð LÀsò Ló ôLr<   rN   c                   ó†  ‡ — e Zd ZdZ	 	 	 	 	 ddededededededee   fˆ fd	„Z	d
e
j                  dedefd„Z	 	 	 	 	 dde
j                  dee
j                     deee
j                        dee
j                     dee
j                     dedee
j                  ee
j                     eee
j                        f   fd„Zˆ xZS )ÚMusicgenAttentionz=Multi-headed attention from 'Attention Is All You Need' paperÚ	embed_dimÚ	num_headsÚdropoutÚ
is_decoderÚbiasÚ	is_causalÚconfigc                 ó
  •— t         ‰| �  «        || _        || _        || _        ||z  | _        || _        | j
                  |z  | j                  k7  rt        d| j                  › d|› d�«      ‚| j
                  dz  | _        || _	        || _
        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        t        j                  |||¬«      | _        y )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).g      à¿©r�   )rS   rT   r‹   rŒ   r�   Úhead_dimr‘   rI   ÚscalingrŽ   r�   ra   ÚLinearÚk_projÚv_projÚq_projÚout_proj)	rV   r‹   rŒ   r�   rŽ   r�   r�   r‘   rW   s	           €r=   rT   zMusicgenAttention.__init__£   sä   ø€ ô 	‰ÑÔØ"ˆŒØ"ˆŒØˆŒØ! YÑ.ˆŒØˆŒà�M‰M˜IÑ%¨$¯.©.Ò8ÜØMÈdÏnÉnÐM]Ø$ Y K¨rð3óð ð —}‘} dÑ*ˆŒØ$ˆŒØ"ˆŒä—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜŸ	™	 )¨Y¸TÔBˆ�r<   Útensorr€   r~   c                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S )Nr(   r$   )rs   rŒ   r”   rE   Ú
contiguous©rV   r›   r€   r~   s       r=   Ú_shapezMusicgenAttention._shapeÂ   s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr<   Úhidden_statesÚkey_value_statesÚpast_key_valuer0   Úlayer_head_maskÚoutput_attentionsÚreturnc                 ó
  — |du}|j                  «       \  }}	}
| j                  |«      | j                  z  }|r0|�.|d   j                  d   |j                  d   k(  r|d   }|d   }�n
|rE| j	                  | j                  |«      d|«      }| j	                  | j                  |«      d|«      }nÃ|�}| j	                  | j                  |«      d|«      }| j	                  | j                  |«      d|«      }t        j                  |d   |gd¬«      }t        j                  |d   |gd¬«      }nD| j	                  | j                  |«      d|«      }| j	                  | j                  |«      d|«      }| j                  r||f}|| j                  z  d| j                  f} | j	                  ||	|«      j                  |Ž } |j                  |Ž } |j                  |Ž }|j                  d«      }t        j                  ||j                  dd«      «      }|j                  «       || j                  z  |	|fk7  r/t!        d|| j                  z  |	|f› d|j                  «       › �«      ‚|�{|j                  «       |d|	|fk7  r#t!        d	|d|	|f› d|j                  «       › �«      ‚|j                  || j                  |	|«      |z   }|j                  || j                  z  |	|«      }t"        j$                  j'                  |d¬«      }|�›|j                  «       | j                  fk7  r*t!        d
| j                  f› d|j                  «       › �«      ‚|j                  dddd«      |j                  || j                  |	|«      z  }|j                  || j                  z  |	|«      }|r?|j                  || j                  |	|«      }|j                  || j                  z  |	|«      }nd}t"        j$                  j)                  || j(                  | j*                  ¬«      }t        j                  ||«      }|j                  «       || j                  z  |	| j                  fk7  r9t!        d|| j                  z  |	| j                  f› d|j                  «       › �«      ‚|j                  || j                  |	| j                  «      }|j                  dd«      }|j                  ||	| j,                  «      }| j/                  |«      }|||fS )ú#Input shape: Batch x Time x ChannelNr   r$   r(   rB   rh   z$Attention weights should be of size ú	, but is z!Attention mask should be of size z/Head mask for a single layer should be of size ©ÚpÚtrainingú `attn_output` should be of size )rz   r™   r•   rG   rŸ   r—   r˜   r6   rp   rŽ   rŒ   r”   rs   ÚreshapeÚbmmrE   rI   ra   Ú
functionalÚsoftmaxr�   r«   r‹   rš   )rV   r    r¡   r¢   r0   r£   r¤   Úis_cross_attentionr~   Útgt_lenÚ_Úquery_statesÚ
key_statesÚvalue_statesÚ
proj_shapeÚsrc_lenÚattn_weightsÚattn_weights_reshapedÚ
attn_probsÚattn_outputs                       r=   r‚   zMusicgenAttention.forwardÅ   s  € ð .°TÐ9Ðà'×,Ñ,Ó.‰ˆˆW�að —{‘{ =Ó1°D·L±LÑ@ˆñ ØÐ*Ø˜qÑ!×'Ñ'¨Ñ*Ð.>×.DÑ.DÀQÑ.GÒGð (¨Ñ*ˆJØ)¨!Ñ,ŠLÙàŸ™ T§[¡[Ð1AÓ%BÀBÈÓLˆJØŸ;™; t§{¡{Ð3CÓ'DÀbÈ#ÓN‰LØÐ'àŸ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLÜŸ™ N°1Ñ$5°zÐ#BÈÔJˆJÜ Ÿ9™9 n°QÑ&7¸Ð%FÈAÔN‰Lð Ÿ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLà�?Š?ð )¨,Ð7ˆNà˜DŸN™NÑ*¨B°·±Ð>ˆ
ØC�t—{‘{ <°¸#Ó>×CÑCÀZÐPˆØ'�Z×'Ñ'¨Ð4ˆ
Ø+�|×+Ñ+¨ZÐ8ˆà—/‘/ !Ó$ˆÜ—y‘y ¨z×/CÑ/CÀAÀqÓ/IÓJˆà×ÑÓ 3¨¯©Ñ#7¸À'Ð"JÒJÜØ6¸¸d¿n¹nÑ8LÈgÐW^Ð7_Ð6`ð aØ ×%Ñ%Ó'Ð(ð*óð ð
 Ð%Ø×"Ñ"Ó$¨¨a°¸'Ð(BÒBÜ Ø7¸¸aÀÈ'Ð8RÐ7SÐS\Ð]k×]pÑ]pÓ]rÐ\sÐtóð ð (×,Ñ,¨S°$·.±.À'È7ÓSÐVdÑdˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLä—}‘}×,Ñ,¨\¸rÐ,ÓBˆàÐ&Ø×#Ñ#Ó%¨$¯.©.Ð):Ò:Ü ØEÀtÇ~Á~ÐFWÐEXð YØ'×,Ñ,Ó.Ð/ð1óð ð +×/Ñ/°°2°q¸!Ó<¸|×?PÑ?PÐQTÐVZ×VdÑVdÐfmÐovÓ?wÑwˆLØ'×,Ñ,¨S°4·>±>Ñ-AÀ7ÈGÓTˆLáð
 %1×$5Ñ$5°c¸4¿>¹>È7ÐT[Ó$\Ð!Ø0×5Ñ5°c¸D¿N¹NÑ6JÈGÐU\Ó]‰Là$(Ð!ä—]‘]×*Ñ*¨<¸4¿<¹<ÐRV×R_ÑR_Ð*Ó`ˆ
ä—i‘i 
¨LÓ9ˆà×ÑÓ #¨¯©Ñ"6¸ÀÇÁÐ!OÒOÜØ2°C¸$¿.¹.Ñ4HÈ'ÐSW×S`ÑS`Ð3aÐ2bð cØ×$Ñ$Ó&Ð'ð)óð ð
 "×&Ñ& s¨D¯N©N¸GÀTÇ]Á]ÓSˆØ!×+Ñ+¨A¨qÓ1ˆð "×)Ñ)¨#¨w¸¿¹ÓGˆà—m‘m KÓ0ˆàÐ1°>ÐAÐAr<   )ç        FTFN©NNNNF)r2   r3   r4   r5   rƒ   r:   Úboolr   r)   rT   r6   r†   rŸ   r	   r‚   r‡   rˆ   s   @r=   rŠ   rŠ       sM  ø„ ÙGð Ø ØØØ+/ñCàðCð ðCð ð	Cð
 ðCð ðCð ðCð ˜Ñ(õCð>e˜UŸ\™\ð e°Cð e¸có eð 48Ø8<Ø15Ø26Ø"'ñvBà—|‘|ðvBð # 5§<¡<Ñ0ðvBð !  u§|¡|Ñ!4Ñ5ð	vBð
 ! §¡Ñ.ðvBð " %§,¡,Ñ/ðvBð  ðvBð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷vBr<   rŠ   c                   óV  ‡ — e Zd ZdZˆ fd„Zdej                  dedefd„Z	 	 	 	 	 ddej                  de	ej                     d	e	e
ej                        d
e	ej                     de	ej                     dede
ej                  e	ej                     e	e
ej                        f   fd„Zˆ xZS )ÚMusicgenFlashAttention2aL  
    Musicgen flash attention module. This module inherits from `MusicgenAttention` as the weights of the module stays
    untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
    flash attention and deal with padding tokens in case the input contains any of them.
    c                 óB   •— t        ‰| �  |i |¤Ž t        «       | _        y rR   )rS   rT   r   Ú_flash_attn_uses_top_left_mask)rV   ÚargsÚkwargsrW   s      €r=   rT   z MusicgenFlashAttention2.__init__F  s#   ø€ Ü‰Ñ˜$Ð) &Ò)ô
 /PÓ.QˆÕ+r<   r›   r€   r~   c                 óR   — |j                  ||| j                  | j                  «      S rR   )rs   rŒ   r”   rž   s       r=   Ú_reshapez MusicgenFlashAttention2._reshapeN  s   € Ø�{‰{˜3 ¨¯©¸¿¹ÓGÐGr<   r    r¡   r¢   r0   r£   r¤   r¥   c           
      óÎ  — |rt        d«      ‚|d u}|j                  «       \  }}	}
| j                  | j                  |«      d|«      }|rP|�N|d   j                  d   |j                  d   k(  r,|d   j                  dd«      }|d   j                  dd«      }�n*|rE| j                  | j                  |«      d|«      }| j                  | j                  |«      d|«      }nã|��| j                  | j                  |«      d|«      }| j                  | j                  |«      d|«      }t        j                  |d   j                  dd«      |gd¬«      }t        j                  |d   j                  dd«      |gd¬«      }nD| j                  | j                  |«      d|«      }| j                  | j                  |«      d|«      }| j                  r$|j                  dd«      |j                  dd«      f}|j                  d   }|�||d   j                  d   z  }|j                  }|t        j                  k(  rÂt        j                  «       rt        j                  «       }nMt        | j                   d«      r| j                   j"                  }n | j                  j$                  j                  }t&        j)                  d	|› d
�«       |j+                  |«      }|j+                  |«      }|j+                  |«      }t-        |||||	| j.                  r| j0                  nd| j2                  | j4                  ¬«      }|j7                  ||	d«      }| j9                  |«      }|sd }||fS )NzDMusicgenFlashAttention2 attention does not support output_attentionsrB   r   r$   r(   rh   éþÿÿÿÚ_pre_quantization_dtypez¾The input hidden states seems to be silently casted in float32, this might be related to the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in ú.r½   )r�   r�   Úuse_top_left_mask)rI   rz   rÇ   r™   rG   rE   r—   r˜   r6   rp   rŽ   r\   Úfloat32Úis_autocast_enabledÚget_autocast_gpu_dtyper_   r‘   rÊ   ÚweightÚloggerÚwarning_oncer`   r+   r«   r�   r�   rÃ   r­   rš   )rV   r    r¡   r¢   r0   r£   r¤   r±   r~   Úq_lenr³   r´   rµ   r¶   Ú
kv_seq_lenÚinput_dtypeÚtarget_dtyper¼   r¹   s                      r=   r‚   zMusicgenFlashAttention2.forwardQ  s0  € ñ ÜÐcÓdÐdð .°TÐ9Ðà%×*Ñ*Ó,‰ˆˆU�Að —}‘} T§[¡[°Ó%?ÀÀSÓIˆñ ØÐ*Ø˜qÑ!×'Ñ'¨Ñ*Ð.>×.DÑ.DÀQÑ.GÒGð (¨Ñ*×4Ñ4°Q¸Ó:ˆJØ)¨!Ñ,×6Ñ6°q¸!Ó<ŠLÙàŸ™ t§{¡{Ð3CÓ'DÀbÈ#ÓNˆJØŸ=™=¨¯©Ð5EÓ)FÈÈCÓP‰LØÐ'àŸ™ t§{¡{°=Ó'AÀ2ÀsÓKˆJØŸ=™=¨¯©°]Ó)CÀRÈÓMˆLÜŸ™ N°1Ñ$5×$?Ñ$?ÀÀ1Ó$EÀzÐ#RÐXYÔZˆJÜ Ÿ9™9 n°QÑ&7×&AÑ&AÀ!ÀQÓ&GÈÐ%VÐ\]Ô^‰Lð Ÿ™ t§{¡{°=Ó'AÀ2ÀsÓKˆJØŸ=™=¨¯©°]Ó)CÀRÈÓMˆLà�?Š?ð )×2Ñ2°1°aÓ8¸,×:PÑ:PÐQRÐTUÓ:VÐWˆNà×%Ñ% bÑ)ˆ
ØÐ%Ø˜.¨Ñ+×1Ñ1°"Ñ5Ñ5ˆJð #×(Ñ(ˆØœ%Ÿ-™-Ò'Ü×(Ñ(Ô*Ü$×;Ñ;Ó=‘ä˜Ÿ™Ð&?Ô@Ø#Ÿ{™{×BÑB‘à#Ÿ{™{×1Ñ1×7Ñ7�ä×Ñðà �> ð$ôð (Ÿ?™?¨<Ó8ˆLØ#Ÿ™ |Ó4ˆJØ'Ÿ?™?¨<Ó8ˆLä.ØØØØØØ$(§M¢M�D—L’L°sØ—n‘nØ"×AÑAô	
ˆð "×)Ñ)¨#¨u°bÓ9ˆØ—m‘m KÓ0ˆá ØˆLà˜L¨.Ð8Ð8r<   r¾   )r2   r3   r4   r5   rT   r6   r†   rƒ   rÇ   r   r	   r¿   r‚   r‡   rˆ   s   @r=   rÁ   rÁ   ?  sæ   ø„ ñôRðH˜uŸ|™|ð H°cð HÀó Hð 48Ø8<Ø15Ø26Ø"'ñi9à—|‘|ði9ð # 5§<¡<Ñ0ði9ð !  u§|¡|Ñ!4Ñ5ð	i9ð
 ! §¡Ñ.ði9ð " %§,¡,Ñ/ði9ð  ði9ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷i9r<   rÁ   c                   ó$  ‡ — e Zd Z	 	 	 	 	 d	dej                  deej                     deeej                        deej                     deej                     dedeej                  eej                     eeej                        f   fˆ fd„Zˆ xZ	S )
ÚMusicgenSdpaAttentionr    r¡   r¢   r0   r£   r¤   r¥   c                 ój  •— |s|�*t         j                  d«       t        ‰| �  ||||||¬«      S |�v|j	                  g d¢¬«      t        j                  |j                  «      j                  k  j                  «       r*t         j                  d«       t        ‰| �  ||||||¬«      S |du}|j                  «       \  }}	}
| j                  |«      }|r0|�.|d   j                  d   |j                  d	   k(  r|d   }|d	   }�n
|rE| j                  | j                  |«      d
|«      }| j                  | j                  |«      d
|«      }nÃ|�}| j                  | j                  |«      d
|«      }| j                  | j                  |«      d
|«      }t        j                   |d   |gd¬«      }t        j                   |d	   |gd¬«      }nD| j                  | j                  |«      d
|«      }| j                  | j                  |«      d
|«      }| j"                  r||f}| j                  ||	|«      }| j$                  r	|€|	d	kD  rdnd}t
        j&                  j(                  j+                  ||||| j,                  r| j.                  nd|¬«      }|j                  «       || j0                  |	| j2                  fk7  r7t5        d|| j0                  |	| j2                  f› d|j                  «       › �«      ‚|j7                  d	d«      }|j9                  ||	| j:                  «      }| j=                  |«      }|d|fS )r§   Na«  MusicgenModel is using MusicgenSdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True` or `layer_head_mask` not None. Falling back to the manual attention implementation, but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.)r¡   r¢   r0   r£   r¤   )r(   r$   r   rh   aº  `torch.nn.functional.scaled_dot_product_attention` does not support having an empty attention mask. Falling back to the manual attention implementation. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.Note that this probably happens because `guidance_scale>1` or because you used `get_unconditional_inputs`. See https://github.com/huggingface/transformers/issues/31189 for more information.r   r$   r(   rB   TFr½   )Ú	attn_maskÚ	dropout_pr�   r¬   r¨   )rÑ   rÒ   rS   r‚   Úmeanr6   Úfinfor\   ÚminÚanyrz   r™   rG   rŸ   r—   r˜   rp   rŽ   r�   ra   r¯   Úscaled_dot_product_attentionr«   r�   rŒ   r”   rI   rE   r­   r‹   rš   )rV   r    r¡   r¢   r0   r£   r¤   r±   r~   r²   r³   r´   rµ   r¶   r�   r¼   rW   s                   €r=   r‚   zMusicgenSdpaAttention.forward¾  sO  ø€ ñ  Ð ;ä×Ñðlôô ‘7‘?ØØ!1Ø-Ø-Ø /Ø"3ð #ó ð ð Ð&Ø×$Ñ$ªÐ$Ó3´u·{±{À>×CWÑCWÓ7X×7\Ñ7\Ñ\×aÑaÔcä×ÑðPôô ‘7‘?ØØ!1Ø-Ø-Ø /Ø"3ð #ó ð ð .°TÐ9Ðà'×,Ñ,Ó.‰ˆˆW�að —{‘{ =Ó1ˆñ ØÐ*Ø˜qÑ!×'Ñ'¨Ñ*Ð.>×.DÑ.DÀQÑ.GÒGð (¨Ñ*ˆJØ)¨!Ñ,ŠLÙàŸ™ T§[¡[Ð1AÓ%BÀBÈÓLˆJØŸ;™; t§{¡{Ð3CÓ'DÀbÈ#ÓN‰LØÐ'àŸ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLÜŸ™ N°1Ñ$5°zÐ#BÈÔJˆJÜ Ÿ9™9 n°QÑ&7¸Ð%FÈAÔN‰Lð Ÿ™ T§[¡[°Ó%?ÀÀSÓIˆJØŸ;™; t§{¡{°=Ó'AÀ2ÀsÓKˆLà�?Š?ð )¨,Ð7ˆNà—{‘{ <°¸#Ó>ˆð
 !ŸNšN¨~Ð/EÈ'ÐTUÊ+‘DÐ[`ˆ	ô —h‘h×)Ñ)×FÑFØØØØ$Ø&*§m¢m�d—l’l¸Øð Gó 
ˆð ×ÑÓ # t§~¡~°wÀÇÁÐ!NÒNÜØ2°C¸¿¹ÈÐRV×R_ÑR_Ð3`Ð2að bØ×$Ñ$Ó&Ð'ð)óð ð
 "×+Ñ+¨A¨qÓ1ˆð "×)Ñ)¨#¨w¸¿¹ÓGˆà—m‘m KÓ0ˆà˜D .Ð0Ð0r<   r¾   )
r2   r3   r4   r6   r†   r   r	   r¿   r‚   r‡   rˆ   s   @r=   rØ   rØ   ½  s¿   ø„ ð 48Ø8<Ø15Ø26Ø"'ñw1à—|‘|ðw1ð # 5§<¡<Ñ0ðw1ð !  u§|¡|Ñ!4Ñ5ð	w1ð
 ! §¡Ñ.ðw1ð " %§,¡,Ñ/ðw1ð  ðw1ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷w1ñ w1r<   rØ   )ÚeagerÚsdpaÚflash_attention_2c                   ó<  ‡ — e Zd Zdefˆ fd„Z	 	 	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     deej                     d	eeej                        d
ee	   dee	   dej                  fd„Z
ˆ xZS )ÚMusicgenDecoderLayerr‘   c           	      óZ  •— t         ‰| �  «        |j                  | _        t	        |j
                     | j                  |j                  |j                  ddd|¬«      | _        |j                  | _	        t        |j                     | _        |j                  | _        t        j                  | j                  «      | _        t	        |j
                     | j                  |j                  |j                  dd|¬«      | _        t        j                  | j                  «      | _        t        j&                  | j                  |j(                  d¬«      | _        t        j&                  |j(                  | j                  d¬«      | _        t        j                  | j                  «      | _        y )NTF)r‹   rŒ   r�   rŽ   r�   r�   r‘   )r�   rŽ   r�   r‘   r“   )rS   rT   Úhidden_sizer‹   ÚMUSICGEN_ATTENTION_CLASSESÚ_attn_implementationÚnum_attention_headsÚattention_dropoutÚ	self_attnr�   r   Úactivation_functionÚactivation_fnÚactivation_dropoutra   Ú	LayerNormÚself_attn_layer_normÚencoder_attnÚencoder_attn_layer_normr–   Úffn_dimÚfc1Úfc2Úfinal_layer_norm©rV   r‘   rW   s     €r=   rT   zMusicgenDecoderLayer.__init__@  s8  ø€ Ü‰ÑÔØ×+Ñ+ˆŒä3°F×4OÑ4OÑPØ—n‘nØ×0Ñ0Ø×,Ñ,ØØØØô
ˆŒð —~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔä$&§L¡L°·±Ó$@ˆÔ!Ü6°v×7RÑ7RÑSØ�N‰NØ×&Ñ&Ø×,Ñ,ØØØô
ˆÔô (*§|¡|°D·N±NÓ'CˆÔ$Ü—9‘9˜TŸ^™^¨V¯^©^À%ÔHˆŒÜ—9‘9˜VŸ^™^¨T¯^©^À%ÔHˆŒÜ "§¡¨T¯^©^Ó <ˆÕr<   r    r0   Úencoder_hidden_statesÚencoder_attention_maskr£   Úcross_attn_layer_head_maskr¢   r¤   Ú	use_cacher¥   c
                 ót  — |}
| j                  |«      }|�|dd nd}| j                  |||||¬«      \  }}}t        j                  j	                  || j                  | j
                  ¬«      }|
|z   }d}d}|�w|}
| j                  |«      }|�|dd nd}| j                  ||||||¬«      \  }}}t        j                  j	                  || j                  | j
                  ¬«      }|
|z   }||z   }|}
| j                  |«      }| j                  | j                  |«      «      }t        j                  j	                  || j                  | j
                  ¬«      }| j                  |«      }t        j                  j	                  || j                  | j
                  ¬«      }|
|z   }|f}|r|||fz  }|	r||fz  }|S )a  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`): attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            encoder_hidden_states (`torch.FloatTensor`):
                cross attention input to the layer of shape `(batch, seq_len, embed_dim)`
            encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
                `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
                `(encoder_attention_heads,)`.
            cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
                size `(decoder_attention_heads,)`.
            past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
        Nr$   )r    r¢   r0   r£   r¤   r©   rÉ   )r    r¡   r0   r£   r¢   r¤   )rñ   rì   ra   r¯   r�   r«   ró   rò   r÷   rî   rõ   rï   rö   )rV   r    r0   rù   rú   r£   rû   r¢   r¤   rü   ÚresidualÚself_attn_past_key_valueÚself_attn_weightsÚpresent_key_valueÚcross_attn_present_key_valueÚcross_attn_weightsÚcross_attn_past_key_valueÚoutputss                     r=   r‚   zMusicgenDecoderLayer.forward`  s  € ð< !ˆØ×1Ñ1°-Ó@ˆð :HÐ9S >°"°1Ñ#5ÐY]Ð à>B¿n¹nØ'Ø3Ø)Ø+Ø/ð ?Mó ?
Ñ;ˆÐ(Ð*;ô Ÿ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆð (,Ð$Ø!ÐØ Ð,Ø$ˆHØ ×8Ñ8¸ÓGˆMð @NÐ?Y¨°r°sÑ(;Ð_cÐ%ØNR×N_ÑN_Ø+Ø!6Ø5Ø :Ø8Ø"3ð O`ó OÑKˆMÐ-Ð/Kô ŸM™M×1Ñ1°-À4Ç<Á<ÐZ^×ZgÑZgÐ1ÓhˆMØ$ }Ñ4ˆMð !2Ð4PÑ PÐð !ˆØ×-Ñ-¨mÓ<ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆÜŸ™×-Ñ-¨m¸t×?VÑ?VÐae×anÑanÐ-ÓoˆØŸ™ Ó/ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆà Ð"ˆáØÐ)Ð+=Ð>Ñ>ˆGáØÐ)Ð+Ñ+ˆGàˆr<   )NNNNNNFT)r2   r3   r4   r*   rT   r6   r†   r   r	   r¿   r‚   r‡   rˆ   s   @r=   rå   rå   ?  sè   ø„ ð=Ð4õ =ðF 26Ø8<Ø9=Ø26Ø=AØ8<Ø,1Ø$(ñWà—|‘|ðWð ! §¡Ñ.ðWð  (¨¯©Ñ5ð	Wð
 !)¨¯©Ñ 6ðWð " %§,¡,Ñ/ðWð %-¨U¯\©\Ñ$:ðWð !  u§|¡|Ñ!4Ñ5ðWð $ D™>ðWð ˜D‘>ðWð 
�‰÷Wr<   rå   c                   ó2   — e Zd ZdZeZdZdZddgZdZ	dZ
d„ Zy)ÚMusicgenPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚmodelTrå   rŠ   c                 óú  — | j                   j                  }t        |t        j                  t        j
                  f«      rY|j                  j                  j                  d|¬«       |j                  �%|j                  j                  j                  «        y y t        |t        j                  «      rf|j                  j                  j                  d|¬«       |j                  �2|j                  j                  |j                     j                  «        y y t        |t        «      rR |j                  |j                  j                   Ž }t        j"                  |d¬«      }|j%                  «        ||_        y y )Nr½   )rÜ   ÚstdF)rc   )r‘   Úinitializer_factorÚ
isinstancera   r–   ÚConv1drÐ   ÚdataÚnormal_r�   Úzero_Ú	EmbeddingÚpadding_idxrN   r^   rZ   rG   rb   rd   )rV   Úmoduler
  rZ   s       r=   Ú_init_weightsz%MusicgenPreTrainedModel._init_weightsÇ  s  € Ø�k‰k×,Ñ,ˆÜ�fœrŸy™y¬"¯)©)Ð4Ô5Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ä˜Ô EÔFØ*�f×*Ñ*¨F¯N©N×,@Ñ,@ÐAˆGÜ—l‘l 7¸%Ô@ˆGØ�O‰OÔØ$ˆF�Nð	 Gr<   N)r2   r3   r4   r5   r*   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_supports_flash_attn_2Ú_supports_sdpar  r;   r<   r=   r  r  º  s6   „ ñð
 )€LØÐØ&*Ð#Ø/Ð1DÐEÐØ!ÐØ€Nó%r<   r  u‡  

    The Musicgen model was proposed in [Simple and Controllable Music Generation](https://arxiv.org/abs/2306.05284) by
    Jade Copet, Felix Kreuk, Itai Gat, Tal Remez, David Kant, Gabriel Synnaeve, Yossi Adi, Alexandre DÃ©fossez. It is an
    encoder decoder transformer trained on the task of conditional music generation

    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

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

    Parameters:
        config ([`MusicgenConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a4  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
            it.

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

            [What are input IDs?](../glossary#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)
        decoder_input_ids (`torch.LongTensor` of shape `(batch_size * num_codebooks, target_sequence_length)`, *optional*):
            Indices of decoder input sequence tokens in the vocabulary, corresponding to the sequence of audio codes.

            Indices can be obtained by encoding an audio prompt with an audio encoder model to predict audio codes,
            such as with the [`EncodecModel`]. See [`EncodecModel.encode`] for details.

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

            <Tip warning={true}>

            The `decoder_input_ids` will automatically be converted from shape `(batch_size * num_codebooks,
            target_sequence_length)` to `(batch_size, num_codebooks, target_sequence_length)` in the forward pass. If
            you obtain audio codes from an audio encoding model, such as [`EncodecModel`], ensure that the number of
            frames is equal to 1, and that you reshape the audio codes from `(frames, batch_size, num_codebooks,
            target_sequence_length)` to `(batch_size * num_codebooks, target_sequence_length)` prior to passing them as
            `decoder_input_ids`.

            </Tip>

        decoder_attention_mask (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
            Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
            be used by default.
        head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
            Mask to nullify selected heads of the attention modules in the encoder. Mask values selected in `[0, 1]`:

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

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

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

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

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

        encoder_outputs (`tuple(tuple(torch.FloatTensor)`, *optional*):
            Tuple consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*: `attentions`)
            `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*) is a sequence of
            hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
        past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
            Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of shape
            `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of shape
            `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

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

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

            If `decoder_input_ids` and `decoder_inputs_embeds` are both unset, `decoder_inputs_embeds` takes the value
            of `inputs_embeds`.
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length, num_codebooks)`, *optional*):
            Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
            `labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
            are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
        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.
aç  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size * num_codebooks, sequence_length)`):
            Indices of input sequence tokens in the vocabulary, corresponding to the sequence of audio codes.

            Indices can be obtained by encoding an audio prompt with an audio encoder model to predict audio codes,
            such as with the [`EncodecModel`]. See [`EncodecModel.encode`] for details.

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

            <Tip warning={true}>

            The `input_ids` will automatically be converted from shape `(batch_size * num_codebooks,
            target_sequence_length)` to `(batch_size, num_codebooks, target_sequence_length)` in the forward pass. If
            you obtain audio codes from an audio encoding model, such as [`EncodecModel`], ensure that the number of
            frames is equal to 1, and that you reshape the audio codes from `(frames, batch_size, num_codebooks,
            target_sequence_length)` to `(batch_size * num_codebooks, target_sequence_length)` prior to passing them as
            `input_ids`.

            </Tip>

        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)
        encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, encoder_sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention of
            the decoder.
        encoder_attention_mask (`torch.LongTensor` of shape `(batch_size, encoder_sequence_length)`, *optional*):
            Mask to avoid performing cross-attention on padding tokens indices of encoder input_ids. Mask values
            selected in `[0, 1]`:

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

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

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

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

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

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

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

            If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
            don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_ids` of shape `(batch_size, sequence_length)`.
        inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
            This is useful if you want more control over how to convert `input_ids` indices into associated vectors
            than the model's internal embedding lookup matrix.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                   óž  ‡ — e Zd ZdZdefˆ fd„Zd„ Zd„ Z ee	«      	 	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
eeej                           de
ej                     de
e   de
e   de
e   de
e   deeef   fd„«       Zˆ xZS )ÚMusicgenDecoderzw
    Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`MusicgenDecoderLayer`]
    r‘   c           	      ó€  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  rt        j                  |j                  «      nd| _        |j                  dz   }t        j                  t!        |j                  «      D �cg c]"  }t        j"                  ||j                  «      ‘Œ$ c}«      | _        t'        |j                  |j                  «      | _        t        j                  t!        |j*                  «      D �cg c]  }t-        |«      ‘Œ c}«      | _        t        j0                  |j                  «      | _        |j4                  | _        d| _        | j;                  «        y c c}w c c}w )Nç      ð?r(   F)rS   rT   r�   Ú	layerdropÚmax_position_embeddingsÚmax_target_positionsrç   Úd_modelÚnum_codebooksÚscale_embeddingrj   ÚsqrtÚembed_scaleÚ
vocab_sizera   Ú
ModuleListÚranger  Úembed_tokensrN   Úembed_positionsÚnum_hidden_layersrå   Úlayersrð   Ú
layer_normré   Úattn_implementationÚgradient_checkpointingÚ	post_init)rV   r‘   r‹   r³   rW   s       €r=   rT   zMusicgenDecoder.__init__¥  sQ  ø€ Ü‰Ñ˜Ô Ø—~‘~ˆŒØ×)Ñ)ˆŒØ$*×$BÑ$BˆÔ!Ø×)Ñ)ˆŒØ#×1Ñ1ˆÔØ<B×<RÒ<Rœ4Ÿ9™9 V×%7Ñ%7Ô8ÐX[ˆÔà×%Ñ%¨Ñ)ˆ	ÜŸM™MÜBGÈ×H\ÑH\ÓB]Ö^¸QŒR�\‰\˜) V×%7Ñ%7Õ8Ò^ó
ˆÔô  EØ×*Ñ*Ø×Ñó 
ˆÔô
 —m‘mÌ5ÐQW×QiÑQiÓKjÖ$kÀaÔ%9¸&Õ%AÒ$kÓlˆŒÜŸ,™, v×'9Ñ'9Ó:ˆŒØ#)×#>Ñ#>ˆÔ à&+ˆÔ#à�‰Õùò _ùò %ls   Ã'F6ÅF;c                 ó   — | j                   S rR   ©r*  ©rV   s    r=   Úget_input_embeddingsz$MusicgenDecoder.get_input_embeddingsÀ  ó   € Ø× Ñ Ð r<   c                 ó   — || _         y rR   r3  ©rV   Úvalues     r=   Úset_input_embeddingsz$MusicgenDecoder.set_input_embeddingsÃ  s
   € Ø!ˆÕr<   r>   r0   rù   rú   Ú	head_maskÚcross_attn_head_maskÚpast_key_valuesÚinputs_embedsrü   r¤   Úoutput_hidden_statesÚreturn_dictr¥   c                 óÀ  — |
�|
n| j                   j                  }
|�|n| j                   j                  }|	�|	n| j                   j                  }	|�|n| j                   j                  }|�|�t        d«      ‚|�?|j                  d| j                  |j                  d   «      }|j                  \  }}}||f}n/|�"|j                  «       d d }|d d …d d …dd …f   }nt        d«      ‚|�|d   d   j                  d   nd}|€<t        t        «      D �cg c]  } | j                  |   |d d …|f   «      ‘Œ  c}«      }| j                  dk(  r|�d|v r|nd }n0| j                  dk(  r|€|
st        ||||«      }nt        ||||«      }|�d|�b| j                  dk(  r	d|v r|nd }nJ| j                  dk(  r |€|
st!        ||j"                  |d   ¬«      }nt%        ||j"                  |d   ¬«      }| j'                  ||«      }||j)                  |j*                  «      z   }t,        j.                  j1                  || j0                  | j2                  ¬	«      }| j4                  r%| j2                  r|	rt6        j9                  d
«       d}	|rdnd }|
rdnd }|
r|�dnd }|	rdnd }t;        ||gddg«      D ]j  \  }}|€Œ	|j                  «       d   t=        | j>                  «      k7  sŒ3t        d|› dt=        | j>                  «      › d|j                  «       d   › d�«      ‚ tA        | j>                  «      D ]Þ  \  }}|r||fz  }tC        jD                  dd«      }| j2                  r|| jF                  k  rŒ@|�||   nd }| j4                  r?| j2                  r3| jI                  |jJ                  |||||�||   nd |�||   nd d |
|	«
      } n ||||||�||   nd |�||   nd ||
|	¬«	      } | d   }|	r|| |
rdnd   fz  }|
sŒÊ|| d   fz  }|€ŒÖ|| d   fz  }Œà | jM                  |«      }|r||fz  }|	r|nd }!|stO        d„ ||!|||fD «       «      S tQ        ||!|||¬«      S c c}w )NzTYou cannot specify both decoder_input_ids and decoder_inputs_embeds at the same timerB   zEYou have to specify either decoder_input_ids or decoder_inputs_embedsr   r$   rã   râ   )r²   r©   z[`use_cache=True` is incompatible with gradient checkpointing`. Setting `use_cache=False`...Fr;   r;  r<  zThe `z` should be specified for z layers, but it is for rË   r(   )r0   rù   rú   r£   rû   r¢   r¤   rü   r   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wrR   r;   )Ú.0Úvs     r=   ú	<genexpr>z*MusicgenDecoder.forward.<locals>.<genexpr>h  s   è ø€ ò àØ�=ô ñùs   ‚©Úlast_hidden_stater=  r    Ú
attentionsÚcross_attentions))r‘   r¤   r?  rü   Úuse_return_dictrI   r­   r#  rG   rz   Úsumr)  r*  r/  r   r   r   r\   r   r+  r`   r]   ra   r¯   r�   r«   r0  rÑ   rÒ   ÚzipÚlenr-  Ú	enumerateÚrandomÚuniformr  Ú_gradient_checkpointing_funcr‚   r.  Útupler   )"rV   r>   r0   rù   rú   r;  r<  r=  r>  rü   r¤   r?  r@  Úinputr~   r#  r€   Úinput_shaperx   ÚcodebookÚ	positionsr    Úall_hidden_statesÚall_self_attnsÚall_cross_attentionsÚnext_decoder_cacherÚ   Ú	mask_nameÚidxÚdecoder_layerÚdropout_probabilityr¢   Úlayer_outputsÚ
next_caches"                                     r=   r‚   zMusicgenDecoder.forwardÆ  sl  € ð  2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ð  ]Ð%>ÜÐsÓtÐtØÐ"à×%Ñ% b¨$×*<Ñ*<¸i¿o¹oÈbÑ>QÓRˆEØ*/¯+©+Ñ'ˆC� Ø ˜.‰KØÐ&Ø'×,Ñ,Ó.¨s°Ð3ˆKØ!¢!¢Q¨© )Ñ,‰EäÐdÓeÐeð DSÐC^ °Ñ!3°AÑ!6×!<Ñ!<¸QÒ!?ÐdeÐàÐ ÜÔafÐgtÓauÖ vÐU]Ð!< ×!2Ñ!2°8Ñ!<¸UÂ1ÀhÀ;Ñ=OÕ!PÒ vÓwˆMà×#Ñ#Ð':Ò:Ø0>Ð0JÈqÐTbÑOb™^Ðim‰NØ×%Ñ%¨Ò/°IÐ4EÑN_ô HØØØØ&ó	‰Nô ?Ø ¨]Ð<RóˆNð
 !Ð,Ð1GÐ1SØ×'Ñ'Ð+>Ò>ØCDÐH^ÑC^Ñ)?ÐdhÑ&Ø×)Ñ)¨VÒ3Ð8LÐ8TÑ]nô *MØ*Ø!×'Ñ'Ø'¨™Oô*Ñ&ô *DØ*¨M×,?Ñ,?ÈÐUWÉô*Ð&ð
 ×(Ñ(¨Ð0FÓGˆ	à%¨	¯©°]×5IÑ5IÓ(JÑJˆäŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆà×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øqôð "�	ñ #7™B¸DÐÙ0™°dˆÙ&7Ð<QÐ<]™rÐdhÐÙ#,™R°$Ðô %(¨Ð4HÐ(IÈKÐYoÐKpÓ$qò 	Ñ ˆI�yØÑ$Ø—>‘>Ó# AÑ&¬#¨d¯k©kÓ*:Ó:Ü$Ø 	˜{Ð*DÄSÈÏÉÓEUÐDVð WØ%ŸN™NÓ,¨QÑ/Ð0°ð3óð ð	ô #,¨D¯K©KÓ"8ò .	@ÑˆC�á#Ø! mÐ%5Ñ5Ð!Ü"(§.¡.°°AÓ"6ÐØ�}Š}Ð"5¸¿¹Ò"FØà5DÐ5P˜_¨SÒ1ÐVZˆNà×*Ò*¨t¯}ª}Ø $× AÑ AØ!×)Ñ)Ø!Ø"Ø)Ø*Ø&/Ð&;�I˜c’NÀØ1EÐ1QÐ(¨Ò-ÐW[ØØ%Øó!‘ñ !.Ø!Ø#1Ø*?Ø+AØ7@Ð7L Y¨s¢^ÐRVà5IÐ5UÐ,¨SÒ1Ð[_à#1Ø&7Ø'ô!�ð *¨!Ñ,ˆMáØ" }Ñ:K±QÐQRÑ'SÐ&UÑUÐ"â Ø =°Ñ#3Ð"5Ñ5�à(Ñ4Ø(¨]¸1Ñ-=Ð,?Ñ?Ñ(ð].	@ð` Ÿ™¨Ó6ˆñ  Ø -Ð!1Ñ1Ðá+4Ñ'¸$ˆ
ÙÜñ à'¨Ð5FÈÐXlÐmôó ð ô
 9Ø+Ø&Ø+Ø%Ø1ô
ð 	
ùò} !ws   Ä#Q©NNNNNNNNNNNN)r2   r3   r4   r5   r*   rT   r5  r:  r!   Ú!MUSICGEN_DECODER_INPUTS_DOCSTRINGr   r6   r9   r†   r7   r	   r¿   r
   r   r‚   r‡   rˆ   s   @r=   r  r     sf  ø„ ñðÐ4õ ò6!ò"ñ +Ð+LÓMð 15Ø15Ø=AØ=AØ,0Ø7;ØEIØ59Ø$(Ø,0Ø/3Ø&*ñl
à˜E×,Ñ,Ñ-ðl
ð ! §¡Ñ.ðl
ð  (¨×(9Ñ(9Ñ:ð	l
ð
 !)¨×)9Ñ)9Ñ :ðl
ð ˜EŸL™LÑ)ðl
ð ' u§|¡|Ñ4ðl
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðl
ð   × 1Ñ 1Ñ2ðl
ð ˜D‘>ðl
ð $ D™>ðl
ð ' t™nðl
ð ˜d‘^ðl
ð 
ˆuÐ?Ð?Ñ	@òl
ó Nôl
r<   r  z^The bare Musicgen decoder model outputting raw hidden-states without any specific head on top.c                   ó   ‡ — e Zd Zdefˆ fd„Zd„ Zd„ Zd„ Z ee	«      	 	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
eeej                           de
ej                     de
e   de
e   de
e   de
e   deeef   fd„«       Zˆ xZS )ÚMusicgenModelr‘   c                 ód   •— t         ‰| �  |«       t        |«      | _        | j	                  «        y rR   )rS   rT   r  Údecoderr1  rø   s     €r=   rT   zMusicgenModel.__init__{  s&   ø€ Ü‰Ñ˜Ô Ü& vÓ.ˆŒà�‰Õr<   c                 ó.   — | j                   j                  S rR   ©rf  r*  r4  s    r=   r5  z"MusicgenModel.get_input_embeddings�  s   € Ø�|‰|×(Ñ(Ð(r<   c                 ó&   — || j                   _        y rR   rh  r8  s     r=   r:  z"MusicgenModel.set_input_embeddings„  s   € Ø$)ˆ�‰Õ!r<   c                 ó   — | j                   S rR   ©rf  r4  s    r=   Úget_decoderzMusicgenModel.get_decoder‡  ó   € Ø�|‰|Ðr<   r>   r0   rù   rú   r;  r<  r=  r>  rü   r¤   r?  r@  r¥   c                 ó˜  — |
�|
n| j                   j                  }
|�|n| j                   j                  }|	�|	n| j                   j                  }	|�|n| j                   j                  }| j                  |||||||||	|
||¬«      }|s|S t        |j                  |j                  |j                  |j                  |j                  ¬«      S )N)r>   r0   rú   rù   r;  r<  r=  r>  rü   r¤   r?  r@  rF  )r‘   r¤   r?  rü   rJ  rf  r   rG  r=  r    rH  rI  )rV   r>   r0   rù   rú   r;  r<  r=  r>  rü   r¤   r?  r@  Údecoder_outputss                 r=   r‚   zMusicgenModel.forwardŠ  sæ   € ð  2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð Ÿ,™,ØØ)Ø#9Ø"7ØØ!5Ø+Ø'ØØ/Ø!5Ø#ð 'ó 
ˆñ Ø"Ð"ä8Ø-×?Ñ?Ø+×;Ñ;Ø)×7Ñ7Ø&×1Ñ1Ø,×=Ñ=ô
ð 	
r<   ra  )r2   r3   r4   r*   rT   r5  r:  rl  r!   rb  r   r6   r9   r†   r7   r	   r¿   r
   r   r‚   r‡   rˆ   s   @r=   rd  rd  v  sW  ø„ ð
Ð4õ ò)ò*òñ +Ð+LÓMð 15Ø15Ø=AØ=AØ,0Ø7;ØEIØ59Ø$(Ø,0Ø/3Ø&*ñ/
à˜E×,Ñ,Ñ-ð/
ð ! §¡Ñ.ð/
ð  (¨×(9Ñ(9Ñ:ð	/
ð
 !)¨×)9Ñ)9Ñ :ð/
ð ˜EŸL™LÑ)ð/
ð ' u§|¡|Ñ4ð/
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBð/
ð   × 1Ñ 1Ñ2ð/
ð ˜D‘>ð/
ð $ D™>ð/
ð ' t™nð/
ð ˜d‘^ð/
ð 
ˆuÐ?Ð?Ñ	@ò/
ó Nô/
r<   rd  zAThe MusicGen decoder model with a language modelling head on top.c            !       óÖ  ‡ — e Zd Zdefˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
 ee«       eee¬	«      	 	 	 	 	 	 	 	 	 	 	 	 	 d&d
eej$                     deej&                     deej(                     deej$                     deej&                     deej&                     deeeej(                           deej(                     deej$                     dee   dee   dee   dee   deeef   fd„«       «       Z	 	 	 	 	 	 	 	 	 d'd„Z	 d(d
ej$                  dedee   fd„Zed„ «       Z ej>                  «       	 	 	 	 	 	 d)deej&                     dee    d ee!   d!ee"   d"ee   d#ed$   fd%„«       Z#ˆ xZ$S )*ÚMusicgenForCausalLMr‘   c           
      óZ  •— t         ‰| �  |«       t        |«      | _        |j                  | _        t        j                  t        |j                  «      D �cg c].  }t        j                  |j                  |j                  d¬«      ‘Œ0 c}«      | _        | j                  «        y c c}w )NFr“   )rS   rT   rd  r  r#  ra   r(  r)  r–   rç   r'  Úlm_headsr1  )rV   r‘   r³   rW   s      €r=   rT   zMusicgenForCausalLM.__init__Â  s   ø€ Ü‰Ñ˜Ô ä" 6Ó*ˆŒ
à#×1Ñ1ˆÔÜŸ™ÜSXÐY_×YmÑYmÓSnÖoÈaŒR�Y‰Y�v×)Ñ)¨6×+<Ñ+<À5ÖIÒoó
ˆŒð
 	�‰Õùò	 ps   Á3B(c                 óB   — | j                   j                  j                  S rR   ©r  rf  r*  r4  s    r=   r5  z(MusicgenForCausalLM.get_input_embeddingsÏ  s   € Ø�z‰z×!Ñ!×.Ñ.Ð.r<   c                 ó:   — || j                   j                  _        y rR   ru  r8  s     r=   r:  z(MusicgenForCausalLM.set_input_embeddingsÒ  s   € Ø*/ˆ�
‰
×ÑÕ'r<   c                 ó   — | j                   S rR   ©rs  r4  s    r=   Úget_output_embeddingsz)MusicgenForCausalLM.get_output_embeddingsÕ  s   € Ø�}‰}Ðr<   c                 ó   — || _         y rR   rx  ©rV   Únew_embeddingss     r=   Úset_output_embeddingsz)MusicgenForCausalLM.set_output_embeddingsØ  s	   € Ø&ˆ�r<   c                 ó&   — || j                   _        y rR   ©r  rf  )rV   rf  s     r=   Úset_decoderzMusicgenForCausalLM.set_decoderÛ  s   € Ø$ˆ�
‰
Õr<   c                 ó.   — | j                   j                  S rR   r  r4  s    r=   rl  zMusicgenForCausalLM.get_decoderÞ  s   € Ø�z‰z×!Ñ!Ð!r<   ©Úoutput_typer  r>   r0   rù   rú   r;  r<  r=  r>  Úlabelsrü   r¤   r?  r@  r¥   c                 ól  — |�|n| j                   j                  }|	�9|€7|€5t        |	| j                   j                  | j                   j                  «      }| j                  |||||||||
|||¬«      }|d   }t        j                  | j                  D �cg c]
  } ||«      ‘Œ c}d¬«      }d}|	��|dd…dd…|	j                  d    d…f   }t        «       }t        j                  g | j                  ¬«      }|	j                  |	| j                   j                  k(  d«      }	t        | j                   j                  «      D ]f  }|dd…|f   j!                  «       j#                  d|j                  d   «      }|	d	|f   j!                  «       j#                  d«      }| |||«      z  }Œh || j                   j                  z  } |j$                  dg|j                  d
d ¢­Ž }|s|f|dd z   }|�|f|z   S |S t'        |||j(                  |j*                  |j,                  |j.                  ¬«      S c c}w )aÓ  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length, num_codebooks)`, *optional*):
            Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
            `labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
            are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
        Returns:
        N)r0   rù   rú   r;  r<  r=  r>  rü   r¤   r?  r@  r   r(   rh   ©r]   rD   rB   .r$   )ÚlossÚlogitsr=  r    rH  rI  )r‘   rJ  rL   r?   Úbos_token_idr  r6   Ústackrs  rG   r   rt   r]   Úmasked_fillr)  r#  r�   rs   r­   r   r=  r    rH  rI  )rV   r>   r0   rù   rú   r;  r<  r=  r>  r„  rü   r¤   r?  r@  rÅ   r  r    ÚheadÚ	lm_logitsr‡  rˆ  Úloss_fctrU  Úcodebook_logitsÚcodebook_labelsÚoutputs                             r=   r‚   zMusicgenForCausalLM.forwardá  sD  € ð6 &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆàÐ YÐ%6¸=Ð;PÜ*¨6°4·;±;×3KÑ3KÈTÏ[É[×MeÑMeÓfˆIà—*‘*ØØ)Ø"7Ø#9ØØ!5Ø+Ø'ØØ/Ø!5Ø#ð ó 
ˆð   ™
ˆä—K‘KÀÇÁÖ O¸¡ mÕ!4Ò OÐUVÔWˆ	àˆØÑð šq¢! f§l¡l°1¡oÐ%5Ñ%7Ð7Ñ8ˆFä'Ó)ˆHÜ—;‘;˜r¨$¯+©+Ô6ˆDð ×'Ñ'¨°$·+±+×2JÑ2JÑ(JÈDÓQˆFô " $§+¡+×";Ñ";Ó<ò C�Ø"(ª¨H¨Ñ"5×"@Ñ"@Ó"B×"GÑ"GÈÈFÏLÉLÐY[ÑL\Ó"]�Ø"(¨¨h¨Ñ"7×"BÑ"BÓ"D×"IÑ"IÈ"Ó"M�Ø™ °/ÓBÑB‘ðCð
 ˜$Ÿ+™+×3Ñ3Ñ3ˆDð &�I×%Ñ% bÐ?¨9¯?©?¸1¸2Ð+>Ò?ˆ	áØ�\ G¨A¨B KÑ/ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä0ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô
ð 	
ùò? !Ps   ÂH1c           	      ó.  — |	€?| j                  || j                  j                  | j                  j                  ¬«      \  }}	| j	                  ||	«      }|
�)|
dkD  r$|j                  d«      }|�|j                  d«      }|�|d d …dd …f   }||||||||dœS )N©r?   Ú
max_lengthr(   ©r$   r(   rB   )r>   r0   rù   rú   r;  r<  r=  rü   )Úbuild_delay_pattern_maskÚgeneration_configr?   r”  Úapply_delay_pattern_maskÚrepeat)rV   r>   r0   rù   rú   r;  r<  r=  rü   Údelay_pattern_maskr1   rÅ   s               r=   Úprepare_inputs_for_generationz1MusicgenForCausalLM.prepare_inputs_for_generation:  sË   € ð Ð%Ø,0×,IÑ,IØØ!×3Ñ3×@Ñ@Ø×1Ñ1×<Ñ<ð -Jó -Ñ)ˆIÐ)ð ×1Ñ1°)Ð=OÓPˆ	àÐ%¨.¸1Ò*<ð "×(Ñ(¨Ó0ˆIØÐ)Ø!/×!6Ñ!6°vÓ!>�àÐ&Ø!¢! R¡S &Ñ)ˆIð #Ø,Ø%:Ø&<Ø"Ø$8Ø.Ø"ñ	
ð 		
r<   r?   r”  c                 óP  — |j                  d| j                  |j                  d   «      }|j                  \  }}}|�|n| j                  j                  }t        j                  |||ft
        j                  |j                  ¬«      dz  }| j                  j                  dk(  r|dz  n|}|d|z  dz
  k  r*|j                  ||z  d«      |j                  ||z  d«      fS t        |«      D ]p  }	| j                  j                  dk(  r|dd…|	f   |dd…|	|	||	z   …f<   Œ3|dd…d|	z  f   |dd…d|	z  |	||	z   …f<   |dd…d|	z  dz   f   |dd…d|	z  dz   |	||	z   …f<   Œr t        j                  t        j                  ||ft
        j                  ¬«      ||z
  dz   ¬«      }
|
t        j                  t        j                  ||ft
        j                  ¬«      «      z   }
| j                  j                  dk(  r|
j                  dd¬	«      }
|
j!                  |j                  «       }||z  | |z  z   }|dd…ddd…f   }|dk(  j#                  «       dd…df   }t%        |«      dkD  rt'        |«      }n|}|j                  ||z  d«      }|d
d|…f   j                  ||z  d«      }||fS )aD  Build a delayed pattern mask to the input_ids. Each codebook is offset by the previous codebook 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 8, we have the delayed pattern mask of shape `(codebooks,
        seq_len)`:
        - [P, -1, -1, -1, -1, P, P, P]
        - [P, P, -1, -1, -1, -1, P, P]
        - [P, P, P, -1, -1, -1, -1, P]
        - [P, P, P, P, -1, -1, -1, -1]
        where P is the special padding token id and -1 indicates that the token is valid for prediction. If we include
        a prompt (decoder input ids), the -1 positions indicate where new tokens should be predicted. Otherwise, the
        mask is set to the value in the prompt:
        - [P, a, b, -1, -1, P, P, P]
        - [P, P, c, d, -1, -1, P, P]
        - [P, P, P, e, f, -1, -1, P]
        - [P, P, P, P, g, h, -1, -1]
        where a-h indicate the input prompt (decoder input ids) that are offset by 1. Now, we only override the -1
        tokens in our prediction.
        rB   Nr[   r$   r(   rg   )Údiagonalr   rh   .)r­   r#  rG   r—  r”  r6   ÚonesÚlongr]   r‘   Úaudio_channelsr)  Útriur¿   ÚtrilÚrepeat_interleaver`   ÚnonzerorM  rÞ   )rV   r>   r?   r”  r~   r#  r€   Úinput_ids_shiftedÚchannel_codebooksrU  Údelay_patternÚmaskÚfirst_codebook_idsÚ	start_idsÚfirst_start_idÚpattern_masks                   r=   r–  z,MusicgenForCausalLM.build_delay_pattern_maskh  sû  € ð, ×%Ñ% b¨$×*<Ñ*<¸i¿o¹oÈbÑ>QÓRˆ	Ø&/§o¡oÑ#ˆˆ]˜Gà#-Ð#9‘Z¸t×?UÑ?U×?`Ñ?`ˆ
ä�J‰J˜˜]¨JÐ7¼u¿z¹zÐR[×RbÑRbÔcÐfhÑhð 	ð 37·+±+×2LÑ2LÐPQÒ2Q˜M¨QÒ.ÐWdÐà˜Ð-Ñ-°Ñ1Ò1Ø×$Ñ$ S¨=Ñ%8¸"Ó=Ð?P×?XÑ?XÐY\Ð_lÑYlÐnpÓ?qÐqÐqô Ð/Ó0ò 	wˆHØ�{‰{×)Ñ)¨QÒ.àPYÒZ[Ð]eÐZeÑPfÐ!¢! X¨x¸'ÀHÑ:LÐ/LÐ"LÒMð U^Ò^_ÐabÐemÑamÐ^mÑTnÐ!¢! Q¨¡\°8¸gÈÑ>PÐ3PÐ"PÑQØXaÒbcÐefÐiqÑeqÐtuÑeuÐbuÑXvÐ!¢! Q¨¡\°AÑ%5°xÀ'ÈHÑBTÐ7TÐ"TÒUð	wô Ÿ
™
Ü�J‰JÐ)¨:Ð6¼e¿j¹jÔIÐT^ÐarÑTrÐuvÑTvô
ˆð &¬¯
©
´5·:±:Ð?PÐR\Ð>]Ôej×eoÑeoÔ3pÓ(qÑqˆà�;‰;×%Ñ%¨Ò*à)×;Ñ;¸AÀ1Ð;ÓEˆMà× Ñ  ×!1Ñ!1Ó2Ð2ˆØÐ,Ñ,°¨u°|Ñ/CÑCˆ	ð '¢q¨!ªQ wÑ/ÐØ'¨2Ñ-×6Ñ6Ó8º¸A¸Ñ>ˆ	Üˆy‹>˜AÒÜ  ›^‰Nð %ˆNð !×(Ñ(¨¨}Ñ)<¸bÓAˆØ˜c ? N ?Ð2Ñ3×;Ñ;¸CÀ-Ñ<OÐQSÓTˆ	Ø˜,Ð&Ð&r<   c                 ój   — | 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.rB   .N)rG   r6   Úwhere)r>   Údecoder_pad_token_maskr€   s      r=   r˜  z,MusicgenForCausalLM.apply_delay_pattern_mask³  sD   € ð —/‘/ "Ñ%ˆØ!7¸¸X¸g¸X¸Ñ!FÐÜ—K‘KÐ 6¸"Ñ <¸iÐI_Ó`ˆ	ØÐr<   Úinputsr—  Úlogits_processorÚstopping_criteriaÚsynced_gpusÚstreamerr,   c           	      óÀ  — |€| j                   }t        j                  |«      } |j                  di |¤Ž}|j	                  «        | j                  |j                  «       «       |�|n	t        «       }|�|n	t        «       }d|v}	|j                  dd«      du}
| j                  ||j                  |«      \  }}}|j                  d   | j                  z  }| j                  ||
|j                  ¬«       |j                  |d<   |j                   |d<   |j                  dd«      €|	r| j#                  |||«      |d<   |j                  d   }|j                  d	«      du xr |j$                  du}|j                  d
«      du xr |j&                  du}| j)                  ||||||¬«      }| j+                  ||j,                  |j$                  ¬«      \  }}|�|j/                  |j1                  «       «       ||d<   |j3                  «       }|j                   �:|j                   dkD  r+|j5                  t7        |j                   «      «       d|_        | j9                  |||d||j                  ¬«      }| j;                  ||¬«      }|t<        j>                  t<        j@                  fv r< | jB                  d||jD                  dœ|¤Ž\  }} | jF                  |f|||||dœ|¤Ž}ntI        d«      ‚|jJ                  r|jL                  }n|}| jO                  ||d   «      }|||jP                  k7     jS                  || j                  d«      }|jJ                  r	||_&        |S |S )á5  

        Generates sequences of token ids for models with a language modeling head.

        <Tip warning={true}>

        Most generation-controlling parameters are set in `generation_config` which, if not passed, will be set to the
        model's default generation configuration. You can override any `generation_config` by passing the corresponding
        parameters to generate(), e.g. `.generate(inputs, num_beams=4, do_sample=True)`.

        For an overview of generation strategies and code examples, check out the [following
        guide](./generation_strategies).

        </Tip>

        Parameters:
            inputs (`torch.Tensor` of varying shape depending on the modality, *optional*):
                The sequence used as a prompt for the generation or as model inputs to the encoder. If `None` the
                method initializes it with `bos_token_id` and a batch size of 1. For decoder-only models `inputs`
                should be in the format `input_ids`. For encoder-decoder models *inputs* can represent any of
                `input_ids`, `input_values`, `input_features`, or `pixel_values`.
            generation_config (`~generation.GenerationConfig`, *optional*):
                The generation configuration to be used as base parametrization for the generation call. `**kwargs`
                passed to generate matching the attributes of `generation_config` will override them. If
                `generation_config` is not provided, the default will be used, which had the following loading
                priority: 1) from the `generation_config.json` model file, if it exists; 2) from the model
                configuration. Please note that unspecified parameters will inherit [`~generation.GenerationConfig`]'s
                default values, whose documentation should be checked to parameterize generation.
            logits_processor (`LogitsProcessorList`, *optional*):
                Custom logits processors that complement the default logits processors built from arguments and
                generation config. If a logit processor is passed that is already created with the arguments or a
                generation config an error is thrown. This feature is intended for advanced users.
            stopping_criteria (`StoppingCriteriaList`, *optional*):
                Custom stopping criteria that complement the default stopping criteria built from arguments and a
                generation config. If a stopping criteria is passed that is already created with the arguments or a
                generation config an error is thrown. This feature is intended for advanced users.
            synced_gpus (`bool`, *optional*, defaults to `False`):
                Whether to continue running the while loop until max_length (needed to avoid deadlocking with
                `FullyShardedDataParallel` and DeepSpeed ZeRO Stage 3).
            streamer (`BaseStreamer`, *optional*):
                Streamer object that will be used to stream the generated sequences. Generated tokens are passed
                through `streamer.put(token_ids)` and the streamer is responsible for any further processing.
            kwargs (`Dict[str, Any]`, *optional*):
                Ad hoc parametrization of `generate_config` and/or additional model-specific kwargs that will be
                forwarded to the `forward` function of the model. If the model is an encoder-decoder model, encoder
                specific kwargs should not be prefixed and decoder specific kwargs should be prefixed with *decoder_*.

        Return:
            [`~utils.ModelOutput`] or `torch.LongTensor`: A [`~utils.ModelOutput`] (if `return_dict_in_generate=True`
            or when `config.return_dict_in_generate=True`) or a `torch.FloatTensor`.

                If the model is *not* an encoder-decoder model (`model.config.is_encoder_decoder=False`), the possible
                [`~utils.ModelOutput`] types are:

                    - [`~generation.GenerateDecoderOnlyOutput`],
                    - [`~generation.GenerateBeamDecoderOnlyOutput`]

                If the model is an encoder-decoder model (`model.config.is_encoder_decoder=True`), the possible
                [`~utils.ModelOutput`] types are:

                    - [`~generation.GenerateEncoderDecoderOutput`],
                    - [`~generation.GenerateBeamEncoderDecoderOutput`]
        Nr/   r0   r   r†  rü   r1   rB   r”  Ú
min_length©r—  Úhas_default_max_lengthÚhas_default_min_lengthÚmodel_input_nameÚinputs_tensorÚinput_ids_lengthr“  rš  r(   ©r—  Úinput_ids_seq_lengthÚencoder_input_idsÚprefix_allowed_tokens_fnr±  r]   ©r—  r²  )r>   Úexpand_size©r±  r²  r—  r³  r´  ú¤Got incompatible mode for generation, should be one of greedy or sampling. Ensure that beam search is de-activated by setting `num_beams=1` and `num_beam_groups=1`.r;   )*r—  ÚcopyÚdeepcopyÚupdateÚvalidateÚ_validate_model_kwargsr   r   ÚgetÚ_prepare_model_inputsr‰  rG   r#  Ú_prepare_special_tokensr]   rü   r1   Ú&_prepare_attention_mask_for_generationr”  r·  Ú_prepare_generated_lengthr–  Ú_decoder_start_token_tensorÚputÚcpuÚget_generation_modeÚappendr   Ú_get_logits_processorÚ_get_stopping_criteriar   ÚSAMPLEÚGREEDY_SEARCHÚ_expand_inputs_for_generationÚnum_return_sequencesÚ_samplerI   Úreturn_dict_in_generateÚ	sequencesr˜  Ú_pad_token_tensorr­   )rV   r°  r—  r±  r²  r³  r´  rÅ   Úmodel_kwargsÚrequires_attention_maskÚkwargs_has_attention_maskr>   r»  Ú
batch_sizer½  r¹  rº  rš  Úgeneration_moder  Ú
output_idss                        r=   ÚgeneratezMusicgenForCausalLM.generate¼  sü  € ðV Ð$Ø $× 6Ñ 6Ðä ŸM™MÐ*;Ó<ÐØ/Ð(×/Ñ/Ñ9°&Ñ9ˆØ×"Ñ"Ô$Ø×#Ñ# L×$5Ñ$5Ó$7Ô8ð 0@Ð/KÑ+ÔQdÓQfÐØ1BÐ1NÑ-ÔThÓTjÐà"3¸<Ð"GÐØ$0×$4Ñ$4Ð5EÀtÓ$LÐTXÐ$XÐ!ð 59×4NÑ4NØÐ%×2Ñ2°Ló5
Ñ1ˆ	Ð# \ð —_‘_ QÑ'¨4×+=Ñ+=Ñ=ˆ
Ø×$Ñ$Ð%6Ð8QÐZc×ZjÑZjÐ$Ôkð %6×$?Ñ$?ˆ�[Ñ!Ø):×)IÑ)IˆÐ%Ñ&à×ÑÐ,¨dÓ3Ð;Ñ@WØ-1×-XÑ-XØÐ,¨ló.ˆLÐ)Ñ*ð
 %Ÿ?™?¨2Ñ.ÐØ!'§¡¨LÓ!9¸TÐ!AÒ!nÐFW×FbÑFbÐjnÐFnÐØ!'§¡¨LÓ!9¸TÐ!AÒ!nÐFW×FbÑFbÐjnÐFnÐØ ×:Ñ:Ø/Ø#9Ø#9Ø-Ø#Ø-ð ;ó 
Ðð )-×(EÑ(EØØ*×FÑFØ(×3Ñ3ð )Fó )
Ñ%ˆ	Ð%ð ÐØ�L‰L˜Ÿ™›Ô)ð .@ˆÐ)Ñ*ð ,×?Ñ?ÓAˆð ×+Ñ+Ð7Ð<M×<\Ñ<\Ð_`Ò<`Ø×#Ñ#Ô$IÐJ[×JjÑJjÓ$kÔlØ/3ÐÔ,ð  ×5Ñ5Ø/Ø!1Ø'Ø%)Ø-Ø×#Ñ#ð 6ó 
Ðð !×7Ñ7Ø/ÐCTð 8ó 
Ðð œ~×4Ñ4´n×6RÑ6RÐSÑSà&H d×&HÑ&Hð 'Ø#Ø-×BÑBñ'ð ñ'Ñ#ˆI�|ð #�d—l‘lØðà!1Ø"3Ø"3Ø'Ø!ñð ñ‰Gô ðlóð ð
 ×4Ò4Ø ×*Ñ*‰Jà ˆJð ×2Ñ2°:¸|ÐL`Ñ?aÓbˆ
ð   
Ð.?×.QÑ.QÑ QÑR×ZÑZØ˜×*Ñ*¨Bó
ˆ
ð ×4Ò4Ø *ˆGÔØˆNàÐr<   )NNNNNNNNNNNNN)	NNNNNNTNNrR   ©NNNNNN)%r2   r3   r4   r*   rT   r5  r:  ry  r}  r€  rl  r!   rb  r#   r   Ú_CONFIG_FOR_DOCr   r6   r9   r†   r7   r	   r¿   r
   r   r‚   r›  rƒ   r–  r„   r˜  r…   r   r   r   rå  r‡   rˆ   s   @r=   rq  rq  ½  s   ø„ ð
Ð4õ ò/ò0òò'ò%ò"ñ +Ð+LÓMÙ¨?ÈÔYð 15Ø15Ø=AØ=AØ,0Ø7;ØEIØ59Ø-1Ø$(Ø,0Ø/3Ø&*ñU
à˜E×,Ñ,Ñ-ðU
ð ! §¡Ñ.ðU
ð  (¨×(9Ñ(9Ñ:ð	U
ð
 !)¨×)9Ñ)9Ñ :ðU
ð ˜EŸL™LÑ)ðU
ð ' u§|¡|Ñ4ðU
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðU
ð   × 1Ñ 1Ñ2ðU
ð ˜×)Ñ)Ñ*ðU
ð ˜D‘>ðU
ð $ D™>ðU
ð ' t™nðU
ð ˜d‘^ðU
ð  
ˆuÐ7Ð7Ñ	8ò!U
ó Zó NðU
ðt Ø"Ø#ØØ!ØØØØó,
ð^ [_ñI'Ø×)Ñ)ðI'Ø9<ðI'ØJRÐSVÉ-óI'ðV ñó ðð €U‡]�]ƒ_ð *.Ø8<Ø:>Ø<@Ø&*Ø-1ñEà˜Ÿ™Ñ&ðEð $Ð$4Ñ5ðEð #Ð#6Ñ7ð	Eð
 $Ð$8Ñ9ðEð ˜d‘^ðEð ˜>Ñ*òEó ôEr<   rq  zœThe composite MusicGen model with a text encoder, audio encoder and Musicgen decoder, for music generation tasks with one or both of text and audio prompts.c            %       ó<  ‡ — e Zd ZeZdZdZdZdZdZ		 	 	 	 d@de
e   de
e   de
e   de
e   fˆ fd„Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Ze	 	 	 dAde
e   de
e   de
e   defd„«       Z ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBde
ej>                     de
ej@                     de
ejB                     de
ej@                     de
ej>                     de
ej@                     de
e"ejB                        de"e"ejB                        de
ejB                     de
ejB                     d e
ej>                     d!e
e#   d"e
e#   d#e
e#   d$e
e#   de$e"ef   f d%„«       «       Z%	 	 	 	 	 	 	 	 	 	 dCd&„Z&	 	 	 dAd'e'd(ed)e(eejR                  f   d*e
e'   d+e
e'   d,ejT                  de"ej>                  e(eejR                  f   f   fd-„Z+d.ejR                  d(e
e   d/e,de(ee-f   fd0„Z.	 dDd(e
e   fd1„Z/d ejR                  fd2„Z0d3„ Z1d4„ Z2d5„ Z3	 	 	 dAd6e
ejR                     d+e
e'   d)e
e(eejR                  f      dej>                  fd7„Z4	 dEd*e$e'e5e'   f   d+e
e'   de'fd8„Z6 ejn                  «       	 	 	 	 	 	 dFd6e
ejR                     d/e
e,   d9e
e8   d:e
e9   d;e
e#   d<e
d=   fd>„«       Z:dGd?„Z;ˆ xZ<S )HÚ MusicgenForConditionalGenerationÚencoder_decoderr>   Tr‘   Útext_encoderÚaudio_encoderrf  c                 ó4  •— |€|�|�|€t        d«      ‚|€6t        j                  |j                  |j                  |j                  «      }n1t	        || j
                  «      st        d|› d| j
                  › �«      ‚|j                  j                  �g|j                  j                  |j                  j                  k7  r:t        d|j                  j                  › d|j                  j                  › d�«      ‚t        ‰| �-  |«       |€!ddlm} |j                  |j                  «      }|€"dd	lm}  |j                  |j                   «      }|€t"        j%                  |j                  «      }|| _        || _        || _        | j                  j                  j'                  «       | j                  j                  j'                  «       k7  rCt(        j+                  d
| j                  j,                  › d| j                  j                  › �«       | j                   j                  j'                  «       | j                  j                   j'                  «       k7  rCt(        j+                  d| j                   j,                  › d| j                  j                   › �«       | j                  j                  j'                  «       | j                  j                  j'                  «       k7  rCt(        j+                  d| j                  j,                  › d| j                  j                  › �«       | j                  j                  j.                  | j                  j                  _        | j                   j                  j.                  | j                  j                   _        | j                  j                  j.                  | j                  j                  _        | j                  j                  | j                  _        | j                  j                   | j                   _        | j                  j                  | j                  _        | j                  j                  j                  | j                  j                  j                  k7  rw| j                  j                  j                  €Wt1        j2                  | j                  j                  j                  | j                  j                  j                  «      | _        | j                  j7                  «       �t        d| j                  › d�«      ‚t9        t;        j<                  | j                  j>                  «      j@                  jC                  «       «      }d|vrt        d«      ‚| jE                  «        y )NzlEither a configuration has to be provided, or all three of text encoder, audio encoder and MusicGen decoder.zConfig: z has to be of type z“If `cross_attention_hidden_size` is specified in the MusicGen decoder's configuration, it has to be equal to the text encoder's `hidden_size`. Got z6 for `config.decoder.cross_attention_hidden_size` and z' for `config.text_encoder.hidden_size`.r$   )ÚAutoModelForTextEncodingr&   zConfig of the text_encoder: z/ is overwritten by shared text_encoder config: zConfig of the audio_encoder: z0 is overwritten by shared audio_encoder config: zConfig of the decoder: z* is overwritten by shared decoder config: zThe encoder zB should not have a LM Head. Please use a model without and LM Headrù   z¸The selected decoder is not prepared for the encoder hidden states to be passed. Please see the following discussion on GitHub: https://github.com/huggingface/transformers/issues/23350)#rI   r)   Úfrom_sub_models_configr‘   r  r  rf  Úcross_attention_hidden_sizerë  rç   rS   rT   Úauto.modeling_autorî  Úfrom_configr'   rì  rq  Ú_from_configÚto_dictrÑ   ÚwarningrW   ré   ra   r–   Úenc_to_dec_projry  ÚsetÚinspectÚ	signaturer‚   Ú
parametersÚkeysÚtie_weights)	rV   r‘   rë  rì  rf  rî  r'   Údecoder_signaturerW   s	           €r=   rT   z)MusicgenForConditionalGeneration.__init__’  s{  ø€ ð ˆ>˜|Ð3°}Ð7LÐPWÐP_ÜØ~óð ð ˆ>Ü#×:Ñ:¸<×;NÑ;NÐP]×PdÑPdÐfm×ftÑftÓu‰Fä˜f d×&7Ñ&7Ô8Ü  8¨F¨8Ð3FÀt×GXÑGXÐFYÐ!ZÓ[Ð[à�>‰>×5Ñ5ÐAØ�~‰~×9Ñ9¸V×=PÑ=P×=\Ñ=\Ò\Ü ðAØAGÇÁ×AkÑAkÐ@lð mIØIO×I\ÑI\×IhÑIhÐHið j:ð:óð ô 	‰Ñ˜Ô àÐÝEà3×?Ñ?À×@SÑ@SÓTˆLàÐ Ý6à1˜I×1Ñ1°&×2FÑ2FÓGˆMàˆ?Ü)×6Ñ6°v·~±~ÓFˆGà(ˆÔØ*ˆÔØˆŒà×Ñ×#Ñ#×+Ñ+Ó-°·±×1IÑ1I×1QÑ1QÓ1SÒSÜ�N‰NØ.¨t×/@Ñ/@×/JÑ/JÐ.Kð LØ—K‘K×,Ñ,Ð-ð/ôð ×Ñ×$Ñ$×,Ñ,Ó.°$·+±+×2KÑ2K×2SÑ2SÓ2UÒUÜ�N‰NØ/°×0BÑ0B×0LÑ0LÐ/Mð NØ—K‘K×-Ñ-Ð.ð0ôð �<‰<×Ñ×&Ñ&Ó(¨D¯K©K×,?Ñ,?×,GÑ,GÓ,IÒIÜ�N‰NØ)¨$¯,©,×*@Ñ*@Ð)Að BØ—K‘K×'Ñ'Ð(ð*ôð 9=×8IÑ8I×8PÑ8P×8eÑ8eˆ�‰× Ñ Ô5Ø9=×9KÑ9K×9RÑ9R×9gÑ9gˆ�‰×!Ñ!Ô6Ø37·<±<×3FÑ3F×3[Ñ3[ˆ�‰×ÑÔ0Ø#'§;¡;×#;Ñ#;ˆ×ÑÔ Ø$(§K¡K×$=Ñ$=ˆ×ÑÔ!Ø"Ÿk™k×1Ñ1ˆ�‰Ôð ×Ñ×$Ñ$×0Ñ0°D·L±L×4GÑ4G×4SÑ4SÒSØ—‘×#Ñ#×?Ñ?ÐGä#%§9¡9¨T×->Ñ->×-EÑ-E×-QÑ-QÐSW×S_ÑS_×SfÑSf×SrÑSrÓ#sˆDÔ à×Ñ×2Ñ2Ó4Ð@ÜØ˜t×0Ñ0Ð1Ð1sÐtóð ô  ¤× 1Ñ 1°$·,±,×2FÑ2FÓ G× RÑ R× WÑ WÓ YÓZÐØ"Ð*;Ñ;Üðkóð ð 	×ÑÕr<   c                 óþ   — | j                   j                  rg| j                  j                  }| j	                  | j
                  | j                  j                  |   | j                  j                  d«      }|| _        y y )Nrë  )r‘   Útie_encoder_decoderrf  r  Ú_tie_encoder_decoder_weightsrë  Ú_modulesÚ_dynamic_tied_weights_keys)rV   Údecoder_base_model_prefixÚtied_weightss      r=   rü  z,MusicgenForConditionalGeneration.tie_weightsï  sj   € à�;‰;×*Ò*à(,¯©×(FÑ(FÐ%Ø×<Ñ<Ø×!Ñ!Ø—‘×%Ñ%Ð&?Ñ@Ø—‘×.Ñ.Øó	ˆLð /;ˆDÕ+ð +r<   c                 ó   — | j                   S rR   )rì  r4  s    r=   Úget_audio_encoderz2MusicgenForConditionalGeneration.get_audio_encoderÿ  s   € Ø×!Ñ!Ð!r<   c                 ó   — | j                   S rR   )rë  r4  s    r=   Úget_text_encoderz1MusicgenForConditionalGeneration.get_text_encoder  r6  r<   c                 ó"   — | j                  «       S rR   )r  r4  s    r=   Úget_encoderz,MusicgenForConditionalGeneration.get_encoder  s   € à×$Ñ$Ó&Ð&r<   c                 ó   — | j                   S rR   rk  r4  s    r=   rl  z,MusicgenForConditionalGeneration.get_decoder	  rm  r<   c                 ó6   — | j                   j                  «       S rR   )rë  r5  r4  s    r=   r5  z5MusicgenForConditionalGeneration.get_input_embeddings  s   € Ø× Ñ ×5Ñ5Ó7Ð7r<   c                 ó6   — | j                   j                  «       S rR   )rf  ry  r4  s    r=   ry  z6MusicgenForConditionalGeneration.get_output_embeddings  s   € Ø�|‰|×1Ñ1Ó3Ð3r<   c                 ó8   — | j                   j                  |«      S rR   )rf  r}  r{  s     r=   r}  z6MusicgenForConditionalGeneration.set_output_embeddings  s   € Ø�|‰|×1Ñ1°.ÓAÐAr<   Ú*text_encoder_pretrained_model_name_or_pathÚ+audio_encoder_pretrained_model_name_or_pathÚ%decoder_pretrained_model_name_or_pathr¥   c           	      óZ  — |j                  «       D ��ci c]%  \  }}|j                  d«      r|t        d«      d |“Œ' }}}|j                  «       D ��ci c]%  \  }}|j                  d«      r|t        d«      d |“Œ' }	}}|j                  «       D ��ci c]&  \  }}|j                  d«      sŒ|t        d«      d |“Œ( }
}}|j                  «       D ]  }|d|z   = Œ
 |	j                  «       D ]  }|d|z   = Œ
 |
j                  «       D ]  }|d|z   = Œ
 |j	                  dd«      }|€�|€t        d«      ‚d|vret        j                  |fi |¤dd	i¤Ž\  }}|j                  d	u s|j                  d	u r't        j                  d
|› d�«       d|_        d|_	        ||d<   t        j                  |g|¢­i |¤Ž}|	j	                  dd«      }|€�|€t        d«      ‚d|	vret        j                  |fi |	¤dd	i¤Ž\  }}	|j                  d	u s|j                  d	u r't        j                  d
|› d�«       d|_        d|_	        ||	d<   t        j                  |g|¢­i |	¤Ž}|
j	                  dd«      }|€ì|€t        d«      ‚d|
vr‡t        j                  |fi |
¤dd	i¤Ž\  }}
t        |t        «      r|j                  }|j                  du s|j                  du r-t        j                  d
|› d|› d|› d�«       d	|_        d	|_	        ||
d<   |
d   j                  du s|
d   j                  du rt        j!                  d|› d|› d�«       t#        j                  |fi |
¤Ž}t        j$                  |j&                  |j&                  |j&                  fi |¤Ž} | ||||¬«      S c c}}w c c}}w c c}}w )a  
        Instantiate a text encoder, an audio encoder, and a MusicGen decoder from one, two or three base classes of the
        library from pretrained model checkpoints.


        The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train
        the model, you need to first set it back in training mode with `model.train()`.

        Params:
            text_encoder_pretrained_model_name_or_path (`str`, *optional*):
                Information necessary to initiate the text encoder. Can be either:

                    - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    - A path to a *directory* containing model weights saved using
                      [`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.

            audio_encoder_pretrained_model_name_or_path (`str`, *optional*):
                Information necessary to initiate the audio encoder. Can be either:

                    - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    - A path to a *directory* containing model weights saved using
                      [`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.

            decoder_pretrained_model_name_or_path (`str`, *optional*, defaults to `None`):
                Information necessary to initiate the decoder. Can be either:

                    - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    - A path to a *directory* containing model weights saved using
                      [`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.

            model_args (remaining positional arguments, *optional*):
                All remaining positional arguments will be passed to the underlying model's `__init__` method.

            kwargs (remaining dictionary of keyword arguments, *optional*):
                Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
                `output_attentions=True`).

                - To update the text encoder configuration, use the prefix *text_encoder_* for each configuration
                  parameter.
                - To update the audio encoder configuration, use the prefix *audio_encoder_* for each configuration
                  parameter.
                - To update the decoder configuration, use the prefix *decoder_* for each configuration parameter.
                - To update the parent model configuration, do not use a prefix for each configuration parameter.

                Behaves differently depending on whether a `config` is provided or automatically loaded.

        Example:

        ```python
        >>> from transformers import MusicgenForConditionalGeneration

        >>> # initialize a musicgen model from a t5 text encoder, encodec audio encoder, and musicgen decoder
        >>> model = MusicgenForConditionalGeneration.from_sub_models_pretrained(
        ...     text_encoder_pretrained_model_name_or_path="google-t5/t5-base",
        ...     audio_encoder_pretrained_model_name_or_path="facebook/encodec_24khz",
        ...     decoder_pretrained_model_name_or_path="facebook/musicgen-small",
        ... )
        >>> # saving model after fine-tuning
        >>> model.save_pretrained("./musicgen-ft")
        >>> # load fine-tuned model
        >>> model = MusicgenForConditionalGeneration.from_pretrained("./musicgen-ft")
        ```Útext_encoder_NÚaudio_encoder_Údecoder_r  zxIf `text_encoder_model` is not defined as an argument, a `text_encoder_pretrained_model_name_or_path` has to be defined.r‘   Úreturn_unused_kwargsTzInitializing z\ as a text_encoder model from a decoder model. Cross-attention and casual mask are disabled.Fz{If `audio_encoder_model` is not defined as an argument, an `audio_encoder_pretrained_model_name_or_path` has to be defined.z^ as an audio_encoder model from a decoder model. Cross-attention and casual mask are disabled.znIf `decoder_model` is not defined as an argument, a `decoder_pretrained_model_name_or_path` has to be defined.z9 as a decoder model. Cross attention layers are added to z and randomly initialized if z2's architecture allows for cross attention layers.zDecoder model z9 is not initialized as a decoder. In order to initialize zî as a decoder, make sure that the attributes `is_decoder` and `add_cross_attention` of `decoder_config` passed to `.from_sub_models_pretrained(...)` are set to `True` or do not pass a `decoder_config` to `.from_sub_models_pretrained(...)`)rë  rì  rf  r‘   )ÚitemsÚ
startswithrM  rû  ÚpoprI   r%   Úfrom_pretrainedrŽ   Úadd_cross_attentionrÑ   Úinfor'   r  r)   rf  rõ  rq  rï  r‘   )Úclsr  r  r  Ú
model_argsrÅ   Úargumentr9  Úkwargs_text_encoderÚkwargs_audio_encoderÚkwargs_decoderÚkeyrë  Úencoder_configrì  rf  Údecoder_configr‘   s                     r=   Úfrom_sub_models_pretrainedz;MusicgenForConditionalGeneration.from_sub_models_pretrained  sÊ  € ðT $*§<¡<£>÷
á�˜%Ø×"Ñ" ?Ô3ð ”S˜Ó)Ð+Ð,¨eÑ3ð
Ðñ 
ð $*§<¡<£>÷ 
á�˜%Ø×"Ñ"Ð#3Ô4ð ”SÐ)Ó*Ð,Ð-¨uÑ4ð 
Ðñ  
ð GMÇlÁlÃn÷
Ù3B°8¸UÐX`×XkÑXkÐlvÕXwˆH”S˜“_Ð&Ð'¨Ñ.ð
ˆñ 
ð
 '×+Ñ+Ó-ò 	.ˆCØ�¨Ñ,Ñ-ð	.à'×,Ñ,Ó.ò 	/ˆCØÐ'¨#Ñ-Ñ.ð	/à!×&Ñ&Ó(ò 	)ˆCØ�z CÑ'Ñ(ð	)ð +×.Ñ.¨w¸Ó=ˆØÐØ9ÐAÜ ð%óð ð
 Ð2Ñ2Ü6@×6PÑ6PØ>ñ7ØBUñ7Ølpò7Ñ3�Ð 3ð "×,Ñ,°Ñ4¸×8ZÑ8ZÐ^bÑ8bÜ—K‘KØ'Ð(RÐ'Sð T^ð ^ôð 16�NÔ-Ø9>�NÔ6à0>Ð# HÑ-ä$×4Ñ4Ø:ðØ=GòØK^ñˆLð -×0Ñ0°¸$Ó?ˆØÐ Ø:ÐBÜ ð%óð ð
 Ð3Ñ3Ü7A×7QÑ7QØ?ñ8ØCWñ8Ønrò8Ñ4�Ð 4ð "×,Ñ,°Ñ4¸×8ZÑ8ZÐ^bÑ8bÜ—K‘KØ'Ð(SÐ'Tð U^ð ^ôð 16�NÔ-Ø9>�NÔ6à1?Ð$ XÑ.ä%×5Ñ5Ø;ðØ>HòØL`ñˆMð !×$Ñ$ W¨dÓ3ˆØˆ?Ø4Ð<Ü ð%óð ð
 ˜~Ñ-Ü1;×1KÑ1KØ9ñ2Ø=Kñ2Øbfò2Ñ.� ô ˜n¬nÔ=Ø%3×%;Ñ%;�Nà!×,Ñ,°Ñ5¸×9[Ñ9[Ð_dÑ9dÜ—K‘KØ'Ð(MÐ'Nð O0Ø0UÐ/Vð WØAÐBÐBtðvôð
 15�NÔ-Ø9=�NÔ6à+9�˜xÑ(à˜hÑ'×2Ñ2°eÑ;¸~ÈhÑ?W×?kÑ?kÐotÑ?tÜ—‘Ø$Ð%JÐ$Kð L.Ø.SÐ-Tð UMðMôô *×9Ñ9Ð:_ÑrÐcqÑrˆGô  ×6Ñ6Ø×Ñ ×!5Ñ!5°w·~±~ñ
ØIOñ
ˆñ  ¸MÐSZÐciÔjÐjùów
ùó 
ùó
s   ”*NÁ*N!ÂN'Â.N'r‚  r0   Úinput_valuesÚpadding_maskÚdecoder_input_idsÚdecoder_attention_maskr/   r=  r>  Údecoder_inputs_embedsr„  rü   r¤   r?  r@  c                 ó¶  — |�|n| j                   j                  }|j                  «       D ��ci c]%  \  }}|j                  d«      r|t	        d«         |“Œ' }}}|j                  «       D ��ci c]%  \  }}|j                  d«      r|t	        d«         |“Œ' }}}|j                  «       D ��ci c]&  \  }}|j                  d«      sŒ|t	        d«      d |“Œ( }}}|€ | j
                  d|||	|||dœ|¤Ž}nt        |t        «      rt        |Ž }|d   }| j
                  j                   j                  | j                  j                   j                  k7  r1| j                  j                   j                  €| j                  |«      }|�||d   z  }|�N|€L|
€Jt        || j                   j                  j                  | j                   j                  j                  «      }nÕ|€Ó|
€Ñ | j                   d||dœ|¤Ž}|j"                  }|j$                  \  }}}}|d	k7  rt'        d
|› d�«      ‚| j                   j                  j(                  dk(  r<|j$                  d   | j                  j*                  dz  k(  r|j-                  dd¬«      }|d   j/                  || j                  j*                  z  |«      } | j                  d|||||
||||||dœ|¤Ž}|s||z   S t1        |j2                  |j4                  |j6                  |j8                  |j:                  |j<                  |j>                  |j8                  |j:                  ¬«	      S c c}}w c c}}w c c}}w )aÿ  
        Returns:

        Examples:
        ```python
        >>> from transformers import AutoProcessor, MusicgenForConditionalGeneration
        >>> import torch

        >>> processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
        >>> model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")

        >>> inputs = processor(
        ...     text=["80s pop track with bassy drums and synth", "90s rock song with loud guitars and heavy drums"],
        ...     padding=True,
        ...     return_tensors="pt",
        ... )

        >>> pad_token_id = model.generation_config.pad_token_id
        >>> decoder_input_ids = (
        ...     torch.ones((inputs.input_ids.shape[0] * model.decoder.num_codebooks, 1), dtype=torch.long)
        ...     * pad_token_id
        ... )

        >>> logits = model(**inputs, decoder_input_ids=decoder_input_ids).logits
        >>> logits.shape  # (bsz * num_codebooks, tgt_len, vocab_size)
        torch.Size([8, 1, 2048])
        ```Nr  r  r  )r>   r0   r>  r¤   r?  r@  r   ).N)r'  r(  r(   ú0Expected 1 frame in the audio code outputs, got úY frames. Ensure chunking is disabled by setting `chunk_length=None` in the audio encoder.r$   rh   ©r   .)r>   r0   rù   rú   r>  r¤   r?  rü   r=  r@  r„  )	r‡  rˆ  r=  Údecoder_hidden_statesÚdecoder_attentionsrI  Úencoder_last_hidden_staterù   Úencoder_attentionsr;   ) r‘   rJ  r  r  rM  rë  r  rR  r   rç   rf  rð  rö  rL   r?   r@   rì  Úaudio_codesrG   rI   r   r#  r£  r­   r   r‡  rˆ  r=  r    rH  rI  rG  )rV   r>   r0   r'  r(  r)  r*  r/   r=  r>  r+  r„  rü   r¤   r?  r@  rÅ   r  r9  r   r!  r"  rù   Úaudio_encoder_outputsr4  Úframesr~   r   r€   ro  s                                 r=   r‚   z(MusicgenForConditionalGeneration.forwardÚ  s¸  € ð` &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð $*§<¡<£>÷
á�˜%Ø×"Ñ" ?Ô3ð ”S˜Ó)Ñ*¨EÑ1ð
Ðñ 
ð $*§<¡<£>÷ 
á�˜%Ø×"Ñ"Ð#3Ô4ð ”SÐ)Ó*Ñ+¨UÑ2ð 
Ðñ  
ð GMÇlÁlÃn÷
Ù3B°8¸UÐX`×XkÑXkÐlvÕXwˆH”S˜“_Ð&Ð'¨Ñ.ð
ˆñ 
ð Ð"Ø/˜d×/Ñ/ð Ø#Ø-Ø+Ø"3Ø%9Ø'ñð &ñ‰Oô ˜¬Ô/Ü-¨Ð?ˆOà /°Ñ 2Ðð ×Ñ×$Ñ$×0Ñ0°D·L±L×4GÑ4G×4SÑ4SÒSØ—‘×#Ñ#×?Ñ?ÐGà$(×$8Ñ$8Ð9NÓ$OÐ!àÐ%Ø$9¸NÈ9Ñ<UÑ$UÐ!àÐÐ%6Ð%>ÐCXÐC`Ü 2Ø˜Ÿ™×+Ñ+×8Ñ8¸$¿+¹+×:MÑ:M×:dÑ:dó!Ñð Ð&Ð+@Ð+HØ$6 D×$6Ñ$6ð %Ø)Ø)ñ%ð 'ñ%Ð!ð
 0×;Ñ;ˆKØ.9×.?Ñ.?Ñ+ˆF�C˜ GØ˜Š{Ü ØFÀvÀhð OTð Tóð ð
 �{‰{×"Ñ"×1Ñ1°QÒ6¸;×;LÑ;LÈQÑ;OÐSW×S_ÑS_×SmÑSmÐqrÑSrÒ;rà)×;Ñ;¸AÀ1Ð;ÓE�à +¨FÑ 3× ;Ñ ;¸CÀ$Ç,Á,×B\ÑB\Ñ<\Ð^eÓ fÐð '˜$Ÿ,™,ð 
Ø'Ø1Ø"7Ø#1Ø/Ø/Ø!5ØØ+Ø#Øñ
ð ñ
ˆñ Ø" _Ñ4Ð4äØ ×%Ñ%Ø"×)Ñ)Ø+×;Ñ;Ø"1×"?Ñ"?Ø.×9Ñ9Ø,×=Ñ=Ø&5×&GÑ&GØ"1×"?Ñ"?Ø.×9Ñ9ô

ð 
	
ùók
ùó 
ùó
s   ®*M	Á.*MÂ.MÃMc                 óÒ  — |
€I| j                   j                  || j                  j                  | j                  j                  ¬«      \  }}
| j                   j                  ||
«      }|�)|dkD  r$|j                  d«      }|�|j                  d«      }|�G|d   d   j                  d   }|j                  d   |kD  r|}n|j                  d   dz
  }|d d …|d …f   }d |	||||||||dœ
S )N)r”  r(   r•  r   r$   )
r>   r/   r=  r)  r0   r*  r;  Údecoder_head_maskr<  rü   )rf  r–  r—  r?   r”  r˜  r™  rG   )rV   r)  r=  r0   r;  r*  r8  r<  rü   r/   Údecoder_delay_pattern_maskr1   rÅ   Úpast_lengthÚremove_prefix_lengths                  r=   r›  z>MusicgenForConditionalGeneration.prepare_inputs_for_generationm  s/  € ð  &Ð-Ø<@¿L¹L×<aÑ<aØ!Ø×&Ñ&×3Ñ3Ø×1Ñ1×<Ñ<ð =bó =Ñ9ÐÐ9ð !ŸL™L×AÑAÐBSÐUoÓpÐàÐ%¨.¸1Ò*<ð !2× 8Ñ 8¸Ó @ÐØ%Ð1Ø)?×)FÑ)FÀvÓ)NÐ&àÐ&Ø)¨!Ñ,¨QÑ/×5Ñ5°aÑ8ˆKð !×&Ñ& qÑ)¨KÒ7Ø'2Ñ$ð (9×'>Ñ'>¸qÑ'AÀAÑ'EÐ$à 1²!Ð5IÑ5JÐ2JÑ KÐð Ø.Ø.Ø!2Ø,Ø&<Ø"Ø!2Ø$8Ø"ñ
ð 	
r<   râ  r»  rß  r@   r‰  r]   c                 óH  — |�d|v r|j                  d«      }nd|v r|dk7  r|j                  d«      }nd}| j                  ||«      }|€| j                  }t        j                  || j
                  j                  z  dft        j                  |¬«      |z  }|€|}||fS |d   |k7  j                  «       j                  «       r\t        j                  ||gd¬«      }d	|v r?|d	   }	t        j                  t        j                  |	«      dd…dd…f   |	fd¬«      }	|	|d	<   ||fS )
zGPrepares `decoder_input_ids` for generation with encoder-decoder modelsNr)  r>   r(   r[   rC   rB   rh   r*  )r  Ú_get_decoder_start_token_idr]   r6   rž  rf  r#  rŸ  ÚallÚitemrp   Ú	ones_like)
rV   râ  r»  rß  r@   r‰  r]   r)  Údecoder_input_ids_startr*  s
             r=   Ú)_prepare_decoder_input_ids_for_generationzJMusicgenForConditionalGeneration._prepare_decoder_input_ids_for_generation§  s[  € ð Ð#Ð(;¸|Ñ(KØ ,× 0Ñ 0Ð1DÓ EÑØ˜LÑ(Ð-=ÀÒ-LØ ,× 0Ñ 0°Ó =Ñà $Ðð "&×!AÑ!AÐBXÐZfÓ!gÐØˆ>Ø—[‘[ˆFä�J‰J˜
 T§\¡\×%?Ñ%?Ñ?ÀÐCÌ5Ï:É:Ð^dÔeØ$ñ%ð 	 ð Ð$Ø 7Ðð ! ,Ð.Ð.ð   Ñ'Ð+AÑA×FÑFÓH×MÑMÔOÜ %§	¡	Ð+BÐDUÐ*VÐ\^Ô _ÐØ'¨<Ñ7Ø)5Ð6NÑ)OÐ&Ü).¯©Ü—_‘_Ð%;Ó<ºQÀÀÀ¸UÑCÐE[Ð\Øô*Ð&ð :P�Ð5Ñ6à  ,Ð.Ð.r<   r¼  r—  c                 ót  ‡— | j                  «       }t        |d«      rd|j                  _        g d¢}|j	                  «       D �‡�ci c]  \  Š}t        ˆfd„|D «       «      s‰|“Œ }	}}t        t        j                  |j                  «      j                  «      }
d|
v xs d|
v }|s(|	j	                  «       D ��ci c]  \  }}||
v sŒ||“Œ }	}}|j                  |	d<   |j                  |	d<   |j                  }|�|n| j                  j                  }d|	d	<   ||	|<    |di |	¤Žj                   }|�j|d
kD  ret#        j$                  |t#        j&                  |«      gd¬«      }d|v r5t#        j$                  |d   t#        j&                  |d   «      gd¬«      |d<   t)        |¬«      |d<   |S c c}}w c c}}w )NÚ_hf_hookT©r  Ú
cross_attnrü   c              3   ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wrR   ©r  ©rC  rª   r  s     €r=   rE  z_MusicgenForConditionalGeneration._prepare_text_encoder_kwargs_for_generation.<locals>.<genexpr>é  ó   øè ø€ ÒI°!�x×*Ñ*¨1×-ÑIùó   ƒrÅ   rß  r¤   r?  r@  r(   r   rh   r0   ©rG  r/   r;   )r  r_   rD  Úio_same_devicer  rß   r÷  rø  rù  r‚   rú  r¤   r?  r1   rë  Úmain_input_namerG  r6   ÚconcatenateÚ
zeros_liker   )rV   r¼  rß  r»  r—  ÚencoderÚirrelevant_prefixr  r9  Úencoder_kwargsÚencoder_signatureÚencoder_accepts_wildcardr1   rG  s          `      r=   Ú+_prepare_text_encoder_kwargs_for_generationzLMusicgenForConditionalGeneration._prepare_text_encoder_kwargs_for_generationÖ  sù  ø€ ð ×'Ñ'Ó)ˆô �7˜JÔ'Ø.2ˆG×ÑÔ+ò DÐð $0×#5Ñ#5Ó#7÷
ð 
á�˜%ÜÓIÐ7HÔIÔIð �e‰Oð
ˆñ 
ô
  ¤× 1Ñ 1°'·/±/Ó B× MÑ MÓNÐØ#+Ð/@Ð#@Ò#gÀNÐVgÐDgÐ Ù'à7E×7KÑ7KÓ7M÷Ù$3 H¨eÐQYÐ]nÒQn�˜%‘ðˆNñ ð /@×.QÑ.QˆÐ*Ñ+Ø1B×1WÑ1WˆÐ-Ñ.Ø*×9Ñ9ˆð 0@Ð/KÑ+ÐQU×QbÑQb×QrÑQrÐØ(,ˆ�}Ñ%Ø+8ˆÐ'Ñ(Ù#Ñ5 nÑ5×GÑGÐð Ð%¨.¸1Ò*<Ü %× 1Ñ 1Ð3DÄe×FVÑFVÐWhÓFiÐ2jÐpqÔ rÐØ <Ñ/Ü16×1BÑ1BØ!Ð"2Ñ3´U×5EÑ5EÀlÐScÑFdÓ5eÐfÐlmô2�Ð-Ñ.ô +:ÐL]Ô*^ˆÐ&Ñ'àÐùó?
ùós   Á!F.Â<F4Ã	F4c                 ó”  ‡— | j                  «       }t        |d«      rd|j                  _        g d¢}|j	                  «       D �‡�ci c]  \  Š}t        ˆfd„|D «       «      s‰|“Œ }}}t        t        j                  |j                  «      j                  «      }	d|	v xs d|	v }
|
s(|j	                  «       D ��ci c]  \  }}||	v sŒ||“Œ }}}|�|n| j                  j                  }d|d<   | j                  j                  j                  dk(  rB|||<    |j                   di |¤Ž}|j"                  }|j$                  }|j&                  \  }}}}�n|j&                  d   d	k7  rt)        d
|j&                  d   › d�«      ‚|d d …d d…d d …f   ||<    |j                   di |¤Ž}|j"                  }|j$                  }|d d …dd …d d …f   ||<    |j                   di |¤Ž}|j"                  }|j$                  }|j&                  \  }}}}|j+                  ||d	|z  |f«      }||d d …d d …d d d	…d d …f<   ||d d …d d …dd d	…d d …f<   |d gk7  s|d gk7  rt-        j.                  ||gd¬«      }nd g|z  }|dk7  rt)        d|› d�«      ‚|d   j1                  || j                  j2                  z  |«      }||d<   ||d<   |S c c}}w c c}}w )NrD  TrE  c              3   ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wrR   rH  rI  s     €r=   rE  z`MusicgenForConditionalGeneration._prepare_audio_encoder_kwargs_for_generation.<locals>.<genexpr>	  rJ  rK  rÅ   rß  r@  r(   r$   z3Expected stereo audio (2-channels) but example has z	 channel.rh   r-  r.  r/  r)  Úaudio_scalesr;   )r  r_   rD  rM  r  rß   r÷  rø  rù  r‚   rú  rì  rN  rf  r‘   r   Úencoder4  rY  rG   rI   Únew_onesr6   rŠ  r­   r#  )rV   r'  rß  r»  rQ  rR  r  r9  rS  rT  rU  r5  r4  rY  r6  r~   r   r€   Úaudio_encoder_outputs_leftÚaudio_codes_leftÚaudio_scales_leftÚaudio_encoder_outputs_rightÚaudio_codes_rightÚaudio_scales_rightr)  s         `                  r=   Ú,_prepare_audio_encoder_kwargs_for_generationzMMusicgenForConditionalGeneration._prepare_audio_encoder_kwargs_for_generation	  sJ  ø€ ð ×(Ñ(Ó*ˆô �7˜JÔ'Ø.2ˆG×ÑÔ+ò DÐð $0×#5Ñ#5Ó#7÷
ð 
á�˜%ÜÓIÐ7HÔIÔIð �e‰Oð
ˆñ 
ô
  ¤× 1Ñ 1°'·/±/Ó B× MÑ MÓNÐØ#+Ð/@Ð#@Ò#gÀNÐVgÐDgÐ Ù'à7E×7KÑ7KÓ7M÷Ù$3 H¨eÐQYÐ]nÒQn�˜%‘ðˆNñ ð
 0@Ð/KÑ+ÐQU×QcÑQc×QsÑQsÐØ(,ˆ�}Ñ%à�<‰<×Ñ×-Ñ-°Ò2Ø/;ˆNÐ+Ñ,Ø$2 G§N¡NÑ$D°^Ñ$DÐ!Ø/×;Ñ;ˆKØ0×=Ñ=ˆLà.9×.?Ñ.?Ñ+ˆF�C˜¢Gð ×!Ñ! !Ñ$¨Ò)Ü ØIÈ,×J\ÑJ\Ð]^ÑJ_ÐI`Ð`iÐjóð ð 0<ºA¸rÀ¸rÂ1¸HÑ/EˆNÐ+Ñ,Ø)7¨¯©Ñ)I¸.Ñ)IÐ&Ø9×EÑEÐØ :× GÑ GÐà/;ºA¸q¹rÂ1¸HÑ/EˆNÐ+Ñ,Ø*8¨'¯.©.Ñ*J¸>Ñ*JÐ'Ø ;× GÑ GÐØ!<×!IÑ!IÐà.>×.DÑ.DÑ+ˆF�C˜ Gà*×3Ñ3°V¸SÀ!ÀiÁ-ÐQXÐ4YÓZˆKà(8ˆKšš1™c ˜c¢1˜Ñ%Ø):ˆKšš1˜a˜d ˜d¢A˜Ñ&à  T FÒ*Ð.@ÀTÀFÒ.JÜ$Ÿ{™{Ð,=Ð?QÐ+RÐXYÔZ‘à $˜v¨™|�à�QŠ;ÜØBÀ6À(ð KPð Póð ð
 (¨Ñ/×7Ñ7¸¸d¿l¹l×>XÑ>XÑ8XÐZaÓbÐà,=ˆÐ(Ñ)Ø'3ˆ�^Ñ$ØÐùó}
ùós   Á!J>Â<KÃ	Kc                 ó”   — t        || j                  j                  j                  | j                  j                  j                  «      S rR   )rL   r‘   rf  r?   r‰  )rV   r„  s     r=   Ú%prepare_decoder_input_ids_from_labelszFMusicgenForConditionalGeneration.prepare_decoder_input_ids_from_labelsS	  s1   € Ü! &¨$¯+©+×*=Ñ*=×*JÑ*JÈDÏKÉK×L_ÑL_×LlÑLlÓmÐmr<   c                 ó   — t        d«      ‚)NzèResizing the embedding layers via the EncoderDecoderModel directly is not supported. Please use the respective methods of the wrapped objects (model.encoder.resize_token_embeddings(...) or model.decoder.resize_token_embeddings(...)))ÚNotImplementedError)rV   rÄ   rÅ   s      r=   Úresize_token_embeddingsz8MusicgenForConditionalGeneration.resize_token_embeddingsV	  s   € Ü!ð;ó
ð 	
r<   c                 ór   — | j                   j                  «       D ]	  }d|_        Œ d| j                   _        y)z3
        Freeze the audio encoder weights.
        FN)rì  rú  rc   Ú_requires_grad©rV   Úparams     r=   Úfreeze_audio_encoderz5MusicgenForConditionalGeneration.freeze_audio_encoder]	  s8   € ð ×'Ñ'×2Ñ2Ó4ò 	(ˆEØ"'ˆEÕð	(à,1ˆ×ÑÕ)r<   c                 ór   — | j                   j                  «       D ]	  }d|_        Œ d| j                   _        y)z2
        Freeze the text encoder weights.
        FN)rë  rú  rc   ri  rj  s     r=   Úfreeze_text_encoderz4MusicgenForConditionalGeneration.freeze_text_encodere	  s8   € ð ×&Ñ&×1Ñ1Ó3ò 	(ˆEØ"'ˆEÕð	(à+0ˆ×ÑÕ(r<   r°  c                 óÊ  — |�|S |j                  d«      }|�I|d   j                  «       dd }t        j                  |t        j                  | j
                  ¬«      dz  S |€t        d«      ‚d}|j                  «       D ]-  }t        |t        j                  «      sŒ|j                  d   } n t        j                  |dft        j                  | j
                  ¬«      |z  S )	z3Initializes input ids for generation, if necessary.Nr/   r   rB   r[   rD   zB`bos_token_id` has to be defined when no `input_ids` are provided.r(   )rË  rz   r6   rž  rŸ  r]   rI   Úvaluesr  r†   rG   )rV   r°  r‰  rß  r/   rG   râ  r9  s           r=   Ú*_maybe_initialize_input_ids_for_generationzKMusicgenForConditionalGeneration._maybe_initialize_input_ids_for_generationm	  sÖ   € ð ÐØˆMà&×*Ñ*Ð+<Ó=ˆØÐ&à# AÑ&×+Ñ+Ó-¨c¨rÐ2ˆEÜ—:‘:˜e¬5¯:©:¸d¿k¹kÔJÈTÑQÐQàÐÜÐaÓbÐbð ˆ
Ø!×(Ñ(Ó*ò 	ˆEÜ˜%¤§¡Õ.Ø"Ÿ[™[¨™^�
Ùð	ô �z‰z˜: q˜/´·±ÀDÇKÁKÔPÐS_Ñ_Ð_r<   c                 ó�   — |�|n| j                   j                  }|�|n| j                   j                  }|�|S |�|S t        d«      ‚)Nz\`decoder_start_token_id` or `bos_token_id` has to be defined for encoder-decoder generation.)r—  r@   r‰  rI   )rV   r@   r‰  s      r=   r=  z<MusicgenForConditionalGeneration._get_decoder_start_token_id‰	  se   € ð
 &Ð1ñ #à×'Ñ'×>Ñ>ð 	ð
 (4Ð'?‘|ÀT×E[ÑE[×EhÑEhˆà!Ð-Ø)Ð)ØÐ%ØÐÜØjó
ð 	
r<   r±  r²  r³  r´  r,   c           	      óB
  — |€| j                   }t        j                  |«      } |j                  di |¤Ž}|j	                  «        | j                  |j                  «       «       |j                  d«      �)t        |d   «      t        u rt        |d   d   ¬«      |d<   |�|n	t        «       }|�|n	t        «       }d|v}	|j                  dd«      du}
| j                  ||j                  |«      \  }}}|j                  d   }| j                  ||
|j                   ¬«       |j"                  |d<   |j$                  |d<   |j                  dd«      €|	r| j'                  |||«      |d<   d|vr| j)                  ||||«      }d	|vrd
|v r| j+                  |d
   |«      }| j-                  ||||j.                  |j0                  |j                   ¬«      \  }}|j                  d   }|j                  d«      du xr |j2                  du}|j                  d«      du xr |j4                  du}| j7                  ||||||¬«      }| j8                  j;                  ||j.                  |j2                  ¬«      \  }}||d<   |�|j=                  |j?                  «       «       |jA                  «       }|j$                  �:|j$                  dkD  r+|jC                  tE        |j$                  «      «       d|_        | jG                  |||d||j                   ¬«      }| jI                  ||¬«      }|tJ        jL                  tJ        jN                  fv rQ | jP                  d||jR                  | jT                  jV                  dœ|¤Ž\  }} | jX                  |f|||||dœ|¤Ž}nt[        d«      ‚|j\                  r|j^                  }n|}| j8                  ja                  ||d   «      }|||jb                  k7     je                  || j8                  jf                  d«      }|d   }|j                  d«      }|€dg|z  }| j8                  jT                  jh                  dk(  r(| jj                  jm                  ||¬«      jn                  }n‹| jj                  jm                  |dd…dd…ddd…dd…f   |¬«      }|jn                  }| jj                  jm                  |dd…dd…ddd…dd…f   |¬«      }|jn                  }tq        jr                  ||gd¬«      }|j\                  r	||_/        |S |S )r¶  Nr/   r   rL  r0   r†  rü   r1   r)  r'  )râ  r»  rß  r@   r‰  r]   rB   r”  r·  r¸  r“  r9  r(   r¾  rÂ  )r>   rÃ  Úis_encoder_decoderrÄ  rÅ  )N.rY  )rY  r$   rh   r;   ):r—  rÆ  rÇ  rÈ  rÉ  rÊ  rË  ÚtyperR  r   r   r   rÌ  r‰  rG   rÍ  r]   rü   r1   rÎ  rV  rb  rB  rÐ  Ú_bos_token_tensorr”  r·  rÏ  rf  r–  rÑ  rÒ  rÓ  rÔ  r   rÕ  rÖ  r   r×  rØ  rÙ  rÚ  r‘   rt  rÛ  rI   rÜ  rÝ  r˜  rÞ  r­   r#  r   rì  ÚdecodeÚaudio_valuesr6   rp   )rV   r°  r—  r±  r²  r³  r´  rÅ   rß  rà  rá  r¼  r»  râ  r>   r½  r¹  rº  r9  rã  r  rä  rY  Úoutput_valuesÚcodec_outputs_leftÚoutput_values_leftÚcodec_outputs_rightÚoutput_values_rights                               r=   rå  z)MusicgenForConditionalGeneration.generate›	  sâ  € ðV Ð$Ø $× 6Ñ 6Ðä ŸM™MÐ*;Ó<ÐØ/Ð(×/Ñ/Ñ9°&Ñ9ˆØ×"Ñ"Ô$Ø×#Ñ# L×$5Ñ$5Ó$7Ô8à×ÑÐ-Ó.Ð:¼tÀLÐQbÑDcÓ?dÔhmÑ?mä.=ÐP\Ð]nÑPoÐpqÑPrÔ.sˆLÐ*Ñ+ð 0@Ð/KÑ+ÔQdÓQfÐØ1BÐ1NÑ-ÔThÓTjÐà"3¸<Ð"GÐØ$0×$4Ñ$4Ð5EÀtÓ$LÐTXÐ$XÐ!ð 9=×8RÑ8RØÐ%×2Ñ2°Ló9
Ñ5ˆÐ'¨ð #×(Ñ(¨Ñ+ˆ
Ø×$Ñ$Ð%6Ð8QÐZg×ZnÑZnÐ$Ôoð %6×$?Ñ$?ˆ�[Ñ!Ø):×)IÑ)IˆÐ%Ñ&à×ÑÐ,¨dÓ3Ð;Ñ@WØ-1×-XÑ-XØÐ0°,ó.ˆLÐ)Ñ*ð  LÑ0à×KÑKØ˜|Ð-=Ð?PóˆLð  lÑ2°~ÈÑ7UØ×LÑLØ˜^Ñ,ØóˆLð #'×"PÑ"PØ!Ø-Ø%Ø#4×#PÑ#PØ*×<Ñ<Ø ×'Ñ'ð #Qó #
Ñˆ	�<ð %Ÿ?™?¨2Ñ.ÐØ!'§¡¨LÓ!9¸TÐ!AÒ!nÐFW×FbÑFbÐjnÐFnÐØ!'§¡¨LÓ!9¸TÐ!AÒ!nÐFW×FbÑFbÐjnÐFnÐØ ×:Ñ:Ø/Ø#9Ø#9Ø-Ø'Ø-ð ;ó 
Ðð 15·±×0UÑ0UØØ*×FÑFØ(×3Ñ3ð 1Vó 1
Ñ-ˆ	Ð-ð 6PˆÐ1Ñ2ð ÐØ�L‰L˜Ÿ™›Ô)ð ,×?Ñ?ÓAˆð ×+Ñ+Ð7Ð<M×<\Ñ<\Ð_`Ò<`Ø×#Ñ#Ô$IÐJ[×JjÑJjÓ$kÔlØ/3ÐÔ,ð  ×5Ñ5Ø/Ø!1Ø+Ø%)Ø-Ø×#Ñ#ð 6ó 
Ðð !×7Ñ7Ø/ÐCTð 8ó 
Ðð œ~×4Ñ4´n×6RÑ6RÐSÑSà&H d×&HÑ&Hð 'Ø#Ø-×BÑBØ#'§;¡;×#AÑ#Añ'ð ñ	'Ñ#ˆI�|ð #�d—l‘lØðà!1Ø"3Ø"3Ø'Ø!ñð ñ‰Gô ðlóð ð
 ×4Ò4Ø ×*Ñ*‰Jà ˆJð —\‘\×:Ñ:¸:À|ÐTpÑGqÓrˆ
ð   
Ð.?×.QÑ.QÑ QÑR×ZÑZØ˜Ÿ™×2Ñ2°Bó
ˆ
ð
   	Ñ*ˆ
à#×'Ñ'¨Ó7ˆØÐØ ˜6 JÑ.ˆLà�<‰<×Ñ×-Ñ-°Ò2Ø ×.Ñ.×5Ñ5ØØ)ð 6ó ÷ ‰lñ ð
 "&×!3Ñ!3×!:Ñ!:¸:ÂaÊÉCÈaÈCÒQRÀlÑ;SÐbnÐ!:Ó!oÐØ!3×!@Ñ!@Ðà"&×"4Ñ"4×";Ñ";¸JÂqÊ!ÈQÈTÐPQÈTÒSTÀ}Ñ<UÐdpÐ";Ó"qÐØ"5×"BÑ"BÐä!ŸI™IÐ'9Ð;NÐ&OÐUVÔWˆMà×4Ò4Ø -ˆGÔØˆNà Ð r<   c                 ó  — t        j                  |d| j                  j                  j                  f| j
                  | j                  ¬«      }t        j                  |df| j
                  t         j                  ¬«      }t        |f|d¬«      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 MusicgenForConditionalGeneration

        >>> model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")

        >>> # 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]   r\   r  )r/   r0   r1   )	r6   rt   r‘   rë  rç   r]   r\   rŸ  r.   )rV   Únum_samplesrG  r0   s       r=   Úget_unconditional_inputsz9MusicgenForConditionalGeneration.get_unconditional_inputs’
  sy   € ô, "ŸK™KØ˜!˜TŸ[™[×5Ñ5×AÑAÐBÈ4Ï;É;Ð^b×^hÑ^hô
Ðô Ÿ™ k°1Ð%5¸d¿k¹kÔQV×Q[ÑQ[Ô\ˆä)Ø.Ð0Ø)Øô
ð 	
r<   )NNNN)NNN)NNNNNNNNNNNNNNN)
NNNNNNNNNNrR   )NNræ  )r(   )=r2   r3   r4   r)   r  r  rN  r  r  r  r   r   rq  rT   rü  r  r  r
  rl  r5  ry  r}  ÚclassmethodÚstrr&  r!   ÚMUSICGEN_INPUTS_DOCSTRINGr#   r   rç  r6   r9   Ú
BoolTensorr7   r	   r¿   r
   r‚   r›  rƒ   r   r†   r]   rB  r   r   rV  rb  rd  rg  rl  rn  rq  r   r=  r…   r   r   rå  r€  r‡   rˆ   s   @r=   ré  ré  …  s
  ø„ ð "€LØ)ÐØ!€OØ&*Ð#Ø!ÐØ€Nð ,0Ø26Ø37Ø15ñ[à˜Ñ(ð[ð ˜Ñ/ð[ð   Ñ0ð	[ð
 Ð-Ñ.õ[òz;ò "ò!ò'òò8ò4òBð ð EIØEIØ?Cñ	Bkà4<¸S±MðBkð 6>¸c±]ðBkð 08¸©}ð	Bkð 
òBkó ðBkñH +Ð+DÓEÙ¨?ÈÔYð 15Ø59Ø48Ø37Ø8<Ø=AØ>BØ;?Ø59Ø=AØ-1Ø$(Ø,0Ø/3Ø&*ñ!O
à˜E×,Ñ,Ñ-ðO
ð ! ×!1Ñ!1Ñ2ðO
ð ˜u×0Ñ0Ñ1ð	O
ð
 ˜u×/Ñ/Ñ0ðO
ð $ E×$4Ñ$4Ñ5ðO
ð !)¨×)9Ñ)9Ñ :ðO
ð " %¨×(9Ñ(9Ñ":Ñ;ðO
ð ˜u U×%6Ñ%6Ñ7Ñ8ðO
ð   × 1Ñ 1Ñ2ðO
ð  (¨×(9Ñ(9Ñ:ðO
ð ˜×)Ñ)Ñ*ðO
ð ˜D‘>ðO
ð $ D™>ðO
ð ' t™nðO
ð  ˜d‘^ð!O
ð$ 
ˆu�oÐ%Ñ	&ò%O
ó Zó FðO
ðh ØØØ#ØØ!ØØØ#'Øó8
ð~ 15Ø&*Ø#ñ-/àð-/ð ð-/ð ˜3 §¡Ð,Ñ-ð	-/ð
 !)¨¡ð-/ð ˜s‘mð-/ð —‘ð-/ð 
ˆu×Ñ  c¨5¯<©<Ð&7Ñ!8Ð8Ñ	9ó-/ð^/à—|‘|ð/ð # 3™-ð	/ð
 ,ð/ð 
ˆc�3ˆh‰ó/ðd MQñJØ<DÀS¹MóJðXn¸E¿L¹Ló nò
ò2ò1ð *.Ø&*Ø:>ñ	`à˜Ÿ™Ñ&ð`ð ˜s‘mð`ð ˜t C¨¯©Ð$5Ñ6Ñ7ð	`ð
 
×	Ñ	ó`ð: cgñ
Ø&+¨C°°c±¨NÑ&;ð
ØRZÐ[^ÑR_ð
à	ó
ð$ €U‡]�]ƒ_ð *.Ø8<Ø:>Ø<@Ø&*Ø-1ñt!à˜Ÿ™Ñ&ðt!ð $Ð$4Ñ5ðt!ð #Ð#6Ñ7ð	t!ð
 $Ð$8Ñ9ðt!ð ˜d‘^ðt!ð ˜>Ñ*òt!ó ðt!÷l 
r<   ré  )ré  rq  rd  r  )Tr5   rÆ  rø  rj   rO  Údataclassesr   Útypingr   r   r   r   r   r	   r
   r6   Útorch.nnra   r   Úactivationsr   Ú
generationr   r   r   r   r   r   Úmodeling_attn_mask_utilsr   r   r   r   Úmodeling_flash_attention_utilsr   r   Úmodeling_outputsr   r   r   r   r   Úmodeling_utilsr   Úutilsr    r!   r"   r#   Úauto.configuration_autor%   rñ  r'   Úconfiguration_musicgenr)   r*   r+   Úgeneration.streamersr,   Ú
get_loggerr2   rÑ   rç  Ú_CHECKPOINT_FOR_DOCr.   r†   rƒ   rL   ÚModulerN   rŠ   rÁ   rØ   rè   rå   r  ÚMUSICGEN_START_DOCSTRINGrƒ  rb  r  rd  rq  ré  Ú__all__r;   r<   r=   ú<module>r—     s	  ðñ ã Û Û Û Ý !ß I× IÑ Iã Ý Ý %å !÷÷ ÷ó ÷ i÷õ õ .÷ó õ 1Ý *ß Iñ ÔÝJáÝ4à	ˆ×	Ñ	˜HÓ	%€à"€Ø/Ð ð ô+ ó +ó ð+ð$ %§,¡,ð ¸cð Ð[^ó ô(*L¨B¯I©Iô *Lô\[B˜Ÿ	™	ô [Bô~{9Ð/ô {9ô|x1Ð-ô x1ðx Ø!Ø0ñÐ ôx˜2Ÿ9™9ô xôv%˜oô %ð<Ð ð(dÐ ðLK%Ð !ô\S
Ð-ô S
ñl ØdØóô@
Ð+ó @
ó	ð@
ñF ØGØóôAÐ1°?ó Aó	ðAñH ðMàóô
h
 ¸ó h
óð
h
òV! r�r<   