+
    œ°³jq8  ã                   ó  € ^ RI Ht ^ RIt^ RIHt ^RIHt ^RIHt ^RIH	t	 ^RI
HtHtHt ^RIHt ^R	IHtHtHtHt ^R
IHt ^RIHt ^RIHt ^RIHtHtHtHt ^RI H!t!  ! R R]4      t" ! R R]4      t# ! R R]4      t$]! RR7       ! R R]4      4       t% ! R R]PL                  4      t']! RR7      ] ! R R]4      4       4       t(]! RR7       ! R R ]$4      4       t)]! R!R7       ! R" R#]$]	4      4       t*. R$Ot+R# )%é    )Ú	dataclassN)Únn)ÚACT2FN)ÚCache)ÚGenerationMixin)ÚBaseModelOutputWithPastÚBaseModelOutputWithPoolingÚCausalLMOutputWithPast)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚtorch_compilable_check)Úmerge_with_config_defaults)Úcapture_outputs)Ú	AutoModel)ÚQwen2AudioAttentionÚQwen2AudioEncoderÚQwen2AudioEncoderLayerÚQwen2AudioPreTrainedModel©ÚVoxtralConfigc                   ó   € ] tR t^+tRtR# )ÚVoxtralAttention© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    Úl/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/voxtral/modular_voxtral.pyr   r   +   ó   † Ûr"   r   c                   ó   € ] tR t^/tRtR# )ÚVoxtralEncoderLayerr   Nr   r   r"   r#   r&   r&   /   r$   r"   r&   c                   ó*   € ] tR t^3tRtRtRtRtRtRt	R# )ÚVoxtralPreTrainedModelTNr   )
r   r   r   r    Ú_supports_flex_attnÚ_supports_cache_classÚ_supports_attention_backendÚ_can_compile_fullgraphÚ_no_split_modulesr!   r   r"   r#   r(   r(   3   s    † ØÐØ ÐØ"&ÐØ!ÐØÔr"   r(   z:
    The Voxtral encoder, which is a Whisper encoder.
    ©Úcustom_introc                   óV   a € ] tR t^<t o R]R]/t]]RV 3R lR ll4       4       t	Rt
V tR# )ÚVoxtralEncoderÚ
attentionsÚhidden_statesNc                óF   <€ V ^8„  d   QhRS[ S[,          RS[S[,          /# )é   ÚkwargsÚreturn)r   r   Útupler	   )ÚformatÚ__classdict__s   "€r#   Ú__annotate__ÚVoxtralEncoder.__annotate__I   s-   ø€ ÷ +
ñ +
ñ Ñ+Õ,ð	+
ñ
 
Ñ+Õ	+ñ+
r"   c           	     ó  € V P                   P                  V P                  P                  ^ ,          ,          V P                  P                  ^ ,          ,          pVP
                  R	,          V8w  d'   \        RV RVP
                  R	,           RV R24      hVP                  V P                  P                  P                  V P                  P                  P                  R7      p\        P                  P                  V P                  V4      4      p\        P                  P                  V P	                  V4      4      pVP                  ^ ^^4      pV P                  P                  pWV,           P                  VP                  4      p\        P                  P!                  WpP                   V P"                  R7      p\%        V P&                  4       F  w  r‰V	! VVR7      pK  	  V P)                  V4      p\+        VR7      # )
a�  
Args:
    input_features (`torch.LongTensor` of shape `(batch_size, feature_size, sequence_length)`):
        Float values of mel features extracted from the raw speech waveform. Raw speech waveform can be
        obtained by loading a `.flac` or `.wav` audio file into an array of type `list[float]` or a
        `numpy.ndarray`, *e.g.* via the soundfile library (`pip install soundfile`). To prepare the array into
        `input_features`, the [`AutoFeatureExtractor`] should be used for extracting the mel features, padding
        and conversion into a tensor of type `torch.FloatTensor`. See [`~WhisperFeatureExtractor.__call__`]
    attention_mask (`torch.Tensor`)`, *optional*):
        Voxtral does not support masking of the `input_features`, this argument is preserved for compatibility,
        but it is not used. By default the silence in the input log mel spectrogram are ignored.
z7Voxtral expects the mel input features to be of length z, but found z-. Make sure to pad the input mel features to Ú.©ÚdtypeÚdevice)ÚpÚtraining)Úattention_mask)Úlast_hidden_stateéÿÿÿÿ)ÚconfigÚmax_source_positionsÚconv1ÚstrideÚconv2ÚshapeÚ
ValueErrorÚtoÚweightr@   rA   r   Ú
functionalÚgeluÚpermuteÚembed_positionsÚdropoutrC   Ú	enumerateÚlayersÚ
layer_normr	   )
ÚselfÚinput_featuresrD   r6   Úexpected_seq_lengthÚinputs_embedsÚ	embed_posr3   ÚidxÚencoder_layers
   &&&,      r#   ÚforwardÚVoxtralEncoder.forwardG   sÊ  € ð( #Ÿk™k×>Ñ>ÀÇÁ×ARÑARÐSTÕAUÕUÐX\×XbÑXb×XiÑXiÐjkÕXlÕlÐØ×Ñ Õ#Ð':Ô:ÜØIÐJ]ÐI^Ð^jÐky×kÑkð  ACõ  lDð  kEð  Erð  sFð  rGð  GHð  Ióð ð (×*Ñ*°·±×1BÑ1B×1HÑ1HÐQU×Q[ÑQ[×QbÑQb×QiÑQiÐ*ÓjˆÜŸ™×*Ñ*¨4¯:©:°nÓ+EÓFˆÜŸ™×*Ñ*¨4¯:©:°mÓ+DÓEˆØ%×-Ñ-¨a°°AÓ6ˆà×(Ñ(×/Ñ/ˆ	Ø&Õ2×6Ñ6°}×7JÑ7JÓKˆÜŸ™×-Ñ-¨m¿|¹|ÐVZ×VcÑVcÐ-Ódˆä"+¨D¯K©KÖ"8ÑˆCÙ)ØØ-ôŠMñ #9ð Ÿ™¨Ó6ˆä)Ø+ô
ð 	
r"   r   ©N)r   r   r   r    r   r&   Ú_can_record_outputsr   r   r_   r!   Ú__classdictcell__©r:   s   @r#   r1   r1   <   s<   ø‡ € ð 	Ð&ØÐ,ðÐð
  Ø÷+
ñ +
ó ó  ö+
r"   r1   c                   óD   a a€ ] tR t^wt oV3R lV 3R lltR tRtVtV ;t# )ÚVoxtralMultiModalProjectorc                ó    <€ V ^8„  d   QhRS[ /# )r5   rG   r   )r9   r:   s   "€r#   r;   Ú'VoxtralMultiModalProjector.__annotate__x   s   ø€ ÷ nñ n™}ñ nr"   c                ót  <€ \         SV `  4        \        P                  ! VP                  P
                  VP                  P                  R R7      V n        \        VP                  ,          V n        \        P                  ! VP                  P                  VP                  P                  R R7      V n        R# ©F)ÚbiasN)ÚsuperÚ__init__r   ÚLinearÚaudio_configÚintermediate_sizeÚtext_configÚhidden_sizeÚlinear_1r   Úprojector_hidden_actÚactÚlinear_2©rX   rG   Ú	__class__s   &&€r#   rm   Ú#VoxtralMultiModalProjector.__init__x   sz   ø€ Ü‰ÑÔÜŸ	š	 &×"5Ñ"5×"GÑ"GÈ×I[ÑI[×IgÑIgÐnsÔtˆŒÜ˜&×5Ñ5Õ6ˆŒÜŸ	š	 &×"4Ñ"4×"@Ñ"@À&×BTÑBT×B`ÑB`ÐglÔmˆŽr"   c                ól   € V P                  V4      pV P                  V4      pV P                  V4      pV# ra   )rs   ru   rv   )rX   Úaudio_featuresr3   s   && r#   r_   Ú"VoxtralMultiModalProjector.forward~   s2   € ØŸ™ nÓ5ˆØŸ™ Ó/ˆØŸ™ mÓ4ˆØÐr"   )ru   rs   rv   )	r   r   r   r    rm   r_   r!   rc   Ú__classcell__©rx   r:   s   @@r#   rf   rf   w   s   ù‡ € ÷nó n÷ò r"   rf   zL
    Base class for Voxtral outputs, with hidden states and attentions.
    c                   ó4   a € ] tR t^…t o RtRtV 3R ltRtV tR# )ÚVoxtralModelOutputWithPastz[
audio_hidden_states (`torch.FloatTensor`, *optional*):
    Projected audio hidden states.
Nc                óH   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   # )r5   NÚaudio_hidden_states)ÚtorchÚFloatTensor)r9   r:   s   "€r#   r;   Ú'VoxtralModelOutputWithPast.__annotate__…   s   ø‡ ‚ ñ ×*Ñ*¨TÕ1Ñ8ò r"   r   )	r   r   r   r    Ú__doc__r‚   Ú__annotate_func__r!   rc   rd   s   @r#   r€   r€   …   s   ø‡ € ñð
 59Ð÷ ƒ r"   r€   z™
    The Voxtral model, which consists of Whisper encoder, a multi-modal projector and a Llama language model,
    without a language modeling head.
    c                   ó¢   a a€ ] tR t^”t oV 3R lt]]! RR7      V3R lR l4       4       tV3R lR lt]]RV3R lR	 ll4       4       t	R
t
VtV ;t# )ÚVoxtralModelc                óú   <€ \         SV `  V4       \        P                  ! VP                  4      V n        \        P                  ! VP                  4      V n        \        V4      V n	        V P                  4        R # ra   )rl   rm   r   Úfrom_configro   Úaudio_towerrq   Úlanguage_modelrf   Úmulti_modal_projectorÚ	post_initrw   s   &&€r#   rm   ÚVoxtralModel.__init__›   sY   ø€ Ü‰Ñ˜Ô Ü$×0Ò0°×1DÑ1DÓEˆÔÜ'×3Ò3°F×4FÑ4FÓGˆÔÜ%?ÀÓ%GˆÔ"Ø�‰Ör"   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.r.   c                ó`   <€ V ^8„  d   QhRS[ P                  RS[S[,          RS[S[,          /# )r5   rY   r6   r7   )rƒ   r„   r   r   r8   r	   )r9   r:   s   "€r#   r;   ÚVoxtralModel.__annotate__¦   s7   ø€ ÷ ñ Ù#×/Ñ/ðÙ;AÑBTÕ;Uðá	Ñ+Õ	+ñr"   c                óÖ   € V P                   ! V3RR/VB pVP                  pVP                  RV P                  P                  P
                  4      pV P                  V4      pWSn        V# )a)  
input_features (`torch.FloatTensor`):
    Float values of mel features extracted from the raw speech waveform. Raw speech waveform can be
    obtained by loading a `.flac` or `.wav` audio file into an array of type `list[float]` or a
    `numpy.ndarray`, *e.g.* via the soundfile library (`pip install soundfile`). To prepare the array into
    `input_features`, the [`AutoFeatureExtractor`] should be used for extracting the mel features, padding
    and conversion into a tensor of type `torch.FloatTensor`. See [`~WhisperFeatureExtractor.__call__`]
Úreturn_dictTrF   )rŒ   rE   ÚreshaperG   ro   rp   rŽ   Úpooler_output)rX   rY   r6   Úaudio_outputsr‚   Úaudio_embedss   &&,   r#   Úget_audio_featuresÚVoxtralModel.get_audio_features¢   sj   € ð ×(Ò(¨ÑTÀTÐTÈVÑTˆØ+×=Ñ=ÐØ1×9Ñ9¸"¸d¿k¹k×>VÑ>V×>hÑ>hÓiÐØ×1Ñ1Ð2EÓFˆØ&2Ô#àÐr"   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# )r5   Ú	input_idsr[   r{   )rƒ   Ú
LongTensorr„   )r9   r:   s   "€r#   r;   r’   ¹   s7   ø€ ÷ "ñ "Ù×)Ñ)ð"Ù:?×:KÑ:Kð"Ù]b×]nÑ]nñ"r"   c           
     ó@  € Vfo   W P                  4       ! \        P                  ! RV P                  P                  \        P
                  VP                  R7      4      8H  pVP                  R4      pMWP                  P                  8H  pVP                  4       pVP                  ^ ,          pVP                  R4      P                  V4      P                  VP                  4      p\        W$,          P                  4       VP                  4       8H  RV RV 24       V# )z×
Obtains multimodal placeholder mask from `input_ids` or `inputs_embeds`, and checks that the placeholder token count is
equal to the length of multimodal features. If the lengths are different, an error is raised.
r?   z6Audio features and audio tokens do not match, tokens: z, features: r   rF   )Úget_input_embeddingsrƒ   ÚfullrG   Úaudio_token_idÚlongrA   ÚallÚsumrL   Ú	unsqueezeÚ	expand_asrN   r   Únumel)rX   rœ   r[   r{   Úspecial_audio_maskÚn_audio_tokensÚn_audio_featuress   &&&&   r#   Úget_placeholder_maskÚ!VoxtralModel.get_placeholder_mask¹   sþ   € ð ÒØ!.×2KÑ2KÔ2MÜ—
’
˜2˜tŸ{™{×9Ñ9ÄÇÁÐTa×ThÑThÔió3ñ "Ðð "4×!7Ñ!7¸Ó!;Ñà!*¯k©k×.HÑ.HÑ!HÐà+×/Ñ/Ó1ˆØ)×/Ñ/°Õ2ÐØ/×9Ñ9¸"Ó=×GÑGÈÓV×YÑYÐZg×ZnÑZnÓoÐÜØÕ-×3Ñ3Ó5¸×9MÑ9MÓ9OÑOØDÀ^ÐDTÐT`ÐaqÐ`rÐsô	
ð "Ð!r"   c                ó6  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[ P                  R,          RS[R,          R	S[S[,          R
S[S[	,          /	# )r5   rœ   NrY   rD   Úposition_idsÚpast_key_valuesr[   Ú	use_cacher6   r7   )
rƒ   r�   r„   ÚTensorr   Úboolr   r   r8   r€   )r9   r:   s   "€r#   r;   r’   Ó   s®   ø€ ÷ )
ñ )
á×#Ñ# dÕ*ð)
ñ ×)Ñ)¨DÕ0ð)
ñ Ÿ™ tÕ+ð	)
ñ
 ×&Ñ&¨Õ-ð)
ñ  �ð)
ñ ×(Ñ(¨4Õ/ð)
ñ ˜$•;ð)
ñ Ñ+Õ,ð)
ñ 
Ñ+Õ	+ñ)
r"   c                ó¼  € Vf   V P                  4       ! V4      pR p	Vej   Vef   V P                  VRR7      P                  p	V P                  WV	R7      p
VP	                  W©P                  VP                  VP                  4      4      pV P                  ! R
RVRVRVRVRV/VB p\        VP                  VP                  VP                  VP                  V	R	7      # )NT)r”   )r[   r{   rD   r®   r¯   r[   r°   )rE   r¯   r3   r2   r‚   r   )rŸ   r™   r–   r«   Úmasked_scatterrN   rA   r@   r�   r€   rE   r¯   r3   r2   )rX   rœ   rY   rD   r®   r¯   r[   r°   r6   r˜   r¨   Úoutputss   &&&&&&&&,   r#   r_   ÚVoxtralModel.forwardÑ   s  € ð Ò Ø ×5Ñ5Ô7¸	ÓBˆMàˆØÒ%¨)Ò*?Ø×2Ñ2°>ÈtÐ2ÓT×bÑbˆLð "&×!:Ñ!:ØÀ|ð ";ó "Ðð *×8Ñ8Ø"§O¡O°M×4HÑ4HÈ-×J]ÑJ]Ó$^óˆMð ,0×+>Ò+>ñ ,
Ø)ð,
à%ð,
ð ,ð,
ð (ð	,
ð
  ð,
ð ñ,
ˆô *Ø%×7Ñ7Ø#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø ,ô
ð 	
r"   )rŒ   r�   rŽ   )NNNNNNN)r   r   r   r    rm   r   r   r™   r«   r_   r!   rc   r}   r~   s   @@r#   r‰   r‰   ”   sa   ù‡ € õð Ùð wô÷óó ð÷&"ð "ð0 Ø÷)
ñ )
ó ó ÷)
ð )
r"   r‰   zs
    The Voxtral model, which consists of Whisper encoder, a multi-modal projector and a Llama language model.
    c                   óh   a a€ ] tR t^ÿt oR.tV 3R ltR t]]RV3R lR ll4       4       t	Rt
VtV ;t# )ÚVoxtralForConditionalGenerationrS   c                óò   <€ \         SV `  V4       \        V4      V n        \        P
                  ! VP                  P                  VP                  P                  R R7      V n	        V P                  4        R# rj   )rl   rm   r‰   Úmodelr   rn   rq   rr   Ú
vocab_sizeÚlm_headr�   rw   s   &&€r#   rm   Ú(VoxtralForConditionalGeneration.__init__  sS   ø€ Ü‰Ñ˜Ô Ü! &Ó)ˆŒ
Ü—y’y ×!3Ñ!3×!?Ñ!?À×ASÑAS×A^ÑA^ÐejÔkˆŒØ�‰Ör"   c                ó:   € V P                   P                  ! V/ VB # ra   )rº   r™   )rX   Úargsr6   s   &*,r#   r™   Ú2VoxtralForConditionalGeneration.get_audio_features  s   € Ø�z‰z×,Ò,¨dÐ=°fÑ=Ð=r"   c                óˆ  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          RS[ P                  R,          RS[ P                  R,          R	S[R,          R
S[S[ P                  ,          RS[S[,          RS[	S[
,          /# )r5   rœ   NrY   rD   r®   r¯   r[   Úlabelsr°   Úlogits_to_keepr6   r7   )rƒ   r�   r„   r±   r   r²   Úintr   r   r8   r
   )r9   r:   s   "€r#   r;   Ú,VoxtralForConditionalGeneration.__annotate__  sã   ø€ ÷ I
ñ I
á×#Ñ# dÕ*ðI
ñ ×)Ñ)¨DÕ0ðI
ñ Ÿ™ tÕ+ð	I
ñ
 ×&Ñ&¨Õ-ðI
ñ  �ðI
ñ ×(Ñ(¨4Õ/ðI
ñ × Ñ  4Õ'ðI
ñ ˜$•;ðI
ñ ™eŸl™lÕ*ðI
ñ Ñ+Õ,ðI
ñ 
Ñ'Õ	'ñI
r"   c
                ó®  € V P                   ! RRVRVRVRVRVRVRV/V
B pVP                  p\        V	\        4      '       d   \	        V	) R4      MT	pV P                  VR	VR	3,          4      pRpVe7   V P                  ! RR
VRVRV P                  P                  P                  /V
B p\        VVVP                  VP                  VP                  R7      # )aš  
Example:

```python
>>> from transformers import VoxtralForConditionalGeneration, AutoProcessor
>>> import torch

>>> device = "cuda" if torch.cuda.is_available() else "cpu"
>>> repo_id = "mistralai/Voxtral-Mini-3B-2507"

>>> processor = AutoProcessor.from_pretrained(repo_id)
>>> model = VoxtralForConditionalGeneration.from_pretrained(repo_id, dtype=torch.bfloat16, device_map=device)

>>> conversation = [
    {
        "role": "user",
        "content": [
            {
                "type": "audio",
                "url": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/dude_where_is_my_car.wav",
            },
            {"type": "text", "text": "What can you tell me about this audio?"},
        ],
    }
]

>>> inputs = processor.apply_chat_template(conversation)
>>> inputs = inputs.to(device, dtype=torch.bfloat16)

>>> outputs = model.generate(**inputs, max_new_tokens=30)
>>> processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
["This audio is a humorous conversation between two friends, likely in English, where one of them is trying to figure out what the other's tattoo says."]
```rœ   rY   rD   r®   r¯   r[   r°   N:NNNÚlogitsrÂ   r»   )ÚlossrÇ   r¯   r3   r2   r   )rº   rE   Ú
isinstancerÄ   Úslicer¼   Úloss_functionrG   rq   r»   r
   r¯   r3   r2   )rX   rœ   rY   rD   r®   r¯   r[   rÂ   r°   rÃ   r6   rµ   r3   Úslice_indicesrÇ   rÈ   s   &&&&&&&&&&,     r#   r_   Ú'VoxtralForConditionalGeneration.forward  s  € ð` —*’*ñ 	
Øð	
à)ð	
ð *ð	
ð &ð		
ð
 ,ð	
ð (ð	
ð  ð	
ð ñ	
ˆð  ×1Ñ1ˆÜ8BÀ>ÔSV×8WÒ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜m¨A¨}¸aÐ,?Õ@ÓAˆàˆØÒØ×%Ò%ñ ØðØ&,ðØ9=¿¹×9PÑ9P×9[Ñ9[ðØ_eñˆDô &ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r"   )r¼   rº   )	NNNNNNNNr   )r   r   r   r    Ú_keep_in_fp32_modules_strictrm   r™   r   r   r_   r!   rc   r}   r~   s   @@r#   r¸   r¸   ÿ   sD   ù‡ € ð %6Ð#6Ð õò>ð Ø÷I
ñ I
ó ó ÷I
ð I
r"   r¸   )r(   r1   r‰   r¸   ),Údataclassesr   rƒ   r   Úactivationsr   Úcache_utilsr   Ú
generationr   Úmodeling_outputsr   r	   r
   Úprocessing_utilsr   Úutilsr   r   r   r   Úutils.genericr   Úutils.output_capturingr   Úautor   Ú qwen2_audio.modeling_qwen2_audior   r   r   r   Úconfiguration_voxtralr   r   r&   r(   r1   ÚModulerf   r€   r‰   r¸   Ú__all__r   r"   r#   Ú<module>rÝ      s2  ðõ  "ã Ý å !Ý  Ý )÷ñ õ
 'ß aÓ aÝ 7Ý 5Ý ÷ó õ 1ô	Ð*ô 	ô	Ð0ô 	ôÐ6ô ñ ðôô
3
Ð&ó 3
óð
3
ôl §¡ô ñ ðôð
 ô9Ð!8ó 9ó óð9ñ ðôôb
Ð)ó b
óðb
ñJ ðôô
W
Ð&<¸oó W
óð
W
òt j‚r"   