Ë
    ÜÓ^jÆ`  ã                   óü  — d dl Z d dlmZ d dlmZ d dlZd dlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZmZmZ ddlmZmZ ddlmZ ddlmZmZmZmZmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z%m&Z&  ejN                  e(«      Z)	 	 d2dejT                  dejV                  dejV                  dejV                  dejV                  dz  de,dz  de,fd„Z- G d„ dejT                  «      Z. G d„ de«      Z/e G d „ d!e«      «       Z0 ed"¬#«       G d$„ d%e0«      «       Z1 G d&„ d'ejT                  «      Z2 ed(¬#«      e G d)„ d*e«      «       «       Z3 ed+¬#«       G d,„ d-e0«      «       Z4 ed.¬#«       G d/„ d0e0e«      «       Z5g d1¢Z6y)3é    N)ÚCallable)Ú	dataclass)Únné   )ÚACT2FN)ÚCache)ÚGenerationMixin)ÚGradientCheckpointingLayer)ÚBaseModelOutputWithPastÚBaseModelOutputWithPoolingÚCausalLMOutputWithPast)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚloggingÚtorch_compilable_check)Úmerge_with_config_defaults)Úcapture_outputsé   )Ú	AutoModelé   )ÚVoxtralConfigÚVoxtralEncoderConfigÚmoduleÚqueryÚkeyÚvalueÚattention_maskÚscalingÚdropoutc                 óœ  — |€|j                  d«      dz  }t        j                  ||j                  dd«      «      |z  }|�||z   }t        j
                  j                  |d¬«      }t        j
                  j                  ||| j                  ¬«      }t        j                  ||«      }	|	j                  dd«      j                  «       }	|	|fS )Néÿÿÿÿç      à¿r   r   )Údim©ÚpÚtrainingr   )
ÚsizeÚtorchÚmatmulÚ	transposer   Ú
functionalÚsoftmaxr#   r*   Ú
contiguous)
r   r   r   r    r!   r"   r#   ÚkwargsÚattn_weightsÚattn_outputs
             úw/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/voxtral/modeling_voxtral.pyÚeager_attention_forwardr6   .   s¹   € ð €Ø—*‘*˜R“. DÑ(ˆä—<‘<  s§}¡}°Q¸Ó':Ó;¸gÑE€LØÐ!Ø# nÑ4ˆä—=‘=×(Ñ(¨¸2Ð(Ó>€Lä—=‘=×(Ñ(¨¸È6Ï?É?Ð(Ó[€LÜ—,‘,˜|¨UÓ3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€Kà˜Ð$Ð$ó    c                   ó,  ‡ — e Zd ZdZ	 	 	 	 	 	 ddedededededed	edz  d
edz  fˆ fd„Zde	j                  dedefd„Z	 	 dde	j                  de	j                  dz  dedee	j                  e	j                  dz  ee	j                     dz  f   fd„Zˆ xZS )ÚVoxtralAttentionz=Multi-headed attention from 'Attention Is All You Need' paperNÚ	embed_dimÚ	num_headsr#   Ú
is_decoderÚbiasÚ	is_causalÚ	layer_idxÚconfigc	                 óz  •— t         ‰	| �  «        || _        || _        || _        ||z  | _        || _        | j
                  |z  | j                  k7  rt        d| j                  › d|› d�«      ‚| j
                  dz  | _        || _	        || _
        |€/|r-t        j                  d| j                  j                  › d�«       || _        t!        j"                  ||d¬«      | _        t!        j"                  |||¬«      | _        t!        j"                  |||¬«      | _        t!        j"                  |||¬«      | _        y )	Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).r&   zInstantiating a decoder z³ without passing `layer_idx` is not recommended and will to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` when creating this class.F©r=   )ÚsuperÚ__init__r:   r;   r#   Úhead_dimr@   Ú
ValueErrorr"   r<   r>   ÚloggerÚwarning_onceÚ	__class__Ú__name__r?   r   ÚLinearÚk_projÚv_projÚq_projÚout_proj)
Úselfr:   r;   r#   r<   r=   r>   r?   r@   rI   s
            €r5   rD   zVoxtralAttention.__init__K   s   ø€ ô 	‰ÑÔØ"ˆŒØ"ˆŒØˆŒØ! YÑ.ˆŒØˆŒà�M‰M˜IÑ%¨$¯.©.Ò8ÜØMÈdÏnÉnÐM]Ø$ Y K¨rð3óð ð —}‘} dÑ*ˆŒØ$ˆŒØ"ˆŒàÐ¡Ü×ÑØ*¨4¯>©>×+BÑ+BÐ*Cð D,ð ,ôð
 #ˆŒä—i‘i 	¨9¸5ÔAˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜ—i‘i 	¨9¸4Ô@ˆŒÜŸ	™	 )¨Y¸TÔBˆ�r7   ÚtensorÚseq_lenÚbszc                 óŽ   — |j                  ||| j                  | j                  «      j                  dd«      j	                  «       S )Nr   r   )Úviewr;   rE   r.   r1   )rP   rQ   rR   rS   s       r5   Ú_shapezVoxtralAttention._shapes   s7   € Ø�{‰{˜3 ¨¯©¸¿¹ÓG×QÑQÐRSÐUVÓW×bÑbÓdÐdr7   Úhidden_statesr!   Úoutput_attentionsÚreturnc                 ó0  — |j                  «       \  }}}| j                  | j                  |«      | j                  z  ||«      }| j                  | j	                  |«      d|«      }	| j                  | j                  |«      d|«      }
t        j                  | j                  j                  t        «      } || ||	|
|f| j                  sdn| j                  d|dœ|¤Ž\  }}|j                  ||d«      j                  «       }| j                  |«      }||fS )z#Input shape: Batch x Time x Channelr%   ç        ç      ð?)r#   r"   rX   )r+   rV   rN   r"   rL   rM   r   Úget_interfacer@   Ú_attn_implementationr6   r*   r#   Úreshaper1   rO   )rP   rW   r!   rX   r2   rS   Útgt_lenÚ_Úquery_statesÚ
key_statesÚvalue_statesÚattention_interfacer4   r3   s                 r5   ÚforwardzVoxtralAttention.forwardv   s  € ð (×,Ñ,Ó.‰ˆˆW�að —{‘{ 4§;¡;¨}Ó#=ÀÇÁÑ#LÈgÐWZÓ[ˆØ—[‘[ §¡¨]Ó!;¸RÀÓEˆ
Ø—{‘{ 4§;¡;¨}Ó#=¸rÀ3ÓGˆä(?×(MÑ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØð
%
ð  $Ÿ}š}‘C°$·,±,ØØ/ñ
%
ð ñ
%
Ñ!ˆ�\ð "×)Ñ)¨#¨w¸Ó;×FÑFÓHˆØ—m‘m KÓ0ˆà˜LÐ(Ð(r7   )r[   FTFNN©NF)rJ   Ú
__module__Ú__qualname__Ú__doc__ÚintÚfloatÚboolr   rD   r,   ÚTensorrV   Útuplerf   Ú__classcell__©rI   s   @r5   r9   r9   H   s	  ø„ ÙGð Ø ØØØ $Ø'+ñ&Càð&Cð ð&Cð ð	&Cð
 ð&Cð ð&Cð ð&Cð ˜‘:ð&Cð  Ñ$õ&CðPe˜UŸ\™\ð e°Cð e¸có eð /3Ø"'ñ	')à—|‘|ð')ð Ÿ™ tÑ+ð')ð  ð	')ð 
ˆu�|‰|˜UŸ\™\¨DÑ0°%¸¿¹Ñ2EÈÑ2LÐLÑ	M÷')r7   r9   c                   ó~   ‡ — e Zd Zdefˆ fd„Zdej                  dej                  dee   dej                  fd„Z	ˆ xZ
S )ÚVoxtralEncoderLayerr@   c                 óh  •— t         ‰| �  «        |j                  | _        t	        | j                  |j
                  |j                  |¬«      | _        t        j                  | j                  «      | _
        |j                  | _        t        |j                     | _        |j                  | _        t        j                   | j                  |j"                  «      | _        t        j                   |j"                  | j                  «      | _        t        j                  | j                  «      | _        y )N)r:   r;   r#   r@   )rC   rD   Úd_modelr:   r9   Úencoder_attention_headsÚattention_dropoutÚ	self_attnr   Ú	LayerNormÚself_attn_layer_normr#   r   Úactivation_functionÚactivation_fnÚactivation_dropoutrK   Úencoder_ffn_dimÚfc1Úfc2Úfinal_layer_norm©rP   r@   rI   s     €r5   rD   zVoxtralEncoderLayer.__init__¡   sÑ   ø€ Ü‰ÑÔØŸ™ˆŒä)Ø—n‘nØ×4Ñ4Ø×,Ñ,Øô	
ˆŒô %'§L¡L°·±Ó$@ˆÔ!Ø—~‘~ˆŒÜ# F×$>Ñ$>Ñ?ˆÔØ"(×";Ñ";ˆÔÜ—9‘9˜TŸ^™^¨V×-CÑ-CÓDˆŒÜ—9‘9˜V×3Ñ3°T·^±^ÓDˆŒÜ "§¡¨T¯^©^Ó <ˆÕr7   rW   r!   r2   rY   c                 ó   — |}| j                  |«      } | j                  d||dœ|¤Ž\  }}t        j                  j	                  || j                  | j
                  ¬«      }||z   }|}| j                  |«      }| j                  | j                  |«      «      }t        j                  j	                  || j                  | j
                  ¬«      }| j                  |«      }t        j                  j	                  || j                  | j
                  ¬«      }||z   }|j                  t        j                  k(  rEt        j                  |j                  «      j                  dz
  }t        j                   || |¬«      }|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.
        )rW   r!   r(   iè  )ÚminÚmax© )rz   rx   r   r/   r#   r*   r�   r|   r   r}   r€   Údtyper,   Úfloat16Úfinfor…   Úclamp)rP   rW   r!   r2   Úresidualra   Úclamp_values          r5   rf   zVoxtralEncoderLayer.forward³   sT  € ð !ˆØ×1Ñ1°-Ó@ˆØ)˜4Ÿ>™>ð 
Ø'Ø)ñ
ð ñ
Ñˆ�qô
 Ÿ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆà ˆØ×-Ñ-¨mÓ<ˆØ×*Ñ*¨4¯8©8°MÓ+BÓCˆÜŸ™×-Ñ-¨m¸t×?VÑ?VÐae×anÑanÐ-ÓoˆØŸ™ Ó/ˆÜŸ™×-Ñ-¨m¸t¿|¹|ÐVZ×VcÑVcÐ-ÓdˆØ  =Ñ0ˆà×Ñ¤%§-¡-Ò/ÜŸ+™+ m×&9Ñ&9Ó:×>Ñ>ÀÑEˆKÜ!ŸK™K¨¸K¸<È[ÔYˆMàÐr7   )rJ   rh   ri   r   rD   r,   rn   r   r   rf   rp   rq   s   @r5   rs   rs       sL   ø„ ð=˜}õ =ð$"à—|‘|ð"ð Ÿ™ð"ð Ð+Ñ,ð	"ð
 
�‰÷"r7   rs   c                   óF   — e Zd ZU eed<   dZdZdZdZdgZ	dZ
dZdZdZdZdZy)ÚVoxtralPreTrainedModelr@   Úmodel)ÚaudioÚtextTNÚpast_key_values)rJ   rh   ri   r   Ú__annotations__Úbase_model_prefixÚinput_modalitiesÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_skip_keys_device_placementÚ_supports_flash_attnÚ_supports_sdpaÚ_supports_flex_attnÚ_supports_cache_classÚ_supports_attention_backendÚ_can_compile_fullgraphr†   r7   r5   rŽ   rŽ   Ø   sL   … àÓØÐØ(ÐØ&*Ð#ØÐØ#4Ð"5ÐØÐØ€NØÐØ ÐØ"&ÐØ!Ñr7   rŽ   z:
    The Voxtral encoder, which is a Whisper encoder.
    ©Úcustom_introc                   óæ   ‡ — e Zd ZU dZeed<   dZdZdgZe	e
dœZdefˆ fd„Zd„ Zd	ej                  fd
„Zdej                  fd„Zee	 ddee   d	eez  fd„«       «       Zdej4                  fd„Zˆ xZS )ÚVoxtralEncoderz·
    Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
    [`VoxtralEncoderLayer`].

    Args:
        config: VoxtralEncoderConfig
    r@   Úinput_featuresr�   rs   )Ú
attentionsrW   c                 ób  •— t         ‰| �  |«       |j                  | _        |j                  | _        |j
                  }|j                  | _        |j                  | _        |j                  rt        j                  |«      nd| _        t        j                  | j                  |dd¬«      | _        t        j                  ||ddd¬«      | _        t        j                   | j                  |«      | _        | j"                  j%                  d«       t        j&                  t)        |j*                  «      D �cg c]  }t-        |«      ‘Œ c}«      | _        t        j0                  |j
                  «      | _        t        j4                  dd¬«      | _        d| _        | j;                  «        y c c}w )	Nr\   r   r   )Úkernel_sizeÚpaddingr   )r¦   Ústrider§   F)r¨   )rC   rD   r#   Úencoder_layerdropÚ	layerdropru   Únum_mel_binsÚmax_source_positionsÚscale_embeddingÚmathÚsqrtÚembed_scaler   ÚConv1dÚconv1Úconv2Ú	EmbeddingÚembed_positionsÚrequires_grad_Ú
ModuleListÚrangeÚencoder_layersrs   Úlayersry   Ú
layer_normÚ	AvgPool1dÚ
avg_poolerÚgradient_checkpointingÚ	post_init)rP   r@   r:   ra   rI   s       €r5   rD   zVoxtralEncoder.__init__   s6  ø€ Ü‰Ñ˜Ô Ø—~‘~ˆŒØ×1Ñ1ˆŒà—N‘Nˆ	Ø"×/Ñ/ˆÔØ$*×$?Ñ$?ˆÔ!Ø39×3IÒ3Iœ4Ÿ9™9 YÔ/ÈsˆÔä—Y‘Y˜t×0Ñ0°)ÈÐTUÔVˆŒ
Ü—Y‘Y˜y¨)ÀÈ1ÐVWÔXˆŒ
ä!Ÿ|™|¨D×,EÑ,EÀyÓQˆÔØ×Ñ×+Ñ+¨EÔ2ä—m‘mÌ%ÐPV×PeÑPeÓJfÖ$gÀQÔ%8¸Õ%@Ò$gÓhˆŒÜŸ,™, v§~¡~Ó6ˆŒäŸ,™, q°Ô3ˆŒà&+ˆÔ#à�‰Õùò %hs   Ä6F,c                 óJ   — | j                  «       D ]	  }d|_        Œ d| _        y rg   )Ú
parametersÚrequires_gradÚ_requires_grad)rP   Úparams     r5   Ú_freeze_parametersz!VoxtralEncoder._freeze_parameters  s(   € Ø—_‘_Ó&ò 	(ˆEØ"'ˆEÕð	(à#ˆÕr7   rY   c                 ó   — | j                   S ©N©r²   )rP   s    r5   Úget_input_embeddingsz#VoxtralEncoder.get_input_embeddings  s   € Ø�z‰zÐr7   r    c                 ó   — || _         y rÇ   rÈ   )rP   r    s     r5   Úset_input_embeddingsz#VoxtralEncoder.set_input_embeddings!  s	   € Øˆ�
r7   r2   c           	      óÖ  — | j                   j                  | j                  j                  d   z  | j                  j                  d   z  }|j
                  d   |k7  r"t        d|› d|j
                  d   › d|› d�«      ‚|j                  | j                  j                  j                  | j                  j                  j                  ¬«      }t        j                  j                  | j                  |«      «      }t        j                  j                  | j	                  |«      «      }|j                  ddd	«      }| j                  j                  }||z   j                  |j                  «      }t        j                  j!                  || j                   | j"                  ¬
«      }t%        | j&                  «      D ]  \  }}	 |	||¬«      }Œ | j)                  |«      }t+        |¬«      S )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.
        r   r%   z7Voxtral expects the mel input features to be of length z, but found z-. Make sure to pad the input mel features to ú.©r‡   Údevicer   r   r(   )r!   )Úlast_hidden_state)r@   r¬   r²   r¨   r³   ÚshaperF   ÚtoÚweightr‡   rÏ   r   r/   ÚgeluÚpermuterµ   r#   r*   Ú	enumeraterº   r»   r   )
rP   r£   r!   r2   Úexpected_seq_lengthÚinputs_embedsÚ	embed_posrW   ÚidxÚencoder_layers
             r5   rf   zVoxtralEncoder.forward$  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¸t¿|¹|ÐVZ×VcÑVcÐ-Ódˆä"+¨D¯K©KÓ"8ò 	ÑˆC�Ù)ØØ-ô‰Mð	ð Ÿ™¨Ó6ˆä)Ø+ô
ð 	
r7   Úinput_lengthsc                 ó6   — |dz
  dz  dz   }|dz
  dz  dz   }||fS )zs
        Computes the output length of the convolutional layers and the output length of the audio encoder
        r   r   r†   )rP   rÜ   Úoutput_lengthss      r5   Ú _get_feat_extract_output_lengthsz/VoxtralEncoder._get_feat_extract_output_lengthsT  s7   € ð '¨Ñ*¨qÑ0°1Ñ4ˆØ'¨!Ñ+°Ñ1°AÑ5ˆØ˜nÐ,Ð,r7   rÇ   )rJ   rh   ri   rj   r   r“   Úmain_input_namer•   r—   r9   rs   Ú_can_record_outputsrD   rÅ   r   ÚModulerÉ   rË   r   r   r   r   ro   r   rf   r,   Ú
LongTensorrß   rp   rq   s   @r5   r¢   r¢   è   s¸   ø… ñð !Ó Ø&€OØÐØ.Ð/Ðà&Ø,ñÐð
Ð3õ ò2$ð
 b§i¡ió ð¨"¯)©)ó ð  Øð ñ+
ð Ð+Ñ,ð	+
ð
 
Ð+Ñ	+ò+
ó ó  ð+
ð\-¸e×>NÑ>N÷ -r7   r¢   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )ÚVoxtralMultiModalProjectorr@   c                 óf  •— t         ‰| �  «        t        j                  |j                  j
                  |j                  j                  d¬«      | _        t        |j                     | _        t        j                  |j                  j                  |j                  j                  d¬«      | _        y ©NFrB   )rC   rD   r   rK   Úaudio_configÚintermediate_sizeÚtext_configÚhidden_sizeÚlinear_1r   Úprojector_hidden_actÚactÚlinear_2r‚   s     €r5   rD   z#VoxtralMultiModalProjector.__init__^  sz   ø€ Ü‰ÑÔÜŸ	™	 &×"5Ñ"5×"GÑ"GÈ×I[ÑI[×IgÑIgÐnsÔtˆŒÜ˜&×5Ñ5Ñ6ˆŒÜŸ	™	 &×"4Ñ"4×"@Ñ"@À&×BTÑBT×B`ÑB`ÐglÔmˆ�r7   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S rÇ   )rì   rî   rï   )rP   Úaudio_featuresrW   s      r5   rf   z"VoxtralMultiModalProjector.forwardd  s2   € ØŸ™ nÓ5ˆØŸ™ Ó/ˆØŸ™ mÓ4ˆØÐr7   )rJ   rh   ri   r   rD   rf   rp   rq   s   @r5   rå   rå   ]  s   ø„ ðn˜}õ nör7   rå   zL
    Base class for Voxtral outputs, with hidden states and attentions.
    c                   ó:   — e Zd ZU dZdZej                  dz  ed<   y)ÚVoxtralModelOutputWithPastzg
    audio_hidden_states (`torch.FloatTensor`, *optional*):
        Projected audio hidden states.
    NÚaudio_hidden_states)rJ   rh   ri   rj   rô   r,   ÚFloatTensorr“   r†   r7   r5   ró   ró   k  s   … ñð
 59Ð˜×*Ñ*¨TÑ1Ô8r7   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                   ó®  ‡ — e Zd Zˆ fd„Ze ed¬«      dej                  dee	   de
ez  fd„«       «       Zdej                  d	ej                  d
ej                  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dz  d	ej                  dz  dedz  dee	   de
ez  fd„«       «       Zˆ xZS )ÚVoxtralModelc                 óô   •— t         ‰| �  |«       t        j                  |j                  «      | _        t        j                  |j                  «      | _        t        |«      | _	        | j                  «        y rÇ   )rC   rD   r   Úfrom_configrè   Úaudio_towerrê   Úlanguage_modelrå   Úmulti_modal_projectorr¿   r‚   s     €r5   rD   zVoxtralModel.__init__�  sY   ø€ Ü‰Ñ˜Ô Ü$×0Ñ0°×1DÑ1DÓEˆÔÜ'×3Ñ3°F×4FÑ4FÓGˆÔÜ%?ÀÓ%GˆÔ"Ø�‰Õr7   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Ÿ   r£   r2   rY   c                 óØ   —  | j                   |fddi|¤Ž}|j                  }|j                  d| j                  j                  j
                  «      }| j                  |«      }||_        |S )aa  
        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_dictTr%   )rú   rÐ   r_   r@   rè   ré   rü   Úpooler_output)rP   r£   r2   Úaudio_outputsrô   Úaudio_embedss         r5   Úget_audio_featureszVoxtralModel.get_audio_featuresˆ  sn   € ð )˜×(Ñ(¨ÑTÀTÐTÈVÑTˆØ+×=Ñ=ÐØ1×9Ñ9¸"¸d¿k¹k×>VÑ>V×>hÑ>hÓiÐØ×1Ñ1Ð2EÓFˆØ&2ˆÔ#àÐr7   Ú	input_idsrØ   rñ   c                 ó.  — |€m| | j                  «       t        j                  | j                  j                  t        j
                  |j                  ¬«      «      k(  }|j                  d«      }n|| j                  j                  k(  }|j                  «       }|j                  d   }|j                  d«      j                  |«      j                  |j                  «      }t        ||   j                  «       |j                  «       k(  d|› d|› �«       |S )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Î   r%   r   z6Audio features and audio tokens do not match, tokens: z, features: )rÉ   r,   rQ   r@   Úaudio_token_idÚlongrÏ   ÚallÚsumrÑ   Ú	unsqueezeÚ	expand_asrÒ   r   Únumel)rP   r  rØ   rñ   Úspecial_audio_maskÚn_audio_tokensÚn_audio_featuress          r5   Úget_placeholder_maskz!VoxtralModel.get_placeholder_maskŸ  s  € ð ÐØ!.Ð2M°$×2KÑ2KÓ2MÜ—‘˜TŸ[™[×7Ñ7¼u¿z¹zÐR_×RfÑRfÔgó3ñ "Ðð "4×!7Ñ!7¸Ó!;Ñà!*¨d¯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ô	
ð "Ð!r7   Nr!   Úposition_idsr’   Ú	use_cachec           	      ó–  — |€ | j                  «       |«      }d }	|�^|�\| j                  |d¬«      j                  }	| j                  |||	¬«      }
|j	                  |
|	j                  |j                  «      «      } | j                  d|||||dœ|¤Ž}t        |j                  |j                  |j                  |j                  |	¬«      S )NT)rþ   )rØ   rñ   )r!   r  r’   rØ   r  )rÐ   r’   rW   r¤   rô   r†   )rÉ   r  rÿ   r  Úmasked_scatterrÒ   rÏ   rû   ró   rÐ   r’   rW   r¤   )rP   r  r£   r!   r  r’   rØ   r  r2   r  r  Úoutputss               r5   rf   zVoxtralModel.forward·  sô   € ð Ð Ø7˜D×5Ñ5Ó7¸	ÓBˆMàˆØÐ%¨)Ð*?Ø×2Ñ2°>ÈtÐ2ÓT×bÑbˆLð "&×!:Ñ!:Ø¨À|ð ";ó "Ðð *×8Ñ8Ð9KÈ\Ï_É_Ð]j×]qÑ]qÓMrÓsˆMà+>¨4×+>Ñ+>ð ,
Ø)Ø%Ø+Ø'Øñ,
ð ñ,
ˆô *Ø%×7Ñ7Ø#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø ,ô
ð 	
r7   )NNNNNNN)rJ   rh   ri   rD   r   r   r,   rõ   r   r   ro   r   r  rã   r  rn   r   rm   ró   rf   rp   rq   s   @r5   r÷   r÷   z  s\  ø„ ôð Ùð wôðØ#×/Ñ/ðØ;AÐBTÑ;Uðà	Ð+Ñ	+òóó ðð&"Ø×)Ñ)ð"Ø:?×:KÑ:Kð"Ø]b×]nÑ]nó"ð0 Øð .2Ø37Ø.2Ø04Ø(,Ø26Ø!%ñ'
à×#Ñ# dÑ*ð'
ð ×)Ñ)¨DÑ0ð'
ð Ÿ™ tÑ+ð	'
ð
 ×&Ñ&¨Ñ-ð'
ð  ™ð'
ð ×(Ñ(¨4Ñ/ð'
ð ˜$‘;ð'
ð Ð+Ñ,ð'
ð 
Ð+Ñ	+ò'
ó ó ô'
r7   r÷   zs
    The Voxtral model, which consists of Whisper encoder, a multi-modal projector and a Llama language model.
    c                   ó^  ‡ — e Zd ZdgZˆ fd„Z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dz  d
ej                  dz  dej                  dz  dedz  deej                  z  dee   deez  fd„«       «       Zˆ fd„Zˆ xZS )ÚVoxtralForConditionalGenerationrµ   c                 óî   •— t         ‰| �  |«       t        |«      | _        t	        j
                  |j                  j                  |j                  j                  d¬«      | _	        | j                  «        y rç   )rC   rD   r÷   r�   r   rK   rê   rë   Ú
vocab_sizeÚlm_headr¿   r‚   s     €r5   rD   z(VoxtralForConditionalGeneration.__init__ë  sS   ø€ Ü‰Ñ˜Ô Ü! &Ó)ˆŒ
Ü—y‘y ×!3Ñ!3×!?Ñ!?À×ASÑAS×A^ÑA^ÐejÔkˆŒØ�‰Õr7   c                 ó:   —  | j                   j                  |i |¤ŽS rÇ   )r�   r  )rP   Úargsr2   s      r5   r  z2VoxtralForConditionalGeneration.get_audio_featuresñ  s   € Ø,ˆt�z‰z×,Ñ,¨dÐ=°fÑ=Ð=r7   Nr  r£   r!   r  r’   rØ   Úlabelsr  Úlogits_to_keepr2   rY   c
                 óŽ  —  | j                   d|||||||dœ|
¤Ž}|j                  }t        |	t        «      rt	        |	 d«      n|	}| j                  |dd…|dd…f   «      }d}|�4 | j                  d||| j                  j                  j                  dœ|
¤Ž}t        |||j                  |j                  |j                  ¬«      S )aj  
        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  r£   r!   r  r’   rØ   r  N)Úlogitsr  r  )Úlossr  r’   rW   r¤   r†   )r�   rÐ   Ú
isinstancerk   Úslicer  Úloss_functionr@   rê   r  r   r’   rW   r¤   )rP   r  r£   r!   r  r’   rØ   r  r  r  r2   r  rW   Úslice_indicesr  r   s                   r5   rf   z'VoxtralForConditionalGeneration.forwardô  sì   € ð` �$—*‘*ð 	
ØØ)Ø)Ø%Ø+Ø'Øñ	
ð ñ	
ˆð  ×1Ñ1ˆÜ8BÀ>ÔSVÔ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜mªA¨}ºaÐ,?Ñ@ÓAˆàˆØÐØ%�4×%Ñ%ð Ø f¸¿¹×9PÑ9P×9[Ñ9[ñØ_eñˆDô &ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r7   c                 ó    •— |j                  dd «      }|j                  dd«      }t        ‰| �  |i |¤Ž}|s|j                  dd«      s||d<   |S )Nr£   Úis_first_iterationFr  T)ÚpopÚgetrC   Úprepare_inputs_for_generation)rP   r  r2   r£   r&  Úmodel_inputsrI   s         €r5   r)  z=VoxtralForConditionalGeneration.prepare_inputs_for_generationA  s]   ø€ ð  Ÿ™Ð$4°dÓ;ˆØ#ŸZ™ZÐ(<¸eÓDÐä‘wÑ<¸dÐMÀfÑMˆá V§Z¡Z°¸TÔ%Bà-;ˆLÐ)Ñ*àÐr7   )	NNNNNNNNr   )rJ   rh   ri   Ú_keep_in_fp32_modules_strictrD   r  r   r   r,   rã   rõ   rn   r   rm   rk   r   r   ro   r   rf   r)  rp   rq   s   @r5   r  r  ã  s2  ø„ ð %6Ð#6Ð ôò>ð Øð .2Ø37Ø.2Ø04Ø(,Ø26Ø*.Ø!%Ø-.ñI
à×#Ñ# dÑ*ðI
ð ×)Ñ)¨DÑ0ðI
ð Ÿ™ tÑ+ð	I
ð
 ×&Ñ&¨Ñ-ðI
ð  ™ðI
ð ×(Ñ(¨4Ñ/ðI
ð × Ñ  4Ñ'ðI
ð ˜$‘;ðI
ð ˜eŸl™lÑ*ðI
ð Ð+Ñ,ðI
ð 
Ð'Ñ	'òI
ó ó ðI
÷Vð r7   r  )rŽ   r¢   r÷   r  )Nr[   )7r®   Úcollections.abcr   Údataclassesr   r,   r   Úactivationsr   Úcache_utilsr   Ú
generationr	   Úmodeling_layersr
   Úmodeling_outputsr   r   r   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r   r   r   r   Úutils.genericr   Úutils.output_capturingr   Úautor   Úconfiguration_voxtralr   r   Ú
get_loggerrJ   rG   râ   rn   rl   r6   r9   rs   rŽ   r¢   rå   ró   r÷   r  Ú__all__r†   r7   r5   ú<module>r<     sÄ  ðó, Ý $Ý !ã Ý å !Ý  Ý )Ý 9ß kÑ kß FÝ &ß jÕ jÝ 7Ý 5Ý ß Fð 
ˆ×	Ñ	˜HÓ	%€ð !Øñ%Ø�I‰Ið%à�<‰<ð%ð 
�‰ð%ð �<‰<ð	%ð
 —L‘L 4Ñ'ð%ð �T‰\ð%ð ó%ô4U)�r—y‘yô U)ôp5Ð4ô 5ðp ô"˜_ó "ó ð"ñ ðôô
m-Ð+ó m-óð
m-ô` §¡ô ñ ðôð
 ô9Ð!8ó 9ó óð9ñ ðôô`
Ð)ó `
óð`
ñF ðôô
eÐ&<¸oó eóð
eòP j�r7   