
    g                    v   d Z ddlZddlZddlmZ ddlmZmZmZ ddl	Z
ddl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mZmZmZmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ dZ0dZ1 e+            rddl2m3Z4  e(            rddl5m6Z6  e,j7        e8          Z9dZ:dZ;dZ<g dZ=dZ>dZ?dZ@dZAdZBdZCddgZDdZEd ZFe G d! d"e#                      ZG	 	 dud#eeHeHf         d$eId%eHd&eejJ                 d'eHd(e
jK        fd)ZL	 dvd*ed+eHd,ee
jK                 fd-ZM G d. d/ejN                  ZO G d0 d1ejN                  ZP G d2 d3ejN                  ZQ G d4 d5ejN                  ZR G d6 d7ejN                  ZS G d8 d9ejN                  ZT G d: d;eT          ZU G d< d=ejN                  ZV G d> d?ejN                  ZW G d@ dAeW          ZX G dB dCeW          ZYeWeYeXdDZZ G dE dFejN                  Z[ G dG dHejN                  Z\ G dI dJejN                  Z] G dK dLejN                  Z^ G dM dNejN                  Z_ G dO dPejN                  Z` G dQ dRejN                  Za G dS dTejN                  Zb G dU dVejN                  Zc G dW dXe          ZddYZedZZf e%d[ee           G d\ d]ed                      Zg e%d^ee           G d_ d`ed                      Zh e%daee           G db dced                      Zi e%ddeede           G df dged                      Zj e%dhee           G di djed                      Zk e%dkee           G dl dmed                      Zl G dn doejN                  Zm G dp dqejN                  Zn e%dree           G ds dted                      ZodS )wzPyTorch Wav2Vec2 model.    N)	dataclass)OptionalTupleUnion)nn)CrossEntropyLoss   )ACT2FN)is_deepspeed_zero3_enabled)is_fsdp_managed_module)BaseModelOutputCausalLMOutputMaskedLMOutputSequenceClassifierOutputTokenClassifierOutputWav2Vec2BaseModelOutputXVectorOutput)PreTrainedModel)#is_torch_greater_or_equal_than_1_13)ModelOutputadd_code_sample_docstringsadd_start_docstrings%add_start_docstrings_to_model_forwardcached_fileis_flash_attn_2_available#is_flash_attn_greater_or_equal_2_10is_peft_availableis_safetensors_availableloggingreplace_return_docstrings   )Wav2Vec2Configzadapter.{}.binzadapter.{}.safetensors)	load_file)_flash_attention_forward   r"   zfacebook/wav2vec2-base-960h)r!   i$  i   z['MISTER QUILTER IS THE APOSTLE OF THE MIDDLE CLASSES AND WE ARE GLAD TO WELCOME HIS GOSPEL'g=
ףpJ@zsuperb/wav2vec2-base-superb-ksz'_unknown_'g)\(@zanton-l/wav2vec2-base-superb-sdzanton-l/wav2vec2-base-superb-svg\(\?c                   (   e Zd ZU dZdZeej                 ed<   dZ	ej        ed<   dZ
ej        ed<   dZej        ed<   dZeeej                          ed<   dZeeej                          ed<   dZeej                 ed	<   dZeej                 ed
<   dS )Wav2Vec2ForPreTrainingOutputa1	  
    Output type of [`Wav2Vec2ForPreTraining`], with potential hidden states and attentions.

    Args:
        loss (*optional*, returned when `sample_negative_indices` are passed, `torch.FloatTensor` of shape `(1,)`):
            Total loss as the sum of the contrastive loss (L_m) and the diversity loss (L_d) as stated in the [official
            paper](https://arxiv.org/pdf/2006.11477.pdf) . (classification) loss.
        projected_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.proj_codevector_dim)`):
            Hidden-states of the model projected to *config.proj_codevector_dim* that can be used to predict the masked
            projected quantized states.
        projected_quantized_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.proj_codevector_dim)`):
            Quantized extracted feature vectors projected to *config.proj_codevector_dim* representing the positive
            target vectors for contrastive loss.
        hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
            Tuple of `torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) of
            shape `(batch_size, sequence_length, hidden_size)`.

            Hidden-states of the model at the output of each layer plus the initial embedding outputs.
        attentions (`tuple(torch.FloatTensor)`, *optional*, returned when `output_attentions=True` is passed or when `config.output_attentions=True`):
            Tuple of `torch.FloatTensor` (one for each layer) of shape `(batch_size, num_heads, sequence_length,
            sequence_length)`.

            Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
            heads.
        contrastive_loss (*optional*, returned when `sample_negative_indices` are passed, `torch.FloatTensor` of shape `(1,)`):
            The contrastive loss (L_m) as stated in the [official paper](https://arxiv.org/pdf/2006.11477.pdf) .
        diversity_loss (*optional*, returned when `sample_negative_indices` are passed, `torch.FloatTensor` of shape `(1,)`):
            The diversity loss (L_d) as stated in the [official paper](https://arxiv.org/pdf/2006.11477.pdf) .
    Nlossprojected_statesprojected_quantized_statescodevector_perplexityhidden_states
attentionscontrastive_lossdiversity_loss)__name__
__module____qualname____doc__r(   r   torchFloatTensor__annotations__r)   r*   r+   r,   r   r-   r.   r/        j/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.pyr'   r'   b   s          < )-D(5$
%,,,*.e'...48 1888/35,3338<M8E%"345<<<59Ju01299948hu0188826NHU./66666r8   r'   shape	mask_probmask_lengthattention_mask	min_masksreturnc                 @   | \  }dk     rt          d          k    rt          d d d          t          j                            d                                          fd}|9|                    d                                                                          nfd	t          |          D             }t          j	        |ft          
          }g }	 |          }
|
dk    r|S |D ]} ||          }t          j                            t          j        |dz
  z
            |d          }t          |          dk    rdz
  }n|d         }t          j        |t          j        |
|z
  t          j        
          |z  g          }|	                    |           t          j        |	          }	t          j        |	dddddf         ||
f          }	|	                    ||
z            }	t          j                  ddddf         }t          j        |||
f                              ||
z            }|	|z   }	|	                                dz
  k    rdz
  |	|	dz
  k    <   t          j        ||	dd           |S )af  
    Computes random mask spans for a given shape. Used to implement [SpecAugment: A Simple Data Augmentation Method for
    ASR](https://arxiv.org/abs/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          | z  z  z             }t          |          }|z  k    rz  }| dz
  z
  |k     rt          | dz
  z
  d          }|S )z;Given input length, compute how many spans should be maskedr!   r   )intmax)input_lengthnum_masked_spanepsilonr<   r;   r>   sequence_lengths     r9   compute_num_masked_spanz6_compute_mask_indices.<locals>.compute_num_masked_span   s~    i,6DwNOOoy99 [(?::-<O ;?+o==!,+/"BAFFOr8   Nc                     g | ]}S r7   r7   ).0_rH   s     r9   
<listcomp>z)_compute_mask_indices.<locals>.<listcomp>   s    999!o999r8   dtyper   F)replace)
ValueErrornprandomranditemsumdetachtolistrangezerosboolchoicearangelenconcatenateonesint32appendarraybroadcast_toreshaperD   put_along_axis)r:   r;   r<   r=   r>   
batch_sizerI   input_lengthsspec_aug_maskspec_aug_mask_idxsmax_num_masked_spanrE   rF   spec_aug_mask_idxdummy_mask_idxoffsetsrG   rH   s    `` `           @@r9   _compute_mask_indicesrp      sP   0 #(JQABBB_$$:^i : :'6: : :
 
 	
 innQ$$&&G        $ % 	2%%''..0009999uZ'8'8999  Hj/:$GGGM11/BBa% 5 511,?? I,,IlkAo677RW - 
 
  !!Q&& -q0NN.q1NN(;o(MUWU] ^ ^ ^ao op
 
 	!!"34444"455 111aaa:&5H+(V  ,33J@SVa@abb i$$T4]3Gog
4G'UVV^^'+5 G ,g5 /A"555GVYZGZ-!0CCD m%7B???r8   features_shapenum_negativesmask_time_indicesc                    | \  }}t          j        |          }t          j        |||ft           j                  }||                    t
                    nt          j        | t
                    }t          |          D ]}||                                         dz
  }|||                  }	t          j	        t          j        |dz             dddf         |dz   |f          }
t           j
                            d||dz   |f          }|||
k    xx         dz  cc<   |	|         ||         ||         <   ||xx         ||z  z  cc<   |S )z>
    Sample `num_negatives` vectors from feature vectors.
    )r:   rP   NrO   r!   r   )size)rS   r^   r[   rb   astyper\   ra   rZ   rW   re   rT   randint)rq   rr   rs   rh   rH   sequence_length_rangesampled_negative_indices	batch_idxhighmapped_masked_indicesfeature_indicessampled_indicess               r9   _sample_negative_indicesr     s    #1J Io66  "xz?M.Zbdbjkkk +<*G  &&&RWUckoMpMpMp  :&& K K	 +//11A5 56G	6R S/")D1H*=*=aaag*FPQS`Habb)++At4!8]:S+TT?:;;;q@;;; MbbqLr +,=i,HI 	!+++y?/JJ++++##r8   c                   &     e Zd Zd fd	Zd Z xZS )Wav2Vec2NoLayerNormConvLayerr   c                 Z   t                                                       |dk    r|j        |dz
           nd| _        |j        |         | _        t          j        | j        | j        |j        |         |j        |         |j	                  | _
        t          |j                 | _        d S )Nr   r!   kernel_sizestridebias)super__init__conv_dimin_conv_dimout_conv_dimr   Conv1dconv_kernelconv_stride	conv_biasconvr
   feat_extract_activation
activationselfconfiglayer_id	__class__s      r9   r   z%Wav2Vec2NoLayerNormConvLayer.__init__(  s    <DqLL6?8a<88a"OH5I*84%h/!
 
 
	 !!?@r8   c                 Z    |                      |          }|                     |          }|S N)r   r   r   r,   s     r9   forwardz$Wav2Vec2NoLayerNormConvLayer.forward6  s*    		-0066r8   r   r0   r1   r2   r   r   __classcell__r   s   @r9   r   r   '  sR        A A A A A A      r8   r   c                   &     e Zd Zd fd	Zd Z xZS )Wav2Vec2LayerNormConvLayerr   c                    t                                                       |dk    r|j        |dz
           nd| _        |j        |         | _        t          j        | j        | j        |j        |         |j        |         |j	                  | _
        t          j        | j        d          | _        t          |j                 | _        d S )Nr   r!   r   T)elementwise_affine)r   r   r   r   r   r   r   r   r   r   r   	LayerNorm
layer_normr
   r   r   r   s      r9   r   z#Wav2Vec2LayerNormConvLayer.__init__=  s    <DqLL6?8a<88a"OH5I*84%h/!
 
 
	 ,t'8TRRR !?@r8   c                     |                      |          }|                    dd          }|                     |          }|                    dd          }|                     |          }|S )NrJ   )r   	transposer   r   r   s     r9   r   z"Wav2Vec2LayerNormConvLayer.forwardL  se    		-00%//B7766%//B7766r8   r   r   r   s   @r9   r   r   <  sR        A A A A A A      r8   r   c                   &     e Zd Zd fd	Zd Z xZS )Wav2Vec2GroupNormConvLayerr   c                    t                                                       |dk    r|j        |dz
           nd| _        |j        |         | _        t          j        | j        | j        |j        |         |j        |         |j	                  | _
        t          |j                 | _        t          j        | j        | j        d          | _        d S )Nr   r!   r   T)
num_groupsnum_channelsaffine)r   r   r   r   r   r   r   r   r   r   r   r
   r   r   	GroupNormr   r   s      r9   r   z#Wav2Vec2GroupNormConvLayer.__init__X  s    <DqLL6?8a<88a"OH5I*84%h/!
 
 
	 !!?@,$2CRVRclpqqqr8   c                     |                      |          }|                     |          }|                     |          }|S r   )r   r   r   r   s     r9   r   z"Wav2Vec2GroupNormConvLayer.forwardh  s;    		-006666r8   r   r   r   s   @r9   r   r   W  sR        r r r r r r       r8   r   c                   $     e Zd Z fdZd Z xZS )Wav2Vec2PositionalConvEmbeddingc                    t                                                       t          j        |j        |j        |j        |j        dz  |j                  | _        t          j        j	        }t          t          j        j        d          rt          j        j        j	        }t                      rdd l}|j                            | j        j        d          5   || j        dd          | _        d d d            n# 1 swxY w Y   t          | j        d          r-| j        j        j        j        }| j        j        j        j        }n| j        j        }| j        j        }|j                            | |           |j                            | |           n || j        dd          | _        t-          |j                  | _        t0          |j                 | _        d S )	Nr%   )r   paddinggroupsweight_normr   )modifier_rankweight)namedimparametrizations)r   r   r   r   hidden_sizenum_conv_pos_embeddingsnum_conv_pos_embedding_groupsr   utilsr   hasattrr   r   	deepspeedzeroGatheredParametersr   	original0	original1weight_gweight_vregister_external_parameterWav2Vec2SamePadLayerr   r
   r   r   )r   r   r   r   r   r   r   s         r9   r   z(Wav2Vec2PositionalConvEmbedding.__init__p  s   I62a77
 
 
	 h*28,m<< 	@(3?K%'' 	E22493CST2UU I I'K	aHHH	I I I I I I I I I I I I I I Ity"455 .95<F95<F9-9-N66tXFFFN66tXFFFF#DIH!DDDDI+F,JKK !?@s   C??DDc                     |                     dd          }|                     |          }|                     |          }|                     |          }|                     dd          }|S Nr!   r%   )r   r   r   r   r   s     r9   r   z'Wav2Vec2PositionalConvEmbedding.forward  se    %//155		-00]3366%//155r8   r   r   s   @r9   r   r   o  sM        A A A A AB      r8   r   c                   $     e Zd Z fdZd Z xZS )r   c                 l    t                                                       |dz  dk    rdnd| _        d S )Nr%   r   r!   )r   r   num_pad_remove)r   r   r   s     r9   r   zWav2Vec2SamePadLayer.__init__  s:    #:Q#>!#C#Caar8   c                 J    | j         dk    r|d d d d d | j          f         }|S Nr   )r   r   s     r9   r   zWav2Vec2SamePadLayer.forward  s;    "")!!!QQQ0F43F2F0F*FGMr8   r   r   s   @r9   r   r     sL        K K K K K      r8   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )Wav2Vec2FeatureEncoderz.Construct the features from raw audio waveformc                    t                                                       j        dk    r7t          d          gfdt	          j        dz
            D             z   }nDj        dk    r!fdt	          j                  D             }nt          dj         d	          t          j        |          | _	        d
| _
        d| _        d S )Ngroupr   r   c                 8    g | ]}t          |d z             S )r!   r   )r   rL   ir   s     r9   rN   z3Wav2Vec2FeatureEncoder.__init__.<locals>.<listcomp>  s>     N N NIJ,Va!eDDDN N Nr8   r!   layerc                 2    g | ]}t          |           S )r   )r   r   s     r9   rN   z3Wav2Vec2FeatureEncoder.__init__.<locals>.<listcomp>  s4       CD*6A>>>  r8   z`config.feat_extract_norm` is z), but has to be one of ['group', 'layer']FT)r   r   feat_extract_normr   rZ   num_feat_extract_layersrR   r   
ModuleListconv_layersgradient_checkpointing_requires_grad)r   r   r   r   s    ` r9   r   zWav2Vec2FeatureEncoder.__init__  s   #w..5fqIIIJ N N N NNSTZTruvTvNwNwN N N KK %00   HMfNlHmHm  KK t1Ittt   =55&+#"r8   c                 P    |                                  D ]	}d|_        
d| _        d S NF)
parametersrequires_gradr   r   params     r9   _freeze_parametersz)Wav2Vec2FeatureEncoder._freeze_parameters  s4    __&& 	( 	(E"'E#r8   c                     |d d d f         }| j         r| j        rd|_        | j        D ]>}| j         r*| j        r#| j        r|                     |j        |          }3 ||          }?|S )NT)r   trainingr   r   r   _gradient_checkpointing_func__call__)r   input_valuesr,   
conv_layers       r9   r   zWav2Vec2FeatureEncoder.forward  s    $QQQW-  	/4= 	/*.M'* 	: 	:J" :t'B :t} : $ A A'!! !
 !+
= 9 9r8   )r0   r1   r2   r3   r   r   r   r   r   s   @r9   r   r     s\        88# # # # #&$ $ $
      r8   r   c                        e Zd Z fdZ xZS )Wav2Vec2FeatureExtractorc                     t                                          |           t          j        d| j        j         d| j        j        d         j         dt                     d S )NzThe class `zD` has been depreciated and will be removed in Transformers v5. Use `r   z
` instead.)r   r   warningswarnr   r0   	__bases__FutureWarningr   r   r   s     r9   r   z!Wav2Vec2FeatureExtractor.__init__  sy       E$.1 E EN,Q/8E E E 		
 	
 	
 	
 	
r8   )r0   r1   r2   r   r   r   s   @r9   r   r     s8        
 
 
 
 
 
 
 
 
r8   r   c                   $     e Zd Z fdZd Z xZS )Wav2Vec2FeatureProjectionc                 .   t                                                       t          j        |j        d         |j                  | _        t          j        |j        d         |j                  | _	        t          j
        |j                  | _        d S )NrJ   eps)r   r   r   r   r   layer_norm_epsr   Linearr   
projectionDropoutfeat_proj_dropoutdropoutr   s     r9   r   z"Wav2Vec2FeatureProjection.__init__  sn    ,vr':@UVVV)FOB$79KLLz&":;;r8   c                     |                      |          }|                     |          }|                     |          }||fS r   )r   r   r   )r   r,   norm_hidden_statess      r9   r   z!Wav2Vec2FeatureProjection.forward  sC    !__];;(:;;]33000r8   r   r   s   @r9   r   r     sG        < < < < <1 1 1 1 1 1 1r8   r   c                   h    e Zd ZdZ	 	 	 	 	 ddededed	ed
ededee         f fdZ	de
j        dedefdZ	 	 	 	 	 dde
j        dee
j                 deee
j                          dee
j                 dee
j                 dedee
j        ee
j                 eee
j                          f         fdZ xZS )Wav2Vec2Attentionz=Multi-headed attention from 'Attention Is All You Need' paper        FTN	embed_dim	num_headsr   
is_decoderr   	is_causalr   c                 
   t                                                       || _        || _        || _        ||z  | _        || _        | j        |z  | j        k    rt          d| j         d| d          | j        dz  | _        || _	        || _
        t          j        |||          | _        t          j        |||          | _        t          j        |||          | _        t          j        |||          | _        d S )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).g      )r   )r   r   r  r  r   head_dimr   rR   scalingr  r	  r   r   k_projv_projq_projout_proj)	r   r  r  r   r  r   r	  r   r   s	           r9   r   zWav2Vec2Attention.__init__  s    	""!Y.MI%$.883dn 3 3%.3 3 3   }d*$"i	94@@@i	94@@@i	94@@@	)YTBBBr8   tensorseq_lenbszc                     |                     ||| j        | j                                      dd                                          S r   )viewr  r  r   
contiguousr   r  r  r  s       r9   _shapezWav2Vec2Attention._shape  s<    {{3GGQQRSUVWWbbdddr8   r,   key_value_statespast_key_valuer=   layer_head_maskoutput_attentionsr?   c                 Z
   |du}|                                 \  }}	}
|                     |          | j        z  }|r6|4|d         j        d         |j        d         k    r|d         }|d         }n>|rU|                     |                     |          d|          }|                     |                     |          d|          }n||                     |                     |          d|          }|                     |                     |          d|          }t          j        |d         |gd          }t          j        |d         |gd          }nT|                     |                     |          d|          }|                     |                     |          d|          }| j	        r||f}|| j
        z  d| j        f} |                     ||	|          j        | } |j        | } |j        | }|                     d          }t          j        ||                    dd                    }|                                 || j
        z  |	|fk    r2t!          d|| j
        z  |	|f d|                                            ||                                 |d|	|fk    r+t!          d	|d|	|f d|                                            |                    || j
        |	|          |z   }|                    || j
        z  |	|          }t"          j                            |d          }||                                 | j
        fk    r-t!          d
| j
        f d|                                            |                    dddd          |                    || j
        |	|          z  }|                    || j
        z  |	|          }|r=|                    || j
        |	|          }|                    || j
        z  |	|          }nd}t"          j                            || j        | j                  }t          j        ||          }|                                 || j
        z  |	| j        fk    r7t!          d|| j
        z  |	| j        f d|                                            |                    || j
        |	| j                  }|                    dd          }|                    ||	| j                  }|                     |          }|||fS )#Input shape: Batch x Time x ChannelNr   r%   r!   rJ   r   z$Attention weights should be of size 	, but is z!Attention mask should be of size z/Head mask for a single layer should be of size )pr    `attn_output` should be of size )ru   r  r  r:   r  r  r  r4   catr  r  r  r  rf   bmmr   rR   r   
functionalsoftmaxr   r   r  r  )r   r,   r  r  r=   r  r  is_cross_attentionr  tgt_lenrM   query_states
key_statesvalue_states
proj_shapesrc_lenattn_weightsattn_weights_reshaped
attn_probsattn_outputs                       r9   r   zWav2Vec2Attention.forward  s    .T9',,..Wa {{=11DL@ 	L*q!'*.>.DQ.GGG (*J)!,LL 	LT[[1A%B%BBLLJ;;t{{3C'D'Db#NNLL'T[[%?%?SIIJ;;t{{='A'A2sKKLN1$5z#BJJJJ 9nQ&7%FANNNLL T[[%?%?SIIJ;;t{{='A'A2sKKL? 	8 ),7NDN*B>
Ct{{<#>>CZP'Z'4
+|+Z8//!$$yz/C/CAq/I/IJJ3#7'"JJJ*dn8LgW^7_ * * %%''* *  
 %""$$a'(BBB ta'8Rtt]k]p]p]r]rtt   (,,S$.'7SSVddL',,S4>-A7GTTL},,\r,BB&##%%$.)::: 1t~FW 1 1',,..1 1   +//2q!<<|?P?PQTVZVdfmov?w?wwL',,S4>-A7GTTL 	)
 %1$5$5c4>7T[$\$\!055cDN6JGU\]]LL$(!]**<4<RVR_*``
i
L99#"6!OOO)C$.4H'SWS`3a ) )$$&&) )  
 "&&sDNGT]SS!++Aq11 "))#wGGmmK001>AAr8   )r  FTFNNNNNF)r0   r1   r2   r3   rC   floatr\   r   r"   r   r4   Tensorr  r   r   r   r   s   @r9   r  r    s       GG  +/C CC C 	C
 C C C (C C C C C C>eU\ eC ec e e e e 488<1526"'vB vB|vB #5<0vB !u|!45	vB
 !.vB "%,/vB  vB 
u|Xel3XeEL>Q5RR	SvB vB vB vB vB vB vB vBr8   r  c                   2    e Zd ZdZ fdZdej        dedefdZ	 	 	 	 	 dd	ej        d
e	ej                 de	e
ej                          de	ej                 de	ej                 dede
ej        e	ej                 e	e
ej                          f         fdZ xZS )Wav2Vec2FlashAttention2aL  
    Wav2Vec2 flash attention module. This module inherits from `Wav2Vec2Attention` as the weights of the module stays
    untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
    flash attention and deal with padding tokens in case the input contains any of them.
    c                 b     t                      j        |i | t                       | _        d S r   )r   r   r   _flash_attn_uses_top_left_mask)r   argskwargsr   s      r9   r   z Wav2Vec2FlashAttention2.__init__  s9    $)&)))
 3V2W2W.W+++r8   r  r  r  c                 F    |                     ||| j        | j                  S r   )r  r  r  r  s       r9   _reshapez Wav2Vec2FlashAttention2._reshape  s    {{3GGGr8   NFr,   r  r  r=   r  r  r?   c           
      R   |rt          d          |d u}|                                \  }}	}
|                     |                     |          d|          }|r^|\|d         j        d         |j        d         k    r:|d                             dd          }|d                             dd          }ng|rV|                     |                     |          d|          }|                     |                     |          d|          }n||                     |                     |          d|          }|                     |                     |          d|          }t          j	        |d                             dd          |gd          }t          j	        |d                             dd          |gd          }nT|                     |                     |          d|          }|                     |                     |          d|          }| j
        r,|                    dd          |                    dd          f}|j        d         }|||d         j        d         z  }|j        }|t          j        k    rt          j                    rt          j                    }n3t          | j        d          r| j        j        }n| j        j        j        }t&                              d	| d
           |                    |          }|                    |          }|                    |          }t-          |||||	| j        r| j        nd| j        | j                  }|                    ||	d          }|                     |          }|sd }|||fS )NzDWav2Vec2FlashAttention2 attention does not support output_attentionsrJ   r   r%   r!   r  r   _pre_quantization_dtypezThe input hidden states seems to be silently casted in float32, this might be related to the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in .r  )r   r	  use_top_left_mask)rR   ru   r<  r  r:   r   r  r  r4   r#  r  rP   float32is_autocast_enabledget_autocast_gpu_dtyper   r   r>  r   loggerwarning_oncetor$   r   r   r	  r8  rf   r  )r   r,   r  r  r=   r  r  r'  r  q_lenrM   r)  r*  r+  
kv_seq_leninput_dtypetarget_dtyper1  r.  s                      r9   r   zWav2Vec2FlashAttention2.forward  s     	ecddd .T9%**,,UA }}T[[%?%?SII 	N*q!'*.>.DQ.GGG (*44Q::J)!,66q!<<LL 	Nt{{3C'D'Db#NNJ==5E)F)FCPPLL't{{='A'A2sKKJ==])C)CRMMLN1$5$?$?1$E$Ez#RXYZZZJ 9nQ&7&A&A!Q&G&G%V\]^^^LL t{{='A'A2sKKJ==])C)CRMML? 	X )221a88,:P:PQRTU:V:VWN%b)
%.+1"55J #(%-''(** 8$;==&?@@ 8#{B#{17$ $ $ $   (??<88L#|44J'??<88L.$(M:DLLsn"A	
 	
 	
 "))#ub99mmK00  	 LL.88r8   r2  )r0   r1   r2   r3   r   r4   r4  rC   r<  r   r   r\   r   r   r   s   @r9   r6  r6    s;        X X X X XHu| Hc H H H H H 488<1526"'i9 i9|i9 #5<0i9 !u|!45	i9
 !.i9 "%,/i9  i9 
u|Xel3XeEL>Q5RR	Si9 i9 i9 i9 i9 i9 i9 i9r8   r6  c                   
    e Zd Z	 	 	 	 	 ddej        deej                 deeej                          deej                 deej                 ded	eej        eej                 eeej                          f         f fd
Z xZ	S )Wav2Vec2SdpaAttentionNFr,   r  r  r=   r  r  r?   c                    |s|At                               d           t                                          ||||||          S |du}|                                \  }}	}
|                     |          }|r6|4|d         j        d         |j        d         k    r|d         }|d         }n>|rU|                     |                     |          d|          }|                     | 	                    |          d|          }n||                     |                     |          d|          }|                     | 	                    |          d|          }t          j        |d         |gd          }t          j        |d         |gd          }nT|                     |                     |          d|          }|                     | 	                    |          d|          }| j        r||f}|                     ||	|          }| j        r
||	dk    rd	nd
}t          j        j                            ||||| j        r| j        nd|          }|                                || j        |	| j        fk    r5t+          d|| j        |	| j        f d|                                           |                    dd          }|                    ||	| j                  }|                     |          }|d|fS )r  Na  Wav2Vec2Model is using Wav2Vec2SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True` or `layer_head_mask` not None. Falling back to the manual attention implementation, but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.)r  r  r=   r  r  r   r%   r!   rJ   r  TFr  )	attn_mask	dropout_pr	  r"  r   )rD  rE  r   r   ru   r  r:   r  r  r  r4   r#  r  r	  r   r%  scaled_dot_product_attentionr   r   r  r  rR   r   rf   r  r  )r   r,   r  r  r=   r  r  r'  r  r(  rM   r)  r*  r+  r	  r1  r   s                   r9   r   zWav2Vec2SdpaAttention.forward  sK     	 ;l   77??!1-- /"3 #    .T9',,..Wa {{=11 	L*q!'*.>.DQ.GGG (*J)!,LL 	LT[[1A%B%BBLLJ;;t{{3C'D'Db#NNLL'T[[%?%?SIIJ;;t{{='A'A2sKKLN1$5z#BJJJJ 9nQ&7%FANNNLL T[[%?%?SIIJ;;t{{='A'A2sKKL? 	8 ),7N{{<#>>
 !N`~/E'TU++DD[`	 h)FF$&*m<dll G 
 
 #t~w!NNN)CRVR_3` ) )$$&&) )  
 "++Aq11 "))#wGGmmK00D.00r8   r2  )
r0   r1   r2   r4   r4  r   r   r\   r   r   r   s   @r9   rL  rL    s        
 488<1526"'f1 f1|f1 #5<0f1 !u|!45	f1
 !.f1 "%,/f1  f1 
u|Xel3XeEL>Q5RR	Sf1 f1 f1 f1 f1 f1 f1 f1 f1 f1r8   rL  )eagersdpaflash_attention_2c                   $     e Zd Z fdZd Z xZS )Wav2Vec2FeedForwardc                    t                                                       t          j        |j                  | _        t          j        |j        |j                  | _	        t          |j        t                    rt          |j                 | _        n|j        | _        t          j        |j        |j                  | _        t          j        |j                  | _        d S r   )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_dropoutr   s     r9   r   zWav2Vec2FeedForward.__init__  s    $&Jv/H$I$I!"$)F,>@X"Y"Yf'-- 	9'-f.?'@D$$'-'8D$If&>@RSS j)>??r8   c                     |                      |          }|                     |          }|                     |          }|                     |          }|                     |          }|S r   )rZ  r^  rX  r_  ra  r   s     r9   r   zWav2Vec2FeedForward.forward  sg    //>>00??11-@@))-88++M::r8   r   r   s   @r9   rU  rU    sL        @ @ @ @ @      r8   rU  c                   &     e Zd Z fdZddZ xZS )Wav2Vec2EncoderLayerc                    t                                                       t          |j                 |j        |j        |j        d          | _        t          j	        |j
                  | _        t          j        |j        |j                  | _        t          |          | _        t          j        |j        |j                  | _        d S )NFr  r  r   r  r   )r   r   WAV2VEC2_ATTENTION_CLASSES_attn_implementationr   num_attention_headsattention_dropout	attentionr   r   r`  r   r   r   r   rU  feed_forwardfinal_layer_normr   s     r9   r   zWav2Vec2EncoderLayer.__init__  s    3F4OP(0,	
 
 
 z&"788,v'9v?TUUU/77 "V-?VEZ [ [ [r8   NFc                    |}|                      |||          \  }}}|                     |          }||z   }|                     |          }||                     |          z   }|                     |          }|f}|r||fz  }|S Nr=   r  )rk  r   r   rl  rm  r   r,   r=   r  attn_residualr.  rM   outputss           r9   r   zWav2Vec2EncoderLayer.forward  s    %)-.L] *8 *
 *
&|Q ]33%566%(9(9-(H(HH--m<< " 	'&Gr8   r   r   r   s   @r9   rd  rd    sQ        \ \ \ \ \       r8   rd  c                   X     e Zd Z fdZ	 	 ddej        deej                 defdZ xZ	S )	#Wav2Vec2EncoderLayerStableLayerNormc                     t                                                       t          |j                 |j        |j        |j        d          | _        t          j	        |j
                  | _        t          j        |j        |j                  | _        t          |          | _        t          j        |j        |j                  | _        t%          |dd           t'          |          | _        d S d | _        d S )NFrf  r   adapter_attn_dim)r   r   rg  rh  r   ri  rj  rk  r   r   r`  r   r   r   r   rU  rl  rm  getattrWav2Vec2AttnAdapterLayeradapter_layerr   s     r9   r   z,Wav2Vec2EncoderLayerStableLayerNorm.__init__  s    3F4OP(0,	
 
 
 z&"788,v'9v?TUUU/77 "V-?VEZ [ [ [6-t44@!9&!A!AD!%Dr8   NFr,   r=   r  c                 J   |}|                      |          }|                     |||          \  }}}|                     |          }||z   }||                     |                     |                    z   }| j        ||                     |          z   }|f}|r||fz  }|S ro  )r   rk  r   rl  rm  rz  rq  s           r9   r   z+Wav2Vec2EncoderLayerStableLayerNorm.forward  s     &66)-.L] *8 *
 *
&|Q ]33%5%(9(9$:O:OP]:^:^(_(__))D,>,>},M,MMM " 	'&Gr8   r   )
r0   r1   r2   r   r4   r4  r   r\   r   r   r   s   @r9   ru  ru    s~        & & & & &* 26"'	 | !.  	       r8   ru  c                   d     e Zd Z fdZ	 	 	 	 ddej        deej                 deded	ef
d
Z	 xZ
S )Wav2Vec2Encoderc                    t                                                       | _        t                    | _        t          j        j        j                  | _	        t          j
        j                  | _        t          j        fdt          j                  D                       | _        d| _        j        dk    | _        d S )Nr   c                 .    g | ]}t                    S r7   )rd  rL   rM   r   s     r9   rN   z,Wav2Vec2Encoder.__init__.<locals>.<listcomp>  s"    $k$k$ka%9&%A%A$k$k$kr8   FrS  r   r   r   r   pos_conv_embedr   r   r   r   r   r   r`  r   r   rZ   num_hidden_layerslayersr   rh  _use_flash_attention_2r   s    `r9   r   zWav2Vec2Encoder.__init__  s    =fEE,v'9v?TUUUz&"788m$k$k$k$k5QWQiKjKj$k$k$kll&+#&,&AEX&X###r8   NFTr,   r=   r  output_hidden_statesreturn_dictc                 (   |rdnd }|rdnd }||                     d                              dd|j        d                   }d|| <   | j        r|d|v r|nd }nd|d d d d d d f                             |j                  z
  }|t          j        |j                  j        z  }|	                    |j        d         d|j        d         |j        d                   }| 
                    |          }	||	z   }|                     |          }|                     |          }t                      pt          |           }
| j        D ]}|r||fz   }t          j        g           }| j        r|| j        j        k     rdnd	}|r|
rB| j        r%| j        r|                     |j        |||          }n ||||
          }|d         }|rd}|r||d         fz   }|r||fz   }|st/          d |||fD                       S t1          |||          S )Nr7   rJ   r!   r%   r         ?rO   TFrp  NNc              3      K   | ]}||V  	d S r   r7   rL   vs     r9   	<genexpr>z*Wav2Vec2Encoder.forward.<locals>.<genexpr>5  (      mmq_`_l_l_l_l_lmmr8   last_hidden_stater,   r-   )	unsqueezerepeatr:   r  rF  rP   r4   finfominexpandr  r   r   r   r   r  rU   r   r   	layerdropr   r   r   tupler   r   r,   r=   r  r  r  all_hidden_statesall_self_attentionsexpand_attention_maskposition_embeddingssynced_gpusr   dropout_probabilityskip_the_layerlayer_outputss                  r9   r   zWav2Vec2Encoder.forward  s    #7@BBD$5?bb4%$2$<$<R$@$@$G$G1mNabcNd$e$e!45M001* 	4B4NSTXfSfSfmq "%~aaatQQQ6F'G'J'JQ^Qd'J'e'e!e!/%+m>Q2R2R2V!V!/!6!6"(+Q0DR0H.J^_aJb" " #11-@@%(;;66]33022R6LT6R6R[ 	P 	PE# I$58H$H! #(*R..%)]o8KdkNc8c8cTTjoN! 1[ 1. 
4= 
$($E$E%&)	% %MM %*E%nXi% % %M !.a 0 - ,  P&9]1=M<O&O# 	E 1]4D D 	nmm]4EGZ$[mmmmmm++*
 
 
 	
r8   NFFT)r0   r1   r2   r   r4   r  r   r4  r\   r   r   r   s   @r9   r}  r}    s        Y Y Y Y Y 26"'%* G
 G
|G
 !.G
  	G

 #G
 G
 G
 G
 G
 G
 G
 G
 G
r8   r}  c                   .     e Zd Z fdZ	 	 	 	 ddZ xZS )Wav2Vec2EncoderStableLayerNormc                    t                                                       | _        t                    | _        t          j        j        j                  | _	        t          j
        j                  | _        t          j        fdt          j                  D                       | _        d| _        j        dk    | _        d S )Nr   c                 .    g | ]}t                    S r7   )ru  r  s     r9   rN   z;Wav2Vec2EncoderStableLayerNorm.__init__.<locals>.<listcomp>E  s"    bbbQ088bbbr8   FrS  r  r   s    `r9   r   z'Wav2Vec2EncoderStableLayerNorm.__init__>  s    =fEE,v'9v?TUUUz&"788mbbbb%H`BaBabbb
 
 ',#&,&AEX&X###r8   NFTc                 X   |rdnd }|rdnd }||                     d                              dd|j        d                   }||                    |j                  z  }| j        r|d|v r|nd }nd|d d d d d d f                             |j                  z
  }|t          j        |j                  j        z  }|	                    |j        d         d|j        d         |j        d                   }| 
                    |          }	||	z   }|                     |          }t                      pt          |           }
| j        D ]}|r||fz   }t          j        g           }| j        r|| j        j        k     rdnd	}|r|
rB| j        r%| j        r|                     |j        |||          }n ||||
          }|d         }|rd}|r||d         fz   }|                     |          }|r||fz   }|st/          d |||fD                       S t1          |||          S )Nr7   rJ   r!   r%   rO   r   r  TFrp  r  c              3      K   | ]}||V  	d S r   r7   r  s     r9   r  z9Wav2Vec2EncoderStableLayerNorm.forward.<locals>.<genexpr>  r  r8   r  )r  r  r:   rF  rP   r  r4   r  r  r  r  r   r   r   r  rU   r   r   r  r   r   r   r   r  r   r  s                  r9   r   z&Wav2Vec2EncoderStableLayerNorm.forwardJ  s    #7@BBD$5?bb4%$2$<$<R$@$@$G$G1mNabcNd$e$e!),A,D,D=K^,D,_,__M* 	4B4NSTXfSfSfmq "%~aaatQQQ6F'G'J'JQ^Qd'J'e'e!e!/%+m>Q2R2R2V!V!/!6!6"(+Q0DR0H.J^_aJb" " #11-@@%(;;]33022R6LT6R6R[ 	P 	PE# I$58H$H! #(*R..%)]o8KdkNc8c8cTTjoN! 1[ 1 . 
4= 
$($E$E%&)	% %MM %*E%nXi% % %M !.a 0 - ,  P&9]1=M<O&O#66 	E 1]4D D 	nmm]4EGZ$[mmmmmm++*
 
 
 	
r8   r  r   r   s   @r9   r  r  =  sg        
Y 
Y 
Y 
Y 
Y "I
 I
 I
 I
 I
 I
 I
 I
r8   r  c                   B     e Zd ZdZ fdZedd            ZddZ xZS )Wav2Vec2GumbelVectorQuantizerz
    Vector quantization using gumbel softmax. See `[CATEGORICAL REPARAMETERIZATION WITH
    GUMBEL-SOFTMAX](https://arxiv.org/pdf/1611.01144.pdf) for more information.
    c                    t                                                       |j        | _        |j        | _        |j        | j        z  dk    r t          d|j         d| j         d          t          j	        t          j        d| j        | j        z  |j        | j        z                      | _        t          j        |j        d         | j        | j        z            | _        d| _        d S )Nr   z`config.codevector_dim z5 must be divisible by `config.num_codevector_groups` z for concatenationr!   rJ   r%   )r   r   num_codevector_groupsr   num_codevectors_per_groupnum_varscodevector_dimrR   r   	Parameterr4   r5   codevectorsr   r   weight_projtemperaturer   s     r9   r   z&Wav2Vec2GumbelVectorQuantizer.__init__  s     68 4?2a77Y&*? Y Y59_Y Y Y   <a4=!@&BW[_[jBjkk
 
 9V_R%8$/DM:YZZ r8   Nc           	         ||                                 d d d d f                             | j                  }t          j        || t          j        |                     } |                     d          |                                z  }n|                     d          }t          j        t          j        |t          j	        |dz             z  d                                                     }|S )Nr   r  gHz>rJ   )
flattenr  r:   r4   where
zeros_likerW   meanexplog)probsmaskmask_extendedmarginal_probs
perplexitys        r9   _compute_perplexityz1Wav2Vec2GumbelVectorQuantizer._compute_perplexity  s     LLNN111dD=9@@MMMKue6Fu6M6MNNE"YY1Y--

:NN"ZZAZ..NY	.59^VZEZ;[;[*[ac d d ddeeiikk
r8   c                    |j         \  }}}|                     |          }|                    ||z  | j        z  d          }| j        rt
          j                            |                                | j	        d          
                    |          }t          j        |                    ||z  | j        d                                          d          }|                     ||          }n|                    d          }	|                    |j                                       d|	                    dd          d          }|                    ||z  | j        d          }|                     ||          }|                    ||z  d          }|                    d          | j        z  }
|
                    ||z  | j        | j        d          }|                    d                              ||d          }||fS )NrJ   T)tauhardr  r!   r  r   )r:   r  r  r   r   r   r%  gumbel_softmaxr3  r  type_asr4   r&  r  argmax	new_zerosscatter_r  r  r  rW   )r   r,   rs   rh   rH   r   codevector_probscodevector_soft_distr  codevector_idxcodevectors_per_groupr  s               r9   r   z%Wav2Vec2GumbelVectorQuantizer.forward  s   3@3F0
O[ ((77%**:+G$/+Y[]^^= 	W!};;##%%4+;$  <    gm$$ 
 $)="":#?RTUU[[]]ce$ $ $  112FHYZZJJ +11b199N,66}7JKKTTN''A..     044Z/5QSWSbdfgg112BDUVVJ+00o1MrRR 0 : :2 > >AQ Q+00o1Mt`d`moqrr!oob))..z?BOOJ&&r8   r   )	r0   r1   r2   r3   r   staticmethodr  r   r   r   s   @r9   r  r    sv         
    ( 	 	 	 \	#' #' #' #' #' #' #' #'r8   r  c                   $     e Zd Z fdZd Z xZS )Wav2Vec2Adapterc                    t                                                       j        j        k    rCt	          j        j        j                  | _        t	          j        j                  | _        nd x| _        | _        t	          j	        fdt          j                  D                       | _        j        | _        d S )Nc              3   6   K   | ]}t                    V  d S r   )Wav2Vec2AdapterLayerr  s     r9   r  z+Wav2Vec2Adapter.__init__.<locals>.<genexpr>  s,      #k#kQ$8$@$@#k#k#k#k#k#kr8   )r   r   output_hidden_sizer   r   r   projr   proj_layer_normr   rZ   num_adapter_layersr  r  r   s    `r9   r   zWav2Vec2Adapter.__init__  s     $(:::	&"4f6OPPDI#%<0I#J#JD  /33DI,m#k#k#k#k%PVPiJjJj#k#k#kkk)r8   c                 X   | j         1| j        *|                      |          }|                     |          }|                    dd          }| j        D ]=}t          j                                        }| j        r|| j        k    r ||          }>|                    dd          }|S r   )r  r  r   r  rS   rT   r   r  )r   r,   r   layerdrop_probs       r9   r   zWav2Vec2Adapter.forward  s    9 T%9%E IIm44M 00??M%//155[ 	5 	5EY--//N= 5^dn%D%D %m 4 4%//155r8   r   r   s   @r9   r  r    sG        * * * * *      r8   r  c                   $     e Zd Z fdZd Z xZS )r  c                     t                                                       t          j        |j        d|j        z  |j        |j        d          | _        d S )Nr%   r!   )r   r   )r   r   r   r   r  adapter_kernel_sizeadapter_strider   r   s     r9   r   zWav2Vec2AdapterLayer.__init__  sU    I%))&(
 
 
			r8   c                 r    |                      |          }t          j                            |d          }|S )Nr!   r  )r   r   r%  glur   s     r9   r   zWav2Vec2AdapterLayer.forward  s3    		-00))-Q)??r8   r   r   s   @r9   r  r    sG        
 
 
 
 
      r8   r  c                   4     e Zd Z fdZdej        fdZ xZS )ry  c                 t   t                                                       |j        | _        |j        | _        t          j        | j                  | _        t          j	        | j        | j                  | _
        t          j                    | _        t          j	        | j        | j                  | _        dS )z
        Implements adapter modules directly with 3D tensor weight as parameters and without using ModuleList to speed
        up training throughput.
        N)r   r   rw  	input_dimr   
hidden_dimr   r   normr   linear_1ReLUact_fnlinear_2r   s     r9   r   z!Wav2Vec2AttnAdapterLayer.__init__  s    
 	0 ,L11		$/4>BBgii	$.$/BBr8   r,   c                     |                      |          }|                     |          }|                     |          }|                     |          }|S r   )r  r  r  r  r   s     r9   r   z Wav2Vec2AttnAdapterLayer.forward"  sL    		-00m44M22m44r8   )r0   r1   r2   r   r4   r5   r   r   r   s   @r9   ry  ry    s[        C C C C CU%6        r8   ry  c                       e Zd ZdZeZdZdZdZdZ	dZ
d Z	 ddeej        ef         dee         fd	Z	 dd
edej        fdZd Zd ZddefdZdS )Wav2Vec2PreTrainedModelz
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    wav2vec2r   Tc           
         t          |t                    rL|j                                         |j                                         d|j        _        d|j        _        dS t          |t                    ro|j        j        j	        
                    dd           |j        j        j	                                         t          j                            |j                   dS t          |t"                    rt          j        
                    |j        j        ddt'          j        d|j        j        d         |j        j        z  z            z             t          j                            |j        j        d           dS t          |t0                    r}t'          j        d|j        j        z            }t          j                            |j        j        | |           t          j                            |j        j        | |           dS t          |t          j                  rT|j        j	        
                    d| j        j                   |j         |j        j	                                         dS dS t          |t          j        t          j        f          r?|j        j	                                         |j        j	                             d	           dS t          |t          j!                  rt          j        "                    |j                   |j        [t'          j        |j#        |j        |j        d         z  z            }t          j                            |j        | |           dS dS dS )
zInitialize the weightsTr  r!   )r  stdr   r%   )abNr  )$r[  Wav2Vec2ForPreTrainingproject_hidreset_parameters	project_q_is_hf_initializedr  r  r   datanormal_r   zero_r   inituniform_r  r   r   mathsqrtr   in_channels	constant_r   r   in_featuresr   r   initializer_ranger   r   fill_r   kaiming_normal_r   )r   moduleks      r9   _init_weightsz%Wav2Vec2PreTrainedModel._init_weights9  s    f455 "	9//111--///48F126F/// =>> 	9%*222CCC#(..000GV/00000 ?@@ 	9GOO"	!v{'>q'AFKD['["\]]]    
 Gfk.22222 9:: 	9	!f/;;<<AGV.5!qAAAGV.3rQ?????	** 	9M&&CT[5R&SSS{& &&((((( '&r| <== 	9K""$$$M$$S)))))	** 	9G##FM222{&Ifmv/AFDVWXDY/YZ[[  a 88888	9 	9 '&r8   Nri   add_adapterc                    || j         j        n|}d }t          | j         j        | j         j                  D ]\  }} ||||          }|r3t          | j         j                  D ]} ||d| j         j                  }|S )zH
        Computes the output length of the convolutional layers
        Nc                 <    t          j        | |z
  |d          dz   S )Nfloor)rounding_moder!   )r4   divrE   r   r   s      r9   _conv_out_lengthzRWav2Vec2PreTrainedModel._get_feat_extract_output_lengths.<locals>._conv_out_lengthi  s&     9\K7wWWWZ[[[r8   r!   )r   r  zipr   r   rZ   r  r  )r   ri   r  r  r   r   rM   s          r9    _get_feat_extract_output_lengthsz8Wav2Vec2PreTrainedModel._get_feat_extract_output_lengths`  s     2=1Ddk--+	\ 	\ 	\
 $'t{'>@W#X#X 	Q 	QK,,]KPPMM 	_4;9:: _ _ 0 04;C] ^ ^r8   feature_vector_lengthr=   c                    |                     d          d d df         }|                     ||          }|                    t          j                  }|j        d         }t          j        ||f|j        |j                  }d|t          j	        |j        d         |j                  |dz
  f<   |
                    dg                               d          
                    dg                                          }|S )NrJ   r  r  r   )rP   devicer!   )r  )cumsumr  rF  r4   longr:   r[   rP   r  r^   flipr\   )r   r  r=   r  non_padded_lengthsoutput_lengthsrh   s          r9   "_get_feature_vector_attention_maskz:Wav2Vec2PreTrainedModel._get_feature_vector_attention_maskw  s   
 ,22r2::111b5A>>?Q_j>kk'**5:66#)!,
./~7KTbTi
 
 
 uv^%9!%<^EZ[[[]kno]opq',,bT2299"==BBB4HHMMOOr8   c                    | j         j        t          | j         d          i }|                                 D ]N\  }}t          |t                    r4|                                D ]\  }}||d                    ||g          <    Ot          | t                    r9| j
                                        D ]\  }}||d                    d|g          <    |S )NzF has no adapter layers. Make sure to define `config.adapter_attn_dim`.r?  lm_head)r   rw  rR   r   named_modulesr[  ry  named_parametersjoinWav2Vec2ForCTCr  )r   adapter_weightsr   r  
param_namer   s         r9   _get_adaptersz%Wav2Vec2PreTrainedModel._get_adapters  s    ;'/vvvwww ..00 	J 	JLD&&":;; J)/)@)@)B)B J J%JDIOCHHdJ-?$@$@AAdN++ 	E#|<<>> E Ee?D)T): ; ;<<r8   c                     |                                  D ],}t          |t                    r|                     |           -t          | t                    r|                     | j                   dS dS )zc
        (Re-)initialize attention adapter layers and lm head for adapter-only fine-tuning
        N)modulesr[  ry  r  r  r  )r   r  s     r9   init_adapter_layersz+Wav2Vec2PreTrainedModel.init_adapter_layers  s}    
 llnn 	+ 	+F&":;; +""6*** dN++ 	-t|,,,,,	- 	-r8   target_langc                 6   | j         j        t          d| d          || j        k    r"|s t                              d| d           dS |                    dd          }|                    dd          }|                    d	d          }|                    d
d          }|                    dd          }|                    dd          }	|                    dd          }
|                    dd          }|                    dt                      rdnd          }|
-t          j	        dt                     |	t          d          |
}	| j         j        }d}|dur|t                              |          }	 t          |||||||	||	  	        }t          |          }n9# t           $ r |r Y n*t"          $ r |rt!          d| d| d| d          Y nw xY w|t$                              |          }	 t          |||||||	||	  	        }t&          rddini }t)          j        |fddi|}n1# t           $ r  t"          $ r t!          d| d| d| d          w xY w|                                 t/          |                                          t/                                                    z
  }t/                                                    t/          |                                          z
  }t3          |          dk    r)t          d| dd                    |           d          t3          |          dk    r)t          d| dd                    |           d          |d         j        d         }|| j         j        k    r=t;          j        | j         j        || j         | j!                   | _"        || j         _        fd!|#                                D             }| $                    |d"           || _        dS )#a  
        Load a language adapter model from a pre-trained adapter model.

        Parameters:
            target_lang (`str`):
                Has to be a language id of an existing adapter weight. Adapter weights are stored in the format
                adapter.<lang>.safetensors or adapter.<lang>.bin
            force_load (`bool`, defaults to `True`):
                Whether the weights shall be loaded even if `target_lang` matches `self.target_lang`.
            cache_dir (`Union[str, os.PathLike]`, *optional*):
                Path to a directory in which a downloaded pretrained model configuration should be cached if the
                standard cache should not be used.
            force_download (`bool`, *optional*, defaults to `False`):
                Whether or not to force the (re-)download of the model weights and configuration files, overriding the
                cached versions if they exist.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible.
                Will be removed in v5 of Transformers.
            proxies (`Dict[str, str]`, *optional*):
                A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
            local_files_only(`bool`, *optional*, defaults to `False`):
                Whether or not to only look at local files (i.e., do not try to download the model).
            token (`str` or `bool`, *optional*):
                The token to use as HTTP bearer authorization for remote files. If `True`, or not specified, will use
                the token generated when running `huggingface-cli login` (stored in `~/.huggingface`).
            revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
                identifier allowed by git.

                <Tip>

                To test a pull request you made on the Hub, you can pass `revision="refs/pr/<pr_number>"`.

                </Tip>

            mirror (`str`, *optional*):
                Mirror source to accelerate downloads in China. If you are from China and have an accessibility
                problem, you can set this option to resolve it. Note that we do not guarantee the timeliness or safety.
                Please refer to the mirror site for more information.

        <Tip>

        Activate the special ["offline-mode"](https://huggingface.co/transformers/installation.html#offline-mode) to
        use this method in a firewalled environment.

        </Tip>

        Examples:

        ```python
        >>> from transformers import Wav2Vec2ForCTC, AutoProcessor

        >>> ckpt = "facebook/mms-1b-all"
        >>> processor = AutoProcessor.from_pretrained(ckpt)
        >>> model = Wav2Vec2ForCTC.from_pretrained(ckpt, target_lang="eng")
        >>> # set specific language
        >>> processor.tokenizer.set_target_lang("spa")
        >>> model.load_adapter("spa")
        ```
        NzCannot load_adapter for - if `config.adapter_attn_dim` is not defined.z#Adapter weights are already set to r?  	cache_dirforce_downloadFresume_downloadproxieslocal_files_onlytokenuse_auth_tokenrevisionuse_safetensorszrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.zV`token` and `use_auth_token` are both specified. Please set only the argument `token`.)filenamer)  r*  r+  r,  r-  r/  r(  zCan't load the model for 'z'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'z=' is the correct path to a directory containing a file named weights_onlyTmap_locationcpur   zThe adapter weights z has unexpected keys: z, z has missing keys: zlm_head.weightr  rP   c                 N    i | ]!\  }}||                     |                   "S r7   )rF  )rL   r  r  r  s      r9   
<dictcomp>z8Wav2Vec2PreTrainedModel.load_adapter.<locals>.<dictcomp>a  s0    QQQdaaoa011QQQr8   )strict)%r   rw  rR   r%  rD  warningpopr   r   r   r   _name_or_pathWAV2VEC2_ADAPTER_SAFE_FILEformatr   safe_load_fileEnvironmentError	ExceptionWAV2VEC2_ADAPTER_PT_FILEr   r4   loadr!  setkeysr_   r  r:   
vocab_sizer   r   r  r  rP   r  itemsload_state_dict)r   r%  
force_loadr:  r(  r)  r*  r+  r,  r-  r.  r/  r0  model_path_or_id
state_dictfilepathweight_pathweights_only_kwargunexpected_keysmissing_keystarget_vocab_sizer  s                        @r9   load_adapterz$Wav2Vec2PreTrainedModel.load_adapter  sJ   ~ ;'/rrrrsss$***:*NNOOOOPPPFJJ{D11	$4e<< **%6==**Y--!::&8%@@

7D))$4d;;::j$// **%6@X@Z@Z8e`eff%M E     l   #E;4
 %''188EEH)$%#1$3#%5%'
 
 
 ,K88

#   "   
    " *J5E J J=MJ J ?GJ J J    /66{CCH )$%#1$3#%5%'
 
 
 @c%jnd%;%;hj""Z !& ) 

 $       &F1A F F9IF F ;CF F F   ,,..joo//0037K7K7M7M3N3NN?//1122S9J9J5K5KK!##tKttW[W`W`apWqWqtttuuu""nKnnTXT]T]^jTkTknnnooo ''78>qA 6669.0A$+]a]g  DL &7DK" RQQQj>N>N>P>PQQQ
Z666 's$    'F( (G7$GG>9H8 8.I&r   )T)r0   r1   r2   r3   r"   config_classbase_model_prefixmain_input_namesupports_gradient_checkpointing_supports_flash_attn_2_supports_sdpar  r   r4   
LongTensorrC   r   r\   r  r  r!  r$  r]  rQ  r7   r8   r9   r  r  ,  s        
 "L"$O&*#!N%9 %9 %9P Z^ "5#3S#89HPQU   0 Y] %(:?:J   (   - - -}' }' }' }' }' }' }' }'r8   r  a  
    Wav2Vec2 was proposed in [wav2vec 2.0: A Framework for Self-Supervised Learning of Speech
    Representations](https://arxiv.org/abs/2006.11477) by Alexei Baevski, Henry Zhou, Abdelrahman Mohamed, Michael
    Auli.

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

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

    Parameters:
        config ([`Wav2Vec2Config`]): 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.
a  
    Args:
        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]` or a `numpy.ndarray`, *e.g.* via 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 [`Wav2Vec2Processor.__call__`] for details.
        attention_mask (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing convolution and attention on padding token indices. Mask values selected in `[0,
            1]`:

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

            [What are attention masks?](../glossary#attention-mask)

            <Tip warning={true}>

            `attention_mask` should only be passed if the corresponding processor has `config.return_attention_mask ==
            True`. For all models whose processor has `config.return_attention_mask == False`, such as
            [wav2vec2-base](https://huggingface.co/facebook/wav2vec2-base-960h), `attention_mask` should **not** be
            passed to avoid degraded performance when doing batched inference. For such models `input_values` should
            simply be padded with 0 and passed without `attention_mask`. Be aware that these models also yield slightly
            different results depending on whether `input_values` is padded or not.

            </Tip>

        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
zbThe bare Wav2Vec2 Model transformer outputting raw hidden-states without any specific head on top.c                   t    e Zd Zdef fdZd Zd Z	 	 ddej        de	ej                 de	ej
                 fd	Z ee           eeeed
e          	 	 	 	 	 dde	ej                 de	ej                 de	ej                 de	e         de	e         de	e         deeef         fd                        Z xZS )Wav2Vec2Modelr   c                    t                                          |           || _        t          |          | _        t          |          | _        |j        dk    s|j        dk    rBt          j
        t          j        |j                                                            | _        |j        rt#          |          | _        nt'          |          | _        |j        rt+          |          nd | _        |                                  d S )Nr  )r   r   r   r   feature_extractorr   feature_projectionmask_time_probmask_feature_probr   r  r4   r4  r   r  masked_spec_embeddo_stable_layer_normr  encoderr}  r  r  adapter	post_initr   s     r9   r   zWav2Vec2Model.__init__  s       !7!?!?";F"C"C  3&&&*BS*H*H%'\%,v?Q2R2R2[2[2]2]%^%^D"& 	39&AADLL*622DL282DNv...$ 	r8   c                 b    t          j        dt                     |                                  dS z
        Calling this function will disable the gradient computation for the feature encoder so that its parameters will
        not be updated during training.
        The method `freeze_feature_extractor` is deprecated and will be removed in Transformers v5. Please use the equivalent `freeze_feature_encoder` method instead.Nr   r   r   freeze_feature_encoderr   s    r9   freeze_feature_extractorz&Wav2Vec2Model.freeze_feature_extractor  ;    
 	Q	
 	
 	

 	##%%%%%r8   c                 8    | j                                          dS 
        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   rj  s    r9   ri  z$Wav2Vec2Model.freeze_feature_encoder  s    
 	1133333r8   Nr,   rs   r=   c                    t          | j        dd          s|S |                                \  }}}|#| j                            |j                  ||<   n| j        j        dk    r| j        r|t          ||f| j        j        | j        j	        || j        j
                  }t          j        ||j        t          j                  }| j                            |j                  ||<   | j        j        dk    r| j        rt          ||f| j        j        | j        j        | j        j                  }t          j        ||j        t          j                  }|dddf                             d|d          }d||<   |S )	z
        Masks extracted features along time axis and/or along feature axis according to
        [SpecAugment](https://arxiv.org/abs/1904.08779).
        apply_spec_augmentTNr   )r;   r<   r=   r>   r5  )r;   r<   r>   rJ   )rx  r   ru   r`  rF  rP   r^  r   rp   mask_time_lengthmask_time_min_masksr4   r  r  r\   r_  mask_feature_lengthmask_feature_min_masksr  )r   r,   rs   r=   rh   rH   r   mask_feature_indicess           r9   _mask_hidden_statesz!Wav2Vec2Model._mask_hidden_states  s    t{$8$?? 	!   4A3E3E3G3G0
O[(/3/E/H/HI\/]/]M+,,['!+++ 5_-+4 K8-+9! ! ! !&->}G[chcm n n n/3/E/H/HI\/]/]M+,;(1,,,#8[)+7 K;+<	$ $ $  $)<0D]Mainis#t#t#t #74#@#G#GO]_#`#` 23M./r8   audio
checkpointoutput_typerR  modalityexpected_outputr   r  r  r  r?   c                 :   ||n| j         j        }||n| j         j        }||n| j         j        }|                     |          }|                    dd          }|#|                     |j        d         |d          }|                     |          \  }}| 	                    |||          }| 
                    |||||          }	|	d         }| j        |                     |          }|s||f|	dd          z   S t          |||	j        |	j                  S )	Nr!   r%   Fr  )rs   r=   r=   r  r  r  r   )r  extract_featuresr,   r-   )r   r  r  use_return_dictr\  r   r  r:   r]  rw  rb  rc  r   r,   r-   )
r   r   r=   rs   r  r  r  r  r,   encoder_outputss
             r9   r   zWav2Vec2Model.forward  s|   " 2C1N--TXT_Tq$8$D  $+Jj 	 &1%<kk$+B]11,??+55a;;%!DD &q)>u E  N +/*A*ABR*S*S''00->~ 1 
 
 ,,)/!5# ' 
 
 (*<# LL77M 	K!#34qrr7JJJ&+-)7&1	
 
 
 	
r8   r  NNNNN)r0   r1   r2   r"   r   rk  ri  r4   r5   r   rX  rw  r   WAV_2_VEC_2_INPUTS_DOCSTRINGr   _CHECKPOINT_FOR_DOCr   _CONFIG_FOR_DOC_EXPECTED_OUTPUT_SHAPEr4  r\   r   r   r   r   r   s   @r9   rZ  rZ    s       
~      (
& 
& 
&4 4 4 :>59	, ,(, $E$56, !!12	, , , ,\ +*+GHH&+$.   269=,0/3&*2
 2
u|,2
 !.2
 $E$56	2

 $D>2
 'tn2
 d^2
 
u--	.2
 2
 2
  IH2
 2
 2
 2
 2
r8   rZ  z5Wav2Vec2 Model with a quantizer and `VQ` head on top.c                       e Zd Zdef fdZdefdZd Zd Ze		 dde
j        d	e
j        d
e
j        defd            Z ee           eee          	 	 	 	 	 	 ddee
j                 dee
j                 dee
j                 dee
j                 dee         dee         dee         deeef         fd                        Z xZS )r  r   c                    t                                          |           t          |          | _        t	          j        |j                  | _        t          |          | _	        t	          j
        |j        |j                  | _        t	          j
        |j        |j                  | _        |                                  d S r   )r   r   rZ  r  r   r   feat_quantizer_dropoutdropout_featuresr  	quantizerr   r   proj_codevector_dimr  r  r  rd  r   s     r9   r   zWav2Vec2ForPreTraining.__init__:  s       %f-- "
6+H I I6v>>9V%79STT6#8&:TUU 	r8   r  c                     || j         _        dS )zb
        Set the Gumbel softmax temperature to a given value. Only necessary for training
        N)r  r  )r   r  s     r9   set_gumbel_temperaturez-Wav2Vec2ForPreTraining.set_gumbel_temperatureG  s     &1"""r8   c                 b    t          j        dt                     |                                  dS rf  rh  rj  s    r9   rk  z/Wav2Vec2ForPreTraining.freeze_feature_extractorM  rl  r8   c                 B    | j         j                                         dS rn  r  r\  r   rj  s    r9   ri  z-Wav2Vec2ForPreTraining.freeze_feature_encoderY  !    
 	'::<<<<<r8   皙?target_featuresnegative_featurespredicted_featuresc                     t          j        | |gd          } t          j        |                                |                                 d                              |           }||z  }|S )z
        Compute logits for contrastive loss based using cosine similarity as the distance measure between
        `[positive_feature, negative_features]` and `[predicted_features]`. Additionally, temperature can be applied.
        r   r  rJ   )r4   r#  cosine_similarityr3  r  )r  r  r  r  logitss        r9   compute_contrastive_logitsz1Wav2Vec2ForPreTraining.compute_contrastive_logits`  ss      )_6G$HaPPP();)A)A)C)C_EZEZE\E\bdeeemm
 

 +%r8   )r{  rR  Nr   r=   rs   ry   r  r  r  r?   c           
      `   ||n| j         j        }||                    t          j                  }|                     ||||||          }|                     |d                   }	|                     |d                   }
|#|                     |
j	        d         |d          }| 
                    |
|          \  }}|                    | j        j        j                  }|                     |          }dx}x}}||j	        \  }}}|                    d|          |                                                    d                   }|                    ||d|                              d	ddd
          }|                     |dddf         ||	| j         j                  }||k                        d          }|                                rt+          d          |dd         |<   |                    dd	                              d|                    d                    }d|                                z
  dz                      dd                                          }t4          j                            |                                |d          }| j         j        | j         j        z  }||z
  |z  |                                z  }|| j         j         |z  z   }|s#|||	||f|d	d         z   S |	||f|d	d         z   S tC          ||	|||j"        |j#        ||          S )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.
        sampled_negative_indices (`torch.BoolTensor` of shape `(batch_size, sequence_length, num_negatives)`, *optional*):
            Indices indicating which quantized target vectors are used as negative sampled vectors in contrastive loss.
            Required input for pre-training.

        Returns:

        Example:

        ```python
        >>> import torch
        >>> from transformers import AutoFeatureExtractor, Wav2Vec2ForPreTraining
        >>> from transformers.models.wav2vec2.modeling_wav2vec2 import _compute_mask_indices, _sample_negative_indices
        >>> from datasets import load_dataset

        >>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base")
        >>> model = Wav2Vec2ForPreTraining.from_pretrained("facebook/wav2vec2-base")

        >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
        >>> input_values = feature_extractor(ds[0]["audio"]["array"], return_tensors="pt").input_values  # Batch size 1

        >>> # compute masked indices
        >>> batch_size, raw_sequence_length = input_values.shape
        >>> sequence_length = model._get_feat_extract_output_lengths(raw_sequence_length).item()
        >>> mask_time_indices = _compute_mask_indices(
        ...     shape=(batch_size, sequence_length), mask_prob=0.2, mask_length=2
        ... )
        >>> sampled_negative_indices = _sample_negative_indices(
        ...     features_shape=(batch_size, sequence_length),
        ...     num_negatives=model.config.num_negatives,
        ...     mask_time_indices=mask_time_indices,
        ... )
        >>> mask_time_indices = torch.tensor(data=mask_time_indices, device=input_values.device, dtype=torch.long)
        >>> sampled_negative_indices = torch.tensor(
        ...     data=sampled_negative_indices, device=input_values.device, dtype=torch.long
        ... )

        >>> with torch.no_grad():
        ...     outputs = model(input_values, mask_time_indices=mask_time_indices)

        >>> # compute cosine similarity between predicted (=projected_states) and target (=projected_quantized_states)
        >>> cosine_sim = torch.cosine_similarity(outputs.projected_states, outputs.projected_quantized_states, dim=-1)

        >>> # show that cosine similarity is much higher than random
        >>> cosine_sim[mask_time_indices.to(torch.bool)].mean() > 0.5
        tensor(True)

        >>> # for contrastive loss training model should be put into train mode
        >>> model = model.train()
        >>> loss = model(
        ...     input_values, mask_time_indices=mask_time_indices, sampled_negative_indices=sampled_negative_indices
        ... ).loss
        ```N)r=   r  r  rs   r  r   r!   Fr  )rs   rJ   r%   r	   z-infirW   )	reduction)r(   r)   r*   r+   r,   r-   r.   r/   )$r   r  rF  r4   r\   r  r  r  r  r:   r  r  r   rP   r  r  permuter  contrastive_logits_temperatureallanyr3  r   rf   ru   r  r   r%  cross_entropyr  r  rW   diversity_loss_weightr'   r,   r-   )r   r   r=   rs   ry   r  r  r  rs  transformer_featuresr  quantized_featuresr+   r(   r.   r/   rh   rH   r   negative_quantized_featuresr  
neg_is_postargetnum_codevectorss                           r9   r   zWav2Vec2ForPreTraining.forwardu  s   J &1%<kk$+B]( 1 4 4UZ @ @--)/!5/#   
 
  $//
;;  00<<%!DD &q)>u E  N 59NN0A 5C 5
 5
11 0224>3H3NOO!^^,>??3777.#/7I7O4J +=*A*A"k*R*R(--//44R88+' +F*J*JOR+ +gaAq!! ( 44"47++$:	 F -0KKPPQSTTJ~~ 7).vqrr
:& %%a++33BAGGF,11333t;FFq!LLTTVVF!}::6<<>>6]b:cc"kCdkFggO.1FF/Y]n]r]r]t]ttN $dk&G.&XXD 	c24FH]^ahijikikalll(*<>STW^_`_a_aWbbb+1'9"7!/)-)	
 	
 	
 		
r8   )r  )NNNNNN)r0   r1   r2   r"   r   rC   r  rk  ri  r  r4   r5   r  r   r  r    r'   r  r   r4  
BoolTensorr\   r   r   r   r   r   s   @r9   r  r  8  s       ~      1# 1 1 1 1
& 
& 
&= = = 
 	 * , "- 	   \( +*+GHH+GVefff 268<?C,0/3&*^
 ^
u|,^
 !.^
 $E$45	^

 #+5+;"<^
 $D>^
 'tn^
 d^^
 
u22	3^
 ^
 ^
 gf IH^
 ^
 ^
 ^
 ^
r8   r  z6Wav2Vec2 Model with a `language modeling` head on top.c                        e Zd Z fdZ ee          	 	 	 	 	 ddej        deej	                 dee
         dee
         dee
         deej                 d	eeef         fd
            Z xZS )Wav2Vec2ForMaskedLMc                 R   t                                          |           t          j        dt                     t          |          | _        t          j        |j	                  | _
        t          j        |j        |j                  | _        |                                  d S )NzSThe class `Wav2Vec2ForMaskedLM` is deprecated. Please use `Wav2Vec2ForCTC` instead.)r   r   r   r   r   rZ  r  r   r   final_dropoutr   r   r   rE  r  rd  r   s     r9   r   zWav2Vec2ForMaskedLM.__init__  s       acp	
 	
 	
 &f--z&"677y!3V5FGG 	r8   Nr   r=   r  r  r  labelsr?   c                    ||n| j         j        }|                     ||||          }|d         }|                     |          }|                     |          }	|s|	f|dd          z   }
|
S t          |	|j        |j                  S )N)r  r  r  r   r%   )r  r,   r-   )r   r  r  r   r  r   r,   r-   )r   r   r=   r  r  r  r  rs  r,   r  outputs              r9   r   zWav2Vec2ForMaskedLM.forward(  s     &1%<kk$+B]--/!5#	   
 
  
]33m,, 	Y,FMV7;P]d]oppppr8   r  )r0   r1   r2   r   r   r  r4   r5   r   rX  r\   r4  r   r   r   r   r   r   s   @r9   r  r    s             +*+GHH 6:,0/3&*)-q q'q !!12q $D>	q
 'tnq d^q &q 
un$	%q q q IHq q q q qr8   r  zfWav2Vec2 Model with a `language modeling` head on top for Connectionist Temporal Classification (CTC).a.  
        target_lang (`str`, *optional*):
            Language id of adapter weights. Adapter weights are stored in the format adapter.<lang>.safetensors or
            adapter.<lang>.bin. Only relevant when using an instance of [`Wav2Vec2ForCTC`] with adapters. Uses 'eng' by
            default.
    c                   >    e Zd Zddee         f fdZd Zd Zd Zd Z	 e
e           eeeeee          	 	 	 	 	 dd	eej                 d
eej                 dee         dee         dee         deej                 deeef         fd                        Z xZS )r  Nr%  c                    t                                          |           t          |          | _        t	          j        |j                  | _        || _        |j	        t          d| j         d          t          |d          r|j        r|j        n|j        }t	          j        ||j	                  | _        |                                  d S )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: `Wav2Vec2ForCTC.from_pretrained(..., vocab_size=vocab_size)`. or define `vocab_size` of your model's configuration.r  )r   r   rZ  r  r   r   r  r   r%  rE  rR   r   r   r  r  r   r   r  rd  )r   r   r%  r  r   s       r9   r   zWav2Vec2ForCTC.__init__Q  s       %f--z&"677&$H H H H   *1)G)GvFL^vF%%djdv 	 y!3V5FGG 	r8   c                    | j         }|)t          | j        dd          t          d| d          |2t          | j        dd          t                              d           dS ||                     |d           dS dS )a'  
        This method overwrites [`~PreTrainedModel.tie_weights`] so that adapter weights can be correctly loaded when
        passing `target_lang=...` to `from_pretrained(...)`.

        This method is **not** supposed to be called by the user and is prone to be changed in the future.
        Nrw  zCannot pass `target_lang`: r'  z)By default `target_lang` is set to 'eng'.T)rH  )r%  rx  r   rR   rD  inforQ  )r   r%  s     r9   tie_weightszWav2Vec2ForCTC.tie_weightsh  s     &"wt{<NPT'U'U']u;uuuvvv WT[:Ld%S%S%_KKCDDDDD$kd;;;;; %$r8   c                 b    t          j        dt                     |                                  dS ro  rg  Nrh  rj  s    r9   rk  z'Wav2Vec2ForCTC.freeze_feature_extractor}  rl  r8   c                 B    | j         j                                         dS rn  r  rj  s    r9   ri  z%Wav2Vec2ForCTC.freeze_feature_encoder  r  r8   c                 L    | j                                         D ]	}d|_        
dS 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r  r   r   r   s     r9   freeze_base_modelz Wav2Vec2ForCTC.freeze_base_model  6    
 ]--// 	( 	(E"'E	( 	(r8   )rz  r{  rR  r}  expected_lossr   r=   r  r  r  r  r?   c           
      p   ||n| j         j        }|>|                                | j         j        k    rt	          d| j         j                   |                     |||||          }|d         }|                     |          }|                     |          }	d}
|Z||nt          j	        |t          j
                  }|                     |                    d                                        t          j
                  }|dk    }|                    d          }|                    |          }t          j                            |	dt          j                                      dd          }t          j        j                            d	
          5  t          j                            ||||| j         j        | j         j        | j         j                  }
ddd           n# 1 swxY w Y   |s|	f|t6          d         z   }|
|
f|z   n|S t9          |
|	|j        |j                  S )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   rO   rJ   )r   rP   r!   F)enabled)blankr  zero_infinityr(   r  r,   r-   )r   r  rD   rE  rR   r  r   r  r4   	ones_liker  r  rW   rF  masked_selectr   r%  log_softmaxrA  r   backendscudnnflagsctc_losspad_token_idctc_loss_reductionctc_zero_infinity_HIDDEN_STATES_START_POSITIONr   r,   r-   )r   r   r=   r  r  r  r  rs  r,   r  r(   ri   labels_masktarget_lengthsflattened_targets	log_probsr  s                    r9   r   zWav2Vec2ForCTC.forward  s   0 &1%<kk$+B]&**,,$+2H"H"H\DKDZ\\]]]--)/!5#   
 
  
]33m,, #1"<%/R^fkfpBqBqBq  !AA.BTBTUWBXBXYY\\]b]ghhM !A+K(__R00N & 4 4[ A A 11&b1VV``abdeffI%++E+:: 	 	}--%!"+2"k<"&+"? .  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	FY)F)G)G!HHF)-)9TGf$$vEfG4IV]Vh
 
 
 	
s    AG11G58G5r   r  )r0   r1   r2   r   r]  r   r  rk  ri  r  r   r  r   r  r   r  _CTC_EXPECTED_OUTPUT_CTC_EXPECTED_LOSSr4   r4  r\   r   r   r   r   r   s   @r9   r  r  F  sz        HSM      .< < <*
& 
& 
&= = =( ( ( +*+GHH&"$,(   26,0/3&*)-D
 D
u|,D
 !.D
 $D>	D

 'tnD
 d^D
 &D
 
un$	%D
 D
 D
  IHD
 D
 D
 D
 D
r8   r  z
    Wav2Vec2 Model with a sequence classification head on top (a linear layer over the pooled output) for tasks like
    SUPERB Keyword Spotting.
    c                   &    e Zd Z fdZd Zd Zd Z ee           e	e
eedee          	 	 	 	 	 ddeej                 d	eej                 d
ee         dee         dee         deej                 deeef         fd                        Z xZS )!Wav2Vec2ForSequenceClassificationc                    t                                          |           t          |d          r|j        rt	          d          t          |          | _        |j        dz   }|j        r.t          j
        t          j        |          |z            | _        t          j        |j        |j                  | _        t          j        |j        |j                  | _        |                                  d S )Nr  z_Sequence classification does not support the use of Wav2Vec2 adapters (config.add_adapter=True)r!   )r   r   r   r  rR   rZ  r  r  use_weighted_layer_sumr   r  r4   ra   layer_weightsr   r   classifier_proj_size	projector
num_labels
classifierrd  r   r   
num_layersr   s      r9   r   z*Wav2Vec2ForSequenceClassification.__init__  s       6=)) 	f.@ 	q   &f---1
( 	S!#ej.D.Dz.Q!R!RD6#5v7RSS)F$?ARSS 	r8   c                 b    t          j        dt                     |                                  dS rf  rh  rj  s    r9   rk  z:Wav2Vec2ForSequenceClassification.freeze_feature_extractor 	  rl  r8   c                 B    | j         j                                         dS rn  r  rj  s    r9   ri  z8Wav2Vec2ForSequenceClassification.freeze_feature_encoder	  r  r8   c                 L    | j                                         D ]	}d|_        
dS r  r  r   s     r9   r  z3Wav2Vec2ForSequenceClassification.freeze_base_model	  r  r8   rx  )rz  r{  rR  r|  r}  r  Nr   r=   r  r  r  r  r?   c                    ||n| j         j        }| j         j        rdn|}|                     |||||          }| j         j        rx|t                   }t          j        |d          }t          j        	                    | j
        d          }	||	                    ddd          z                      d          }n|d         }|                     |          }||                    d          }
nh|                     |j        d         |          }d|| <   |                    d          |                    d                              dd          z  }
|                     |
          }d}|Kt%                      } ||                    d| j         j                  |                    d                    }|s|f|t          d         z   }||f|z   n|S t)          |||j        |j        	          S )
  
        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  rJ   r   r  r  )r   r  r  r  r  r4   stackr   r%  r&  r  r  rW   r  r  r  r:   r  r   r  r   r,   r-   )r   r   r=   r  r  r  r  rs  r,   norm_weightspooled_outputpadding_maskr  r(   loss_fctr  s                   r9   r   z)Wav2Vec2ForSequenceClassification.forward	  s&   2 &1%<kk$+B]'+{'IcttOc--)/!5#   
 
 ;- 	'#$ABM!K1===M=001C0LLL*\->->r1a-H-HHMMRSMTTMM#AJM}55!)..1.55MMBB=CVWXCY[ijjL+.M<-()--!-44|7G7GA7G7N7N7S7STVXY7Z7ZZM//'))H8FKKDK,BCCV[[QS__UUD 	FY)F)G)G!HHF)-)9TGf$$vE'!/)	
 
 
 	
r8   r  )r0   r1   r2   r   rk  ri  r  r   r  r   _SEQ_CLASS_CHECKPOINTr   r  _SEQ_CLASS_EXPECTED_OUTPUT_SEQ_CLASS_EXPECTED_LOSSr   r4   r4  r\   r   r   r   r   r   s   @r9   r  r    sJ           "
& 
& 
&= = =( ( ( +*+GHH(,$2.   26,0/3&*)-;
 ;
u|,;
 !.;
 $D>	;

 'tn;
 d^;
 &;
 
u..	/;
 ;
 ;
  IH;
 ;
 ;
 ;
 ;
r8   r  zd
    Wav2Vec2 Model with a frame classification head on top for tasks like Speaker Diarization.
    c                   $    e Zd Z fdZd Zd Zd Z ee           e	e
eede          	 	 	 	 	 ddeej                 d	eej                 d
eej                 dee         dee         dee         deeef         fd                        Z xZS )#Wav2Vec2ForAudioFrameClassificationc                    t                                          |           t          |d          r|j        rt	          d          t          |          | _        |j        dz   }|j        r.t          j
        t          j        |          |z            | _        t          j        |j        |j                  | _        |j        | _        |                                  d S )Nr  zbAudio frame classification does not support the use of Wav2Vec2 adapters (config.add_adapter=True)r!   )r   r   r   r  rR   rZ  r  r  r  r   r  r4   ra   r  r   r   r  r  init_weightsr  s      r9   r   z,Wav2Vec2ForAudioFrameClassification.__init__i	  s       6=)) 	f.@ 	t   &f---1
( 	S!#ej.D.Dz.Q!R!RD)F$68IJJ +r8   c                 b    t          j        dt                     |                                  dS r  rh  rj  s    r9   rk  z<Wav2Vec2ForAudioFrameClassification.freeze_feature_extractory	  rl  r8   c                 B    | j         j                                         dS rn  r  rj  s    r9   ri  z:Wav2Vec2ForAudioFrameClassification.freeze_feature_encoder	  r  r8   c                 L    | j                                         D ]	}d|_        
dS r  r  r   s     r9   r  z5Wav2Vec2ForAudioFrameClassification.freeze_base_model	  r  r8   rx  ry  Nr   r=   r  r  r  r  r?   c           	         ||n| j         j        }| j         j        rdn|}|                     |||||          }| j         j        rx|t                   }t          j        |d          }t          j        	                    | j
        d          }	||	                    ddd          z                      d          }n|d         }|                     |          }
d}|`t                      } ||
                    d| j                  t          j        |                    d| j                  d                    }|s|
f|t          d         z   }|S t#          ||
|j        |j        	          S )
r  NTr  r!   r  rJ   r   )axisr  )r   r  r  r  r  r4   r  r   r%  r&  r  r  rW   r  r   r  r  r   r,   r-   )r   r   r=   r  r  r  r  rs  r,   r  r  r(   r  r  s                 r9   r   z+Wav2Vec2ForAudioFrameClassification.forward	  s   0 &1%<kk$+B]'+{'IcttOc--)/!5#   
 
 ;- 	'#$ABM!K1===M=001C0LLL*\->->r1a-H-HHMMRSMTTMM#AJM//'))H8FKKDO<<el6;;WY[_[jKkKkrs>t>t>tuuD 	Y)F)G)G!HHFM$!/)	
 
 
 	
r8   r  )r0   r1   r2   r   rk  ri  r  r   r  r   _FRAME_CLASS_CHECKPOINTr   r  _FRAME_EXPECTED_OUTPUTr   r4   r4  r\   r   r   r   r   r   s   @r9   r  r  b	  sG            
& 
& 
&= = =( ( ( +*+GHH*)$.   26)-,0/3&*3
 3
u|,3
 !.3
 &	3

 $D>3
 'tn3
 d^3
 
u++	,3
 3
 3
  IH3
 3
 3
 3
 3
r8   r  c                   &     e Zd Zd fd	Zd Z xZS )AMSoftmaxLoss      >@皙?c                    t          t          |                                            || _        || _        || _        t          j        t          j	        ||          d          | _
        t          j                    | _        d S )NT)r   )r   r  r   scalemarginr  r   r  r4   randnr   r   r(   )r   r  r  r  r  r   s        r9   r   zAMSoftmaxLoss.__init__	  sk    mT""++---
$l5;y*#E#EUYZZZ'))			r8   c                    |                                 }t          j                            | j        d          }t          j                            |d          }t          j        ||          }|| j        z
  }t          j                            || j	                  }| j
        t          j        |                                ||          z  }|                     ||          }|S )Nr   r  r!   )r  r   r%  	normalizer   r4   mmr  one_hotr  r  r  r\   r(   )	r   r,   r  r   	cos_thetapsionehotr  r(   s	            r9   r   zAMSoftmaxLoss.forward	  s    !!((!(<<//1/EEH]F33	$+%&&vt??ek&++--iHHHyy((r8   )r  r  r   r   s   @r9   r  r  	  sL        * * * * * *      r8   r  c                   D     e Zd Zd fd	Zdej        dej        fdZ xZS )	TDNNLayerr   c                    t                                                       |dk    r|j        |dz
           n|j        |         | _        |j        |         | _        |j        |         | _        |j        |         | _        t          j
        | j        | j        z  | j                  | _        t          j                    | _        d S )Nr   r!   )r   r   tdnn_dimr   r   tdnn_kernelr   tdnn_dilationdilationr   r   kernelr  r   r   s      r9   r   zTDNNLayer.__init__	  s    <DqLL6?8a<88fo^fNg"OH5!-h7,X6i 043C CTEVWW'))r8   r,   r?   c                    t                      r/ddlm} t          | j        |          rt          j        d           |                    dd          }| j        j        	                    | j
        | j        | j                                      dd          }t          j                            ||| j        j        | j                  }|                    dd          }|                     |          }|S )Nr   )	LoraLayerzDetected LoRA on TDNNLayer. LoRA weights won't be applied due to optimization. You should exclude TDNNLayer from LoRA's target modules.r!   r%   )r  )r   peft.tuners.lorar  r[  r  r   r   r   r   r  r   r   r   r   r%  conv1dr   r  r   )r   r,   r  r   s       r9   r   zTDNNLayer.forward	  s     	222222$+y11 O   &//155#(():D<LdN^__iijkmnoo,,]FDKDT_c_l,mm%//15566r8   r   )r0   r1   r2   r   r4   r4  r   r   r   s   @r9   r	  r	  	  sc        $ $ $ $ $ $U\ el        r8   r	  zl
    Wav2Vec2 Model with an XVector feature extraction head on top for tasks like Speaker Verification.
    c                   J    e Zd Z fdZd Zd Zd Zdeej	        e
f         fdZ ee           eeeede          	 	 	 	 	 dd
eej                 deej                 dee         dee         dee         deej                 deeef         fd                        Z xZS )Wav2Vec2ForXVectorc                    t                                                     t                    | _        j        dz   }j        r.t          j        t          j	        |          |z            | _
        t          j        j        j        d                   | _        fdt          t!          j                            D             }t          j        |          | _        t          j        j        d         dz  j                  | _        t          j        j        j                  | _        t-          j        j                  | _        |                                  d S )Nr!   r   c                 0    g | ]}t          |          S r7   )r	  r   s     r9   rN   z/Wav2Vec2ForXVector.__init__.<locals>.<listcomp>
  s#    QQQy++QQQr8   rJ   r%   )r   r   rZ  r  r  r  r   r  r4   ra   r  r   r   r  r  rZ   r_   r   tdnnxvector_output_dimr\  r  r  r  	objectiver  )r   r   r  tdnn_layersr   s    `  r9   r   zWav2Vec2ForXVector.__init__
  s)      %f---1
( 	S!#ej.D.Dz.Q!R!RD6#5vq7IJJQQQQU3v;O;O5P5PQQQM+..	!#6?2+>+BFD]!^!^)F$=v?XYY&v'@&BSTTr8   c                 b    t          j        dt                     |                                  dS r  rh  rj  s    r9   rk  z+Wav2Vec2ForXVector.freeze_feature_extractor"
  rl  r8   c                 B    | j         j                                         dS rn  r  rj  s    r9   ri  z)Wav2Vec2ForXVector.freeze_feature_encoder.
  r  r8   c                 L    | j                                         D ]	}d|_        
dS r  r  r   s     r9   r  z$Wav2Vec2ForXVector.freeze_base_model5
  r  r8   ri   c                 D    d }| j         j        D ]} |||d          }|S )z?
        Computes the output length of the TDNN layers
        c                     | |z
  |z  dz   S )Nr!   r7   r  s      r9   r  zEWav2Vec2ForXVector._get_tdnn_output_lengths.<locals>._conv_out_lengthB
  s     !;.69A==r8   r!   )r   r  )r   ri   r  r   s       r9   _get_tdnn_output_lengthsz+Wav2Vec2ForXVector._get_tdnn_output_lengths=
  sE    
	> 	> 	>
  ;2 	L 	LK,,]KKKMMr8   rx  ry  Nr   r=   r  r  r  r  r?   c                 >   ||n| j         j        }| j         j        rdn|}|                     |||||          }| j         j        rx|t                   }t          j        |d          }t          j        	                    | j
        d          }	||	                    ddd          z                      d          }n|d         }|                     |          }| j        D ]}
 |
|          }|-|                    d          }|                    d          }n|                     |                    d                    }|                     |          }g }g }t'          |          D ]k\  }}|                    ||d|f                             d                     |                    ||d|f                             d                     lt          j        |          }t          j        |          }t          j        ||gd          }|                     |          }|                     |          }d}||                     ||          }|s||f|t          d         z   }||f|z   n|S t3          ||||j        |j                  S )	r  NTr  r!   r  rJ   r   )r(   r  
embeddingsr,   r-   )r   r  r  r  r  r4   r  r   r%  r&  r  r  rW   r  r  r  r  r  r!  	enumeraterc   r#  r\  r  r  r   r,   r-   )r   r   r=   r  r  r  r  rs  r,   r  
tdnn_layermean_featuresstd_featuresfeat_extract_output_lengthstdnn_output_lengthsr   lengthstatistic_poolingoutput_embeddingsr  r(   r  s                         r9   r   zWav2Vec2ForXVector.forwardL
  s   0 &1%<kk$+B]'+{'IcttOc--)/!5#   
 
 ;- 	'#$ABM!K1===M=001C0LLL*\->->r1a-H-HHMMRSMTTMM#AJM}55) 	6 	6J&J}55MM !)..1.55M(,,,33LL*.*O*OP^PbPbghPbPiPi*j*j'"&"?"?@["\"\ML&':;; J J	6$$]1gvg:%>%C%C%C%J%JKKK##M!WfW*$=$A$Aa$A$H$HIIII!K66M ;|44L!I}l&CLLL 223DEE!233>>&&11D 	F/07;X;Y;Y3ZZF)-)9TGf$$vE(!/)
 
 
 	
r8   r  )r0   r1   r2   r   rk  ri  r  r   r4   rX  rC   r!  r   r  r   _XVECTOR_CHECKPOINTr   r  _XVECTOR_EXPECTED_OUTPUTr   r4  r\   r   r   r   r   s   @r9   r  r  
  s~           &
& 
& 
&= = =( ( (eE<Lc<Q6R     +*+GHH&!$0   26,0/3&*)-I
 I
u|,I
 !.I
 $D>	I

 'tnI
 d^I
 &I
 
um#	$I
 I
 I
  IHI
 I
 I
 I
 I
r8   r  r   r   )pr3   r  r   dataclassesr   typingr   r   r   numpyrS   r4   torch.utils.checkpointr   torch.nnr   activationsr
   integrations.deepspeedr   integrations.fsdpr   modeling_outputsr   r   r   r   r   r   r   modeling_utilsr   pytorch_utilsr   r   r   r   r   r   r   r   r   r   r   r   r    configuration_wav2vec2r"   rA  r<  safetensors.torchr#   r>  modeling_flash_attention_utilsr$   
get_loggerr0   rD  r  r  r  r  r  r  r  r  r  r  r  r-  r.  r'   rC   r3  rX  ndarrayrp   r   Moduler   r   r   r   r   r   r   r   r  r6  rL  rg  rU  rd  ru  r}  r  r  r  r  ry  r  WAV_2_VEC_2_START_DOCSTRINGr  rZ  r  r  r  r  r  r  r	  r  r7   r8   r9   <module>rA     sj
       ! ! ! ! ! ! ) ) ) ) ) ) ) ) ) )                % % % % % % ! ! ! ! ! ! @ @ @ @ @ @ 7 7 7 7 7 7                  . - - - - - @ @ @ @ @ @                          3 2 2 2 2 2 , 5  >======  KJJJJJJ		H	%	% !"  # 4 &  u   9 *   < Q  8   &7 &7 &7 &7 &7; &7 &7 &7Z 26t tc?tt t U-.	t
 t Zt t t tp Z^!$ !$!$*-!$BJ2:BV!$ !$ !$ !$H    29   *       6       0* * * * *bi * * *Z    29   + + + + +RY + + +\
 
 
 
 
5 
 
 
1 1 1 1 1	 1 1 1 [B [B [B [B [B	 [B [B [B~|9 |9 |9 |9 |9/ |9 |9 |9~h1 h1 h1 h1 h1- h1 h1 h1X !0      ")   0         29      F* * * * *") * * *ZR
 R
 R
 R
 R
bi R
 R
 R
jV
 V
 V
 V
 V
RY V
 V
 V
rI' I' I' I' I'BI I' I' I'X    bi   >    29   $    ry   2y' y' y' y' y'o y' y' y'x	 &#  L h P
 P
 P
 P
 P
+ P
 P
	 P
f QSnoo\
 \
 \
 \
 \
4 \
 \
 po\
~ RTopp*q *q *q *q *q1 *q *q qp*qZ p	 	T
 T
 T
 T
 T
, T
 T
	 	T
n    q
 q
 q
 q
 q
(? q
 q
 q
h   	 g
 g
 g
 g
 g
*A g
 g
 g
T    BI   .    	   >   	 O
 O
 O
 O
 O
0 O
 O
 O
 O
 O
r8   