Ë
    T^(hQ ã                   óx  — d Z ddlZddlZddlmZmZmZ ddlZddlZddlm	Z	 ddl
mZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZmZmZ dd
lmZ ddlmZmZm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(  e%jR                  e*«      Z+dZ,dZ-d„ Z. G d„ de	j^                  «      Z0 G d„ de	j^                  «      Z1 G d„ de	j^                  «      Z2 G d„ de	j^                  «      Z3 G d„ de	j^                  «      Z4 G d„ de	j^                  «      Z5 G d„ de	j^                  «      Z6 G d „ d!e	j^                  «      Z7 G d"„ d#e	j^                  «      Z8 G d$„ d%e	j^                  «      Z9 G d&„ d'e	j^                  «      Z: G d(„ d)e	j^                  «      Z; G d*„ d+e«      Z<d,Z=d-Z> e#d.e=«       G d/„ d0e<«      «       Z? e#d1e=«       G d2„ d3e<«      «       Z@ e#d4e=«       G d5„ d6e<e«      «       ZA e#d7e=«       G d8„ d9e<«      «       ZB e#d:e=«       G d;„ d<e<«      «       ZC e#d=e=«       G d>„ d?e<«      «       ZD e#d@e=«       G dA„ dBe<«      «       ZEg dC¢ZFy)DzPyTorch RemBERT model.é    N)ÚOptionalÚTupleÚUnion)Únn)ÚBCEWithLogitsLossÚCrossEntropyLossÚMSELossé   )ÚACT2FN)ÚGenerationMixin)Ú)BaseModelOutputWithPastAndCrossAttentionsÚ,BaseModelOutputWithPoolingAndCrossAttentionsÚ!CausalLMOutputWithCrossAttentionsÚMaskedLMOutputÚMultipleChoiceModelOutputÚQuestionAnsweringModelOutputÚSequenceClassifierOutputÚTokenClassifierOutput)ÚPreTrainedModel)Úapply_chunking_to_forwardÚ find_pruneable_heads_and_indicesÚprune_linear_layer)Úadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚRemBertConfigr   úgoogle/rembertc           
      ó´  ‡— 	 ddl }ddl}ddl}t        j                  j                  |«      }t        j                  d|› �«       |j                  j                  |«      }g }g }	|D ]s  \  Š}
t        ˆfd„dD «       «      rŒt        j                  d‰› d|
› �«       |j                  j                  |‰«      }|j                  ‰«       |	j                  |«       Œu t        ||	«      D �]È  \  Š}‰j!                  d	d
«      Š‰j#                  d«      Št        d„ ‰D «       «      r(t        j                  ddj%                  ‰«      › �«       Œd| }‰D ]À  }|j'                  d|«      r|j#                  d|«      }n|g}|d   dk(  s|d   dk(  rt)        |d«      }nW|d   dk(  s|d   dk(  rt)        |d«      }n:|d   dk(  rt)        |d«      }n%|d   dk(  rt)        |d«      }n	 t)        ||d   «      }t/        |«      dk\  sŒ®t1        |d   «      }||   }ŒÂ dd dk(  rt)        |d«      }n|dk(  r|j3                  |«      }	 |j4                  |j4                  k7  r&t7        d|j4                  › d|j4                  › d �«      ‚	 t        j                  d!‰› �«       t=        j>                  |«      |_         �ŒË | S # t        $ r t        j                  d«       ‚ w xY w# t*        $ r7 t        j                  dj-                  dj%                  ‰«      «      «       Y �ŒÈw xY w# t8        $ r1}|xj:                  |j4                  |j4                  fz  c_        ‚ d}~ww xY w)"z'Load tf checkpoints in a pytorch model.r   Nz™Loading 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   ó&   •K  — | ]  }|‰v –— Œ
 y ­w©N© )Ú.0ÚdenyÚnames     €új/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/rembert/modeling_rembert.pyú	<genexpr>z-load_tf_weights_in_rembert.<locals>.<genexpr>N   s   øè ø€ ÒX ˆt�tŒ|ÑXùs   ƒ)Úadam_vÚadam_mÚoutput_embeddingÚclszLoading TF weight z with shape zbert/zrembert/ú/c              3   ó$   K  — | ]  }|d v –— Œ
 y­w))r*   r+   ÚAdamWeightDecayOptimizerÚAdamWeightDecayOptimizer_1Úglobal_stepNr$   )r%   Úns     r(   r)   z-load_tf_weights_in_rembert.<locals>.<genexpr>_   s   è ø€ ò 
àð ÐnÔnñ
ùó   ‚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ÚarraysrZ   ÚarrayÚpointerÚm_nameÚscope_namesÚnumÚer'   s                    @r(   Úload_tf_weights_in_rembertrp   8   sV  ø€ ð
ÛãÛô �g‰g�o‰oÐ0Ó1€GÜ
‡K�KÐ8¸¸	ÐBÔCà—‘×'Ñ'¨Ó0€IØ€EØ€FØ ò 	‰ˆˆeô ÓXÐ(WÔXÔXàÜ�‰Ð(¨¨¨l¸5¸'ÐBÔCØ—‘×&Ñ& w°Ó5ˆØ�‰�TÔØ�‰�eÕð	ô ˜5 &Ó)ó 1/‰ˆˆeà�|‰|˜G ZÓ0ˆð �z‰z˜#‹ˆô ñ 
àô
ô 
ô �K‰K˜) C§H¡H¨T£NÐ#3Ð4Ô5ØØˆØò 	'ˆFØ�|‰|Ð,¨fÔ5Ø Ÿh™h y°&Ó9‘à%˜h�Ø˜1‰~ Ò)¨[¸©^¸wÒ-FÜ! '¨8Ó4‘Ø˜Q‘ =Ò0°KÀ±NÀfÒ4LÜ! '¨6Ó2‘Ø˜Q‘Ð#3Ò3Ü! '¨8Ó4‘Ø˜Q‘ 7Ò*Ü! '¨<Ó8‘ðÜ% g¨{¸1©~Ó>�Gô �;Ó 1Ó$Ü˜+ a™.Ó)�Ø! #™,‘ð+	'ð, �#�$ˆ<˜=Ò(Ü˜g xÓ0‰GØ�xÒØ—L‘L Ó'ˆEð	Ø�}‰} §¡Ò+Ü  >°'·-±-°Ð@QÐRW×R]ÑR]ÐQ^Ð^iÐ!jÓkÐkð ,ô
 	�‰Ð0°°Ð7Ô8Ü×'Ñ'¨Ó.ˆŽðc1/ðd €LøôS ò Ü�‰ðQô	
ð 	ðûôn &ò Ü—K‘K × 4Ñ 4°S·X±X¸d³^Ó DÔEÚðûô ò 	Ø�FŠF�w—}‘} e§k¡kÐ2Ñ2�FØûð	ús5   ƒJ7 Ç!KÉ ?LÊ7 KË<LÌLÌ	MÌ&,MÍMc                   óÊ   ‡ — e Zd ZdZˆ fd„Z	 	 	 	 	 d
deej                     deej                     deej                     deej                     de	dej                  fd	„Zˆ xZS )ÚRemBertEmbeddingszGConstruct the embeddings from word, position and token_type embeddings.c                 ó|  •— t         ‰| �  «        t        j                  |j                  |j
                  |j                  ¬«      | _        t        j                  |j                  |j
                  «      | _	        t        j                  |j                  |j
                  «      | _        t        j                  |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        | j#                  dt%        j&                  |j                  «      j)                  d«      d¬«       y )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©Úselfrb   Ú	__class__s     €r(   r{   zRemBertEmbeddings.__init__Ž   sç   ø€ Ü‰ÑÔÜ!Ÿ|™|Ø×Ñ˜v×:Ñ:È×H[ÑH[ô 
ˆÔô $&§<¡<°×0NÑ0NÐPV×PkÑPkÓ#lˆÔ Ü%'§\¡\°&×2HÑ2HÈ&×JeÑJeÓ%fˆÔ"ô Ÿ™ f×&AÑ&AÀv×G\ÑG\Ô]ˆŒÜ—z‘z &×"<Ñ"<Ó=ˆŒð 	×ÑØœEŸL™L¨×)GÑ)GÓH×OÑOÐPWÓXÐejð 	õ 	
ó    Ú	input_idsÚtoken_type_idsrw   Úinputs_embedsÚpast_key_values_lengthÚreturnc                 óÊ  — |�|j                  «       }n|j                  «       d d }|d   }|€| j                  d d …|||z   …f   }|€:t        j                  |t        j                  | j                  j
                  ¬«      }|€| j                  |«      }| j                  |«      }||z   }	| j                  |«      }
|	|
z  }	| j                  |	«      }	| j                  |	«      }	|	S )Nrx   r   ©ÚdtypeÚdevice)Úsizerw   r^   ÚzerosÚlongr™   r€   r„   r‚   r…   r‰   )rŽ   r‘   r’   rw   r“   r”   Úinput_shapeÚ
seq_lengthr„   Ú
embeddingsr‚   s              r(   ÚforwardzRemBertEmbeddings.forward    só   € ð Ð Ø#Ÿ.™.Ó*‰Kà'×,Ñ,Ó.¨s°Ð3ˆKà  ‘^ˆ
àÐØ×,Ñ,ªQÐ0FÈÐVlÑIlÐ0lÐ-lÑmˆLàÐ!Ü"Ÿ[™[¨¼E¿J¹JÈt×O`ÑO`×OgÑOgÔhˆNàÐ Ø ×0Ñ0°Ó;ˆMØ $× :Ñ :¸>Ó JÐà"Ð%:Ñ:ˆ
Ø"×6Ñ6°|ÓDÐØÐ)Ñ)ˆ
Ø—^‘^ JÓ/ˆ
Ø—\‘\ *Ó-ˆ
ØÐr�   )NNNNr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r{   r   r^   Ú
LongTensorÚFloatTensorrX   ÚTensorr    Ú__classcell__©r�   s   @r(   rr   rr   ‹   s‹   ø„ ÙQô
ð( 15Ø59Ø37Ø59Ø&'ñà˜E×,Ñ,Ñ-ðð ! ×!1Ñ!1Ñ2ðð ˜u×/Ñ/Ñ0ð	ð
   × 1Ñ 1Ñ2ðð !$ðð 
�‰÷r�   rr   c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚRemBertPoolerc                 ó²   •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  «       | _        y r#   )rz   r{   r   ÚLinearÚhidden_sizeÚdenseÚTanhÚ
activationr�   s     €r(   r{   zRemBertPooler.__init__Ã   s9   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ'™'›)ˆ�r�   Úhidden_statesr•   c                 ó\   — |d d …df   }| j                  |«      }| j                  |«      }|S )Nr   )r¯   r±   )rŽ   r²   Úfirst_token_tensorÚpooled_outputs       r(   r    zRemBertPooler.forwardÈ   s6   € ð +ª1¨a¨4Ñ0ÐØŸ
™
Ð#5Ó6ˆØŸ™¨Ó6ˆØÐr�   ©r¡   r¢   r£   r{   r^   r§   r    r¨   r©   s   @r(   r«   r«   Â   s#   ø„ ô$ð
 U§\¡\ð °e·l±l÷ r�   r«   c                   óö   ‡ — e Zd Zˆ fd„Zd„ Z	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     de	e	ej                        d	e
d
e	fd„Zˆ xZS )ÚRemBertSelfAttentionc                 óî  •— t         ‰| �  «        |j                  |j                  z  dk7  r2t	        |d«      s&t        d|j                  › d|j                  › d�«      ‚|j                  | _        t        |j                  |j                  z  «      | _        | j                  | j                  z  | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  | j                  «      | _        t        j                  |j                  «      | _        |j"                  | _        y )Nr   Úembedding_sizezThe hidden size (z6) is not a multiple of the number of attention heads (ú))rz   r{   r®   Únum_attention_headsÚhasattrr[   rX   Úattention_head_sizeÚall_head_sizer   r­   ÚqueryÚkeyÚvaluer‡   Úattention_probs_dropout_probr‰   Ú
is_decoderr�   s     €r(   r{   zRemBertSelfAttention.__init__Ò   s)  ø€ Ü‰ÑÔØ×Ñ × :Ñ :Ñ:¸aÒ?ÌÐPVÐXhÔHiÜØ# F×$6Ñ$6Ð#7ð 8Ø ×4Ñ4Ð5°Qð8óð ð
 $*×#=Ñ#=ˆÔ Ü#& v×'9Ñ'9¸F×<VÑ<VÑ'VÓ#WˆÔ Ø!×5Ñ5¸×8PÑ8PÑPˆÔä—Y‘Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
Ü—9‘9˜V×/Ñ/°×1CÑ1CÓDˆŒÜ—Y‘Y˜v×1Ñ1°4×3EÑ3EÓFˆŒ
ä—z‘z &×"EÑ"EÓFˆŒà ×+Ñ+ˆ�r�   c                 ó    — |j                  «       d d | j                  | j                  fz   } |j                  |Ž }|j	                  dddd«      S )Nrx   r   r>   r   r
   )rš   r¼   r¾   ÚviewÚpermute)rŽ   ÚxÚnew_x_shapes      r(   Útranspose_for_scoresz)RemBertSelfAttention.transpose_for_scoresæ   sN   € Ø—f‘f“h˜s �m t×'?Ñ'?À×AYÑAYÐ&ZÑZˆØˆA�F‰F�KÐ ˆØ�y‰y˜˜A˜q !Ó$Ð$r�   r²   Úattention_maskÚ	head_maskÚencoder_hidden_statesÚencoder_attention_maskÚpast_key_valueÚoutput_attentionsr•   c                 ó¬  — | j                  |«      }|d u}	|	r|�|d   }
|d   }|}�n |	rC| j                  | j                  |«      «      }
| j                  | j                  |«      «      }|}n»|�y| j                  | j                  |«      «      }
| j                  | j                  |«      «      }t	        j
                  |d   |
gd¬«      }
t	        j
                  |d   |gd¬«      }n@| j                  | j                  |«      «      }
| j                  | j                  |«      «      }| j                  |«      }| j                  r|
|f}t	        j                  ||
j                  dd«      «      }|t        j                  | j                  «      z  }|�||z   }t        j                  j                  |d¬«      }| j                  |«      }|�||z  }t	        j                  ||«      }|j!                  dddd«      j#                  «       }|j%                  «       d d | j&                  fz   } |j(                  |Ž }|r||fn|f}| j                  r||fz   }|S )Nr   r   r>   ©Údimrx   éþÿÿÿr
   )rÀ   rÊ   rÁ   rÂ   r^   ÚcatrÄ   ÚmatmulrY   ÚmathÚsqrtr¾   r   Ú
functionalÚsoftmaxr‰   rÇ   Ú
contiguousrš   r¿   rÆ   )rŽ   r²   rË   rÌ   rÍ   rÎ   rÏ   rÐ   Úmixed_query_layerÚis_cross_attentionÚ	key_layerÚvalue_layerÚquery_layerÚattention_scoresÚattention_probsÚcontext_layerÚnew_context_layer_shapeÚoutputss                     r(   r    zRemBertSelfAttention.forwardë   sX  € ð !ŸJ™J }Ó5Ðð
 3¸$Ð>Ðá .Ð"<à& qÑ)ˆIØ(¨Ñ+ˆKØ3ŠNÙØ×1Ñ1°$·(±(Ð;PÓ2QÓRˆIØ×3Ñ3°D·J±JÐ?TÓ4UÓVˆKØ3‰NØÐ'Ø×1Ñ1°$·(±(¸=Ó2IÓJˆIØ×3Ñ3°D·J±J¸}Ó4MÓNˆKÜŸ	™	 >°!Ñ#4°iÐ"@ÀaÔHˆIÜŸ)™) ^°AÑ%6¸Ð$DÈ!ÔL‰Kà×1Ñ1°$·(±(¸=Ó2IÓJˆIØ×3Ñ3°D·J±J¸}Ó4MÓNˆKà×/Ñ/Ð0AÓBˆà�?Š?ð (¨Ð5ˆNô !Ÿ<™<¨°Y×5HÑ5HÈÈRÓ5PÓQÐà+¬d¯i©i¸×8PÑ8PÓ.QÑQÐØÐ%à/°.Ñ@Ðô Ÿ-™-×/Ñ/Ð0@ÀbÐ/ÓIˆð Ÿ,™, Ó7ˆð Ð Ø-°	Ñ9ˆOäŸ™ _°kÓBˆà%×-Ñ-¨a°°A°qÓ9×DÑDÓFˆØ"/×"4Ñ"4Ó"6°s¸Ð";¸t×?QÑ?QÐ>SÑ"SÐØ*˜×*Ñ*Ð,CÐDˆá6G�= /Ñ2ÈmÐM]ˆà�?Š?Ø Ð 1Ñ1ˆGØˆr�   ©NNNNNF)r¡   r¢   r£   r{   rÊ   r^   r§   r   r¦   r   Úboolr    r¨   r©   s   @r(   r¸   r¸   Ñ   s½   ø„ ô,ò(%ð 7;Ø15Ø=AØ>BØ:>Ø"'ñLà—|‘|ðLð ! ×!2Ñ!2Ñ3ðLð ˜E×-Ñ-Ñ.ð	Lð
  (¨×(9Ñ(9Ñ:ðLð !)¨×):Ñ):Ñ ;ðLð ˜e E×$5Ñ$5Ñ6Ñ7ðLð  ðLð 
÷Lr�   r¸   c                   ón   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  dej
                  fd„Zˆ xZS )ÚRemBertSelfOutputc                 ó(  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        j                  |j                  |j                  ¬«      | _        t        j                  |j                  «      | _
        y ©Nru   )rz   r{   r   r­   r®   r¯   r…   r†   r‡   rˆ   r‰   r�   s     €r(   r{   zRemBertSelfOutput.__init__<  s`   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
ÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆ�r�   r²   Úinput_tensorr•   c                 ór   — | j                  |«      }| j                  |«      }| j                  ||z   «      }|S r#   ©r¯   r‰   r…   ©rŽ   r²   rì   s      r(   r    zRemBertSelfOutput.forwardB  ó7   € ØŸ
™
 =Ó1ˆØŸ™ ]Ó3ˆØŸ™ }°|Ñ'CÓDˆØÐr�   r¶   r©   s   @r(   ré   ré   ;  ó1   ø„ ô>ð U§\¡\ð ÀÇÁð ÐRW×R^ÑR^÷ r�   ré   c                   ó  ‡ — e Zd Zˆ fd„Zd„ Z	 	 	 	 	 	 ddej                  deej                     deej                     deej                     deej                     dee	e	ej                           d	ee
   d
e	ej                     fd„Zˆ xZS )ÚRemBertAttentionc                 ó€   •— t         ‰| �  «        t        |«      | _        t	        |«      | _        t        «       | _        y r#   )rz   r{   r¸   rŽ   ré   ÚoutputÚsetÚpruned_headsr�   s     €r(   r{   zRemBertAttention.__init__J  s0   ø€ Ü‰ÑÔÜ(¨Ó0ˆŒ	Ü'¨Ó/ˆŒÜ›EˆÕr�   c                 ó>  — t        |«      dk(  ry t        || j                  j                  | j                  j                  | j
                  «      \  }}t        | j                  j                  |«      | j                  _        t        | j                  j                  |«      | j                  _        t        | j                  j                  |«      | j                  _	        t        | j                  j                  |d¬«      | j                  _        | j                  j                  t        |«      z
  | j                  _        | j                  j                  | j                  j                  z  | j                  _        | j
                  j                  |«      | _        y )Nr   r   rÒ   )rW   r   rŽ   r¼   r¾   r÷   r   rÀ   rÁ   rÂ   rõ   r¯   r¿   Úunion)rŽ   ÚheadsÚindexs      r(   Úprune_headszRemBertAttention.prune_headsQ  s  € Üˆu‹:˜Š?ØÜ7Ø�4—9‘9×0Ñ0°$·)±)×2OÑ2OÐQU×QbÑQbó
‰ˆˆuô
 -¨T¯Y©Y¯_©_¸eÓDˆ�	‰	ŒÜ*¨4¯9©9¯=©=¸%Ó@ˆ�	‰	ŒÜ,¨T¯Y©Y¯_©_¸eÓDˆ�	‰	ŒÜ.¨t¯{©{×/@Ñ/@À%ÈQÔOˆ�‰Ôð )-¯	©	×(EÑ(EÌÈEË
Ñ(Rˆ�	‰	Ô%Ø"&§)¡)×"?Ñ"?À$Ç)Á)×B_ÑB_Ñ"_ˆ�	‰	ÔØ ×-Ñ-×3Ñ3°EÓ:ˆÕr�   r²   rË   rÌ   rÍ   rÎ   rÏ   rÐ   r•   c           	      óp   — | j                  |||||||«      }| j                  |d   |«      }	|	f|dd  z   }
|
S )Nr   r   )rŽ   rõ   )rŽ   r²   rË   rÌ   rÍ   rÎ   rÏ   rÐ   Úself_outputsÚattention_outputrå   s              r(   r    zRemBertAttention.forwardd  sW   € ð —y‘yØØØØ!Ø"ØØó
ˆð  Ÿ;™; |°A¡¸ÓFÐØ#Ð%¨°Q°RÐ(8Ñ8ˆØˆr�   ræ   )r¡   r¢   r£   r{   rü   r^   r§   r   r¦   r   rç   r    r¨   r©   s   @r(   ró   ró   I  sÆ   ø„ ô"ò;ð, 7;Ø15Ø=AØ>BØDHØ,1ñà—|‘|ðð ! ×!2Ñ!2Ñ3ðð ˜E×-Ñ-Ñ.ð	ð
  (¨×(9Ñ(9Ñ:ðð !)¨×):Ñ):Ñ ;ðð !  u¨U×->Ñ->Ñ'?Ñ!@ÑAðð $ D™>ðð 
ˆu�|‰|Ñ	÷r�   ró   c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚRemBertIntermediatec                 ó  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        |j                  t        «      rt        |j                     | _        y |j                  | _        y r#   )rz   r{   r   r­   r®   Úintermediate_sizer¯   Ú
isinstanceÚ
hidden_actÚstrr   Úintermediate_act_fnr�   s     €r(   r{   zRemBertIntermediate.__init__~  s]   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3KÑ3KÓLˆŒ
Ü�f×'Ñ'¬Ô-Ü'-¨f×.?Ñ.?Ñ'@ˆDÕ$à'-×'8Ñ'8ˆDÕ$r�   r²   r•   c                 óJ   — | j                  |«      }| j                  |«      }|S r#   )r¯   r  ©rŽ   r²   s     r(   r    zRemBertIntermediate.forward†  s&   € ØŸ
™
 =Ó1ˆØ×0Ñ0°Ó?ˆØÐr�   r¶   r©   s   @r(   r  r  }  s#   ø„ ô9ð U§\¡\ð °e·l±l÷ r�   r  c                   ón   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  dej
                  fd„Zˆ xZS )ÚRemBertOutputc                 ó(  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        j                  |j
                  |j                  ¬«      | _        t        j                  |j                  «      | _        y rë   )rz   r{   r   r­   r  r®   r¯   r…   r†   r‡   rˆ   r‰   r�   s     €r(   r{   zRemBertOutput.__init__Ž  s`   ø€ Ü‰ÑÔÜ—Y‘Y˜v×7Ñ7¸×9KÑ9KÓLˆŒ
ÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆŒÜ—z‘z &×"<Ñ"<Ó=ˆ�r�   r²   rì   r•   c                 ór   — | j                  |«      }| j                  |«      }| j                  ||z   «      }|S r#   rî   rï   s      r(   r    zRemBertOutput.forward”  rð   r�   r¶   r©   s   @r(   r  r  �  rñ   r�   r  c                   ó  ‡ — e Zd Zˆ fd„Z	 	 	 	 	 	 ddej
                  deej                     deej                     deej                     deej                     deeeej                           dee	   d	eej
                     fd
„Z
d„ Zˆ xZS )ÚRemBertLayerc                 ób  •— t         ‰| �  «        |j                  | _        d| _        t	        |«      | _        |j                  | _        |j                  | _        | j                  r*| j                  st        | › d�«      ‚t	        |«      | _	        t        |«      | _        t        |«      | _        y )Nr   z> should be used as a decoder model if cross attention is added)rz   r{   Úchunk_size_feed_forwardÚseq_len_dimró   Ú	attentionrÄ   Úadd_cross_attentionr[   Úcrossattentionr  Úintermediater  rõ   r�   s     €r(   r{   zRemBertLayer.__init__œ  s”   ø€ Ü‰ÑÔØ'-×'EÑ'EˆÔ$ØˆÔÜ)¨&Ó1ˆŒØ ×+Ñ+ˆŒØ#)×#=Ñ#=ˆÔ Ø×#Ò#Ø—?’?Ü  D 6Ð)gÐ!hÓiÐiÜ"2°6Ó":ˆDÔÜ/°Ó7ˆÔÜ# FÓ+ˆ�r�   r²   rË   rÌ   rÍ   rÎ   rÏ   rÐ   r•   c           	      óÒ  — |�|d d nd }| j                  |||||¬«      }	|	d   }
| j                  r|	dd }|	d   }n|	dd  }d }| j                  rT|�Rt        | d«      st        d| › d�«      ‚|�|d	d  nd }| j	                  |
||||||«      }|d   }
||dd z   }|d   }|z   }t        | j                  | j                  | j                  |
«      }|f|z   }| j                  r|fz   }|S )
Nr>   )rÐ   rÏ   r   r   rx   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Ä   r½   r[   r  r   Úfeed_forward_chunkr  r  )rŽ   r²   rË   rÌ   rÍ   rÎ   rÏ   rÐ   Úself_attn_past_key_valueÚself_attention_outputsrÿ   rå   Úpresent_key_valueÚcross_attn_present_key_valueÚcross_attn_past_key_valueÚcross_attention_outputsÚlayer_outputs                    r(   r    zRemBertLayer.forward«  s}  € ð :HÐ9S >°"°1Ñ#5ÐY]Ð Ø!%§¡ØØØØ/Ø3ð "0ó "
Ðð 2°!Ñ4Ðð �?Š?Ø,¨Q¨rÐ2ˆGØ 6°rÑ :Ñà,¨Q¨RÐ0ˆGà'+Ð$Ø�?Š?Ð4Ð@Ü˜4Ð!1Ô2Ü Ø=¸d¸Vð DDð Dóð ð @NÐ?Y¨°r°sÑ(;Ð_cÐ%Ø&*×&9Ñ&9Ø ØØØ%Ø&Ø)Ø!ó'Ð#ð  7°qÑ9ÐØÐ 7¸¸"Ð =Ñ=ˆGð ,CÀ2Ñ+FÐ(Ø 1Ð4PÑ PÐä0Ø×#Ñ# T×%AÑ%AÀ4×CSÑCSÐUeó
ˆð  �/ GÑ+ˆð �?Š?ØÐ!2Ð 4Ñ4ˆGàˆr�   c                 óL   — | j                  |«      }| j                  ||«      }|S r#   )r  rõ   )rŽ   rÿ   Úintermediate_outputr  s       r(   r  zRemBertLayer.feed_forward_chunkí  s,   € Ø"×/Ñ/Ð0@ÓAÐØ—{‘{Ð#6Ð8HÓIˆØÐr�   ræ   )r¡   r¢   r£   r{   r^   r§   r   r¦   r   rç   r    r  r¨   r©   s   @r(   r  r  ›  sÇ   ø„ ô,ð$ 7;Ø15Ø=AØ>BØDHØ,1ñ?à—|‘|ð?ð ! ×!2Ñ!2Ñ3ð?ð ˜E×-Ñ-Ñ.ð	?ð
  (¨×(9Ñ(9Ñ:ð?ð !)¨×):Ñ):Ñ ;ð?ð !  u¨U×->Ñ->Ñ'?Ñ!@ÑAð?ð $ D™>ð?ð 
ˆu�|‰|Ñ	ó?öDr�   r  c                   ó  ‡ — e Zd Zˆ fd„Z	 	 	 	 	 	 	 	 	 ddej
                  deej                     deej                     deej                     deej                     deeeej                           dee	   d	e	d
e	de	de
eef   fd„Zˆ xZS )ÚRemBertEncoderc                 ó.  •— t         ‰| �  «        || _        t        j                  |j
                  |j                  «      | _        t        j                  t        |j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _        d| _        y c c}w )NF)rz   r{   rb   r   r­   r~   r®   Úembedding_hidden_mapping_inÚ
ModuleListÚrangeÚnum_hidden_layersr  ÚlayerÚgradient_checkpointing)rŽ   rb   Ú_r�   s      €r(   r{   zRemBertEncoder.__init__ô  sn   ø€ Ü‰ÑÔØˆŒä+-¯9©9°V×5PÑ5PÐRX×RdÑRdÓ+eˆÔ(Ü—]‘]Ä%È×H`ÑH`ÓBaÖ#b¸Q¤L°Õ$8Ò#bÓcˆŒ
Ø&+ˆÕ#ùò $cs   Á,Br²   rË   rÌ   rÍ   rÎ   Úpast_key_valuesÚ	use_cacherÐ   Úoutput_hidden_statesÚreturn_dictr•   c                 ó¼  — | j                   r%| j                  r|rt        j                  d«       d}| j	                  |«      }|	rdnd }|rdnd }|r| j
                  j                  rdnd }|rdnd }t        | j                  «      D ]¤  \  }}|	r||fz   }|�||   nd }|�||   nd }| j                   r/| j                  r#| j                  |j                  |||||||«      }n ||||||||«      }|d   }|r	||d   fz  }|sŒ|||d   fz   }| j
                  j                  sŒœ||d   fz   }Œ¦ |	r||fz   }|
st        d„ |||||fD «       «      S t        |||||¬	«      S )
NzZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Fr$   r   rx   r   r>   c              3   ó$   K  — | ]  }|�|–— Œ
 y ­wr#   r$   )r%   Úvs     r(   r)   z)RemBertEncoder.forward.<locals>.<genexpr>>  s   è ø€ ò 
àð �=ô ñ
ùr4   )Úlast_hidden_stater,  r²   Ú
attentionsÚcross_attentions)r*  ÚtrainingrD   Úwarning_oncer%  rb   r  Ú	enumerater)  Ú_gradient_checkpointing_funcÚ__call__Útupler   )rŽ   r²   rË   rÌ   rÍ   rÎ   r,  r-  rÐ   r.  r/  Úall_hidden_statesÚall_self_attentionsÚall_cross_attentionsÚnext_decoder_cacheÚiÚlayer_moduleÚlayer_head_maskrÏ   Úlayer_outputss                       r(   r    zRemBertEncoder.forwardü  sÞ  € ð ×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øpôð "�	Ø×8Ñ8¸ÓGˆÙ"6™B¸DÐÙ$5™b¸4ÐÙ%6¸4¿;¹;×;ZÒ;Z™rÐ`dÐá#,™R°$ÐÜ(¨¯©Ó4ò #	V‰OˆAˆ|Ù#Ø$5¸Ð8HÑ$HÐ!à.7Ð.C˜i¨šlÈˆOØ3BÐ3N˜_¨QÒ/ÐTXˆNà×*Ò*¨t¯}ª}Ø $× AÑ AØ ×)Ñ)Ø!Ø"Ø#Ø)Ø*Ø"Ø%ó	!‘ñ !-Ø!Ø"Ø#Ø)Ø*Ø"Ø%ó!�ð *¨!Ñ,ˆMÙØ" }°RÑ'8Ð&:Ñ:Ð"Ú Ø&9¸]È1Ñ=MÐ<OÑ&OÐ#Ø—;‘;×2Ó2Ø+?À=ÐQRÑCSÐBUÑ+UÑ(ðG#	VñJ  Ø 1°]Ð4DÑ DÐáÜñ 
ð "Ø&Ø%Ø'Ø(ðô
ó 
ð 
ô 9Ø+Ø.Ø+Ø*Ø1ô
ð 	
r�   )	NNNNNNFFT)r¡   r¢   r£   r{   r^   r§   r   r¦   r   rç   r   r   r    r¨   r©   s   @r(   r#  r#  ó  sö   ø„ ô,ð 7;Ø15Ø=AØ>BØEIØ$(Ø"'Ø%*Ø ñS
à—|‘|ðS
ð ! ×!2Ñ!2Ñ3ðS
ð ˜E×-Ñ-Ñ.ð	S
ð
  (¨×(9Ñ(9Ñ:ðS
ð !)¨×):Ñ):Ñ ;ðS
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðS
ð ˜D‘>ðS
ð  ðS
ð #ðS
ð ðS
ð 
ˆuÐ?Ð?Ñ	@÷S
r�   r#  c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚRemBertPredictionHeadTransformc                 óh  •— t         ‰| �  «        t        j                  |j                  |j                  «      | _        t        |j                  t        «      rt        |j                     | _
        n|j                  | _
        t        j                  |j                  |j                  ¬«      | _        y rë   )rz   r{   r   r­   r®   r¯   r  r  r  r   Útransform_act_fnr…   r†   r�   s     €r(   r{   z'RemBertPredictionHeadTransform.__init__T  s{   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3EÑ3EÓFˆŒ
Ü�f×'Ñ'¬Ô-Ü$*¨6×+<Ñ+<Ñ$=ˆDÕ!à$*×$5Ñ$5ˆDÔ!ÜŸ™ f×&8Ñ&8¸f×>SÑ>SÔTˆ�r�   r²   r•   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S r#   )r¯   rG  r…   r	  s     r(   r    z&RemBertPredictionHeadTransform.forward]  s4   € ØŸ
™
 =Ó1ˆØ×-Ñ-¨mÓ<ˆØŸ™ }Ó5ˆØÐr�   r¶   r©   s   @r(   rE  rE  S  s$   ø„ ôUð U§\¡\ð °e·l±l÷ r�   rE  c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚRemBertLMPredictionHeadc                 ón  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        j                  |j
                  |j                  «      | _        t        |j                     | _        t        j                  |j
                  |j                  ¬«      | _        y rë   )rz   r{   r   r­   r®   Úoutput_embedding_sizer¯   r}   Údecoderr   r  r±   r…   r†   r�   s     €r(   r{   z RemBertLMPredictionHead.__init__e  sz   ø€ Ü‰ÑÔÜ—Y‘Y˜v×1Ñ1°6×3OÑ3OÓPˆŒ
Ü—y‘y ×!=Ñ!=¸v×?PÑ?PÓQˆŒÜ  ×!2Ñ!2Ñ3ˆŒÜŸ™ f×&BÑ&BÈ×H]ÑH]Ô^ˆ�r�   r²   r•   c                 óŽ   — | j                  |«      }| j                  |«      }| j                  |«      }| j                  |«      }|S r#   )r¯   r±   r…   rM  r	  s     r(   r    zRemBertLMPredictionHead.forwardl  s@   € ØŸ
™
 =Ó1ˆØŸ™¨Ó6ˆØŸ™ }Ó5ˆØŸ™ ]Ó3ˆØÐr�   r¶   r©   s   @r(   rJ  rJ  d  s$   ø„ ô_ð U§\¡\ð °e·l±l÷ r�   rJ  c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚRemBertOnlyMLMHeadc                 óB   •— t         ‰| �  «        t        |«      | _        y r#   )rz   r{   rJ  Úpredictionsr�   s     €r(   r{   zRemBertOnlyMLMHead.__init__v  s   ø€ Ü‰ÑÔÜ2°6Ó:ˆÕr�   Úsequence_outputr•   c                 ó(   — | j                  |«      }|S r#   )rR  )rŽ   rS  Úprediction_scoress      r(   r    zRemBertOnlyMLMHead.forwardz  s   € Ø ×,Ñ,¨_Ó=ÐØ Ð r�   r¶   r©   s   @r(   rP  rP  u  s#   ø„ ô;ð! u§|¡|ð !¸¿¹÷ !r�   rP  c                   ó&   — e Zd ZdZeZeZdZdZ	d„ Z
y)ÚRemBertPreTrainedModelz†
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    ÚrembertTc                 ó  — t        |t        j                  «      rm|j                  j                  j                  d| j                  j                  ¬«       |j                  �%|j                  j                  j                  «        yyt        |t        j                  «      rz|j                  j                  j                  d| j                  j                  ¬«       |j                  �2|j                  j                  |j                     j                  «        yyt        |t        j                  «      rJ|j                  j                  j                  «        |j                  j                  j                  d«       yy)zInitialize the weightsg        )ÚmeanÚstdNg      ð?)r  r   r­   r7   r`   Únormal_rb   Úinitializer_ranger:   Úzero_r|   rt   r…   Úfill_)rŽ   Úmodules     r(   Ú_init_weightsz$RemBertPreTrainedModel._init_weightsŠ  s  € ä�fœbŸi™iÔ(ð �M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ä˜¤§¡Ô-Ø�K‰K×Ñ×"Ñ"Ô$Ø�M‰M×Ñ×$Ñ$ SÕ)ð .r�   N)r¡   r¢   r£   r¤   r   Úconfig_classrp   Úload_tf_weightsÚbase_model_prefixÚsupports_gradient_checkpointingra  r$   r�   r(   rW  rW    s$   „ ñð
 !€LØ0€OØ!ÐØ&*Ð#ó*r�   rW  aJ  
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`RemBertConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
a5
  
    Args:
        input_ids (`torch.LongTensor` of shape `({0})`):
            Indices of input sequence tokens in the vocabulary.

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

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`torch.FloatTensor` of shape `({0})`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

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

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

        inputs_embeds (`torch.FloatTensor` of shape `({0}, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert *input_ids* indices into associated vectors than the
            model's internal embedding lookup matrix.
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
zaThe bare RemBERT Model transformer outputting raw hidden-states without any specific head on top.c            !       óú  ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zd„ Z ee	j                  d«      «       edee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 dd	eej                      d
eej                      deej                      deej                      deej"                     deej"                     deej"                     deej"                     deeeej"                           dee   dee   dee   dee   deeef   fd„«       «       Zˆ xZS )ÚRemBertModela  

    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://arxiv.org/abs/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.
    c                 óº   •— t         ‰| �  |«       || _        t        |«      | _        t        |«      | _        |rt        |«      nd | _        | j                  «        y r#   )
rz   r{   rb   rr   rŸ   r#  Úencoderr«   ÚpoolerÚ	post_init)rŽ   rb   Úadd_pooling_layerr�   s      €r(   r{   zRemBertModel.__init__é  sK   ø€ Ü‰Ñ˜Ô ØˆŒä+¨FÓ3ˆŒÜ% fÓ-ˆŒá/@”m FÔ+ÀdˆŒð 	�‰Õr�   c                 ó.   — | j                   j                  S r#   ©rŸ   r€   ©rŽ   s    r(   Úget_input_embeddingsz!RemBertModel.get_input_embeddingsõ  s   € Ø�‰×.Ñ.Ð.r�   c                 ó&   — || j                   _        y r#   rn  )rŽ   rÂ   s     r(   Úset_input_embeddingsz!RemBertModel.set_input_embeddingsø  s   € Ø*/ˆ�‰Õ'r�   c                 ó˜   — |j                  «       D ]7  \  }}| j                  j                  |   j                  j	                  |«       Œ9 y)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)Úitemsri  r)  r  rü   )rŽ   Úheads_to_pruner)  rú   s       r(   Ú_prune_headszRemBertModel._prune_headsû  sE   € ð
 +×0Ñ0Ó2ò 	C‰LˆE�5Ø�L‰L×Ñ˜uÑ%×/Ñ/×;Ñ;¸EÕBñ	Cr�   úbatch_size, sequence_lengthr    ©Ú
checkpointÚoutput_typerb  r‘   rË   r’   rw   rÌ   r“   rÍ   rÎ   r,  r-  rÐ   r.  r/  r•   c                 ó  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }| j                   j                  r|
�|
n| j                   j
                  }
nd}
|�|�t        d«      ‚|�#| j                  ||«       |j                  «       }n!|�|j                  «       dd }nt        d«      ‚|\  }}|�|j                  n|j                  }|	�|	d   d   j                  d   nd}|€t        j                  |||z   f|¬«      }|€&t        j                  |t        j                  |¬	«      }| j                  ||«      }| j                   j                  rE|�C|j                  «       \  }}}||f}|€t        j                  ||¬«      }| j!                  |«      }nd}| j#                  || j                   j$                  «      }| j'                  |||||¬
«      }| j)                  ||||||	|
|||¬«
      }|d   }| j*                  �| j+                  |«      nd}|s
||f|dd z   S t-        |||j.                  |j0                  |j2                  |j4                  ¬«      S )a  
        encoder_hidden_states  (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
            the model is configured as a decoder.
        encoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
            the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.
        past_key_values (`tuple(tuple(torch.FloatTensor))` of length `config.n_layers` with each tuple having 4 tensors of shape `(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`):
            Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.
            If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
            don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_ids` of shape `(batch_size, sequence_length)`.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).
        NFzDYou cannot specify both input_ids and inputs_embeds at the same timerx   z5You have to specify either input_ids or inputs_embedsr   r>   )r™   r—   )r‘   rw   r’   r“   r”   )	rË   rÌ   rÍ   rÎ   r,  r-  rÐ   r.  r/  r   )r3  Úpooler_outputr,  r²   r4  r5  )rb   rÐ   r.  Úuse_return_dictrÄ   r-  r[   Ú%warn_if_padding_and_no_attention_maskrš   r™   rZ   r^   Úonesr›   rœ   Úget_extended_attention_maskÚinvert_attention_maskÚget_head_maskr(  rŸ   ri  rj  r   r,  r²   r4  r5  )rŽ   r‘   rË   r’   rw   rÌ   r“   rÍ   rÎ   r,  r-  rÐ   r.  r/  r�   Ú
batch_sizerž   r™   r”   Úextended_attention_maskÚencoder_batch_sizeÚencoder_sequence_lengthr+  Úencoder_hidden_shapeÚencoder_extended_attention_maskÚembedding_outputÚencoder_outputsrS  rµ   s                                r(   r    zRemBertModel.forward  sÍ  € ðR 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà�;‰;×!Ò!Ø%.Ð%:™	ÀÇÁ×@UÑ@U‰IàˆIàÐ  ]Ð%>ÜÐcÓdÐdØÐ"Ø×6Ñ6°yÀ.ÔQØ#Ÿ.™.Ó*‰KØÐ&Ø'×,Ñ,Ó.¨s°Ð3‰KäÐTÓUÐUà!,Ñˆ
�JØ%.Ð%:�×!Ò!À×@TÑ@Tˆð DSÐC^ °Ñ!3°AÑ!6×!<Ñ!<¸QÒ!?ÐdeÐàÐ!Ü"ŸZ™Z¨*°jÐCYÑ6YÐ)ZÐdjÔkˆNØÐ!Ü"Ÿ[™[¨¼E¿J¹JÈvÔVˆNð 15×0PÑ0PÐQ_ÐalÓ0mÐð �;‰;×!Ò!Ð&;Ð&GØ=R×=WÑ=WÓ=YÑ:ÐÐ 7¸Ø$6Ð8OÐ#PÐ Ø%Ð-Ü).¯©Ð4HÐQWÔ)XÐ&Ø.2×.HÑ.HÐI_Ó.`Ñ+à.2Ð+ð ×&Ñ& y°$·+±+×2OÑ2OÓPˆ	àŸ?™?ØØ%Ø)Ø'Ø#9ð +ó 
Ðð Ÿ,™,ØØ2ØØ"7Ø#BØ+ØØ/Ø!5Ø#ð 'ó 
ˆð *¨!Ñ,ˆØ8<¿¹Ð8O˜Ÿ™ OÔ4ÐUYˆáØ# ]Ð3°oÀaÀbÐ6IÑIÐIä;Ø-Ø'Ø+×;Ñ;Ø)×7Ñ7Ø&×1Ñ1Ø,×=Ñ=ô
ð 	
r�   )T)NNNNNNNNNNNNN)r¡   r¢   r£   r¤   r{   rp  rr  rv  r   ÚREMBERT_INPUTS_DOCSTRINGrV   r   r   Ú_CONFIG_FOR_DOCr   r^   r¥   r¦   r   rç   r   r   r    r¨   r©   s   @r(   rg  rg  Ø  s¥  ø„ ñ

õ
ò/ò0òCñ +Ð+C×+JÑ+JÐKhÓ+iÓjÙØ#Ø=Ø$ôð 15Ø59Ø59Ø37Ø15Ø59Ø=AØ>BØEIØ$(Ø,0Ø/3Ø&*ñy
à˜E×,Ñ,Ñ-ðy
ð ! ×!1Ñ!1Ñ2ðy
ð ! ×!1Ñ!1Ñ2ð	y
ð
 ˜u×/Ñ/Ñ0ðy
ð ˜E×-Ñ-Ñ.ðy
ð   × 1Ñ 1Ñ2ðy
ð  (¨×(9Ñ(9Ñ:ðy
ð !)¨×):Ñ):Ñ ;ðy
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðy
ð ˜D‘>ðy
ð $ D™>ðy
ð ' t™nðy
ð ˜d‘^ðy
ð 
ˆuÐBÐBÑ	Còy
óó kôy
r�   rg  z5RemBERT Model with a `language modeling` head on top.c                   óä  ‡ — e Zd ZdgZˆ fd„Zd„ Zd„ Z eej                  d«      «       e
dee¬«      	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     d	eej                     d
eej                     deej                     deej                      deej                      deej                      deej                      deej                     dee   dee   dee   deeef   fd„«       «       Zdd„Zˆ xZS )ÚRemBertForMaskedLMúcls.predictions.decoder.weightc                 óÊ   •— t         ‰| �  |«       |j                  rt        j	                  d«       t        |d¬«      | _        t        |«      | _        | j                  «        y )NznIf you want to use `RemBertForMaskedLM` make sure `config.is_decoder=False` for bi-directional self-attention.F©rl  ©
rz   r{   rÄ   rD   Úwarningrg  rX  rP  r-   rk  r�   s     €r(   r{   zRemBertForMaskedLM.__init__‰  sR   ø€ Ü‰Ñ˜Ô à×ÒÜ�N‰Nð1ôô
 $ F¸eÔDˆŒÜ% fÓ-ˆŒð 	�‰Õr�   c                 óB   — | j                   j                  j                  S r#   ©r-   rR  rM  ro  s    r(   Úget_output_embeddingsz(RemBertForMaskedLM.get_output_embeddings˜  ó   € Ø�x‰x×#Ñ#×+Ñ+Ð+r�   c                 ó:   — || j                   j                  _        y r#   r•  ©rŽ   Únew_embeddingss     r(   Úset_output_embeddingsz(RemBertForMaskedLM.set_output_embeddings›  ó   € Ø'5ˆ�‰×ÑÕ$r�   rw  r    rx  r‘   rË   r’   rw   rÌ   r“   rÍ   rÎ   ÚlabelsrÐ   r.  r/  r•   c                 óž  — |�|n| j                   j                  }| j                  |||||||||
||¬«      }|d   }| j                  |«      }d}|	�Ft	        «       } ||j                  d| j                   j                  «      |	j                  d«      «      }|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  ¬«      S )a£  
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
            config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
            loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
        N)
rË   r’   rw   rÌ   r“   rÍ   rÎ   rÐ   r.  r/  r   rx   r>   ©ÚlossÚlogitsr²   r4  )
rb   r}  rX  r-   r   rÆ   r}   r   r²   r4  )rŽ   r‘   rË   r’   rw   rÌ   r“   rÍ   rÎ   r�  rÐ   r.  r/  rå   rS  rU  Úmasked_lm_lossÚloss_fctrõ   s                      r(   r    zRemBertForMaskedLM.forwardž  s   € ð6 &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—,‘,ØØ)Ø)Ø%ØØ'Ø"7Ø#9Ø/Ø!5Ø#ð ó 
ˆð " !™*ˆØ ŸH™H _Ó5ÐàˆØÐÜ'Ó)ˆHÙ%Ð&7×&<Ñ&<¸RÀÇÁ×AWÑAWÓ&XÐZ`×ZeÑZeÐfhÓZiÓjˆNáØ'Ð)¨G°A°B¨KÑ7ˆFØ3AÐ3M�^Ð%¨Ñ.ÐYÐSYÐYäØØ$Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
r�   c                 ó–  — |j                   }|d   }| j                  j                  €J d«       ‚t        j                  ||j                  |j                   d   df«      gd¬«      }t        j                  |df| j                  j                  t        j                  |j                  ¬«      }t        j                  ||gd¬«      }||dœS )Nr   z.The PAD token should be defined for generationr   rx   rÒ   r—   )r‘   rË   )	rZ   rb   r   r^   rÕ   Ú	new_zerosÚfullrœ   r™   )rŽ   r‘   rË   Úmodel_kwargsr�   Úeffective_batch_sizeÚdummy_tokens          r(   Úprepare_inputs_for_generationz0RemBertForMaskedLM.prepare_inputs_for_generationÜ  s¹   € Ø—o‘oˆØ*¨1™~Ðð �{‰{×'Ñ'Ð3ÐeÐ5eÓeÐ3ÜŸ™ N°N×4LÑ4LÈn×NbÑNbÐcdÑNeÐghÐMiÓ4jÐ#kÐqsÔtˆÜ—j‘jØ! 1Ð% t§{¡{×'?Ñ'?ÄuÇzÁzÐZc×ZjÑZjô
ˆô —I‘I˜y¨+Ð6¸AÔ>ˆ	à&¸.ÑIÐIr�   )NNNNNNNNNNNNr#   )r¡   r¢   r£   Ú_tied_weights_keysr{   r–  r›  r   r‹  rV   r   r   rŒ  r   r^   r¥   r¦   rç   r   r   r    rª  r¨   r©   s   @r(   rŽ  rŽ  …  s~  ø„ à:Ð;Ðôò,ò6ñ +Ð+C×+JÑ+JÐKhÓ+iÓjÙØ#Ø"Ø$ôð 15Ø59Ø59Ø37Ø15Ø59Ø=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
ð ' t™nð6
ð ˜d‘^ð6
ð 
ˆu�nÐ$Ñ	%ò6
óó kð6
÷pJr�   rŽ  zIRemBERT Model with a `language modeling` head on top for CLM fine-tuning.c            #       ó  ‡ — e Zd ZdgZˆ fd„Zd„ Zd„ Z eej                  d«      «       e
ee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     d	eej                     d
eej                     deej                      deej                      deej                      deej                      deeeej                            deej                     dee   dee   dee   dee   deeef   fd„«       «       Zd„ Zˆ xZS )ÚRemBertForCausalLMr�  c                 óÊ   •— t         ‰| �  |«       |j                  st        j	                  d«       t        |d¬«      | _        t        |«      | _        | j                  «        y )NzOIf you want to use `RemBertForCausalLM` as a standalone, add `is_decoder=True.`Fr‘  r’  r�   s     €r(   r{   zRemBertForCausalLM.__init__ñ  sL   ø€ Ü‰Ñ˜Ô à× Ò Ü�N‰NÐlÔmä# F¸eÔDˆŒÜ% fÓ-ˆŒð 	�‰Õr�   c                 óB   — | j                   j                  j                  S r#   r•  ro  s    r(   r–  z(RemBertForCausalLM.get_output_embeddingsý  r—  r�   c                 ó:   — || j                   j                  _        y r#   r•  r™  s     r(   r›  z(RemBertForCausalLM.set_output_embeddings   rœ  r�   rw  )rz  rb  r‘   rË   r’   rw   rÌ   r“   rÍ   rÎ   r,  r�  r-  rÐ   r.  r/  r•   c                 ó–  — |�|n| j                   j                  }| j                  |||||||||	||||¬«      }|d   }| j                  |«      }d}|
�* | j                  ||
fd| j                   j
                  i|¤Ž}|s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  |j                  |j                  ¬«      S )a
  
        encoder_hidden_states  (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if
            the model is configured as a decoder.
        encoder_attention_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
            the cross-attention if the model is configured as a decoder. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.
        past_key_values (`tuple(tuple(torch.FloatTensor))` of length `config.n_layers` with each tuple having 4 tensors of shape `(batch_size, num_heads, sequence_length - 1, embed_size_per_head)`):
            Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.
            If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those that
            don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of all
            `decoder_input_ids` of shape `(batch_size, sequence_length)`.
        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]`.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).

        Returns:

        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’   rw   rÌ   r“   rÍ   rÎ   r,  r-  rÐ   r.  r/  r   r}   r>   )r   r¡  r,  r²   r4  r5  )rb   r}  rX  r-   Úloss_functionr}   r   r,  r²   r4  r5  )rŽ   r‘   rË   r’   rw   rÌ   r“   rÍ   rÎ   r,  r�  r-  rÐ   r.  r/  Úkwargsrå   rS  rU  Úlm_lossrõ   s                        r(   r    zRemBertForCausalLM.forward  s  € ðz &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—,‘,ØØ)Ø)Ø%ØØ'Ø"7Ø#9Ø+ØØ/Ø!5Ø#ð ó 
ˆð  " !™*ˆØ ŸH™H _Ó5ÐàˆØÐØ(�d×(Ñ(Ø!Øñð  Ÿ;™;×1Ñ1ðð ñ	ˆGñ Ø'Ð)¨G°A°B¨KÑ7ˆFØ,3Ð,?�W�J Ñ'ÐKÀVÐKä0ØØ$Ø#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø$×5Ñ5ô
ð 	
r�   c                 ó\   ‡— d}|D ]#  }|t        ˆfd„|d d D «       «      |dd  z   fz  }Œ% |S )Nr$   c              3   ót   •K  — | ]/  }|j                  d ‰j                  |j                  «      «      –— Œ1 y­w)r   N)Úindex_selectÚtor™   )r%   Ú
past_stateÚbeam_idxs     €r(   r)   z4RemBertForCausalLM._reorder_cache.<locals>.<genexpr>o  s.   øè ø€ ÒrÐU_�j×-Ñ-¨a°·±¸Z×=NÑ=NÓ1O×PÑrùs   ƒ58r>   )r;  )rŽ   r,  rº  Úreordered_pastÚ
layer_pasts     `  r(   Ú_reorder_cachez!RemBertForCausalLM._reorder_cachek  sT   ø€ ØˆØ)ò 	ˆJØÜÓrÐcmÐnpÐopÐcqÔrÓrØ˜Q˜R�.ñ!ðñ ‰Nð	ð
 Ðr�   )NNNNNNNNNNNNNN)r¡   r¢   r£   r«  r{   r–  r›  r   r‹  rV   r   r   rŒ  r   r^   r¥   r¦   r   rç   r   r    r½  r¨   r©   s   @r(   r­  r­  ë  sÀ  ø„ ð ;Ð;Ðô
ò,ò6ñ +Ð+C×+JÑ+JÐKhÓ+iÓjÙÐ+LÐ[jÔkð 15Ø59Ø59Ø37Ø15Ø59Ø=AØ>BØEIØ-1Ø$(Ø,0Ø/3Ø&*ñd
à˜E×,Ñ,Ñ-ðd
ð ! ×!1Ñ!1Ñ2ðd
ð ! ×!1Ñ!1Ñ2ð	d
ð
 ˜u×/Ñ/Ñ0ðd
ð ˜E×-Ñ-Ñ.ðd
ð   × 1Ñ 1Ñ2ðd
ð  (¨×(9Ñ(9Ñ:ðd
ð !)¨×):Ñ):Ñ ;ðd
ð " %¨¨e×.?Ñ.?Ñ(@Ñ"AÑBðd
ð ˜×)Ñ)Ñ*ðd
ð ˜D‘>ðd
ð $ D™>ðd
ð ' t™nðd
ð ˜d‘^ðd
ð" 
ˆuÐ7Ð7Ñ	8ò#d
ó ló kðd
öL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                   óŠ  ‡ — e Zd Zˆ fd„Z eej                  d«      «       edee	¬«      	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
e   de
e   de
e   deeef   fd„«       «       Zˆ xZS )Ú RemBertForSequenceClassificationc                 ó,  •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  «      | _        t        j                  |j                  |j                  «      | _        | j                  «        y r#   ©rz   r{   Ú
num_labelsrg  rX  r   r‡   Úclassifier_dropout_probr‰   r­   r®   r=   rk  r�   s     €r(   r{   z)RemBertForSequenceClassification.__init__}  si   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ# FÓ+ˆŒÜ—z‘z &×"@Ñ"@ÓAˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr�   rw  r    rx  r‘   rË   r’   rw   rÌ   r“   r�  rÐ   r.  r/  r•   c                 ó@  — |
�|
n| j                   j                  }
| j                  ||||||||	|
¬«	      }|d   }| j                  |«      }| j	                  |«      }d}|��‡| j                   j
                  €�| j                  dk(  rd| j                   _        nl| j                  dkD  rL|j                  t        j                  k(  s|j                  t        j                  k(  rd| j                   _        nd| j                   _        | j                   j
                  dk(  rIt        «       }| j                  dk(  r& ||j                  «       |j                  «       «      }nŒ |||«      }n‚| j                   j
                  dk(  r=t        «       } ||j                  d| j                  «      |j                  d«      «      }n,| j                   j
                  dk(  rt        «       } |||«      }|
s|f|dd z   }|�|f|z   S |S t!        |||j"                  |j$                  ¬	«      S )
a�  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        N©rË   r’   rw   rÌ   r“   rÐ   r.  r/  r   Ú
regressionÚsingle_label_classificationÚmulti_label_classificationrx   r>   rŸ  )rb   r}  rX  r‰   r=   Úproblem_typerÂ  r˜   r^   rœ   rX   r	   Úsqueezer   rÆ   r   r   r²   r4  )rŽ   r‘   rË   r’   rw   rÌ   r“   r�  rÐ   r.  r/  rå   rµ   r¡  r   r£  rõ   s                    r(   r    z(RemBertForSequenceClassification.forward‡  sè  € ð2 &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—,‘,ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#ð ó 

ˆð   ™
ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆàˆØÑØ�{‰{×'Ñ'Ð/Ø—?‘? aÒ'Ø/;�D—K‘KÕ,Ø—_‘_ qÒ(¨f¯l©l¼e¿j¹jÒ.HÈFÏLÉLÔ\a×\eÑ\eÒLeØ/L�D—K‘KÕ,à/K�D—K‘KÔ,à�{‰{×'Ñ'¨<Ò7Ü"›9�Ø—?‘? aÒ'Ù# F§N¡NÓ$4°f·n±nÓ6FÓG‘Dá# F¨FÓ3‘DØ—‘×)Ñ)Ð-JÒJÜ+Ó-�Ù §¡¨B°·±Ó @À&Ç+Á+ÈbÃ/ÓR‘Ø—‘×)Ñ)Ð-IÒIÜ,Ó.�Ù ¨Ó/�ÙØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä'ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r�   ©
NNNNNNNNNN)r¡   r¢   r£   r{   r   r‹  rV   r   r   rŒ  r   r^   r¦   r¥   rç   r   r   r    r¨   r©   s   @r(   r¿  r¿  u  sB  ø„ ôñ +Ð+C×+JÑ+JÐKhÓ+iÓjÙØ#Ø,Ø$ôð 26Ø6:Ø59Ø48Ø15Ø59Ø-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
ð ' t™nðE
ð ˜d‘^ðE
ð 
ˆuÐ.Ð.Ñ	/òE
óó kôE
r�   r¿  z¨
    RemBERT Model with a multiple choice classification head on top (a linear layer on top of the pooled output and a
    softmax) e.g. for RocStories/SWAG tasks.
    c                   óŠ  ‡ — e Zd Zˆ fd„Z eej                  d«      «       edee	¬«      	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
e   de
e   de
e   deeef   fd„«       «       Zˆ xZS )ÚRemBertForMultipleChoicec                 óö   •— t         ‰| �  |«       t        |«      | _        t	        j
                  |j                  «      | _        t	        j                  |j                  d«      | _
        | j                  «        y )Nr   )rz   r{   rg  rX  r   r‡   rÃ  r‰   r­   r®   r=   rk  r�   s     €r(   r{   z!RemBertForMultipleChoice.__init__Ý  sV   ø€ Ü‰Ñ˜Ô ä# FÓ+ˆŒÜ—z‘z &×"@Ñ"@ÓAˆŒÜŸ)™) F×$6Ñ$6¸Ó:ˆŒð 	�‰Õr�   z(batch_size, num_choices, sequence_lengthr    rx  r‘   rË   r’   rw   rÌ   r“   r�  rÐ   r.  r/  r•   c                 óL  — |
�|
n| j                   j                  }
|�|j                  d   n|j                  d   }|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|�!|j                  d|j	                  d«      «      nd}|�1|j                  d|j	                  d«      |j	                  d«      «      nd}| j                  ||||||||	|
¬«	      }|d   }| j                  |«      }| j                  |«      }|j                  d|«      }d}|�t        «       } |||«      }|
s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  ¬«      S )aJ  
        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   rx   rÔ   rÅ  r>   rŸ  )rb   r}  rZ   rÆ   rš   rX  r‰   r=   r   r   r²   r4  )rŽ   r‘   rË   r’   rw   rÌ   r“   r�  rÐ   r.  r/  Únum_choicesrå   rµ   r¡  Úreshaped_logitsr   r£  rõ   s                      r(   r    z RemBertForMultipleChoice.forwardç  sÝ  € ð2 &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆØ,5Ð,A�i—o‘o aÒ(À}×GZÑGZÐ[\ÑG]ˆà>GÐ>S�I—N‘N 2 y§~¡~°bÓ'9Ô:ÐY]ˆ	ØM[ÐMg˜×,Ñ,¨R°×1DÑ1DÀRÓ1HÔIÐmqˆØM[ÐMg˜×,Ñ,¨R°×1DÑ1DÀRÓ1HÔIÐmqˆØGSÐG_�|×(Ñ(¨¨\×->Ñ->¸rÓ-BÔCÐeiˆð Ð(ð ×Ñ˜r =×#5Ñ#5°bÓ#9¸=×;MÑ;MÈbÓ;QÔRàð 	ð —,‘,ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#ð ó 

ˆð   ™
ˆàŸ™ ]Ó3ˆØ—‘ Ó/ˆØ Ÿ+™+ b¨+Ó6ˆàˆØÐÜ'Ó)ˆHÙ˜O¨VÓ4ˆDáØ%Ð'¨'°!°"¨+Ñ5ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä(ØØ"Ø!×/Ñ/Ø×)Ñ)ô	
ð 	
r�   rË  )r¡   r¢   r£   r{   r   r‹  rV   r   r   rŒ  r   r^   r¦   r¥   rç   r   r   r    r¨   r©   s   @r(   rÍ  rÍ  Õ  sB  ø„ ôñ +Ð+C×+JÑ+JÐKuÓ+vÓwÙØ#Ø-Ø$ôð 26Ø6:Ø59Ø48Ø15Ø59Ø-1Ø,0Ø/3Ø&*ñ@
à˜E×-Ñ-Ñ.ð@
ð ! ×!2Ñ!2Ñ3ð@
ð ! ×!1Ñ!1Ñ2ð	@
ð
 ˜u×0Ñ0Ñ1ð@
ð ˜E×-Ñ-Ñ.ð@
ð   × 1Ñ 1Ñ2ð@
ð ˜×)Ñ)Ñ*ð@
ð $ D™>ð@
ð ' t™nð@
ð ˜d‘^ð@
ð 
ˆuÐ/Ð/Ñ	0ò@
óó xô@
r�   rÍ  z¦
    RemBERT Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g. for
    Named-Entity-Recognition (NER) tasks.
    c                   óŠ  ‡ — e Zd Zˆ fd„Z eej                  d«      «       edee	¬«      	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
e   de
e   de
e   deeef   fd„«       «       Zˆ xZS )ÚRemBertForTokenClassificationc                 ó0  •— t         ‰| �  |«       |j                  | _        t        |d¬«      | _        t        j                  |j                  «      | _        t        j                  |j                  |j                  «      | _        | j                  «        y ©NFr‘  rÁ  r�   s     €r(   r{   z&RemBertForTokenClassification.__init__8  sk   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒä# F¸eÔDˆŒÜ—z‘z &×"@Ñ"@ÓAˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr�   rw  r    rx  r‘   rË   r’   rw   rÌ   r“   r�  rÐ   r.  r/  r•   c                 ó¨  — |
�|
n| j                   j                  }
| j                  ||||||||	|
¬«	      }|d   }| j                  |«      }| j	                  |«      }d}|�<t        «       } ||j                  d| j                  «      |j                  d«      «      }|
s|f|dd z   }|�|f|z   S |S t        |||j                  |j                  ¬«      S )zÛ
        labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
        NrÅ  r   rx   r>   rŸ  )rb   r}  rX  r‰   r=   r   rÆ   rÂ  r   r²   r4  )rŽ   r‘   rË   r’   rw   rÌ   r“   r�  rÐ   r.  r/  rå   rS  r¡  r   r£  rõ   s                    r(   r    z%RemBertForTokenClassification.forwardC  sö   € ð. &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—,‘,ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#ð ó 

ˆð " !™*ˆàŸ,™, Ó7ˆØ—‘ Ó1ˆàˆØÐÜ'Ó)ˆHÙ˜FŸK™K¨¨D¯O©OÓ<¸f¿k¹kÈ"»oÓNˆDáØ�Y ¨¨ Ñ,ˆFØ)-Ð)9�T�G˜fÑ$ÐE¸vÐEä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r�   rË  )r¡   r¢   r£   r{   r   r‹  rV   r   r   rŒ  r   r^   r¦   r¥   rç   r   r   r    r¨   r©   s   @r(   rÓ  rÓ  0  s5  ø„ ô	ñ +Ð+C×+JÑ+JÐKhÓ+iÓjÙØ#Ø)Ø$ôð 26Ø6:Ø59Ø48Ø15Ø59Ø-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
ð ' t™nð2
ð ˜d‘^ð2
ð 
ˆuÐ+Ð+Ñ	,ò2
óó kô2
r�   rÓ  zà
    RemBERT Model with a span classification head on top for extractive question-answering tasks like SQuAD (a linear
    layers on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c                   óª  ‡ — e Zd Zˆ fd„Z eej                  d«      «       edee	¬«      	 	 	 	 	 	 	 	 	 	 	 dde
ej                     de
ej                     de
ej                     de
ej                     d	e
ej                     d
e
ej                     de
ej                     de
ej                     de
e   de
e   de
e   deeef   fd„«       «       Zˆ xZS )ÚRemBertForQuestionAnsweringc                 óè   •— t         ‰| �  |«       |j                  | _        t        |d¬«      | _        t        j                  |j                  |j                  «      | _        | j                  «        y rÕ  )
rz   r{   rÂ  rg  rX  r   r­   r®   Ú
qa_outputsrk  r�   s     €r(   r{   z$RemBertForQuestionAnswering.__init__†  sU   ø€ Ü‰Ñ˜Ô à ×+Ñ+ˆŒä# F¸eÔDˆŒÜŸ)™) F×$6Ñ$6¸×8IÑ8IÓJˆŒð 	�‰Õr�   rw  r    rx  r‘   rË   r’   rw   rÌ   r“   Ústart_positionsÚend_positionsrÐ   r.  r/  r•   c                 óð  — |�|n| j                   j                  }| j                  |||||||	|
|¬«	      }|d   }| j                  |«      }|j	                  dd¬«      \  }}|j                  d«      }|j                  d«      }d}|�·|�µt        |j                  «       «      dkD  r|j                  d«      }t        |j                  «       «      dkD  r|j                  d«      }|j                  d«      }|j                  d|«       |j                  d|«       t        |¬«      } |||«      } |||«      }||z   dz  }|s||f|dd z   }|�|f|z   S |S t        ||||j                  |j                  ¬	«      S )
a  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        NrÅ  r   r   rx   rÒ   )Úignore_indexr>   )r   Ústart_logitsÚ
end_logitsr²   r4  )rb   r}  rX  rÚ  rQ   rÊ  rW   rš   Úclamp_r   r   r²   r4  )rŽ   r‘   rË   r’   rw   rÌ   r“   rÛ  rÜ  rÐ   r.  r/  rå   rS  r¡  rß  rà  Ú
total_lossÚignored_indexr£  Ú
start_lossÚend_lossrõ   s                          r(   r    z#RemBertForQuestionAnswering.forward‘  s¬  € ð< &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆà—,‘,ØØ)Ø)Ø%ØØ'Ø/Ø!5Ø#ð ó 

ˆð " !™*ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ó#:Ñ ˆ�jØ#×+Ñ+¨BÓ/ˆØ×'Ñ'¨Ó+ˆ
àˆ
ØÐ&¨=Ð+Dä�?×'Ñ'Ó)Ó*¨QÒ.Ø"1×"9Ñ"9¸"Ó"=�Ü�=×%Ñ%Ó'Ó(¨1Ò,Ø -× 5Ñ 5°bÓ 9�à(×-Ñ-¨aÓ0ˆMØ×"Ñ" 1 mÔ4Ø× Ñ   MÔ2ä'°]ÔCˆHÙ! ,°Ó@ˆJÙ 
¨MÓ:ˆHØ$ xÑ/°1Ñ4ˆJáØ" JÐ/°'¸!¸"°+Ñ=ˆFØ/9Ð/E�Z�M FÑ*ÐQÈ6ÐQä+ØØ%Ø!Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r�   )NNNNNNNNNNN)r¡   r¢   r£   r{   r   r‹  rV   r   r   rŒ  r   r^   r¦   r¥   rç   r   r   r    r¨   r©   s   @r(   rØ  rØ  ~  s[  ø„ ô	ñ +Ð+C×+JÑ+JÐKhÓ+iÓjÙØ#Ø0Ø$ôð 26Ø6:Ø59Ø48Ø15Ø59Ø6:Ø48Ø,0Ø/3Ø&*ñH
à˜E×-Ñ-Ñ.ðH
ð ! ×!2Ñ!2Ñ3ðH
ð ! ×!1Ñ!1Ñ2ð	H
ð
 ˜u×0Ñ0Ñ1ðH
ð ˜E×-Ñ-Ñ.ðH
ð   × 1Ñ 1Ñ2ðH
ð " %×"2Ñ"2Ñ3ðH
ð   × 0Ñ 0Ñ1ðH
ð $ D™>ðH
ð ' t™nðH
ð ˜d‘^ðH
ð 
ˆuÐ2Ð2Ñ	3òH
óó kôH
r�   rØ  )
r­  rŽ  rÍ  rØ  r¿  rÓ  r  rg  rW  rp   )Gr¤   r×   rF   Útypingr   r   r   r^   Útorch.utils.checkpointr   Útorch.nnr   r   r	   Úactivationsr   Ú
generationr   Úmodeling_outputsr   r   r   r   r   r   r   r   Úmodeling_utilsr   Úpytorch_utilsr   r   r   Úutilsr   r   r   r   r   Úconfiguration_rembertr   Ú
get_loggerr¡   rD   rŒ  Ú_CHECKPOINT_FOR_DOCrp   ÚModulerr   r«   r¸   ré   ró   r  r  r  r#  rE  rJ  rP  rW  ÚREMBERT_START_DOCSTRINGr‹  rg  rŽ  r­  r¿  rÍ  rÓ  rØ  Ú__all__r$   r�   r(   ú<module>rõ     sª  ðñ ã Û 	ß )Ñ )ã Û Ý ß AÑ Aå !Ý )÷	÷ 	ó 	õ .ß lÑ l÷õ õ 1ð 
ˆ×	Ñ	˜HÓ	%€à!€Ø&Ð òPôf3˜Ÿ	™	ô 3ôn�B—I‘Iô ôf˜2Ÿ9™9ô fôT˜Ÿ	™	ô ô0�r—y‘yô 0ôh˜"Ÿ)™)ô ô �B—I‘Iô ôU�2—9‘9ô Uôp\
�R—Y‘Yô \
ô@ R§Y¡Yô ô"˜bŸi™iô ô"!˜Ÿ™ô !ô*˜_ô *ð8	Ð ð/Ð ñd ØgØóôf
Ð)ó f
ó	ðf
ñR ÐQÐSjÓkôbJÐ/ó bJó lðbJñJ ØSÐUlóôDÐ/°ó DóðDñN ðð óôV
Ð'=ó V
óðV
ñr ðð óôQ
Ð5ó Q
óðQ
ñh ðð óôD
Ð$:ó D
óðD
ñN ðð óôZ
Ð"8ó Z
óðZ
òz�r�   