
    g*                     0   d Z ddlZddlmZmZmZmZmZm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mZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZmZmZ ddl m!Z! ddl"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0  e+            rddl1m2Z2  e-j3        e4          Z5dZ6dZ7de8de8dej9        fdZ:de8de8dej9        fdZ; G d dej<                  Z= G d dej<                  Z> G d de>          Z? G d d e>          Z@ G d! d"ej<                  ZAe>e?e@d#ZB G d$ d%ej<                  ZC G d& d'ej<                  ZD G d( d)e!          ZEd*ZFd+ZG e)d,eF           G d- d.eE                      ZH e)d/eF           G d0 d1eE                      ZI e)d2eF           G d3 d4eE                      ZJ e)d5eF           G d6 d7eE                      ZK e)d8eF           G d9 d:eE                      ZL e)d;eF           G d< d=eE                      ZMdS )>z
PyTorch DistilBERT model adapted in part from Facebook, Inc XLM model (https://github.com/facebookresearch/XLM) and in
part from HuggingFace PyTorch version of Google AI Bert model (https://github.com/google-research/bert)
    N)DictListOptionalSetTupleUnion)nn)BCEWithLogitsLossCrossEntropyLossMSELoss   )get_activation)PretrainedConfig)is_deepspeed_zero3_enabled)#_prepare_4d_attention_mask_for_sdpa)BaseModelOutputMaskedLMOutputMultipleChoiceModelOutputQuestionAnsweringModelOutputSequenceClassifierOutputTokenClassifierOutput)PreTrainedModel)apply_chunking_to_forward find_pruneable_heads_and_indices"is_torch_greater_or_equal_than_2_2prune_linear_layer)add_code_sample_docstringsadd_start_docstrings%add_start_docstrings_to_model_forwardis_flash_attn_2_available#is_flash_attn_greater_or_equal_2_10loggingreplace_return_docstrings   )DistilBertConfig)_flash_attention_forwardzdistilbert-base-uncasedr%   n_posdimoutc                 $   t                      rodd l}|j                            |d          5  t          j                                        dk    rt          | ||           d d d            d S # 1 swxY w Y   d S t          | ||           d S )Nr   )modifier_rankr'   r(   r)   )r   	deepspeedzeroGatheredParameterstorchdistributedget_rank_create_sinusoidal_embeddings)r'   r(   r)   r-   s       n/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/distilbert/modeling_distilbert.pycreate_sinusoidal_embeddingsr5   H   s    !## E^..s!.DD 	M 	M ))++q00-EsLLLL	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	&EsDDDDDDs   5A11A58A5c           	         t          j        fdt          |           D                       }d|_        t	          j        t          j        |d d dd df                             |d d dd df<   t	          j        t          j        |d d dd df                             |d d dd df<   |                                 d S )Nc                 J    g | ]fd t                    D             S )c           	      R    g | ]#}t          j        d d|dz  z  z            z  $S )i'     )nppower).0jr(   poss     r4   
<listcomp>z<_create_sinusoidal_embeddings.<locals>.<listcomp>.<listcomp>T   s7    \\\AcBHUAaL34F$G$GG\\\    )range)r<   r>   r(   s    @r4   r?   z1_create_sinusoidal_embeddings.<locals>.<listcomp>T   s=    uuuad\\\\\QVWZQ[Q[\\\uuur@   Fr   r9   r$   )	r:   arrayrA   requires_gradr0   FloatTensorsincosdetach_)r'   r(   r)   position_encs    `  r4   r3   r3   S   s    8uuuuhmnshthtuuuvvLC$RVLADqD,A%B%BCCC14a4L$RVLADqD,A%B%BCCC14a4LKKMMMMMr@   c                   d     e Zd Zdef fdZddej        deej                 dej        fdZ xZ	S )	
Embeddingsconfigc                    t                                                       t          j        |j        |j        |j                  | _        t          j        |j        |j                  | _	        t          j
        |j        d          | _
        t          j        |j                  | _        |                     dt          j        |j                                      d          d           d S )N)padding_idx-q=epsposition_ids)r$   F)
persistent)super__init__r	   	Embedding
vocab_sizer(   pad_token_idword_embeddingsmax_position_embeddingsposition_embeddings	LayerNormDropoutdropoutregister_bufferr0   arangeexpandselfrK   	__class__s     r4   rU   zEmbeddings.__init__\   s    !|F,=vzW]Wjkkk#%<0NPVPZ#[#[ fje<<<z&.11EL)GHHOOPWXXej 	 	
 	
 	
 	
 	
r@   N	input_idsinput_embedsreturnc                    ||                      |          }|                    d          }t          | d          r| j        ddd|f         }nNt	          j        |t          j        |j                  }|                    d          	                    |          }| 
                    |          }||z   }|                     |          }|                     |          }|S )a  
        Parameters:
            input_ids (torch.Tensor):
                torch.tensor(bs, max_seq_length) The token ids to embed.
            input_embeds (*optional*, torch.Tensor):
                The pre-computed word embeddings. Can only be passed if the input ids are `None`.


        Returns: torch.tensor(bs, max_seq_length, dim) The embedded tokens (plus position embeddings, no token_type
        embeddings)
        Nr$   rQ   )dtypedevicer   )rY   sizehasattrrQ   r0   r`   longrj   	unsqueeze	expand_asr[   r\   r^   )rc   re   rf   
seq_lengthrQ   r[   
embeddingss          r4   forwardzEmbeddings.forwardg   s      //	::L!&&q))

 4(( 	J,QQQ^<LL <
%*YM]^^^L'11!44>>yIIL"66|DD!$77
^^J//
\\*--
r@   N)
__name__
__module____qualname__r   rU   r0   Tensorr   rr   __classcell__rd   s   @r4   rJ   rJ   [   s        	
/ 	
 	
 	
 	
 	
 	
  Xel=S _d_k        r@   rJ   c                        e Zd Zdef fdZdee         fdZ	 	 ddej	        dej	        d	ej	        d
ej	        de
ej	                 dedeej	        df         fdZ xZS )MultiHeadSelfAttentionrK   c                    t                                                       || _        |j        | _        |j        | _        t          j        |j                  | _        d| _	        | j        | j        z  dk    r t          d| j         d| j         d          t          j        |j        |j                  | _        t          j        |j        |j                  | _        t          j        |j        |j                  | _        t          j        |j        |j                  | _        t!                      | _        | j        | j        z  | _        d S )NpFr   zself.n_heads: z must divide self.dim:  evenlyin_featuresout_features)rT   rU   rK   n_headsr(   r	   r]   attention_dropoutr^   	is_causal
ValueErrorLinearq_link_linv_linout_linsetpruned_headsattention_head_sizerb   s     r4   rU   zMultiHeadSelfAttention.__init__   s   ~:zF$<=== 8dl"a''ddlddSWS[dddeeeY6:FJOOO
Y6:FJOOO
Y6:FJOOO
yVZfjQQQ&)ee#'8t|#;   r@   headsc                    t          |          dk    rd S t          || j        | j        | j                  \  }}t          | j        |          | _        t          | j        |          | _        t          | j        |          | _        t          | j	        |d          | _	        | j        t          |          z
  | _        | j        | j        z  | _
        | j                            |          | _        d S )Nr   r$   r(   )lenr   r   r   r   r   r   r   r   r   r(   union)rc   r   indexs      r4   prune_headsz"MultiHeadSelfAttention.prune_heads   s    u::??F74<!94;L
 
u (
E::
'
E::
'
E::
)$,1EEE|c%jj0+dl: -33E::r@   NFquerykeyvaluemask	head_maskoutput_attentionsrg   .c                     |                                 \  }}|                     d          }	 j         j        z  dd|	f}
dt          j        dt          j        f fd}dt          j        dt          j        f fd} |                     |                    } |                     |                    } |                     |                    }|t          j	                  z  }t          j
        ||                    dd                    }|dk                        |
                              |          }|                    |t          j        t          j        |j                  j                            }t&          j                            |d	
          }                     |          }|||z  }t          j
        ||          } ||          }                     |          }|r||fS |fS )  
        Parameters:
            query: torch.tensor(bs, seq_length, dim)
            key: torch.tensor(bs, seq_length, dim)
            value: torch.tensor(bs, seq_length, dim)
            mask: torch.tensor(bs, seq_length)

        Returns:
            weights: torch.tensor(bs, n_heads, seq_length, seq_length) Attention weights context: torch.tensor(bs,
            seq_length, dim) Contextualized layer. Optional: only if `output_attentions=True`
        r$   xrg   c                 f    |                      dj                                      dd          S separate headsrR   r$   r9   viewr   	transposer   bsdim_per_headrc   s    r4   shapez-MultiHeadSelfAttention.forward.<locals>.shape   s-    66"b$,==GG1MMMr@   c                     |                      dd                                                              dj        z            S zgroup headsr$   r9   rR   r   
contiguousr   r   r   s    r4   unshapez/MultiHeadSelfAttention.forward.<locals>.unshape   s<    ;;q!$$//1166r2t|l?Z[[[r@   r9   r   r   rR   r   )rk   r(   r   r0   rw   r   r   r   mathsqrtmatmulr   r   ro   masked_filltensorfinfori   minr	   
functionalsoftmaxr^   r   )rc   r   r   r   r   r   r   q_lengthr(   k_length
mask_reshpr   r   qkvscoresweightscontextr   r   s   `                  @@r4   rr   zMultiHeadSelfAttention.forward   s7   ( "JJLLHc88A;; x4</!Q)
	NU\ 	Nel 	N 	N 	N 	N 	N 	N 	N 	N	\u| 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ E$**U##$$E$**S//""E$**U##$$	,'''aQ!2!233	
++55f==##%,u{6<88<==
 
 -''B'77,,w''  	)G,w**''"",,w'' 	W%%:r@   NF)rt   ru   rv   r   rU   r   intr   r0   rw   r   boolr   rr   rx   ry   s   @r4   r{   r{      s        </ < < < < < <,;c ; ; ; ;, -1"'> >|> \> |	>
 l> EL)>  > 
u|S 	!> > > > > > > >r@   r{   c                        e Zd ZdZ fdZ	 	 ddej        dej        dej        dej        d	eej                 d
ede	ej        df         fdZ
 xZS )DistilBertFlashAttention2aS  
    DistilBert flash attention module. This module inherits from `MultiHeadSelfAttention` 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 rs   )rT   rU   r!   _flash_attn_uses_top_left_mask)rc   argskwargsrd   s      r4   rU   z"DistilBertFlashAttention2.__init__   s9    $)&)))
 3V2W2W.W+++r@   NFr   r   r   r   r   r   rg   .c           
          |                                 \  }} j         j        z  dt          j        dt          j        f fd}	 |	                     |                    }
 |	                     |                    } |	                     |                    } j        r j	        j
        nd}|
j        t          j        k    rt          j                    rt          j                    }n3t           j	        d          r j	        j        }n j        j        j        }t$                              d| d           |
                    |          }
|                    |          }|                    |          }t+          |
||||| j         j                  }|                    | j        z            }                     |          }|r||fS |fS )	r   r   rg   c                 >    |                      dj                  S )r   rR   )r   r   r   
batch_sizer   rc   s    r4   reshapez2DistilBertFlashAttention2.forward.<locals>.reshape  s    66*b$,EEEr@           _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^   use_top_left_maskr   )rk   r(   r   r0   rw   r   r   r   trainingrK   r   ri   float32is_autocast_enabledget_autocast_gpu_dtyperl   r   weightloggerwarning_oncetor&   r   r   r   r   )rc   r   r   r   r   r   r   r   r(   r   query_states
key_statesvalue_statesattn_dropouttarget_dtypeattn_weightsattn_weights_reshapedattn_outputr   r   s   `                 @@r4   rr   z!DistilBertFlashAttention2.forward  s   ( %*JJLL!
Hcx4</	Fu| 	F 	F 	F 	F 	F 	F 	F 	F 	F wtzz%0011WTZZ__--
wtzz%00118<Nt{443 ..(** 7$;==&?@@ 7#{B#z06$ $ $ $   (??<88L#|44J'??<88L/ "An	
 	
 	
 !- 4 4Z4<ZfKf g gll#899 	"..>!r@   r   )rt   ru   rv   __doc__rU   r0   rw   r   r   r   rr   rx   ry   s   @r4   r   r      s         X X X X X -1"'N" N"|N" \N" |	N"
 lN" EL)N"  N" 
u|S 	!N" N" N" N" N" N" N" N"r@   r   c                        e Zd Zdef fdZ	 	 ddej        dej        dej        dej        d	eej                 d
ede	ej        df         f fdZ
 xZS )DistilBertSdpaAttentionrK   c                 ~    t                                          |           |j        | _        t           | _        d S )N)rK   )rT   rU   r   dropout_probr   require_contiguous_qkvrb   s     r4   rU   z DistilBertSdpaAttention.__init__S  s:    '''"4*L&L###r@   NFr   r   r   r   r   r   rg   .c                 t    |s|@t                               d           t                                          ||||||          S |                                \  }} j         j        z  dt          j        dt          j        f fd}dt          j        dt          j        f fd}	 | 	                    |                    }
 | 
                    |                    } |                     |                    } j        rN|
j        j        dk    r>|<|
                                }
|                                }|                                }t          j        j                            |
||| j        r j        ndd	
          } |	|          }                     |          }|fS )r   Na  DistilBertSdpaAttention is used but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True` or `head_mask`. 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   rg   c                 f    |                      dj                                      dd          S r   r   r   s    r4   r   z.DistilBertSdpaAttention.forward.<locals>.shape  s/    66*b$,EEOOPQSTUUUr@   c                     |                      dd                                                              dj        z            S r   r   r   s    r4   r   z0DistilBertSdpaAttention.forward.<locals>.unshape  s=    ;;q!$$//1166z2t|VbGbcccr@   cudar   F)	attn_mask	dropout_pr   )r   r   rT   rr   rk   r(   r   r0   rw   r   r   r   r   rj   typer   r	   r   scaled_dot_product_attentionr   r   r   )rc   r   r   r   r   r   r   _r   r   r   r   r   r   r   r   rd   s   `             @@r4   rr   zDistilBertSdpaAttention.forwardX  s   (  		 5d   77??!   !::<<
Aqx4</	VU\ 	Vel 	V 	V 	V 	V 	V 	V 	V 	V	du| 	d 	d 	d 	d 	d 	d 	d 	d 	d E$**U##$$E$**S//""E$**U##$$
 & 	18=F+B+BtGWAAAh)FF+/=Ad''c G 
 
 gk**ll;//~r@   r   rt   ru   rv   r   rU   r0   rw   r   r   r   rr   rx   ry   s   @r4   r   r   R  s        M/ M M M M M M -1"'G G|G \G |	G
 lG EL)G  G 
u|S 	!G G G G G G G G G Gr@   r   c                   l     e Zd Zdef fdZdej        dej        fdZdej        dej        fdZ xZ	S )FFNrK   c                 r   t                                                       t          j        |j                  | _        |j        | _        d| _        t          j        |j        |j	                  | _
        t          j        |j	        |j                  | _        t          |j                  | _        d S )Nr}   r$   r   )rT   rU   r	   r]   r^   chunk_size_feed_forwardseq_len_dimr   r(   
hidden_dimlin1lin2r   
activationrb   s     r4   rU   zFFN.__init__  s    zFN333'-'E$I&*6CTUUU	I&*;&*UUU	():;;r@   inputrg   c                 D    t          | j        | j        | j        |          S rs   )r   ff_chunkr   r   )rc   r   s     r4   rr   zFFN.forward  s     (8TVZVfhmnnnr@   c                     |                      |          }|                     |          }|                     |          }|                     |          }|S rs   )r   r   r   r^   )rc   r   r   s      r4   r   zFFN.ff_chunk  sG    IIeOOAIIaLLLLOOr@   )
rt   ru   rv   r   rU   r0   rw   rr   r   rx   ry   s   @r4   r   r     s        </ < < < < < <oU\ oel o o o oel u|        r@   r   )eagerflash_attention_2sdpac                        e Zd Zdef fdZ	 	 	 ddej        deej                 deej                 ded	e	ej        d
f         f
dZ
 xZS )TransformerBlockrK   c                    t                                                       |j        |j        z  dk    r t	          d|j         d|j         d          t          |j                 |          | _        t          j	        |j        d          | _
        t          |          | _        t          j	        |j        d          | _        d S )Nr   zconfig.n_heads z must divide config.dim r   rN   )normalized_shaperP   )rT   rU   r(   r   r   DISTILBERT_ATTENTION_CLASSES_attn_implementation	attentionr	   r\   sa_layer_normr   ffnoutput_layer_normrb   s     r4   rU   zTransformerBlock.__init__  s     :&!++jv~jjW]Wajjjkkk5f6QRSYZZ\6:5QQQv;;!#vzu!U!U!Ur@   NFr   r   r   r   rg   .c                 h   |                      ||||||          }|r|\  }}n>t          |          t          ur t          dt          |           d          |d         }|                     ||z             }|                     |          }|                     ||z             }|f}|r|f|z   }|S )ae  
        Parameters:
            x: torch.tensor(bs, seq_length, dim)
            attn_mask: torch.tensor(bs, seq_length)

        Returns:
            sa_weights: torch.tensor(bs, n_heads, seq_length, seq_length) The attention weights ffn_output:
            torch.tensor(bs, seq_length, dim) The output of the transformer block contextualization.
        )r   r   r   r   r   r   z$sa_output must be a tuple but it is z typer   )r  r   tuple	TypeErrorr	  r
  r  )	rc   r   r   r   r   	sa_output
sa_weights
ffn_outputoutputs	            r4   rr   zTransformerBlock.forward  s    " NN/ # 
 
	  	%$-!IzzIe++ ]tI ] ] ]^^^!!I&&y1}55	 XXi((
#'#9#9*y:P#Q#Q
 	, ]V+Fr@   )NNFr   ry   s   @r4   r  r    s        V/ V V V V V V  -1,0"') )<) EL)) EL)	)
  ) 
u|S 	!) ) ) ) ) ) ) )r@   r  c                        e Zd Zdef fdZ	 	 	 	 	 ddej        deej                 deej                 ded	ed
ee         de	e
eej        df         f         fdZ xZS )TransformerrK   c                     t                                                       j        | _        t          j        fdt          j                  D                       | _        d| _        d S )Nc                 .    g | ]}t                    S  )r  )r<   r   rK   s     r4   r?   z(Transformer.__init__.<locals>.<listcomp>  s"    #]#]#]$4V$<$<#]#]#]r@   F)rT   rU   n_layersr	   
ModuleListrA   layergradient_checkpointingrb   s    `r4   rU   zTransformer.__init__  sa    ]#]#]#]#]eFOF\F\#]#]#]^^
&+###r@   NFr   r   r   r   output_hidden_statesreturn_dictrg   .c                 Z   |rdnd}|rdnd}|}	t          | j                  D ]\  }
}|r||	fz   }| j        r,| j        r%|                     |j        |	|||
         |          }n ||	|||
         |          }|d         }	|rAt          |          dk    rt          dt          |                     |d         }||fz   }t          |          dk    rt          dt          |                     |r||	fz   }|st          d	 |	||fD                       S t          |	||
          S )a  
        Parameters:
            x: torch.tensor(bs, seq_length, dim) Input sequence embedded.
            attn_mask: torch.tensor(bs, seq_length) Attention mask on the sequence.

        Returns:
            hidden_state: torch.tensor(bs, seq_length, dim) Sequence of hidden states in the last (top)
            layer all_hidden_states: Tuple[torch.tensor(bs, seq_length, dim)]
                Tuple of length n_layers with the hidden states from each layer.
                Optional: only if output_hidden_states=True
            all_attentions: Tuple[torch.tensor(bs, n_heads, seq_length, seq_length)]
                Tuple of length n_layers with the attention weights from each layer
                Optional: only if output_attentions=True
        r  NrR   r9   z7The length of the layer_outputs should be 2, but it is r   r$   z7The length of the layer_outputs should be 1, but it is c              3      K   | ]}||V  	d S rs   r  )r<   r   s     r4   	<genexpr>z&Transformer.forward.<locals>.<genexpr>?  s(      ggqYZYfYfYfYfYfggr@   )last_hidden_statehidden_states
attentions)
	enumerater  r  r   _gradient_checkpointing_func__call__r   r   r  r   )rc   r   r   r   r   r  r  all_hidden_statesall_attentionshidden_stateilayer_modulelayer_outputsr#  s                 r4   rr   zTransformer.forward  s   . #7@BBD0:d(44 	u 	uOA|# H$5$G!* t}  $ A A ) aL%! ! !- aL%	! ! ),L  u}%%**$%s_bcp_q_q%s%sttt*1-
!/:-!?}%%**$%s_bcp_q_q%s%sttt +   	D 1\O C 	hgg\3Dn$Ugggggg*:KXf
 
 
 	
r@   )NNFFN)rt   ru   rv   r   rU   r0   rw   r   r   r   r   r   rr   rx   ry   s   @r4   r  r    s        ,/ , , , , , , -1,0"'%*&*C
 C
<C
 EL)C
 EL)	C

  C
 #C
 d^C
 
elC&7 88	9C
 C
 C
 C
 C
 C
 C
 C
r@   r  c                   @    e Zd ZdZeZdZdZdZdZ	dZ
dej        fdZdS )DistilBertPreTrainedModelz
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    N
distilbertTmodulec                 .   t          |t          j                  rT|j        j                            d| j        j                   |j         |j        j        	                                 dS dS t          |t          j
                  r_|j        j                            d| j        j                   |j        +|j        j        |j                 	                                 dS dS t          |t          j                  r?|j        j        	                                 |j        j                            d           dS t          |t                    r=| j        j        r3t!          | j        j        | j        j        |j        j                   dS dS dS )zInitialize the weights.r   )meanstdNg      ?)
isinstancer	   r   r   datanormal_rK   initializer_rangebiaszero_rV   rM   r\   fill_rJ   sinusoidal_pos_embdsr5   rZ   r(   r[   )rc   r0  s     r4   _init_weightsz'DistilBertPreTrainedModel._init_weightsS  s   fbi(( 	 M&&CT[5R&SSS{& &&((((( '&-- 
	M&&CT[5R&SSS!-"6#56<<>>>>> .--- 	K""$$$M$$S)))))
++ 	0P 	(3T[_fF`Fg    	 	 	 	r@   )rt   ru   rv   r   r%   config_classload_tf_weightsbase_model_prefixsupports_gradient_checkpointing_supports_flash_attn_2_supports_sdpar	   Moduler<  r  r@   r4   r.  r.  F  s^         
 $LO$&*#!NBI      r@   r.  aD  

    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, resizing the input embeddings, pruning heads
    etc.)

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

    Parameters:
        config ([`DistilBertConfig`]): 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_ids (`torch.LongTensor` of shape `({0})`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`torch.FloatTensor` of shape `({0})`, *optional*):
            Mask to avoid performing 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)
        head_mask (`torch.FloatTensor` of shape `(num_heads,)` or `(num_layers, num_heads)`, *optional*):
            Mask to nullify selected heads of the self-attention modules. Mask values selected in `[0, 1]`:

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.

        inputs_embeds (`torch.FloatTensor` of shape `({0}, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        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.
zfThe bare DistilBERT encoder/transformer outputting raw hidden-states without any specific head on top.c                       e Zd Zdef fdZdej        fdZdefdZ	dej        fdZ
dej        fd	Zd
eeeee                  f         fdZ ee                    d                     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ej        df         f         fd                        Z xZS )DistilBertModelrK   c                    t                                          |           t          |          | _        t	          |          | _        |j        dk    | _        |j        dk    | _        | 	                                 d S )Nr   r  )
rT   rU   rJ   rq   r  transformerr  _use_flash_attention_2	_use_sdpa	post_initrb   s     r4   rU   zDistilBertModel.__init__  sr       $V,,&v..&,&AEX&X#4> 	r@   rg   c                     | j         j        S z1
        Returns the position embeddings
        )rq   r[   rc   s    r4   get_position_embeddingsz'DistilBertModel.get_position_embeddings  s     22r@   new_num_position_embeddingsc                    || j         j        z
  }|dk    rdS t                              d| d           || j         _        | j        j        j                                        }t          j	        | j         j        | j         j
                  | j        _        | j         j        r1t          | j         j        | j         j
        | j        j                   nt          j                    5  |dk    r*t          j        |          | j        j        j        d| <   n+t          j        |d|                   | j        j        _        ddd           n# 1 swxY w Y   | j        j                            | j                   dS )  
        Resizes position embeddings of the model if `new_num_position_embeddings != config.max_position_embeddings`.

        Arguments:
            new_num_position_embeddings (`int`):
                The number of new position embedding matrix. If position embeddings are learned, increasing the size
                will add newly initialized vectors at the end, whereas reducing the size will remove vectors from the
                end. If position embeddings are not learned (*e.g.* sinusoidal position embeddings), increasing the
                size will add correct vectors at the end following the position encoding algorithm, whereas reducing
                the size will remove vectors from the end.
        r   Nz(Setting `config.max_position_embeddings=z`...r,   )rK   rZ   r   inforq   r[   r   cloner	   rV   r(   r;  r5   r0   no_grad	Parameterr   rj   )rc   rO  num_position_embeds_diffold_position_embeddings_weights       r4   resize_position_embeddingsz*DistilBertModel.resize_position_embeddings  s    $?Ad#d  $q((F`?Z```aaa.I+)-)L)S)Y)Y)[)[&.0l4;;^`d`k`o.p.p+;+ 	(k9t{TXTlTs       +a//]_]i6^ ^DO7>?YAY@Y?YZZ BD67P8P7PQB BDO7>               	+..t{;;;;;s   (AEEEc                     | j         j        S rs   rq   rY   rM  s    r4   get_input_embeddingsz$DistilBertModel.get_input_embeddings  s    ..r@   new_embeddingsc                     || j         _        d S rs   rZ  rc   r\  s     r4   set_input_embeddingsz$DistilBertModel.set_input_embeddings  s    *8'''r@   heads_to_prunec                     |                                 D ]/\  }}| j        j        |         j                            |           0dS )z
        Prunes heads of the model. heads_to_prune: dict of {layer_num: list of heads to prune in this layer} See base
        class PreTrainedModel
        N)itemsrG  r  r  r   )rc   r`  r  r   s       r4   _prune_headszDistilBertModel._prune_heads  sV    
 +0022 	G 	GLE5"5)3??FFFF	G 	Gr@   batch_size, num_choices
checkpointoutput_typer=  Nre   attention_maskr   inputs_embedsr   r  r  .c                    ||n| j         j        }||n| j         j        }||n| j         j        }||t	          d          |+|                     ||           |                                }n.||                                d d         }nt	          d          ||j        n|j        }	|d u }
|                     || j         j	                  }| 
                    ||          }| j        r|d|v r|nd }n@|t          j        ||	          }| j        r!|
r|st          ||j        |d                   }|                     ||||||          S )	NzDYou cannot specify both input_ids and inputs_embeds at the same timerR   z5You have to specify either input_ids or inputs_embedsr   )rj   r$   )tgt_len)r   r   r   r   r  r  )rK   r   r  use_return_dictr   %warn_if_padding_and_no_attention_maskrk   rj   get_head_masknum_hidden_layersrq   rH  r0   onesrI  r   ri   rG  )rc   re   rh  r   ri  r   r  r  input_shaperj   head_mask_is_nonerq   s               r4   rr   zDistilBertModel.forward  s     2C1N--TXT_Tq$8$D  $+Jj 	 &1%<kk$+B] ]%>cddd"66y.QQQ#..**KK&',,..ss3KKTUUU%.%:!!@T%-&&y$+2OPP	__Y>>
& 		0>0JqTbObOb^^imNN%!&K!G!G!G~ "3 <M !D"J$4k!n" " " $/!5#   
 
 	
r@   )NNNNNNN)rt   ru   rv   r   rU   r	   rV   rN  r   rX  r[  r_  r   r   rc  r   DISTILBERT_INPUTS_DOCSTRINGformatr   _CHECKPOINT_FOR_DOCr   _CONFIG_FOR_DOCr   r0   rw   r   r   r   rr   rx   ry   s   @r4   rE  rE    s       
	/ 	 	 	 	 	 	3 3 3 3 3(<c (< (< (< (<T/bl / / / /92< 9 9 9 9G4T$s)_0D+E G G G G +*+F+M+MNg+h+hii&#$   -115,004,0/3&*4
 4
EL)4
 !.4
 EL)	4

  -4
 $D>4
 'tn4
 d^4
 
elC&7 88	94
 4
 4
  ji4
 4
 4
 4
 4
r@   rE  z?DistilBert Model with a `masked language modeling` head on top.c                       e Zd ZdgZdef fdZdej        fdZde	fdZ
dej        fdZd	ej        fd
Z ee                    d                     eeee          	 	 	 	 	 	 	 	 ddeej                 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ej        df         f         fd                        Z xZS )DistilBertForMaskedLMzvocab_projector.weightrK   c                    t                                          |           t          |j                  | _        t	          |          | _        t          j        |j        |j                  | _	        t          j
        |j        d          | _        t          j        |j        |j                  | _        |                                  t          j                    | _        d S )NrN   rO   )rT   rU   r   r   rE  r/  r	   r   r(   vocab_transformr\   vocab_layer_normrW   vocab_projectorrJ  r   mlm_loss_fctrb   s     r4   rU   zDistilBertForMaskedLM.__init__/  s       ():;;)&11!yVZ@@ "VZU C C C!yV5FGG 	/11r@   rg   c                 4    | j                                         S rL  r/  rN  rM  s    r4   rN  z-DistilBertForMaskedLM.get_position_embeddings>       66888r@   rO  c                 :    | j                             |           dS rQ  Nr/  rX  rc   rO  s     r4   rX  z0DistilBertForMaskedLM.resize_position_embeddingsD  !     	223NOOOOOr@   c                     | j         S rs   r|  rM  s    r4   get_output_embeddingsz+DistilBertForMaskedLM.get_output_embeddingsR  s    ##r@   r\  c                     || _         d S rs   r  r^  s     r4   set_output_embeddingsz+DistilBertForMaskedLM.set_output_embeddingsU  s    -r@   rd  re  Nre   rh  r   ri  labelsr   r  r  .c	           	      (   ||n| j         j        }|                     |||||||          }	|	d         }
|                     |
          }|                     |          }|                     |          }|                     |          }d}|P|                     |                    d|	                    d                    |                    d                    }|s|f|	dd         z   }||f|z   n|S t          |||	j        |	j                  S )a  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
            config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
            loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
        Nre   rh  r   ri  r   r  r  r   rR   r$   losslogitsr"  r#  )rK   rl  r/  rz  r   r{  r|  r}  r   rk   r   r"  r#  )rc   re   rh  r   ri  r  r   r  r  dlbrt_outputr"  prediction_logitsmlm_lossr  s                 r4   rr   zDistilBertForMaskedLM.forwardX  sP   . &1%<kk$+B])'/!5# ' 
 
 %Q 00?? OO,=>> 112CDD 001BCC(():)?)?DUDZDZ[]D^D^)_)_agalalmoapapqqH 	N')L,<<F-5-AXK&((vM$&4#.	
 
 
 	
r@   NNNNNNNN)rt   ru   rv   _tied_weights_keysr   rU   r	   rV   rN  r   rX  rC  r  r  r   rs  rt  r   ru  r   rv  r   r0   rw   
LongTensorr   r   r   rr   rx   ry   s   @r4   rx  rx  (  s       
 332/ 2 2 2 2 2 29 9 9 9 9Pc P P P P$ry $ $ $ $.BI . . . . +*+F+M+MNg+h+hii&"$   -115,004-1,0/3&*/
 /
EL)/
 !./
 EL)	/

  -/
 )*/
 $D>/
 'tn/
 d^/
 
~uU\3%677	8/
 /
 /
  ji/
 /
 /
 /
 /
r@   rx  z
    DistilBert Model transformer with a sequence classification/regression head on top (a linear layer on top of the
    pooled output) e.g. for GLUE tasks.
    c                       e Zd Zdef fdZdej        fdZdefdZ	 e
e                    d                     eeee          	 	 	 	 	 	 	 	 dd
eej                 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ej        df         f         fd                        Z xZS )#DistilBertForSequenceClassificationrK   c                    t                                          |           |j        | _        || _        t	          |          | _        t          j        |j        |j                  | _	        t          j        |j        |j                  | _
        t          j        |j                  | _        |                                  d S rs   )rT   rU   
num_labelsrK   rE  r/  r	   r   r(   pre_classifier
classifierr]   seq_classif_dropoutr^   rJ  rb   s     r4   rU   z,DistilBertForSequenceClassification.__init__  s        +)&11 i
FJ??)FJ0ABBz&"<== 	r@   rg   c                 4    | j                                         S rL  r  rM  s    r4   rN  z;DistilBertForSequenceClassification.get_position_embeddings  r  r@   rO  c                 :    | j                             |           dS r  r  r  s     r4   rX  z>DistilBertForSequenceClassification.resize_position_embeddings  r  r@   zbatch_size, sequence_lengthre  Nre   rh  r   ri  r  r   r  r  .c	           	      d   ||n| j         j        }|                     |||||||          }	|	d         }
|
dddf         }|                     |          } t	          j                    |          }|                     |          }|                     |          }d}|Z| j         j        f| j	        dk    rd| j         _        nN| j	        dk    r7|j
        t          j        k    s|j
        t          j        k    rd| j         _        nd| j         _        | j         j        dk    rWt                      }| j	        dk    r1 ||                                |                                          }n |||          }n| j         j        dk    rGt!                      } ||                    d| j	                  |                    d                    }n*| j         j        dk    rt%                      } |||          }|s|f|	dd         z   }||f|z   n|S t'          |||	j        |	j        	          S )
a  
        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).
        Nr  r   r$   
regressionsingle_label_classificationmulti_label_classificationrR   r  )rK   rl  r/  r  r	   ReLUr^   r  problem_typer  ri   r0   rm   r   r   squeezer   r   r
   r   r"  r#  )rc   re   rh  r   ri  r  r   r  r  distilbert_outputr)  pooled_outputr  r  loss_fctr  s                   r4   rr   z+DistilBertForSequenceClassification.forward  sT   . &1%<kk$+B] OO)'/!5# , 
 
 )+$QQQT*++M::!		-00]33//{'/?a''/;DK,,_q((flej.H.HFL\a\eLeLe/LDK,,/KDK,{'<77"99?a''#8FNN$4$4fnn6F6FGGDD#8FF33DD)-JJJ+--xB @ @&++b//RR)-III,..x// 	FY!2122!66F)-)9TGf$$vE'+9(3	
 
 
 	
r@   r  )rt   ru   rv   r   rU   r	   rV   rN  r   rX  r   rs  rt  r   ru  r   rv  r   r0   rw   r  r   r   r   rr   rx   ry   s   @r4   r  r    s       /      9 9 9 9 9Pc P P P P +*+F+M+MNk+l+lmm&,$   -115,004-1,0/3&*C
 C
EL)C
 !.C
 EL)	C

  -C
 )*C
 $D>C
 'tnC
 d^C
 
'u|S/@)AA	BC
 C
 C
  nmC
 C
 C
 C
 C
r@   r  z
    DistilBert Model with a span classification head on top for extractive question-answering tasks like SQuAD (a
    linear layers on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c                       e Zd Zdef fdZdej        fdZdefdZ	 e
e                    d                     eeee          	 	 	 	 	 	 	 	 	 dd
eej                 deej                 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ej        df         f         fd                        Z xZS )DistilBertForQuestionAnsweringrK   c                 b   t                                          |           t          |          | _        t	          j        |j        |j                  | _        |j        dk    rt          d|j                   t	          j
        |j                  | _        |                                  d S )Nr9   z)config.num_labels should be 2, but it is )rT   rU   rE  r/  r	   r   r(   r  
qa_outputsr   r]   
qa_dropoutr^   rJ  rb   s     r4   rU   z'DistilBertForQuestionAnswering.__init__  s       )&11)FJ0ABB!!\IZ\\]]]z&"344 	r@   rg   c                 4    | j                                         S rL  r  rM  s    r4   rN  z6DistilBertForQuestionAnswering.get_position_embeddings  r  r@   rO  c                 :    | j                             |           dS r  r  r  s     r4   rX  z9DistilBertForQuestionAnswering.resize_position_embeddings   r  r@   rd  re  Nre   rh  r   ri  start_positionsend_positionsr   r  r  .c
           	         |	|	n| j         j        }	|                     |||||||	          }
|
d         }|                     |          }|                     |          }|                    dd          \  }}|                    d                                          }|                    d                                          }d}||t          |	                                          dk    r|                    d          }t          |	                                          dk    r|                    d          }|	                    d          }|
                    d|          }|
                    d|          }t          j        |          } |||          } |||          }||z   dz  }|	s||f|
dd         z   }||f|z   n|S t          ||||
j        |
j        	          S )
a  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        Nr  r   r$   rR   r   )ignore_indexr9   )r  start_logits
end_logitsr"  r#  )rK   rl  r/  r^   r  splitr  r   r   rk   clampr	   r   r   r"  r#  )rc   re   rh  r   ri  r  r  r   r  r  r  r"  r  r  r  
total_lossignored_indexr  
start_lossend_lossr  s                        r4   rr   z&DistilBertForQuestionAnswering.forward.  s%   8 &1%<kk$+B] OO)'/!5# , 
 
 *!,]33//#)<<r<#:#: j#++B//::<<''++6688

&=+D?''))**Q.."1"9"9""="==%%''((1,, - 5 5b 9 9(--a00M-33A}EEO)//=AAM*FFFH!,@@Jx
M::H$x/14J 	R"J/2CABB2GGF/9/EZMF**6Q+%!+9(3
 
 
 	
r@   )	NNNNNNNNN)rt   ru   rv   r   rU   r	   rV   rN  r   rX  r   rs  rt  r   ru  r   rv  r   r0   rw   r   r   r   rr   rx   ry   s   @r4   r  r    s       /      9 9 9 9 9Pc P P P P +*+F+M+MNg+h+hii&0$   -115,0042604,0/3&*D
 D
EL)D
 !.D
 EL)	D

  -D
 "%,/D
  -D
 $D>D
 'tnD
 d^D
 
+U5<3D-EE	FD
 D
 D
  jiD
 D
 D
 D
 D
r@   r  z
    DistilBert Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g.
    for Named-Entity-Recognition (NER) tasks.
    c                       e Zd Zdef fdZdej        fdZdefdZ	 e
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j                 dee         dee         dee         deeeej        df         f         fd                        Z xZS ) DistilBertForTokenClassificationrK   c                 6   t                                          |           |j        | _        t          |          | _        t          j        |j                  | _        t          j        |j	        |j                  | _
        |                                  d S rs   )rT   rU   r  rE  r/  r	   r]   r^   r   hidden_sizer  rJ  rb   s     r4   rU   z)DistilBertForTokenClassification.__init__  sx        +)&11z&.11)F$68IJJ 	r@   rg   c                 4    | j                                         S rL  r  rM  s    r4   rN  z8DistilBertForTokenClassification.get_position_embeddings  r  r@   rO  c                 :    | j                             |           dS r  r  r  s     r4   rX  z;DistilBertForTokenClassification.resize_position_embeddings  r  r@   re  Nre   rh  r   ri  r  r   r  r  .c	           	         ||n| j         j        }|                     |||||||          }	|	d         }
|                     |
          }
|                     |
          }d}|Ft                      } ||                    d| j                  |                    d                    }|s|f|	dd         z   }||f|z   n|S t          |||	j	        |	j
                  S )z
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
        Nrh  r   ri  r   r  r  r   rR   r$   r  )rK   rl  r/  r^   r  r   r   r  r   r"  r#  )rc   re   rh  r   ri  r  r   r  r  outputssequence_outputr  r  r  r  s                  r4   rr   z(DistilBertForTokenClassification.forward  s   * &1%<kk$+B]//)'/!5# " 
 
 "!*,,7711'))H8FKKDO<<fkk"ooNND 	FY,F)-)9TGf$$vE$!/)	
 
 
 	
r@   r  )rt   ru   rv   r   rU   r	   rV   rN  r   rX  r   rs  r   ru  r   rv  r   r0   rw   r  r   r   r   rr   rx   ry   s   @r4   r  r  {  s       	/ 	 	 	 	 	 	9 9 9 9 9Pc P P P P +*+FGG&)$   -115,004-1,0/3&*.
 .
EL).
 !..
 EL)	.

  -.
 )*.
 $D>.
 'tn.
 d^.
 
$eEL#,=&>>	?.
 .
 .
  HG.
 .
 .
 .
 .
r@   r  z
    DistilBert Model with a multiple choice classification head on top (a linear layer on top of the pooled output and
    a softmax) e.g. for RocStories/SWAG tasks.
    c                       e Zd Zdef fdZdej        fdZdefdZ	 e
e                    d                     eee          	 	 	 	 	 	 	 	 dd
eej                 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ej        df         f         fd                        Z xZS )DistilBertForMultipleChoicerK   c                 \   t                                          |           t          |          | _        t	          j        |j        |j                  | _        t	          j        |j        d          | _        t	          j	        |j
                  | _        |                                  d S )Nr$   )rT   rU   rE  r/  r	   r   r(   r  r  r]   r  r^   rJ  rb   s     r4   rU   z$DistilBertForMultipleChoice.__init__  s       )&11 i
FJ??)FJ22z&"<== 	r@   rg   c                 4    | j                                         S rL  r  rM  s    r4   rN  z3DistilBertForMultipleChoice.get_position_embeddings  r  r@   rO  c                 :    | j                             |           dS )a  
        Resizes position embeddings of the model if `new_num_position_embeddings != config.max_position_embeddings`.

        Arguments:
            new_num_position_embeddings (`int`)
                The number of new position embeddings. If position embeddings are learned, increasing the size will add
                newly initialized vectors at the end, whereas reducing the size will remove vectors from the end. If
                position embeddings are not learned (*e.g.* sinusoidal position embeddings), increasing the size will
                add correct vectors at the end following the position encoding algorithm, whereas reducing the size
                will remove vectors from the end.
        Nr  r  s     r4   rX  z6DistilBertForMultipleChoice.resize_position_embeddings  r  r@   z(batch_size, num_choices, sequence_length)rg  r=  Nre   rh  r   ri  r  r   r  r  .c	           	      |   ||n| j         j        }||j        d         n|j        d         }	|)|                    d|                    d                    nd}|)|                    d|                    d                    nd}|=|                    d|                    d          |                    d                    nd}|                     |||||||          }
|
d         }|dddf         }|                     |          } t          j                    |          }| 	                    |          }| 
                    |          }|                    d|	          }d}|t                      } |||          }|s|f|
dd         z   }||f|z   n|S t          |||
j        |
j                  S )aW  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the multiple choice classification loss. Indices should be in `[0, ...,
            num_choices-1]` where `num_choices` is the size of the second dimension of the input tensors. (See
            `input_ids` above)

        Returns:

        Examples:

        ```python
        >>> from transformers import AutoTokenizer, DistilBertForMultipleChoice
        >>> import torch

        >>> tokenizer = AutoTokenizer.from_pretrained("distilbert-base-cased")
        >>> model = DistilBertForMultipleChoice.from_pretrained("distilbert-base-cased")

        >>> prompt = "In Italy, pizza served in formal settings, such as at a restaurant, is presented unsliced."
        >>> choice0 = "It is eaten with a fork and a knife."
        >>> choice1 = "It is eaten while held in the hand."
        >>> labels = torch.tensor(0).unsqueeze(0)  # choice0 is correct (according to Wikipedia ;)), batch size 1

        >>> encoding = tokenizer([[prompt, choice0], [prompt, choice1]], return_tensors="pt", padding=True)
        >>> outputs = model(**{k: v.unsqueeze(0) for k, v in encoding.items()}, labels=labels)  # batch size is 1

        >>> # the linear classifier still needs to be trained
        >>> loss = outputs.loss
        >>> logits = outputs.logits
        ```Nr$   rR   r  r   r  )rK   rl  r   r   rk   r/  r  r	   r  r^   r  r   r   r"  r#  )rc   re   rh  r   ri  r  r   r  r  num_choicesr  r)  r  r  reshaped_logitsr  r  r  s                     r4   rr   z#DistilBertForMultipleChoice.forward   s   X &1%<kk$+B],5,Aioa((}GZ[\G]>G>SINN2y~~b'9'9:::Y]	M[Mg,,R1D1DR1H1HIIImq ( r=#5#5b#9#9=;M;Mb;Q;QRRR 	 //)'/!5# " 
 
 qz$QQQT*++M::!		-00]33// ++b+66'))H8OV44D 	F%''!""+5F)-)9TGf$$vE("!/)	
 
 
 	
r@   r  )rt   ru   rv   r   rU   r	   rV   rN  r   rX  r   rs  rt  r#   r   rv  r   r0   rw   r  r   r   r   rr   rx   ry   s   @r4   r  r    s       	/ 	 	 	 	 	 	9 9 9 9 9Pc P P P P +*#**+UVV  +DSbccc -115,004-1,0/3&*T
 T
EL)T
 !.T
 EL)	T

  -T
 )*T
 $D>T
 'tnT
 d^T
 
(%c0A*BB	CT
 T
 T
 dc T
 T
 T
 T
 T
r@   r  )Nr   r   typingr   r   r   r   r   r   numpyr:   r0   r	   torch.nnr
   r   r   activationsr   configuration_utilsr   integrations.deepspeedr   modeling_attn_mask_utilsr   modeling_outputsr   r   r   r   r   r   modeling_utilsr   pytorch_utilsr   r   r   r   utilsr   r   r   r    r!   r"   r#   configuration_distilbertr%   modeling_flash_attention_utilsr&   
get_loggerrt   r   ru  rv  r   rw   r5   r3   rC  rJ   r{   r   r   r   r  r  r  r.  DISTILBERT_START_DOCSTRINGrs  rE  rx  r  r  r  r  r  r@   r4   <module>r     sR    
  : : : : : : : : : : : : : : : :            A A A A A A A A A A ) ) ) ) ) ) 3 3 3 3 3 3 @ @ @ @ @ @ K K K K K K                . - - - - -                             7 6 6 6 6 6  KJJJJJJ 
	H	%	%/ $E E# EEL E E E E 3 U\    + + + + + + + +\e e e e eRY e e eP^" ^" ^" ^" ^" 6 ^" ^" ^"BM M M M M4 M M M`    ")   , $2#    7 7 7 7 7ry 7 7 7tJ
 J
 J
 J
 J
") J
 J
 J
\       D  " J l D
 D
 D
 D
 D
/ D
 D
	 D
N I a
 a
 a
 a
 a
5 a
 a
	 a
H   k
 k
 k
 k
 k
*C k
 k
 k
\   l
 l
 l
 l
 l
%> l
 l
 l
^   T
 T
 T
 T
 T
'@ T
 T
 T
n   x
 x
 x
 x
 x
"; x
 x
 x
 x
 x
r@   