
    fTh                     J   S r SSKrSSKrSSKJrJrJr  SSKrSSKJ	r	  SSK
J	s  Jr  SSKrSSKJrJrJr  SSKJr  SSKJrJrJrJr  SSKJr  SS	KJr  SS
KJrJrJr  SSK J!r!  \RD                  " \#5      r$ " S S\	RJ                  5      r& " S S\	RJ                  5      r'\ " S S\5      5       r( " S S\	RJ                  5      r) " S S\	RJ                  5      r* " S S\	RJ                  5      r+ " S S\	RJ                  5      r, " S S\	RJ                  5      r- " S S\	RJ                  5      r. " S S \	RJ                  5      r/\ " S! S"\(5      5       r0 " S# S$\	RJ                  5      r1\" S%S&9 " S' S(\(5      5       r2\ " S) S*\(5      5       r3\" S+S&9 " S, S-\(5      5       r4/ S.Qr5g)/zPyTorch LayoutLMv3 model.    N)OptionalTupleUnion)BCEWithLogitsLossCrossEntropyLossMSELoss   )ACT2FN)BaseModelOutputQuestionAnsweringModelOutputSequenceClassifierOutputTokenClassifierOutput)PreTrainedModel)apply_chunking_to_forward)auto_docstringlogging	torch_int   )LayoutLMv3Configc                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )LayoutLMv3PatchEmbeddings/   zLayoutLMv3 image (patch) embeddings. This class also automatically interpolates the position embeddings for varying
image sizes.c                   > [         TU ]  5         [        UR                  [        R
                  R                  5      (       a  UR                  OUR                  UR                  4n[        UR                  [        R
                  R                  5      (       a  UR                  OUR                  UR                  4nUS   US   -  US   US   -  4U l        [        R                  " UR                  UR                  X3S9U l        g )Nr   r   )kernel_sizestride)super__init__
isinstance
input_sizecollectionsabcIterable
patch_sizepatch_shapennConv2dnum_channelshidden_sizeproj)selfconfig
image_sizer#   	__class__s       j/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/layoutlmv3/modeling_layoutlmv3.pyr   "LayoutLMv3PatchEmbeddings.__init__3   s     &++[__-E-EFF ##V%6%67 	 &++[__-E-EFF ##V%6%67 	
 'qMZ]:JqMZXY]<Z[IIf1163E3ES]q	    c                 d   U R                  U5      nUbz  UR                  SU R                  S   U R                  S   S5      nUR                  SSSS5      nUR                  S   UR                  S   pT[
        R                  " X$U4SS9nX2-   nUR                  S5      R                  SS5      nU$ )Nr   r   r	      bicubic)sizemode)	r)   viewr$   permuteshapeFinterpolateflatten	transpose)r*   pixel_valuesposition_embedding
embeddingspatch_heightpatch_widths         r.   forward!LayoutLMv3PatchEmbeddings.forwardC   s    YY|,
)!3!8!8D<L<LQ<OQUQaQabcQdfh!i!3!;!;Aq!Q!G(2(8(8(;Z=M=Ma=P+!"/AWbHcjs!t#8J''*44Q:
r0   )r$   r)   N	__name__
__module____qualname____firstlineno____doc__r   rC   __static_attributes____classcell__r-   s   @r.   r   r   /   s    r  r0   r   c                   R   ^  \ rS rSrSrU 4S jrS rS rS r     S	S jr	Sr
U =r$ )
LayoutLMv3TextEmbeddingsR   ze
LayoutLMv3 text embeddings. Same as `RobertaEmbeddings` but with added spatial (layout) embeddings.
c                 *  > [         TU ]  5         [        R                  " UR                  UR
                  UR                  S9U l        [        R                  " UR                  UR
                  5      U l	        [        R                  " UR
                  UR                  S9U l
        [        R                  " UR                  5      U l        U R                  S[         R"                  " UR$                  5      R'                  S5      SS9  UR                  U l        [        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R4                  5      U l        [        R                  " UR,                  UR4                  5      U l        g )N)padding_idxepsposition_ids)r   r2   F)
persistent)r   r   r%   	Embedding
vocab_sizer(   pad_token_idword_embeddingstype_vocab_sizetoken_type_embeddings	LayerNormlayer_norm_epsDropouthidden_dropout_probdropoutregister_buffertorcharangemax_position_embeddingsexpandrS   position_embeddingsmax_2d_position_embeddingscoordinate_sizex_position_embeddingsy_position_embeddings
shape_sizeh_position_embeddingsw_position_embeddingsr*   r+   r-   s     r.   r   !LayoutLMv3TextEmbeddings.__init__W   s}   !||F,=,=v?Q?Q_e_r_rs%'\\&2H2H&J\J\%]"f&8&8f>S>STzz&"<"<= 	ELL)G)GHOOPWXej 	 	
 "..#%<<**F,>,>DL\L\$
  &(\\&2S2SU[UkUk%l"%'\\&2S2SU[UkUk%l"%'\\&2S2SU[UfUf%g"%'\\&2S2SU[UfUf%g"r0   c           	      J    U R                  US S 2S S 2S4   5      nU R                  US S 2S S 2S4   5      nU R                  US S 2S S 2S4   5      nU R                  US S 2S S 2S4   5      nU R                  [        R
                  " US S 2S S 2S4   US S 2S S 2S4   -
  SS5      5      nU R                  [        R
                  " US S 2S S 2S4   US S 2S S 2S4   -
  SS5      5      n[        R                  " UUUUUU/SS9n	U	$ ! [         a  n[        S5      UeS nAff = f)	Nr   r   r3   r	   z;The `bbox` coordinate values should be within 0-1000 range.i  r2   dim)rk   rl   
IndexErrorrn   rd   clipro   cat)
r*   bboxleft_position_embeddingsupper_position_embeddingsright_position_embeddingslower_position_embeddingsern   ro   spatial_position_embeddingss
             r.   %calculate_spatial_position_embeddings>LayoutLMv3TextEmbeddings.calculate_spatial_position_embeddingsn   sN   	c'+'A'A$q!Qw-'P$(,(B(B41a=(Q%(,(B(B41a=(Q%(,(B(B41a=(Q% !% : :5::d1aQR7mVZ[\^_ab[bVcFcefhl;m n $ : :5::d1aQR7mVZ[\^_ab[bVcFcefhl;m n ',ii()))%% 
'
# +*%  	cZ[abb	cs   A,D 
D"DD"c                     UR                  U5      R                  5       n[        R                  " USS9R	                  U5      U-  nUR                  5       U-   $ )z
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding
symbols are ignored. This is modified from fairseq's `utils.make_positions`.
r   rs   )neintrd   cumsumtype_aslong)r*   	input_idsrS   maskincremental_indicess        r.   "create_position_ids_from_input_ids;LayoutLMv3TextEmbeddings.create_position_ids_from_input_ids   sP     ||K(,,.$||Da8@@F$N"'')K77r0   c                    UR                  5       SS nUS   n[        R                  " U R                  S-   X0R                  -   S-   [        R                  UR
                  S9nUR                  S5      R                  U5      $ )zq
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.
Nr2   r   dtypedevicer   )r5   rd   re   rS   r   r   	unsqueezerg   )r*   inputs_embedsinput_shapesequence_lengthrV   s        r.   &create_position_ids_from_inputs_embeds?LayoutLMv3TextEmbeddings.create_position_ids_from_inputs_embeds   s~     $((*3B/%a.||q /4D4D"Dq"HPUPZPZcpcwcw
 %%a(//<<r0   c                 L   UcI  Ub5  U R                  XR                  5      R                  UR                  5      nOU R	                  U5      nUb  UR                  5       nOUR                  5       S S nUc8  [        R                  " U[        R                  U R                  R                  S9nUc  U R                  U5      nU R                  U5      nXW-   nU R                  U5      n	X-  nU R                  U5      n
X-   nU R                  U5      nU R                  U5      nU$ )Nr2   r   )r   rS   tor   r   r5   rd   zerosr   rV   r[   r]   rh   r   r^   rb   )r*   r   rx   token_type_idsrV   r   r   r]   r@   rh   r~   s              r.   rC    LayoutLMv3TextEmbeddings.forward   s    $#FFyRbRbcff$$   $JJ=Y #..*K',,.s3K!"[[EJJtO`O`OgOghN  00;M $ : :> J":
"66|D)
&*&P&PQU&V#=
^^J/
\\*-
r0   )
r^   rb   rn   rS   rh   r]   ro   r[   rk   rl   )NNNNN)rG   rH   rI   rJ   rK   r   r   r   r   rC   rL   rM   rN   s   @r.   rP   rP   R   s8    h.+48
= ' 'r0   rP   c                   "    \ rS rSr\rSrS rSrg)LayoutLMv3PreTrainedModel   
layoutlmv3c                 ,   [        U[        R                  [        R                  45      (       ak  UR                  R
                  R                  SU R                  R                  S9  UR                  b%  UR                  R
                  R                  5         gg[        U[        R                  5      (       ax  UR                  R
                  R                  SU R                  R                  S9  UR                  b2  UR                  R
                  UR                     R                  5         gg[        U[        R                  5      (       aJ  UR                  R
                  R                  5         UR                  R
                  R                  S5        g[        U[        5      (       ae  U R                  R                   (       aI  UR"                  R
                  R                  5         UR$                  R
                  R                  5         ggg)zInitialize the weights        )meanstdNg      ?)r   r%   Linearr&   weightdatanormal_r+   initializer_rangebiaszero_rX   rS   r^   fill_LayoutLMv3Modelvisual_embed	cls_token	pos_embed)r*   modules     r.   _init_weights'LayoutLMv3PreTrainedModel._init_weights   sg   fryy"))455 MM&&CT[[5R5R&S{{&  &&( '--MM&&CT[[5R5R&S!!-""6#5#56<<> .--KK""$MM$$S)00{{''  %%++-  %%++- ( 1r0    N)	rG   rH   rI   rJ   r   config_classbase_model_prefixr   rL   r   r0   r.   r   r      s    #L$.r0   r   c                   L   ^  \ rS rSrU 4S jrS rSS jr     SS jrSrU =r	$ )	LayoutLMv3SelfAttention   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        UR$                  U l        g )Nr   embedding_sizezThe hidden size (z6) is not a multiple of the number of attention heads ())r   r   r(   num_attention_headshasattr
ValueErrorr   attention_head_sizeall_head_sizer%   r   querykeyvaluer`   attention_probs_dropout_probrb   has_relative_attention_biashas_spatial_attention_biasrp   s     r.   r    LayoutLMv3SelfAttention.__init__   s;    : ::a?PVXhHiHi#F$6$6#7 8 445Q8 
 $*#=#= #&v'9'9F<V<V'V#W !558P8PPYYv1143E3EF
99V//1C1CDYYv1143E3EF
zz&"E"EF+1+M+M(*0*K*K'r0   c                     UR                  5       S S U R                  U R                  4-   nUR                  " U6 nUR	                  SSSS5      $ )Nr2   r   r3   r   r	   )r5   r   r   r7   r8   )r*   xnew_x_shapes      r.   transpose_for_scores,LayoutLMv3SelfAttention.transpose_for_scores   sL    ffhsmt'?'?AYAY&ZZFFK yyAq!$$r0   c                     X-  nUR                  SS9R                  S5      nX4-
  U-  n[        R                  " SS9" U5      $ )a  
https://arxiv.org/abs/2105.13290 Section 2.4 Stabilization of training: Precision Bottleneck Relaxation
(PB-Relax). A replacement of the original nn.Softmax(dim=-1)(attention_scores). Seems the new attention_probs
will result in a slower speed and a little bias. Can use torch.allclose(standard_attention_probs,
cogview_attention_probs, atol=1e-08) for comparison. The smaller atol (e.g., 1e-08), the better.
r2   rs   )amaxr   r%   Softmax)r*   attention_scoresalphascaled_attention_scores	max_valuenew_attention_scoress         r.   cogview_attention)LayoutLMv3SelfAttention.cogview_attention   sN     #3":+00b0:DDRH	 7 CuLzzb!"677r0   c                    U R                  U5      nU R                  U R                  U5      5      nU R                  U R                  U5      5      n	U R                  U5      n
[        R
                  " U
[        R                  " U R                  5      -  UR                  SS5      5      nU R                  (       a:  U R                  (       a)  XU-   [        R                  " U R                  5      -  -  nO6U R                  (       a%  X[        R                  " U R                  5      -  -  nUb  X-   nU R                  U5      nU R                  U5      nUb  X-  n[        R
                  " X5      nUR                  SSSS5      R                  5       nUR!                  5       S S U R"                  4-   nUR$                  " U6 nU(       a  X4nU$ U4nU$ )Nr2   r   r3   r   r	   )r   r   r   r   rd   matmulmathsqrtr   r=   r   r   r   rb   r8   
contiguousr5   r   r7   )r*   hidden_statesattention_mask	head_maskoutput_attentionsrel_pos
rel_2d_posmixed_query_layer	key_layervalue_layerquery_layerr   attention_probscontext_layernew_context_layer_shapeoutputss                   r.   rC   LayoutLMv3SelfAttention.forward  s    !JJ}5--dhh}.EF	//

=0IJ//0AB
 !<<dii@X@X6Y(Y[d[n[noqsu[vw++0O0O:!54C[C[9\ \\--$))D4L4L*M MM%/@ 001AB ,,7  -9O_B%--aAq9DDF"/"4"4"6s";t?Q?Q>S"S%**,CD6G=2 O\M]r0   )	r   r   rb   r   r   r   r   r   r   )    NNFNN)
rG   rH   rI   rJ   r   r   r   rC   rL   rM   rN   s   @r.   r   r      s.    L(%

8 1 1r0   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	$ )LayoutLMv3SelfOutputi=  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   )r   r   r%   r   r(   denser^   r_   r`   ra   rb   rp   s     r.   r   LayoutLMv3SelfOutput.__init__>  s`    YYv1163E3EF
f&8&8f>S>STzz&"<"<=r0   r   input_tensorreturnc                 p    U R                  U5      nU R                  U5      nU R                  X-   5      nU$ rE   r   rb   r^   r*   r   r   s      r.   rC   LayoutLMv3SelfOutput.forwardD  5    

=1]3}'CDr0   r^   r   rb   
rG   rH   rI   rJ   r   rd   TensorrC   rL   rM   rN   s   @r.   r   r   =  6    >U\\  RWR^R^  r0   r   c                   <   ^  \ rS rSrU 4S jr     SS jrSrU =r$ )LayoutLMv3AttentioniL  c                 b   > [         TU ]  5         [        U5      U l        [	        U5      U l        g rE   )r   r   r   r*   r   outputrp   s     r.   r   LayoutLMv3Attention.__init__M  s&    +F3	*62r0   c           	      j    U R                  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   self_outputsattention_outputr   s
             r.   rC   LayoutLMv3Attention.forwardR  sY     yy! ! 
  ;;|AF#%QR(88r0   )r  r*   r   )rG   rH   rI   rJ   r   rC   rL   rM   rN   s   @r.   r   r   L  s#    3  r0   r   c                   B   ^  \ rS rSrU 4S jr     SS jrS rSrU =r$ )LayoutLMv3Layerii  c                    > [         TU ]  5         UR                  U l        SU l        [	        U5      U l        [        U5      U l        [        U5      U l	        g Nr   )
r   r   chunk_size_feed_forwardseq_len_dimr   	attentionLayoutLMv3IntermediateintermediateLayoutLMv3Outputr  rp   s     r.   r   LayoutLMv3Layer.__init__j  sI    '-'E'E$,V426:&v.r0   c           	          U R                  UUUUUUS9nUS   nUSS  n	[        U R                  U R                  U R                  U5      n
U
4U	-   n	U	$ )N)r   r   r   r   r   )r  r   feed_forward_chunkr  r  )r*   r   r   r   r   r   r   self_attention_outputsr  r   layer_outputs              r.   rC   LayoutLMv3Layer.forwardr  s|     "&/! "0 "
 2!4(,0##T%A%A4CSCSUe
  /G+r0   c                 J    U R                  U5      nU R                  X!5      nU$ rE   )r  r  )r*   r  intermediate_outputr  s       r.   r  "LayoutLMv3Layer.feed_forward_chunk  s)    "//0@A{{#6Ir0   )r  r  r  r  r  r   )	rG   rH   rI   rJ   r   rC   r  rL   rM   rN   s   @r.   r	  r	  i  s(    / 8 r0   r	  c                   Z   ^  \ rS rSrU 4S jrSS jrS rS r         S	S jrSr	U =r
$ )
LayoutLMv3Encoderi  c                   > [         TU ]  5         Xl        [        R                  " [        UR                  5       Vs/ s H  n[        U5      PM     sn5      U l        SU l	        UR                  U l
        UR                  U l        U R                  (       aQ  UR                  U l        UR                  U l        [        R                  " U R                  UR                  SS9U l        U R                  (       a  UR"                  U l        UR$                  U l        [        R                  " U R$                  UR                  SS9U l        [        R                  " U R$                  UR                  SS9U l        g g s  snf )NF)r   )r   r   r+   r%   
ModuleListrangenum_hidden_layersr	  layergradient_checkpointingr   r   rel_pos_binsmax_rel_posr   r   rel_pos_biasmax_rel_2d_posrel_2d_pos_binsrel_pos_x_biasrel_pos_y_bias)r*   r+   _r-   s      r.   r   LayoutLMv3Encoder.__init__  s#   ]]U6KcKcEd#eEdOF$;Ed#ef
&+#+1+M+M(*0*K*K'++ & 3 3D%11D "		$*;*;V=W=W^c dD**"("7"7D#)#9#9D "$))D,@,@&B\B\ch"iD"$))D,@,@&B\B\ch"iD	 + $fs   E<c                 D   SnU(       a4  US-  nXQS:  R                  5       U-  -  n[        R                  " U5      nO,[        R                  " U* [        R                  " U5      5      nUS-  nXg:  nU[        R
                  " UR                  5       U-  5      [        R
                  " XG-  5      -  X7-
  -  R                  [        R                   5      -   n	[        R                  " U	[        R                  " XS-
  5      5      n	U[        R                  " XU	5      -  nU$ )Nr   r3   r   )r   rd   absmax
zeros_likelogfloatr   r   min	full_likewhere)
r*   relative_positionbidirectionalnum_bucketsmax_distanceretn	max_exactis_smallval_if_larges
             r.   relative_position_bucket*LayoutLMv3Encoder.relative_position_bucket  s    AK)//1K??C		+,A		,,e.>.>?P.QRA  1$	= !IIaggi)+,txx8P/QQU`Ulm
"UZZ. yyu|[\_/]^u{{855
r0   c                    UR                  S5      UR                  S5      -
  nU R                  UU R                  U R                  S9n[        R
                  " 5          U R                  R                  R                  5       U   R                  SSSS5      nS S S 5        UR                  5       nU$ ! , (       d  f       N = f)Nr   r2   r7  r8  r   r	   r   r3   )r   r>  r#  r$  rd   no_gradr%  r   tr8   r   )r*   rV   rel_pos_matr   s       r.   _cal_1d_pos_emb!LayoutLMv3Encoder._cal_1d_pos_emb  s    ",,R0<3I3I"3MM//)))) 0 
 ]]_''..0027;CCAq!QOG $$& _s   :B22
C c                    US S 2S S 2S4   nUS S 2S S 2S4   nUR                  S5      UR                  S5      -
  nUR                  S5      UR                  S5      -
  nU R                  UU R                  U R                  S9nU R                  UU R                  U R                  S9n[        R
                  " 5          U R                  R                  R                  5       U   R                  SSSS5      nU R                  R                  R                  5       U   R                  SSSS5      nS S S 5        UR                  5       nUR                  5       nXg-   nU$ ! , (       d  f       N4= f)Nr   r	   r   r2   rA  r   r3   )r   r>  r'  r&  rd   rB  r(  r   rC  r8   r)  r   )	r*   rx   position_coord_xposition_coord_yrel_pos_x_2d_matrel_pos_y_2d_mat	rel_pos_x	rel_pos_yr   s	            r.   _cal_2d_pos_emb!LayoutLMv3Encoder._cal_2d_pos_emb  sf   1a=1a=+55b9<L<V<VWY<ZZ+55b9<L<V<VWY<ZZ11,,,, 2 
	
 11,,,, 2 
	 ]]_++22446yAII!QPQSTUI++22446yAII!QPQSTUI  ((*	((*	*
 _s   >A3E
E-c           
      X   U(       a  SOS nU(       a  SOS nU R                   (       a  U R                  U5      OS nU R                  (       a  U R                  U5      OS n[	        U R
                  5       H  u  nnU(       a  X4-   nUb  XO   OS nU R                  (       a3  U R                  (       a"  U R                  UR                  UUUUUU5      nOU" UUUUUUS9nUS   nU(       d  Mx  UUS   4-   nM     U(       a  X4-   nU(       d  [        S UUU4 5       5      $ [        UUUS9$ )Nr   r  r   r   c              3   0   #    U  H  nUc  M  Uv   M     g 7frE   r   ).0vs     r.   	<genexpr>,LayoutLMv3Encoder.forward.<locals>.<genexpr>!  s"      A
  s   	last_hidden_stater   
attentions)r   rE  r   rN  	enumerater!  r"  training_gradient_checkpointing_func__call__tupler   )r*   r   rx   r   r   r   output_hidden_statesreturn_dictrV   rA   rB   all_hidden_statesall_self_attentionsr   r   ilayer_modulelayer_head_masklayer_outputss                      r.   rC   LayoutLMv3Encoder.forward  sR    #7BD$5b48<8X8X$&&|4^b373R3RT))$/X\
(4OA|#$58H$H!.7.CilO**t}} $ A A ))!"#%! !-!"#%#)! *!,M  &9]1=M<O&O#9  5<   14D D  "%'   ++*
 	
r0   )r+   r"  r   r   r!  r&  r$  r'  r%  r#  r(  r)  )Tr      )	NNNFFTNNN)rG   rH   rI   rJ   r   r>  rE  rN  rC   rL   rM   rN   s   @r.   r  r    sA    j(."< "B
 B
r0   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	$ )r  i2  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 rE   )r   r   r%   r   r(   intermediate_sizer   r   
hidden_actstrr
   intermediate_act_fnrp   s     r.   r   LayoutLMv3Intermediate.__init__3  s`    YYv1163K3KL
f''--'-f.?.?'@D$'-'8'8D$r0   r   r   c                 J    U R                  U5      nU R                  U5      nU$ rE   r   rm  )r*   r   s     r.   rC   LayoutLMv3Intermediate.forward;  s&    

=100?r0   rp  r   rN   s   @r.   r  r  2  s(    9U\\ ell  r0   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	$ )r  iB  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   )r   r   r%   r   rj  r(   r   r^   r_   r`   ra   rb   rp   s     r.   r   LayoutLMv3Output.__init__C  s`    YYv779K9KL
f&8&8f>S>STzz&"<"<=r0   r   r   r   c                 p    U R                  U5      nU R                  U5      nU R                  X-   5      nU$ rE   r   r   s      r.   rC   LayoutLMv3Output.forwardI  r   r0   r   r   rN   s   @r.   r  r  B  r   r0   r  c                     ^  \ rS rSrU 4S jrS rS rS rS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\\   S\\   S\\   S\\\4   4S jj5       rSrU =r$ )r   iP  c                   > [         TU ]  U5        Xl        UR                  (       a  [	        U5      U l        UR                  (       Ga  [        U5      U l        [        UR                  UR                  -  5      n[        R                  " [        R                  " SSUR                   5      5      U l        [        R                  " [        R                  " SX"-  S-   UR                   5      5      U l        [        R&                  " SS9U l        [        R*                  " UR                   UR,                  S9U l        [        R&                  " UR.                  5      U l        U R                  R2                  (       d  U R                  R4                  (       a  U R7                  X"4S9  [        R*                  " UR                   SS9U l        [;        U5      U l        U R?                  5         g )Nr   r   )prT   )r,   gư>) r   r   r+   
text_embedrP   r@   r   r   patch_embedr   r   r#   r%   	Parameterrd   r   r(   r   r   r`   pos_dropr^   r_   ra   rb   r   r   init_visual_bboxnormr  encoderinit_weights)r*   r+   r5   r-   s      r.   r   LayoutLMv3Model.__init__R  sL    6v>DO  9@Dv((6+<+<<=D\\%++aF<N<N*OPDN\\%++aq&J\J\*]^DNJJ-DM\\&*<*<&BWBWXDN::f&@&@ADL{{66$++:`:`%%$%>V%7%7TBDI(0r0   c                 .    U R                   R                  $ rE   r@   r[   )r*   s    r.   get_input_embeddings$LayoutLMv3Model.get_input_embeddingso  s    ...r0   c                 $    XR                   l        g rE   r  )r*   r   s     r.   set_input_embeddings$LayoutLMv3Model.set_input_embeddingsr  s    */'r0   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  r!  r  prune_heads)r*   heads_to_pruner!  headss       r.   _prune_headsLayoutLMv3Model._prune_headsu  s<    
 +002LELLu%//;;EB 3r0   c           	         [         R                  " [         R                  " SX!S   S-   -  U5      US   SS9n[         R                  " [         R                  " SX!S   S-   -  U5      US   SS9n[         R                  " USS R	                  US   S5      USS R	                  US   S5      R                  SS5      USS R	                  US   S5      USS R	                  US   S5      R                  SS5      /SS9R                  SS5      n[         R                  " SSUS-
  US-
  //5      n[         R                  " Xe/SS9U l	        g)	z:
Create the bounding boxes for the visual (patch) tokens.
r   r   trunc)rounding_modeNr2   rs      )
rd   divre   stackrepeatr=   r7   tensorrw   visual_bbox)r*   r,   max_lenvisual_bbox_xvisual_bbox_yr  cls_token_boxs          r.   r~   LayoutLMv3Model.init_visual_bbox}  sX    		LLG!}q'897CZPQ]bi
 		LLG!}q'897CZPQ]bi
 kkcr"))*Q-;cr"))*Q-;EEaKab!((A:ab!((A:DDQJ	 
 $r1+ 	 ueWq['A+&N%OP 99m%AqIr0   c                     U R                   R                  USS5      nUR                  U5      R                  U5      nU$ r  )r  r  r   type)r*   r   r   
batch_sizer  s        r.   calculate_visual_bbox%LayoutLMv3Model.calculate_visual_bbox  s;    &&--j!Q?!nnV,11%8r0   c                 .   U R                  U5      nUR                  5       u  p4nU R                  R                  USS5      n[        R
                  " Xb4SS9nU R                  b  X R                  -   nU R                  U5      nU R                  U5      nU$ )Nr2   r   rs   )	r{  r5   r   rg   rd   rw   r   r}  r  )r*   r>   r@   r  seq_lenr*  
cls_tokenss          r.   forward_imageLayoutLMv3Model.forward_image  s    %%l3
 ",!2
Q^^**:r2>
YY
7Q?
 >>%#nn4J]]:.
YYz*
r0   r   rx   r   r   rV   r   r   r>   r   r^  r_  r   c                 	   U	b  U	OU R                   R                  n	U
b  U
OU R                   R                  n
Ub  UOU R                   R                  nUb!  UR	                  5       nUu  pUR
                  nOMUb$  UR	                  5       SS nUu  pUR
                  nO&Ub  [        U5      nUR
                  nO[        S5      eUc  Ub  Uc  [        R                  " UW4US9nUc$  [        R                  " W[        R                  US9nUc:  [        R                  " [        [        W5      S/-   5      [        R                  US9nU R                  UUUUUS9nS=nnS=nnUGb*  [        UR                   S   U R                   R"                  -  5      [        UR                   S	   U R                   R"                  -  5      nnU R%                  U5      n[        R                  " UUR                   S
   4[        R                  US9nUb  [        R&                  " UU/S
S9nOUnU R                   R(                  (       d  U R                   R*                  (       a  U R                   R*                  (       a<  U R-                  U[        R                  US9nUb  [        R&                  " UU/S
S9nOUn[        R.                  " SUR                   S
   [        R                  US9R1                  US
5      nUc  UbQ  [        R.                  " SWS
   US9R3                  S5      nUR5                  U5      n[        R&                  " UU/S
S9nOUnUc  Ub  [        R&                  " WU/S
S9nOUnU R7                  U5      nU R9                  U5      nOU R                   R(                  (       d  U R                   R*                  (       am  U R                   R*                  (       a  UnU R                   R(                  (       a5  U R                  R:                  SS2SWS
   24   nUR=                  U5      nUnU R?                  USUWR@                  S9nU RC                  X`R                   RD                  5      nU RG                  UUUUUU	U
UUUS9
nUS   nU(       d	  U4US
S -   $ [I        UURJ                  URL                  S9$ )a<  
input_ids (`torch.LongTensor` of shape `(batch_size, token_sequence_length)`):
    Indices of input sequence tokens in the vocabulary.

    Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
    token. See `pixel_values` for `patch_sequence_length`.

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

    [What are input IDs?](../glossary#input-ids)
bbox (`torch.LongTensor` of shape `(batch_size, token_sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner.

    Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
    token. See `pixel_values` for `patch_sequence_length`.
token_type_ids (`torch.LongTensor` of shape `(batch_size, token_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.

    Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
    token. See `pixel_values` for `patch_sequence_length`.

    [What are token type IDs?](../glossary#token-type-ids)
position_ids (`torch.LongTensor` of shape `(batch_size, token_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]`.

    Note that `sequence_length = token_sequence_length + patch_sequence_length + 1` where `1` is for [CLS]
    token. See `pixel_values` for `patch_sequence_length`.

    [What are position IDs?](../glossary#position-ids)
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, token_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.

Examples:

```python
>>> from transformers import AutoProcessor, AutoModel
>>> from datasets import load_dataset

>>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False)
>>> model = AutoModel.from_pretrained("microsoft/layoutlmv3-base")

>>> dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train", trust_remote_code=True)
>>> example = dataset[0]
>>> image = example["image"]
>>> words = example["tokens"]
>>> boxes = example["bboxes"]

>>> encoding = processor(image, words, boxes=boxes, return_tensors="pt")

>>> outputs = model(**encoding)
>>> last_hidden_states = outputs.last_hidden_state
```Nr2   zEYou have to specify either input_ids or inputs_embeds or pixel_values)r   r   r  )r   rx   rV   r   r   r3   r	   r   rs   )r   r  r   )r   )	rx   rV   r   r   r   r^  r_  rA   rB   rV  )'r+   r   r^  use_return_dictr5   r   lenr   rd   onesr   r   r]  listr@   r   r9   r#   r  rw   r   r   r  re   r  r   rg   r^   rb   rV   	expand_asget_extended_attention_maskr   get_head_maskr   r  r   r   rX  )r*   r   rx   r   r   rV   r   r   r>   r   r^  r_  r   r  
seq_lengthr   embedding_output
final_bboxfinal_position_idsrA   rB   visual_embeddingsvisual_attention_maskr  visual_position_idsextended_attention_maskencoder_outputssequence_outputs                               r.   rC   LayoutLMv3Model.forward  s   \ 2C1N-TXT_T_TqTq$8$D $++JjJj 	 &1%<k$++B]B] #..*K%0"J%%F&',,.s3K%0"J"))F%\*J!((Fdee M$=%!&j*-Ev!V%!&[

SY!Z|{{5k):aS)@#A\bc##)-+  /   +/.
'%)){#,,,Q/$++2H2HHI,,,Q/$++2H2HHI &L !% 2 2< @$)JJ.44Q78

SY%! )!&N<Q+RXY!Z!6{{66$++:`:`;;99"&"<"<V5::bl"<"mK'%*YYk/B%J
%0
&+ll(..q1F'&Q' $ (M,E#(<<;q>&#Q#[#[\]#^L#/#6#6{#CL).LBU3V\])^&)<&$(A#(99.>@Q-RXY#Z #4 #~~.>?#||,<=[[448^8^{{55!
{{66#;;A?OQ?O<OP+55i@%1"040P0PD&0@0F0F 1Q 1
 &&y++2O2OP	,,+2/!5#%# ' 
 *!,#%(;;;-)77&11
 	
r0   )r^   r   r+   rb   r@   r  r  r{  r}  r   r  ))   r  i  )NNNNNNNNNNN)rG   rH   rI   rJ   r   r  r  r  r~  r  r  r   r   rd   
LongTensorFloatTensorboolr   r   r   rC   rL   rM   rN   s   @r.   r   r   P  sQ   :/0CJ.
"  15+/6:5937155948,0/3&*C
E,,-C
 u''(C
 !!2!23	C

 !!1!12C
 u//0C
 E--.C
   1 12C
 u001C
 $D>C
 'tnC
 d^C
 
uo%	&C
 C
r0   r   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )LayoutLMv3ClassificationHeadiq  zT
Head for sentence-level classification tasks. Reference: RobertaClassificationHead
c                   > [         TU ]  5         X l        U(       a4  [        R                  " UR
                  S-  UR
                  5      U l        O0[        R                  " UR
                  UR
                  5      U l        UR                  b  UR                  OUR                  n[        R                  " U5      U l
        [        R                  " UR
                  UR                  5      U l        g )Nr	   )r   r   pool_featurer%   r   r(   r   classifier_dropoutra   r`   rb   
num_labelsout_proj)r*   r+   r  r  r-   s       r.   r   %LayoutLMv3ClassificationHead.__init__v  s    (6#5#5#96;M;MNDJ6#5#5v7I7IJDJ)/)B)B)NF%%TZTnTn 	 zz"45		&"4"4f6G6GHr0   c                     U R                  U5      nU R                  U5      n[        R                  " U5      nU R                  U5      nU R	                  U5      nU$ rE   )rb   r   rd   tanhr  )r*   r   s     r.   rC   $LayoutLMv3ClassificationHead.forward  sI    LLOJJqMJJqMLLOMM!r0   )r   rb   r  r  )FrF   rN   s   @r.   r  r  q  s    I r0   r  a  
    LayoutLMv3 Model with a token classification head on top (a linear layer on top of the final hidden states) e.g.
    for sequence labeling (information extraction) tasks such as [FUNSD](https://guillaumejaume.github.io/FUNSD/),
    [SROIE](https://rrc.cvc.uab.es/?ch=13), [CORD](https://github.com/clovaai/cord) and
    [Kleister-NDA](https://github.com/applicaai/kleister-nda).
    )custom_introc                     ^  \ rS rSrU 4S jr\            SS\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S	\\R                     S
\\R                     S\\
   S\\
   S\\
   S\\R                     S\\\4   4S jj5       rSrU =r$ ) LayoutLMv3ForTokenClassificationi  c                 p  > [         TU ]  U5        UR                  U l        [        U5      U l        [
        R                  " UR                  5      U l        UR                  S:  a1  [
        R                  " UR                  UR                  5      U l        O[        USS9U l        U R                  5         g )N
   Fr  )r   r   r  r   r   r%   r`   ra   rb   r   r(   
classifierr  r  rp   s     r.   r   )LayoutLMv3ForTokenClassification.__init__  s      ++)&1zz&"<"<=r! ii(:(:F<M<MNDO:6PUVDOr0   r   rx   r   r   rV   r   r   labelsr   r^  r_  r>   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b  UR                  5       nOUR                  5       SS nUS   nUS   SS2SU24   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$ )ay  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner.
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]`.

Examples:

```python
>>> from transformers import AutoProcessor, AutoModelForTokenClassification
>>> from datasets import load_dataset

>>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False)
>>> model = AutoModelForTokenClassification.from_pretrained("microsoft/layoutlmv3-base", num_labels=7)

>>> dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train", trust_remote_code=True)
>>> example = dataset[0]
>>> image = example["image"]
>>> words = example["tokens"]
>>> boxes = example["bboxes"]
>>> word_labels = example["ner_tags"]

>>> encoding = processor(image, words, boxes=boxes, word_labels=word_labels, return_tensors="pt")

>>> outputs = model(**encoding)
>>> loss = outputs.loss
>>> logits = outputs.logits
```N)
rx   r   r   rV   r   r   r   r^  r_  r>   r2   r   r   losslogitsr   rX  )r+   r  r   r5   rb   r  r   r7   r  r   r   rX  )r*   r   rx   r   r   rV   r   r   r  r   r^  r_  r>   r   r   r  r  r  r  loss_fctr  s                        r.   rC   (LayoutLMv3ForTokenClassification.forward  s:   ^ &1%<k$++B]B]//))%'/!5#% " 
  #..*K',,.s3K ^
!!*Q^4,,71')HFKKDOO<fkk"oNDY,F)-)9TGf$EvE$!//))	
 	
r0   )r  rb   r   r  NNNNNNNNNNNN)rG   rH   rI   rJ   r   r   r   rd   r  r  r  r   r   r   rC   rL   rM   rN   s   @r.   r  r    sK     15+/6:59371559-1,0/3&*37V
E,,-V
 u''(V
 !!2!23	V

 !!1!12V
 u//0V
 E--.V
   1 12V
 ))*V
 $D>V
 'tnV
 d^V
 u//0V
 
u++	,V
 V
r0   r  c                      ^  \ rS rSrU 4S jr\             SS\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S	\\R                     S
\\R                     S\\
   S\\
   S\\
   S\\R                     S\\R                     S\\\4   4S jj5       rSrU =r$ )LayoutLMv3ForQuestionAnsweringi  c                    > [         TU ]  U5        UR                  U l        [        U5      U l        [        USS9U l        U R                  5         g NFr  )r   r   r  r   r   r  
qa_outputsr  rp   s     r.   r   'LayoutLMv3ForQuestionAnswering.__init__  sC      ++)&16vERr0   r   r   r   rV   r   r   start_positionsend_positionsr   r^  r_  rx   r>   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UR	                  SSS9u  nnUR                  S5      R                  5       nUR                  S5      R                  5       nSnUb  Ub  [        UR                  5       5      S:  a  UR                  S5      n[        UR                  5       5      S:  a  UR                  S5      nUR                  S5      nUR                  SU5      nUR                  SU5      n[        US9nU" UU5      nU" UU5      nUU-   S-  nU(       d  UU4USS -   nUb  U4U-   $ U$ [        UUUUR                  UR                  S	9$ )
a_  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner.

Examples:

```python
>>> from transformers import AutoProcessor, AutoModelForQuestionAnswering
>>> from datasets import load_dataset
>>> import torch

>>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False)
>>> model = AutoModelForQuestionAnswering.from_pretrained("microsoft/layoutlmv3-base")

>>> dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train", trust_remote_code=True)
>>> example = dataset[0]
>>> image = example["image"]
>>> question = "what's his name?"
>>> words = example["tokens"]
>>> boxes = example["bboxes"]

>>> encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
>>> start_positions = torch.tensor([1])
>>> end_positions = torch.tensor([3])

>>> outputs = model(**encoding, start_positions=start_positions, end_positions=end_positions)
>>> loss = outputs.loss
>>> start_scores = outputs.start_logits
>>> end_scores = outputs.end_logits
```N
r   r   rV   r   r   r   r^  r_  rx   r>   r   r   r2   rs   )ignore_indexr3   )r  start_logits
end_logitsr   rX  )r+   r  r   r  splitsqueezer   r  r5   clampr   r   r   rX  )r*   r   r   r   rV   r   r   r  r  r   r^  r_  rx   r>   r   r  r  r  r  
total_lossignored_indexr  
start_lossend_lossr  s                            r.   rC   &LayoutLMv3ForQuestionAnswering.forward  s   f &1%<k$++B]B]//))%'/!5#% " 
 "!*1#)<<r<#: j#++B/::<''+668

&=+D?'')*Q."1"9"9""==%%'(1, - 5 5b 9(--a0M-33A}EO)//=AM']CH!,@J
M:H$x/14J"J/'!"+=F/9/EZMF*Q6Q+%!!//))
 	
r0   )r   r  r  )NNNNNNNNNNNNN)rG   rH   rI   rJ   r   r   r   rd   r  r  r  r   r   r   rC   rL   rM   rN   s   @r.   r  r    sd     156:593715596:48,0/3&*+/37d
E,,-d
 !!2!23d
 !!1!12	d

 u//0d
 E--.d
   1 12d
 "%"2"23d
   0 01d
 $D>d
 'tnd
 d^d
 u''(d
 u//0d
 
u22	3d
 d
r0   r  a
  
    LayoutLMv3 Model with a sequence classification head on top (a linear layer on top of the final hidden state of the
    [CLS] token) e.g. for document image classification tasks such as the
    [RVL-CDIP](https://www.cs.cmu.edu/~aharley/rvl-cdip/) dataset.
    c                     ^  \ rS rSrU 4S jr\            SS\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S\\R                     S	\\R                     S
\\
   S\\
   S\\
   S\\R                     S\\R                     S\\\4   4S jj5       rSrU =r$ )#LayoutLMv3ForSequenceClassificationio  c                    > [         TU ]  U5        UR                  U l        Xl        [	        U5      U l        [        USS9U l        U R                  5         g r  )	r   r   r  r+   r   r   r  r  r  rp   s     r.   r   ,LayoutLMv3ForSequenceClassification.__init__w  sH      ++)&16vERr0   r   r   r   rV   r   r   r  r   r^  r_  rx   r>   r   c                 H   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   SS2SSS24   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$ )
a  
bbox (`torch.LongTensor` of shape `(batch_size, sequence_length, 4)`, *optional*):
    Bounding boxes of each input sequence tokens. Selected in the range `[0,
    config.max_2d_position_embeddings-1]`. Each bounding box should be a normalized version in (x0, y0, x1, y1)
    format, where (x0, y0) corresponds to the position of the upper left corner in the bounding box, and (x1,
    y1) represents the position of the lower right corner.

Examples:

```python
>>> from transformers import AutoProcessor, AutoModelForSequenceClassification
>>> from datasets import load_dataset
>>> import torch

>>> processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False)
>>> model = AutoModelForSequenceClassification.from_pretrained("microsoft/layoutlmv3-base")

>>> dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train", trust_remote_code=True)
>>> example = dataset[0]
>>> image = example["image"]
>>> words = example["tokens"]
>>> boxes = example["bboxes"]

>>> encoding = processor(image, words, boxes=boxes, return_tensors="pt")
>>> sequence_label = torch.tensor([1])

>>> outputs = model(**encoding, labels=sequence_label)
>>> loss = outputs.loss
>>> logits = outputs.logits
```Nr  r   r   
regressionsingle_label_classificationmulti_label_classificationr2   r  )r+   r  r   r  problem_typer  r   rd   r   r   r   r  r   r7   r   r   r   rX  )r*   r   r   r   rV   r   r   r  r   r^  r_  rx   r>   r   r  r  r  r  r  s                      r.   rC   +LayoutLMv3ForSequenceClassification.forward  s   \ &1%<k$++B]B]//))%'/!5#% " 
 "!*Q1W-1{{''/??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'!//))	
 	
r0   )r  r+   r   r  r  )rG   rH   rI   rJ   r   r   r   rd   r  r  r  r   r   r   rC   rL   rM   rN   s   @r.   r  r  o  sK     156:59371559-1,0/3&*+/37`
E,,-`
 !!2!23`
 !!1!12	`

 u//0`
 E--.`
   1 12`
 ))*`
 $D>`
 'tn`
 d^`
 u''(`
 u//0`
 
u..	/`
 `
r0   r  )r  r  r  r   r   )6rK   r    r   typingr   r   r   rd   torch.nnr%   torch.nn.functional
functionalr:   torch.utils.checkpointr   r   r   activationsr
   modeling_outputsr   r   r   r   modeling_utilsr   pytorch_utilsr   utilsr   r   r   configuration_layoutlmv3r   
get_loggerrG   loggerModuler   rP   r   r   r   r   r	  r  r  r  r   r  r  r  r  __all__r   r0   r.   <module>r	     s       ) )      A A !  . 6 
 7 
		H	% 		  Fsryy sl . . .2Wbii Wv299 ")) :(bii (VZ
		 Z
|RYY  ryy  ]
/ ]
 ]
@	299 6 e
'@ e
e
P o
%> o
 o
d k
*C k
k
\r0   