
    <h                         S r SSKrSSKrSSKJrJr  SSKrSSKrSSK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  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)  \'RT                  " \+5      r,S r- " S S\R\                  5      r/ " S S\R\                  5      r0 " S S\R\                  5      r1 " S S\R\                  5      r2 " S S\R\                  5      r3 " S S\R\                  5      r4 " S S\R\                  5      r5 " S  S!\5      r6 " S" S#\R\                  5      r7 " S$ S%\R\                  5      r8 " S& S'\R\                  5      r9 " S( S)\R\                  5      r:\& " S* S+\ 5      5       r;\&" S,S-9 " S. S/\;5      5       r<\& " S0 S1\;5      5       r=\&" S2S-9 " S3 S4\;\5      5       r>\&" S5S-9 " S6 S7\;5      5       r?\& " S8 S9\;5      5       r@\& " S: S;\;5      5       rA\& " S< S=\;5      5       rB/ S>QrCg)?zPyTorch RemBERT model.    N)OptionalUnion)nn)BCEWithLogitsLossCrossEntropyLossMSELoss   )ACT2FN)CacheEncoderDecoderCache)GenerationMixin)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   )RemBertConfigc           
        ^  SSK nSSKnSSKn[        R                  R                  U5      n[        R                  SU 35        UR                  R                  U5      n/ n/ n	U H{  u  mn
[        U4S jS 5       5      (       a  M"  [        R                  ST SU
 35        UR                  R                  UT5      nUR                  T5        U	R                  U5        M}     [        X5       GH  u  mnTR!                  S	S
5      mTR#                  S5      m[        S T 5       5      (       a)  [        R                  SSR%                  T5       35        Mj  U nT H  nUR'                  SU5      (       a  UR#                  SU5      nOU/nUS   S:X  d	  US   S:X  a  [)        US5      nOZUS   S:X  d	  US   S:X  a  [)        US5      nO;US   S:X  a  [)        US5      nO%US   S:X  a  [)        US5      nO [)        XS   5      n[/        U5      S:  d  M  [1        US   5      nX   nM     WSS S:X  a  [)        US5      nOUS:X  a  UR3                  U5      n UR4                  UR4                  :w  a&  [7        SUR4                   SUR4                   S 35      e [        R                  S!T 35        [<        R>                  " U5      Ul         GM     U $ ! [         a    [        R                  S5        e f = f! [*         a8    [        R                  SR-                  SR%                  T5      5      5         GM  f = f! [8         a1  nU=R:                  UR4                  UR4                  4-  sl        e SnAff = f)"z'Load tf checkpoints in a pytorch model.r   NzLoading a TensorFlow model in PyTorch, requires TensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions.z&Converting TensorFlow checkpoint from c              3   *   >#    U H	  oT;   v   M     g 7fN ).0denynames     d/var/www/html/shao/venv/lib/python3.13/site-packages/transformers/models/rembert/modeling_rembert.py	<genexpr>-load_tf_weights_in_rembert.<locals>.<genexpr>G   s     X(Wt|(Ws   )adam_vadam_moutput_embeddingclszLoading TF weight z with shape zbert/zrembert//c              3   *   #    U H
  nUS ;   v   M     g7f))r)   r*   AdamWeightDecayOptimizerAdamWeightDecayOptimizer_1global_stepNr"   )r#   ns     r&   r'   r(   X   s      
 nns   z	Skipping z[A-Za-z]+_\d+z_(\d+)kernelgammaweightoutput_biasbetabiasoutput_weightssquad
classifierzSkipping {}   r   i_embeddingszPointer shape z and array shape z mismatchedzInitialize PyTorch weight )!renumpy
tensorflowImportErrorloggererrorospathabspathinfotrainlist_variablesanyload_variableappendzipreplacesplitjoin	fullmatchgetattrAttributeErrorformatlenint	transposeshape
ValueErrorAssertionErrorargstorch
from_numpydata)modelconfigtf_checkpoint_pathr>   nptftf_path	init_varsnamesarraysrX   arraypointerm_namescope_namesnumer%   s                    @r&   load_tf_weights_in_rembertrn   1   sL   
 ggoo01G
KK8	BC''0IEF e X(WXXX(l5'BC&&w5Te ! 5)e||GZ0 zz#  

 
 
 KK)CHHTN#345F||,f55 hhy&9%h1~)[^w-F!'84Q=0KNf4L!'62Q#33!'84Q7*!'<8%g1~>G ;1$+a.)!,+ , #$<=(gx0GxLL'E	}}+ >'--@QRWR]R]Q^^i!jkk ,
 	078''.c *d LS  Q	
 	n & KK 4 4SXXd^ DE  	FFw}}ekk22F	s6   K :K<A M!K9<=L>=L>
M<,M77M<c                      ^  \ rS rSrSrU 4S jr     SS\\R                     S\\R                     S\\R                     S\\R                     S\
S	\R                  4S
 jjrSrU =r$ )RemBertEmbeddings   zGConstruct the embeddings from word, position and token_type embeddings.c                 v  > [         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 R#                  S[$        R&                  " UR                  5      R)                  S5      SS9  g )N)padding_idxepsposition_ids)r   F)
persistent)super__init__r   	Embedding
vocab_sizeinput_embedding_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register_bufferr\   arangeexpandselfr`   	__class__s     r&   rz   RemBertEmbeddings.__init__   s    !||v::H[H[ 
 $&<<0N0NPVPkPk#l %'\\&2H2H&JeJe%f" f&A&AvG\G\]zz&"<"<= 	ELL)G)GHOOPWXej 	 	
    	input_idstoken_type_idsrv   inputs_embedspast_key_values_lengthreturnc                    Ub  UR                  5       nOUR                  5       S S nUS   nUc  U R                  S S 2XWU-   24   nUc8  [        R                  " U[        R                  U R                  R
                  S9nUc  U R                  U5      nU R                  U5      nXH-   n	U R                  U5      n
X-  n	U R                  U	5      n	U R                  U	5      n	U	$ )Nrw   r   dtypedevice)sizerv   r\   zeroslongr   r   r   r   r   r   )r   r   r   rv   r   r   input_shape
seq_lengthr   
embeddingsr   s              r&   forwardRemBertEmbeddings.forward   s      #..*K',,.s3K ^
,,Q0FVlIl0l-lmL!"[[EJJtO`O`OgOghN  00;M $ : :> J":
"66|D)
^^J/
\\*-
r   )r   r   r   r   r   )NNNNr   )__name__
__module____qualname____firstlineno____doc__rz   r   r\   
LongTensorFloatTensorrV   Tensorr   __static_attributes____classcell__r   s   @r&   rp   rp      s    Q
( 15593759&'E,,- !!1!12 u//0	
   1 12 !$ 
 r   rp   c                   b   ^  \ rS rSrU 4S jrS\R                  S\R                  4S jrSrU =r	$ )RemBertPooler   c                    > [         TU ]  5         [        R                  " UR                  UR                  5      U l        [        R                  " 5       U l        g r!   )ry   rz   r   Linearhidden_sizedenseTanh
activationr   s     r&   rz   RemBertPooler.__init__   s9    YYv1163E3EF
'')r   hidden_statesr   c                 \    US S 2S4   nU R                  U5      nU R                  U5      nU$ )Nr   )r   r   )r   r   first_token_tensorpooled_outputs       r&   r   RemBertPooler.forward   s6     +1a40

#566r   )r   r   
r   r   r   r   rz   r\   r   r   r   r   r   s   @r&   r   r      s(    $
U\\ ell  r   r   c                      ^  \ rS rSrSU 4S jjr      SS\R                  S\\R                     S\\R                     S\\R                     S\\	   S\
S	\\R                     S
\4S jjrSrU =r$ )RemBertSelfAttention   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R"                  U l        X l        g )Nr   embedding_sizezThe hidden size (z6) is not a multiple of the number of attention heads ())ry   rz   r   num_attention_headshasattrrY   rV   attention_head_sizeall_head_sizer   r   querykeyvaluer   attention_probs_dropout_probr   
is_decoder	layer_idxr   r`   r   r   s      r&   rz   RemBertSelfAttention.__init__   s1    : ::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 ++"r   r   attention_mask	head_maskencoder_hidden_statespast_key_valueoutput_attentionscache_positionr   c                    UR                   u  pn
U R                  U5      R                  USU R                  U R                  5      R                  SS5      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  W(       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bN  U(       d  UOS nWR%                  UUU R                  SU05      u  nnU(       a  SUR                  U R                  '   [&        R(                  " UUR                  SS5      5      nU[*        R,                  " U R                  5      -  nUb  UU-   n[.        R0                  R3                  USS9nU R5                  U5      nUb  UU-  n[&        R(                  " UU5      nUR7                  SSSS	5      R9                  5       nUR;                  5       S S U R<                  4-   nUR                  " U6 nUU4$ )
Nrw   r   r<   r   Tdimr   r	   )rX   r   viewr   r   rW   
isinstancer   
is_updatedgetr   cross_attention_cacheself_attention_cachelayerskeysvaluesr   r   updater\   matmulmathsqrtr   
functionalsoftmaxr   permute
contiguousr   r   )r   r   r   r   r   r   r   r   
batch_sizer   _query_layeris_cross_attentionr   curr_past_key_valuecurrent_states	key_layervalue_layerattention_scoresattention_probscontext_layernew_context_layer_shapes                         r&   r   RemBertSelfAttention.forward   s    %2$7$7!
JJ}%T*b$":":D<T<TUYq!_ 	 3$>%.*=>>+66::4>>J
%*8*N*N'*8*M*M'&4#2D.-."<+224>>BGGI-44T^^DKKK (j"d&>&>@X@XY1a  

>*j"d&>&>@X@XY1a  )7It)<)C)C{DNN=M~<^*&	; &@DN--dnn= !<<Y5H5HR5PQ+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%**,CDo--r   )	r   r   r   r   r   r   r   r   r   r!   NNNNFN)r   r   r   r   rz   r\   r   r   r   r   booltupler   r   r   r   s   @r&   r   r      s    #0 7;15=A*."'15Q.||Q. !!2!23Q. E--.	Q.
  ((9(9:Q. !Q.  Q. !.Q. 
Q. Q.r   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	$ )RemBertSelfOutputi5  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 Nrt   )ry   rz   r   r   r   r   r   r   r   r   r   r   s     r&   rz   RemBertSelfOutput.__init__6  s`    YYv1163E3EF
f&8&8f>S>STzz&"<"<=r   r   input_tensorr   c                 p    U R                  U5      nU R                  U5      nU R                  X-   5      nU$ r!   r   r   r   r   r   r   s      r&   r   RemBertSelfOutput.forward<  5    

=1]3}'CDr   r   r   r   r   r   s   @r&   r   r   5  6    >U\\  RWR^R^  r   r   c                     ^  \ rS rSrSU 4S jjrS r      SS\R                  S\\R                     S\\R                     S\\R                     S\\
   S	\\   S
\\R                     S\\R                     4S jjrSrU =r$ )RemBertAttentioniC  c                 |   > [         TU ]  5         [        XS9U l        [	        U5      U l        [        5       U l        g )Nr   )ry   rz   r   r   r   outputsetpruned_headsr   s      r&   rz   RemBertAttention.__init__D  s0    (E	'/Er   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   )rU   r   r   r   r   r  r   r   r   r   r  r   r   union)r   headsindexs      r&   prune_headsRemBertAttention.prune_headsK  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: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   )r   r  )r   r   r   r   r   r   r   r   self_outputsattention_outputoutputss              r&   r   RemBertAttention.forward^  s\     yy)"7)/) ! 
  ;;|AF#%QR(88r   )r  r  r   r!   r   )r   r   r   r   rz   r  r\   r   r   r   r   r   r   r   r   r   r   s   @r&   r  r  C  s    ";, 7;15=A*.,115|| !!2!23 E--.	
  ((9(9: ! $D> !. 
u||	 r   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	$ )RemBertIntermediateiw  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!   )ry   rz   r   r   r   intermediate_sizer   r   
hidden_actstrr
   intermediate_act_fnr   s     r&   rz   RemBertIntermediate.__init__x  s`    YYv1163K3KL
f''--'-f.?.?'@D$'-'8'8D$r   r   r   c                 J    U R                  U5      nU R                  U5      nU$ r!   r   r!  r   r   s     r&   r   RemBertIntermediate.forward  s&    

=100?r   r$  r   r   s   @r&   r  r  w  s(    9U\\ ell  r   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	$ )RemBertOutputi  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   )ry   rz   r   r   r  r   r   r   r   r   r   r   r   s     r&   rz   RemBertOutput.__init__  s`    YYv779K9KL
f&8&8f>S>STzz&"<"<=r   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      r&   r   RemBertOutput.forward  r  r   r  r   r   s   @r&   r(  r(    r  r   r(  c                   .  ^  \ 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
\\R                     S\\R                     4S jjrS rSrU =r$ )RemBertLayeri  c                 r  > [         TU ]  5         UR                  U l        SU l        [	        X5      U l        UR                  U l        UR                  U l        U R                  (       a-  U R                  (       d  [        U  S35      e[	        XS9U l	        [        U5      U l        [        U5      U l        g )Nr   z> should be used as a decoder model if cross attention is addedr
  )ry   rz   chunk_size_feed_forwardseq_len_dimr  	attentionr   add_cross_attentionrY   crossattentionr  intermediater(  r  r   s      r&   rz   RemBertLayer.__init__  s    '-'E'E$)&< ++#)#=#= ##?? D6)g!hii"26"OD/7#F+r   r   r   r   r   encoder_attention_maskr   r   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   r4  z'If `encoder_hidden_states` are passed, z` has to be instantiated with cross-attention layers by setting `config.add_cross_attention=True`r  )	r2  r   r   rY   r4  r   feed_forward_chunkr0  r1  )r   r   r   r   r   r7  r   r   r   self_attention_outputsr  r  cross_attention_outputslayer_outputs                 r&   r   RemBertLayer.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+r   c                 J    U R                  U5      nU R                  X!5      nU$ r!   )r5  r  )r   r  intermediate_outputr<  s       r&   r9  RemBertLayer.feed_forward_chunk  s)    "//0@A{{#6Ir   )r3  r2  r0  r4  r5  r   r  r1  r!   )NNNNNFN)r   r   r   r   rz   r\   r   r   r   r   r   r   r   r9  r   r   r   s   @r&   r.  r.    s    ,$ 7;15=A>B*.,115.||. !!2!23. E--.	.
  ((9(9:. !)):): ;. !. $D>. !.. 
u||	.b r   r.  c                   F  ^  \ rS rSrU 4S jr          SS\R                  S\\R                     S\\R                     S\\R                     S\\R                     S\\	\	\R                           S	\\
   S
\
S\
S\
S\\R                     S\\	\4   4S jjrSrU =r$ )RemBertEncoderi  c           
      0  > [         TU ]  5         Xl        [        R                  " UR
                  UR                  5      U 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)ry   rz   r`   r   r   r}   r   embedding_hidden_mapping_in
ModuleListrangenum_hidden_layersr.  layergradient_checkpointing)r   r`   ir   s      r&   rz   RemBertEncoder.__init__  ss    +-99V5P5PRXRdRd+e(]]uU[UmUmOn#oOn!L$EOn#op
&+# $ps   -Br   r   r   r   r7  past_key_values	use_cacher   output_hidden_statesreturn_dictr   r   c           
      N   U R                   (       a/  U R                  (       a  U(       a  [        R                  S5        SnSnU(       aB  [	        U[
        5      (       d-  [        R                  S5        Sn[        R                  " U5      nU R                  U5      nU	(       a  SOS nU(       a  SOS nU(       a  U R                  R                  (       a  SOS n[        U R                  5       Hg  u  nnU	(       a  X4-   nUb  UU   OS nU" UUUUUUU5      nUS   nU(       d  M8  UUS   4-   nU R                  R                  (       d  M^  UUS   4-   nMi     U	(       a  X4-   nU(       a  UR                  5       nU
(       d  [        S	 UUUUU4 5       5      $ [        UUUUUS
9$ )NzZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...FzPassing 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)`.Tr"   r   r   r<   c              3   .   #    U H  nUc  M  Uv   M     g 7fr!   r"   )r#   vs     r&   r'   )RemBertEncoder.forward.<locals>.<genexpr>&  s"      
A  s   	)last_hidden_staterL  r   
attentionscross_attentions)rI  trainingrB   warning_oncer   r   r   from_legacy_cacherD  r`   r3  	enumeraterH  to_legacy_cacher   r   )r   r   r   r   r   r7  rL  rM  r   rN  rO  r   return_legacy_cacheall_hidden_statesall_self_attentionsall_cross_attentionsrJ  layer_modulelayer_head_masklayer_outputss                       r&   r   RemBertEncoder.forward  s    &&4==##p "	#Z??\
 #'1CCOTO88G"6BD$5b4%64;;;Z;Zr`d(4OA|#$58H$H!.7.CilO(%&!M *!,M  &9]1=M<O&O#;;222+?=QRCSBU+U()  5,   14D D-==?O 
 "#%'(
 
 
 9+++*1
 	
r   )r`   rD  rI  rH  )
NNNNNNFFTN)r   r   r   r   rz   r\   r   r   r   r   r   r   r   r   r   r   r   s   @r&   rB  rB    s   , 7;15=A>BEI$("'%* 15R
||R
 !!2!23R
 E--.	R

  ((9(9:R
 !)):): ;R
 "%e.?.?(@"ABR
 D>R
  R
 #R
 R
 !.R
 
u??	@R
 R
r   rB  c                   b   ^  \ rS rSrU 4S jrS\R                  S\R                  4S jrSrU =r	$ )RemBertPredictionHeadTransformi;  c                 p  > [         TU ]  5         [        R                  " UR                  UR                  5      U l        [        UR                  [        5      (       a  [        UR                     U l
        OUR                  U l
        [        R                  " UR                  UR                  S9U l        g r   )ry   rz   r   r   r   r   r   r  r   r
   transform_act_fnr   r   r   s     r&   rz   'RemBertPredictionHeadTransform.__init__<  s~    YYv1163E3EF
f''--$*6+<+<$=D!$*$5$5D!f&8&8f>S>STr   r   r   c                 l    U R                  U5      nU R                  U5      nU R                  U5      nU$ r!   )r   rg  r   r%  s     r&   r   &RemBertPredictionHeadTransform.forwardE  s4    

=1--m<}5r   )r   r   rg  r   r   s   @r&   re  re  ;  s)    UU\\ ell  r   re  c                   b   ^  \ rS rSrU 4S jrS\R                  S\R                  4S jrSrU =r	$ )RemBertLMPredictionHeadiL  c                 n  > [         TU ]  5         [        R                  " UR                  UR
                  5      U l        [        R                  " UR
                  UR                  5      U l        [        UR                     U l        [        R                  " UR
                  UR                  S9U l        g r   )ry   rz   r   r   r   output_embedding_sizer   r|   decoderr
   r  r   r   r   r   s     r&   rz    RemBertLMPredictionHead.__init__M  sz    YYv1163O3OP
yy!=!=v?P?PQ !2!23f&B&BH]H]^r   r   r   c                     U R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU$ r!   )r   r   r   ro  r%  s     r&   r   RemBertLMPredictionHead.forwardT  s@    

=16}5]3r   )r   r   ro  r   r   r   s   @r&   rl  rl  L  s)    _U\\ ell  r   rl  c                   b   ^  \ rS rSrU 4S jrS\R                  S\R                  4S jrSrU =r	$ )RemBertOnlyMLMHeadi]  c                 B   > [         TU ]  5         [        U5      U l        g r!   )ry   rz   rl  predictionsr   s     r&   rz   RemBertOnlyMLMHead.__init__^  s    26:r   sequence_outputr   c                 (    U R                  U5      nU$ r!   rv  )r   rx  prediction_scoress      r&   r   RemBertOnlyMLMHead.forwardb  s     ,,_=  r   rz  r   r   s   @r&   rt  rt  ]  s(    ;!u|| ! ! !r   rt  c                   2    \ rS rSr% \\S'   \rSrSr	S r
Srg)RemBertPreTrainedModelig  r`   rembertTc                    [        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g)zInitialize the weightsg        )meanstdNg      ?)r   r   r   r5   r^   normal_r`   initializer_ranger8   zero_r{   rs   r   fill_)r   modules     r&   _init_weights$RemBertPreTrainedModel._init_weightsn  s   fbii(( MM&&CT[[5R5R&S{{&  &&( '--MM&&CT[[5R5R&S!!-""6#5#56<<> .--KK""$MM$$S) .r   r"   N)r   r   r   r   r   __annotations__rn   load_tf_weightsbase_model_prefixsupports_gradient_checkpointingr  r   r"   r   r&   r~  r~  g  s    0O!&*#*r   r~  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](https://huggingface.co/papers/1706.03762) by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit,
    Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.

    To behave as an 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.
    )custom_introc            "         ^  \ rS rS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\	\\\
R                           S\	\   S\	\   S\	\   S\	\   S\	\
R                     S\\\4   4S jj5       rSrU =r$ )RemBertModeli  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                  5         g)z^
add_pooling_layer (bool, *optional*, defaults to `True`):
    Whether to add a pooling layer
N)
ry   rz   r`   rp   r   rB  encoderr   pooler	post_init)r   r`   add_pooling_layerr   s      r&   rz   RemBertModel.__init__  sK    
 	 +F3%f-/@mF+d 	r   c                 .    U R                   R                  $ r!   r   r   r   s    r&   get_input_embeddings!RemBertModel.get_input_embeddings  s    ...r   c                 $    XR                   l        g r!   r  )r   r   s     r&   set_input_embeddings!RemBertModel.set_input_embeddings  s    */'r   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  rH  r2  r  )r   heads_to_prunerH  r  s       r&   _prune_headsRemBertModel._prune_heads  s<    
 +002LELLu%//;;EB 3r   r   r   r   rv   r   r   r   r7  rL  rM  r   rN  rO  r   r   c                 l   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c  [        R                  " UUU-   4US9nUc$  [        R                   " U[        R"                  US9nU R%                  X/5      nU R                   R                  (       aE  UbB  UR                  5       u  nnnUU4nUc  [        R                  " UUS9nU R'                  U5      nOS nU R)                  XPR                   R*                  5      nU R-                  UUUUUS	9nU R/                  UUUUUU	U
UUUUS
9nUS   nU R0                  b  U R1                  U5      OS nU(       d
  UU4USS  -   $ [3        UUUR4                  UR6                  UR8                  UR:                  S9$ )NFzDYou cannot specify both input_ids and inputs_embeds at the same timerw   z5You have to specify either input_ids or inputs_embedsr   r   )r   r   )r   rv   r   r   r   )
r   r   r   r7  rL  rM  r   rN  rO  r   r   )rT  pooler_outputrL  r   rU  rV  )r`   r   rN  use_return_dictr   rM  rY   %warn_if_padding_and_no_attention_maskr   r   r   r   rX   get_seq_lengthr\   onesr   r   get_extended_attention_maskinvert_attention_maskget_head_maskrG  r   r  r  r   rL  r   rU  rV  )r   r   r   r   rv   r   r   r   r7  rL  rM  r   rN  rO  r   r   r   r   r   r   extended_attention_maskencoder_batch_sizeencoder_sequence_lengthr   encoder_hidden_shapeencoder_extended_attention_maskembedding_outputencoder_outputsrx  r   s                                 r&   r   RemBertModel.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 # !"ZZ*jCY6Y)ZdjkN!"[[EJJvVN 150P0PQ_0m ;;!!&;&G=R=W=W=Y: 7$68O#P %-).4HQW)X&.2.H.HI_.`+.2+ &&y++2O2OP	??%)'#9 + 
 ,,2"7#B+/!5#) ' 
 *!,8<8OO4UY#]3oab6III;-'+;;)77&11,==
 	
r   )r`   r   r  r  )TNNNNNNNNNNNNNN)r   r   r   r   rz   r  r  r  r   r   r\   r   r   r   r   r   r   r   r   r   r   r   s   @r&   r  r    s    /0C  155959371559=A>BEI$(,0/3&*15m
E,,-m
 !!1!12m
 !!1!12	m

 u//0m
 E--.m
   1 12m
  ((9(9:m
 !)):): ;m
 "%e.?.?(@"ABm
 D>m
 $D>m
 'tnm
 d^m
 !.m
  
uBB	C!m
 m
r   r  c                     ^  \ rS rSr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\\\4   4S jj5       rSS jr\S\4S j5       rSrU =r$ )RemBertForMaskedLMi  cls.predictions.decoder.weightc                    > [         TU ]  U5        UR                  (       a  [        R	                  S5        [        USS9U l        [        U5      U l        U R                  5         g )NznIf you want to use `RemBertForMaskedLM` make sure `config.is_decoder=False` for bi-directional self-attention.Fr  
ry   rz   r   rB   warningr  r  rt  r,   r  r   s     r&   rz   RemBertForMaskedLM.__init__  sR     NN1
 $FeD%f- 	r   c                 B    U R                   R                  R                  $ r!   r,   rv  ro  r  s    r&   get_output_embeddings(RemBertForMaskedLM.get_output_embeddings.      xx##+++r   c                 8    XR                   R                  l        g r!   r  r   new_embeddingss     r&   set_output_embeddings(RemBertForMaskedLM.set_output_embeddings1      '5$r   r   r   r   rv   r   r   r   r7  labelsr   rN  rO  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	bF  [	        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{  
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   r   rv   r   r   r   r7  r   rN  rO  r   rw   r<   losslogitsr   rU  )
r`   r  r  r,   r   r   r|   r   r   rU  )r   r   r   r   rv   r   r   r   r7  r  r   rN  rO  r  rx  r{  masked_lm_lossloss_fctr  s                      r&   r   RemBertForMaskedLM.forward4  s    , &1%<k$++B]B],,))%'"7#9/!5#  
 "!* HH_5')H%&7&<&<RAWAW&XZ`ZeZefhZijN')GABK7F3A3M^%.YSYY$!//))	
 	
r   c                    UR                   nUS   nU R                  R                  c   S5       e[        R                  " X"R                  UR                   S   S45      /SS9n[        R                  " US4U R                  R                  [        R                  UR                  S9n[        R                  " X/SS9nXS.$ )Nr   z.The PAD token should be defined for generationr   rw   r   r   )r   r   )	rX   r`   r~   r\   cat	new_zerosfullr   r   )r   r   r   model_kwargsr   effective_batch_sizedummy_tokens          r&   prepare_inputs_for_generation0RemBertForMaskedLM.prepare_inputs_for_generationm  s    oo*1~ {{''3e5ee3N4L4LnNbNbcdNeghMi4j#kqstjj!1%t{{'?'?uzzZcZjZj
 IIy6A>	&IIr   c                     g)z
Legacy correction: RemBertForMaskedLM can't call `generate()` from `GenerationMixin`, even though it has a
`prepare_inputs_for_generation` method.
Fr"   )r,   s    r&   can_generateRemBertForMaskedLM.can_generate{  s     r   r,   r  )NNNNNNNNNNNNr!   )r   r   r   r   _tied_weights_keysrz   r  r  r   r   r\   r   r   r   r   r   r   r   r  classmethodr  r   r   r   s   @r&   r  r    sp   :;,6  155959371559=A>B-1,0/3&*6
E,,-6
 !!1!126
 !!1!12	6

 u//06
 E--.6
   1 126
  ((9(9:6
 !)):): ;6
 ))*6
 $D>6
 'tn6
 d^6
 
un$	%6
 6
pJ T  r   r  zS
    RemBERT Model with a `language modeling` head on top for CLM fine-tuning.
    c            "         ^  \ rS rSr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\	\
R                     S\	\   S\	\   S\	\   S\	\   S\\\4   4S jj5       rSrU =r$ )RemBertForCausalLMi  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 )NzOIf you want to use `RemBertForCausalLM` as a standalone, add `is_decoder=True.`Fr  r  r   s     r&   rz   RemBertForCausalLM.__init__  sL       NNlm#FeD%f- 	r   c                 B    U R                   R                  R                  $ r!   r  r  s    r&   r  (RemBertForCausalLM.get_output_embeddings  r  r   c                 8    XR                   R                  l        g r!   r  r  s     r&   r  (RemBertForCausalLM.set_output_embeddings  r  r   r   r   r   rv   r   r   r   r7  rL  r  rM  r   rN  rO  r   c                    Ub  UOU R                   R                  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
b*  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  
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 n `[0, ..., config.vocab_size]`.

Example:

```python
>>> from transformers import AutoTokenizer, RemBertForCausalLM, RemBertConfig
>>> import torch

>>> tokenizer = AutoTokenizer.from_pretrained("google/rembert")
>>> config = RemBertConfig.from_pretrained("google/rembert")
>>> config.is_decoder = True
>>> model = RemBertForCausalLM.from_pretrained("google/rembert", config=config)

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

>>> prediction_logits = outputs.logits
```N)r   r   rv   r   r   r   r7  rL  rM  r   rN  rO  r   r|   r<   )r  r  rL  r   rU  rV  )r`   r  r  r,   loss_functionr|   r   rL  r   rU  rV  )r   r   r   r   rv   r   r   r   r7  rL  r  rM  r   rN  rO  kwargsr  rx  r{  lm_lossr  s                        r&   r   RemBertForCausalLM.forward  s   R &1%<k$++B]B],,))%'"7#9+/!5#  
  "!* HH_5((!  ;;11 	G ')GABK7F,3,?WJ'KVK0$#33!//))$55
 	
r   r  r  )r   r   r   r   r  rz   r  r  r   r   r\   r   r   r   r   r   r   r   r   r   r   s   @r&   r  r    s    ;;
,6  155959371559=A>BEI-1$(,0/3&*Q
E,,-Q
 !!1!12Q
 !!1!12	Q

 u//0Q
 E--.Q
   1 12Q
  ((9(9:Q
 !)):): ;Q
 "%e.?.?(@"ABQ
 ))*Q
 D>Q
 $D>Q
 'tnQ
 d^Q
" 
u77	8#Q
 Q
r   r  z
    RemBERT 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                   R  ^  \ 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\\\4   4S jj5       rSrU =r$ ) RemBertForSequenceClassificationi  c                 0  > [         TU ]  U5        UR                  U l        [        U5      U l        [
        R                  " UR                  5      U l        [
        R                  " UR                  UR                  5      U l        U R                  5         g r!   ry   rz   
num_labelsr  r  r   r   classifier_dropout_probr   r   r   r;   r  r   s     r&   rz   )RemBertForSequenceClassification.__init__  si      ++#F+zz&"@"@A))F$6$68I8IJ 	r   r   r   r   rv   r   r   r  r   rN  rO  r   c                 R   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Gb  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$ )
ae  
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   r   rv   r   r   r   rN  rO  r   
regressionsingle_label_classificationmulti_label_classificationrw   r<   r  )r`   r  r  r   r;   problem_typer  r   r\   r   rV   r   squeezer   r   r   r   r   rU  )r   r   r   r   rv   r   r   r  r   rN  rO  r  r   r  r  r  r  s                    r&   r   (RemBertForSequenceClassification.forward  s   ( &1%<k$++B]B],,))%'/!5#  

  
]3/{{''/??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'!//))	
 	
r   r;   r   r  r  
NNNNNNNNNN)r   r   r   r   rz   r   r   r\   r   r   r   r   r   r   r   r   r   r   s   @r&   r  r    s     266:59481559-1,0/3&*E
E--.E
 !!2!23E
 !!1!12	E

 u001E
 E--.E
   1 12E
 ))*E
 $D>E
 'tnE
 d^E
 
u..	/E
 E
r   r  c                   R  ^  \ 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\\\4   4S jj5       rSrU =r$ )RemBertForMultipleChoiceiM  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   )ry   rz   r  r  r   r   r  r   r   r   r;   r  r   s     r&   rz   !RemBertForMultipleChoice.__init__O  sV     #F+zz&"@"@A))F$6$6: 	r   r   r   r   rv   r   r   r  r   rN  rO  r   c                 Z   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  [        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  
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.

    [What are token type IDs?](../glossary#token-type-ids)
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.
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)
Nr   rw   r   r  r<   r  )r`   r  rX   r   r   r  r   r;   r   r   r   rU  )r   r   r   r   rv   r   r   r  r   rN  rO  num_choicesr  r   r  reshaped_logitsr  r  r  s                      r&   r    RemBertForMultipleChoice.forwardY  s   X &1%<k$++B]B],5,Aiooa(}GZGZ[\G]>G>SINN2y~~b'9:Y]	M[Mg,,R1D1DR1HImqM[Mg,,R1D1DR1HImqGSG_|((\->->r-BCei ( r=#5#5b#9=;M;Mb;QR 	 ,,))%'/!5#  

  
]3/ ++b+6')HO4D%''!"+5F)-)9TGf$EvE("!//))	
 	
r   )r;   r   r  r  )r   r   r   r   rz   r   r   r\   r   r   r   r   r   r   r   r   r   r   s   @r&   r  r  M  s     266:59481559-1,0/3&*X
E--.X
 !!2!23X
 !!1!12	X

 u001X
 E--.X
   1 12X
 ))*X
 $D>X
 'tnX
 d^X
 
u//	0X
 X
r   r  c                   R  ^  \ 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\\\4   4S jj5       rSrU =r$ )RemBertForTokenClassificationi  c                 .  > [         TU ]  U5        UR                  U l        [        USS9U l        [
        R                  " UR                  5      U l        [
        R                  " UR                  UR                  5      U l        U R                  5         g NFr  r  r   s     r&   rz   &RemBertForTokenClassification.__init__  sk      ++#FeDzz&"@"@A))F$6$68I8IJ 	r   r   r   r   rv   r   r   r  r   rN  rO  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b<  [        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$ )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]`.
Nr  r   rw   r<   r  )r`   r  r  r   r;   r   r   r  r   r   rU  )r   r   r   r   rv   r   r   r  r   rN  rO  r  rx  r  r  r  r  s                    r&   r   %RemBertForTokenClassification.forward  s    $ &1%<k$++B]B],,))%'/!5#  

 "!*,,71')HFKKDOO<fkk"oNDY,F)-)9TGf$EvE$!//))	
 	
r   r  r  )r   r   r   r   rz   r   r   r\   r   r   r   r   r   r   r   r   r   r   s   @r&   r  r    s   	  266:59481559-1,0/3&*2
E--.2
 !!2!232
 !!1!12	2

 u0012
 E--.2
   1 122
 ))*2
 $D>2
 'tn2
 d^2
 
u++	,2
 2
r   r  c                   r  ^  \ 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\\\4   4S jj5       rSrU =r$ )RemBertForQuestionAnsweringi  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	  )
ry   rz   r  r  r  r   r   r   
qa_outputsr  r   s     r&   rz   $RemBertForQuestionAnswering.__init__  sU      ++#FeD))F$6$68I8IJ 	r   r   r   r   rv   r   r   start_positionsend_positionsr   rN  rO  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      nUR                  S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        UR                  SU5        [        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$ )	Nr  r   r   rw   r   )ignore_indexr<   )r  start_logits
end_logitsr   rU  )r`   r  r  r  rO   r  rU   r   clamp_r   r   r   rU  )r   r   r   r   rv   r   r   r  r  r   rN  rO  r  rx  r  r  r  
total_lossignored_indexr  
start_lossend_lossr  s                          r&   r   #RemBertForQuestionAnswering.forward  s    &1%<k$++B]B],,))%'/!5#  

 "!*1#)<<r<#: j#++B/''+

&=+D?'')*Q."1"9"9""==%%'(1, - 5 5b 9(--a0M""1m4  M2']CH!,@J
M:H$x/14J"J/'!"+=F/9/EZMF*Q6Q+%!!//))
 	
r   )r  r  r  )NNNNNNNNNNN)r   r   r   r   rz   r   r   r\   r   r   r   r   r   r   r   r   r   r   s   @r&   r  r    s$   	  266:594815596:48,0/3&*>
E--.>
 !!2!23>
 !!1!12	>

 u001>
 E--.>
   1 12>
 "%"2"23>
   0 01>
 $D>>
 'tn>
 d^>
 
u22	3>
 >
r   r  )
r  r  r  r  r  r  r.  r  r~  rn   )Dr   r   rD   typingr   r   r\   torch.utils.checkpointr   torch.nnr   r   r   activationsr
   cache_utilsr   r   
generationr   modeling_layersr   modeling_outputsr   r   r   r   r   r   r   r   modeling_utilsr   pytorch_utilsr   r   r   utilsr   r   configuration_rembertr   
get_loggerr   rB   rn   Modulerp   r   r   r   r  r  r(  r.  rB  re  rl  rt  r~  r  r  r  r  r  r  r  __all__r"   r   r&   <module>r-     sN     	 "    A A ! 5 ) 9	 	 	 . l l , 0 
		H	%Pf3		 3nBII g.299 g.V		 0ryy 0h"))  BII D- DN[
RYY [
~RYY "bii "! ! *_ * *. 	M
) M
M
` e/ e eP 
g
/ g

g
T Q
'= Q
Q
h d
5 d
 d
N ?
$: ?
 ?
D K
"8 K
 K
\r   