§
    9²¸jE  ã                   ó²  — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZ ddlm Z  ddl!m"Z" ddl#m$Z$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-  ej.        e/¦  «        Z0 e¦   «         rd dlZ ed¬¦  «        e G d„ de"¦  «        ¦   «         ¦   «         Z1 e d¬¦  «        e G d„ de)¦  «        ¦   «         ¦   «         Z2d„ Z3d„ Z4 G d„ d e-¦  «        Z5 G d!„ d"e'¦  «        Z6e G d#„ d$e&¦  «        ¦   «         Z7 G d%„ d&e%¦  «        Z8 ed'¬(¦  «         G d)„ d*e$¦  «        ¦   «         Z9g d+¢Z:dS ),é    )Ú	dataclass)ÚpiN)Ústrict)ÚTensorÚbroadcast_tensorsé   )Úinitialization)ÚCache)ÚPreTrainedConfig)ÚBaseModelOutputWithPooling)ÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚis_torch_availableÚloggingÚtorch_compilable_check)Úrequiresé   )ÚAudioFlamingo3Config)Ú&AudioFlamingo3ForConditionalGenerationÚAudioFlamingo3ModelÚ!AudioFlamingo3ModelOutputWithPastÚAudioFlamingo3PreTrainedModel)ÚAudioFlamingo3Processor)ÚCONFIG_MAPPING)ÚMoonshineRotaryEmbeddingznvidia/music-flamingo-2601-hf)Ú
checkpointc                   óX   — e Zd ZU dZdZeed<   dZeed<   dZe	ed<   dZ
edz  ed	<   d
„ ZdS )ÚMusicFlamingoConfiga…  
    audio_bos_token_id (`int`, *optional*, defaults to 151670):
        The beginning-of-audio token index used to mark the start of audio spans.
    audio_eos_token_id (`int`, *optional*, defaults to 151671):
        The end-of-audio token index used to mark the end of audio spans.
    audio_frame_step (`float`, *optional*, defaults to 0.01):
        Duration in seconds of one input mel frame (trained with hop_length 160 at sampling_rate 16000).

    Example:

    ```python
    >>> from transformers import MusicFlamingoForConditionalGeneration, MusicFlamingoConfig, AudioFlamingo3EncoderConfig, Qwen2Config

    >>> # Initializing an MusicFlamingoEncoder config
    >>> audio_config = AudioFlamingo3EncoderConfig()

    >>> # Initializing a Qwen2 config
    >>> text_config = Qwen2Config()

    >>> # Initializing an MusicFlamingo configuration
    >>> configuration = MusicFlamingoConfig(audio_config, text_config)

    >>> # Initializing a model from the musicflamingo style configuration
    >>> model = MusicFlamingoForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```ivP Úaudio_bos_token_idiwP Úaudio_eos_token_idg{®Gáz„?Úaudio_frame_stepNÚrope_parametersc                 ó”  — | j         €ddddœ| _         t          | j        t          ¦  «        rA| j        d         dv r
d| j        d<   t	          | j        d                  d
i | j        ¤Ž| _        n | j        €t	          d         ¦   «         | _        t          | j        t          ¦  «        rK| j                             dd¦  «        | j        d<   t	          | j        d                  d
i | j        ¤Ž| _        n | j        €t	          d         ¦   «         | _        | j         d	         | _        | j        j        | _	        t          j        | fi |¤Ž d S )NÚdefaultg     À’@gš™™™™™É?)Ú	rope_typeÚ
rope_thetaÚpartial_rotary_factorÚ
model_type)NÚmusicflamingo_encoderÚaudioflamingo3_encoderÚqwen2r)   © )r%   Ú
isinstanceÚaudio_configÚdictr   Útext_configÚgetÚmax_position_embeddingsÚhidden_sizeÚhead_dimr   Ú__post_init__)ÚselfÚkwargss     ú‡/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/transformers/models/musicflamingo/modular_musicflamingo.pyr8   z!MusicFlamingoConfig.__post_init__^   s[  € ØÔÐ'à&Ø$Ø),ð$ð $ˆDÔ õ
 �dÔ'­Ñ.Ô.ð 	KØÔ  Ô.Ð2QÐQÐQØ2J�Ô! ,Ñ/å .¨tÔ/@ÀÔ/NÔ OÐ dÐ dÐRVÔRcÐ dÐ dˆDÔÐØÔÐ&Ý .Ð/GÔ HÑ JÔ JˆDÔå�dÔ&­Ñ-Ô-ð 	9Ø-1Ô-=×-AÒ-AÀ,ÐPWÑ-XÔ-XˆDÔ˜\Ñ*Ý-¨dÔ.>¸|Ô.LÔMÐaÐaÐPTÔP`ÐaÐaˆDÔÐØÔÐ%Ý-¨gÔ6Ñ8Ô8ˆDÔà'+Ô';¸LÔ'IˆÔ$ØÔ)Ô5ˆŒÝÔ& tÐ6Ð6¨vÐ6Ð6Ð6Ð6Ð6ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   ÚintÚ__annotations__r#   r$   Úfloatr%   r2   r8   r/   r<   r;   r!   r!   9   sx   € € € € € € ðð ð: %Ð˜Ð$Ð$Ñ$Ø$Ð˜Ð$Ð$Ñ$Ø"Ð�eÐ"Ð"Ñ"Ø#'€O�T˜D‘[Ð'Ð'Ñ'ð7ð 7ð 7ð 7ð 7r<   r!   )Útorch)Úbackendsc                   ó‚   ‡ — e Zd Z	 	 	 	 	 dˆ fd„	Zdeded	efd
„Zed„ ¦   «         Z	ed„ ¦   «         Z
d„ Zd„ Zd„ Zd„ Zˆ xZS )ÚMusicFlamingoProcessorNú<sound>ú<|sound_bos|>ú<|sound_eos|>é°  c                 óÜ   •— t          ¦   «                              |||||¬¦  «         | `|| _        || _        |                     |¦  «        | _        |                     |¦  «        | _        dS )as  
        audio_token (`Optional[str]`, *optional*, defaults to `"<sound>"`):
            Special token used to represent audio inputs in the chat template.
        audio_bos_token (`Optional[str]`, *optional*, defaults to `"<|sound_bos|>"`):
            Special token used to represent the beginning of audio.
        audio_eos_token (`Optional[str]`, *optional*, defaults to `"<|sound_eos|>"`):
            Special token used to represent the end of audio.
        max_audio_len (`int`, *optional*, defaults to 1200):
            Maximum length of audio sequences in seconds. Audio longer than this will be truncated.
        )Úchat_templateÚaudio_tokenÚmax_audio_lenN)ÚsuperÚ__init__Údefault_transcription_promptÚaudio_bos_tokenÚaudio_eos_tokenÚconvert_tokens_to_idsr"   r#   )	r9   Úfeature_extractorÚ	tokenizerrM   rN   rS   rT   rO   Ú	__class__s	           €r;   rQ   zMusicFlamingoProcessor.__init__{   s   ø€ õ( 	‰Œ×ÒØØØ'Ø#Ø'ð 	ñ 	
ô 	
ð 	
ð Ð-Ø.ˆÔØ.ˆÔØ"+×"AÒ"AÀ/Ñ"RÔ"RˆÔØ"+×"AÒ"AÀ/Ñ"RÔ"RˆÔÐÐr<   Úaudio_inputsÚ	audio_idxÚreturnc                 óR   — |d         |         }| j         | j        |z  z   | j        z   S )NÚnum_audio_tokens)rS   rN   rT   )r9   rY   rZ   r:   r]   s        r;   Úreplace_audio_tokenz*MusicFlamingoProcessor.replace_audio_tokenœ   s2   € Ø'Ð(:Ô;¸IÔFÐØÔ# dÔ&6Ð9IÑ&IÑIÈDÔL`Ñ`Ð`r<   c                 ó*   — | j         | j        | j        gS ©N)Úaudio_token_idr"   r#   ©r9   s    r;   Úaudio_token_idsz&MusicFlamingoProcessor.audio_token_ids    s   € àÔ# TÔ%<¸dÔ>UÐVÐVr<   c                 óD   — t                                d¦  «         | j        S )zLDeprecated alias for `audio_token_ids`; will be removed in a future release.z@`audio_ids` is deprecated; please use `audio_token_ids` instead.)ÚloggerÚwarning_oncerc   rb   s    r;   Ú	audio_idsz MusicFlamingoProcessor.audio_ids¥   s"   € õ 	×ÒÐ^Ñ_Ô_Ð_ØÔ#Ð#r<   c                 ó    — t          d¦  «        ‚©Nz/This method is not supported for MusicFlamingo.©ÚNotImplementedError©r9   Úargsr:   s      r;   Úapply_transcription_requestz2MusicFlamingoProcessor.apply_transcription_request«   ó   € Ý!Ð"SÑTÔTÐTr<   c                 ó    — t          d¦  «        ‚©Nz5MusicFlamingo does not need to overwrite this method.rj   rl   s      r;   ÚdecodezMusicFlamingoProcessor.decode®   ó   € Ý!Ð"YÑZÔZÐZr<   c                 ó    — t          d¦  «        ‚rq   rj   rl   s      r;   Úbatch_decodez#MusicFlamingoProcessor.batch_decode±   rs   r<   c                 ó    — t          d¦  «        ‚ri   rj   rl   s      r;   Ú"_strip_assistant_prefix_and_quotesz9MusicFlamingoProcessor._strip_assistant_prefix_and_quotes´   ro   r<   )NrH   rI   rJ   rK   )r=   r>   r?   rQ   r2   rA   Ústrr^   Úpropertyrc   rg   rn   rr   ru   rw   Ú__classcell__©rX   s   @r;   rG   rG   x   s  ø€ € € € € ð ØØ'Ø'ØðSð Sð Sð Sð Sð SðBa°ð aÀð aÐSVð að að að að ðWð Wñ „XðWð ð$ð $ñ „Xð$ð
Uð Uð Uð[ð [ð [ð[ð [ð [ðUð Uð Uð Uð Uð Uð Ur<   rG   c                 óÌ   —  | j         g | j        d d…         ¢d‘d‘R Ž } |                      d¬¦  «        \  }}t          j        | |fd¬¦  «        } |                      d¦  «        S )Néÿÿÿÿr   ©Údiméþÿÿÿ)ÚreshapeÚshapeÚunbindrD   ÚstackÚflatten)ÚxÚx1Úx2s      r;   Úrotate_halfr‰   ¸   sn   € ØˆŒ	Ð'�1”7˜3˜B˜3”<Ð' Ð' QÐ'Ð'Ð'€AØ�XŠX˜"ˆXÑÔ�F€BˆÝŒ�b�S˜"�I 2Ð&Ñ&Ô&€AØ�9Š9�R‰=Œ=Ðr<   c                 ór  — | j         }|                      t          j        ¦  «        } |                     | ¦  «        }|                     | ¦  «        }|j        d         }| d|d …f         }| dd |…f         }||z  t          |¦  «        |z  z   }t          j        ||fd¬¦  «                             |¦  «        S )Nr}   .r~   )ÚdtypeÚtorD   Úfloat64r‚   r‰   Úcat)Úhidden_statesÚcosÚsinÚoriginal_dtypeÚrot_dimÚpassthroughÚrotateds          r;   Úapply_rotary_time_embr–   ¿   s³   € Ø"Ô(€NØ!×$Ò$¥U¤]Ñ3Ô3€MØ
�&Š&�Ñ
Ô
€CØ
�&Š&�Ñ
Ô
€CØŒi˜Œm€Gà  W X X Ô.€KØ˜C  ' ˜MÔ*€GØ˜‰}¥¨WÑ!5Ô!5¸Ñ!;Ñ<€GÝŒ9�g˜{Ð+°Ð4Ñ4Ô4×7Ò7¸ÑGÔGÐGr<   c            	       ó~   ‡ — e Zd ZdZd
defˆ fd„Zd„ Z ej        ¦   «         de	de
dee	e	f         fd	„¦   «         Zˆ xZS )ÚMusicFlamingoRotaryEmbeddinga·  Rotary time embedding module used by MusicFlamingo checkpoints.

    This is a checkpoint-faithful integration, not a direct implementation of the RoTE formulation described in
    (Goel et al., 2024): https://arxiv.org/abs/2410.12109. It applies axial rotary embeddings over the window index
    within each audio sample and the encoder time index within each window, then modulates both axes with absolute
    timestamps in seconds.
    NÚconfigc                 ó´   •— t          ¦   «                              |¦  «         |                      | j        ¦  «        }t	          j        |d¬¦  «        | _        d S )NF)Ú
persistent)rP   rQ   Ú_compute_position_anglesÚinv_freqÚnnÚBufferÚposition_angles)r9   r™   Údevicer    rX   s       €r;   rQ   z%MusicFlamingoRotaryEmbedding.__init__Õ   sM   ø€ Ý‰Œ×Ò˜Ñ Ô Ð Ø×7Ò7¸¼ÑFÔFˆÝ!œy¨ÀUÐKÑKÔKˆÔÐÐr<   c                 ó&  — t          j        t          | j        ¦  «        |j        |j        ¬¦  «        }|| j        z  dt          z  z  }|                     d¦  «        |z  }t          j        |dd¬¦  «        }| 	                    |j        ¬¦  «        S )N©r¡   r‹   r   r}   r~   )r‹   )
rD   ÚarangerA   Úmax_seq_len_cachedr¡   r‹   r   Ú	unsqueezeÚrepeat_interleaverŒ   )r9   r�   Ú	positionsr    s       r;   rœ   z5MusicFlamingoRotaryEmbedding._compute_position_anglesÚ   s‡   € Ý”L¥ TÔ%<Ñ!=Ô!=ÀhÄoÐ]eÔ]kÐlÑlÔlˆ	Ø Ô 7Ñ7¸1½r¹6ÑBˆ	Ø#×-Ò-¨bÑ1Ô1°HÑ<ˆÝÔ1°/À1È"ÐMÑMÔMˆØ×!Ò!¨¬Ð!Ñ7Ô7Ð7r<   Ú
timestampsÚseq_lenr[   c                 ó¤  — |dd…df                               | j        j        | j        j        ¬¦  «        }| j        j        dz  |z  }t          j        ||z  ¦  «        | j        z  }| 	                    d¦  «        | j        z  }t          j
        |dd¬¦  «        }|dd…ddd…f         }| j        d|…         ddd…dd…f         }t          ||¦  «        \  }}t          j        ||fd¬¦  «        }| dz  t          z                        |¦  «        }	||	 	                    d¦  «        z  }|                     ¦   «         |                     ¦   «         fS )zBCompute 2D axial rotary embeddings for window and time dimensions.Nr   r£   é   r}   r   r~   )rŒ   r�   r¡   r‹   r™   r$   rD   Úroundr¥   r¦   r§   r    r   rŽ   r   r�   r‘   )
r9   r©   rª   Úwindow_startsÚwindow_durationÚwindow_positionsÚwindow_freqsÚ
time_freqsÚfreqsÚangles
             r;   Úforwardz$MusicFlamingoRotaryEmbedding.forwardá   sO  € ð
 # 1 1 1 a 4Ô(×+Ò+°4´=Ô3GÈtÌ}ÔObÐ+ÑcÔcˆØœ+Ô6¸Ñ:¸WÑDˆÝ œ; }°Ñ'FÑGÔGÈ$ÔJaÑaÐØ'×1Ò1°"Ñ5Ô5¸¼ÑEˆÝÔ.¨|¸QÀBÐGÑGÔGˆð $ A A A t¨Q¨Q¨Q JÔ/ˆØÔ)¨(¨7¨(Ô3°D¸!¸!¸!¸Q¸Q¸Q°JÔ?ˆ
Ý#4°\À:Ñ#NÔ#NÑ ˆ�jÝ”	˜<¨Ð4¸"Ð=Ñ=Ô=ˆØ�˜q‘¥2Ñ%×)Ò)¨%Ñ0Ô0ˆØ˜Ÿš¨Ñ+Ô+Ñ+ˆØ�yŠy‰{Œ{˜EŸIšI™KœKÐ'Ð'r<   r`   )r=   r>   r?   r@   r!   rQ   rœ   rD   Úno_gradr   rA   Útuplerµ   rz   r{   s   @r;   r˜   r˜   Ì   s±   ø€ € € € € ðð ðLð LÐ2ð Lð Lð Lð Lð Lð Lð
8ð 8ð 8ð €U„]�_„_ð( &ð (°3ð (¸5ÀÈÀÔ;Pð (ð (ð (ñ „_ð(ð (ð (ð (ð (r<   r˜   c                   óB   — e Zd ZdZ ej        ¦   «         d„ ¦   «         ZdS )ÚMusicFlamingoPreTrainedModelNc                 óÆ   — t          j        | |¦  «         t          |t          ¦  «        r6|                     |j        ¦  «        }t          j        |j        |¦  «         d S d S r`   )	r   Ú_init_weightsr0   r˜   rœ   r�   ÚinitÚcopy_r    )r9   ÚmoduleÚbuffer_values      r;   r»   z*MusicFlamingoPreTrainedModel._init_weightsù   sb   € åÔ% d¨FÑ3Ô3Ð3Ý�fÕ:Ñ;Ô;ð 	=Ø!×:Ò:¸6¼?ÑKÔKˆLÝŒJ�vÔ-¨|Ñ<Ô<Ð<Ð<Ð<ð	=ð 	=r<   )r=   r>   r?   Ú_no_split_modulesrD   r¶   r»   r/   r<   r;   r¹   r¹   ö   s;   € € € € € ØÐà€U„]�_„_ð=ð =ñ „_ð=ð =ð =r<   r¹   c                   ó   — e Zd ZdS )Ú MusicFlamingoModelOutputWithPastN)r=   r>   r?   r/   r<   r;   rÂ   rÂ     s   € € € € € à€Dr<   rÂ   c                   ó°  ‡ — e Zd Zdefˆ fd„Zdej        dej        dedej        fd„Z	e
 ed¬	¦  «        d
ej        dej        dej        dee         deez  f
d„¦   «         ¦   «         Ze
e	 	 	 	 	 	 	 	 ddej        dz  d
ej        dz  dej        dz  dej        dz  dej        dz  dedz  dej        dz  dedz  dee         fd„¦   «         ¦   «         Zˆ xZS )ÚMusicFlamingoModelr™   c                 ór   •— t          ¦   «                              |¦  «         t          |¦  «        | _        d S r`   )rP   rQ   r˜   Úpos_emb©r9   r™   rX   s     €r;   rQ   zMusicFlamingoModel.__init__  s.   ø€ Ý‰Œ×Ò˜Ñ Ô Ð Ý3°FÑ;Ô;ˆŒˆˆr<   Ú	input_idsÚpost_lengthsÚmax_post_lengthr[   c                 ó\  — || j         j        k    }t          j        t          j        j                             |                     ¦   «         dd¬¦  «        d¬¦  «        }t          j        |dk    ¦  «        \  }}t          j        |dk    ¦  «        \  }}||z
   	                    t          j
        ¦  «        }	|                     ¦   «         }
|                     ¦   «         }t          |
|k    d|
› d|› �¦  «         | j         j        d	z  }t          j        ||j        t          j        ¬
¦  «        |z  }t          j        t          j        d|j        ¬¦  «        t          j        |d¬¦  «        d d…         g¦  «        }t          j        |	d¬¦  «        }t          j        ||d¬¦  «        }t          j        |t          j        |	j        d         |j        ¬¦  «        ¦  «        }t          j        |j        d         |j        ¬¦  «        ||         z
  }|                     d¦  «        |z  |z  |z   S )N)é   rÌ   r   )ÚvaluerÌ   r~   r}   z6Audio features and audio tokens do not match, tokens: z, features: r¬   r£   ©r¡   T)Úright)r™   ra   rD   Údiffrž   Ú
functionalÚpadrA   ÚwhererŒ   ÚlongÚsumr   r$   r¤   r¡   Úfloat32rŽ   ÚzerosÚcumsumÚsearchsortedr‚   r¦   )r9   rÈ   rÉ   rÊ   Úaudio_token_maskrÐ   Ú_ÚstartsÚendsÚsample_lengthsÚn_audio_tokensÚn_audio_featuresÚaudio_embed_frame_stepÚframe_offsetsÚcumsum_postÚcumsum_samplesÚsample_indicesÚsample_start_rowsÚwindow_indicess                      r;   Ú_build_audio_timestampsz*MusicFlamingoModel._build_audio_timestamps  s  € ð %¨¬Ô(BÒBÐÝŒz�%œ(Ô-×1Ò1Ð2B×2FÒ2FÑ2HÔ2HÈ&ÐXYÐ1ÑZÔZÐ`aÐbÑbÔbˆÝ”K ¨¢	Ñ*Ô*‰	ˆˆ6Ý”+˜d bšjÑ)Ô)‰ˆˆ4Ø ™-×+Ò+­E¬JÑ7Ô7ˆà)×-Ò-Ñ/Ô/ˆØ'×+Ò+Ñ-Ô-ÐÝØÐ.Ò.ØsÀ^ÐsÐsÐaqÐsÐsñ	
ô 	
ð 	
ð "&¤Ô!=ÀÑ!AÐåŒL˜°Ô1DÍEÌMÐZÑZÔZÐ]sÑsð 	õ
 ”i¥¤¨Q°|Ô7JÐ!KÑ!KÔ!KÍUÌ\ÐZfÐlmÐMnÑMnÔMnÐorÐprÐorÔMsÐ tÑuÔuˆÝœ n¸!Ð<Ñ<Ô<ˆÝÔ+¨N¸KÈtÐTÑTÔTˆõ "Ô.Ø�EœL¨Ô)=¸aÔ)@ÈÔI\Ð]Ñ]Ô]ñ
ô 
Ðõ ŒL˜Ô+¨AÔ.°|Ô7JÐKÑKÔKÐN_Ð`nÔNoÑoð 	ð
 ×'Ò'¨Ñ*Ô*¨_Ñ<Ð?UÑUÐXeÑeÐer<   zŸThis method is used to get the audio embeddings from input features (a log mel spectrogram), meaning inferring the audio encoder and the multi-modal projector.©Úcustom_introÚinput_featuresÚinput_features_maskr:   c                 ó   —  | j         |f|ddœ|¤Ž}|j        }| j                              |                     d¦  «                             t
          j        ¦  «        ¦  «        \  }}|                      |||j        d         ¦  «        }	|  	                    |	                     |j
        ¦  «        |j        d         ¬¦  «        \  }
}t          ||
|¦  «        }|                      |¦  «        }t          j        |j        d         |j
        ¬¦  «        ddd…f         |dd…df         k     }||                     |j
        ¦  «                 |_        |S )	az  
        input_features_mask (`torch.Tensor` of shape `(batch_size, feature_sequence_length)`):
            Mask to avoid performing attention on padded feature indices.
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Token ids containing the audio token ID placeholders, for reconstructing rotary time embedding timestamps.
        T)rì   Úreturn_dictr}   r€   )rª   rÌ   rÎ   N)Úaudio_towerÚlast_hidden_stateÚ _get_feat_extract_output_lengthsrÕ   rŒ   rD   rÔ   rè   r‚   rÆ   r¡   r–   Úmulti_modal_projectorr¤   Úpooler_output)r9   rë   rì   rÈ   r:   Úaudio_outputr�   rÛ   rÉ   Úaudio_timestampsr�   r‘   Úaudio_embedsÚ
valid_masks                 r;   Úget_audio_featuresz%MusicFlamingoModel.get_audio_features4  sc  € ð" (�tÔ'Øð
à 3Øð
ð 
ð ð	
ð 
ˆð %Ô6ˆØÔ*×KÒKÐL_×LcÒLcÐdfÑLgÔLg×LjÒLjÕkpÔkuÑLvÔLvÑwÔw‰ˆˆ<Ø×7Ò7¸	À<ÐQ^ÔQdÐegÔQhÑiÔiÐØ—<’<Ð 0× 3Ò 3°MÔ4HÑ IÔ IÐS`ÔSfÐgiÔSj�<ÑkÔk‰ˆˆSÝ-¨m¸SÀ#ÑFÔFˆØ×1Ò1°-Ñ@Ô@ˆõ ”\ ,Ô"4°QÔ"7ÀÔ@SÐTÑTÔTÐUYÐ[\Ð[\Ð[\ÐU\Ô]Ð`lÐmnÐmnÐmnÐptÐmtÔ`uÒuˆ
Ø%1°*·-²-ÀÔ@SÑ2TÔ2TÔ%UˆÔ"àÐr<   NÚattention_maskÚposition_idsÚpast_key_valuesÚinputs_embedsÚ	use_cachec	           	      ó–  — |€ |                       ¦   «         |¦  «        }d}
|�l|�j|                      |||d¬¦  «        j        }
|                      |||
¬¦  «        }|                     ||
                     |j        |j        ¦  «        ¦  «        } | j        d|||||dœ|	¤Ž}t          |j
        |j        |j        |j        |
¬¦  «        S )z³
        input_features_mask (`torch.Tensor` of shape `(batch_size, feature_sequence_length)`):
            Mask to avoid performing attention on padding feature indices.
        NT)rÈ   rî   )rü   Úaudio_features)rü   rù   rú   rû   rý   )rð   rû   r�   Ú
attentionsÚaudio_hidden_statesr/   )Úget_input_embeddingsrø   ró   Úget_placeholder_maskÚmasked_scatterrŒ   r¡   r‹   Úlanguage_modelrÂ   rð   rû   r�   r   )r9   rÈ   rë   rì   rù   rú   rû   rü   rý   r:   rö   Úspecial_audio_maskÚoutputss                r;   rµ   zMusicFlamingoModel.forwardX  s!  € ð$ Ð Ø7˜D×5Ò5Ñ7Ô7¸	ÑBÔBˆMàˆØÐ%¨)Ð*?Ø×2Ò2ØÐ 3¸yÐVZð 3ñ ô äð ð
 "&×!:Ò!:Ø¨À|ð ";ñ "ô "Ðð *×8Ò8Ø" L§O¢O°MÔ4HÈ-ÔJ]Ñ$^Ô$^ñô ˆMð &�$Ô%ð 
Ø'Ø)Ø%Ø+Øð
ð 
ð ð
ð 
ˆõ 0Ø%Ô7Ø#Ô3Ø!Ô/ØÔ)Ø ,ð
ñ 
ô 
ð 	
r<   )NNNNNNNN)r=   r>   r?   r!   rQ   rD   Ú
LongTensorrA   ÚFloatTensorrè   r   r   r   r   r   r·   r   rø   r
   Úboolrµ   rz   r{   s   @r;   rÄ   rÄ     sù  ø€ € € € € ð<Ð2ð <ð <ð <ð <ð <ð <ð'fàÔ#ð'fð Ô&ð'fð ð	'fð
 
Ô	ð'fð 'fð 'fð 'fðR Ø€^ð wðñ ô ðàÔ)ðð #œ\ðð Ô#ð	ð
 Ð+Ô,ðð 
Ð+Ñ	+ðð ð ñô ñ Ôðð@ Øð .2Ø37Ø37Ø.2Ø04Ø(,Ø26Ø!%ð0
ð 0
àÔ# dÑ*ð0
ð Ô)¨DÑ0ð0
ð #œ\¨DÑ0ð	0
ð
 œ tÑ+ð0
ð Ô&¨Ñ-ð0
ð  ™ð0
ð Ô(¨4Ñ/ð0
ð ˜$‘;ð0
ð Ð+Ô,ð0
ð 0
ð 0
ñ „^ñ Ôð0
ð 0
ð 0
ð 0
ð 0
r<   rÄ   z�
    The MusicFlamingo model which consists of a fine-tuned Whisper encoder, rotary time embedding, a multi-modal projector, and a Qwen2 language model.
    ré   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )Ú%MusicFlamingoForConditionalGenerationr™   c                 óš   •— t          ¦   «                              |¦  «         t          |¦  «        | _        |                      ¦   «          d S r`   )rP   rQ   rÄ   ÚmodelÚ	post_initrÇ   s     €r;   rQ   z.MusicFlamingoForConditionalGeneration.__init__“  s@   ø€ Ý‰Œ×Ò˜Ñ Ô Ð Ý'¨Ñ/Ô/ˆŒ
Ø�ŠÑÔÐÐÐr<   c                 ó,   —  | j         j        |||fi |¤ŽS r`   )r  rø   )r9   rë   rì   rÈ   r:   s        r;   rø   z8MusicFlamingoForConditionalGeneration.get_audio_features˜  s&   € Ø,ˆtŒzÔ,¨^Ð=PÐR[ÐfÐfÐ_eÐfÐfÐfr<   )r=   r>   r?   r!   rQ   rø   rz   r{   s   @r;   r  r  �  s[   ø€ € € € € ðÐ2ð ð ð ð ð ð ð
gð gð gð gð gð gð gr<   r  )r!   rG   r  rÄ   r¹   );Údataclassesr   Úmathr   Útorch.nnrž   Úhuggingface_hub.dataclassesr   rD   r   r   Ú r	   r¼   Úcache_utilsr
   Úconfiguration_utilsr   Úmodeling_outputsr   Úmodeling_utilsr   Úprocessing_utilsr   Úutilsr   r   r   r   r   r   Úutils.import_utilsr   Ú+audioflamingo3.configuration_audioflamingo3r   Ú&audioflamingo3.modeling_audioflamingo3r   r   r   r   Ú(audioflamingo3.processing_audioflamingo3r   Úautor   Úmoonshine.modeling_moonshiner   Ú
get_loggerr=   re   r!   rG   r‰   r–   r˜   r¹   rÂ   rÄ   r  Ú__all__r/   r<   r;   ú<module>r$     sç  ðð  "Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .Ø +Ð +Ð +Ð +Ð +Ð +Ð +Ð +à &Ð &Ð &Ð &Ð &Ð &Ø  Ð  Ð  Ð  Ð  Ð  Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø :Ð :Ð :Ð :Ð :Ð :Ø -Ð -Ð -Ð -Ð -Ð -Ø &Ð &Ð &Ð &Ð &Ð &ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð +Ð *Ð *Ð *Ð *Ð *Ø NÐ NÐ NÐ NÐ NÐ Nðð ð ð ð ð ð ð ð ð ð ð ð OÐ NÐ NÐ NÐ NÐ NØ !Ð !Ð !Ð !Ð !Ð !Ø CÐ CÐ CÐ CÐ CÐ Cð 
ˆÔ	˜HÑ	%Ô	%€ð ÐÑÔð Ø€L€L€Lð €Ð:Ð;Ñ;Ô;Øð:7ð :7ð :7ð :7ð :7Ð.ñ :7ô :7ñ „ñ <Ô;ð:7ðz 
€�:ÐÑÔØð;Uð ;Uð ;Uð ;Uð ;UÐ4ñ ;Uô ;Uñ „ñ Ôð;Uð|ð ð ð
Hð 
Hð 
Hð'(ð '(ð '(ð '(ð '(Ð#;ñ '(ô '(ð '(ðT=ð =ð =ð =ð =Ð#@ñ =ô =ð =ð ð	ð 	ð 	ð 	ð 	Ð'Hñ 	ô 	ñ „ð	ðD
ð D
ð D
ð D
ð D
Ð,ñ D
ô D
ð D
ðN €ððñ ô ð
gð gð gð gð gÐ,Rñ gô gñô ð
gðð ð €€€r<   