
    Z j                        S SK r S SKrS SKJr  S SKrS SKrS SKJr  S SKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJrJrJrJrJrJr  SSK J!r!J"r"  SSK#J$r$  SSK%J&r&J'r'J(r(  SSK)J*r*   " S S\5      r+ " S S\RX                  5      r- " S S\RX                  5      r. " S S\RX                  5      r/ " S S\RX                  5      r0 " S S\RX                  5      r1  SPS\RX                  S \Rd                  S!\Rd                  S"\Rd                  S#\Rd                  S-  S$\3S-  S%\3S&\$\&   4S' jjr4 " S( S)\RX                  5      r5 " S* S+\RX                  5      r6 " S, S-\5      r7 " S. S/\RX                  5      r8 " S0 S1\RX                  5      r9 " S2 S3\RX                  5      r:\' " S4 S5\"5      5       r;  SQS6\<\=\=4   S7\3S8\=S#\R|                  S-  S9\=S:\R~                  4S; jjr@\rA\' " S< S=\;5      5       rBS>rC\'" S?S@9 " SA SB\;5      5       rD\'" SCS@9 " SD SE\;5      5       rE\' " SF SG\;5      5       rF " SH SI\RX                  5      rG " SJ SK\RX                  5      rH\'" SLS@9 " SM SN\;5      5       rI/ SOQrJg)R    N)Callable)nn)CrossEntropyLoss   )initialization)ACT2FN)is_deepspeed_zero3_enabled)is_fsdp_managed_module)create_bidirectional_mask)FlashAttentionKwargs)GradientCheckpointingLayer)BaseModelOutputCausalLMOutputSequenceClassifierOutputTokenClassifierOutputWav2Vec2BaseModelOutputXVectorOutput)ALL_ATTENTION_FUNCTIONSPreTrainedModel)Unpack)TransformersKwargsauto_docstringis_peft_available   )Data2VecAudioConfigc                   2   ^  \ rS rSrSU 4S jjrS rSrU =r$ )Data2VecAudioConvLayer3   c                   > [         TU ]  5         US:  a  UR                  US-
     OSU l        UR                  U   U l        [
        R                  " U R                  U R                  UR                  U   UR                  U   UR                  S9U l
        [
        R                  " U R                  SS9U l        [        UR                     U l        g )Nr   r   )kernel_sizestridebiasTelementwise_affine)super__init__conv_dimin_conv_dimout_conv_dimr   Conv1dconv_kernelconv_stride	conv_biasconv	LayerNorm
layer_normr   feat_extract_activation
activationselfconfiglayer_id	__class__s      څ/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/data2vec/modeling_data2vec_audio.pyr&   Data2VecAudioConvLayer.__init__4   s    <DqL6??8a<8a"OOH5II**84%%h/!!
	 ,,t'8'8TR !?!?@    c                     U R                  U5      nUR                  SS5      nU R                  U5      nUR                  SS5      nU R                  U5      nU$ )N)r.   	transposer0   r2   r4   hidden_statess     r8   forwardData2VecAudioConvLayer.forwardC   sV    		-0%//B76%//B76r:   )r2   r.   r(   r0   r)   r   __name__
__module____qualname____firstlineno__r&   rA   __static_attributes____classcell__r7   s   @r8   r   r   3   s    A r:   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )Data2VecAudioPadLayerN   c                 R   > [         TU ]  5         US-  S:X  a  SU l        g SU l        g )N   r   r   )r%   r&   num_pad_remove)r4   num_conv_pos_embeddingsr7   s     r8   r&   Data2VecAudioPadLayer.__init__O   s)    #:Q#>!#Car:   c                 X    U R                   S:  a  US S 2S S 2S U R                   * 24   nU$ Nr   rQ   r?   s     r8   rA   Data2VecAudioPadLayer.forwardS   s6    ")!Q0F43F3F2F0F*FGMr:   rV   rD   rK   s   @r8   rM   rM   N   s    K r:   rM   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ ) Data2VecAudioPositionalConvLayerY   c                 r  > [         TU ]  5         [        R                  " UR                  UR                  UR
                  UR
                  S-  UR                  S9U l        [        UR
                  5      U l	        [        UR                     U l        [        R                  " UR                  SS9U l        g )NrP   )r    paddinggroupsFr#   )r%   r&   r   r*   hidden_sizeconv_pos_kernel_sizenum_conv_pos_embedding_groupsr.   rM   r\   r   r1   r2   r/   r0   r4   r5   r7   s     r8   r&   )Data2VecAudioPositionalConvLayer.__init__Z   s    II33//1477
	 -V-H-HI !?!?@,,v'9'9eTr:   c                     U R                  U5      nU R                  U5      nUR                  SS5      nU R                  U5      nUR                  SS5      nU R	                  U5      nU$ Nr   rP   )r.   r\   r>   r0   r2   r?   s     r8   rA   (Data2VecAudioPositionalConvLayer.forwardi   sd    		-0]3%//156%//156r:   )r2   r.   r0   r\   rD   rK   s   @r8   rY   rY   Y   s    U r:   rY   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )$Data2VecAudioPositionalConvEmbeddingt   c                    > [         TU ]  5         [        R                  " [	        UR
                  5       Vs/ s H  n[        U5      PM     sn5      U l        g s  snf N)r%   r&   r   
ModuleListrangerR   rY   layersr4   r5   _r7   s      r8   r&   -Data2VecAudioPositionalConvEmbedding.__init__u   sF    mm?DVEcEc?de?d!-f5?de
es   Ac                     UR                  SS5      nU R                   H  nU" U5      nM     UR                  SS5      nU$ rd   )r>   rm   )r4   r@   layers      r8   rA   ,Data2VecAudioPositionalConvEmbedding.forward{   sD    %//15[[E!-0M !%//15r:   )rm   rD   rK   s   @r8   rg   rg   t   s    
 r:   rg   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )Data2VecAudioFeatureEncoder   z.Construct the features from raw audio waveformc           
         > [         TU ]  5         [        R                  " [	        UR
                  5       Vs/ s H  n[        XS9PM     sn5      U l        SU l        SU l	        g s  snf )N)r6   FT)
r%   r&   r   rk   rl   num_feat_extract_layersr   conv_layersgradient_checkpointing_requires_grad)r4   r5   ir7   s      r8   r&   $Data2VecAudioFeatureEncoder.__init__   s\    ==AFvGeGeAfgAfA#F7Afg
 ',#" hs   A%c                 N    U R                  5        H
  nSUl        M     SU l        g NF)
parametersrequires_gradr{   r4   params     r8   _freeze_parameters.Data2VecAudioFeatureEncoder._freeze_parameters   s#    __&E"'E '#r:   c                     US S 2S 4   nU R                   (       a  U R                  (       a  SUl        U R                   H  nU" U5      nM     U$ )NT)r{   trainingr   ry   )r4   input_valuesr@   
conv_layers       r8   rA   #Data2VecAudioFeatureEncoder.forward   sK    $QW- 4==*.M'**J&}5M + r:   )r{   ry   rz   )
rE   rF   rG   rH   __doc__r&   r   rA   rI   rJ   rK   s   @r8   ru   ru      s    8#$

 
r:   ru   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )Data2VecAudioFeatureProjection   c                 4  > [         TU ]  5         [        R                  " UR                  S   UR
                  S9U l        [        R                  " UR                  S   UR                  5      U l	        [        R                  " UR                  5      U l        g )Nr=   eps)r%   r&   r   r/   r'   layer_norm_epsr0   Linearr^   
projectionDropoutfeat_proj_dropoutdropoutra   s     r8   r&   'Data2VecAudioFeatureProjection.__init__   sf    ,,vr':@U@UV))FOOB$79K9KLzz&":":;r:   c                 n    U R                  U5      nU R                  U5      nU R                  U5      nX4$ rj   )r0   r   r   )r4   r@   norm_hidden_statess      r8   rA   &Data2VecAudioFeatureProjection.forward   s7    !__];(:;]300r:   )r   r0   r   rD   rK   s   @r8   r   r      s    <1 1r:   r   modulequerykeyvalueattention_maskscalingr   kwargsc                    Uc  UR                  S5      S-  n[        R                  " XR                  SS5      5      U-  nUb  X-   n[        R
                  R                  USS9n[        R
                  R                  XU R                  S9n[        R                  " X5      n	U	R                  SS5      R                  5       n	X4$ )Nr=         rP   r   dim)pr   r   )
sizetorchmatmulr>   r   
functionalsoftmaxr   r   
contiguous)
r   r   r   r   r   r   r   r   attn_weightsattn_outputs
             r8   eager_attention_forwardr      s     **R.D( <<}}Q':;gEL!#4==((2(>L==((6??([L,,|3K''1-88:K$$r:   c                   :  ^  \ rS rSrSr     SS\S\S\S\S\S	\S
\S-  4U 4S jjjr	   SS\
R                  S\
R                  S-  S\
R                  S-  S\S-  S\\   S\\
R                  \
R                  S-  \\
R                     S-  4   4S jjrSrU =r$ )Data2VecAudioAttention   z=Multi-headed attention from 'Attention Is All You Need' paperN	embed_dim	num_headsr   
is_decoderr"   	is_causalr5   c                   > [         TU ]  5         Xl        X l        X0l        X-  U l        Xpl        U R
                  U-  U R                  :w  a  [        SU R                   SU S35      eU R
                  S-  U l        X@l	        X`l
        [        R                  " XUS9U l        [        R                  " XUS9U l        [        R                  " XUS9U l        [        R                  " XUS9U l        g )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).r   )r"   )r%   r&   r   r   r   head_dimr5   
ValueErrorr   r   r   r   r   k_projv_projq_projout_proj)	r4   r   r   r   r   r"   r   r5   r7   s	           r8   r&   Data2VecAudioAttention.__init__   s     	""!.MMI%$..8MdnnM]$YKr3  }}d*$"ii	4@ii	4@ii	4@		)TBr:   r@   key_value_statesr   output_attentionsr   returnc                    USLnUR                   SS n/ UQSPU R                  P7nU R                  U5      R                  U5      R	                  SS5      n	U(       a  UOUn
/ U
R                   SS QSPU R                  P7nU R                  U
5      R                  U5      R	                  SS5      nU R                  U
5      R                  U5      R	                  SS5      n[        R                  " U R                  R                  [        5      nU" U U	UUU4U R                  (       d  SOU R                  U R                  US.UD6u  nnUR                  " / UQSP76 R!                  5       nU R#                  U5      nUUS4$ )z#Input shape: Batch x Time x ChannelNr=   r   rP           )r   r   r   )shaper   r   viewr>   r   r   r   get_interfacer5   _attn_implementationr   r   r   r   reshaper   r   )r4   r@   r   r   r   r   is_cross_attentioninput_shapehidden_shapequery_statescurrent_stateskv_shape
key_statesvalue_statesattention_interfacer   r   s                    r8   rA   Data2VecAudioAttention.forward   s    .T9 $))#2.88b8$--8 {{=166|DNNqRST-?)]B^))#2.BBDMMB[[055h?II!QO
{{>277AKKAqQ(?(M(MKK,,.E)
 %8
%
  $}}C$,,LL/
%
 
%
!\ "));;;;FFHmmK0L$..r:   )r5   r   r   r   r   r   r   r   r   r   r   r   )r   FTFN)NNF)rE   rF   rG   rH   r   intfloatboolr   r&   r   Tensorr   r   tuplerA   rI   rJ   rK   s   @r8   r   r      s
   G  -1CC C 	C
 C C C $d*C CD 15.2).0/||0/  ,,-0/ t+	0/
  $;0/ -.0/ 
u||U\\D0%2E2LL	M0/ 0/r:   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )Data2VecAudioFeedForwardi   c                   > [         TU ]  5         [        R                  " UR                  5      U l        [        R                  " UR                  UR                  5      U l	        [        UR                  [        5      (       a  [        UR                     U l        OUR                  U l        [        R                  " UR                  UR                  5      U l        [        R                  " UR                   5      U l        g rj   )r%   r&   r   r   activation_dropoutintermediate_dropoutr   r^   intermediate_sizeintermediate_dense
isinstance
hidden_actstrr   intermediate_act_fnoutput_densehidden_dropoutoutput_dropoutra   s     r8   r&   !Data2VecAudioFeedForward.__init__!  s    $&JJv/H/H$I!"$))F,>,>@X@X"Yf''--'-f.?.?'@D$'-'8'8D$IIf&>&>@R@RS jj)>)>?r:   c                     U R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU R	                  U5      nU$ rj   )r   r   r   r   r   r?   s     r8   rA    Data2VecAudioFeedForward.forward.  sX    //>00?11-@))-8++M:r:   )r   r   r   r   r   rD   rK   s   @r8   r   r      s    @ r:   r   c                   2   ^  \ rS rSrU 4S jrSS jrSrU =r$ )Data2VecAudioEncoderLayeri8  c                   > [         TU ]  5         [        UR                  UR                  UR
                  SUS9U l        [        R                  " UR                  5      U l
        [        R                  " UR                  UR                  S9U l        [        U5      U l        [        R                  " UR                  UR                  S9U l        g )NF)r   r   r   r   r5   r   )r%   r&   r   r^   num_attention_headsattention_dropout	attentionr   r   r   r   r/   r   r0   r   feed_forwardfinal_layer_normra   s     r8   r&   "Data2VecAudioEncoderLayer.__init__9  s    /((00,,
 zz&"7"78,,v'9'9v?T?TU4V< "V-?-?VEZEZ [r:   c                     UnU R                  XUS9u  pnU R                  U5      nXA-   nU R                  U5      nXR                  U5      -   nU R	                  U5      nU4nU(       a  Xu4-  nU$ )Nr   r   )r   r   r0   r   r   )r4   r@   r   r   attn_residualr   ro   outputss           r8   rA   !Data2VecAudioEncoderLayer.forwardH  s    %)-L] *8 *
&Q ]3%56%(9(9-(HH--m< "&Gr:   )r   r   r   r   r0   r   rD   rK   s   @r8   r   r   8  s    \ r:   r   c                      ^  \ rS rSrU 4S jr    SS\R                  S\R                  S-  S\S\S\4
S	 jjr	S
r
U =r$ )Data2VecAudioEncoderi\  c                   > [         TU ]  5         Xl        [        U5      U l        [
        R                  " UR                  UR                  S9U l	        [
        R                  " UR                  5      U l        [
        R                  " [        UR                  5       Vs/ s H  n[!        U5      PM     sn5      U l        SU l        g s  snf )Nr   F)r%   r&   r5   rg   pos_conv_embedr   r/   r^   r   r0   r   r   r   rk   rl   num_hidden_layersr   rm   rz   rn   s      r8   r&   Data2VecAudioEncoder.__init__]  s    B6J,,v'9'9v?T?TUzz&"7"78mmPUV\VnVnPo$pPo1%>v%FPo$pq&+# %qs    C	Nr@   r   r   output_hidden_statesreturn_dictc                 ,   U(       a  SOS nU(       a  SOS nUb4  UR                  S5      R                  SSUR                  S   5      nSX) '   [        U R                  UUS9nU R                  U5      n	XR                  UR                  5      -   nU R                  U5      nU R                  U5      n[        5       =(       d    [        U 5      n
U R                   H  nU(       a  Xa4-   n[        R                  " / 5      nU R                  =(       a    XR                  R                   :  nU(       a  U
(       a  U" XUS9nUS   nU(       a  SnU(       d  M|  UWS   4-   nM     U(       a  Xa4-   nU(       d  [#        S	 XU4 5       5      $ [%        UUUS
9$ )N r=   r   rP   r   )r5   inputs_embedsr   r   NNc              3   .   #    U  H  oc  M  Uv   M     g 7frj   r  ).0vs     r8   	<genexpr>/Data2VecAudioEncoder.forward.<locals>.<genexpr>  s     m$[q$[s   	)last_hidden_stater@   
attentions)	unsqueezerepeatr   r   r5   r   todevicer0   r   r	   r
   rm   r   randr   	layerdropr   r   )r4   r@   r   r   r   r   all_hidden_statesall_self_attentionsexpand_attention_maskposition_embeddingssynced_gpusrr   dropout_probabilityskip_the_layerlayer_outputss                  r8   rA   Data2VecAudioEncoder.forwardf  s    #7BD$5b4%$2$<$<R$@$G$G1mNaNabcNd$e!45M012;;')
 #11-@%(>(>}?S?S(TT6]302R6LT6R[[E#$58H$H! #(**R.!]]Z/B[[EZEZ/ZN![ %!Te! !.a 0 ,  &9]1=M<O&O#' !*   14D Dm]GZ$[mmm++*
 	
r:   )r5   r   rz   r0   rm   r   )NFFT)rE   rF   rG   rH   r&   r   tensorr   r   rA   rI   rJ   rK   s   @r8   r   r   \  s]    , /3"'%* ;
||;
 t+;
  	;

 #;
 ;
 ;
r:   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )Data2VecAudioAdapterLayeri  c                    > [         TU ]  5         [        R                  " UR                  SUR                  -  UR
                  UR                  SS9U l        g )NrP   r   )r!   r\   )r%   r&   r   r*   output_hidden_sizeadapter_kernel_sizeadapter_strider.   ra   s     r8   r&   "Data2VecAudioAdapterLayer.__init__  sJ    II%%)))&&((
	r:   c                 d    U R                  U5      n[        R                  R                  USS9nU$ )Nr   r   )r.   r   r   glur?   s     r8   rA   !Data2VecAudioAdapterLayer.forward  s/    		-0))-Q)?r:   )r.   rD   rK   s   @r8   r  r    s    
 r:   r  c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )Data2VecAudioAdapteri  c                   >^ [         TU ]  5         TR                  TR                  :w  aV  [        R
                  " TR                  TR                  5      U l        [        R                  " TR                  5      U l        OS =U l        U l        [        R                  " U4S j[        TR                  5       5       5      U l        TR                  U l        g )Nc              3   :   >#    U  H  n[        T5      v   M     g 7frj   )r  )r  ro   r5   s     r8   r  0Data2VecAudioAdapter.__init__.<locals>.<genexpr>  s     #pOo!$=f$E$EOos   )r%   r&   r  r^   r   r   projr/   proj_layer_normrk   rl   num_adapter_layersrm   r  ra   s    `r8   r&   Data2VecAudioAdapter.__init__  s     $$(:(::		&"4"4f6O6OPDI#%<<0I0I#JD /33DI,mm#puU[UnUnOo#pp))r:   c                 |   U R                   b/  U R                  b"  U R                  U5      nU R                  U5      nUR                  SS5      nU R                   HK  n[        R
                  R                  5       nU R                  (       a  X0R                  :  d  MC  U" U5      nMM     UR                  SS5      nU$ rd   )r*  r+  r>   rm   nprandomr   r  )r4   r@   rr   layerdrop_probs       r8   rA   Data2VecAudioAdapter.forward  s    99 T%9%9%E IIm4M 00?M%//15[[EYY--/N==^nn%D %m 4 !
 &//15r:   )r  rm   r*  r+  rD   rK   s   @r8   r&  r&    s    * r:   r&  c                       \ rS rSr% \\S'   SrSrSrSr	Sr
SrSr\R                  " 5       S 5       rSS	\R                   \-  S
\S-  4S jjr SS\S\R                   4S jjrSrg)Data2VecAudioPreTrainedModeli  r5   data2vec_audior   audioTc                 *   [        U[        5      (       a  [        R                  " SUR                  R
                  -  5      n[        R                  " UR                  R                  U* US9  [        R                  " UR                  R                  U* US9  g[        U[        5      (       a,  [        R                  " UR                  R                  S5        g[        U[        R                  5      (       ac  [        R                  " UR                  SU R                   R"                  S9  UR                  b!  [        R$                  " UR                  5        gg[        U[        R&                  [        R(                  45      (       a\  UR                  b   [        R$                  " UR                  5        UR                  b!  [        R*                  " UR                  5        gg[        U[        R,                  5      (       a  [        R.                  " UR                  5        UR                  b_  [        R                  " UR0                  UR2                  UR4                  S   -  -  5      n[        R                  " UR                  U* US9  ggg)zInitialize the weightsr   )abr   r   )meanstdN)r   r   mathsqrtr   in_featuresinituniform_weightr"   rY   	constant_r.   r   r   normal_r5   initializer_rangezeros_r/   	GroupNormones_r*   kaiming_normal_r]   in_channelsr    )r4   r   ks      r8   _init_weights*Data2VecAudioPreTrainedModel._init_weights  s    f<==		!f//;;;<AMM&++22qbA>MM&++00QB!< @AANN6;;++Q/		**LLSdkk6S6ST{{&FKK( 'r|| <=={{&FKK(}}(

6==) )		**  /{{&IIfmmv/A/AFDVDVWXDY/YZ[fkkaR15 ' +r:   Ninput_lengthsadd_adapterc                 d   Uc  U R                   R                  OUnS n[        U R                   R                  U R                   R                  5       H  u  pEU" XU5      nM     U(       aD  [        U R                   R                  5       H!  nU" USU R                   R                  5      nM#     U$ )z8
Computes the output length of the convolutional layers
c                 8    [         R                  " X-
  USS9S-   $ )Nfloor)rounding_moder   )r   divinput_lengthr    r!   s      r8   _conv_out_lengthWData2VecAudioPreTrainedModel._get_feat_extract_output_lengths.<locals>._conv_out_length  s      99\7wWZ[[[r:   r   )r5   rN  zipr+   r,   rl   r,  r   )r4   rM  rN  rV  r    r!   ro   s          r8    _get_feat_extract_output_lengths=Data2VecAudioPreTrainedModel._get_feat_extract_output_lengths  s    
 2=1Ddkk--+	\
 $'t{{'>'>@W@W#XK,]PM $Y 4;;99: 04;;C]C] ^ ; r:   feature_vector_lengthr   c                    UR                  SS9S S 2S4   nU R                  XCS9nUR                  [        R                  5      nUR
                  S   n[        R                  " Xa4UR                  UR                  S9nSU[        R                  " UR
                  S   UR                  S9US-
  4'   UR                  S/5      R                  S5      R                  S/5      R                  5       nU$ )Nr=   r   rN  r   )dtyper  r   )r  )cumsumrY  r  r   longr   zerosr^  r  arangeflipr   )r4   r[  r   rN  non_padded_lengthsoutput_lengths
batch_sizes          r8   "_get_feature_vector_attention_mask?Data2VecAudioPreTrainedModel._get_feature_vector_attention_mask  s    
 ,22r2:1b5A>>?Q>k'**5::6#))!,
/~7K7KTbTiTi
 uv^%9%9!%<^EZEZ[]kno]opq',,bT299"=BBB4HMMOr:   r  rj   )rE   rF   rG   rH   r   __annotations__base_model_prefixmain_input_nameinput_modalitiessupports_gradient_checkpointing_supports_flash_attn_supports_sdpa_supports_flex_attnr   no_gradrK  
LongTensorr   r   rY  rg  rI   r  r:   r8   r4  r4    s    ($O&*#N
]]_6 62e>N>NQT>T cgjncn , Y]%(:?:J:J r:   r4  r   	mask_probmask_length	min_masksr   c           	        ^^^^^ U u  nmTS:  a  [        S5      eTT:  a  [        ST ST S35      e[        R                  R                  S5      R	                  5       mUUUUU4S jnUb-  UR                  5       R                  S5      R                  5       O[        U5       Vs/ s H  nTPM     snn[        R                  " UT4[        S	9n	/ n
U" T5      nUS
:X  a  U	$ U H  nU" U5      n[        R                  R                  [        R                  " UTS-
  -
  5      USS9n[        U5      S
:X  a  TS-
  nOUS
   n[        R                  " U[        R                  " X-
  [        R                   S	9U-  /5      nU
R#                  U5        M     [        R$                  " U
5      n
[        R&                  " U
SS2SS2S4   X[T45      n
U
R)                  X[T-  5      n
[        R                  " T5      SSSS24   n[        R&                  " UX[T45      R)                  X[T-  5      nU
U-   n
U
R+                  5       TS-
  :  a  TS-
  XTS-
  :  '   [        R,                  " XSS5        U	$ s  snf )a2  
Computes random mask spans for a given shape. Used to implement [SpecAugment: A Simple Data Augmentation Method for
ASR](https://huggingface.co/papers/1904.08779). Note that this method is not optimized to run on TPU and should be run on
CPU as part of the preprocessing during training.

Args:
    shape: The shape for which to compute masks. This should be of a tuple of size 2 where
           the first element is the batch size and the second element is the length of the axis to span.
    mask_prob:  The percentage of the whole axis (between 0 and 1) which will be masked. The number of
                independently generated mask spans of length `mask_length` is computed by
                `mask_prob*shape[1]/mask_length`. Note that due to overlaps, `mask_prob` is an upper bound and the
                actual percentage will be smaller.
    mask_length: size of the mask
    min_masks: minimum number of masked spans
    attention_mask: A (right-padded) attention mask which independently shortens the feature axis of
                    each batch dimension.
r   z&`mask_length` has to be bigger than 0.zO`mask_length` has to be smaller than `sequence_length`, but got `mask_length`: z and `sequence_length`: `c                    > [        TU -  T-  T-   5      n[        UT5      nUT-  T:  a  TT-  nU TS-
  -
  U:  a  [        U TS-
  -
  S5      nU$ )z;Given input length, compute how many spans should be maskedr   r   )r   max)rU  num_masked_spanepsilonrt  rs  ru  sequence_lengths     r8   compute_num_masked_span6_compute_mask_indices.<locals>.compute_num_masked_spanJ  so    i,6DwNOoy9 [(?:-<O ;?+o=!,+/"BAFOr:   Nr=   r^  r   F)replace)r   r/  r0  r  itemdetachsumtolistrl   ra  r   choicerb  lenconcatenateonesint32appendarraybroadcast_tor   ry  put_along_axis)r   rs  rt  r   ru  rf  r}  ro   rM  spec_aug_maskspec_aug_mask_idxsmax_num_masked_spanrU  rz  spec_aug_mask_idxdummy_mask_idxoffsetsr{  r|  s    `` `            @@r8   _compute_mask_indicesr  $  s   0 #(JQABB_$]^i]j&&7q:
 	
 iinnQ$$&G $ % 	##B'..0',Z'89'8!o'89  HHj/:$GM1/Ba%1,? II,,IIlkAo67RW - 
  !Q& -q0N.q1NNN(;(MUWU]U] ^ao op
 	!!"34/ &2 "45 1a:&+(V ,33JVa@ab ii$T4]3Goog
'UV^^+5G ,g5 /A"55GVYZGZ!0CCD mB?w :s   (I0c                   @  ^  \ rS rSrS\4U 4S jjrS r  SS\R                  S\R                  S-  S\R                  S-  4S	 jjr
\     SS
\R                  S-  S\R                  S-  S\R                  S-  S\S-  S\S-  S\S-  S\\-  4S jj5       rSrU =r$ )Data2VecAudioModeli  r5   c                   > [         TU ]  U5        Xl        [        U5      U l        [        U5      U l        UR                  S:  d  UR                  S:  aG  [        R                  " [        R                  " UR                  5      R                  5       5      U l        [!        U5      U l        UR$                  (       a  ['        U5      OS U l        U R+                  5         g Nr   )r%   r&   r5   ru   feature_extractorr   feature_projectionmask_time_probmask_feature_probr   	Parameterr   r   r^   r@  masked_spec_embedr   encoderrN  r&  adapter	post_initra   s     r8   r&   Data2VecAudioModel.__init__  s     !<V!D"@"H   3&&*B*BS*H%'\\%,,v?Q?Q2R2[2[2]%^D"+F37=7I7I+F3t 	r:   c                 8    U R                   R                  5         gz
Calling this function will disable the gradient computation for the feature encoder so that its parameter will
not be updated during training.
N)r  r   r4   s    r8   freeze_feature_encoder)Data2VecAudioModel.freeze_feature_encoder  s    
 	113r:   Nr@   mask_time_indicesr   c                    [        U R                  SS5      (       d  U$ UR                  5       u  pEnUb(  U R                  R	                  UR
                  5      X'   OU R                  R                  S:  a  U R                  (       a  [        XE4U R                  R                  U R                  R                  UU R                  R                  S9n[        R                  " X!R                  [        R                  S9nU R                  R	                  UR
                  5      X'   U R                  R                  S:  a  U R                  (       a  [        XF4U R                  R                  U R                  R                   U R                  R"                  S9n[        R                  " XqR                  [        R                  S9nUSS2S4   R%                  SUS5      nSX'   U$ )	z
Masks extracted features along time axis and/or along feature axis according to
[SpecAugment](https://huggingface.co/papers/1904.08779).
apply_spec_augmentTNr   )rs  rt  r   ru  )r  r^  )rs  rt  ru  r=   )getattrr5   r   r  r  r^  r  r   r  mask_time_lengthmask_time_min_masksr   r  r  r   r  mask_feature_lengthmask_feature_min_masksexpand)r4   r@   r  r   rf  r|  r^   mask_feature_indicess           r8   _mask_hidden_states&Data2VecAudioModel._mask_hidden_states  s    t{{$8$??   4A3E3E3G0
[(/3/E/E/H/HI\I\/]M,[[''!+ 5-++44 KK88-++99! !&->G[G[chcmcm n/3/E/E/H/HI\I\/]M,;;((1,#8)++77 KK;;++<<	$  $)<<0DMaMainisis#t #74#@#G#GO]_#` 23M/r:   r   r   r   r   r   c                 >   Ub  UOU R                   R                  nUb  UOU R                   R                  nUb  UOU R                   R                  nU R	                  U5      nUR                  SS5      nUb  U R                  UR                  S   USS9nU R                  U5      u  pU R                  XUS9n	U R                  U	UUUUS9n
U
S   n	U R                  b  U R                  U	5      n	U(       d	  X4U
SS -   $ [        U	UU
R                  U
R                  S	9$ )
a  
mask_time_indices (`torch.BoolTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Indices to mask extracted features for contrastive loss. When in training mode, model learns to predict
    masked extracted features in *config.proj_codevector_dim* space.
Nr   rP   Fr]  )r  r   r   r   r   r   r   )r	  extract_featuresr@   r
  )r5   r   r   r   r  r>   rg  r   r  r  r  r  Data2VecAudioBaseModelOutputr@   r
  )r4   r   r   r  r   r   r   r   r  r@   encoder_outputss              r8   rA   Data2VecAudioModel.forward  sY     2C1N-TXT_T_TqTq$8$D $++JjJj 	 &1%<k$++BYBY11,?+55a;%!DD &&q)>u E N +/*A*ABR*S'00~ 1 
 ,,)/!5# ' 
 (*<<# LL7M!4qr7JJJ++-)77&11	
 	
r:   )r  r5   r  r  r  r  r  NNNNN)rE   rF   rG   rH   r   r&   r  r   FloatTensorrr  r  r   r   r   r   r  rA   rI   rJ   rK   s   @r8   r  r    s    2 "4 7;26	,((, !,,t3, ((4/	,\  /36:)-,0#'8
llT)8
 t+8
 !,,t3	8

  $;8
 #Tk8
 D[8
 
-	-8
 8
r:   r  rP   zu
    Data2VecAudio Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC).
    )custom_introc                      ^  \ rS rSrU 4S jrS r\     SS\R                  S-  S\R                  S-  S\	S-  S\	S-  S	\	S-  S
\R                  S-  S\
\-  4S jj5       rSrU =r$ )Data2VecAudioForCTCi%  c                   > [         TU ]  U5        [        U5      U l        [        R
                  " UR                  5      U l        UR                  c  [        SU R                   S35      e[        US5      (       a  UR                  (       a  UR                  OUR                  n[        R                  " X!R                  5      U l        U R#                  5         g)a2  
config ([`Data2VecAudioForCTC`]):
    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.
NzYou are trying to instantiate z with a configuration that does not define the vocabulary size of the language model head. Please instantiate the model as follows: `Data2VecAudioForCTC.from_pretrained(..., vocab_size=vocab_size)`. or define `vocab_size` of your model's configuration.rN  )r%   r&   r  r5  r   r   final_dropoutr   
vocab_sizer   r7   hasattrrN  r  r^   r   lm_headr  )r4   r5   r  r7   s      r8   r&   Data2VecAudioForCTC.__init__+  s     	 08zz&"6"67$00@ AH H  *1)G)GFL^L^F%%djdvdv 	 yy!35F5FG 	r:   c                 L    U R                   R                  R                  5         gr  r5  r  r   r  s    r8   r  *Data2VecAudioForCTC.freeze_feature_encoderF      
 	--@@Br:   Nr   r   r   r   r   labelsr   c                    Ub  UOU R                   R                  nUbJ  UR                  5       U R                   R                  :  a"  [	        SU R                   R                   35      eU R                  UUUUUS9nUS   n	U R                  U	5      n	U R                  U	5      n
SnUGbX  Ub  UO"[        R                  " U[        R                  S9nU R                  UR                  S5      5      R                  [        R                  5      nUS:  nUR                  S5      nUR                  U5      n[        R                   R#                  U
S[        R$                  S9R'                  SS5      n[        R(                  R*                  R-                  S	S
9   [        R                   R/                  UUUUU R                   R0                  U R                   R2                  U R                   R4                  S9nSSS5        U(       d  U
4U[6        S -   nUb  U4U-   $ U$ [9        XUR:                  UR<                  S9$ ! , (       d  f       NL= f)a  
labels (`torch.LongTensor` of shape `(batch_size, target_length)`, *optional*):
    Labels for connectionist temporal classification. Note that `target_length` has to be smaller or equal to
    the sequence length of the output logits. Indices are selected in `[-100, 0, ..., config.vocab_size - 1]`.
    All labels set to `-100` are ignored (masked), the loss is only computed for labels in `[0, ...,
    config.vocab_size - 1]`.
Nz$Label values must be <= vocab_size: r  r   r  r=   )r   r^  r   F)enabled)blank	reductionzero_infinitylosslogitsr@   r
  )r5   r   ry  r  r   r5  r   r  r   	ones_liker`  rY  r  r  masked_selectr   r   log_softmaxfloat32r>   backendscudnnflagsctc_losspad_token_idctc_loss_reductionctc_zero_infinity_HIDDEN_STATES_START_POSITIONr   r@   r
  )r4   r   r   r   r   r   r  r   r   r@   r  r  rM  labels_masktarget_lengthsflattened_targets	log_probsoutputs                     r8   rA   Data2VecAudioForCTC.forwardM  s    $ &1%<k$++BYBY&**,$++2H2H"HCDKKDZDZC[\]]%%)/!5# & 
  
]3m, #1"<%//R^fkfpfpBq  !AA.BTBTUWBXY\\]b]g]ghM !A+K(__R0N & 4 4[ A 11&b1V``abdefI%%++E+:}}--%!"++22"kk<<"&++"?"? .  ; Y)F)G!HHF)-)9TGf$EvEG4I4IV]VhVh
 	
 ;:s   A H??
I)r5  r   r  r  )rE   rF   rG   rH   r&   r  r   r   r   r   r   r   rA   rI   rJ   rK   s   @r8   r  r  %  s    6C  /3)-,0#'&*E
llT)E
 t+E
  $;	E

 #TkE
 D[E
 t#E
 
	E
 E
r:   r  z
    Data2VecAudio Model with a sequence classification head on top (a linear layer over the pooled output) for tasks like
    SUPERB Keyword Spotting.
    c                      ^  \ rS rSrU 4S jrS rS r\     SS\R                  S-  S\R                  S-  S\
S-  S	\
S-  S
\
S-  S\R                  S-  S\\-  4S jj5       rSrU =r$ )&Data2VecAudioForSequenceClassificationi  c                 "  > [         TU ]  U5        [        US5      (       a  UR                  (       a  [	        S5      e[        U5      U l        UR                  S-   nUR                  (       a2  [        R                  " [        R                  " U5      U-  5      U l        [        R                  " UR                  UR                   5      U l        [        R                  " UR                   UR$                  5      U l        U R)                  5         g )NrN  zdSequence classification does not support the use of Data2VecAudio adapters (config.add_adapter=True)r   )r%   r&   r  rN  r   r  r5  r   use_weighted_layer_sumr   r  r   r  layer_weightsr   r^   classifier_proj_size	projector
num_labels
classifierr  r4   r5   
num_layersr7   s      r8   r&   /Data2VecAudioForSequenceClassification.__init__  s     6=))f.@.@v  18--1
((!#ejj.Dz.Q!RD6#5#5v7R7RS))F$?$?ARARS 	r:   c                 L    U R                   R                  R                  5         gr  r  r  s    r8   r  =Data2VecAudioForSequenceClassification.freeze_feature_encoder  r  r:   c                 T    U R                   R                  5        H
  nSUl        M     gz
Calling this function will disable the gradient computation for the base model so that its parameters will not
be updated during training. Only the classification head will be updated.
FNr5  r   r   r   s     r8   freeze_base_model8Data2VecAudioForSequenceClassification.freeze_base_model  %    
 ((335E"'E 6r:   Nr   r   r   r   r   r  r   c                 0   Ub  UOU R                   R                  nU R                   R                  (       a  SOUnU R                  UUUUUS9nU R                   R                  (       ai  U[           n	[
        R                  " U	SS9n	[        R                  R                  U R                  SS9n
XR                  SSS5      -  R                  SS9n	OUS   n	U R                  U	5      n	Uc  U	R                  SS9nOU R                  U	R                   S   U5      nUR#                  S5      R%                  SSU	R                   S   5      nS	X) '   U	R                  SS9UR                  SS9R                  SS5      -  nU R'                  U5      nSnUbF  [)        5       nU" UR                  SU R                   R*                  5      UR                  S5      5      nU(       d  U4U[        S -   nUb  U4U-   $ U$ [-        UUUR.                  UR0                  S
9$ )  
input_values (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
    Float values of input raw speech waveform. Values can be obtained by loading a `.flac` or `.wav` audio file
    into an array of type `list[float]`, a `numpy.ndarray` or a `torch.Tensor`, *e.g.* via the torchcodec library
    (`pip install torchcodec`) or the soundfile library (`pip install soundfile`).
    To prepare the array into `input_values`, the [`AutoProcessor`] should be used for padding and conversion
    into a tensor of type `torch.FloatTensor`. See [`Data2VecAudioProcessor.__call__`] for details.
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
    config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
    `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
NTr  r   r   r=   r   rP   r   r  )r5   r   r  r5  r  r   stackr   r   r   r  r   r  r  r:  rg  r   r  r  r  r   r  r   r@   r
  )r4   r   r   r   r   r   r  r   r   r@   norm_weightspooled_outputpadding_maskexpand_padding_maskr  r  loss_fctr  s                     r8   rA   .Data2VecAudioForSequenceClassification.forward  s   0 &1%<k$++BYBY'+{{'I'ItOc%%)/!5# & 
 ;;--#$ABM!KK1=M==001C1C0LL*->->r1a-HHMMRSMTM#AJM}5!)..1.5MBB=CVCVWXCY[ijL"."8"8"<"C"CAq-J]J]^_J`"a25M./)--!-4|7G7GA7G7N7S7STVXY7ZZM/')HFKKDKK,B,BCV[[QS_UDY)F)G!HHF)-)9TGf$EvE'!//))	
 	
r:   )r  r5  r  r  r  )rE   rF   rG   rH   r&   r  r  r   r   r   r   r   r   rA   rI   rJ   rK   s   @r8   r  r    s    "C(  /3)-,0#'&*C
llT)C
 t+C
  $;	C

 #TkC
 D[C
 t#C
 
)	)C
 C
r:   r  c                      ^  \ rS rSrU 4S jrS rS r\     SS\R                  S-  S\R                  S-  S\R                  S-  S	\
S-  S
\
S-  S\
S-  S\\-  4S jj5       rSrU =r$ )(Data2VecAudioForAudioFrameClassificationi  c                   > [         TU ]  U5        [        US5      (       a  UR                  (       a  [	        S5      e[        U5      U l        UR                  S-   nUR                  (       a2  [        R                  " [        R                  " U5      U-  5      U l        [        R                  " UR                  UR                   5      U l        UR                   U l        U R%                  5         g )NrN  zgAudio frame classification does not support the use of Data2VecAudio adapters (config.add_adapter=True)r   )r%   r&   r  rN  r   r  r5  r   r  r   r  r   r  r  r   r^   r  r  r  r  s      r8   r&   1Data2VecAudioForAudioFrameClassification.__init__  s     6=))f.@.@y  18--1
((!#ejj.Dz.Q!RD))F$6$68I8IJ ++r:   c                 L    U R                   R                  R                  5         gr  r  r  s    r8   r  ?Data2VecAudioForAudioFrameClassification.freeze_feature_encoder  r  r:   c                 T    U R                   R                  5        H
  nSUl        M     gr  r  r   s     r8   r  :Data2VecAudioForAudioFrameClassification.freeze_base_model  r  r:   Nr   r   r  r   r   r   r   c           	         Ub  UOU R                   R                  nU R                   R                  (       a  SOUnU R                  UUUUUS9nU R                   R                  (       ai  U[           n	[
        R                  " U	SS9n	[        R                  R                  U R                  SS9n
XR                  SSS5      -  R                  SS9n	OUS   n	U R                  U	5      nSnUbZ  [        5       nU" UR                  SU R                  5      [
        R                   " UR                  SU R                  5      SS95      nU(       d  U4U[        S -   nU$ [#        UUUR$                  UR&                  S	9$ )
r  NTr  r   r   r=   r   )axisr  )r5   r   r  r5  r  r   r  r   r   r   r  r   r  r  r   r  argmaxr   r@   r
  )r4   r   r   r  r   r   r   r   r   r@   r  r  r  r  r  s                  r8   rA   0Data2VecAudioForAudioFrameClassification.forward%  sh   0 &1%<k$++BYBY'+{{'I'ItOc%%)/!5# & 
 ;;--#$ABM!KK1=M==001C1C0LL*->->r1a-HHMMRSMTM#AJM/')HFKKDOO<ell6;;WY[_[j[jKkrs>tuDY)F)G!HHFM$!//))	
 	
r:   )r  r5  r  r  r  )rE   rF   rG   rH   r&   r  r  r   r   r   r   r   r   rA   rI   rJ   rK   s   @r8   r  r    s     C(  /3&*)-,0#':
llT):
 t+:
 t#	:

  $;:
 #Tk:
 D[:
 
&	&:
 :
r:   r  c                   2   ^  \ rS rSrSU 4S jjrS rSrU =r$ )AMSoftmaxLossic  c                    > [         TU ]  5         X0l        X@l        X l        [
        R                  " [        R                  " X5      SS9U l	        [
        R                  " 5       U l        g )NT)r   )r%   r&   scalemarginr  r   r  r   randnrA  r   r  )r4   	input_dimr  r  r  r7   s        r8   r&   AMSoftmaxLoss.__init__d  sI    
$ll5;;y#EUYZ'')	r:   c                    UR                  5       n[        R                  R                  U R                  SS9n[        R                  R                  USS9n[
        R                  " X5      nX@R                  -
  n[        R                  R                  X R                  5      nU R                  [
        R                  " UR                  5       XT5      -  nU R                  Xr5      nU$ )Nr   r   r   )flattenr   r   	normalizerA  r   mmr  one_hotr  r  wherer   r  )	r4   r@   r  rA  	cos_thetapsionehotr  r  s	            r8   rA   AMSoftmaxLoss.forwardl  s    !((!(<//1/EHH]3	++%&&v?ekk&++-HHyy(r:   )r  r  r  r  rA  )g      >@g?rD   rK   s   @r8   r  r  c  s    * r:   r  c                   f   ^  \ rS rSrSU 4S jjrS\R                  S\R                  4S jrSrU =r	$ )	TDNNLayeriz  c                   > [         TU ]  5         US:  a  UR                  US-
     OUR                  U   U l        UR                  U   U l        UR
                  U   U l        UR                  U   U l        [        R                  " U R                  U R                  -  U R                  5      U l        [        R                  " 5       U l        g )Nr   r   )r%   r&   tdnn_dimr(   r)   tdnn_kernelr    tdnn_dilationdilationr   r   kernelReLUr2   r3   s      r8   r&   TDNNLayer.__init__{  s    <DqL6??8a<8foo^fNg"OOH5!--h7,,X6ii 0 043C3C CTEVEVW'')r:   r@   r   c                 >   [        5       (       a  SSKJn  [        5       (       a1  [        U R                  W5      (       a  [
        R                  " S5        UR                  SS5      nU R                  R                  R                  U R                  U R                  U R                  5      R                  SS5      n[        R                  R                  XU R                  R                   U R"                  S9nUR                  SS5      nU R%                  U5      nU$ )Nr   )	LoraLayerzDetected LoRA on TDNNLayer. LoRA weights won't be applied due to optimization. You should exclude TDNNLayer from LoRA's target modules.r   rP   )r%  )r   peft.tuners.lorar*  r   r&  warningswarnr>   rA  r   r)   r    r(   r   r   conv1dr"   r%  r2   )r4   r@   r*  rA  s       r8   rA   TDNNLayer.forward  s    2$++y11O &//15##(():):D<L<LdN^N^_iijkmno,,]DKKDTDT_c_l_l,m%//156r:   )r2   r%  r(   r&  r    r)   rC   )
rE   rF   rG   rH   r&   r   r   rA   rI   rJ   rK   s   @r8   r   r   z  s(    $U\\ ell  r:   r   zq
    Data2VecAudio Model with an XVector feature extraction head on top for tasks like Speaker Verification.
    c                      ^  \ rS rSrU 4S jrS rS rS\R                  \	-  4S jr
\     SS\R                  S-  S	\R                  S-  S
\S-  S\S-  S\S-  S\R                  S-  S\\-  4S jj5       rSrU =r$ )Data2VecAudioForXVectori  c                 2  > [         TU ]  U5        [        U5      U l        UR                  S-   nUR
                  (       a2  [        R                  " [        R                  " U5      U-  5      U l
        [        R                  " UR                  UR                  S   5      U l        [        [!        UR                  5      5       Vs/ s H  n[#        X5      PM     nn[        R$                  " U5      U l        [        R                  " UR                  S   S-  UR(                  5      U l        [        R                  " UR(                  UR(                  5      U l        [/        UR(                  UR0                  5      U l        U R5                  5         g s  snf )Nr   r   r=   rP   )r%   r&   r  r5  r   r  r   r  r   r  r  r   r^   r"  r  rl   r  r   rk   tdnnxvector_output_dimr  r  r  r  	objectiver  )r4   r5   r  r|   tdnn_layersr7   s        r8   r&    Data2VecAudioForXVector.__init__  s    08--1
((!#ejj.Dz.Q!RD6#5#5vq7IJ5:3v;O5PQ5Py+5PQMM+.	!#6??2+>+BFD]D]!^))F$=$=v?X?XY&v'@'@&BSBST Rs   Fc                 L    U R                   R                  R                  5         gr  r  r  s    r8   r  .Data2VecAudioForXVector.freeze_feature_encoder  r  r:   c                 T    U R                   R                  5        H
  nSUl        M     gr  r  r   s     r8   r  )Data2VecAudioForXVector.freeze_base_model  r  r:   rM  c                 X    S nU R                   R                   H  nU" XS5      nM     U$ )z/
Computes the output length of the TDNN layers
c                     X-
  U-  S-   $ )Nr   r  rT  s      r8   rV  JData2VecAudioForXVector._get_tdnn_output_lengths.<locals>._conv_out_length  s     !.69A==r:   r   )r5   r#  )r4   rM  rV  r    s       r8   _get_tdnn_output_lengths0Data2VecAudioForXVector._get_tdnn_output_lengths  s1    
	>
  ;;22K,]KM 3 r:   Nr   r   r   r   r   r  r   c                    Ub  UOU R                   R                  nU R                   R                  (       a  SOUnU R                  UUUUUS9nU R                   R                  (       ai  U[           n	[
        R                  " U	SS9n	[        R                  R                  U R                  SS9n
XR                  SSS5      -  R                  SS9n	OUS   n	U R                  U	5      n	U R                   H  nU" U	5      n	M     Uc  U	R                  SS9nU	R!                  SS9nOU R#                  UR                  SS95      nU R%                  U5      n/ n/ n['        U5       HP  u  nnUR)                  U	USU24   R                  SS95        UR)                  U	USU24   R!                  SS95        MR     [
        R                  " U5      n[
        R                  " U5      n[
        R*                  " X/SS9nU R-                  U5      nU R/                  U5      nSnUb  U R1                  UU5      nU(       d  UU4U[        S -   nUb  U4U-   $ U$ [3        UUUUR4                  UR6                  S9$ )	r  NTr  r   r   r=   r   )r  r  
embeddingsr@   r
  )r5   r   r  r5  r  r   r  r   r   r   r  r   r  r  r3  r:  r;  rY  r?  	enumerater  catr  r  r5  r   r@   r
  )r4   r   r   r   r   r   r  r   r   r@   r  
tdnn_layermean_featuresstd_featuresfeat_extract_output_lengthstdnn_output_lengthsr|   lengthstatistic_poolingoutput_embeddingsr  r  r  s                          r8   rA   Data2VecAudioForXVector.forward  s   0 &1%<k$++BYBY'+{{'I'ItOc%%)/!5# & 
 ;;--#$ABM!KK1=M==001C1C0LL*->->r1a-HHMMRSMTM#AJM}5))J&}5M $ !)..1.5M(,,,3L*.*O*OP^PbPbghPbPi*j'"&"?"?@["\ML&':;	6$$]1gvg:%>%C%C%C%JK##M!WfW*$=$A$Aa$A$HI < "KK6M ;;|4L!II}&CL 223DE!23>>&&1D/07;X;Y3ZZF)-)9TGf$EvE(!//))
 	
r:   )r  r5  r  r  r5  r  r3  r  )rE   rF   rG   rH   r&   r  r  r   rr  r   r?  r   r   r   r   r   rA   rI   rJ   rK   s   @r8   r1  r1    s    &C(e6F6F6L   /3)-,0#'&*P
llT)P
 t+P
  $;	P

 #TkP
 D[P
 t#P
 
	P
 P
r:   r1  )r  r  r  r1  r  r4  r  rU   )Kr<  r,  collections.abcr   numpyr/  r   r   torch.nnr    r   r?  activationsr   integrations.deepspeedr	   integrations.fsdpr
   masking_utilsr   modeling_flash_attention_utilsr   modeling_layersr   modeling_outputsr   r   r   r   r   r   modeling_utilsr   r   processing_utilsr   utilsr   r   r   configuration_data2vec_audior   r   ModulerM   rY   rg   ru   r   r   r   r   r   r   r   r   r  r&  r4  r   r   rr  ndarrayr  r  r  r  r  r  r  r  r   r1  __all__r  r:   r8   <module>r`     s  *   $    % & ! @ 7 6 B 9  G & J J =7 6BII ryy 6299 ")) :1RYY 1* !%II%<<% 
% <<	%
 LL4'% T\% % '(%8R/RYY R/jryy 0! : !HE
299 E
P		 $299 > K? K Kd /3tc?tt t $$t+	t
 t ZZtn  7  @
5 @
 @
F !"  
i
6 i

i
X e
-I e
e
P [
/K [
 [
|BII .		 @ 
C
: C

C
Lr:   