
    bCi&                    &   S r SSKrSSKJrJr  SSKrSSKJr  SSKJrJ	r	J
r
  SSKJrJr  SSKJrJrJr  SS	KJr  SS
KJrJr  SSKJr  SSKJrJrJrJrJrJrJ r J!r!  SSK"J#r#  SSK$J%r%J&r&J'r'  SSK(J)r)J*r*  SSK+J,r,  SSK-J.r.  \*R^                  " \05      r1 " S S\Rd                  5      r3 " S S\Rd                  5      r4 " S S\45      r5 " S S\Rd                  5      r6\4\5S.r7 " S S\Rd                  5      r8 " S S\Rd                  5      r9 " S  S!\Rd                  5      r: " S" S#\5      r; " S$ S%\Rd                  5      r< " S& S'\Rd                  5      r=\) " S( S)\#5      5       r> " S* S+\Rd                  5      r? " S, S-\Rd                  5      r@\) " S. S/\>5      5       rA\) " S0 S1\>5      5       rB\)" S2S39 " S4 S5\>5      5       rC\) " S6 S7\>5      5       rD\) " S8 S9\>5      5       rE\) " S: S;\>5      5       rF\)" S<S39 " S= S>\>\5      5       rGSAS? jrH/ S@QrIg)BzPyTorch CamemBERT model.    N)OptionalUnion)nn)BCEWithLogitsLossCrossEntropyLossMSELoss   )ACT2FNgelu)CacheDynamicCacheEncoderDecoderCache)GenerationMixin)#_prepare_4d_attention_mask_for_sdpa*_prepare_4d_causal_attention_mask_for_sdpa)GradientCheckpointingLayer))BaseModelOutputWithPastAndCrossAttentions,BaseModelOutputWithPoolingAndCrossAttentions!CausalLMOutputWithCrossAttentionsMaskedLMOutputMultipleChoiceModelOutputQuestionAnsweringModelOutputSequenceClassifierOutputTokenClassifierOutput)PreTrainedModel)apply_chunking_to_forward find_pruneable_heads_and_indicesprune_linear_layer)auto_docstringlogging)deprecate_kwarg   )CamembertConfigc                   >   ^  \ rS rSrSrU 4S jr SS jrS rSrU =r	$ )CamembertEmbeddings3   zN
Same as BertEmbeddings with a tiny tweak for positional embeddings indexing.
c                   > [         TU ]  5         [        R                  " UR                  UR
                  UR                  S9U l        [        R                  " UR                  UR
                  5      U l	        [        R                  " UR                  UR
                  5      U l        [        R                  " UR
                  UR                  S9U l        [        R                  " UR                  5      U l        [#        USS5      U l        U R'                  S[(        R*                  " UR                  5      R-                  S5      SS9  U R'                  S	[(        R.                  " U R0                  R3                  5       [(        R4                  S
9SS9  UR                  U l        [        R                  " UR                  UR
                  U R6                  S9U l	        g )N)padding_idxepsposition_embedding_typeabsoluteposition_ids)r"   F)
persistenttoken_type_idsdtype)super__init__r   	Embedding
vocab_sizehidden_sizepad_token_idword_embeddingsmax_position_embeddingsposition_embeddingstype_vocab_sizetoken_type_embeddings	LayerNormlayer_norm_epsDropouthidden_dropout_probdropoutgetattrr+   register_buffertorcharangeexpandzerosr-   sizelongr(   selfconfig	__class__s     j/home/james-whalen/.local/lib/python3.13/site-packages/transformers/models/camembert/modeling_camembert.pyr4   CamembertEmbeddings.__init__9   si   !||F,=,=v?Q?Q_e_r_rs#%<<0N0NPVPbPb#c %'\\&2H2H&J\J\%]" f&8&8f>S>STzz&"<"<='.v7PR\']$ELL)G)GHOOPWXej 	 	
 	ekk$*;*;*@*@*B%**Ubg 	 	

 "..#%<<**F,>,>DL\L\$
     c                    Uc+  Ub  [        XR                  U5      nOU R                  U5      nUb  UR                  5       nOUR                  5       S S nUS   nUcv  [	        U S5      (       a-  U R
                  S S 2S U24   nUR                  US   U5      n	U	nO8[        R                  " U[        R                  U R                  R                  S9nUc  U R                  U5      nU R                  U5      n
XJ-   nU R                  S:X  a  U R                  U5      nX-  nU R!                  U5      nU R#                  U5      nU$ )Nr.   r"   r0   r   r2   devicer,   )"create_position_ids_from_input_idsr(   &create_position_ids_from_inputs_embedsrI   hasattrr0   rG   rE   rH   rJ   r-   rT   r9   r=   r+   r;   r>   rB   )rL   	input_idsr0   r-   inputs_embedspast_key_values_lengthinput_shape
seq_lengthbuffered_token_type_ids buffered_token_type_ids_expandedr=   
embeddingsr;   s                rO   forwardCamembertEmbeddings.forwardR   sM    $A)M]M]_uv#JJ=Y #..*K',,.s3K ^

 !t-..*.*=*=a*n*M'3J3Q3QR]^_R`bl3m0!A!&[

SWSdSdSkSk!l  00;M $ : :> J":
'':5"&":":<"H-J^^J/
\\*-
rQ   c                    UR                  5       SS nUS   n[        R                  " U R                  S-   X0R                  -   S-   [        R                  UR
                  S9nUR                  S5      R                  U5      $ )z
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.

Args:
    inputs_embeds: torch.Tensor

Returns: torch.Tensor
Nr.   r"   rS   r   )rI   rE   rF   r(   rJ   rT   	unsqueezerG   )rL   rY   r[   sequence_lengthr-   s        rO   rV   :CamembertEmbeddings.create_position_ids_from_inputs_embedsz   s~     $((*3B/%a.||q /4D4D"Dq"HPUPZPZcpcwcw
 %%a(//<<rQ   )r>   rB   r(   r+   r;   r=   r9   )NNNNr   )
__name__
__module____qualname____firstlineno____doc__r4   r`   rV   __static_attributes____classcell__rN   s   @rO   r%   r%   3   s$    

4 rs&P= =rQ   r%   c                     ^  \ rS rSrSU 4S jjr\" SSSS9      SS\R                  S\\R                     S	\\R                     S
\\R                     S\\
   S\\   S\\R                     S\\R                     4S jj5       rSrU =r$ )CamembertSelfAttention   c                   > [         TU ]  5         UR                  UR                  -  S:w  a7  [	        US5      (       d&  [        SUR                   SUR                   S35      eUR                  U l        [        UR                  UR                  -  5      U l        U R                  U R                  -  U l        [        R                  " UR                  U R                  5      U l        [        R                  " UR                  U R                  5      U l        [        R                  " UR                  U R                  5      U l        [        R                  " UR                  5      U l        U=(       d    [#        USS5      U l        U R$                  S:X  d  U R$                  S	:X  aG  UR&                  U l        [        R(                  " S
UR&                  -  S-
  U R                  5      U l        UR,                  U l        X0l        g )Nr   embedding_sizezThe hidden size (z6) is not a multiple of the number of attention heads ()r+   r,   relative_keyrelative_key_query   r"   )r3   r4   r7   num_attention_headsrW   
ValueErrorintattention_head_sizeall_head_sizer   Linearquerykeyvaluer@   attention_probs_dropout_probrB   rC   r+   r:   r5   distance_embedding
is_decoder	layer_idxrL   rM   r+   r   rN   s       rO   r4   CamembertSelfAttention.__init__   s    : ::a?PVXhHiHi#F$6$6#7 8 445Q8 
 $*#=#= #&v'9'9F<V<V'V#W !558P8PPYYv1143E3EF
99V//1C1CDYYv1143E3EF
zz&"E"EF'> (
'-zC
$ ''>9T=Y=Y]q=q+1+I+ID(&(ll1v7U7U3UXY3Y[_[s[s&tD# ++"rQ   past_key_valuepast_key_values4.58new_nameversionhidden_statesattention_mask	head_maskencoder_hidden_statesoutput_attentionscache_positionreturnc                 	   UR                   u  pn
U R                  U5      nUR                  USU R                  U R                  5      R                  SS5      nSnUS LnUb]  [        U[        5      (       aF  UR                  R                  U R                  5      nU(       a  UR                  nOUR                  nOUnU(       a  UOUnU(       aQ  UbN  U(       aG  WR                  U R                     R                  nUR                  U R                     R                  nOU R!                  U5      nUR                  USU R                  U R                  5      R                  SS5      nU R#                  U5      nUR                  USU R                  U R                  5      R                  SS5      nUbc  U(       d  UOS nWR%                  UUU R                  SU05      u  nnU(       a.  [        U[        5      (       a  SUR                  U R                  '   [&        R(                  " UUR                  SS5      5      nU R*                  S:X  d  U R*                  S	:X  Ga  UR                   S   UR                   S   nnUbB  [&        R,                  " US-
  [&        R.                  UR0                  S
9R                  SS5      nO>[&        R2                  " U[&        R.                  UR0                  S
9R                  SS5      n[&        R2                  " U[&        R.                  UR0                  S
9R                  SS5      nUU-
  nU R5                  UU R6                  -   S-
  5      nUR9                  UR:                  S9nU R*                  S:X  a  [&        R<                  " SUU5      nUU-   nOHU R*                  S	:X  a8  [&        R<                  " SUU5      n[&        R<                  " SUU5      nUU-   U-   nU[>        R@                  " U R                  5      -  nUb  UU-   n[B        RD                  RG                  USS9nU RI                  U5      nUb  UU-  n[&        R(                  " UU5      nURK                  SSSS5      RM                  5       nURO                  5       S S U RP                  4-   nUR                  U5      nUU4$ )Nr.   r"   rv   Fr   Trt   ru   rS   r1   zbhld,lrd->bhlrzbhrd,lrd->bhlrdimr   r	   ))shaper}   viewrw   rz   	transpose
isinstancer   
is_updatedgetr   cross_attention_cacheself_attention_cachelayerskeysvaluesr~   r   updaterE   matmulr+   tensorrJ   rT   rF   r   r:   tor2   einsummathsqrtr   
functionalsoftmaxrB   permute
contiguousrI   r{   )rL   r   r   r   r   r   r   r   
batch_sizer\   _query_layerr   is_cross_attentioncurr_past_key_valuecurrent_states	key_layervalue_layerattention_scoresquery_length
key_lengthposition_ids_lposition_ids_rdistancepositional_embeddingrelative_position_scoresrelative_position_scores_queryrelative_position_scores_keyattention_probscontext_layernew_context_layer_shapes                                  rO   r`   CamembertSelfAttention.forward   sa    %2$7$7!
jj/!&&z2t7O7OQUQiQijttq
 
2$>&/+>??,77;;DNNK
%*9*O*O'*9*N*N'&5#2D.-/"=*+224>>BGGI-44T^^DKKK0I!z2t7O7OQUQiQijtt1I **^4K%**B 8 8$:R:Ri1o  *7It)<)C)C{DNN=M~<^*&	; &*_FY*Z*ZAEO..t~~> !<<Y5H5HR5PQ''>9T=Y=Y]q=q'2'8'8';Y__Q=O*L*!&j1nEJJWdWkWk!l!q!q" "'l%**UbUiUi!j!o!oprtu!v"\\*EJJ}OcOcdiijkmopN%6H#'#:#:8dFbFb;bef;f#g #7#:#:ARAR#:#S ++~=+0<<8H+Wk+l(#36N#N --1EE16>NP[]q1r./4||<LiYm/n,#36T#TWs#s +dii8P8P.QQ%/.@ --//0@b/I ,,7  -	9O_kB%--aAq9DDF"/"4"4"6s";t?Q?Q>S"S%**+BCo--rQ   )r{   rz   r   rB   r   r~   r   r:   rw   r+   r}   r   NNNNNNFNrf   rg   rh   ri   r4   r!   rE   Tensorr   FloatTensorr   booltupler`   rk   rl   rm   s   @rO   ro   ro      s    #6 %0A6R 7;15=A+/,115e.||e. !!2!23e. E--.	e.
  ((9(9:e. "%e. $D>e. !.e. 
u||	e. Se.rQ   ro   c                   $  ^  \ rS rSrSU 4S jjr\" SSSS9      SS\R                  S\\R                     S	\\R                     S
\\R                     S\\
   S\\   S\\R                     S\\R                     4U 4S jjj5       rSrU =r$ )CamembertSdpaSelfAttentioni  c                 D   > [         TU ]  XUS9  UR                  U l        g Nr+   r   )r3   r4   r   dropout_probr   s       rO   r4   #CamembertSdpaSelfAttention.__init__  s$    \ef"??rQ   r   r   r   r   r   r   r   r   r   r   r   c           	      (  > U R                   S:w  d
  U(       d  Ub*  [        R                  S5        [        TU ]  UUUUUUU5      $ UR                  5       u  pn
U R                  U5      R                  USU R                  U R                  5      R                  SS5      nSnUS LnU(       a  UOUnUb]  [        U[        5      (       aF  UR                  R                  U R                  5      nU(       a  UR                   nOUR"                  nOUnU(       a  UOUnU(       aQ  UbN  U(       aG  WR$                  U R                     R&                  nUR$                  U R                     R(                  nOU R+                  U5      R                  USU R                  U R                  5      R                  SS5      nU R-                  U5      R                  USU R                  U R                  5      R                  SS5      nUbc  U(       d  UOS nWR/                  UUU R                  SU05      u  nnU(       a.  [        U[        5      (       a  SUR                  U R                  '   U R0                  =(       a    U(       + =(       a    US L =(       a    U	S:  n[2        R4                  R6                  R9                  UUUUU R:                  (       a  U R<                  OS	US
9nUR                  SS5      nUR?                  XU R@                  5      nUS 4$ )Nr,   a  CamembertSdpaSelfAttention is used but `torch.nn.functional.scaled_dot_product_attention` does not support non-absolute `position_embedding_type` or `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.   r"   rv   Fr   T        )	attn_mask	dropout_p	is_causal)!r+   loggerwarning_oncer3   r`   rI   r}   r   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r~   r   r   r   rE   r   r   scaled_dot_product_attentiontrainingr   reshaper{   )rL   r   r   r   r   r   r   r   bsztgt_lenr   r   r   r   r   r   r   r   r   attn_outputrN   s                       rO   r`   "CamembertSdpaSelfAttention.forward  s    '':59JiNcH 7?%!  (,,.a JJ}%**3D4L4LdNfNfgqqrsuvw 	 
2$>2D.-&/+>??,77;;DNNK
%*9*O*O'*9*N*N'&5#2D.-/"=*+224>>BGGI-44T^^DKKK (c2t779Q9QR1a  

>*c2t779Q9QR1a  *7It)<)C)C{DNN=M~<^*&	; &*_FY*Z*ZAEO..t~~> OOi,>(>i>UYCYi^ehi^i	hh))FF$+/==d''c G 
 "++Aq1!))#8J8JKD  rQ   )r   r   r   r   rm   s   @rO   r   r     s    @
 %0A6R 2615=A+/,115^!||^! !.^! E--.	^!
  ((9(9:^! "%^! $D>^! !.^! 
u||	^! S^!rQ   r   c                   z   ^  \ rS rSrU 4S jrS\R                  S\R                  S\R                  4S jrSrU =r	$ )CamembertSelfOutputi|  c                 (  > [         TU ]  5         [        R                  " UR                  UR                  5      U l        [        R                  " UR                  UR                  S9U l        [        R                  " UR                  5      U l
        g Nr)   )r3   r4   r   r|   r7   denser>   r?   r@   rA   rB   rK   s     rO   r4   CamembertSelfOutput.__init__}  s`    YYv1163E3EF
f&8&8f>S>STzz&"<"<=rQ   r   input_tensorr   c                 p    U R                  U5      nU R                  U5      nU R                  X-   5      nU$ Nr   rB   r>   rL   r   r   s      rO   r`   CamembertSelfOutput.forward  5    

=1]3}'CDrQ   r>   r   rB   
rf   rg   rh   ri   r4   rE   r   r`   rk   rl   rm   s   @rO   r   r   |  6    >U\\  RWR^R^  rQ   r   )eagersdpac                   $  ^  \ rS rSrSU 4S jjrS r\" SSSS9      SS\R                  S	\	\R                     S
\	\R                     S\	\R                     S\	\   S\	\   S\	\R                     S\\R                     4S jj5       rSrU =r$ )CamembertAttentioni  c                    > [         TU ]  5         [        UR                     " UUUS9U l        [        U5      U l        [        5       U l        g r   )	r3   r4    CAMEMBERT_SELF_ATTENTION_CLASSES_attn_implementationrL   r   outputsetpruned_headsr   s       rO   r4   CamembertAttention.__init__  sF    4V5P5PQ$;
	
 *&1ErQ   c                 6   [        U5      S:X  a  g [        XR                  R                  U R                  R                  U R
                  5      u  p[        U R                  R                  U5      U R                  l        [        U R                  R                  U5      U R                  l        [        U R                  R                  U5      U R                  l	        [        U R                  R                  USS9U R                  l        U R                  R                  [        U5      -
  U R                  l        U R                  R                  U R                  R                  -  U R                  l        U R
                  R                  U5      U l        g )Nr   r"   r   )lenr   rL   rw   rz   r   r   r}   r~   r   r   r   r{   union)rL   headsindexs      rO   prune_headsCamembertAttention.prune_heads  s   u:?79900$))2O2OQUQbQb

 -TYY__eD		*499==%@		,TYY__eD		.t{{/@/@%QO )-		(E(EE
(R		%"&))"?"?$))B_B_"_		 --33E:rQ   r   r   r   r   r   r   r   r   r   r   r   c           
      l    U R                  UUUUUUUS9nU R                  US   U5      n	U	4USS  -   n
U
$ )Nr   r   r   r   r   r   r   r"   )rL   r   )rL   r   r   r   r   r   r   r   self_outputsattention_outputoutputss              rO   r`   CamembertAttention.forward  s\     yy)"7+/) ! 
  ;;|AF#%QR(88rQ   )r   r   rL   r   r   )rf   rg   rh   ri   r4   r   r!   rE   r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r   r     s    ";$ %0A6R 7;15=A+/,115|| !!2!23 E--.	
  ((9(9: "% $D> !. 
u||	 SrQ   r   c                   b   ^  \ rS rSrU 4S jrS\R                  S\R                  4S jrSrU =r	$ )CamembertIntermediatei  c                   > [         TU ]  5         [        R                  " UR                  UR
                  5      U l        [        UR                  [        5      (       a  [        UR                     U l        g UR                  U l        g r   )r3   r4   r   r|   r7   intermediate_sizer   r   
hidden_actstrr
   intermediate_act_fnrK   s     rO   r4   CamembertIntermediate.__init__  s`    YYv1163K3KL
f''--'-f.?.?'@D$'-'8'8D$rQ   r   r   c                 J    U R                  U5      nU R                  U5      nU$ r   r   r  )rL   r   s     rO   r`   CamembertIntermediate.forward  s&    

=100?rQ   r  r   rm   s   @rO   r  r    s(    9U\\ ell  rQ   r  c                   z   ^  \ rS rSrU 4S jrS\R                  S\R                  S\R                  4S jrSrU =r	$ )CamembertOutputi  c                 (  > [         TU ]  5         [        R                  " UR                  UR
                  5      U l        [        R                  " UR
                  UR                  S9U l        [        R                  " UR                  5      U l        g r   )r3   r4   r   r|   r
  r7   r   r>   r?   r@   rA   rB   rK   s     rO   r4   CamembertOutput.__init__  s`    YYv779K9KL
f&8&8f>S>STzz&"<"<=rQ   r   r   r   c                 p    U R                  U5      nU R                  U5      nU R                  X-   5      nU$ r   r   r   s      rO   r`   CamembertOutput.forward  r   rQ   r   r   rm   s   @rO   r  r    r   rQ   r  c                   D  ^  \ rS rSrSU 4S jjr\" SSSS9       SS\R                  S\\R                     S	\\R                     S
\\R                     S\\R                     S\\
   S\\   S\\R                     S\\R                     4S jj5       rS rSrU =r$ )CamembertLayeri  c                 r  > [         TU ]  5         UR                  U l        SU l        [	        XS9U l        UR                  U l        UR                  U l        U R                  (       a/  U R                  (       d  [        U  S35      e[	        USUS9U l	        [        U5      U l        [        U5      U l        g )Nr"   r   z> should be used as a decoder model if cross attention is addedr,   r   )r3   r4   chunk_size_feed_forwardseq_len_dimr   	attentionr   add_cross_attentionrx   crossattentionr  intermediater  r   )rL   rM   r   rN   s      rO   r4   CamembertLayer.__init__  s    '-'E'E$+FH ++#)#=#= ##?? D6)g!hii"4VU_kt"uD1&9%f-rQ   r   r   r   r   r   r   r   r   encoder_attention_maskr   r   r   c	           
      P   U R                  UUUUUUS9n	U	S   n
U	SS  nU R                  (       aD  UbA  [        U S5      (       d  [        SU  S35      eU R	                  U
UUUUUUS9nUS   n
XSS  -   n[        U R                  U R                  U R                  U
5      nU4U-   nU$ )N)r   r   r   r   r   r   r"   r   z'If `encoder_hidden_states` are passed, z` has to be instantiated with cross-attention layers by setting `config.add_cross_attention=True`r  )	r  r   rW   rx   r   r   feed_forward_chunkr  r  )rL   r   r   r   r   r#  r   r   r   self_attention_outputsr  r  cross_attention_outputslayer_outputs                 rO   r`   CamembertLayer.forward  s    "&)/+) "0 "
 2!4(,??4@4!122 =dV DD D 
 '+&9&9 5#&; /"3- ': '#  7q9 ;;G0##T%A%A4CSCSUe
  /G+rQ   c                 J    U R                  U5      nU R                  X!5      nU$ r   )r!  r   )rL   r  intermediate_outputr(  s       rO   r%  !CamembertLayer.feed_forward_chunk'  s)    "//0@A{{#6IrQ   )r  r  r  r   r!  r   r   r  r   )NNNNNFN)rf   rg   rh   ri   r4   r!   rE   r   r   r   r   r   r   r`   r%  rk   rl   rm   s   @rO   r  r    s    . %0A6R 7;15=A>B+/,115.||. !!2!23. E--.	.
  ((9(9:. !)):): ;. "%. $D>. !.. 
u||	. S.` rQ   r  c                   V  ^  \ rS rSrSU 4S jjr          SS\R                  S\\R                     S\\R                     S\\R                     S\\R                     S\\	   S	\\
   S
\\
   S\\
   S\\
   S\\R                     S\\\R                     \4   4S jjrSrU =r$ )CamembertEncoderi.  c           
         > [         TU ]  5         Xl        [        R                  " [        UR                  5       Vs/ s H  n[        XS9PM     sn5      U l        SU l	        g s  snf )Nr  F)
r3   r4   rM   r   
ModuleListrangenum_hidden_layersr  layergradient_checkpointing)rL   rM   r   irN   s       rO   r4   CamembertEncoder.__init__/  sT    ]]QVW]WoWoQp#qQpAN6$GQp#qr
&+# $rs   A$r   r   r   r   r#  r   	use_cacher   output_hidden_statesreturn_dictr   r   c                    U	(       a  SOS nU(       a  SOS nU(       a  U R                   R                  (       a  SOS nU R                  (       a/  U R                  (       a  U(       a  [        R                  S5        SnU(       aL  U R                   R                  (       a1  Uc.  [        [        U R                   S9[        U R                   S95      nU(       a[  U R                   R                  (       a@  [        U[        5      (       a+  [        R                  S5        [        R                  " U5      n[        U R                  5       He  u  nnU	(       a  X4-   nUb  X?   OS nU" UUUUUUUUS9nUS   nU(       d  M6  UUS   4-   nU R                   R                  (       d  M\  UUS	   4-   nMg     U	(       a  X4-   nU
(       d  [        S
 UUUUU4 5       5      $ [        UUUUUS9$ )N zZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...F)rM   zPassing a tuple of `past_key_values` is deprecated and will be removed in Transformers v4.58.0. You should pass an instance of `EncoderDecoderCache` instead, e.g. `past_key_values=EncoderDecoderCache.from_legacy_cache(past_key_values)`.)r#  r   r   r   r   r"   rv   c              3   0   #    U  H  nUc  M  Uv   M     g 7fr   r;  ).0vs     rO   	<genexpr>+CamembertEncoder.forward.<locals>.<genexpr>t  s"      
A  s   	)last_hidden_stater   r   
attentionscross_attentions)rM   r  r4  r   r   r   r   r   r   r   r   from_legacy_cache	enumerater3  r   )rL   r   r   r   r   r#  r   r7  r   r8  r9  r   all_hidden_statesall_self_attentionsall_cross_attentionsr5  layer_modulelayer_head_masklayer_outputss                      rO   r`   CamembertEncoder.forward5  s    #7BD$5b4%64;;;Z;Zr`d&&4==##p "	//O4K1,dkk2RT`hlhshsTtuO//JPU4V4V\
 2CCOTO(4OA|#$58H$H!.7.CilO(%'= /"3-	M *!,M  &9]1=M<O&O#;;222+?=QRCSBU+U(+  5.   14D D 
 "#%'(
 
 
 9+++*1
 	
rQ   )rM   r4  r3  r   )
NNNNNNFFTN)rf   rg   rh   ri   r4   rE   r   r   r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r.  r.  .  s   , 7;15=A>B+/$(,1/4&*15P
||P
 !!2!23P
 E--.	P

  ((9(9:P
 !)):): ;P
 "%P
 D>P
 $D>P
 'tnP
 d^P
 !.P
 
uU\\"$MM	NP
 P
rQ   r.  c                   b   ^  \ rS rSrU 4S jrS\R                  S\R                  4S jrSrU =r	$ )CamembertPooleri  c                    > [         TU ]  5         [        R                  " UR                  UR                  5      U l        [        R                  " 5       U l        g r   )r3   r4   r   r|   r7   r   Tanh
activationrK   s     rO   r4   CamembertPooler.__init__  s9    YYv1163E3EF
'')rQ   r   r   c                 \    US S 2S4   nU R                  U5      nU R                  U5      nU$ Nr   )r   rQ  )rL   r   first_token_tensorpooled_outputs       rO   r`   CamembertPooler.forward  s6     +1a40

#566rQ   )rQ  r   r   rm   s   @rO   rN  rN    s(    $
U\\ ell  rQ   rN  c                   2    \ rS rSr% \\S'   SrSrSrS r	Sr
g)CamembertPreTrainedModeli  rM   robertaTc                    [        U[        R                  5      (       ak  UR                  R                  R                  SU R                  R                  S9  UR                  b%  UR                  R                  R                  5         gg[        U[        R                  5      (       ax  UR                  R                  R                  SU R                  R                  S9  UR                  b2  UR                  R                  UR                     R                  5         gg[        U[        R                  5      (       aJ  UR                  R                  R                  5         UR                  R                  R                  S5        g[        U[        5      (       a%  UR                  R                  R                  5         gg)zInitialize the weightsr   )meanstdNg      ?)r   r   r|   weightdatanormal_rM   initializer_rangebiaszero_r5   r(   r>   fill_CamembertLMHead)rL   modules     rO   _init_weights&CamembertPreTrainedModel._init_weights  s2   fbii(( MM&&CT[[5R5R&S{{&  &&( '--MM&&CT[[5R5R&S!!-""6#5#56<<> .--KK""$MM$$S)00KK""$ 1rQ   r;  N)rf   rg   rh   ri   r#   __annotations__base_model_prefixsupports_gradient_checkpointing_supports_sdparg  rk   r;  rQ   rO   rY  rY    s    !&*#N%rQ   rY  c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )CamembertClassificationHeadi  z-Head for sentence-level classification tasks.c                 b  > [         TU ]  5         [        R                  " UR                  UR                  5      U l        UR                  b  UR                  OUR                  n[        R                  " U5      U l	        [        R                  " UR                  UR                  5      U l        g r   )r3   r4   r   r|   r7   r   classifier_dropoutrA   r@   rB   
num_labelsout_projrL   rM   rp  rN   s      rO   r4   $CamembertClassificationHead.__init__  s    YYv1163E3EF
)/)B)B)NF%%TZTnTn 	 zz"45		&"4"4f6G6GHrQ   c                     US S 2SS S 24   nU R                  U5      nU R                  U5      n[        R                  " U5      nU R                  U5      nU R	                  U5      nU$ rT  )rB   r   rE   tanhrr  rL   featureskwargsxs       rO   r`   #CamembertClassificationHead.forward  sY    Q1WLLOJJqMJJqMLLOMM!rQ   )r   rB   rr  )	rf   rg   rh   ri   rj   r4   r`   rk   rl   rm   s   @rO   rn  rn    s    7I rQ   rn  c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )re  i  z,Camembert Head for masked language modeling.c                   > [         TU ]  5         [        R                  " UR                  UR                  5      U l        [        R                  " UR                  UR                  S9U l        [        R                  " UR                  UR                  5      U l
        [        R                  " [        R                  " UR                  5      5      U l        U R                  U R                  l        g r   )r3   r4   r   r|   r7   r   r>   r?   
layer_normr6   decoder	ParameterrE   rH   rb  rK   s     rO   r4   CamembertLMHead.__init__  s    YYv1163E3EF
,,v'9'9v?T?TUyy!3!3V5F5FGLLV->->!?@	 IIrQ   c                     U R                  U5      n[        U5      nU R                  U5      nU R                  U5      nU$ r   )r   r   r~  r  rw  s       rO   r`   CamembertLMHead.forward  s;    JJx GOOA LLOrQ   c                     U R                   R                  R                  R                  S:X  a  U R                  U R                   l        g U R                   R                  U l        g )Nmeta)r  rb  rT   typerL   s    rO   _tie_weightsCamembertLMHead._tie_weights  sC     <<##((F2 $		DLL))DIrQ   )rb  r  r   r~  )
rf   rg   rh   ri   rj   r4   r`   r  rk   rl   rm   s   @rO   re  re    s    6&* *rQ   re  c            "         ^  \ rS rSrSr/ rSU 4S jjrS rS rS r	\
              SS\\R                     S\\R                     S	\\R                     S
\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\   S\\   S\\   S\\   S\\   S\\R                     S\\\R                     \4   4S jj5       rSrU =r$ )CamembertModeli  a  

The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of
cross-attention is added between the self-attention layers, following the architecture described in *Attention is
all you need*_ by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz
Kaiser and Illia Polosukhin.

To behave as a decoder the model needs to be initialized with the `is_decoder` argument of the configuration set to
`True`. To be used in a Seq2Seq model, the model needs to initialized with both `is_decoder` argument and
`add_cross_attention` set to `True`; an `encoder_hidden_states` is then expected as an input to the forward pass.

.. _*Attention is all you need*: https://huggingface.co/papers/1706.03762

c                   > [         TU ]  U5        Xl        [        U5      U l        [        U5      U l        U(       a  [        U5      OSU l        UR                  U l
        UR                  U l        U R                  5         g)z^
add_pooling_layer (bool, *optional*, defaults to `True`):
    Whether to add a pooling layer
N)r3   r4   rM   r%   r_   r.  encoderrN  poolerr   attn_implementationr+   	post_init)rL   rM   add_pooling_layerrN   s      rO   r4   CamembertModel.__init__  sg    
 	 -f5'/1Bof-#)#>#> '-'E'E$ 	rQ   c                 .    U R                   R                  $ r   r_   r9   r  s    rO   get_input_embeddings#CamembertModel.get_input_embeddings  s    ...rQ   c                 $    XR                   l        g r   r  )rL   r   s     rO   set_input_embeddings#CamembertModel.set_input_embeddings  s    */'rQ   c                     UR                  5        H7  u  p#U R                  R                  U   R                  R	                  U5        M9     g)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)itemsr  r3  r  r   )rL   heads_to_pruner3  r   s       rO   _prune_headsCamembertModel._prune_heads  s<    
 +002LELLu%//;;EB 3rQ   rX   r   r0   r-   r   rY   r   r#  r   r7  r   r8  r9  r   r   c                    Ub  UOU R                   R                  nUb  UOU R                   R                  nUb  UOU R                   R                  nU R                   R                  (       a  U
b  U
OU R                   R
                  n
OSn
Ub  Ub  [        S5      eUb"  U R                  X5        UR                  5       nO"Ub  UR                  5       S S nO[        S5      eUu  nnUb  UR                  OUR                  nSnU	b:  [        U	[        5      (       d  U	S   S   R                  S   OU	R                  5       nUcs  [        U R                  S5      (       a4  U R                  R                   S S 2S U24   nUR#                  UU5      nUnO$[$        R&                  " U[$        R(                  US9nU R                  UUUUUS	9nUc  [$        R*                  " UUU-   4US
9nU R,                  S:H  =(       a(    U R.                  S:H  =(       a    US L =(       a    U(       + nU(       aT  UR1                  5       S:X  a@  U R                   R                  (       a  [3        UUUU5      nO'[5        UUR6                  US9nOU R9                  X/5      nU R                   R                  (       av  Ubs  UR                  5       u  nnnUU4nUc  [$        R*                  " UUS
9nU(       a*  UR1                  5       S:X  a  [5        UUR6                  US9nOU R;                  U5      nOS nU R=                  XPR                   R>                  5      nU RA                  UUUUUU	U
UUUUS9nUS   nU RB                  b  U RC                  U5      OS n U(       d
  UU 4USS  -   $ [E        UU URF                  URH                  URJ                  URL                  S9$ )NFzDYou cannot specify both input_ids and inputs_embeds at the same timer.   z5You have to specify either input_ids or inputs_embedsr   r   r0   rS   )rX   r-   r0   rY   rZ   )rT   r   r,   rv   )r   )
r   r   r   r#  r   r7  r   r8  r9  r   r"   )rA  pooler_outputr   r   rB  rC  )'rM   r   r8  use_return_dictr   r7  rx   %warn_if_padding_and_no_attention_maskrI   rT   r   r   r   get_seq_lengthrW   r_   r0   rG   rE   rH   rJ   onesr  r+   r   r   r   r2   get_extended_attention_maskinvert_attention_maskget_head_maskr2  r  r  r   r   r   rB  rC  )!rL   rX   r   r0   r-   r   rY   r   r#  r   r7  r   r8  r9  r   r[   r   r\   rT   rZ   r]   r^   embedding_outputuse_sdpa_attention_masksextended_attention_maskencoder_batch_sizeencoder_sequence_lengthr   encoder_hidden_shapeencoder_extended_attention_maskencoder_outputssequence_outputrV  s!                                    rO   r`   CamembertModel.forward  s   & 2C1N-TXT_T_TqTq$8$D $++JjJj 	 &1%<k$++B]B];;!!%.%:	@U@UII ]%>cdd"66yQ#..*K&',,.s3KTUU!,
J%.%:!!@T@T!"& "/599  "1%++B/$335 # !t(899*.//*H*HKZK*X'3J3Q3QR\^h3i0!A!&[

SY!Z??%)'#9 + 
 !"ZZZBX5X(YbhiN $$. &,,
:&T!& &%	 	! $(:(:(<(A {{%%*T"$*	+' +N"$4$:$:J+' '+&F&F~&c# ;;!!&;&G=R=W=W=Y: 7$68O#P %-).4HQW)X&',B,F,F,HA,M 3V*,<,B,BJ3/ 372L2LMc2d/.2+ &&y++2O2OP	,,2"7#B+/!5#) ' 
 *!,8<8OO4UY#]3oab6III;-'+;;)77&11,==
 	
rQ   )r  rM   r_   r  r  r+   )TNNNNNNNNNNNNNN)rf   rg   rh   ri   rj   _no_split_modulesr4   r  r  r  r   r   rE   r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r  r    s    &/0C  -11515/3,0048<9=+/$(,0/3&*15S
ELL)S
 !.S
 !.	S

 u||,S
 ELL)S
  -S
  (5S
 !) 6S
 "%S
 D>S
 $D>S
 'tnS
 d^S
 !.S
  
uU\\"$PP	Q!S
 S
rQ   r  c                     ^  \ rS rSrSS/rU 4S jrS rS r\            SS\	\
R                     S\	\
R                     S	\	\
R                     S
\	\
R                     S\	\
R                     S\	\
R                     S\	\
R                     S\	\
R                     S\	\
R                     S\	\   S\	\   S\	\   S\\\
R                      \4   4S jj5       rSrU =r$ )CamembertForMaskedLMi  lm_head.decoder.weightlm_head.decoder.biasc                    > [         TU ]  U5        UR                  (       a  [        R	                  S5        [        USS9U l        [        U5      U l        U R                  5         g )NzpIf you want to use `CamembertForMaskedLM` make sure `config.is_decoder=False` for bi-directional self-attention.Fr  
r3   r4   r   r   warningr  rZ  re  lm_headr  rK   s     rO   r4   CamembertForMaskedLM.__init__  sR     NN1
 &fF&v. 	rQ   c                 .    U R                   R                  $ r   r  r  r  s    rO   get_output_embeddings*CamembertForMaskedLM.get_output_embeddings      ||###rQ   c                 $    XR                   l        g r   r  rL   new_embeddingss     rO   set_output_embeddings*CamembertForMaskedLM.set_output_embeddings      -rQ   rX   r   r0   r-   r   rY   r   r#  labelsr   r8  r9  r   c                    Ub  UOU R                   R                  nU R                  UUUUUUUUU
UUS9nUS   nU R                  U5      nSnU	ba  U	R	                  UR
                  5      n	[        5       nU" UR                  SU R                   R                  5      U	R                  S5      5      nU(       d  U4USS -   nUb  U4U-   $ U$ [        UUUR                  UR                  S9$ )a  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
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)
r   r0   r-   r   rY   r   r#  r   r8  r9  r   r.   rv   losslogitsr   rB  )rM   r  rZ  r  r   rT   r   r   r6   r   r   rB  )rL   rX   r   r0   r-   r   rY   r   r#  r  r   r8  r9  r  r  prediction_scoresmasked_lm_lossloss_fctr   s                      rO   r`   CamembertForMaskedLM.forward  s   > &1%<k$++B]B],,))%'"7#9/!5#  
 "!* LL9YY0778F')H%&7&<&<RAWAW&XZ`ZeZefhZijN')GABK7F3A3M^%.YSYY$!//))	
 	
rQ   r  rZ  )NNNNNNNNNNNN)rf   rg   rh   ri   _tied_weights_keysr4   r  r  r   r   rE   
LongTensorr   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r  r    sk    34JK$.  156:59371559=A>B-1,0/3&*@
E,,-@
 !!2!23@
 !!1!12	@

 u//0@
 E--.@
   1 12@
  ((9(9:@
 !)):): ;@
 ))*@
 $D>@
 'tn@
 d^@
 
uU\\"N2	3@
 @
rQ   r  z
    CamemBERT Model transformer with a sequence classification/regression head on top (a linear layer on top of the
    pooled output) e.g. for GLUE tasks.
    )custom_introc                   l  ^  \ rS rSrU 4S jr\          SS\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S	\\R                     S
\\
   S\\
   S\\
   S\\\R                     \4   4S jj5       rSrU =r$ )"CamembertForSequenceClassificationi  c                    > [         TU ]  U5        UR                  U l        Xl        [	        USS9U l        [        U5      U l        U R                  5         g NFr  )	r3   r4   rq  rM   r  rZ  rn  
classifierr  rK   s     rO   r4   +CamembertForSequenceClassification.__init__  sH      ++%fF5f= 	rQ   rX   r   r0   r-   r   rY   r  r   r8  r9  r   c                 f   U
b  U
OU R                   R                  n
U R                  UUUUUUUU	U
S9	nUS   nU R                  U5      nSnUGb  UR	                  UR
                  5      nU R                   R                  c  U R                  S:X  a  SU R                   l        OoU R                  S:  aN  UR                  [        R                  :X  d  UR                  [        R                  :X  a  SU R                   l        OSU R                   l        U R                   R                  S:X  aI  [        5       nU R                  S:X  a&  U" UR                  5       UR                  5       5      nOU" X5      nOU R                   R                  S:X  a=  [        5       nU" UR                  SU R                  5      UR                  S5      5      nO,U R                   R                  S:X  a  [!        5       nU" X5      nU
(       d  U4US	S -   nUb  U4U-   $ U$ [#        UUUR$                  UR&                  S
9$ )a  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
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).
Nr   r0   r-   r   rY   r   r8  r9  r   r"   
regressionsingle_label_classificationmulti_label_classificationr.   rv   r  )rM   r  rZ  r  r   rT   problem_typerq  r2   rE   rJ   ry   r   squeezer   r   r   r   r   rB  rL   rX   r   r0   r-   r   rY   r  r   r8  r9  r  r  r  r  r  r   s                    rO   r`   *CamembertForSequenceClassification.forward(  s   : &1%<k$++B]B],,))%'/!5#  

 "!*1YYv}}-F{{''/??a'/;DKK,__q(fllejj.HFLL\a\e\eLe/LDKK,/KDKK,{{''<7"9??a'#FNN$4fnn6FGD#F3D))-JJ+-B @&++b/R))-II,./Y,F)-)9TGf$EvE'!//))	
 	
rQ   )r  rM   rq  rZ  
NNNNNNNNNN)rf   rg   rh   ri   r4   r   r   rE   r  r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r  r    s"   	  156:59371559-1,0/3&*N
E,,-N
 !!2!23N
 !!1!12	N

 u//0N
 E--.N
   1 12N
 ))*N
 $D>N
 'tnN
 d^N
 
uU\\"$<<	=N
 N
rQ   r  c                   l  ^  \ rS rSrU 4S jr\          SS\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S	\\R                     S
\\
   S\\
   S\\
   S\\\R                     \4   4S jj5       rSrU =r$ )CamembertForMultipleChoiceiz  c                    > [         TU ]  U5        [        U5      U l        [        R
                  " UR                  5      U l        [        R                  " UR                  S5      U l
        U R                  5         g )Nr"   )r3   r4   r  rZ  r   r@   rA   rB   r|   r7   r  r  rK   s     rO   r4   #CamembertForMultipleChoice.__init__}  sV     %f-zz&"<"<=))F$6$6: 	rQ   rX   r0   r   r  r-   r   rY   r   r8  r9  r   c                    U
b  U
OU R                   R                  n
Ub  UR                  S   OUR                  S   nUb!  UR                  SUR	                  S5      5      OSnUb!  UR                  SUR	                  S5      5      OSnUb!  UR                  SUR	                  S5      5      OSnUb!  UR                  SUR	                  S5      5      OSnUb1  UR                  SUR	                  S5      UR	                  S5      5      OSnU R                  UUUUUUUU	U
S9	nUS   nU R                  U5      nU R                  U5      nUR                  SU5      nSnUb.  UR                  UR                  5      n[        5       nU" UU5      nU
(       d  U4USS -   nUb  U4U-   $ U$ [        UUUR                  UR                  S9$ )aO  
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
    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)
token_type_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
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)
position_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`, *optional*):
    Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
    config.max_position_embeddings - 1]`.

    [What are position IDs?](../glossary#position-ids)
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, num_choices, sequence_length, 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.
Nr"   r.   r   )r-   r0   r   r   rY   r   r8  r9  rv   r  )rM   r  r   r   rI   rZ  rB   r  r   rT   r   r   r   rB  )rL   rX   r0   r   r  r-   r   rY   r   r8  r9  num_choicesflat_input_idsflat_position_idsflat_token_type_idsflat_attention_maskflat_inputs_embedsr  rV  r  reshaped_logitsr  r  r   s                           rO   r`   "CamembertForMultipleChoice.forward  s   Z &1%<k$++B]B],5,Aiooa(}GZGZ[\G]CLCXINN2,>?^bLXLdL--b,2C2CB2GHjnR`Rln11"n6I6I"6MNrvR`Rln11"n6I6I"6MNrv ( r=#5#5b#9=;M;Mb;QR 	 ,,*..,/!5#  

  
]3/ ++b+6YY556F')HOV4D%''!"+5F)-)9TGf$EvE("!//))	
 	
rQ   )r  rB   rZ  r  )rf   rg   rh   ri   r4   r   r   rE   r  r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r  r  z  s"     15596:-1371559,0/3&*Z
E,,-Z
 !!1!12Z
 !!2!23	Z

 ))*Z
 u//0Z
 E--.Z
   1 12Z
 $D>Z
 'tnZ
 d^Z
 
uU\\"$==	>Z
 Z
rQ   r  c                   l  ^  \ rS rSrU 4S jr\          SS\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S	\\R                     S
\\
   S\\
   S\\
   S\\\R                     \4   4S jj5       rSrU =r$ )CamembertForTokenClassificationi  c                 d  > [         TU ]  U5        UR                  U l        [        USS9U l        UR
                  b  UR
                  OUR                  n[        R                  " U5      U l	        [        R                  " UR                  UR                  5      U l        U R                  5         g r  )r3   r4   rq  r  rZ  rp  rA   r   r@   rB   r|   r7   r  r  rs  s      rO   r4   (CamembertForTokenClassification.__init__  s      ++%fF)/)B)B)NF%%TZTnTn 	 zz"45))F$6$68I8IJ 	rQ   rX   r   r0   r-   r   rY   r  r   r8  r9  r   c                    U
b  U
OU R                   R                  n
U R                  UUUUUUUU	U
S9	nUS   nU R                  U5      nU R	                  U5      nSnUbW  UR                  UR                  5      n[        5       nU" UR                  SU R                  5      UR                  S5      5      nU
(       d  U4USS -   nUb  U4U-   $ U$ [        UUUR                  UR                  S9$ )a  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
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]`.
Nr  r   r.   rv   r  )rM   r  rZ  rB   r  r   rT   r   r   rq  r   r   rB  r  s                    rO   r`   'CamembertForTokenClassification.forward  s   6 &1%<k$++B]B],,))%'/!5#  

 "!*,,71YYv}}-F')HFKKDOO<fkk"oNDY,F)-)9TGf$EvE$!//))	
 	
rQ   )r  rB   rq  rZ  r  )rf   rg   rh   ri   r4   r   r   rE   r  r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r  r    s     156:59371559-1,0/3&*=
E,,-=
 !!2!23=
 !!1!12	=

 u//0=
 E--.=
   1 12=
 ))*=
 $D>=
 'tn=
 d^=
 
uU\\"$99	:=
 =
rQ   r  c                     ^  \ rS rSrU 4S jr\           SS\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S	\\R                     S
\\R                     S\\
   S\\
   S\\
   S\\\R                     \4   4S jj5       rSrU =r$ )CamembertForQuestionAnsweringi7  c                    > [         TU ]  U5        UR                  U l        [        USS9U l        [
        R                  " UR                  UR                  5      U l        U R                  5         g r  )
r3   r4   rq  r  rZ  r   r|   r7   
qa_outputsr  rK   s     rO   r4   &CamembertForQuestionAnswering.__init__:  sU      ++%fF))F$6$68I8IJ 	rQ   rX   r   r0   r-   r   rY   start_positionsend_positionsr   r8  r9  r   c                 $   Ub  UOU R                   R                  nU R                  UUUUUUU	U
US9	nUS   nU R                  U5      nUR	                  SSS9u  nnUR                  S5      R                  5       nUR                  S5      R                  5       nSnUb  Ub  [        UR                  5       5      S:  a  UR                  S5      n[        UR                  5       5      S:  a  UR                  S5      nUR                  S5      nUR                  SU5      nUR                  SU5      n[        US9nU" X5      nU" UU5      nUU-   S-  nU(       d  UU4USS -   nUb  U4U-   $ U$ [        UUUUR                  UR                  S	9$ )
a  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
Nr  r   r"   r.   r   )ignore_indexrv   )r  start_logits
end_logitsr   rB  )rM   r  rZ  r  splitr  r   r   rI   clampr   r   r   rB  )rL   rX   r   r0   r-   r   rY   r  r  r   r8  r9  r  r  r  r  r  
total_lossignored_indexr  
start_lossend_lossr   s                          rO   r`   %CamembertForQuestionAnswering.forwardD  s   4 &1%<k$++B]B],,))%'/!5#  

 "!*1#)<<r<#: j#++B/::<''+668

&=+D?'')*Q."1"9"9""==%%'(1, - 5 5b 9(--a0M-33A}EO)//=AM']CH!,@J
M:H$x/14J"J/'!"+=F/9/EZMF*Q6Q+%!!//))
 	
rQ   )rq  r  rZ  )NNNNNNNNNNN)rf   rg   rh   ri   r4   r   r   rE   r  r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r  r  7  s;     156:593715596:48,0/3&*I
E,,-I
 !!2!23I
 !!1!12	I

 u//0I
 E--.I
   1 12I
 "%"2"23I
   0 01I
 $D>I
 'tnI
 d^I
 
uU\\"$@@	AI
 I
rQ   r  zU
    CamemBERT Model with a `language modeling` head on top for CLM fine-tuning.
    c            "         ^  \ rS rSrSS/rU 4S jrS rS r\              SS\	\
R                     S\	\
R                     S	\	\
R                     S
\	\
R                     S\	\
R                     S\	\
R                     S\	\
R                     S\	\
R                     S\	\
R                     S\	\   S\	\   S\	\   S\	\   S\	\   S\\\
R"                     \4   4S jj5       rSrU =r$ )CamembertForCausalLMi  r  r  c                    > [         TU ]  U5        UR                  (       d  [        R	                  S5        [        USS9U l        [        U5      U l        U R                  5         g )NzQIf you want to use `CamembertLMHeadModel` as a standalone, add `is_decoder=True.`Fr  r  rK   s     rO   r4   CamembertForCausalLM.__init__  sL       NNno%fF&v. 	rQ   c                 .    U R                   R                  $ r   r  r  s    rO   r  *CamembertForCausalLM.get_output_embeddings  r  rQ   c                 $    XR                   l        g r   r  r  s     rO   r  *CamembertForCausalLM.set_output_embeddings  r  rQ   rX   r   r0   r-   r   rY   r   r#  r  r   r7  r   r8  r9  r   c                    Ub  UOU R                   R                  nU	b  SnU R                  UUUUUUUUU
UUUUS9nUS   nU R                  U5      nSnU	bE  U	R	                  UR
                  5      n	U R                  " UU	4SU R                   R                  0UD6nU(       d  U4USS -   nUb  U4U-   $ U$ [        UUUR                  UR                  UR                  UR                  S9$ )a  
token_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,1]`:

    - 0 corresponds to a *sentence A* token,
    - 1 corresponds to a *sentence B* token.
    This parameter can only be used when the model is initialized with `type_vocab_size` parameter with value
    >= 2. All the value in this tensor should be always < type_vocab_size.

    [What are token type IDs?](../glossary#token-type-ids)
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Labels for computing the left-to-right language modeling loss (next word prediction). 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]`

Example:

```python
>>> from transformers import AutoTokenizer, CamembertForCausalLM, AutoConfig
>>> import torch

>>> tokenizer = AutoTokenizer.from_pretrained("almanach/camembert-base")
>>> config = AutoConfig.from_pretrained("almanach/camembert-base")
>>> config.is_decoder = True
>>> model = CamembertForCausalLM.from_pretrained("almanach/camembert-base", config=config)

>>> inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
>>> outputs = model(**inputs)

>>> prediction_logits = outputs.logits
```NF)r   r0   r-   r   rY   r   r#  r   r7  r   r8  r9  r   r6   rv   )r  r  r   r   rB  rC  )rM   r  rZ  r  r   rT   loss_functionr6   r   r   r   rB  rC  )rL   rX   r   r0   r-   r   rY   r   r#  r  r   r7  r   r8  r9  ry  r  r  r  lm_lossr   s                        rO   r`   CamembertForCausalLM.forward  s4   d &1%<k$++B]B]I,,))%'"7#9+/!5#  
  "!* LL9YY0778F((!  ;;11 	G ')GABK7F,3,?WJ'KVK0$#33!//))$55
 	
rQ   r  r  )rf   rg   rh   ri   r  r4   r  r  r   r   rE   r  r   r   r   r   r   r   r   r`   rk   rl   rm   s   @rO   r  r    s    34JK
$.  156:59371559=A>B-1+/$(,0/3&*^
E,,-^
 !!2!23^
 !!1!12	^

 u//0^
 E--.^
   1 12^
  ((9(9:^
 !)):): ;^
 ))*^
 "%^
 D>^
 $D>^
 'tn^
 d^^
" 
uU\\"$EE	F#^
 ^
rQ   r  c                     U R                  U5      R                  5       n[        R                  " USS9R	                  U5      U-   U-  nUR                  5       U-   $ )z
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols
are ignored. This is modified from fairseq's `utils.make_positions`.

Args:
    x: torch.Tensor x:

Returns: torch.Tensor
r"   r   )nery   rE   cumsumtype_asrJ   )rX   r(   rZ   maskincremental_indicess        rO   rU   rU     sW     <<$((*D <<!4<<TBE[[_cc##%33rQ   )r  r  r  r  r  r  r  rY  )r   )Jrj   r   typingr   r   rE   r   torch.nnr   r   r   activationsr
   r   cache_utilsr   r   r   
generationr   modeling_attn_mask_utilsr   r   modeling_layersr   modeling_outputsr   r   r   r   r   r   r   r   modeling_utilsr   pytorch_utilsr   r   r   utilsr   r    utils.deprecationr!   configuration_camembertr#   
get_loggerrf   r   Moduler%   ro   r   r   r   r   r  r  r  r.  rN  rY  rn  re  r  r  r  r  r  r  r  rU   __all__r;  rQ   rO   <module>r-     sZ      "   A A ' C C ) w 9	 	 	 . l l , 0 4 
		H	%V=")) V=tB.RYY B.Le!!7 e!R"))  $&$  3 3nBII  bii C/ CNW
ryy W
vbii  % % %6")) .*bii *> I
- I
 I
X Y
3 Y
 Y
x [
)A [
[
| f
!9 f
 f
R M
&> M
 M
` U
$< U
 U
p t
3_ t
t
p4 	rQ   